Preparation before removing babel plugins - adding import extensions and displayName manually#2580
Open
joyenjoyer wants to merge 3 commits into
Open
Preparation before removing babel plugins - adding import extensions and displayName manually#2580joyenjoyer wants to merge 3 commits into
joyenjoyer wants to merge 3 commits into
Conversation
Appends .js/index.js to relative imports across the source so the output resolves under native ESM.
Preserves component identity without Babel's add-displayname plugin.
The explicit .js relative-import extensions added for native ESM must still resolve when webpack bundles the .ts/.tsx source directly (Cypress component tests and the docs app). Add resolve.extensionAlias mapping .js->.ts/.tsx to the Cypress and ui-webpack-config configs so the source prep does not break those builds. No transpiler change.
|
Visual regression report✅ No changes.
Baselines come from the |
matyasf
reviewed
Jun 9, 2026
Comment on lines
+81
to
+88
| // Source carries explicit `.js` extensions on relative imports (added for | ||
| // native-ESM library output). When bundling `.ts`/`.tsx` source directly, | ||
| // map a `.js` specifier back to its TypeScript source. | ||
| extensionAlias: { | ||
| '.js': ['.ts', '.tsx', '.js'], | ||
| '.jsx': ['.tsx', '.jsx'], | ||
| '.mjs': ['.mts', '.mjs'] | ||
| }, |
Collaborator
There was a problem hiding this comment.
Will this also be need to be set for end users?
Contributor
Author
There was a problem hiding this comment.
We only need this because Cypress and the docs build straight from our .ts source, so the new .js import extensions have to be pointed back at the real .ts/.tsx files. Consumers never hit this since they use the built es/ and lib/ output where those .js files actually exist.
balzss
reviewed
Jun 10, 2026
balzss
left a comment
Contributor
There was a problem hiding this comment.
overall looks and works well, great work! some minor comments:
- you added displaynames for the docs package components but didn't add the extensions for the imports there. is that intentional?
- you added explicit type resolution for the cypress config but not for vitest. i'm not sure it's bad if it's implicit but worth thinking about
- the commit msg scope is a bit misleading. they are
build(swc)but swc migration was not done in those commits
Contributor
Author
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR prepares the removal of Babel and Babel plugins. It writes two things into the source that Babel plugins inject today: explicit relative-import extensions and static
displayNames. It also adds minimal webpack config so our own toolchains resolve the new specifiers.No transpiler change. Babel still runs, with the same plugins. The plugins are idempotent. They skip a specifier already ending in
.js. They skip a class that already has adisplayName. So the compiledes/andlib/output stays semantically identical tomaster.This keeps
masterreleasable. It also makes the later SWC safe.This is PR1 of a 3-PR stack:
babel-loader→swc-loaderin the Cypress + docs webpack builds. Library build still Babel. Nothing published changes.What changed (3 commits)
add explicit import extensions to relative specifiers— appends.js(or/index.jsfor directory imports) to relativeimport/export ... fromspecifiers. Reproducesbabel-plugin-add-import-extension. Relative specifiers only. Bare/package and type-only imports are untouched.add static displayName to component classes— addsstatic displayName = '<ClassName>'to React class components that lack one. Reproducesbabel-plugin-add-displayname-for-react. It is idempotent: it skips classes that already have one, and any class without arendermethod. This includes the__docs__app. Its Babel config (packages/__docs__/babel.config.js) uses@instructure/ui-babel-preset, which runsadd-displayname-for-reactunconditionally. So Babel was already injectingdisplayNameinto the docs' class components at build time. Writing it into the source keeps that behavior identical once Babel is removed in PR3.resolve .js specifiers to TypeScript source in webpack— addsresolve.extensionAlias(.js→.ts/.tsx) to the Cypress config and the sharedui-webpack-config. This lets webpack builds that bundle the.ts/.tsxsource directly (Cypress, docs) resolve the new.jsspecifiers. It is a consequence of the source change, so it lives here.What is intentionally NOT in this PR
ui-icons/src/generated,ui-themestokens). Those are generated/gitignored, so the source edits can't cover them. Generator updates will be in a later PR.Compiled-output deltas vs
masterAll behavior-preserving:
es/) — cosmetic codegen only. Semantically identical. The possible differences are:"./useStyle.js"→'./useStyle.js').lib/) — the added.jsspecifiers, plus therequirebinding names Babel derives from them. Behavior-preserving. They disappear once PR3 drops thelib/build.How to test?
esfolders, compare it to latest mastermasterabove), it is only an issue if the two files are not semantically identical