diff --git a/packages/shims-node.d.ts b/packages/shims-node.d.ts index 2acda4e5643f675d8c7697d7507d84e28c71d738..01cdab31ed5534d48c74978ccb5d0890fd8f8fb9 100644 --- a/packages/shims-node.d.ts +++ b/packages/shims-node.d.ts @@ -56,5 +56,6 @@ declare namespace NodeJS { HX_Version: string UNI_APP_X_PAGE_COUNT: string + UNI_APP_X_TSC?: string } } diff --git a/packages/uni-app-uts/src/plugins/android/index.ts b/packages/uni-app-uts/src/plugins/android/index.ts index 31885ffa4a6964670b7de9a4a3f89abca5737e85..29431dc3d55e326b40e2f2b0ff187bde15a1eabd 100644 --- a/packages/uni-app-uts/src/plugins/android/index.ts +++ b/packages/uni-app-uts/src/plugins/android/index.ts @@ -1,5 +1,6 @@ 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) + }, + }), + ] + : []), ] } diff --git a/packages/uni-app-uts/src/plugins/android/mainUTS.ts b/packages/uni-app-uts/src/plugins/android/mainUTS.ts index 3bc9a3f33163c20f8b6595e036e694cba18f49ff..71b87a1a8090b572333a3b42dd097ec1f296ecf3 100644 --- a/packages/uni-app-uts/src/plugins/android/mainUTS.ts +++ b/packages/uni-app-uts/src/plugins/android/mainUTS.ts @@ -20,7 +20,6 @@ export function uniAppMainPlugin(): Plugin { import './${MANIFEST_JSON_UTS}' import './${PAGES_JSON_UTS}' ${code} -export default 'main.uts' ` } }, diff --git a/packages/uni-app-uts/src/plugins/android/plugin.ts b/packages/uni-app-uts/src/plugins/android/plugin.ts index b8351b56a2f364094af896c43ffd2604942d4c89..d928b9b5acbe464dfa8107c77d687623aae9864e 100644 --- a/packages/uni-app-uts/src/plugins/android/plugin.ts +++ b/packages/uni-app-uts/src/plugins/android/plugin.ts @@ -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 diff --git a/packages/uni-app-uts/src/plugins/android/uvue/index.ts b/packages/uni-app-uts/src/plugins/android/uvue/index.ts index 6be863f7a9524b6b3e93cdfbdd2c9e5dc01f2ab0..6021507baa4e62a18abf9cd9c5bdebda9b9cf986 100644 --- a/packages/uni-app-uts/src/plugins/android/uvue/index.ts +++ b/packages/uni-app-uts/src/plugins/android/uvue/index.ts @@ -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', diff --git a/packages/uni-uts-v1/src/tsc/kotlin/index.ts b/packages/uni-uts-v1/src/tsc/kotlin/index.ts index dc5ab97823136c708deee66ca081c78c4afb3e2c..2d111915f6e3327d790de3a1f296cabaef568c5f 100644 --- a/packages/uni-uts-v1/src/tsc/kotlin/index.ts +++ b/packages/uni-uts-v1/src/tsc/kotlin/index.ts @@ -1,6 +1,12 @@ import { extend, isFunction } from '@vue/shared' import { RPT2Options } from 'rollup-plugin-typescript2' -interface UTS2KotlinOptions extends Omit {} +interface UTS2KotlinOptions extends Omit { + inputDir: string + sourcemap?: boolean + isUTSFile?: (fileName: string) => boolean + fileName?: (fileName: string) => string + jsCode?: (code: string) => Promise +} type uts2kotlin = (options: UTS2KotlinOptions) => import('rollup').Plugin[] export const uts2kotlin: uts2kotlin = (options) => {