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) {
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)