| 1 | /** |
| 2 | * This file wraps the implementation of register so all modules `require()`-ed |
| 3 | * internally within register are stored in a separate module cache. |
| 4 | * This prevents un-transformed modules being stored in global module cache, |
| 5 | * and allows register to transform these modules if they are loaded externally. |
| 6 | */ |
| 7 | |
| 8 | // TODO: Remove this file in Babel 8 |
| 9 | |
| 10 | const Module = require("module"); |
| 11 | |
| 12 | const globalModuleCache = Module._cache; |
| 13 | const internalModuleCache = Object.create(null); |
| 14 | |
| 15 | Module._cache = internalModuleCache; |
| 16 | const node = require("./node"); |
| 17 | |
| 18 | // NOTE: This Module._cache set is intercepted by the beforeEach hook in |
| 19 | // packages/babel-register/test/index.js to install dependencies mocks. |
| 20 | Module._cache = globalModuleCache; |
| 21 | |
| 22 | // Add source-map-support to global cache as it's stateful |
| 23 | const smsPath = require.resolve("source-map-support"); |
| 24 | globalModuleCache[smsPath] = internalModuleCache[smsPath]; |
| 25 | |
| 26 | const register = node.default; |
| 27 | register(); |
| 28 | |
| 29 | module.exports = node; |