From ae95d2298b05931c879c91b5d40d7d5d23ad7a07 Mon Sep 17 00:00:00 2001 From: shitao Date: Sat, 7 Jun 2025 13:59:36 +0800 Subject: [PATCH] Error of no sourcemap no file Issue: ICDBLD Signed-off-by: shitao Change-Id: I49fbbf8733674547dc4ec6bbe7a067d71efef551 --- .../ark_compiler/generate_sourcemap.ts | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/compiler/src/fast_build/ark_compiler/generate_sourcemap.ts b/compiler/src/fast_build/ark_compiler/generate_sourcemap.ts index 522df4094..28862e9c0 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; } -- Gitee