From 8f162c1300e40eb9381e23f8fb5a5ec2c7acf007 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 20 Oct 2022 17:15:41 +0800 Subject: [PATCH] wip(uts): compiler --- packages/uni-cli-shared/src/resolve.ts | 24 +++++++++++++++++------- packages/uni-cloud/lib/uni.plugin.js | 3 +-- packages/uni-uts-v1/src/kotlin.ts | 2 +- packages/uni-uts-v1/src/swift.ts | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/uni-cli-shared/src/resolve.ts b/packages/uni-cli-shared/src/resolve.ts index f74a2f4e4..94f3b0920 100644 --- a/packages/uni-cli-shared/src/resolve.ts +++ b/packages/uni-cli-shared/src/resolve.ts @@ -201,13 +201,23 @@ function resolveUtsFile( } export function resolveUTSCompiler(): typeof UTSCompiler { + let compilerPath: string = '' if (isInHBuilderX()) { - return require(path.resolve( - process.env.UNI_HBUILDERX_PLUGINS, - 'uniapp-uts' - )) + try { + compilerPath = require.resolve( + path.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'uniapp-uts') + ) + } catch (e) {} + } + if (!compilerPath) { + try { + compilerPath = require.resolve('@dcloudio/uni-uts-v1', { + paths: [process.env.UNI_CLI_CONTEXT], + }) + } catch (e) {} + } + if (!compilerPath) { + throw 'uts compiler is not found' } - return require(require.resolve('@dcloudio/uni-uts-v1', { - paths: [process.env.UNI_CLI_CONTEXT], - })) + return require(compilerPath) } diff --git a/packages/uni-cloud/lib/uni.plugin.js b/packages/uni-cloud/lib/uni.plugin.js index ad6e45045..60b7b6ebf 100644 --- a/packages/uni-cloud/lib/uni.plugin.js +++ b/packages/uni-cloud/lib/uni.plugin.js @@ -150,8 +150,7 @@ exports.default = () => [ const isSecureNetworkEnabled = (0, uni_cli_shared_1.isEnableSecureNetwork)(inputDir, platform); return { define: { - 'process.env.UNI_SECURE_NETWORK_ENABLE': isSecureNetworkEnabled, - 'process.env.UNI_SECURE_NETWORK_CONFIG': process.env.UNI_SECURE_NETWORK_CONFIG, + 'process.env.UNI_SECURE_NETWORK': isSecureNetworkEnabled, }, }; }, diff --git a/packages/uni-uts-v1/src/kotlin.ts b/packages/uni-uts-v1/src/kotlin.ts index e421fff42..2fc56e899 100644 --- a/packages/uni-uts-v1/src/kotlin.ts +++ b/packages/uni-uts-v1/src/kotlin.ts @@ -152,7 +152,7 @@ function resolveSourceMapFile(outputDir: string, kotlinFile: string) { async function compile(filename: string) { if (!process.env.UNI_HBUILDERX_PLUGINS) { - return console.error('process.env.UNI_HBUILDERX_PLUGINS is not found') + throw 'process.env.UNI_HBUILDERX_PLUGINS is not found' } const { bundle, UtsTarget } = getUtsCompiler() const inputDir = process.env.UNI_INPUT_DIR diff --git a/packages/uni-uts-v1/src/swift.ts b/packages/uni-uts-v1/src/swift.ts index b8eb54aab..2deebe190 100644 --- a/packages/uni-uts-v1/src/swift.ts +++ b/packages/uni-uts-v1/src/swift.ts @@ -40,7 +40,7 @@ export async function runSwiftDev(_filename: string) {} async function compile(filename: string) { if (!process.env.UNI_HBUILDERX_PLUGINS) { - return console.error('process.env.UNI_HBUILDERX_PLUGINS is not found') + throw 'process.env.UNI_HBUILDERX_PLUGINS is not found' } const { bundle, UtsTarget } = getUtsCompiler() const inputDir = process.env.UNI_INPUT_DIR -- GitLab