Write pages serially and close file handle (#1395)
This commit is contained in:
parent
1baadefa35
commit
0fca1fbcab
1 changed files with 15 additions and 10 deletions
|
@ -212,16 +212,21 @@ ${stack}
|
||||||
|
|
||||||
// write to disk and free up memory
|
// write to disk and free up memory
|
||||||
timer.write = performance.now();
|
timer.write = performance.now();
|
||||||
await Promise.all(
|
for (const id of Object.keys(buildState)) {
|
||||||
Object.keys(buildState).map(async (id) => {
|
const outPath = new URL(`.${id}`, astroConfig.dist);
|
||||||
const outPath = new URL(`.${id}`, astroConfig.dist);
|
const parentDir = path.dirname(fileURLToPath(outPath));
|
||||||
const parentDir = path.dirname(fileURLToPath(outPath));
|
await fs.promises.mkdir(parentDir, {recursive: true});
|
||||||
await fs.promises.mkdir(parentDir, { recursive: true });
|
const handle = await fs.promises.open(outPath, "w")
|
||||||
await fs.promises.writeFile(outPath, buildState[id].contents, buildState[id].encoding);
|
await fs.promises.writeFile(handle, buildState[id].contents, buildState[id].encoding);
|
||||||
delete buildState[id];
|
|
||||||
delete depTree[id];
|
// Ensure the file handle is not left hanging which will
|
||||||
})
|
// result in the garbage collector loggin errors in the console
|
||||||
);
|
// when it eventually has to close them.
|
||||||
|
await handle.close();
|
||||||
|
|
||||||
|
delete buildState[id];
|
||||||
|
delete depTree[id];
|
||||||
|
};
|
||||||
debug(logging, 'build', `wrote files to disk [${stopTimer(timer.write)}]`);
|
debug(logging, 'build', `wrote files to disk [${stopTimer(timer.write)}]`);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue