Repository navigation
feat(cli): Port the v3-to-v4 codemod from the archived getsentry/cli as cli3to4 #1968
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d1335e8
feat(cli): Port the v3-to-v4 codemod from the archived getsentry/cli
sentry-junior[bot] e305dbc
fix(cli): Address Bugbot findings in the v3-to-v4 codemod
sentry-junior[bot] 1ac71fc
fix(cli): Keep codemod output runnable for bare CJS requires and comm…
sentry-junior[bot] 39e7b05
chore(cli): Add the Codemod Registry verification file for @getsentry
sentry-junior[bot] 660e406
Merge origin/main into feat/cli-codemod-port
sentry-junior[bot] 87afd56
feat(cli): Rename the codemod to cli3to4, publish on version bumps, m…
sentry-junior[bot] 4b63d3a
fix(cli3to4): Migrate files that only import v3 types
sentry-junior[bot] 21a6295
feat(cli3to4): Map releases.new projects and v3 static helpers, move …
sentry-junior[bot] 27943dc
fix(cli3to4): Parenthesize projects expressions before joining them
sentry-junior[bot] 93f6f73
fix(cli3to4): Migrate CJS requires outside const initializers and inl…
sentry-junior[bot] 244ddb9
fix(cli3to4): Migrate chained new SentryCli() calls, publish only fro…
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| codemod-verification=b6bab3ce-7770-40b0-9076-98bd50580f7d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| name: Publish codemod | ||
|
|
||
| # Publishes packages/codemod-cli3to4 to the Codemod Registry as `@getsentry/cli3to4` | ||
| # whenever a push to main changes the `version` in its codemod.yaml. Codemod | ||
| # authenticates the publish with this workflow's GitHub Actions OIDC token, so | ||
| # no API key is stored here. The `@getsentry` scope must be verified once on | ||
| # codemod.com; see packages/codemod-cli3to4/README.md. | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - "packages/codemod-cli3to4/codemod.yaml" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| check: | ||
| name: Check codemod version | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| changed: ${{ steps.version.outputs.changed }} | ||
| steps: | ||
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - id: version | ||
| env: | ||
| BEFORE_SHA: ${{ github.event.before }} | ||
| run: node scripts/codemod-version-changed.mjs | ||
|
|
||
| publish: | ||
| name: Publish to Codemod Registry | ||
| needs: check | ||
| # Only main is published, also for manual runs from another branch. | ||
| if: github.ref == 'refs/heads/main' && (github.event_name == 'workflow_dispatch' || needs.check.outputs.changed == 'true') | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| - uses: codemod/publish-action@dd6c8dbc5ceb1a6146feba41481d88b43da50024 # v1 | ||
| with: | ||
| path: packages/codemod-cli3to4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| node_modules/ | ||
| target/ | ||
| *.tgz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # `@getsentry/cli3to4` | ||
|
|
||
| A [Codemod](https://codemod.com) that migrates programmatic **`@sentry/cli` v3** | ||
| usage (the `SentryCli` class) to the **v4 `sentry` package** (`createSentrySDK` | ||
| factory + typed command methods). | ||
|
|
||
| It is referenced from the CLI's | ||
| [migration guide](https://cli.sentry.dev/migrating-from-v3/). | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| npx codemod @getsentry/cli3to4 | ||
| ``` | ||
|
|
||
| Run it from your project root; it rewrites `.js`/`.ts`/`.jsx`/`.tsx` files (and | ||
| their `.mjs`/`.cjs`/`.mts`/`.cts` variants) in place. Review the diff afterward — | ||
| the codemod inserts `// TODO(sentry-v4): …` comments wherever an option shape | ||
| changed and needs a manual decision (it flags rather than guesses). | ||
|
|
||
| ## What it does | ||
|
|
||
| - Rewrites the module specifier `@sentry/cli` → `sentry`, **keeping your local | ||
| binding name** (so re-exports and pass-throughs stay valid). v3's named | ||
| export becomes v4's factory: `import { SentryCli }` → | ||
| `import { createSentrySDK as SentryCli }`, `const { SentryCli } = require(…)` | ||
| → `const { createSentrySDK: SentryCli } = require(…)`, and `X.SentryCli` → | ||
| `X.createSentrySDK`. The v2 default-export shapes (`import X from`, bare | ||
| `require`) map to v4's default export. | ||
| - `new SentryCli(configFile?, options?)` → `SentryCli(options?)` — drops `new` | ||
| (v4 exports a factory, not a class) and the removed `configFile` positional, | ||
| and renames the `authToken` option to `token`. | ||
| - Maps the release/sourcemap methods to the typed v4 SDK: | ||
| `releases.new`→`release.create`, `releases.finalize`→`release.finalize`, | ||
| `releases.setCommits`→`release["set-commits"]`, | ||
| `releases.newDeploy`→`release.deploy` (renaming `env` to `environment`), | ||
| `releases.listDeploys`→`release.deploys`, | ||
| `releases.proposeVersion`→`release["propose-version"]`, | ||
| `releases.uploadSourceMaps`→`sourcemap.upload`, | ||
| `sourceMaps.inject`→`sourcemap.inject`, and `execute([...])`→`run(...)`. | ||
| The release version moves into the options object as `orgVersion` (or | ||
| `release` for `sourcemap.upload`). | ||
| - Only touches files that actually import `@sentry/cli`, and only rewrites | ||
| method calls on instances it can see created via `new SentryCli(...)`. | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| # Run the test fixtures (tests/<case>/input.ts + expected.ts) | ||
| pnpm test | ||
|
|
||
| # Type-check the transform | ||
| pnpm run typecheck | ||
|
|
||
| # Update expected fixtures after an intentional change | ||
| pnpm dlx codemod@1.12.7 jssg test -l typescript ./scripts/codemod.ts -u | ||
| ``` | ||
|
|
||
| ## Publishing | ||
|
|
||
| Published to the [Codemod Registry](https://codemod.com/registry) under the | ||
| `@getsentry` scope. Codemod verifies that scope against this repository | ||
| (`.codemod/verification` at the repo root). To release, bump `version` in | ||
| `codemod.yaml` and merge to `main`. | ||
| [`.github/workflows/publish-codemod.yml`](../../.github/workflows/publish-codemod.yml) | ||
| runs on pushes to `main` that touch `codemod.yaml` and publishes with GitHub | ||
| Actions OIDC when the version changed. You can also run it by hand from the | ||
| Actions tab. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| schema_version: "1.0" | ||
|
|
||
| name: "@getsentry/cli3to4" | ||
| version: "0.1.0" | ||
| description: "Migrate @sentry/cli v3 SDK usage to the v4 sentry package" | ||
| author: "Sentry" | ||
| license: "MIT" | ||
| repository: "https://github.com/getsentry/toolkit" | ||
|
|
||
| targets: | ||
| # Keep this aligned with the files matched in workflow.yaml. | ||
| languages: ["typescript", "tsx"] | ||
|
|
||
| keywords: ["sentry", "sentry-cli", "migration", "v3", "v4"] | ||
|
|
||
| registry: | ||
| access: "public" | ||
| visibility: "public" | ||
|
|
||
| capabilities: [] | ||
|
|
||
| workflows: | ||
| - name: main | ||
| default: true | ||
| path: workflow.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "@sentry/cli3to4", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "description": "Codemod that migrates @sentry/cli v3 SDK usage to the v4 sentry package", | ||
| "type": "module", | ||
| "license": "MIT", | ||
| "scripts": { | ||
| "test": "pnpm dlx codemod@1.12.7 jssg test -l typescript ./scripts/codemod.ts", | ||
| "typecheck": "tsc --noEmit" | ||
| }, | ||
| "devDependencies": { | ||
| "@codemod.com/jssg-types": "1.6.3", | ||
| "typescript": "catalog:" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.