Preparation before removing babel plugins - adding import extensions and displayName manually#2580
Conversation
|
Visual regression report✅ No changes.
Baselines come from the |
| // 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'] | ||
| }, |
There was a problem hiding this comment.
Will this also be need to be set for end users?
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
left a comment
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
|
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.
5709b9e to
83835f1
Compare
matyasf
left a comment
There was a problem hiding this comment.
looks good, I've checked it with the new diff tool
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