Skip to content

Commit dd8926f

Browse files
authored
chore: Add typescript to type check JS Interface via JSDoc (#2611)
This PR adds `typescript` to the repo to type-check the JS interface of Sentry CLI. I decided to build on top of the already existing JSDoc type annotations but actually enforce them by running TS. This also surfaced an incorrect type annotation which I fixed as well, along with adding some minor necessary annotations.
1 parent d227ec6 commit dd8926f

File tree

8 files changed

+62
-5
lines changed

8 files changed

+62
-5
lines changed

.github/workflows/test_node.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ on:
88
value: ${{ jobs.test_node.result }}
99

1010
jobs:
11+
type_check:
12+
name: Type Check
13+
runs-on: ubuntu-24.04
14+
steps:
15+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
16+
17+
- name: Use Node.js
18+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # 4.4.0
19+
with:
20+
node-version-file: package.json
21+
22+
# We need to skip the fallback download because downloading will fail on release branches because the new version isn't available yet.
23+
- run: SENTRYCLI_SKIP_DOWNLOAD=1 npm install
24+
25+
- run: npm run check:types
26+
1127
test_node:
1228
strategy:
1329
fail-fast: false

js/helper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ function mockBinaryPath(mockPath) {
186186
* @typedef {object} OptionSchema
187187
* @prop {string} param The flag of the command line option including dashes.
188188
* @prop {OptionType} type The value type of the command line option.
189+
* @prop {string} [invertedParam] The flag of the command line option including dashes (optional).
189190
*/
190191

191192
/**
@@ -245,7 +246,7 @@ function serializeOptions(schema, options) {
245246
/**
246247
* Serializes the command and its options into an arguments array.
247248
*
248-
* @param {string} command The literal name of the command.
249+
* @param {string[]} command The literal name of the command.
249250
* @param {OptionsSchema} [schema] An options schema required by the command.
250251
* @param {object} [options] An options object according to the schema.
251252
* @returns {string[]} An arguments array that can be passed via command line.
@@ -330,6 +331,7 @@ async function execute(args, live, silent, configFile, config = {}) {
330331
stdio: ['ignore', output, output],
331332
});
332333
pid.on('exit', () => {
334+
// @ts-expect-error - this is a TODO (v3) to fix and resolve a string here
333335
resolve();
334336
});
335337
} else {

js/releases/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ const DEFAULT_IGNORE = ['node_modules'];
1010

1111
/**
1212
* Schema for the `upload-sourcemaps` command.
13-
* @type {OptionsSchema}
13+
* @type {import('../helper').OptionsSchema}
1414
*/
1515
const SOURCEMAPS_SCHEMA = require('./options/uploadSourcemaps');
1616

1717
/**
1818
* Schema for the `deploys new` command.
19-
* @type {OptionsSchema}
19+
* @type {import('../helper').OptionsSchema}
2020
*/
2121
const DEPLOYS_SCHEMA = require('./options/deploys');
2222

@@ -95,7 +95,7 @@ class Releases {
9595
commitFlags.push('--ignore-missing');
9696
}
9797

98-
return this.execute(['releases', 'set-commits', release].concat(commitFlags));
98+
return this.execute(['releases', 'set-commits', release].concat(commitFlags), false);
9999
}
100100

101101
/**

js/releases/options/deploys.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @type {import('../../helper').OptionsSchema}
3+
*/
14
module.exports = {
25
env: {
36
param: '--env',

js/releases/options/uploadSourcemaps.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @type {import('../../helper').OptionsSchema}
3+
*/
14
module.exports = {
25
ignore: {
36
param: '--ignore',

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
"which": "^2.0.2"
2323
},
2424
"devDependencies": {
25+
"@types/node": "^20.10.0",
2526
"@vercel/nft": "^0.22.1",
2627
"eslint": "^7.32.0",
2728
"eslint-config-prettier": "^8.5.0",
2829
"jest": "^27.5.1",
2930
"npm-run-all": "^4.1.5",
30-
"prettier": "2.8.8"
31+
"prettier": "2.8.8",
32+
"typescript": "~5.8.3"
3133
},
3234
"optionalDependencies": {
3335
"@sentry/cli-darwin": "2.47.1",
@@ -49,6 +51,7 @@
4951
"test:watch": "jest --watch --notify",
5052
"test:eslint": "eslint bin/* scripts/**/*.js js/**/*.js",
5153
"test:prettier": "prettier --check bin/* scripts/**/*.js js/**/*.js",
54+
"check:types": "tsc --noEmit",
5255
"test:vercel-nft": "node scripts/test-vercel-nft.js"
5356
},
5457
"jest": {

tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"checkJs": true,
5+
"noEmit": true,
6+
"resolveJsonModule": true,
7+
"target": "ES2015",
8+
"moduleResolution": "node",
9+
"skipLibCheck": true
10+
},
11+
"include": ["js/**/*.js"],
12+
"exclude": ["**/__tests__/**", "**/__mocks__/**"]
13+
}

yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,13 @@
788788
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.18.tgz#8dfb97f0da23c2293e554c5a50d61ef134d7697f"
789789
integrity sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==
790790

791+
"@types/node@^20.10.0":
792+
version "20.19.8"
793+
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.19.8.tgz#d4a81f631d9dc5015c6e608a102c83e19d03c9db"
794+
integrity sha512-HzbgCY53T6bfu4tT7Aq3TvViJyHjLjPNaAS3HOuMc9pw97KHsUtXNX4L+wu59g1WnjsZSko35MbEqnO58rihhw==
795+
dependencies:
796+
undici-types "~6.21.0"
797+
791798
"@types/prettier@^2.1.5":
792799
version "2.7.2"
793800
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.2.tgz#6c2324641cc4ba050a8c710b2b251b377581fbf0"
@@ -3652,6 +3659,11 @@ typedarray-to-buffer@^3.1.5:
36523659
dependencies:
36533660
is-typedarray "^1.0.0"
36543661

3662+
typescript@~5.8.3:
3663+
version "5.8.3"
3664+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.3.tgz#92f8a3e5e3cf497356f4178c34cd65a7f5e8440e"
3665+
integrity sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==
3666+
36553667
unbox-primitive@^1.0.2:
36563668
version "1.0.2"
36573669
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e"
@@ -3662,6 +3674,11 @@ unbox-primitive@^1.0.2:
36623674
has-symbols "^1.0.3"
36633675
which-boxed-primitive "^1.0.2"
36643676

3677+
undici-types@~6.21.0:
3678+
version "6.21.0"
3679+
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.21.0.tgz#691d00af3909be93a7faa13be61b3a5b50ef12cb"
3680+
integrity sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==
3681+
36653682
universalify@^0.2.0:
36663683
version "0.2.0"
36673684
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"

0 commit comments

Comments
 (0)