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

feat: intro @zendeskgarden/codemods + add v8-v9 migration transforms #1928

Closed
wants to merge 6 commits into from

Conversation

ze-flo
Copy link
Contributor

@ze-flo ze-flo commented Sep 25, 2024

Description

🚀 Introducing...

   __ _  __ _ _ __ __| | ___ _ __     ___ ___   __| | ___ _ __ ___   ___   __| |___
  / _` |/ _` | '__/ _` |/ _ \ '_ \   / __/ _ \ / _` |/ _ \ '_ ` _ \ / _ \ / _` / __|
 | (_| | (_| | | | (_| |  __/ | | | | (_| (_) | (_| |  __/ | | | | | (_) | (_| \__ \
  \__, |\__,_|_|  \__,_|\___|_| |_|  \___\___/ \__,_|\___|_| |_| |_|\___/ \__,_|___/
  |___/

The @zendeskgarden/codemods package offers a variety of codemods designed to automate
code transformations in Garden-based projects.

Detail

  • Introduces the new package @zendeskgarden/codemods
  • Adds v8-to-v9 codemods. Each codemod is aligned with the v9 migration guide
  • Tests transforms in various scenarios
  • Adds detailed docs
  • Links available codemod to v9 migration guide when available

Checklist

  • 👌 design updates will be Garden Designer approved (add the designer as a reviewer)
  • 🌐 demo is up-to-date (npm start)
  • ⬅️ renders as expected with reversed (RTL) direction
  • ⚫ renders as expected in dark mode
  • 🤘 renders as expected with Bedrock CSS (?bedrock)
  • 💂‍♂️ includes new unit tests. Maintain existing coverage (always >= 96%)
  • ♿ tested for WCAG 2.1 AA accessibility compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

@@ -102,6 +105,10 @@ consider additional positioning prop support on a case-by-case basis.
- same breaking changes as `ColorSwatch`.
- `popperModifiers` prop (see [note](#breaking-changes))

<!-- prettier-ignore -->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prettier doesn't support Github-flavored Markdown alerts. 😢

commonConfig[0].output[0],
{
...commonConfig[0].output[1],
entryFileNames: '[name].mjs'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's 2024 and the CommonJS / ESM struggles are still real! 😡

Currently, jscodeshift doesn't support ESM, and the latest version of libraries like Chalk and @inquire/prompts dropped CommonJS support.

After trying several approaches, I’ve found a workable solution:

  • Setting "type": "module" did not resolve the issues with jscodeshift.
  • Directing the "module" to the CommonJS build failed with Chalk and other ESM-only libraries.

Since this package requires Node.js version 18 or higher, we can use the .mjs extension to maintain compatibility and avoid encountering ERR_REQUIRE_ESM errors when executing the script.

I'm open to suggestions for reusing the common Rollup config instead.

@@ -0,0 +1,97 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would not typically recommend snapshot testing; however, among all the available unit testing methods, defineSnapshotTest appears to be the easiest to set up while still ensuring that the test files remain reasonably readable.

return root.find(j.ImportDeclaration, {
source: {
// ensure deep equal check
value: (val: string) => val === importSource
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very important. The object literal form (ex: { source: { value: importSource } }) appears to use String.prototype.includes, which has led to surprises with react-dropdowns and react-dropdown.next.

Comment on lines +10 to +11
// @ts-expect-error - TS7016: Could not find a declaration file for module
import { defineSnapshotTest } from 'jscodeshift/dist/testUtils';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not types are available. 😞

Would it be better to add declare module jscodeshift/dist/testUtils {} to a .d.ts file?

importSource: '@zendeskgarden/react-notifications',
subComponents: ['Close', 'Paragraph', 'Title'],
mainComponent: 'Well',
bannedComponents: ['Well', 'Notification']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alert, Well, and Notifications share the same subcomponent names. To avoid modifying JSX nodes incorrectly, it's preferable to skip files that import a combination of these components.

@coveralls
Copy link

Coverage Status

coverage: 95.08% (-0.8%) from 95.923%
when pulling 98288d5 on ze-flo/garden-codemods
into ddb2d0c on main.

@ze-flo
Copy link
Contributor Author

ze-flo commented Nov 15, 2024

Garden Codemods was offered internally as an early access experimental tool. Further considerations need to be addressed before releasing it as an open-source package. Closing for now.

@ze-flo ze-flo closed this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants