Skip to content

[Babel 8] Refactor register cache - #17229

Merged
nicolo-ribaudo merged 4 commits into
babel:mainfrom
liuxingbaoyu:register-cache
Jan 30, 2026
Merged

nicolo-ribaudo merged 4 commits into
babel:mainfrom
liuxingbaoyu:register-cache

Conversation

@liuxingbaoyu

Copy link
Copy Markdown
Member
Q                       A
Fixed Issues? Fixes #5667, Fixes #9320
Patch: Bug Fix? √
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? √
Documentation PR Link
Any Dependency Changes?
License MIT

This also fixes a hidden bug in Babel 8: process.on("exit", cb) would not be called.

@babel-bot

babel-bot commented Apr 8, 2025 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60734

});

let createdAt = this.db.get("created_at");
// If the cache is older than 30 days, clear it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I compile something every day for 31st day, on the 31st day will it delate all the cache or the data from the 1t day?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will remove all caches.

Comment thread packages/babel-register/package.json Outdated
"clone-deep": "^4.0.1",
"find-cache-dir": "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0",
"find-cache-dir": "condition:BABEL_8_BREAKING ? ^5.0.0 : ^2.0.0 (esm:default)",
"lmdb": "condition:BABEL_8_BREAKING ? ^3.2.6 : (esm:open)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make LMDB an optional dependency? The node-lmdb depends on node-gyp-build, which will kick it when the prebuilt binary bindings does not match the user arch. It is likely to happen when we still support a node version that is not supported by the prebuilt.

This opens all sort of install issues because of the tools/libs required and users may not be familiar with them.

See also parcel-bundler/parcel#8152 for an example.

If we make it an optional dependency, users can still use Babel register regardless of node-gyp-errors, though the cache handling is not as efficient as it would be.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is an annoying problem.
But I worry that making it an optional dependency will make almost no one use it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I investigated and the pre-built packages released by lmdb support node-api, so the version shouldn't be a problem.
But they do not provide some pre-built packages compared to rollup, such as the lack of Windows x86 and arm.

@liuxingbaoyu

Copy link
Copy Markdown
Member Author

I changed it to cacache.
Since it uses a lot of small files, the performance may not be comparable to lmdb.
I added a batch cache logic, hoping the performance will be better.
It would be nice if lmdb could support more platforms, and jest would also benefit.

@JLHwung

JLHwung commented Apr 10, 2025

Copy link
Copy Markdown
Contributor

I changed it to cacache.

Since it uses a lot of small files, the performance may not be comparable to lmdb.

I added a batch cache logic, hoping the performance will be better.

It would be nice if lmdb could support more platforms, and jest would also benefit.

Thought: if the batch cacache is performant, we can use it for the Babel-loader as well.

@liuxingbaoyu

Copy link
Copy Markdown
Member Author

@JLHwung
What do you think about importing webpack internal files directly or do we explicitly depend on a specific version of webpack to use its cache.
https://github.com/webpack/webpack/blob/eda2e284ac7020fb8e8aa5a6c1fd1547a0ad1b08/lib/cache/PackFileCacheStrategy.js
This is incredibly awesome and seems easy to use.

@JLHwung

JLHwung commented Apr 12, 2025

Copy link
Copy Markdown
Contributor

@liuxingbaoyu The webpack cache PR was held back because of #16915 (comment), but we don't have an opportunity to debug why the webpack cache is slower than the current babel-loader file cache.

@liuxingbaoyu liuxingbaoyu added PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release pkg: register labels Apr 14, 2025
@liuxingbaoyu
liuxingbaoyu force-pushed the register-cache branch 2 times, most recently from 7838d13 to fa98620 Compare January 27, 2026 11:55
@pkg-pr-new

pkg-pr-new Bot commented Jan 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 4501a33

@liuxingbaoyu liuxingbaoyu mentioned this pull request Jan 28, 2026
1 task done

exports.init = import("@babel/core").then(initialize);
exports.init = (async function () {
await import("@babel/core").then(initialize).catch(err => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we require(esm) now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot we're using light-jest-runner, let me try!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suddenly realized that we can use mjs directly in the worker, which greatly simplifies the code.

This comment was marked as outdated.

This comment was marked as outdated.

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but are we still blocked on the babel-loader bug?

@liuxingbaoyu

Copy link
Copy Markdown
Member Author

Yes, I am investigating.

@nicolo-ribaudo nicolo-ribaudo added this to the v7.29.0 milestone Jan 29, 2026
@nicolo-ribaudo
nicolo-ribaudo merged commit f7ca0dd into babel:main Jan 30, 2026
54 of 55 checks passed
@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: register PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

babel-register doesn't save modules to cache properly babel-register cache grows infinitely and breaks v8

4 participants