mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-19 16:43:34 -04:00
!988 watch changed files
Merge pull request !988 from houhaoyu/master21
This commit is contained in:
@@ -65,11 +65,17 @@ 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 = getChangedFileList(projectConfig);
|
||||
projectConfig.xtsMode = /ets_loader_ark$/.test(__dirname);
|
||||
projectConfig.localPropertiesPath = projectConfig.localPropertiesPath || process.env.localPropertiesPath
|
||||
projectConfig.projectProfilePath = projectConfig.projectProfilePath || process.env.projectProfilePath
|
||||
}
|
||||
|
||||
function getChangedFileList(projectConfig) {
|
||||
return (projectConfig.hotReloadWatch && projectConfig.hotReloadWatch.outChangedFileList) ?
|
||||
projectConfig.hotReloadWatch.outChangedFileList : path.join(projectConfig.cachePath, 'changedFileList.json');
|
||||
}
|
||||
|
||||
function loadEntryObj(projectConfig) {
|
||||
let manifest = {};
|
||||
initProjectConfig(projectConfig);
|
||||
|
||||
@@ -35,11 +35,13 @@ import {
|
||||
import {
|
||||
circularFile,
|
||||
mkDir,
|
||||
writeFileSync
|
||||
} from './utils';
|
||||
import {
|
||||
MODULE_ETS_PATH,
|
||||
MODULE_SHARE_PATH,
|
||||
BUILD_SHARE_PATH,
|
||||
ESMODULE
|
||||
} from './pre_define';
|
||||
import {
|
||||
createLanguageService,
|
||||
@@ -223,6 +225,30 @@ export class ResultStates {
|
||||
}
|
||||
});
|
||||
|
||||
compiler.hooks.watchRun.tap('WatchRun', (comp) => {
|
||||
if (comp.modifiedFiles) {
|
||||
const isTsAndEtsFile: boolean = [...comp.modifiedFiles].some((item: string) => {
|
||||
return /.(ts|ets)$/.test(item);
|
||||
});
|
||||
if (!isTsAndEtsFile) {
|
||||
process.env.watchTs = 'end';
|
||||
}
|
||||
}
|
||||
if (this.shouldWriteChangedList(comp)) {
|
||||
interface filesObj {
|
||||
modifiedFiles: string[],
|
||||
removedFiles: string[]
|
||||
}
|
||||
const filesObj: filesObj = {
|
||||
modifiedFiles: [...comp.modifiedFiles].filter((file) => {
|
||||
return fs.statSync(file).isFile();
|
||||
}),
|
||||
removedFiles: [...comp.removedFiles]
|
||||
};
|
||||
writeFileSync(projectConfig.outChangedFileList, JSON.stringify(filesObj));
|
||||
}
|
||||
})
|
||||
|
||||
compiler.hooks.done.tap('Result States', (stats: Stats) => {
|
||||
if (projectConfig.isPreview && projectConfig.aceSoPath &&
|
||||
useOSFiles && useOSFiles.size > 0) {
|
||||
@@ -239,17 +265,13 @@ export class ResultStates {
|
||||
}
|
||||
this.printResult();
|
||||
});
|
||||
}
|
||||
|
||||
compiler.hooks.watchRun.tap('Listening State', (compiler: Compiler) => {
|
||||
if (compiler.modifiedFiles) {
|
||||
const isTsAndEtsFile: boolean = [...compiler.modifiedFiles].some((item: string) => {
|
||||
return /.(ts|ets)$/.test(item);
|
||||
});
|
||||
if (!isTsAndEtsFile) {
|
||||
process.env.watchTs = 'end';
|
||||
}
|
||||
}
|
||||
});
|
||||
private shouldWriteChangedList(comp): boolean {
|
||||
return projectConfig.compileMode === ESMODULE && process.env.watchMode && !projectConfig.isPreview &&
|
||||
projectConfig.outChangedFileList && (comp.modifiedFiles || comp.removedFiles) &&
|
||||
!(comp.modifiedFiles && [...comp.modifiedFiles].length === 1 &&
|
||||
[...comp.modifiedFiles][0] == projectConfig.projectPath);
|
||||
}
|
||||
|
||||
private printDiagnostic(diagnostic: ts.Diagnostic): void {
|
||||
@@ -319,13 +341,13 @@ export class ResultStates {
|
||||
if (this.noteCount > 0) {
|
||||
resultInfo += ` NOTE:${this.noteCount}`;
|
||||
}
|
||||
if (result === 'SUCCESS ' && projectConfig.isPreview) {
|
||||
if (result === 'SUCCESS ' && process.env.watchMode) {
|
||||
this.printPreviewResult(resultInfo);
|
||||
} else {
|
||||
logger.info(this.blue, 'COMPILE RESULT:' + result + `{${resultInfo}}`, this.reset);
|
||||
}
|
||||
} else {
|
||||
if (projectConfig.isPreview) {
|
||||
if (process.env.watchMode) {
|
||||
this.printPreviewResult();
|
||||
} else {
|
||||
console.info(this.blue, 'COMPILE RESULT:SUCCESS ', this.reset);
|
||||
|
||||
@@ -205,7 +205,7 @@ export class GenAbcPlugin {
|
||||
|
||||
function clearGlobalInfo() {
|
||||
// fix bug of multi trigger
|
||||
if (!projectConfig.isPreview) {
|
||||
if (!process.env.watchMode) {
|
||||
intermediateJsBundle = [];
|
||||
moduleInfos = [];
|
||||
}
|
||||
@@ -529,7 +529,7 @@ export function initAbcEnv() : string[] {
|
||||
}
|
||||
|
||||
function invokeCluterModuleToAbc(): void {
|
||||
if (projectConfig.isPreview) {
|
||||
if (process.env.watchMode) {
|
||||
process.exitCode = SUCCESS;
|
||||
}
|
||||
filterIntermediateModuleByHashJson(buildPathInfo, moduleInfos);
|
||||
@@ -573,7 +573,7 @@ function invokeCluterModuleToAbc(): void {
|
||||
if (count_ === totalWorkerNumber) {
|
||||
writeModuleHashJson();
|
||||
clearGlobalInfo();
|
||||
if (projectConfig.isPreview) {
|
||||
if (process.env.watchMode) {
|
||||
console.info(blue, 'COMPILE RESULT:SUCCESS ', reset);
|
||||
}
|
||||
}
|
||||
@@ -657,7 +657,7 @@ function judgeModuleWorkersToGenAbc(callback): void {
|
||||
}
|
||||
|
||||
function invokeWorkersToGenAbc(): void {
|
||||
if (projectConfig.isPreview) {
|
||||
if (process.env.watchMode) {
|
||||
process.exitCode = SUCCESS;
|
||||
}
|
||||
let cmdPrefix: string = '';
|
||||
@@ -709,7 +709,7 @@ function invokeWorkersToGenAbc(): void {
|
||||
count_++;
|
||||
if (count_ === workerNumber) {
|
||||
// for preview of with incre compile
|
||||
if (projectConfig.isPreview) {
|
||||
if (process.env.watchMode) {
|
||||
processExtraAssetForBundle();
|
||||
console.info(red, 'COMPILE RESULT:SUCCESS ', reset);
|
||||
}
|
||||
@@ -723,7 +723,7 @@ function invokeWorkersToGenAbc(): void {
|
||||
});
|
||||
|
||||
// for preview of without incre compile
|
||||
if (workerNumber === 0 && projectConfig.isPreview) {
|
||||
if (workerNumber === 0 && process.env.watchMode) {
|
||||
processExtraAssetForBundle();
|
||||
}
|
||||
}
|
||||
@@ -816,7 +816,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));
|
||||
}
|
||||
}
|
||||
@@ -892,7 +892,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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,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)) {
|
||||
@@ -222,7 +222,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());
|
||||
@@ -290,7 +290,7 @@ function collectSpecialFunctionNode(node: ts.FunctionDeclaration, asNameFromPare
|
||||
function isExportEntry(node: ts.ClassDeclaration, log: LogInfo[], entryCollection: Set<string>,
|
||||
exportCollection: Set<string>, defaultCollection: Set<string>, 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) {
|
||||
|
||||
@@ -199,6 +199,9 @@ function setProjectConfig(envArgs) {
|
||||
if (envArgs.cachePath) {
|
||||
projectConfig.cachePath = envArgs.cachePath;
|
||||
}
|
||||
if (envArgs.watchMode) {
|
||||
projectConfig.hotReloadWatch = envArgs.watchMode;
|
||||
}
|
||||
}
|
||||
|
||||
function setReleaseConfig(config) {
|
||||
|
||||
Reference in New Issue
Block a user