diff --git a/compiler/main.js b/compiler/main.js index 9c3b6c5..95ddcc0 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -46,6 +46,8 @@ const resources = { }; const abilityPagesFullPath = []; +const systemModules = []; + function initProjectConfig(projectConfig) { projectConfig.entryObj = {}; projectConfig.projectPath = projectConfig.projectPath || process.env.aceModuleRoot || @@ -304,6 +306,13 @@ function filterWorker(workerPath) { } })() +;(function readSystemModules() { + const systemModulesPath = path.resolve(__dirname,'../../api'); + if (fs.existsSync(systemModulesPath)) { + systemModules.push(...fs.readdirSync(systemModulesPath)); + } +})() + function readAppResource(resources, filePath) { if (fs.existsSync(filePath)) { const appResource = fs.readFileSync(filePath, "utf-8"); @@ -374,3 +383,4 @@ exports.abilityConfig = abilityConfig; exports.readWorkerFile = readWorkerFile; exports.abilityPagesFullPath = abilityPagesFullPath; exports.loadModuleInfo = loadModuleInfo; +exports.systemModules = systemModules; diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index f976be3..5af515f 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -17,7 +17,10 @@ import fs from 'fs'; import path from 'path'; import * as ts from 'typescript'; -import { projectConfig } from '../main'; +import { + projectConfig, + systemModules +} from '../main'; import { processSystemApi, preprocessExtend, @@ -140,9 +143,9 @@ function resolveModuleNames(moduleNames: string[], containingFile: string): ts.R } else { resolvedModules.push(null); } - } else if (/^@(system|ohos)/.test(moduleName.trim())) { + } else if (/^@(system|ohos)/i.test(moduleName.trim())) { const modulePath: string = path.resolve(__dirname, '../../../api', moduleName + '.d.ts'); - if (ts.sys.fileExists(modulePath)) { + if (systemModules.includes(moduleName + '.d.ts') && ts.sys.fileExists(modulePath)) { resolvedModules.push(getResolveModule(modulePath, '.d.ts')); } else { resolvedModules.push(null);