Don't patch Module without preload cache
This commit is contained in:
parent
9687aee2ca
commit
390eab2556
1 changed files with 52 additions and 50 deletions
|
@ -71,11 +71,12 @@ const ModuleInternals = Module as unknown as {
|
||||||
_extensions: unknown;
|
_extensions: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
const previousModuleCompile = ModuleInternals.prototype._compile;
|
if (cachedData || process.env.GENERATE_PRELOAD_CACHE) {
|
||||||
ModuleInternals.prototype._compile = function _compile(
|
const previousModuleCompile = ModuleInternals.prototype._compile;
|
||||||
|
ModuleInternals.prototype._compile = function _compile(
|
||||||
content: string,
|
content: string,
|
||||||
filename: string
|
filename: string
|
||||||
) {
|
) {
|
||||||
if (filename !== srcPath) {
|
if (filename !== srcPath) {
|
||||||
throw new Error(`Unexpected filename: ${filename}`);
|
throw new Error(`Unexpected filename: ${filename}`);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +124,8 @@ ModuleInternals.prototype._compile = function _compile(
|
||||||
Buffer,
|
Buffer,
|
||||||
];
|
];
|
||||||
return compiledWrapper.apply(this.exports, args);
|
return compiledWrapper.apply(this.exports, args);
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-dynamic-require
|
// eslint-disable-next-line import/no-dynamic-require
|
||||||
require(srcPath);
|
require(srcPath);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue