feat:Fix sometimes mapping merged twice

This commit is contained in:
pengfei.zhou 2021-03-02 15:29:43 +08:00 committed by osborn
parent cf888e3655
commit cd74a60c9e

View File

@ -60,6 +60,11 @@ async function doMerge(jsFile: string) {
export async function mergeMap(mapFile: 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`; const lockFile = `${mapFile}.lock`;
if (fs.existsSync(lockFile)) { if (fs.existsSync(lockFile)) {
console.log("In mergeMap,skip") console.log("In mergeMap,skip")
@ -72,8 +77,10 @@ export async function mergeMap(mapFile: string) {
const mergedMap = createMergedSourceMapFromFiles([ const mergedMap = createMergedSourceMapFromFiles([
buildMap, buildMap,
mapFile, mapFile,
], true); ], true) as string;
await fs.promises.writeFile(mapFile, mergedMap); const mapObj = JSON.parse(mergedMap);
mapObj.merged = true
await fs.promises.writeFile(mapFile, JSON.stringify(mapObj), "utf-8");
} }
} finally { } finally {
await fs.promises.unlink(lockFile) await fs.promises.unlink(lockFile)