Skip to content

Commit f9878c8

Browse files
authored
chore: Prepare to use TypeScript natively (#2910)
### Description This PR is a starting point of upgrading to TypeScript and preparing for future upgrades around testing and maintenance. I've seen that couple of types between the `*.js` files and the `index.d.ts` were not 100% in sync, which is one of the reasons the move to TypeScript natively could help here. ### What's new / changed - moved `js` to `lib` in order to keep `js` as the same output folder which is delivered to NPM - `js/index.d.ts` stays as type export for NPM and the types are re-exported via the jsdoc `@typedef` - `types.ts` is actually the same as the previous `index.d.ts` excluding the `SentryCli` class - TypeScript is partially used to keep the changes minimal - I aligned the jsdoc types with the actual text from the previous `index.d.ts`
1 parent 8270534 commit f9878c8

File tree

21 files changed

+340
-295
lines changed

21 files changed

+340
-295
lines changed

.cursor/rules/javascript-development.mdc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ alwaysApply: false
99
## Code Organization
1010

1111
- Maintain compatibility with existing npm package structure
12-
- Update TypeScript definitions in `js/index.d.ts` if needed
1312
- Consider impact on installation flow in `scripts/install.js`
1413
- Test across different Node.js versions
1514

@@ -36,6 +35,6 @@ npm run check:types
3635

3736
## TypeScript Support
3837

39-
- Type definitions maintained in `js/index.d.ts`
38+
- Type definitions are generated via TypeScript
4039
- Sync with Rust CLI interface changes
4140
- Consider backward compatibility for JS API

.cursor/rules/sentry-cli-project.mdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This is **sentry-cli**, a command-line utility for working with Sentry. It's pri
2020
## Project Structure
2121

2222
- `src/` - Core Rust source code with command modules and utilities
23-
- `js/` - JavaScript wrapper and npm package code
23+
- `lib/` - JavaScript wrapper and npm package code
2424
- `scripts/` - Build and utility scripts
2525
- `tests/integration/` - Integration tests using `.trycmd` format
2626
- `npm-binary-distributions/` - Platform-specific binary packages

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/.cursor/rules/javascript-development.mdc @getsentry/team-javascript-sdks @getsentry/owners-sentry-cli
55
/.npmignore @getsentry/team-javascript-sdks @getsentry/owners-sentry-cli
66
/bin/ @getsentry/team-javascript-sdks @getsentry/owners-sentry-cli # these are the JS "binaries"
7-
/js @getsentry/team-javascript-sdks @getsentry/owners-sentry-cli
7+
/lib @getsentry/team-javascript-sdks @getsentry/owners-sentry-cli
88
/package.json @getsentry/team-javascript-sdks @getsentry/owners-sentry-cli
99
/scripts/*.js @getsentry/team-javascript-sdks @getsentry/owners-sentry-cli
1010
/tsconfig.json @getsentry/team-javascript-sdks @getsentry/owners-sentry-cli

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ jobs:
228228
with:
229229
node-version: '20.10.0'
230230

231+
- name: Install dependencies
232+
run: npm ci --ignore-scripts
233+
231234
- name: Download compiled binaries
232235
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # 6.0.0
233236
with:

.github/workflows/test_node.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
- name: Install dependencies via npm ci
2828
if: ${{ !inputs.triggered-by-release }}
29-
run: npm ci
29+
run: npm ci --ignore-scripts
3030

3131
# For pushes to the release branch, we need to install the dependencies via `npm install`
3232
# because the `package-lock.json` is not updated with the new versions of the optional
@@ -37,7 +37,30 @@ jobs:
3737

3838
- run: npm run check:types
3939

40+
prepare_build:
41+
name: Prepare Build
42+
runs-on: ubuntu-24.04
43+
steps:
44+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
45+
46+
- name: Use Node.js
47+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # 6.0.0
48+
with:
49+
node-version-file: package.json
50+
51+
- name: Install dependencies
52+
run: npm ci --ignore-scripts
53+
54+
- name: Build
55+
run: npm run build
56+
57+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
58+
with:
59+
name: artifact-build
60+
path: js
61+
4062
test_node:
63+
needs: prepare_build
4164
strategy:
4265
fail-fast: false
4366
matrix:
@@ -56,7 +79,7 @@ jobs:
5679

5780
- name: Install dependencies via npm ci
5881
if: ${{ !inputs.triggered-by-release }}
59-
run: npm ci
82+
run: npm ci --ignore-scripts
6083

6184
# For pushes to the release branch, we need to install the dependencies via `npm install`
6285
# because the `package-lock.json` is not updated with the new versions of the optional
@@ -65,6 +88,15 @@ jobs:
6588
if: ${{ inputs.triggered-by-release }}
6689
run: npm install --omit=optional --ignore-scripts
6790

91+
- name: Download build artifact
92+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # 5.0.0
93+
with:
94+
name: artifact-build
95+
path: js
96+
97+
- name: Install CLI
98+
run: npm run install-cli
99+
68100
# older node versions need an older nft
69101
- run: SENTRYCLI_SKIP_DOWNLOAD=1 npm install @vercel/nft@0.22.1
70102
if: matrix.node-version == '10.x' || matrix.node-version == '12.x'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target
44
node_modules
55
coverage
66
dist
7+
js
78
dump
89
checksums.txt
910
yarn-error.log

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646

4747
- Slightly sped up the `sentry-cli sourcemaps upload` command by eliminating an HTTP request to the Sentry server, which was not required in most cases ([#2913](https://github.com/getsentry/sentry-cli/pull/2913)).
4848

49+
### Internal changes
50+
51+
- Migrated JavaScript wrapper to TypeScript for better type safety ([#2910](https://github.com/getsentry/sentry-cli/pull/2910))
52+
4953
## 2.57.0
5054

5155
### New Features

js/index.d.ts

Lines changed: 0 additions & 248 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)