@@ -51,7 +51,7 @@ const {
5151 makeRequireFunction,
5252 normalizeReferrerURL,
5353 stripBOM,
54- stripShebangOrBOM ,
54+ loadNativeModule
5555} = require ( 'internal/modules/cjs/helpers' ) ;
5656const { getOptionValue } = require ( 'internal/options' ) ;
5757const enableSourceMaps = getOptionValue ( '--enable-source-maps' ) ;
@@ -961,9 +961,9 @@ function wrapSafe(filename, content) {
961961 } ) ;
962962 }
963963
964- let compiledWrapper ;
964+ let compiled ;
965965 try {
966- compiledWrapper = compileFunction (
966+ compiled = compileFunction (
967967 content ,
968968 filename ,
969969 0 ,
@@ -981,36 +981,39 @@ function wrapSafe(filename, content) {
981981 ]
982982 ) ;
983983 } catch ( err ) {
984- enrichCJSError ( err ) ;
984+ if ( experimentalModules ) {
985+ enrichCJSError ( err ) ;
986+ }
985987 throw err ;
986988 }
987989
988990 if ( experimentalModules ) {
989991 const { callbackMap } = internalBinding ( 'module_wrap' ) ;
990- callbackMap . set ( compiledWrapper , {
992+ callbackMap . set ( compiled . cacheKey , {
991993 importModuleDynamically : async ( specifier ) => {
992994 const loader = await asyncESM . loaderPromise ;
993995 return loader . import ( specifier , normalizeReferrerURL ( filename ) ) ;
994996 }
995997 } ) ;
996998 }
997999
998- return compiledWrapper ;
1000+ return compiled . function ;
9991001}
10001002
10011003// Run the file contents in the correct scope or sandbox. Expose
10021004// the correct helper variables (require, module, exports) to
10031005// the file.
10041006// Returns exception, if any.
10051007Module . prototype . _compile = function ( content , filename ) {
1008+ let moduleURL ;
1009+ let redirects ;
10061010 if ( manifest ) {
1007- const moduleURL = pathToFileURL ( filename ) ;
1011+ moduleURL = pathToFileURL ( filename ) ;
1012+ redirects = manifest . getRedirector ( moduleURL ) ;
10081013 manifest . assertIntegrity ( moduleURL , content ) ;
10091014 }
10101015
1011- // Strip after manifest integrity check
1012- content = stripShebangOrBOM ( content ) ;
1013-
1016+ maybeCacheSourceMap ( filename , content , this ) ;
10141017 const compiledWrapper = wrapSafe ( filename , content ) ;
10151018
10161019 var inspectorWrapper = null ;
0 commit comments