Fix bytecode har hot reload bug

Issue:
https: //gitee.com/openharmony/developtools_ace_ets2bundle/issues/IAZ88S
Signed-off-by: xuhangqi <xuhangqi@huawei.com>
Change-Id: Ie53dd58387c5cfd907df9fbbfddc277f7cd2aef5
This commit is contained in:
xuhangqi 2024-10-23 16:31:58 +08:00
parent b207eaa3eb
commit 2019927dca
8 changed files with 46 additions and 25 deletions

View File

@ -32,6 +32,7 @@ export class ModuleBuildMode extends ModuleMode {
if (isEs2Abc(this.projectConfig)) {
this.generateEs2AbcCmd();
this.addCacheFileArgs();
this.genDescriptionsForMergedEs2abc(!!this.projectConfig.byteCodeHarInfo);
this.generateMergedAbcOfEs2Abc(parentEvent);
} else if (isTs2Abc(this.projectConfig)) {
this.filterModulesByHashJson();

View File

@ -74,7 +74,7 @@ export class ModuleColdreloadMode extends ModuleMode {
private compileAllFiles(rollupObject: Object, parentEvent: Object): void {
this.prepareForCompilation(rollupObject, parentEvent);
SourceMapGenerator.getInstance().buildModuleSourceMapInfo(parentEvent);
this.generateAbcByEs2abc(parentEvent);
this.generateAbcByEs2abc(parentEvent, !!this.projectConfig.byteCodeHarInfo);
}
private compileChangeListFiles(rollupObject: Object, parentEvent: Object): void {
@ -118,7 +118,8 @@ export class ModuleColdreloadMode extends ModuleMode {
const outputABCPath: string = path.join(this.projectConfig.patchAbcPath, MODULES_ABC);
validateFilePathLength(outputABCPath, this.logger);
this.moduleAbcPath = outputABCPath;
this.generateAbcByEs2abc(parentEvent);
// During incremental compilation, the bytecode har path must be blocked from being written to filesInfo.
this.generateAbcByEs2abc(parentEvent, false);
}
private updateSourceMapFromFileList(fileList: Array<string>, parentEvent: Object): void {
@ -147,9 +148,10 @@ export class ModuleColdreloadMode extends ModuleMode {
stopEvent(eventUpdateSourceMapFromFileList);
}
private generateAbcByEs2abc(parentEvent: Object): void {
private generateAbcByEs2abc(parentEvent: Object, includeByteCodeHarInfo: boolean): void {
this.generateEs2AbcCmd();
this.addColdReloadArgs();
this.genDescriptionsForMergedEs2abc(includeByteCodeHarInfo);
this.generateMergedAbcOfEs2Abc(parentEvent);
}
}

View File

@ -40,6 +40,7 @@ export class ModuleHotfixMode extends ModuleMode {
SourceMapGenerator.getInstance().buildModuleSourceMapInfo(parentEvent);
this.generateEs2AbcCmdForHotfix();
this.genDescriptionsForMergedEs2abc(!!this.projectConfig.byteCodeHarInfo);
this.generateMergedAbcOfEs2Abc(parentEvent);
}

View File

@ -83,7 +83,7 @@ export class ModuleHotreloadMode extends ModuleMode {
private compileAllFiles(rollupObject: Object, parentEvent: Object): void {
this.prepareForCompilation(rollupObject, parentEvent);
SourceMapGenerator.getInstance().buildModuleSourceMapInfo(parentEvent);
this.generateAbcByEs2abc(parentEvent);
this.generateAbcByEs2abc(parentEvent, !!this.projectConfig.byteCodeHarInfo);
}
private compileChangeListFiles(rollupObject: Object, parentEvent: Object): void {
@ -130,7 +130,8 @@ export class ModuleHotreloadMode extends ModuleMode {
const outputABCPath: string = path.join(this.projectConfig.patchAbcPath, MODULES_ABC);
validateFilePathLength(outputABCPath, this.logger);
this.moduleAbcPath = outputABCPath;
this.generateAbcByEs2abc(parentEvent);
// During incremental compilation, the bytecode har path must be blocked from being written to filesInfo.
this.generateAbcByEs2abc(parentEvent, false);
}
private parseChangedFileListJson(changedFileListJson: string): object {
@ -181,9 +182,10 @@ export class ModuleHotreloadMode extends ModuleMode {
stopEvent(eventUpdateSourceMapFromFileList);
}
private generateAbcByEs2abc(parentEvent: Object): void {
private generateAbcByEs2abc(parentEvent: Object, includeByteCodeHarInfo: boolean): void {
this.generateEs2AbcCmd();
this.addHotReloadArgs();
this.genDescriptionsForMergedEs2abc(includeByteCodeHarInfo);
this.generateMergedAbcOfEs2Abc(parentEvent);
}
}

View File

@ -528,7 +528,7 @@ export class ModuleMode extends CommonMode {
this.cmdArgs.push(`"@${this.cacheFilePath}"`);
}
private generateCompileFilesInfo() {
private generateCompileFilesInfo(includeByteCodeHarInfo: boolean) {
let filesInfo: string = '';
this.moduleInfos.forEach((info) => {
const moduleType: string = info.isCommonJs ? COMMONJS : ESM;
@ -536,7 +536,7 @@ export class ModuleMode extends CommonMode {
filesInfo += `${info.cacheFilePath};${info.recordName};${moduleType};${info.sourceFile};${info.packageName};` +
`${isSharedModule}\n`;
});
if (this.projectConfig.byteCodeHarInfo) {
if (includeByteCodeHarInfo) {
Object.entries(this.projectConfig.byteCodeHarInfo).forEach(([pkgName, abcInfo]) => {
// es2abc parses file path and pkgName according to the file extension .abc.
// Accurate version replacement requires 'pkgName' to es2abc.
@ -572,8 +572,8 @@ export class ModuleMode extends CommonMode {
fs.writeFileSync(this.cacheFilePath, abcCacheFilesInfo, 'utf-8');
}
private genDescriptionsForMergedEs2abc() {
this.generateCompileFilesInfo();
genDescriptionsForMergedEs2abc(includeByteCodeHarInfo: boolean) {
this.generateCompileFilesInfo(includeByteCodeHarInfo);
if (!this.byteCodeHar) {
this.generateNpmEntriesInfo();
}
@ -584,7 +584,6 @@ export class ModuleMode extends CommonMode {
// collect data error from subprocess
let errMsg: string = '';
const eventGenDescriptionsForMergedEs2abc = createAndStartEvent(parentEvent, 'generate descriptions for merged es2abc');
this.genDescriptionsForMergedEs2abc();
stopEvent(eventGenDescriptionsForMergedEs2abc);
const genAbcCmd: string = this.cmdArgs.join(' ');
try {

View File

@ -32,6 +32,7 @@ export class ModulePreviewMode extends ModuleMode {
if (isEs2Abc(this.projectConfig)) {
this.generateEs2AbcCmd();
this.addCacheFileArgs();
this.genDescriptionsForMergedEs2abc(!!this.projectConfig.byteCodeHarInfo);
this.generateMergedAbcOfEs2Abc(parentEvent);
} else if (isTs2Abc(this.projectConfig)) {
this.filterModulesByHashJson();

View File

@ -78,8 +78,8 @@ class ModuleModeMock extends ModuleMode {
return { moduleInfos: moduleMode.moduleInfos, sourceMap: sourceMapGenerator.getSourceMaps() };
}
generateCompileFilesInfoMock() {
this.generateCompileFilesInfo();
generateCompileFilesInfoMock(includeByteCodeHarInfo: boolean) {
this.generateCompileFilesInfo(includeByteCodeHarInfo);
}
generateNpmEntriesInfoMock() {
@ -138,7 +138,7 @@ class ModuleModeMock extends ModuleMode {
return false;
}
checkGenerateCompileFilesInfo(): boolean {
checkGenerateCompileFilesInfo(includeByteCodeHarInfo: boolean): boolean {
let mockfilesInfo: string = '';
const filesInfo = fs.readFileSync(this.filesInfoPath, 'utf-8');
this.moduleInfos.forEach((info) => {
@ -148,7 +148,7 @@ class ModuleModeMock extends ModuleMode {
`${info.cacheFilePath};${info.recordName};${moduleType};${info.sourceFile};${info.packageName};` +
`${isSharedModule}\n`;
});
if (this.projectConfig.byteCodeHarInfo) {
if (includeByteCodeHarInfo) {
Object.entries(this.projectConfig.byteCodeHarInfo).forEach(([pkgName, abcInfo]) => {
const abcPath: string = toUnixPath(abcInfo.abcPath);
mockfilesInfo += `${abcPath};;;;${pkgName};\n`;

View File

@ -943,8 +943,8 @@ mocha.describe('test module_mode file api', function () {
SourceMapGenerator.initInstance(this.rollup);
const moduleMode = new ModuleModeMock(this.rollup);
moduleMode.addModuleInfoItemMock(this.rollup, false, '');
moduleMode.generateCompileFilesInfoMock();
expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true;
moduleMode.generateCompileFilesInfoMock(false);
expect(moduleMode.checkGenerateCompileFilesInfo(false) === true).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
@ -953,8 +953,8 @@ mocha.describe('test module_mode file api', function () {
SourceMapGenerator.initInstance(this.rollup);
const moduleMode = new ModuleModeMock(this.rollup);
moduleMode.addModuleInfoItemMock(this.rollup, false, '');
moduleMode.generateCompileFilesInfoMock();
expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true;
moduleMode.generateCompileFilesInfoMock(false);
expect(moduleMode.checkGenerateCompileFilesInfo(false) === true).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
@ -963,8 +963,8 @@ mocha.describe('test module_mode file api', function () {
SourceMapGenerator.initInstance(this.rollup);
const moduleMode = new ModuleModeMock(this.rollup);
moduleMode.addModuleInfoItemMock(this.rollup, false, '');
moduleMode.generateCompileFilesInfoMock();
expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true;
moduleMode.generateCompileFilesInfoMock(false);
expect(moduleMode.checkGenerateCompileFilesInfo(false) === true).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
@ -973,8 +973,8 @@ mocha.describe('test module_mode file api', function () {
SourceMapGenerator.initInstance(this.rollup);
const moduleMode = new ModuleModeMock(this.rollup);
moduleMode.addModuleInfoItemMock(this.rollup, false, '');
moduleMode.generateCompileFilesInfoMock();
expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true;
moduleMode.generateCompileFilesInfoMock(false);
expect(moduleMode.checkGenerateCompileFilesInfo(false) === true).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
@ -988,8 +988,23 @@ mocha.describe('test module_mode file api', function () {
};
const moduleMode = new ModuleModeMock(this.rollup);
moduleMode.addModuleInfoItemMock(this.rollup, false, '');
moduleMode.generateCompileFilesInfoMock();
expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true;
moduleMode.generateCompileFilesInfoMock(true);
expect(moduleMode.checkGenerateCompileFilesInfo(true) === true).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('4-6: test generateCompileFilesInfo under hot reload debug incremental', function () {
this.rollup.hotReload();
SourceMapGenerator.initInstance(this.rollup);
this.rollup.share.projectConfig.byteCodeHarInfo = {
'har': {
'abcPath': 'module.abc'
}
};
const moduleMode = new ModuleModeMock(this.rollup);
moduleMode.addModuleInfoItemMock(this.rollup, false, '');
moduleMode.generateCompileFilesInfoMock(false);
expect(moduleMode.checkGenerateCompileFilesInfo(false) === true).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});