File tree Expand file tree Collapse file tree 1 file changed +10
-15
lines changed
Expand file tree Collapse file tree 1 file changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -1150,23 +1150,18 @@ async function loadConfigFromBundledFile(
11501150) : Promise < UserConfigExport > {
11511151 // for esm, before we can register loaders without requiring users to run node
11521152 // with --experimental-loader themselves, we have to do a hack here:
1153- // convert to base64 , load it with native Node ESM.
1153+ // write it to disk , load it with native Node ESM, then delete the file .
11541154 if ( isESM ) {
1155+ const fileBase = `${ fileName } .timestamp-${ Date . now ( ) } -${ Math . random ( )
1156+ . toString ( 16 )
1157+ . slice ( 2 ) } `
1158+ const fileNameTmp = `${ fileBase } .mjs`
1159+ const fileUrl = `${ pathToFileURL ( fileBase ) } .mjs`
1160+ await fsp . writeFile ( fileNameTmp , bundledCode )
11551161 try {
1156- // Postfix the bundled code with a timestamp to avoid Node's ESM loader cache
1157- const configTimestamp = `${ fileName } .timestamp:${ Date . now ( ) } -${ Math . random ( )
1158- . toString ( 16 )
1159- . slice ( 2 ) } `
1160- return (
1161- await dynamicImport (
1162- 'data:text/javascript;base64,' +
1163- Buffer . from ( `${ bundledCode } \n//${ configTimestamp } ` ) . toString (
1164- 'base64' ,
1165- ) ,
1166- )
1167- ) . default
1168- } catch ( e ) {
1169- throw new Error ( `${ e . message } at ${ fileName } ` )
1162+ return ( await dynamicImport ( fileUrl ) ) . default
1163+ } finally {
1164+ fs . unlink ( fileNameTmp , ( ) => { } ) // Ignore errors
11701165 }
11711166 }
11721167 // for cjs, we can register a custom loader via `_require.extensions`
You can’t perform that action at this time.
0 commit comments