diff --git a/compiler/main.js b/compiler/main.js index d17eeda..186d084 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -65,6 +65,8 @@ function initProjectConfig(projectConfig) { projectConfig.cachePath = projectConfig.cachePath || process.env.cachePath || path.resolve(__dirname, 'node_modules/.cache'); projectConfig.aceSoPath = projectConfig.aceSoPath || process.env.aceSoPath; + projectConfig.outChangedFileList = (projectConfig.watchMode && projectConfig.watchMode.outChangedFileList) ? + projectConfig.watchMode.outChangedFileList : path.join(projectConfig.cachePath, 'changedFileList.json'); projectConfig.xtsMode = /ets_loader_ark$/.test(__dirname); } diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index e912ea9..37632e1 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -223,6 +223,24 @@ export class ResultStates { } }); + compiler.hooks.watchRun.tap('WatchRun', (comp) => { + if (process.env.watchMode && projectConfig.outChangedFileList && (comp.modifiedFiles || comp.removedFiles) && + !(comp.modifiedFiles && [...comp.modifiedFiles].length === 1 && [...comp.modifiedFiles][0] == projectConfig.projectPath)) { + const filesObj = { + modifiedFiles: [...comp.modifiedFiles].filter((file) => { + return fs.statSync(file).isFile(); + }), + removedFiles: [...comp.removedFiles] + }; + if (fs.existsSync(path.dirname(projectConfig.outChangedFileList))) { + fs.writeFileSync(projectConfig.outChangedFileList, JSON.stringify(filesObj)); + } else { + fs.mkdirSync(path.dirname(projectConfig.outChangedFileList)); + fs.writeFileSync(projectConfig.outChangedFileList, JSON.stringify(filesObj)); + } + } + }) + compiler.hooks.done.tap('Result States', (stats: Stats) => { if (projectConfig.isPreview && projectConfig.aceSoPath && useOSFiles && useOSFiles.size > 0) { diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index b0af0f9..90c2234 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -180,7 +180,7 @@ export class GenAbcPlugin { function clearGlobalInfo() { // fix bug of multi trigger - if (!projectConfig.isPreview) { + if (!process.env.watchMode) { intermediateJsBundle = []; moduleInfos = []; } @@ -494,7 +494,7 @@ function invokeCluterModuleToAbc(): void { if (count_ === totalWorkerNumber) { writeModuleHashJson(); clearGlobalInfo(); - if (projectConfig.isPreview) { + if (process.env.watchMode) { console.info(blue, 'COMPILE RESULT:SUCCESS ', reset); } } @@ -628,7 +628,7 @@ function invokeWorkersToGenAbc(): void { if (count_ === workerNumber) { writeHashJson(); clearGlobalInfo(); - if (projectConfig.isPreview) { + if (process.env.watchMode) { console.info(red, 'COMPILE RESULT:SUCCESS ', reset); } } @@ -733,7 +733,7 @@ function writeModuleHashJson(): void { return; } // fix bug of multi trigger - if (!projectConfig.isPreview || delayCount < 1) { + if (!process.env.watchMode || delayCount < 1) { fs.writeFileSync(hashFilePath, JSON.stringify(moduleHashJsonObject)); } } @@ -778,7 +778,7 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil if (jsonObject[input] === hashInputContentData && jsonObject[abcPath] === hashAbcContentData) { updateJsonObject[input] = hashInputContentData; updateJsonObject[abcPath] = hashAbcContentData; - if (!projectConfig.isPreview) { + if (!process.env.watchMode) { fs.unlinkSync(input); } } else { @@ -806,7 +806,7 @@ function writeHashJson(): void { const hashAbcContentData: any = toHashData(abcPath); hashJsonObject[input] = hashInputContentData; hashJsonObject[abcPath] = hashAbcContentData; - if (!projectConfig.isPreview) { + if (!process.env.watchMode) { fs.unlinkSync(input); } } @@ -815,7 +815,7 @@ function writeHashJson(): void { return; } // fix bug of multi trigger - if (!projectConfig.isPreview || delayCount < 1) { + if (!process.env.watchMode || delayCount < 1) { fs.writeFileSync(hashFilePath, JSON.stringify(hashJsonObject)); } } diff --git a/compiler/src/process_import.ts b/compiler/src/process_import.ts index 7f4a930..ea32b4c 100644 --- a/compiler/src/process_import.ts +++ b/compiler/src/process_import.ts @@ -195,7 +195,7 @@ function visitAllNode(node: ts.Node, sourceFile: ts.SourceFile, defaultNameFromP if (ts.isExportDeclaration(node) && node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements) { node.exportClause.elements.forEach(item => { - if (projectConfig.isPreview) { + if (process.env.watchMode) { exportCollection.add((item.propertyName ? item.propertyName : item.name).escapedText.toString()); } if (item.name && ts.isIdentifier(item.name)) { @@ -225,7 +225,7 @@ function visitAllNode(node: ts.Node, sourceFile: ts.SourceFile, defaultNameFromP } if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) { - if (projectConfig.isPreview && node.exportClause && ts.isNamedExports(node.exportClause) && + if (process.env.watchMode && node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements) { node.exportClause.elements.forEach(item => { exportCollection.add((item.propertyName ? item.propertyName : item.name).escapedText.toString()); @@ -293,7 +293,7 @@ function collectSpecialFunctionNode(node: ts.FunctionDeclaration, asNameFromPare function isExportEntry(node: ts.ClassDeclaration, log: LogInfo[], entryCollection: Set, exportCollection: Set, defaultCollection: Set, fileResolvePath: string, sourceFile: ts.SourceFile): void { - if (projectConfig.isPreview && node && node.decorators) { + if (process.env.watchMode && node && node.decorators) { let existExport: boolean = false; let existEntry: boolean = false; if (node.modifiers) { diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index 93dad6d..e11515a 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -198,6 +198,9 @@ function setProjectConfig(envArgs) { if (envArgs.cachePath) { projectConfig.cachePath = envArgs.cachePath; } + if (envArgs.watchMode) { + projectConfig.watchMode = envArgs.watchMode; + } } function setReleaseConfig(config) {