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

wip(uts): compiler

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