Skip to content
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

Add codemod to replace individual package imports with monopackage imports #6471

Merged
merged 4 commits into from
Jun 4, 2024

Conversation

reidbarber
Copy link
Member

@reidbarber reidbarber commented May 30, 2024

Replaces individual package imports with monopackage imports, where possible.

Works for:

  • @react-spectrum/* -> @adobe/react-spectrum
  • @react-aria/* -> react-aria
  • @react-stately/* -> react-stately

By default this will apply to all the above packages, or optionally you can specify which packages to apply this to by passing a comma-separated list to the packages option: --packages=react-aria,react-stately,react-spectrum.

Run this from a directory where the relevant packages are installed in node_modules so it knows which monopackage exports are available to use (since exports may vary by version).

  1. Install jscodeshift: npm i -g jscodeshift
  2. Run: jscodeshift -t /path/to/use-monopackages.ts src/

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented May 30, 2024

@rspbot
Copy link

rspbot commented May 30, 2024

@adobe adobe deleted a comment from rspbot May 30, 2024
Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know how you've found this to run on a project with hundreds of files, but you could move a lot of this outside the transform function and only perform once (discovery of all the monopackage exports)

@reidbarber
Copy link
Member Author

@snowystinger good idea, I'll try to handle that in a follow-up, as well as integrating this: https://github.com/facebook/jscodeshift/blob/main/recipes/retain-first-comment.md

@rspbot
Copy link

rspbot commented Jun 4, 2024

@rspbot
Copy link

rspbot commented Jun 4, 2024

## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@reidbarber reidbarber merged commit 7da3d38 into main Jun 4, 2024
26 checks passed
@reidbarber reidbarber deleted the codemod-use-monopackage branch June 4, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants