@@ -6,9 +6,6 @@ const { decorateErrorStack } = require('internal/util');
6
6
const assert = require ( 'assert' ) ;
7
7
const resolvedPromise = SafePromise . resolve ( ) ;
8
8
9
- const enableDebug = ( process . env . NODE_DEBUG || '' ) . match ( / \b e s m \b / ) ||
10
- process . features . debug ;
11
-
12
9
/* A ModuleJob tracks the loading of a single Module, and the ModuleJobs of
13
10
* its dependencies, over time. */
14
11
class ModuleJob {
@@ -27,25 +24,24 @@ class ModuleJob {
27
24
28
25
// Wait for the ModuleWrap instance being linked with all dependencies.
29
26
const link = async ( ) => {
30
- const dependencyJobs = [ ] ;
31
27
( { module : this . module ,
32
28
reflect : this . reflect } = await this . modulePromise ) ;
33
29
if ( inspectBrk ) {
34
30
const initWrapper = process . binding ( 'inspector' ) . callAndPauseOnStart ;
35
31
initWrapper ( this . module . instantiate , this . module ) ;
36
32
}
37
33
assert ( this . module instanceof ModuleWrap ) ;
38
- this . module . link ( async ( dependencySpecifier ) => {
39
- const dependencyJobPromise =
40
- this . loader . getModuleJob ( dependencySpecifier , url ) ;
41
- dependencyJobs . push ( dependencyJobPromise ) ;
42
- const dependencyJob = await dependencyJobPromise ;
43
- return ( await dependencyJob . modulePromise ) . module ;
34
+
35
+ const dependencyJobs = [ ] ;
36
+ const promises = this . module . link ( async ( specifier ) => {
37
+ const jobPromise = this . loader . getModuleJob ( specifier , url ) ;
38
+ dependencyJobs . push ( jobPromise ) ;
39
+ return ( await ( await jobPromise ) . modulePromise ) . module ;
44
40
} ) ;
45
- if ( enableDebug ) {
46
- // Make sure all dependencies are entered into the list synchronously.
47
- Object . freeze ( dependencyJobs ) ;
48
- }
41
+
42
+ if ( promises !== undefined )
43
+ await SafePromise . all ( promises ) ;
44
+
49
45
return SafePromise . all ( dependencyJobs ) ;
50
46
} ;
51
47
// Promise for the list of all dependencyJobs.
0 commit comments