diff --git a/packages/uni-app-harmony/.gitignore b/packages/uni-app-harmony/.gitignore index f2989f1e85..d1d397b3ce 100644 --- a/packages/uni-app-harmony/.gitignore +++ b/packages/uni-app-harmony/.gitignore @@ -1 +1,2 @@ -dist/packages \ No newline at end of file +dist/packages +dist-x/packages \ No newline at end of file diff --git a/packages/uni-app-harmony/src/compiler/plugin.ts b/packages/uni-app-harmony/src/compiler/plugin.ts index 7aac3b56a2..500bc75d59 100644 --- a/packages/uni-app-harmony/src/compiler/plugin.ts +++ b/packages/uni-app-harmony/src/compiler/plugin.ts @@ -352,7 +352,11 @@ function genAppHarmonyUniModules( extApiCodes.push(...registerProviderCodes) } importCodes.unshift( - `import { registerUniProvider, uni } from '@dcloudio/uni-app-runtime'` + `import { registerUniProvider, uni } from '${ + process.env.UNI_APP_X !== 'true' + ? '@dcloudio/uni-app-runtime' + : '@dcloudio/uni-app-x-runtime' + }'` ) context.emitFile({ diff --git a/packages/uni-app-harmony/vite.config.ts b/packages/uni-app-harmony/vite.config.ts index 514c3f5f56..7515c2c39e 100644 --- a/packages/uni-app-harmony/vite.config.ts +++ b/packages/uni-app-harmony/vite.config.ts @@ -267,7 +267,7 @@ function generateExtApiSourceCode(isUniAppX = false) { .map((key) => injects[key][1]) extApiStandaloneBuildJson.push({ input: path.resolve(extApiTempDir, extApi), - output: path.resolve(__dirname, `dist/packages/${extApi}`), + output: path.resolve(__dirname, isUniAppX ? 'dist-x' : 'dist', `packages/${extApi}`), plugin: extApi, type: standaloneExtApi.type, apis, @@ -276,7 +276,7 @@ function generateExtApiSourceCode(isUniAppX = false) { const [_, service, provider] = extApi.split('-') extApiStandaloneBuildJson.push({ input: path.resolve(extApiTempDir, extApi), - output: path.resolve(__dirname, `dist/packages/${extApi}`), + output: path.resolve(__dirname, isUniAppX ? 'dist-x' : 'dist', `packages/${extApi}`), plugin: extApi, type: standaloneExtApi.type, provider, diff --git a/packages/uni-uts-v1/src/arkts.ts b/packages/uni-uts-v1/src/arkts.ts index 1076572c11..a87ca52188 100644 --- a/packages/uni-uts-v1/src/arkts.ts +++ b/packages/uni-uts-v1/src/arkts.ts @@ -37,10 +37,15 @@ export function mergeArkTSAutoImports( return result } -export function getArkTSAutoImports(): AutoImportOptions { +function getRuntimePackageName(isX = false) { + return isX ? '@dcloudio/uni-app-x-runtime' : '@dcloudio/uni-app-runtime' +} + +export function getArkTSAutoImports(isX = false): AutoImportOptions { + const runtimePackageName = getRuntimePackageName(isX) return mergeArkTSAutoImports( { - '@dcloudio/uni-app-runtime': [ + [runtimePackageName]: [ ['defineAsyncApi'], ['defineSyncApi'], ['defineTaskApi'], @@ -109,24 +114,24 @@ export async function compileArkTSExtApi( rootDir: string, pluginDir: string, outputDir: string, - { isExtApi, isOhpmPackage = false, transform }: ArkTSCompilerOptions + { isExtApi, isX, isOhpmPackage = false, transform }: ArkTSCompilerOptions ): Promise { const filename = resolveAppHarmonyIndexFile(pluginDir) if (!filename) { return } + const runtimePackageName = getRuntimePackageName(isX) const { bundle, UTSTarget } = getUTSCompiler() const pluginId = path.basename(pluginDir) const outputUniModuleDir = outputDir - let autoImportExternals = getArkTSAutoImports() + let autoImportExternals = getArkTSAutoImports(isX) if (isOhpmPackage) { // 只保留uni-app-runtime autoImportExternals = { - '@dcloudio/uni-app-runtime': - autoImportExternals['@dcloudio/uni-app-runtime'], + [runtimePackageName]: autoImportExternals[runtimePackageName], } } @@ -136,7 +141,7 @@ export async function compileArkTSExtApi( root: rootDir, filename: resolveBundleInputFileName('app-harmony', filename), paths: { - '@dcloudio/uni-runtime': '@dcloudio/uni-app-runtime', + '@dcloudio/uni-runtime': runtimePackageName, }, parseOptions: { tsx: true, @@ -275,7 +280,7 @@ export async function compileArkTSExtApi( buildOption: { arkOptions: { runtimeOnly: { - packages: ['@dcloudio/uni-app-runtime'], + packages: [runtimePackageName], }, }, }, @@ -319,7 +324,7 @@ export default { export async function compileArkTS( pluginDir: string, - { isExtApi, transform }: ArkTSCompilerOptions + { isExtApi, isX, transform }: ArkTSCompilerOptions ): Promise { const inputDir = process.env.UNI_INPUT_DIR const pluginId = path.basename(pluginDir) @@ -327,7 +332,7 @@ export async function compileArkTS( resolveBundleInputRoot('app-harmony', inputDir), pluginDir, resolveAppHarmonyUniModuleDir(pluginId), - { isExtApi, transform } + { isExtApi, isX, transform } ) } diff --git a/scripts/build.js b/scripts/build.js index 55bed25b9d..f7c39529aa 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -294,6 +294,7 @@ async function postBuildArkTS (isUniAppX = false) { harBuildJson[i] await compileArkTSExtApi(path.resolve(input, '..'), input, output, { isExtApi: true, + isX: isUniAppX, isOhpmPackage: true, transform: {}, })