diff options
author | 2021-09-24 18:58:08 +0300 | |
---|---|---|
committer | 2021-09-24 17:58:08 +0200 | |
commit | 0fca1fbcabf1c27d18864eb80a15e37e42d93c88 (patch) | |
tree | 994fc0fe74ba0ddb2578130147f9b4530279abe7 | |
parent | 1baadefa35e4f3e7c4262f989ea82e874146cb64 (diff) | |
download | astro-0fca1fbcabf1c27d18864eb80a15e37e42d93c88.tar.gz astro-0fca1fbcabf1c27d18864eb80a15e37e42d93c88.tar.zst astro-0fca1fbcabf1c27d18864eb80a15e37e42d93c88.zip |
Write pages serially and close file handle (#1395)
-rw-r--r-- | packages/astro/src/build.ts | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/packages/astro/src/build.ts b/packages/astro/src/build.ts index 5f68ef21e..02d52bc88 100644 --- a/packages/astro/src/build.ts +++ b/packages/astro/src/build.ts @@ -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)}]`); /** |