From bd544abd64006b79f42726689a779cf18f523320 Mon Sep 17 00:00:00 2001 From: patak Date: Thu, 6 Jul 2023 15:41:33 +0200 Subject: [PATCH 1/2] Revert "fix: timestamp config dynamicImport (#13502)" This reverts commit 6a87c65262388a918fa6fcdd55afb2d7352757d4. --- packages/vite/src/node/config.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index bf6ecbb708dc29..6db717a5c7581a 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1153,16 +1153,10 @@ async function loadConfigFromBundledFile( // convert to base64, load it with native Node ESM. if (isESM) { try { - // Postfix the bundled code with a timestamp to avoid Node's ESM loader cache - const configTimestamp = `${fileName}.timestamp:${Date.now()}-${Math.random() - .toString(16) - .slice(2)}` return ( await dynamicImport( 'data:text/javascript;base64,' + - Buffer.from(`${bundledCode}\n//${configTimestamp}`).toString( - 'base64', - ), + Buffer.from(bundledCode).toString('base64'), ) ).default } catch (e) { From 6389d6d250c94a4f1cc39e3bba406930c2d54c74 Mon Sep 17 00:00:00 2001 From: patak Date: Thu, 6 Jul 2023 15:42:51 +0200 Subject: [PATCH 2/2] Revert "fix: unexpected config temporary file (#13269)" This reverts commit ff3ce312a572ec126808afb97b5d3f0a6f9adcb1. --- packages/vite/src/node/config.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 6db717a5c7581a..b9442a3305b743 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1150,17 +1150,18 @@ async function loadConfigFromBundledFile( ): Promise { // 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`