File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -115,8 +115,25 @@ function makeLazyForwardModule(pkg) {
115
115
: `require(${ S ( require . resolve ( pkg ) ) } )` ;
116
116
117
117
const moduleContents = require ( pkg ) ;
118
- let source = `'use strict';\nlet _cache;\n` ;
119
- source += `function orig() {\n_cache = ${ realRequire } ; orig = () => _cache; return _cache;\n}\n` ;
118
+ let source = `'use strict';\nlet _cache, orig;\n` ;
119
+ source += `function _realModule() {\n_cache = ${ realRequire } ; orig = () => _cache; return _cache;\n}\n` ;
120
+
121
+ if ( process . env . MONGOSH_DEBUG_WEBPACK_FORWARDING_MODULES ) {
122
+ source += `const _startupSnapshot = __non_webpack_require__("v8").startupSnapshot;
123
+ function _throwModule() {\nthrow new Error('cannot load package "' + ${ S (
124
+ pkg
125
+ ) } + '" while building snapshot');\n}
126
+ if (_startupSnapshot.isBuildingSnapshot()) {
127
+ orig = _throwModule;
128
+ _startupSnapshot.addDeserializeCallback(() => orig = _realModule);
129
+ } else {
130
+ orig = _realModule;
131
+ }
132
+ ` ;
133
+ } else {
134
+ source += `orig = _realModule;\n` ;
135
+ }
136
+
120
137
if ( typeof moduleContents === 'function' ) {
121
138
source += `module.exports = function(...args) { return orig().apply(this, args); };\n` ;
122
139
} else {
You can’t perform that action at this time.
0 commit comments