@@ -51,7 +51,7 @@ const {
51
51
makeRequireFunction,
52
52
normalizeReferrerURL,
53
53
stripBOM,
54
- stripShebangOrBOM ,
54
+ loadNativeModule
55
55
} = require ( 'internal/modules/cjs/helpers' ) ;
56
56
const { getOptionValue } = require ( 'internal/options' ) ;
57
57
const enableSourceMaps = getOptionValue ( '--enable-source-maps' ) ;
@@ -961,9 +961,9 @@ function wrapSafe(filename, content) {
961
961
} ) ;
962
962
}
963
963
964
- let compiledWrapper ;
964
+ let compiled ;
965
965
try {
966
- compiledWrapper = compileFunction (
966
+ compiled = compileFunction (
967
967
content ,
968
968
filename ,
969
969
0 ,
@@ -981,36 +981,39 @@ function wrapSafe(filename, content) {
981
981
]
982
982
) ;
983
983
} catch ( err ) {
984
- enrichCJSError ( err ) ;
984
+ if ( experimentalModules ) {
985
+ enrichCJSError ( err ) ;
986
+ }
985
987
throw err ;
986
988
}
987
989
988
990
if ( experimentalModules ) {
989
991
const { callbackMap } = internalBinding ( 'module_wrap' ) ;
990
- callbackMap . set ( compiledWrapper , {
992
+ callbackMap . set ( compiled . cacheKey , {
991
993
importModuleDynamically : async ( specifier ) => {
992
994
const loader = await asyncESM . loaderPromise ;
993
995
return loader . import ( specifier , normalizeReferrerURL ( filename ) ) ;
994
996
}
995
997
} ) ;
996
998
}
997
999
998
- return compiledWrapper ;
1000
+ return compiled . function ;
999
1001
}
1000
1002
1001
1003
// Run the file contents in the correct scope or sandbox. Expose
1002
1004
// the correct helper variables (require, module, exports) to
1003
1005
// the file.
1004
1006
// Returns exception, if any.
1005
1007
Module . prototype . _compile = function ( content , filename ) {
1008
+ let moduleURL ;
1009
+ let redirects ;
1006
1010
if ( manifest ) {
1007
- const moduleURL = pathToFileURL ( filename ) ;
1011
+ moduleURL = pathToFileURL ( filename ) ;
1012
+ redirects = manifest . getRedirector ( moduleURL ) ;
1008
1013
manifest . assertIntegrity ( moduleURL , content ) ;
1009
1014
}
1010
1015
1011
- // Strip after manifest integrity check
1012
- content = stripShebangOrBOM ( content ) ;
1013
-
1016
+ maybeCacheSourceMap ( filename , content , this ) ;
1014
1017
const compiledWrapper = wrapSafe ( filename , content ) ;
1015
1018
1016
1019
var inspectorWrapper = null ;
0 commit comments