提交 f1eed78b 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 27a73253
...@@ -56,5 +56,6 @@ declare namespace NodeJS { ...@@ -56,5 +56,6 @@ declare namespace NodeJS {
HX_Version: string HX_Version: string
UNI_APP_X_PAGE_COUNT: string UNI_APP_X_PAGE_COUNT: string
UNI_APP_X_TSC?: string
} }
} }
import { import {
parseUniExtApiNamespacesOnce, parseUniExtApiNamespacesOnce,
resolveUTSCompiler,
uniUTSUniModulesPlugin, uniUTSUniModulesPlugin,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
import { uniPrePlugin } from '../pre' import { uniPrePlugin } from '../pre'
...@@ -10,6 +11,7 @@ import { uniAppManifestPlugin } from './manifestJson' ...@@ -10,6 +11,7 @@ import { uniAppManifestPlugin } from './manifestJson'
import { uniAppPagesPlugin } from './pagesJson' import { uniAppPagesPlugin } from './pagesJson'
import { uniAppUVuePlugin } from './uvue' import { uniAppUVuePlugin } from './uvue'
import { uniCloudPlugin } from './unicloud' import { uniCloudPlugin } from './unicloud'
import { parseImports, parseUTSRelativeFilename } from './utils'
export function init() { export function init() {
return [ return [
...@@ -28,5 +30,21 @@ export function init() { ...@@ -28,5 +30,21 @@ export function init() {
uniAppCssPlugin(), uniAppCssPlugin(),
uniAppUVuePlugin(), uniAppUVuePlugin(),
uniCloudPlugin(), uniCloudPlugin(),
...(process.env.UNI_APP_X_TSC === 'true'
? [
// 必须在 uvue 处理之后
resolveUTSCompiler().uts2kotlin({
inputDir: process.env.UNI_INPUT_DIR,
sourcemap: process.env.NODE_ENV === 'development',
fileName(fileName) {
const name = parseUTSRelativeFilename(fileName)
return name === 'main.uts' ? 'index.uts' : name
},
jsCode(code) {
return parseImports(code)
},
}),
]
: []),
] ]
} }
...@@ -20,7 +20,6 @@ export function uniAppMainPlugin(): Plugin { ...@@ -20,7 +20,6 @@ export function uniAppMainPlugin(): Plugin {
import './${MANIFEST_JSON_UTS}' import './${MANIFEST_JSON_UTS}'
import './${PAGES_JSON_UTS}' import './${PAGES_JSON_UTS}'
${code} ${code}
export default 'main.uts'
` `
} }
}, },
......
...@@ -136,6 +136,9 @@ export function uniAppPlugin(): UniVitePlugin { ...@@ -136,6 +136,9 @@ export function uniAppPlugin(): UniVitePlugin {
injectAssetPlugin(config, { isAppX: true }) injectAssetPlugin(config, { isAppX: true })
}, },
async transform(code, id) { async transform(code, id) {
if (process.env.UNI_APP_X_TSC === 'true') {
return
}
const { filename } = parseVueRequest(id) const { filename } = parseVueRequest(id)
if (!filename.endsWith('.uts')) { if (!filename.endsWith('.uts')) {
return return
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
type SFCDescriptor, type SFCDescriptor,
type SFCParseResult, type SFCParseResult,
} from '@vue/compiler-sfc' } from '@vue/compiler-sfc'
import type { TransformPluginContext } from 'rollup' import type { SourceMapInput, TransformPluginContext } from 'rollup'
import { isString } from '@vue/shared' import { isString } from '@vue/shared'
import { import {
...@@ -120,6 +120,12 @@ export function uniAppUVuePlugin(): Plugin { ...@@ -120,6 +120,12 @@ export function uniAppUVuePlugin(): Plugin {
) )
return null return null
} }
if (process.env.UNI_APP_X_TSC === 'true') {
return {
code: uts,
map: sourceMap as SourceMapInput,
}
}
const fileName = parseUTSRelativeFilename(filename) const fileName = parseUTSRelativeFilename(filename)
this.emitFile({ this.emitFile({
type: 'asset', type: 'asset',
......
import { extend, isFunction } from '@vue/shared' import { extend, isFunction } from '@vue/shared'
import { RPT2Options } from 'rollup-plugin-typescript2' import { RPT2Options } from 'rollup-plugin-typescript2'
interface UTS2KotlinOptions extends Omit<RPT2Options, 'transformers'> {} interface UTS2KotlinOptions extends Omit<RPT2Options, 'transformers'> {
inputDir: string
sourcemap?: boolean
isUTSFile?: (fileName: string) => boolean
fileName?: (fileName: string) => string
jsCode?: (code: string) => Promise<string>
}
type uts2kotlin = (options: UTS2KotlinOptions) => import('rollup').Plugin[] type uts2kotlin = (options: UTS2KotlinOptions) => import('rollup').Plugin[]
export const uts2kotlin: uts2kotlin = (options) => { export const uts2kotlin: uts2kotlin = (options) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册