[babel 8] Move @babel/register transform to a separate worker (#14025)

This commit is contained in:
Nicolò Ribaudo
2021-12-29 16:33:12 +01:00
committed by GitHub
parent d1cabf6bc8
commit e77e3de402
31 changed files with 791 additions and 381 deletions

View File

@@ -0,0 +1,29 @@
/**
* 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.
*/
// TODO: Remove this file in Babel 8
const Module = require("module");
const globalModuleCache = Module._cache;
const internalModuleCache = Object.create(null);
Module._cache = internalModuleCache;
const node = require("./node");
// NOTE: This Module._cache set is intercepted by the beforeEach hook in
// packages/babel-register/test/index.js to install dependencies mocks.
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];
const register = node.default;
register();
module.exports = node;