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 |
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