Skip to content

Commit 9f52e21

Browse files
s10y10yang.song
authored and
yang.song
committed
fix: unexpected temporary file (#13267)
1 parent 3f3fff2 commit 9f52e21

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

packages/vite/src/node/config.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fs from 'node:fs'
2-
import fsp from 'node:fs/promises'
32
import path from 'node:path'
43
import { pathToFileURL } from 'node:url'
54
import { promisify } from 'node:util'
@@ -1091,18 +1090,17 @@ async function loadConfigFromBundledFile(
10911090
): Promise<UserConfigExport> {
10921091
// for esm, before we can register loaders without requiring users to run node
10931092
// with --experimental-loader themselves, we have to do a hack here:
1094-
// write it to disk, load it with native Node ESM, then delete the file.
1093+
// convert to base64, load it with native Node ESM.
10951094
if (isESM) {
1096-
const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
1097-
.toString(16)
1098-
.slice(2)}`
1099-
const fileNameTmp = `${fileBase}.mjs`
1100-
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
1101-
await fsp.writeFile(fileNameTmp, bundledCode)
11021095
try {
1103-
return (await dynamicImport(fileUrl)).default
1096+
return (
1097+
await dynamicImport(
1098+
'data:text/javascript;base64,' +
1099+
Buffer.from(bundledCode).toString('base64'),
1100+
)
1101+
).default
11041102
} finally {
1105-
fs.unlink(fileNameTmp, () => {}) // Ignore errors
1103+
// Ignore errors
11061104
}
11071105
}
11081106
// for cjs, we can register a custom loader via `_require.extensions`

0 commit comments

Comments
 (0)