@@ -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' ) ;
@@ -870,9 +870,9 @@ function wrapSafe(filename, content) {
870870 } ) ;
871871 }
872872
873- let compiledWrapper ;
873+ let compiled ;
874874 try {
875- compiledWrapper = compileFunction (
875+ compiled = compileFunction (
876876 content ,
877877 filename ,
878878 0 ,
@@ -890,36 +890,39 @@ function wrapSafe(filename, content) {
890890 ]
891891 ) ;
892892 } catch ( err ) {
893- enrichCJSError ( err ) ;
893+ if ( experimentalModules ) {
894+ enrichCJSError ( err ) ;
895+ }
894896 throw err ;
895897 }
896898
897899 if ( experimentalModules ) {
898900 const { callbackMap } = internalBinding ( 'module_wrap' ) ;
899- callbackMap . set ( compiledWrapper , {
901+ callbackMap . set ( compiled . cacheKey , {
900902 importModuleDynamically : async ( specifier ) => {
901903 const loader = await asyncESM . loaderPromise ;
902904 return loader . import ( specifier , normalizeReferrerURL ( filename ) ) ;
903905 }
904906 } ) ;
905907 }
906908
907- return compiledWrapper ;
909+ return compiled . function ;
908910}
909911
910912// Run the file contents in the correct scope or sandbox. Expose
911913// the correct helper variables (require, module, exports) to
912914// the file.
913915// Returns exception, if any.
914916Module . prototype . _compile = function ( content , filename ) {
917+ let moduleURL ;
918+ let redirects ;
915919 if ( manifest ) {
916- const moduleURL = pathToFileURL ( filename ) ;
920+ moduleURL = pathToFileURL ( filename ) ;
921+ redirects = manifest . getRedirector ( moduleURL ) ;
917922 manifest . assertIntegrity ( moduleURL , content ) ;
918923 }
919924
920- // Strip after manifest integrity check
921- content = stripShebangOrBOM ( content ) ;
922-
925+ maybeCacheSourceMap ( filename , content , this ) ;
923926 const compiledWrapper = wrapSafe ( filename , content ) ;
924927
925928 var inspectorWrapper = null ;
0 commit comments