Skip to content

Commit

Permalink
fix: make resolveConfig() concurrent safe (#9224)
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout authored Jul 19, 2022
1 parent ae5639c commit dfaeb2b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,12 +1020,14 @@ async function loadConfigFromBundledFile(
// with --experimental-loader themselves, we have to do a hack here:
// write it to disk, load it with native Node ESM, then delete the file.
if (isESM) {
const fileUrl = pathToFileURL(fileName)
fs.writeFileSync(fileName + '.mjs', bundledCode)
const fileBase = `${fileName}.timestamp-${Date.now()}`
const fileNameTmp = `${fileBase}.mjs`
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
fs.writeFileSync(fileNameTmp, bundledCode)
try {
return (await dynamicImport(`${fileUrl}.mjs?t=${Date.now()}`)).default
return (await dynamicImport(fileUrl)).default
} finally {
fs.unlinkSync(fileName + '.mjs')
fs.unlinkSync(fileNameTmp)
}
}
// for cjs, we can register a custom loader via `_require.extensions`
Expand Down

0 comments on commit dfaeb2b

Please sign in to comment.