Skip to content

Commit

Permalink
Revert "fix: unexpected config temporary file (#13269)"
Browse files Browse the repository at this point in the history
This reverts commit ff3ce31.
  • Loading branch information
patak-dev committed Jul 6, 2023
1 parent bd544ab commit 6389d6d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,17 +1150,18 @@ async function loadConfigFromBundledFile(
): Promise<UserConfigExport> {
// for esm, before we can register loaders without requiring users to run node
// with --experimental-loader themselves, we have to do a hack here:
// convert to base64, load it with native Node ESM.
// write it to disk, load it with native Node ESM, then delete the file.
if (isESM) {
const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
.toString(16)
.slice(2)}`
const fileNameTmp = `${fileBase}.mjs`
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
await fsp.writeFile(fileNameTmp, bundledCode)
try {
return (
await dynamicImport(
'data:text/javascript;base64,' +
Buffer.from(bundledCode).toString('base64'),
)
).default
} catch (e) {
throw new Error(`${e.message} at ${fileName}`)
return (await dynamicImport(fileUrl)).default
} finally {
fs.unlink(fileNameTmp, () => {}) // Ignore errors
}
}
// for cjs, we can register a custom loader via `_require.extensions`
Expand Down

0 comments on commit 6389d6d

Please sign in to comment.