0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

Bugfix: handle unawaited promise (#176)

This commit is contained in:
Drew Powers 2021-05-06 12:55:17 -06:00 committed by GitHub
parent b81abd5b2c
commit 95b1733c89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 16 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix: wait for async operation to finish

View file

@ -169,7 +169,7 @@ const defaultExtensions: Readonly<Record<string, ValidExtensionPlugins>> = {
}; };
/** Gather necessary framework runtimes (React, Vue, Svelte, etc.) for dynamic components */ /** 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>(); const imports = new Set<string>();
// Only astro files // Only astro files
@ -332,20 +332,22 @@ async function gatherRuntimes({ astroConfig, buildState, filepath, logging, reso
}); });
// add all imports to build output // add all imports to build output
[...imports].map(async (url) => { await Promise.all(
// dont end up in an infinite loop building same URLs over and over [...imports].map(async (url) => {
const alreadyBuilt = buildState[url]; if (buildState[url]) return; // dont build already-built URLs
if (alreadyBuilt) return;
// add new results to buildState // add new results to buildState
const result = await runtime.load(url); const result = await runtime.load(url);
if (result.statusCode === 200) { if (result.statusCode === 200) {
buildState[url] = { buildState[url] = {
srcPath: filepath, srcPath: filepath,
contents: result.contents, contents: result.contents,
contentType: result.contentType || mime.getType(url) || '', contentType: result.contentType || mime.getType(url) || '',
encoding: 'utf8', encoding: 'utf8',
}; };
} }
}); })
);
return imports;
} }