@wise/wds-codemods 0.0.1-experimental-731cdc7 โ†’ 0.0.1-experimental-cbae00f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/.changeset/better-impalas-drop.md +5 -0
  2. package/.changeset/config.json +13 -0
  3. package/.changeset/quick-mails-joke.md +128 -0
  4. package/.github/CODEOWNERS +1 -0
  5. package/.github/actions/bootstrap/action.yml +49 -0
  6. package/.github/actions/commitlint/action.yml +27 -0
  7. package/.github/actions/test/action.yml +23 -0
  8. package/.github/workflows/cd-cd.yml +127 -0
  9. package/.github/workflows/renovate.yml +16 -0
  10. package/.husky/commit-msg +1 -0
  11. package/.husky/pre-commit +1 -0
  12. package/.nvmrc +1 -0
  13. package/.prettierignore +1 -0
  14. package/.prettierrc.js +5 -0
  15. package/DEVELOPER.md +783 -0
  16. package/babel.config.js +28 -0
  17. package/commitlint.config.js +3 -0
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +135 -133
  20. package/dist/index.js.map +1 -1
  21. package/dist/transforms/button.d.ts +16 -0
  22. package/dist/transforms/button.js +566 -493
  23. package/dist/transforms/button.js.map +1 -1
  24. package/eslint.config.js +15 -0
  25. package/jest.config.js +9 -0
  26. package/mkdocs.yml +4 -0
  27. package/package.json +14 -19
  28. package/renovate.json +9 -0
  29. package/scripts/build.sh +10 -0
  30. package/src/__tests__/runCodemod.test.ts +96 -0
  31. package/src/index.ts +4 -0
  32. package/src/runCodemod.ts +88 -0
  33. package/src/transforms/button/__tests__/button.test.tsx +153 -0
  34. package/src/transforms/button/button.ts +418 -0
  35. package/src/transforms/helpers/__tests__/createTestTransform.test.ts +27 -0
  36. package/src/transforms/helpers/__tests__/hasImport.test.ts +52 -0
  37. package/src/transforms/helpers/__tests__/iconUtils.test.ts +207 -0
  38. package/src/transforms/helpers/__tests__/jsxElementUtils.test.ts +130 -0
  39. package/src/transforms/helpers/__tests__/jsxReportingUtils.test.ts +265 -0
  40. package/src/transforms/helpers/createTestTransform.ts +18 -0
  41. package/src/transforms/helpers/hasImport.ts +60 -0
  42. package/src/transforms/helpers/iconUtils.ts +87 -0
  43. package/src/transforms/helpers/index.ts +5 -0
  44. package/src/transforms/helpers/jsxElementUtils.ts +67 -0
  45. package/src/transforms/helpers/jsxReportingUtils.ts +224 -0
  46. package/src/utils/__tests__/getOptions.test.ts +170 -0
  47. package/src/utils/__tests__/handleError.test.ts +18 -0
  48. package/src/utils/__tests__/loadTransformModules.test.ts +51 -0
  49. package/src/utils/__tests__/reportManualReview.test.ts +42 -0
  50. package/src/utils/getOptions.ts +63 -0
  51. package/src/utils/handleError.ts +6 -0
  52. package/src/utils/index.ts +4 -0
  53. package/src/utils/loadTransformModules.ts +28 -0
  54. package/src/utils/reportManualReview.ts +17 -0
  55. package/test-button.tsx +230 -0
  56. package/test-file.js +2 -0
  57. package/tsconfig.json +14 -0
  58. package/tsup.config.js +13 -0
  59. package/dist/reportManualReview-DQ00-OKx.js +0 -50
  60. package/dist/reportManualReview-DQ00-OKx.js.map +0 -1
@@ -0,0 +1,5 @@
1
+ ---
2
+ '@wise/wds-codemods': patch
3
+ ---
4
+
5
+ NPM release setup
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
3
+ "changelog": ["@changesets/changelog-github", { "repo": "transferwise/wds-codemods" }],
4
+ "commit": false,
5
+ "fixed": [],
6
+ "linked": [],
7
+ "access": "public",
8
+ "baseBranch": "main",
9
+ "updateInternalDependencies": "minor",
10
+ "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
11
+ "onlyUpdatePeerDependentsWhenOutOfRange": true
12
+ }
13
+ }
@@ -0,0 +1,128 @@
1
+ ---
2
+ '@wise/wds-codemods': major
3
+ ---
4
+
5
+ # ๐ŸŽ‰ @wise/wds-codemods@1.0.0 - Initial Release
6
+
7
+ Welcome to the first major release of WDS Codemods! This comprehensive toolkit provides automated migration support for Wise Design System components, making it easy to upgrade your codebase to the latest component versions.
8
+
9
+ ## โœจ Core Features
10
+
11
+ ### ๐Ÿ”ง Transform Engine
12
+
13
+ - **Interactive CLI**: Choose transforms and configure options with an intuitive command-line interface
14
+ - **Dry Run Mode**: Preview changes before applying them to your codebase
15
+ - **Monorepo Support**: Built-in support for monorepo package structures with automatic package detection
16
+ - **Smart Package Detection**: Automatically detects package versions in both `package.json` dependencies and `node_modules`
17
+ - **Comprehensive Reporting**: Generates detailed reports for manual review items that require developer attention
18
+
19
+ ### ๐ŸŽฏ Button Component Transform
20
+
21
+ - **ActionButton Migration**: Automatically converts deprecated `ActionButton` components to modern `Button` with `v2` prop
22
+ - **Legacy Prop Migration**: Transforms legacy props (`priority`, `size`, `type`, `htmlType`, `sentiment`) to new API
23
+ - **Enum Value Conversion**: Converts enum values (e.g., `Priority.PRIMARY`, `Size.LARGE`) to string literals
24
+ - **Icon Integration**: Intelligently processes icon children and converts them to `addonStart`/`addonEnd` props
25
+ - **Link Button Handling**: Properly migrates `as="a"` usage with automatic `href` management
26
+ - **Smart Size Mapping**: Maps legacy size values to new design tokens (`xs`, `sm`, `md`, `lg`, `xl`)
27
+
28
+ ### ๐Ÿ›ก๏ธ Robust Validation & Safety
29
+
30
+ - **Package Version Validation**: Ensures transforms only run when target packages are present and meet version requirements
31
+ - **TypeScript & JSX Support**: Full support for TypeScript and JSX syntax parsing
32
+ - **Expression Analysis**: Handles complex expressions, conditionals, and dynamic values with appropriate fallbacks
33
+ - **Gitignore Integration**: Respects `.gitignore` patterns to avoid processing unnecessary files
34
+ - **Caching System**: Intelligent caching for package version checks to improve performance
35
+
36
+ ### ๐Ÿ“Š Advanced Reporting
37
+
38
+ - **Manual Review Detection**: Identifies code patterns that require human attention
39
+ - **Line-by-Line Reporting**: Precise location reporting for manual review items
40
+ - **Issue Classification**: Categorizes issues by type (deprecated props, unsupported values, ambiguous expressions)
41
+ - **Batch Processing**: Handles multiple files and provides comprehensive summary reports
42
+
43
+ ## ๐Ÿš€ Usage Examples
44
+
45
+ ### Basic Usage
46
+
47
+ ```bash
48
+ npx @wise/wds-codemods
49
+ ```
50
+
51
+ ### Advanced Usage
52
+
53
+ ```bash
54
+ # Run specific transform on a directory
55
+ npx @wise/wds-codemods button ./src --dry
56
+
57
+ # Target monorepo packages
58
+ npx @wise/wds-codemods button ./packages --monorepo
59
+
60
+ # Custom ignore patterns
61
+ npx @wise/wds-codemods button ./src --ignore-pattern "**/*.test.tsx,**/stories/**"
62
+ ```
63
+
64
+ ## ๐Ÿ“‹ Supported Transforms
65
+
66
+ ### Button Transform (`button`)
67
+
68
+ Migrates Button and ActionButton components from `@transferwise/components` v46.5.0+
69
+
70
+ **Transformations include:**
71
+
72
+ - โœ… `ActionButton` โ†’ `Button` with `v2` prop
73
+ - โœ… Legacy prop migrations (`priority`, `size`, `type`, etc.)
74
+ - โœ… Enum value conversions
75
+ - โœ… Icon children processing
76
+ - โœ… Link button handling (`as="a"` โ†’ proper href management)
77
+ - โœ… Sentiment mapping (`type="negative"` โ†’ `sentiment="negative"`)
78
+
79
+ ## ๐Ÿ—๏ธ Architecture Highlights
80
+
81
+ ### Modular Design
82
+
83
+ - **Transform System**: Extensible architecture for adding new component transforms
84
+ - **Helper Utilities**: Reusable utilities for JSX manipulation, reporting, and validation
85
+ - **Package Detection**: Multi-strategy package version detection (dependencies + node_modules)
86
+ - **Test Infrastructure**: Comprehensive testing utilities for transform development
87
+
88
+ ### Developer Experience
89
+
90
+ - **Type Safety**: Full TypeScript support with proper type definitions
91
+ - **Error Handling**: Graceful error handling with helpful error messages
92
+ - **Debug Support**: Extensive debug logging for troubleshooting
93
+ - **Extensible**: Easy to add new transforms and extend existing functionality
94
+
95
+ ## ๐Ÿงช Quality Assurance
96
+
97
+ This release includes:
98
+
99
+ - โœ… **100% Test Coverage** for core utilities and transforms
100
+ - โœ… **End-to-End Testing** with real-world code examples
101
+ - โœ… **Edge Case Handling** for complex expressions and unusual patterns
102
+ - โœ… **Performance Optimization** with intelligent caching and batching
103
+ - โœ… **Memory Management** for large codebases
104
+
105
+ ## ๐Ÿ”ฎ What's Next?
106
+
107
+ This foundation enables:
108
+
109
+ - ๐ŸŽฏ Additional component transforms (Forms, Navigation, etc.)
110
+ - ๐Ÿš€ Enhanced reporting and analytics
111
+ - ๐Ÿ”ง IDE integrations and tooling
112
+ - ๐Ÿ“ฑ Support for additional package managers
113
+ - ๐ŸŒ Community contributions and extensibility
114
+
115
+ ## ๐Ÿ™ Getting Started
116
+
117
+ 1. Install the package: `npm install -D @wise/wds-codemods`
118
+ 2. Run your first transform: `npx @wise/wds-codemods`
119
+ 3. Review the generated `codemod-report.txt` for any manual review items
120
+ 4. Commit your changes and enjoy your modernized codebase!
121
+
122
+ ---
123
+
124
+ **Breaking Changes**: This is the initial release, so no breaking changes from previous versions.
125
+
126
+ **Migration Guide**: See our documentation for detailed migration examples and best practices.
127
+
128
+ Ready to modernize your Wise Design System components? Let's go! ๐Ÿš€
@@ -0,0 +1 @@
1
+ * @transferwise/design-system-web
@@ -0,0 +1,49 @@
1
+ name: 'Bootstrap'
2
+ description: 'Set up Node.js and install dependencies'
3
+
4
+ inputs:
5
+ github-token:
6
+ description: 'GitHub token for authentication'
7
+ required: true
8
+ npm-token-automation:
9
+ description: 'NPM token for authentication'
10
+ required: false
11
+
12
+ runs:
13
+ using: 'composite'
14
+ steps:
15
+ - name: Setup Node.js
16
+ uses: actions/setup-node@v4
17
+ with:
18
+ node-version-file: '.nvmrc'
19
+ registry-url: 'https://registry.npmjs.org'
20
+
21
+ - name: Setup pnpm
22
+ uses: pnpm/action-setup@v4
23
+
24
+ - name: Configure npm registry
25
+ shell: bash
26
+ run: |
27
+ echo "registry=https://registry.npmjs.org/" > .npmrc
28
+ echo "//registry.npmjs.org/:_authToken=${{ inputs.npm-token-automation }}" >> .npmrc
29
+ env:
30
+ NODE_AUTH_TOKEN: ${{ inputs.npm-token-automation }}
31
+
32
+ - name: Get pnpm store directory
33
+ shell: bash
34
+ run: |
35
+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
36
+
37
+ - name: Setup pnpm cache
38
+ uses: actions/cache@v4
39
+ with:
40
+ path: ${{ env.STORE_PATH }}
41
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
42
+ restore-keys: |
43
+ ${{ runner.os }}-pnpm-store-
44
+
45
+ - name: Install dependencies
46
+ shell: bash
47
+ run: pnpm install --frozen-lockfile
48
+ env:
49
+ NODE_AUTH_TOKEN: ${{ inputs.npm-token-automation }}
@@ -0,0 +1,27 @@
1
+ name: Commitlint
2
+ description: 'Lint all commit messages for the project'
3
+
4
+ inputs:
5
+ github-token:
6
+ required: true
7
+ description: 'secrets.GITHUB_TOKEN'
8
+
9
+ runs:
10
+ using: composite
11
+ steps:
12
+ - name: ๐Ÿ” Mark repo directory as safe for git # https://github.blog/2022-04-12-git-security-vulnerability-announced/
13
+ run: git config --global --add safe.directory $GITHUB_WORKSPACE
14
+ shell: bash
15
+
16
+ - name: ๐Ÿ› ๏ธ Bootstrap dependencies
17
+ uses: ./.github/actions/bootstrap
18
+ with:
19
+ github-token: ${{ inputs.github-token }}
20
+
21
+ - name: Fetch full commit history
22
+ run: git fetch --unshallow
23
+ shell: bash
24
+
25
+ - name: Run Commitlint
26
+ run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
27
+ shell: bash
@@ -0,0 +1,23 @@
1
+ name: Test
2
+ description: 'Run all tests for the project'
3
+
4
+ inputs:
5
+ github-token:
6
+ required: true
7
+ description: 'secrets.GITHUB_TOKEN'
8
+
9
+ runs:
10
+ using: composite
11
+ steps:
12
+ - name: ๐Ÿ” Mark repo directory as safe for git # https://github.blog/2022-04-12-git-security-vulnerability-announced/
13
+ run: git config --global --add safe.directory $GITHUB_WORKSPACE
14
+ shell: bash
15
+
16
+ - name: ๐Ÿ› ๏ธ Bootstrap dependencies
17
+ uses: ./.github/actions/bootstrap
18
+ with:
19
+ github-token: ${{ inputs.github-token }}
20
+
21
+ - name: ๐Ÿงช Run tests
22
+ run: pnpm run test
23
+ shell: bash
@@ -0,0 +1,127 @@
1
+ name: '๐Ÿš€ CI/CD'
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ concurrency:
10
+ group: ${{ github.workflow }}-${{ github.ref }}
11
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
12
+
13
+ env:
14
+ DO_NOT_TRACK: 1
15
+
16
+ jobs:
17
+ pipeline:
18
+ name: '๐Ÿš€ Build, Lint & Test'
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - name: ๐Ÿ›’ Check out repository
23
+ uses: actions/checkout@v4
24
+
25
+ - name: โš™๏ธ Bootstrap
26
+ uses: ./.github/actions/bootstrap
27
+ with:
28
+ github-token: ${{ secrets.GITHUB_TOKEN }}
29
+ npm-token-automation: ${{ secrets.NPM_TOKEN_AUTOMATION }}
30
+
31
+ - name: ๐Ÿ“ Lint
32
+ run: pnpm run lint
33
+
34
+ - name: ๐Ÿงช Run Tests
35
+ run: pnpm test
36
+
37
+ - name: ๐Ÿ—๏ธ Build
38
+ run: pnpm run build
39
+
40
+ publish-branch:
41
+ name: ๐Ÿš€ Publish experimental packages
42
+ if: ${{ github.event_name == 'pull_request' && !startsWith(github.head_ref, 'changeset-release/') }}
43
+ runs-on: ubuntu-latest
44
+ timeout-minutes: 10
45
+ needs: [pipeline]
46
+
47
+ steps:
48
+ - name: ๐Ÿ›’ Check out repository
49
+ uses: actions/checkout@v4
50
+ with:
51
+ token: ${{ secrets.GH_ACCESS_TOKEN }}
52
+
53
+ - name: โš™๏ธ Bootstrap
54
+ uses: ./.github/actions/bootstrap
55
+ with:
56
+ github-token: ${{ secrets.GITHUB_TOKEN }}
57
+ npm-token-automation: ${{ secrets.NPM_TOKEN_AUTOMATION }}
58
+
59
+ - name: ๐Ÿ—๏ธ Build
60
+ run: pnpm run build
61
+
62
+ - name: Setup npm token
63
+ run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_AUTOMATION }}" >> ~/.npmrc
64
+ shell: bash
65
+
66
+ - name: Publish snapshot release on npm
67
+ run: |
68
+ # Get current version from package.json
69
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
70
+ EXPERIMENTAL_VERSION="${CURRENT_VERSION}-experimental-${GITHUB_SHA:0:7}"
71
+
72
+ # Update package.json version directly
73
+ npm version $EXPERIMENTAL_VERSION --no-git-tag-version
74
+
75
+ # Publish the experimental version
76
+ npm publish --tag experimental
77
+ env:
78
+ GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
79
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_AUTOMATION }}
80
+
81
+ publish:
82
+ name: ๐Ÿš€ Publish stable packages
83
+ if: ${{ github.ref == 'refs/heads/main' }}
84
+ runs-on: ubuntu-latest
85
+ needs: [pipeline]
86
+
87
+ steps:
88
+ - name: ๐Ÿ›’ Check out repository
89
+ uses: actions/checkout@v4
90
+ with:
91
+ token: ${{ secrets.GH_ACCESS_TOKEN }}
92
+
93
+ - name: โš™๏ธ Bootstrap
94
+ uses: ./.github/actions/bootstrap
95
+ with:
96
+ github-token: ${{ secrets.GITHUB_TOKEN }}
97
+ npm-token-automation: ${{ secrets.NPM_TOKEN_AUTOMATION }}
98
+
99
+ - name: ๐Ÿ—๏ธ Build
100
+ run: pnpm run build
101
+
102
+ - name: ๐Ÿ‘ฉโ€๐Ÿ’ป Set GitHub credentials
103
+ run: |
104
+ mkdir -p ~/.ssh
105
+ ssh-keyscan github.com >> ~/.ssh/known_hosts
106
+ git config --global user.name "tw-actions"
107
+ git config --global user.email circle@circle.tw.ee
108
+
109
+ - name: ๐Ÿ” Set up commit signing
110
+ uses: crazy-max/ghaction-import-gpg@v6
111
+ with:
112
+ gpg_private_key: ${{ secrets.GPG_SIGN_KEY }}
113
+ git_config_global: true
114
+ git_user_signingkey: true
115
+ git_commit_gpgsign: true
116
+
117
+ - name: Create changesets release PR
118
+ id: changesets
119
+ uses: changesets/action@v1
120
+ with:
121
+ publish: pnpm release
122
+ commit: 'chore: release'
123
+ title: 'chore: release new version and update changelog'
124
+ setupGitUser: false
125
+ env:
126
+ GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
127
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN_AUTOMATION }}
@@ -0,0 +1,16 @@
1
+ name: Renovate
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - pnpm-lock.yaml
9
+ schedule:
10
+ - cron: '0 2 * * 1' # Run every Monday at 2AM
11
+ workflow_dispatch:
12
+
13
+ jobs:
14
+ renovate:
15
+ uses: transferwise/renovate-workflows/.github/workflows/run.yaml@v1
16
+ secrets: inherit
@@ -0,0 +1 @@
1
+ npx --no -- commitlint --edit $1
@@ -0,0 +1 @@
1
+ pnpm lint
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ lts/*
@@ -0,0 +1 @@
1
+ pnpm-lock.yaml
package/.prettierrc.js ADDED
@@ -0,0 +1,5 @@
1
+ export default {
2
+ printWidth: 100,
3
+ singleQuote: true,
4
+ trailingComma: 'all',
5
+ };