diff --git a/compiler/main.js b/compiler/main.js index 832182d..8b847dc 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -62,6 +62,7 @@ function initProjectConfig(projectConfig) { projectConfig.aceBuildJson = projectConfig.aceBuildJson || process.env.aceBuildJson; projectConfig.cachePath = projectConfig.cachePath || process.env.cachePath || path.resolve(__dirname, 'node_modules/.cache'); + projectConfig.aceSoPath = projectConfig.aceSoPath || process.env.aceSoPath; } function loadEntryObj(projectConfig) { diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 44994e8..2bd39b6 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -29,9 +29,15 @@ import CachedSource from 'webpack-sources/lib/CachedSource'; import ConcatSource from 'webpack-sources/lib/ConcatSource'; import { transformLog } from './process_ui_syntax'; -import { moduleCollection } from './validate_ui_syntax'; +import { + moduleCollection, + useOSFiles +} from './validate_ui_syntax'; import { projectConfig } from '../main'; -import { circularFile } from './utils'; +import { + circularFile, + mkDir +} from './utils'; import { MODULE_SHARE_PATH, BUILD_SHARE_PATH } from './pre_define'; import { createLanguageService, @@ -179,6 +185,10 @@ export class ResultStates { }); compiler.hooks.done.tap('Result States', (stats: Stats) => { + if (projectConfig.isPreview && projectConfig.aceSoPath && + useOSFiles && useOSFiles.size > 0) { + this.writeUseOSFiles(); + } this.mStats = stats; this.warningCount = 0; this.noteCount = 0; @@ -204,6 +214,17 @@ export class ResultStates { } } + private writeUseOSFiles(): void { + let info: string = ''; + if (!fs.existsSync(projectConfig.aceSoPath)) { + const parent: string = path.join(projectConfig.aceSoPath, '..'); + if (!(fs.existsSync(parent) && !fs.statSync(parent).isFile())) { + mkDir(parent); + } + } + fs.writeFileSync(projectConfig.aceSoPath, info + Array.from(useOSFiles).join('\n')); + } + private printResult(): void { this.printWarning(); this.printError(); diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 900d679..3cfecb0 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -76,7 +76,7 @@ export function createLanguageService(rootFileNames: string[]): ts.LanguageServi } if (/(? { return item.replace(new RegExp('\\b' + STRUCT + '\\b', 'g'), `${CLASS} `); - }))); + }), false, fileResolvePath)); const sourceFile: ts.SourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS); visitAllNode(sourceFile, defaultName, asName, path.dirname(fileResolvePath), log); diff --git a/compiler/src/process_system_module.ts b/compiler/src/process_system_module.ts index 9ef05d3..89745d7 100644 --- a/compiler/src/process_system_module.ts +++ b/compiler/src/process_system_module.ts @@ -16,5 +16,5 @@ import { processSystemApi } from './validate_ui_syntax'; module.exports = function processSystemModule(source: string): string { - return processSystemApi(source); + return processSystemApi(source, false, this.resourcePath); }; diff --git a/compiler/src/result_process.ts b/compiler/src/result_process.ts index fe96bf2..dd05dbe 100644 --- a/compiler/src/result_process.ts +++ b/compiler/src/result_process.ts @@ -35,7 +35,7 @@ import { abilityConfig } from '../main'; module.exports = function resultProcess(source: string, map: any): void { process.env.compiler = BUILD_OFF; - source = processSystemApi(source, true); + source = processSystemApi(source, true, this.resourcePath); if (/\.ets$/.test(this.resourcePath)) { componentInfo.id = 0; propertyCollection.clear(); diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index eb8b8ca..50c985f 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -112,6 +112,7 @@ export const objectLinkCollection: Map> = new Map(); export const isStaticViewCollection: Map = new Map(); export const moduleCollection: Set = new Set(); +export const useOSFiles: Set = new Set(); export function validateUISyntax(source: string, content: string, filePath: string, fileQuery: string): LogInfo[] { @@ -734,7 +735,7 @@ export function preprocessExtend(content: string, extendCollection?: Set }); } -export function processSystemApi(content: string, isProcessWhiteList: boolean = false): string { +export function processSystemApi(content: string, isProcessWhiteList: boolean = false, sourcePath: string): string { let REG_SYSTEM: RegExp; if (isProcessWhiteList) { REG_SYSTEM = @@ -749,6 +750,9 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = const newContent: string = content.replace(REG_LIB_SO, (_, item1, item2, item3, item4) => { const libSoValue: string = item1 || item3; const libSoKey: string = item2 || item4; + if (sourcePath) { + useOSFiles.add(sourcePath); + } return `var ${libSoValue} = globalThis.requireNapi("${libSoKey}", true);`; }).replace(REG_SYSTEM, (item, item1, item2, item3, item4, item5, item6, item7) => { let moduleType: string = item2 || item5;