diff options
author | 2021-05-06 12:55:17 -0600 | |
---|---|---|
committer | 2021-05-06 14:55:17 -0400 | |
commit | 95b1733c899f1a2ffa8aaf72af22ffd1df148c9f (patch) | |
tree | 3bd4bb88556692892e39d2e18520b6653c239dbb | |
parent | b81abd5b2c0e68f05c99eaad54eb5b9a6bc092db (diff) | |
download | astro-95b1733c899f1a2ffa8aaf72af22ffd1df148c9f.tar.gz astro-95b1733c899f1a2ffa8aaf72af22ffd1df148c9f.tar.zst astro-95b1733c899f1a2ffa8aaf72af22ffd1df148c9f.zip |
Bugfix: handle unawaited promise (#176)
-rw-r--r-- | .changeset/khaki-bags-brake.md | 5 | ||||
-rw-r--r-- | packages/astro/src/build/page.ts | 34 |
2 files changed, 23 insertions, 16 deletions
diff --git a/.changeset/khaki-bags-brake.md b/.changeset/khaki-bags-brake.md new file mode 100644 index 000000000..adb570869 --- /dev/null +++ b/.changeset/khaki-bags-brake.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix: wait for async operation to finish diff --git a/packages/astro/src/build/page.ts b/packages/astro/src/build/page.ts index 89e2ac2a5..691b37507 100644 --- a/packages/astro/src/build/page.ts +++ b/packages/astro/src/build/page.ts @@ -169,7 +169,7 @@ const defaultExtensions: Readonly<Record<string, ValidExtensionPlugins>> = { }; /** Gather necessary framework runtimes (React, Vue, Svelte, etc.) for dynamic components */ -async function gatherRuntimes({ astroConfig, buildState, filepath, logging, resolvePackageUrl, mode, runtime }: PageBuildOptions) { +async function gatherRuntimes({ astroConfig, buildState, filepath, logging, resolvePackageUrl, mode, runtime }: PageBuildOptions): Promise<Set<string>> { const imports = new Set<string>(); // Only astro files @@ -332,20 +332,22 @@ async function gatherRuntimes({ astroConfig, buildState, filepath, logging, reso }); // add all imports to build output - [...imports].map(async (url) => { - // don’t end up in an infinite loop building same URLs over and over - const alreadyBuilt = buildState[url]; - if (alreadyBuilt) return; + await Promise.all( + [...imports].map(async (url) => { + if (buildState[url]) return; // don’t build already-built URLs - // add new results to buildState - const result = await runtime.load(url); - if (result.statusCode === 200) { - buildState[url] = { - srcPath: filepath, - contents: result.contents, - contentType: result.contentType || mime.getType(url) || '', - encoding: 'utf8', - }; - } - }); + // add new results to buildState + const result = await runtime.load(url); + if (result.statusCode === 200) { + buildState[url] = { + srcPath: filepath, + contents: result.contents, + contentType: result.contentType || mime.getType(url) || '', + encoding: 'utf8', + }; + } + }) + ); + + return imports; } |