Skip to content

fix(register): skip hook for ignored files#17928

Open
JLHwung wants to merge 3 commits intobabel:mainfrom
JLHwung:skip-hook-for-ignored-files
Open

fix(register): skip hook for ignored files#17928
JLHwung wants to merge 3 commits intobabel:mainfrom
JLHwung:skip-hook-for-ignored-files

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented Apr 7, 2026

Q                       A
Fixed Issues? Fixes #17903
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In this PR we skip the babel-register hook for ignored files in programmatic options. Previously the hook was still registered for ignored files and therefore an ignored .ts file may throw syntax error because the original JS loader, where the builtin TS type stripping happens, was skipped as pirates has no knowledge that Babel does not handle this ignored file.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: register labels Apr 7, 2026
return await store({ code, map });
}

async function isFileIgnored(filename: string) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This helper can potentially be reused by the babel-cli: See #17878

Do you think we should make it an API of @babel/core?

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Apr 7, 2026

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 7, 2026

Open in StackBlitz

commit: 6167bbd

@liuxingbaoyu
Copy link
Copy Markdown
Member

https://babeljs.io/docs/babel-register#specifying-options
@babel/register supports ignore and only options, and supporting them may be sufficient.

@JLHwung
Copy link
Copy Markdown
Contributor Author

JLHwung commented Apr 8, 2026

https://babeljs.io/docs/babel-register#specifying-options @babel/register supports ignore and only options, and supporting them may be sufficient.

Thanks, as is said in the docs, @babel/register does not support ignore and only in config files, I will simplify the implementation.

@JLHwung
Copy link
Copy Markdown
Contributor Author

JLHwung commented Apr 8, 2026

https://babeljs.io/docs/babel-register#specifying-options @babel/register supports ignore and only options, and supporting them may be sufficient.

I looked into this issue a bit, if we want to completely remove the loadPartialConfig call, we will have to somehow duplicate the pattern matching logic of @babel/core to @babel/register, such as packages/babel-core/src/config/pattern-to-regex.ts and the matchesPatterns in packages/babel-core/src/config/config-chain.ts.

If performance is your concern, I think what we can do is to disable configFile and babelrc in the first loadPartialConfig call so the core only checks if the file is deemed ignored via programmatic options. This will reduce the overhead of looking for .babelrc or babel.config.

@liuxingbaoyu
Copy link
Copy Markdown
Member

It appears that we don't support patterns in the documentation, but only regular expressions and functions.

@JLHwung
Copy link
Copy Markdown
Contributor Author

JLHwung commented Apr 21, 2026

It appears that we don't support patterns in the documentation, but only regular expressions and functions.

I believe this is a doc issue. In somewhere we mentioned that it supports regex / glob, elsewhere regex / function. I have updated the register docs to reflect on the current implementation: babel/website#3190

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@babel/register interfers with Node built-in type stripping for ignored files

3 participants