2
2
3
3
const {
4
4
ArrayIsArray,
5
- ArrayPrototypePush,
6
5
PromisePrototypeThen,
7
- ReflectApply,
8
- SafeMap,
9
6
SafeSet,
10
7
SafeWeakMap,
11
8
ObjectFreeze,
@@ -17,7 +14,7 @@ const {
17
14
} = require ( 'internal/errors' ) . codes ;
18
15
const { getOptionValue } = require ( 'internal/options' ) ;
19
16
const { pathToFileURL } = require ( 'internal/url' ) ;
20
- const { kEmptyObject, createDeferredPromise } = require ( 'internal/util' ) ;
17
+ const { kEmptyObject } = require ( 'internal/util' ) ;
21
18
const {
22
19
setImportModuleDynamicallyCallback,
23
20
setInitializeImportMetaObjectCallback,
@@ -95,14 +92,6 @@ async function importModuleDynamicallyCallback(wrap, specifier, assertions) {
95
92
}
96
93
97
94
function initializeESM ( ) {
98
- const { setESMLoader } = require ( 'internal/process/esm_loader' ) ;
99
- // Minimal mock for letting `--require` work before we have any actual ESM loader.
100
- setESMLoader ( { __proto__ : null , cjsCache : new SafeMap ( ) , import ( ) {
101
- const { promise, resolve, reject } = createDeferredPromise ( ) ;
102
- ArrayPrototypePush ( this . importRequests , { arguments : arguments , resolve, reject } ) ;
103
- return promise ;
104
- } , importRequests : [ ] } ) ;
105
-
106
95
initializeDefaultConditions ( ) ;
107
96
// Setup per-isolate callbacks that locate data or callbacks that we keep
108
97
// track of for different ESM modules.
@@ -126,22 +115,10 @@ async function initializeHooks() {
126
115
const hooks = new Hooks ( ) ;
127
116
128
117
const { DefaultModuleLoader } = require ( 'internal/modules/esm/loader' ) ;
129
- const { esmLoader , setESMLoader } = require ( 'internal/process/esm_loader' ) ;
118
+ const { init } = require ( 'internal/process/esm_loader' ) ;
130
119
class ModuleLoader extends DefaultModuleLoader {
131
- constructor ( ) {
132
- super ( ) ;
133
- for ( const { 0 : key , 1 : value } of esmLoader . cjsCache ) {
134
- // Getting back the values from the mocked loader.
135
- this . cjsCache . set ( key , value ) ;
136
- }
137
- for ( let i = 0 ; i < esmLoader . importRequests . length ; i ++ ) {
138
- PromisePrototypeThen (
139
- ReflectApply ( this . import , this , esmLoader . importRequests [ i ] . arguments ) ,
140
- esmLoader . importRequests [ i ] . resolve ,
141
- esmLoader . importRequests [ i ] . reject ,
142
- ) ;
143
- }
144
- }
120
+ // eslint-disable-next-line no-useless-constructor
121
+ constructor ( ) { super ( ) ; }
145
122
146
123
loaderType = 'internal' ;
147
124
async #getModuleJob( specifier , parentURL , importAssertions ) {
@@ -166,8 +143,6 @@ async function initializeHooks() {
166
143
}
167
144
const privateModuleLoader = new ModuleLoader ( ) ;
168
145
169
- setESMLoader ( privateModuleLoader ) ;
170
-
171
146
const parentURL = pathToFileURL ( cwd ) . href ;
172
147
173
148
for ( let i = 0 ; i < customLoaderPaths . length ; i ++ ) {
@@ -185,6 +160,8 @@ async function initializeHooks() {
185
160
186
161
const preloadScripts = hooks . initializeGlobalPreload ( ) ;
187
162
163
+ init ( privateModuleLoader ) ;
164
+
188
165
return { __proto__ : null , hooks, preloadScripts } ;
189
166
}
190
167
0 commit comments