-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: jsx migration script #869
Conversation
…or extensionless imports
What do you think about creating a new codemod command namespace? So something like....
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 tested this on few apps (login, data-entry and app-management) and it works as expected. I wonder if the docs here are a good place to document the caveats (i.e. failure for some import *...
) and any other things that might need to be checked manually.
Thanks for the review! The That said, it'll definitely be documented in the larger Vite migration documentation 👍 |
# [12.0.0-alpha.11](v12.0.0-alpha.10...v12.0.0-alpha.11) (2024-08-29) ### Features * jsx migration script ([#869](#869)) ([7764f49](7764f49))
🎉 This PR is included in version 12.0.0-alpha.11 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
LIBS-657
The script:
.js
files in/src
for JSX syntax, then renames them to.jsx
.ts
files aren't handled; it's assumed that TS enforces using.tsx
extensions for files with JSX syntax... although it would be easy to addentryPoints
values ind2.config.js
, if neededI started this trying to use regexes to detect JSX syntax and import statements, but it ended up being best to use an AST parser. It's a bit slower, but still only took a few seconds for the thousands of JS files in the capture app, for example
Looking for input:
jsx-migration
?Recommended testing
You can test this out in an app (or more) of your choice -- here are a few that I've tried:
skipUpdatingImportsWithoutExtension
flag. Somewhere there's a file that has two imports from the same file (separated to group the objects conceptually) -- this is a test of the import replacement logicSteps:
@dhis2/cli-app-scripts
alpha & deduplicate app-runtime:yarn add @dhis2/cli-app-scripts@alpha && npx yarn-deduplicate yarn.lock && yarn
3. Watch out for any other resolutions on relevant libs: cli-app-scripts, app-runtime
package.json
andyarn.lock
before running the script. Then, if I want to undo the results of the script, I can click the "Discard All Changes" undo arrow in the Source Control tab on the Unstaged Changes section and go back to the beginning (see video below)bin
to run the local version of the script, e.g.../app-platform/cli/bin/d2-app-scripts jsx-migration
7.
--debug
to get detailed logs8.
--globString "..."
to test out a custom glob (the default issrc/**/*.js
)9.
--skipUpdatingImportsWithoutExtension
-- maybe self-explanatory (I figure some repos will want to leave the imports without file extensions. Functionally, this works fine with Vite. In some repos though, this creates linting complaints, but I'm sure the linting rules can be updated)yarn start
to make sure the app worksVSCode Source control:
source-control.mov