-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Bug Report
Current Behavior
For scripts that don't exit the event loop (e.g. an express server), modules that are loaded outside of the original script don't get cached.
Input Code
Minimal repro here: https://github.com/jbasrai/babel-register-cache
yarnnode index.js- Ctrl-C to end process
Expected behavior/code
Expected world.js to be cached, but inspecting the cache reveals that it isn't.
Babel Configuration (.babelrc, package.json, cli command)
module.exports = function (api) {
api.cache.forever()
return {
presets: [ '@babel/preset-env' ]
}
}Environment
- Babel version(s): core v7.2.2, register v7.0.0
- Node/npm version: Node v8.12, npm v5.8
- OS: OSX 10.12.6
- Monorepo: no
- How you are using Babel:
register
Possible Solution
The process.on('exit') listener is not being used correctly. The docs say that it is only called when process.exit() is called explicitly OR when Node's event loop no longer has work to perform. In the above case, none of these conditions are met, and so a required module is never cached.
Instead, I think a more comprehensive exit handler should be used to save the cache.