From b93c6bc0e23bafa3f3f03242b63a94c8407ba261 Mon Sep 17 00:00:00 2001 From: liyancheng2 Date: Thu, 11 Sep 2025 13:29:11 +0800 Subject: [PATCH] oh sdk path support kit transform Issue: https://gitee.com/openharmony/third_party_typescript/issues/ICXHM6 Signed-off-by: liyancheng2 Change-Id: I8ed8960c28d0dedd7dc6375a6e1d2408c2ed0e4b --- lib/tsc.js | 29 +++++++++++--- lib/tsserver.js | 32 +++++++++++++--- lib/tsserverlibrary.d.ts | 1 + lib/tsserverlibrary.js | 32 +++++++++++++--- lib/typescript.d.ts | 1 + lib/typescript.js | 31 ++++++++++++--- lib/typingsInstaller.js | 29 +++++++++++--- src/compiler/ohApi.ts | 38 ++++++++++++++----- .../reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 10 files changed, 156 insertions(+), 39 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 85a72f8be8..f3aa4ff32b 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -39074,11 +39074,12 @@ function getKitJsonObject(name, sdkPath, compilerOptions) { if (kitJsonCache == null ? void 0 : kitJsonCache.has(name)) { return kitJsonCache.get(name); } - const OHOS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./openharmony/ets/build-tools/ets-loader/kit_configs"; - const HMS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; + const OHOS_KIT_CONFIG_PATH = ohosKitConfigPath(compilerOptions); + const HMS_KIT_CONFIG_PATH = hmsKitConfigPath(compilerOptions); const ohosJsonPath = resolvePath(sdkPath, OHOS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); const hmsJsonPath = resolvePath(sdkPath, HMS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); - let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : void 0; + const ohJsonPath = ohKitConfigJsonPath(compilerOptions, ohosJsonPath); + let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : sys.fileExists(ohJsonPath) ? sys.readFile(ohJsonPath, "utf-8") : void 0; if (!fileInfo) { kitJsonCache == null ? void 0 : kitJsonCache.set(name, void 0); return void 0; @@ -39091,10 +39092,26 @@ function isMixedCompilerSDKPath(compilerOptions) { if (!compilerOptions.etsLoaderPath) { return false; } - if (normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader")) { - return true; + return normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader"); +} +function isOhSDKPath(compilerOptions) { + if (!compilerOptions.etsLoaderPath) { + return false; } - return false; + return normalizePath(compilerOptions.etsLoaderPath).includes("OpenHarmony/SDK"); +} +function ohosKitConfigPath(compilerOptions) { + if (!isOhSDKPath(compilerOptions) && isMixedCompilerSDKPath(compilerOptions)) { + return "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs"; + } else { + return "./openharmony/ets/build-tools/ets-loader/kit_configs"; + } +} +function hmsKitConfigPath(compilerOptions) { + return isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; +} +function ohKitConfigJsonPath(compilerOptions, ohosJsonPath) { + return isOhSDKPath(compilerOptions) ? `${compilerOptions.etsLoaderPath}/kit_configs` : ohosJsonPath; } function cleanKitJsonCache() { kitJsonCache == null ? void 0 : kitJsonCache.clear(); diff --git a/lib/tsserver.js b/lib/tsserver.js index 29f28e5ba8..e9e8163380 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -1815,6 +1815,7 @@ __export(server_exports, { isObjectLiteralOrClassExpressionMethodOrAccessor: () => isObjectLiteralOrClassExpressionMethodOrAccessor, isObjectTypeDeclaration: () => isObjectTypeDeclaration, isOctalDigit: () => isOctalDigit, + isOhSDKPath: () => isOhSDKPath, isOhpm: () => isOhpm, isOhpmAndOhModules: () => isOhpmAndOhModules, isOmittedExpression: () => isOmittedExpression, @@ -41763,11 +41764,12 @@ function getKitJsonObject(name, sdkPath, compilerOptions) { if (kitJsonCache == null ? void 0 : kitJsonCache.has(name)) { return kitJsonCache.get(name); } - const OHOS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./openharmony/ets/build-tools/ets-loader/kit_configs"; - const HMS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; + const OHOS_KIT_CONFIG_PATH = ohosKitConfigPath(compilerOptions); + const HMS_KIT_CONFIG_PATH = hmsKitConfigPath(compilerOptions); const ohosJsonPath = resolvePath(sdkPath, OHOS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); const hmsJsonPath = resolvePath(sdkPath, HMS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); - let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : void 0; + const ohJsonPath = ohKitConfigJsonPath(compilerOptions, ohosJsonPath); + let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : sys.fileExists(ohJsonPath) ? sys.readFile(ohJsonPath, "utf-8") : void 0; if (!fileInfo) { kitJsonCache == null ? void 0 : kitJsonCache.set(name, void 0); return void 0; @@ -41780,10 +41782,26 @@ function isMixedCompilerSDKPath(compilerOptions) { if (!compilerOptions.etsLoaderPath) { return false; } - if (normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader")) { - return true; + return normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader"); +} +function isOhSDKPath(compilerOptions) { + if (!compilerOptions.etsLoaderPath) { + return false; } - return false; + return normalizePath(compilerOptions.etsLoaderPath).includes("OpenHarmony/SDK"); +} +function ohosKitConfigPath(compilerOptions) { + if (!isOhSDKPath(compilerOptions) && isMixedCompilerSDKPath(compilerOptions)) { + return "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs"; + } else { + return "./openharmony/ets/build-tools/ets-loader/kit_configs"; + } +} +function hmsKitConfigPath(compilerOptions) { + return isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; +} +function ohKitConfigJsonPath(compilerOptions, ohosJsonPath) { + return isOhSDKPath(compilerOptions) ? `${compilerOptions.etsLoaderPath}/kit_configs` : ohosJsonPath; } function cleanKitJsonCache() { kitJsonCache == null ? void 0 : kitJsonCache.clear(); @@ -118118,6 +118136,7 @@ __export(ts_exports3, { isObjectLiteralOrClassExpressionMethodOrAccessor: () => isObjectLiteralOrClassExpressionMethodOrAccessor, isObjectTypeDeclaration: () => isObjectTypeDeclaration, isOctalDigit: () => isOctalDigit, + isOhSDKPath: () => isOhSDKPath, isOhpm: () => isOhpm, isOhpmAndOhModules: () => isOhpmAndOhModules, isOmittedExpression: () => isOmittedExpression, @@ -178910,6 +178929,7 @@ if (typeof process !== "undefined") { isObjectLiteralOrClassExpressionMethodOrAccessor, isObjectTypeDeclaration, isOctalDigit, + isOhSDKPath, isOhpm, isOhpmAndOhModules, isOmittedExpression, diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index b30d6a1d65..6d2f3e78b3 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -9856,6 +9856,7 @@ declare namespace ts { function hasTsNoCheckOrTsIgnoreFlag(node: SourceFile): boolean; function createObfTextSingleLineWriter(): EmitTextWriter; function isMixedCompilerSDKPath(compilerOptions: CompilerOptions): boolean; + function isOhSDKPath(compilerOptions: CompilerOptions): boolean; function cleanKitJsonCache(): void; function getMaxFlowDepth(compilerOptions: CompilerOptions): number; function getErrorCode(diagnostic: Diagnostic): ErrorInfo; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 730522f823..b8cc62af21 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -1815,6 +1815,7 @@ __export(tsserverlibrary_exports, { isObjectLiteralOrClassExpressionMethodOrAccessor: () => isObjectLiteralOrClassExpressionMethodOrAccessor, isObjectTypeDeclaration: () => isObjectTypeDeclaration, isOctalDigit: () => isOctalDigit, + isOhSDKPath: () => isOhSDKPath, isOhpm: () => isOhpm, isOhpmAndOhModules: () => isOhpmAndOhModules, isOmittedExpression: () => isOmittedExpression, @@ -41665,11 +41666,12 @@ function getKitJsonObject(name, sdkPath, compilerOptions) { if (kitJsonCache == null ? void 0 : kitJsonCache.has(name)) { return kitJsonCache.get(name); } - const OHOS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./openharmony/ets/build-tools/ets-loader/kit_configs"; - const HMS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; + const OHOS_KIT_CONFIG_PATH = ohosKitConfigPath(compilerOptions); + const HMS_KIT_CONFIG_PATH = hmsKitConfigPath(compilerOptions); const ohosJsonPath = resolvePath(sdkPath, OHOS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); const hmsJsonPath = resolvePath(sdkPath, HMS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); - let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : void 0; + const ohJsonPath = ohKitConfigJsonPath(compilerOptions, ohosJsonPath); + let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : sys.fileExists(ohJsonPath) ? sys.readFile(ohJsonPath, "utf-8") : void 0; if (!fileInfo) { kitJsonCache == null ? void 0 : kitJsonCache.set(name, void 0); return void 0; @@ -41682,10 +41684,26 @@ function isMixedCompilerSDKPath(compilerOptions) { if (!compilerOptions.etsLoaderPath) { return false; } - if (normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader")) { - return true; + return normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader"); +} +function isOhSDKPath(compilerOptions) { + if (!compilerOptions.etsLoaderPath) { + return false; } - return false; + return normalizePath(compilerOptions.etsLoaderPath).includes("OpenHarmony/SDK"); +} +function ohosKitConfigPath(compilerOptions) { + if (!isOhSDKPath(compilerOptions) && isMixedCompilerSDKPath(compilerOptions)) { + return "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs"; + } else { + return "./openharmony/ets/build-tools/ets-loader/kit_configs"; + } +} +function hmsKitConfigPath(compilerOptions) { + return isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; +} +function ohKitConfigJsonPath(compilerOptions, ohosJsonPath) { + return isOhSDKPath(compilerOptions) ? `${compilerOptions.etsLoaderPath}/kit_configs` : ohosJsonPath; } function cleanKitJsonCache() { kitJsonCache == null ? void 0 : kitJsonCache.clear(); @@ -154584,6 +154602,7 @@ __export(ts_exports3, { isObjectLiteralOrClassExpressionMethodOrAccessor: () => isObjectLiteralOrClassExpressionMethodOrAccessor, isObjectTypeDeclaration: () => isObjectTypeDeclaration, isOctalDigit: () => isOctalDigit, + isOhSDKPath: () => isOhSDKPath, isOhpm: () => isOhpm, isOhpmAndOhModules: () => isOhpmAndOhModules, isOmittedExpression: () => isOmittedExpression, @@ -177907,6 +177926,7 @@ __export(ts_server_exports3, { isObjectLiteralOrClassExpressionMethodOrAccessor, isObjectTypeDeclaration, isOctalDigit, + isOhSDKPath, isOhpm, isOhpmAndOhModules, isOmittedExpression, diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 2b76bcd165..2bfe957dd0 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -5853,6 +5853,7 @@ declare namespace ts { function hasTsNoCheckOrTsIgnoreFlag(node: SourceFile): boolean; function createObfTextSingleLineWriter(): EmitTextWriter; function isMixedCompilerSDKPath(compilerOptions: CompilerOptions): boolean; + function isOhSDKPath(compilerOptions: CompilerOptions): boolean; function cleanKitJsonCache(): void; function getMaxFlowDepth(compilerOptions: CompilerOptions): number; function getErrorCode(diagnostic: Diagnostic): ErrorInfo; diff --git a/lib/typescript.js b/lib/typescript.js index 0d0d5531a4..3ff14cd447 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -1815,6 +1815,7 @@ __export(typescript_exports, { isObjectLiteralOrClassExpressionMethodOrAccessor: () => isObjectLiteralOrClassExpressionMethodOrAccessor, isObjectTypeDeclaration: () => isObjectTypeDeclaration, isOctalDigit: () => isOctalDigit, + isOhSDKPath: () => isOhSDKPath, isOhpm: () => isOhpm, isOhpmAndOhModules: () => isOhpmAndOhModules, isOmittedExpression: () => isOmittedExpression, @@ -41680,11 +41681,12 @@ function getKitJsonObject(name, sdkPath, compilerOptions) { if (kitJsonCache == null ? void 0 : kitJsonCache.has(name)) { return kitJsonCache.get(name); } - const OHOS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./openharmony/ets/build-tools/ets-loader/kit_configs"; - const HMS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; + const OHOS_KIT_CONFIG_PATH = ohosKitConfigPath(compilerOptions); + const HMS_KIT_CONFIG_PATH = hmsKitConfigPath(compilerOptions); const ohosJsonPath = resolvePath(sdkPath, OHOS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); const hmsJsonPath = resolvePath(sdkPath, HMS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); - let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : void 0; + const ohJsonPath = ohKitConfigJsonPath(compilerOptions, ohosJsonPath); + let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : sys.fileExists(ohJsonPath) ? sys.readFile(ohJsonPath, "utf-8") : void 0; if (!fileInfo) { kitJsonCache == null ? void 0 : kitJsonCache.set(name, void 0); return void 0; @@ -41697,10 +41699,26 @@ function isMixedCompilerSDKPath(compilerOptions) { if (!compilerOptions.etsLoaderPath) { return false; } - if (normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader")) { - return true; + return normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader"); +} +function isOhSDKPath(compilerOptions) { + if (!compilerOptions.etsLoaderPath) { + return false; } - return false; + return normalizePath(compilerOptions.etsLoaderPath).includes("OpenHarmony/SDK"); +} +function ohosKitConfigPath(compilerOptions) { + if (!isOhSDKPath(compilerOptions) && isMixedCompilerSDKPath(compilerOptions)) { + return "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs"; + } else { + return "./openharmony/ets/build-tools/ets-loader/kit_configs"; + } +} +function hmsKitConfigPath(compilerOptions) { + return isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; +} +function ohKitConfigJsonPath(compilerOptions, ohosJsonPath) { + return isOhSDKPath(compilerOptions) ? `${compilerOptions.etsLoaderPath}/kit_configs` : ohosJsonPath; } function cleanKitJsonCache() { kitJsonCache == null ? void 0 : kitJsonCache.clear(); @@ -166134,6 +166152,7 @@ if (typeof console !== "undefined") { isObjectLiteralOrClassExpressionMethodOrAccessor, isObjectTypeDeclaration, isOctalDigit, + isOhSDKPath, isOhpm, isOhpmAndOhModules, isOmittedExpression, diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 32a1b753f9..66e5e9a776 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -29418,11 +29418,12 @@ function getKitJsonObject(name, sdkPath, compilerOptions) { if (kitJsonCache == null ? void 0 : kitJsonCache.has(name)) { return kitJsonCache.get(name); } - const OHOS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./openharmony/ets/build-tools/ets-loader/kit_configs"; - const HMS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; + const OHOS_KIT_CONFIG_PATH = ohosKitConfigPath(compilerOptions); + const HMS_KIT_CONFIG_PATH = hmsKitConfigPath(compilerOptions); const ohosJsonPath = resolvePath(sdkPath, OHOS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); const hmsJsonPath = resolvePath(sdkPath, HMS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); - let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : void 0; + const ohJsonPath = ohKitConfigJsonPath(compilerOptions, ohosJsonPath); + let fileInfo = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, "utf-8") : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, "utf-8") : sys.fileExists(ohJsonPath) ? sys.readFile(ohJsonPath, "utf-8") : void 0; if (!fileInfo) { kitJsonCache == null ? void 0 : kitJsonCache.set(name, void 0); return void 0; @@ -29435,10 +29436,26 @@ function isMixedCompilerSDKPath(compilerOptions) { if (!compilerOptions.etsLoaderPath) { return false; } - if (normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader")) { - return true; + return normalizePath(compilerOptions.etsLoaderPath).endsWith("ets1.1/build-tools/ets-loader"); +} +function isOhSDKPath(compilerOptions) { + if (!compilerOptions.etsLoaderPath) { + return false; } - return false; + return normalizePath(compilerOptions.etsLoaderPath).includes("OpenHarmony/SDK"); +} +function ohosKitConfigPath(compilerOptions) { + if (!isOhSDKPath(compilerOptions) && isMixedCompilerSDKPath(compilerOptions)) { + return "./openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs"; + } else { + return "./openharmony/ets/build-tools/ets-loader/kit_configs"; + } +} +function hmsKitConfigPath(compilerOptions) { + return isMixedCompilerSDKPath(compilerOptions) ? "./hms/ets/ets1.1/build-tools/ets-loader/kit_configs" : "./hms/ets/build-tools/ets-loader/kit_configs"; +} +function ohKitConfigJsonPath(compilerOptions, ohosJsonPath) { + return isOhSDKPath(compilerOptions) ? `${compilerOptions.etsLoaderPath}/kit_configs` : ohosJsonPath; } function setVirtualNodeAndKitImportFlags(node, start = 0, end = 0) { node.virtual = true; diff --git a/src/compiler/ohApi.ts b/src/compiler/ohApi.ts index 7f0c87b11c..d3f42d1f6f 100644 --- a/src/compiler/ohApi.ts +++ b/src/compiler/ohApi.ts @@ -1180,18 +1180,16 @@ function getKitJsonObject(name: string, sdkPath: string, compilerOptions: Compil if (kitJsonCache?.has(name)) { return kitJsonCache.get(name); } - const OHOS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? - './openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs' : - './openharmony/ets/build-tools/ets-loader/kit_configs'; - const HMS_KIT_CONFIG_PATH = isMixedCompilerSDKPath(compilerOptions) ? - './hms/ets/ets1.1/build-tools/ets-loader/kit_configs' : - './hms/ets/build-tools/ets-loader/kit_configs'; + const OHOS_KIT_CONFIG_PATH = ohosKitConfigPath(compilerOptions); + const HMS_KIT_CONFIG_PATH = hmsKitConfigPath(compilerOptions); const ohosJsonPath = resolvePath(sdkPath, OHOS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); const hmsJsonPath = resolvePath(sdkPath, HMS_KIT_CONFIG_PATH, `./${name}${JSON_SUFFIX}`); + const ohJsonPath = ohKitConfigJsonPath(compilerOptions, ohosJsonPath); let fileInfo: string | undefined = sys.fileExists(ohosJsonPath) ? sys.readFile(ohosJsonPath, 'utf-8') : sys.fileExists(hmsJsonPath) ? sys.readFile(hmsJsonPath, 'utf-8') : + sys.fileExists(ohJsonPath) ? sys.readFile(ohJsonPath, 'utf-8') : undefined; if (!fileInfo) { kitJsonCache?.set(name, undefined); @@ -1209,10 +1207,32 @@ export function isMixedCompilerSDKPath(compilerOptions: CompilerOptions): boolea if (!compilerOptions.etsLoaderPath) { return false; } - if (normalizePath(compilerOptions.etsLoaderPath).endsWith('ets1.1/build-tools/ets-loader')) { - return true; + return normalizePath(compilerOptions.etsLoaderPath).endsWith('ets1.1/build-tools/ets-loader'); +} + +export function isOhSDKPath(compilerOptions: CompilerOptions): boolean { + if (!compilerOptions.etsLoaderPath) { + return false; } - return false; + return normalizePath(compilerOptions.etsLoaderPath).includes('OpenHarmony/SDK'); +} + +function ohosKitConfigPath(compilerOptions: CompilerOptions): string { + if (!isOhSDKPath(compilerOptions) && isMixedCompilerSDKPath(compilerOptions)) { + return './openharmony/ets/ets1.1/build-tools/ets-loader/kit_configs'; + } else { + return './openharmony/ets/build-tools/ets-loader/kit_configs'; + } +} + +function hmsKitConfigPath(compilerOptions: CompilerOptions): string { + return isMixedCompilerSDKPath(compilerOptions) ? + './hms/ets/ets1.1/build-tools/ets-loader/kit_configs' : + './hms/ets/build-tools/ets-loader/kit_configs'; +} + +function ohKitConfigJsonPath(compilerOptions: CompilerOptions, ohosJsonPath: string): string { + return isOhSDKPath(compilerOptions) ? `${compilerOptions.etsLoaderPath}/kit_configs` : ohosJsonPath; } export function cleanKitJsonCache(): void { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index b30d6a1d65..6d2f3e78b3 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -9856,6 +9856,7 @@ declare namespace ts { function hasTsNoCheckOrTsIgnoreFlag(node: SourceFile): boolean; function createObfTextSingleLineWriter(): EmitTextWriter; function isMixedCompilerSDKPath(compilerOptions: CompilerOptions): boolean; + function isOhSDKPath(compilerOptions: CompilerOptions): boolean; function cleanKitJsonCache(): void; function getMaxFlowDepth(compilerOptions: CompilerOptions): number; function getErrorCode(diagnostic: Diagnostic): ErrorInfo; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 2b76bcd165..2bfe957dd0 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5853,6 +5853,7 @@ declare namespace ts { function hasTsNoCheckOrTsIgnoreFlag(node: SourceFile): boolean; function createObfTextSingleLineWriter(): EmitTextWriter; function isMixedCompilerSDKPath(compilerOptions: CompilerOptions): boolean; + function isOhSDKPath(compilerOptions: CompilerOptions): boolean; function cleanKitJsonCache(): void; function getMaxFlowDepth(compilerOptions: CompilerOptions): number; function getErrorCode(diagnostic: Diagnostic): ErrorInfo; -- Gitee