mirror of
https://github.com/withastro/astro.git
synced 2025-03-24 23:21:57 -05:00
Fix temporary file conflicts
This commit is contained in:
parent
985d3a0ec0
commit
ef2156e41b
1 changed files with 7 additions and 1 deletions
|
@ -182,7 +182,7 @@ export async function importBundledFile({
|
|||
root: URL;
|
||||
}): Promise<{ default?: unknown }> {
|
||||
// Write it to disk, load it with native Node ESM, then delete the file.
|
||||
const tmpFileUrl = new URL(`./db.timestamp-${Date.now()}.mjs`, root);
|
||||
const tmpFileUrl = tempUrl(root);
|
||||
await writeFile(tmpFileUrl, code, { encoding: 'utf8' });
|
||||
try {
|
||||
return await import(/* @vite-ignore */ tmpFileUrl.pathname);
|
||||
|
@ -194,3 +194,9 @@ export async function importBundledFile({
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Get a unique temporary file URL. Combines timestamp and a random ID to avoid conflicts. */
|
||||
function tempUrl(root: URL) {
|
||||
const uuid = Math.random().toFixed(10).slice(2);
|
||||
return new URL(`./db.timestamp-${Date.now()}-${uuid}.mjs`, root);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue