Skip to content

feat: add support for including the babel partial config to cache key#1638

Closed
EvanBacon wants to merge 1 commit intofacebook:mainfrom
EvanBacon:@evanbacon/transformer/add-babel-partial-config
Closed

feat: add support for including the babel partial config to cache key#1638
EvanBacon wants to merge 1 commit intofacebook:mainfrom
EvanBacon:@evanbacon/transformer/add-babel-partial-config

Conversation

@EvanBacon
Copy link
Copy Markdown
Contributor

Summary

Update the Metro Babel transformer to generate cache keys that include the contents of user Babel configuration files, ensuring cache invalidation when Babel configs change. This is similar to what Jest does and it seems to work really well for them.

Changelog: [Fix] Include user-defined babel config in transformer cache key to ensure correctness

Test plan

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 9, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jan 9, 2026
Update the Metro Babel transformer to generate cache keys that include the contents of user Babel configuration files, ensuring cache invalidation when Babel configs change.
@EvanBacon EvanBacon force-pushed the @evanbacon/transformer/add-babel-partial-config branch from de0439b to 4f84860 Compare January 9, 2026 23:48
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Jan 11, 2026

@robhogan has imported this pull request. If you are a Meta employee, you can view this in D90469997.

cwd: options.projectRoot,
root: options.projectRoot,
// Use a dummy filename in the project root to trigger config resolution
filename: options.projectRoot + '/index.js',
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.

This filename doesn't seem to be necessary AFAICT, Babel still finds the project root config without it:

Image

I'm going to omit it before landing unless you found otherwise?

Comment on lines +170 to +178
// babel.config.js or similar project-wide config
if (partialConfig.config != null) {
configFiles.push(partialConfig.config);
}

// .babelrc or .babelrc.js file-relative config
if (partialConfig.babelrc != null) {
configFiles.push(partialConfig.babelrc);
}
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.

It looks like we can use partialConfig.files (which was missing from Flow types) instead of checking these two props here, which also includes extends files, ignore files, etc.

From the docs:

A Set of file paths that were read to build the resulting config, including project wide config files, local config files,
extended config files, ignore files, etc. Useful for implementing watch mode or cache invalidation.

...which seems perfect

@robhogan
Copy link
Copy Markdown
Contributor

robhogan commented Mar 7, 2026

Also, re previous discussion about perf impact - IIRC we both thought this was called for each worker - it's actually only called once by the main thread, so no concerns.

export const getCacheKey = (config: JsTransformerConfig): string => {
export const getCacheKey = (
config: JsTransformerConfig,
projectRoot: string,
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.

Just a heads up that I'm going to make this arg optional (so it's non breaking) and wrap it in an object (for future extension)

@meta-codesync meta-codesync bot closed this in ac169d2 Mar 7, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Mar 7, 2026

@robhogan merged this pull request in ac169d2.

meta-codesync bot pushed a commit to facebook/react-native that referenced this pull request Mar 7, 2026
Summary:
Update the Metro Babel transformer to generate cache keys that include the contents of user Babel configuration files, ensuring cache invalidation when Babel configs change. This is similar to what Jest does and it seems to work really well for them.

Metro changelog: [Fix] Include user-defined babel config in transformer cache key to ensure correctness

Changelog: [Internal]

bypass-github-export-checks

X-link: facebook/metro#1638

Reviewed By: vzaidman

Differential Revision: D90469997

Pulled By: robhogan

fbshipit-source-id: 44d06e7ec873988bcd0dff61ec13318d20f7223b
zoontek pushed a commit to zoontek/react-native that referenced this pull request Mar 9, 2026
Summary:
Update the Metro Babel transformer to generate cache keys that include the contents of user Babel configuration files, ensuring cache invalidation when Babel configs change. This is similar to what Jest does and it seems to work really well for them.

Metro changelog: [Fix] Include user-defined babel config in transformer cache key to ensure correctness

Changelog: [Internal]

bypass-github-export-checks

X-link: facebook/metro#1638

Reviewed By: vzaidman

Differential Revision: D90469997

Pulled By: robhogan

fbshipit-source-id: 44d06e7ec873988bcd0dff61ec13318d20f7223b
robhogan pushed a commit that referenced this pull request Apr 1, 2026
…#1638)

Summary:
Update the Metro Babel transformer to generate cache keys that include the contents of user Babel configuration files, ensuring cache invalidation when Babel configs change. This is similar to what Jest does and it seems to work really well for them.

Metro changelog: [Fix] Include user-defined babel config in transformer cache key to ensure correctness

Changelog: [Internal]

bypass-github-export-checks

Pull Request resolved: #1638

Reviewed By: vzaidman

Differential Revision: D90469997

Pulled By: robhogan

fbshipit-source-id: 44d06e7ec873988bcd0dff61ec13318d20f7223b
@robhogan robhogan mentioned this pull request Apr 9, 2026
robhogan pushed a commit that referenced this pull request Apr 13, 2026
…#1638)

Summary:
Update the Metro Babel transformer to generate cache keys that include the contents of user Babel configuration files, ensuring cache invalidation when Babel configs change. This is similar to what Jest does and it seems to work really well for them.

Metro changelog: [Fix] Include user-defined babel config in transformer cache key to ensure correctness

Changelog: [Internal]

bypass-github-export-checks

Pull Request resolved: #1638

Reviewed By: vzaidman

Differential Revision: D90469997

Pulled By: robhogan

fbshipit-source-id: 44d06e7ec873988bcd0dff61ec13318d20f7223b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants