From 6044da0fea0508f76298bad91c9be46fab47d235 Mon Sep 17 00:00:00 2001 From: hufeng Date: Thu, 7 Jul 2022 14:17:40 +0800 Subject: [PATCH] Fix failing resolve relative-path in node_modules dir Description: relative-path in node_modules, having including path `src/main/ets|js` will cause ohm resolving failure. This PR will search the Path to choose whether replacing OhmUrl Signed-off-by: hufeng Change-Id: I4f08fd5f9b2b43609ead207abe9bfc25d84445ba --- compiler/src/validate_ui_syntax.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 0307dba..4f8556c 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -998,11 +998,15 @@ function replaceRelativePath(item:string, moduleRequest: string, sourcePath: str const filePath: string = path.resolve(path.dirname(sourcePath), moduleRequest); const result: RegExpMatchArray | null = filePath.match(/(\S+)(\/|\\)src(\/|\\)main(\/|\\)(ets|js)(\/|\\)(\S+)/); if (result && projectConfig.aceModuleJsonPath) { - const packageInfo: string[] = getPackageInfo(projectConfig.aceModuleJsonPath); - const bundleName: string = packageInfo[0]; - const moduleName: string = packageInfo[1]; - moduleRequest = `@bundle:${bundleName}/${moduleName}/${result[5]}/${toUnixPath(result[7])}`; - item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); + const npmModuleIdx: number = result[1].search(/(\/|\\)node_modules(\/|\\)/); + const projectRootPath: string = projectConfig.projectRootPath; + if (npmModuleIdx == -1 || npmModuleIdx == projectRootPath.search(/(\/|\\)node_modules(\/|\\)/)) { + const packageInfo: string[] = getPackageInfo(projectConfig.aceModuleJsonPath); + const bundleName: string = packageInfo[0]; + const moduleName: string = packageInfo[1]; + moduleRequest = `@bundle:${bundleName}/${moduleName}/${result[5]}/${toUnixPath(result[7])}`; + item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); + } } } return item;