Write pages serially and close file handle (#1395)

This commit is contained in:
Tero Lindeman 2021-09-24 18:58:08 +03:00 committed by GitHub
parent 1baadefa35
commit 0fca1fbcab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -212,16 +212,21 @@ ${stack}
// write to disk and free up memory
timer.write = performance.now();
await Promise.all(
Object.keys(buildState).map(async (id) => {
const outPath = new URL(`.${id}`, astroConfig.dist);
const parentDir = path.dirname(fileURLToPath(outPath));
await fs.promises.mkdir(parentDir, { recursive: true });
await fs.promises.writeFile(outPath, buildState[id].contents, buildState[id].encoding);
delete buildState[id];
delete depTree[id];
})
);
for (const id of Object.keys(buildState)) {
const outPath = new URL(`.${id}`, astroConfig.dist);
const parentDir = path.dirname(fileURLToPath(outPath));
await fs.promises.mkdir(parentDir, {recursive: true});
const handle = await fs.promises.open(outPath, "w")
await fs.promises.writeFile(handle, buildState[id].contents, buildState[id].encoding);
// 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)}]`);
/**