@@ -47,8 +47,8 @@ const {
47
47
SafeWeakMap,
48
48
String,
49
49
StringPrototypeEndsWith,
50
- StringPrototypeIndexOf,
51
50
StringPrototypeLastIndexOf,
51
+ StringPrototypeIndexOf,
52
52
StringPrototypeMatch,
53
53
StringPrototypeSlice,
54
54
StringPrototypeStartsWith,
@@ -82,8 +82,9 @@ const {
82
82
const { getOptionValue } = require ( 'internal/options' ) ;
83
83
const preserveSymlinks = getOptionValue ( '--preserve-symlinks' ) ;
84
84
const preserveSymlinksMain = getOptionValue ( '--preserve-symlinks-main' ) ;
85
- const manifest = getOptionValue ( '--experimental-policy' ) ?
86
- require ( 'internal/process/policy' ) . manifest :
85
+ // Do not eagerly grab .manifest, it may be in TDZ
86
+ const policy = getOptionValue ( '--experimental-policy' ) ?
87
+ require ( 'internal/process/policy' ) :
87
88
null ;
88
89
const { compileFunction } = internalBinding ( 'contextify' ) ;
89
90
@@ -1043,10 +1044,10 @@ function wrapSafe(filename, content, cjsModuleInstance) {
1043
1044
Module . prototype . _compile = function ( content , filename ) {
1044
1045
let moduleURL ;
1045
1046
let redirects ;
1046
- if ( manifest ) {
1047
+ if ( policy ?. manifest ) {
1047
1048
moduleURL = pathToFileURL ( filename ) ;
1048
- redirects = manifest . getRedirector ( moduleURL ) ;
1049
- manifest . assertIntegrity ( moduleURL , content ) ;
1049
+ redirects = policy . manifest . getDependencyMapper ( moduleURL ) ;
1050
+ policy . manifest . assertIntegrity ( moduleURL , content ) ;
1050
1051
}
1051
1052
1052
1053
maybeCacheSourceMap ( filename , content , this ) ;
@@ -1115,9 +1116,9 @@ Module._extensions['.js'] = function(module, filename) {
1115
1116
Module . _extensions [ '.json' ] = function ( module , filename ) {
1116
1117
const content = fs . readFileSync ( filename , 'utf8' ) ;
1117
1118
1118
- if ( manifest ) {
1119
+ if ( policy ?. manifest ) {
1119
1120
const moduleURL = pathToFileURL ( filename ) ;
1120
- manifest . assertIntegrity ( moduleURL , content ) ;
1121
+ policy . manifest . assertIntegrity ( moduleURL , content ) ;
1121
1122
}
1122
1123
1123
1124
try {
@@ -1131,10 +1132,10 @@ Module._extensions['.json'] = function(module, filename) {
1131
1132
1132
1133
// Native extension for .node
1133
1134
Module . _extensions [ '.node' ] = function ( module , filename ) {
1134
- if ( manifest ) {
1135
+ if ( policy ?. manifest ) {
1135
1136
const content = fs . readFileSync ( filename ) ;
1136
1137
const moduleURL = pathToFileURL ( filename ) ;
1137
- manifest . assertIntegrity ( moduleURL , content ) ;
1138
+ policy . manifest . assertIntegrity ( moduleURL , content ) ;
1138
1139
}
1139
1140
// Be aware this doesn't use `content`
1140
1141
return process . dlopen ( module , path . toNamespacedPath ( filename ) ) ;
0 commit comments