Skip to content

Commit 3ffcddd

Browse files
feat(typescript): Upgrade to TS v4 (back compatible with TS v3.8) (#2995)
1 parent 437ade1 commit 3ffcddd

17 files changed

+4453
-29
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ module.exports = {
1313
version: 'detect', // React version. "detect" automatically picks the version you have installed.
1414
},
1515
ignorePatterns: [
16-
'test/react-native/versions/*',
16+
'test/react-native/versions/**/*',
1717
'coverage/**/*',
18+
'test/typescript/**/*',
1819
],
1920
overrides: [
2021
{

.github/workflows/buildandtest.yml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- uses: actions/setup-node@v3
1717
with:
18-
node-version: 14
18+
node-version: 16
1919
- uses: actions/cache@v3
2020
id: cache
2121
with:
@@ -86,7 +86,7 @@ jobs:
8686
- uses: actions/checkout@v3
8787
- uses: actions/setup-node@v3
8888
with:
89-
node-version: 14
89+
node-version: 16
9090
- uses: actions/cache@v3
9191
id: cache
9292
with:
@@ -97,6 +97,16 @@ jobs:
9797
run: yarn install
9898
- name: Build
9999
run: yarn build
100+
- name: Archive dist
101+
uses: actions/upload-artifact@v3
102+
with:
103+
name: dist
104+
path: dist
105+
- name: Archive ts3.8
106+
uses: actions/upload-artifact@v3
107+
with:
108+
name: ts3.8
109+
path: ts3.8
100110
- name: Pack
101111
run: yarn pack
102112
- name: Archive Artifacts
@@ -106,6 +116,45 @@ jobs:
106116
path: |
107117
${{ github.workspace }}/*.tgz
108118
119+
job_type_check:
120+
name: Type Check Typescript 3.8
121+
runs-on: ubuntu-latest
122+
needs: [job_build]
123+
steps:
124+
- uses: actions/checkout@v3
125+
- uses: actions/setup-node@v3
126+
with:
127+
node-version: 16
128+
- uses: actions/cache@v3
129+
id: cache
130+
with:
131+
path: test/typescript/ts3.8/node_modules
132+
key: ${{ runner.os }}-${{ github.sha }}-ts3.8
133+
- name: Download dist
134+
uses: actions/download-artifact@v3
135+
with:
136+
name: dist
137+
path: dist
138+
- name: Download ts3.8
139+
uses: actions/download-artifact@v3
140+
with:
141+
name: ts3.8
142+
path: ts3.8
143+
- name: Install Global Dependencies
144+
run: yarn global add yalc
145+
- name: Publish SDK
146+
run: yalc publish
147+
- name: Install SDK
148+
working-directory: test/typescript/ts3.8
149+
run: yalc add @sentry/react-native
150+
- name: Install Dependencies
151+
if: ${{ steps.cache.outputs['cache-hit'] != 'true' }}
152+
working-directory: test/typescript/ts3.8
153+
run: yarn install
154+
- name: Type Check
155+
working-directory: test/typescript/ts3.8
156+
run: yarn type-check
157+
109158
job_bundle:
110159
name: Bundle
111160
runs-on: ubuntu-latest
@@ -120,7 +169,7 @@ jobs:
120169
- uses: actions/checkout@v3
121170
- uses: actions/setup-node@v3
122171
with:
123-
node-version: '14'
172+
node-version: 16
124173
- name: Cache Dependencies
125174
uses: actions/cache@v3
126175
id: cache

.github/workflows/e2e.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
- uses: actions/checkout@v3
143143
- uses: actions/setup-node@v3
144144
with:
145-
node-version: "14"
145+
node-version: 16
146146
- uses: actions/setup-java@v3
147147
with:
148148
java-version: "11"
@@ -165,7 +165,7 @@ jobs:
165165
run: yalc publish
166166
- uses: actions/setup-node@v3
167167
with:
168-
node-version: "16"
168+
node-version: 16
169169
- uses: actions/cache@v3
170170
id: app-plain-cache
171171
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
build/
1212
DerivedData
1313
dist
14+
ts3.8
1415
coverage
1516

1617
## Various settings

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
!CHANGELOG.md
66
!README.md
77
!/dist/**/*
8+
!ts3.8/**/*
89
!RNSentry.podspec
910
!sentry.gradle
1011
!react-native.config.js

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Unreleased
44

55
### Features
6-
6+
- Add TS 4.1 typings ([#2995](https://github.com/getsentry/sentry-react-native/pull/2995))
7+
- TS 3.8 are present and work automatically with older projects
78
- Add CPU Info to Device Context ([#2984](https://github.com/getsentry/sentry-react-native/pull/2984))
89

910
### Fixes

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
"description": "Official Sentry SDK for react-native",
77
"typings": "dist/js/index.d.ts",
88
"types": "dist/js/index.d.ts",
9+
"typesVersions": {
10+
"<4.1": { "*": ["ts3.8/*"] }
11+
},
912
"typescript": {
1013
"definition": "dist/js/index.d.ts"
1114
},
1215
"main": "dist/js/index.js",
1316
"scripts": {
14-
"build": "yarn build:sdk && yarn build:tools",
17+
"build": "yarn build:sdk && yarn downlevel && yarn build:tools",
1518
"build:sdk": "tsc -p tsconfig.build.json",
1619
"build:sdk:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
1720
"build:tools": "tsc -p tsconfig.build.tools.json",
21+
"downlevel": "downlevel-dts dist ts3.8/dist --to=3.8",
1822
"clean": "rimraf dist coverage",
1923
"test": "jest",
2024
"fix": "yarn fix:eslint && yarn fix:prettier",
@@ -64,6 +68,7 @@
6468
"@types/jest": "^29.2.5",
6569
"@types/react": "^18.0.25",
6670
"babel-jest": "^29.3.1",
71+
"downlevel-dts": "^0.11.0",
6772
"eslint": "^7.6.0",
6873
"eslint-plugin-react": "^7.20.6",
6974
"eslint-plugin-react-native": "^3.8.1",
@@ -75,7 +80,7 @@
7580
"replace-in-file": "^6.0.0",
7681
"rimraf": "^4.1.1",
7782
"ts-jest": "^29.0.5",
78-
"typescript": "3.8.3"
83+
"typescript": "4.1.3"
7984
},
8085
"rnpm": {
8186
"commands": {},

src/js/sdk.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function init(passedOptions: ReactNativeOptions): void {
138138
/**
139139
* Inits the Sentry React Native SDK with automatic instrumentation and wrapped features.
140140
*/
141-
export function wrap<P>(
141+
export function wrap<P extends JSX.IntrinsicAttributes>(
142142
RootComponent: React.ComponentType<P>,
143143
options?: ReactNativeWrapperOptions
144144
): React.ComponentType<P> {

src/js/tracing/reactnativenavigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Transaction as TransactionType, TransactionContext } from '@sentry/types';
22
import { logger } from '@sentry/utils';
3-
import type { EmitterSubscription } from 'react-native';
3+
import type { EmitterSubscription } from 'react-native/Libraries/vendor/emitter/EventEmitter';
44

55
import type { OnConfirmRoute, TransactionCreator } from './routingInstrumentation';
66
import { InternalRoutingInstrumentation } from './routingInstrumentation';

test/e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"appium-xcuitest-driver": "^4.16.6",
1717
"babel-jest": "^29.3.1",
1818
"jest": "^29.3.1",
19-
"typescript": "3.8.3",
19+
"typescript": "4.1.3",
2020
"webdriverio": "7.26.0"
2121
}
2222
}

test/e2e/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6251,10 +6251,10 @@ type-is@~1.6.18:
62516251
media-typer "0.3.0"
62526252
mime-types "~2.1.24"
62536253

6254-
typescript@3.8.3:
6255-
version "3.8.3"
6256-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
6257-
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
6254+
typescript@4.1.3:
6255+
version "4.1.3"
6256+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
6257+
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==
62586258

62596259
ua-parser-js@^1.0.1:
62606260
version "1.0.32"

test/typescript/ts3.8/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// we need to import the SDK to ensure tsc check the types
2+
import * as _Sentry from '@sentry/react-native';

test/typescript/ts3.8/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "sentry-react-native-ts-3-8-test",
3+
"version": "0.0.0",
4+
"description": "Sentry React Native TypeScript 3.8 Test",
5+
"main": "index.ts",
6+
"scripts": {
7+
"type-check": "tsc --project tsconfig.build.json"
8+
},
9+
"license": "MIT",
10+
"devDependencies": {
11+
"@types/react": "17.0.58",
12+
"@types/react-native": "0.65.30",
13+
"typescript": "3.8.3"
14+
},
15+
"dependencies": {
16+
"@sentry/react-native": "file:.yalc/@sentry/react-native",
17+
"react": "17.0.2",
18+
"react-native": "0.65.3"
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"include": [
3+
"index.ts",
4+
],
5+
"compilerOptions": {
6+
"skipLibCheck": false,
7+
"noEmit": true,
8+
"types": [],
9+
"jsx": "react-native",
10+
"target": "es6",
11+
"moduleResolution": "node",
12+
},
13+
}

0 commit comments

Comments
 (0)