Skip to content

Commit 7f01a00

Browse files
authored
fix: backport make resolveConfig() concurrent safe (#9224) (#9229)
1 parent 0d13630 commit 7f01a00

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/vite/src/node/config.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -925,20 +925,22 @@ export async function loadConfigFromFile(
925925
let userConfig: UserConfigExport | undefined
926926

927927
if (isESM) {
928-
const fileUrl = require('url').pathToFileURL(resolvedPath)
929928
const bundled = await bundleConfigFile(resolvedPath, true)
930929
dependencies = bundled.dependencies
931930
if (isTS) {
932931
// before we can register loaders without requiring users to run node
933932
// with --experimental-loader themselves, we have to do a hack here:
934933
// bundle the config file w/ ts transforms first, write it to disk,
935934
// load it with native Node ESM, then delete the file.
936-
fs.writeFileSync(resolvedPath + '.js', bundled.code)
937-
userConfig = (await dynamicImport(`${fileUrl}.js?t=${Date.now()}`))
938-
.default
939-
fs.unlinkSync(resolvedPath + '.js')
935+
const fileBase = `${resolvedPath}.timestamp-${Date.now()}`
936+
const fileNameTmp = `${fileBase}.js`
937+
const fileUrl = `${require('url').pathToFileURL(fileBase)}.js`
938+
fs.writeFileSync(fileNameTmp, bundled.code)
939+
userConfig = (await dynamicImport(fileUrl)).default
940+
fs.unlinkSync(fileNameTmp)
940941
debug(`TS + native esm config loaded in ${getTime()}`, fileUrl)
941942
} else {
943+
const fileUrl = require('url').pathToFileURL(resolvedPath)
942944
// using Function to avoid this from being compiled away by TS/Rollup
943945
// append a query so that we force reload fresh config in case of
944946
// server restart

0 commit comments

Comments
 (0)