From cd74a60c9e323bff2187bcad9ebf57be7016b2df Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 2 Mar 2021 15:29:43 +0800 Subject: [PATCH] feat:Fix sometimes mapping merged twice --- doric-cli/src/actions.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doric-cli/src/actions.ts b/doric-cli/src/actions.ts index 94270605..d272a847 100644 --- a/doric-cli/src/actions.ts +++ b/doric-cli/src/actions.ts @@ -60,6 +60,11 @@ async function doMerge(jsFile: string) { export async function mergeMap(mapFile: string) { + const mapContent = await fs.promises.readFile(mapFile, "utf-8"); + if (JSON.parse(mapContent).merged) { + console.log("Already merged"); + return; + } const lockFile = `${mapFile}.lock`; if (fs.existsSync(lockFile)) { console.log("In mergeMap,skip") @@ -72,8 +77,10 @@ export async function mergeMap(mapFile: string) { const mergedMap = createMergedSourceMapFromFiles([ buildMap, mapFile, - ], true); - await fs.promises.writeFile(mapFile, mergedMap); + ], true) as string; + const mapObj = JSON.parse(mergedMap); + mapObj.merged = true + await fs.promises.writeFile(mapFile, JSON.stringify(mapObj), "utf-8"); } } finally { await fs.promises.unlink(lockFile)