|
4 | 4 | require('internal/modules/cjs/loader'); |
5 | 5 |
|
6 | 6 | const { |
7 | | - Array, |
8 | | - ArrayIsArray, |
9 | 7 | FunctionPrototypeCall, |
10 | 8 | ObjectSetPrototypeOf, |
11 | 9 | PromisePrototypeThen, |
12 | | - SafePromiseAllReturnArrayLike, |
13 | 10 | SafeWeakMap, |
14 | 11 | } = primordials; |
15 | 12 |
|
@@ -236,51 +233,18 @@ class DefaultModuleLoader { |
236 | 233 | * |
237 | 234 | * This method must NOT be renamed: it functions as a dynamic import on a |
238 | 235 | * loader module. |
239 | | - * @param {string | string[]} specifiers Path(s) to the module. |
| 236 | + * @param {string} specifier The first parameter of an `import()` expression. |
240 | 237 | * @param {string} parentURL Path of the parent importing the module. |
241 | 238 | * @param {Record<string, string>} importAssertions Validations for the |
242 | 239 | * module import. |
243 | 240 | * @returns {Promise<ExportedHooks | KeyedExports[]>} |
244 | 241 | * A collection of module export(s) or a list of collections of module |
245 | 242 | * export(s). |
246 | 243 | */ |
247 | | - async import(specifiers, parentURL, importAssertions) { |
248 | | - // For loaders, `import` is passed multiple things to process, it returns a |
249 | | - // list pairing the url and exports collected. This is especially useful for |
250 | | - // error messaging, to identity from where an export came. But, in most |
251 | | - // cases, only a single url is being "imported" (ex `import()`), so there is |
252 | | - // only 1 possible url from which the exports were collected and it is |
253 | | - // already known to the caller. Nesting that in a list would only ever |
254 | | - // create redundant work for the caller, so it is later popped off the |
255 | | - // internal list. |
256 | | - const wasArr = ArrayIsArray(specifiers); |
257 | | - if (!wasArr) { specifiers = [specifiers]; } |
258 | | - |
259 | | - const count = specifiers.length; |
260 | | - const jobs = new Array(count); |
261 | | - |
262 | | - for (let i = 0; i < count; i++) { |
263 | | - jobs[i] = PromisePrototypeThen( |
264 | | - this |
265 | | - .getModuleJob(specifiers[i], parentURL, importAssertions) |
266 | | - .run(), |
267 | | - ({ module }) => module.getNamespace(), |
268 | | - ); |
269 | | - } |
270 | | - |
271 | | - const namespaces = await SafePromiseAllReturnArrayLike(jobs); |
272 | | - |
273 | | - if (!wasArr) { return namespaces[0]; } // We can skip the pairing below |
274 | | - |
275 | | - for (let i = 0; i < count; i++) { |
276 | | - namespaces[i] = { |
277 | | - __proto__: null, |
278 | | - url: specifiers[i], |
279 | | - exports: namespaces[i], |
280 | | - }; |
281 | | - } |
282 | | - |
283 | | - return namespaces; |
| 244 | + async import(specifier, parentURL, importAssertions) { |
| 245 | + const moduleJob = this.getModuleJob(specifier, parentURL, importAssertions); |
| 246 | + const { module } = await moduleJob.run(); |
| 247 | + return module.getNamespace(); |
284 | 248 | } |
285 | 249 |
|
286 | 250 | /** |
|
0 commit comments