fix: babel-register transform internal dependencies (#12665)
Closes #11964, #12662.
This commit is contained in:
21
packages/babel-register/src/nodeWrapper.js
Normal file
21
packages/babel-register/src/nodeWrapper.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* This file wraps the implementation of register so all modules `require()`-ed
|
||||
* internally within register are stored in a separate module cache.
|
||||
* This prevents un-transformed modules being stored in global module cache,
|
||||
* and allows register to transform these modules if they are loaded externally.
|
||||
*/
|
||||
|
||||
const Module = require("module");
|
||||
|
||||
const globalModuleCache = Module._cache;
|
||||
const internalModuleCache = Object.create(null);
|
||||
|
||||
Module._cache = internalModuleCache;
|
||||
const node = require("./node");
|
||||
Module._cache = globalModuleCache;
|
||||
|
||||
// Add source-map-support to global cache as it's stateful
|
||||
const smsPath = require.resolve("source-map-support");
|
||||
globalModuleCache[smsPath] = internalModuleCache[smsPath];
|
||||
|
||||
module.exports = node;
|
||||
Reference in New Issue
Block a user