diff --git a/compiler/src/fast_build/ark_compiler/generate_sourcemap.ts b/compiler/src/fast_build/ark_compiler/generate_sourcemap.ts index 522df409403b1f5a0f79d7f7ddff2493a677c598..28862e9c045b75bf717579d0b221de03491147f3 100644 --- a/compiler/src/fast_build/ark_compiler/generate_sourcemap.ts +++ b/compiler/src/fast_build/ark_compiler/generate_sourcemap.ts @@ -328,15 +328,29 @@ export class SourceMapGenerator { stopEvent(eventWriteCachedSourceMaps); } + public checkAndWriteEnd(): void { + if (!this.isFirstAppend) { + this.writeOrigin('\n}'); + } + //no collect sourcemap + if (!fs.existsSync(this.sourceMapPath)) { + this.writeOrigin('{}'); + } + if (!fs.existsSync(this.sourceMapPathTmp)) { + this.writeTemp(''); + } + this.closeFd(); + if (fs.existsSync(this.cacheSourceMapPath)) { + fs.unlinkSync(this.cacheSourceMapPath); + } + fs.renameSync(this.sourceMapPathTmp, this.cacheSourceMapPath); + } + public async writeUsedAndUnmodifiedSourceMapToFile(parentEvent: CompileEvent | undefined): Promise { const eventMergeCachedSourceMaps = createAndStartEvent(parentEvent, 'merge cached source maps'); let cacheSourceMapInfo: Object = this.getCacheSourceMapInfo(); if (!cacheSourceMapInfo.exist) { - if (!this.isFirstAppend) { - this.writeOrigin('\n}'); - } - this.closeFd(); - fs.renameSync(this.sourceMapPathTmp, this.cacheSourceMapPath); + this.checkAndWriteEnd(); stopEvent(eventMergeCachedSourceMaps); return; } @@ -361,17 +375,15 @@ export class SourceMapGenerator { this.writeTemp(`\n${this.formatTemp(smObj.key, smObj.val)}`); } } - if (!this.isFirstAppend) { - this.writeOrigin('\n}'); - } - this.closeFd(); - fs.unlinkSync(this.cacheSourceMapPath); - fs.renameSync(this.sourceMapPathTmp, this.cacheSourceMapPath); + this.checkAndWriteEnd(); })(); stopEvent(eventMergeCachedSourceMaps); } public buildModuleSourceMapInfoSingle(parentEvent: CompileEvent | undefined): void { + if (this.projectConfig.widgetCompile) { + return; + } if (!this.isCompileSingle) { return; } @@ -382,14 +394,6 @@ export class SourceMapGenerator { } public buildModuleSourceMapInfo(parentEvent: CompileEvent | undefined): void { - if (this.isCompileSingle) { - this.writeUsedAndUnmodifiedSourceMapToFile(parentEvent); - } else { - this.buildModuleSourceMapInfoAll(parentEvent); - } - } - - public buildModuleSourceMapInfoAll(parentEvent: CompileEvent | undefined): void { if (this.projectConfig.widgetCompile) { return; }