Skip to content

Commit

Permalink
feat(typescript): Upgrade to TS v4 (back compatible with TS v3.8) (#2995
Browse files Browse the repository at this point in the history
)
  • Loading branch information
krystofwoldrich authored Apr 25, 2023
1 parent 437ade1 commit 3ffcddd
Show file tree
Hide file tree
Showing 17 changed files with 4,453 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ module.exports = {
version: 'detect', // React version. "detect" automatically picks the version you have installed.
},
ignorePatterns: [
'test/react-native/versions/*',
'test/react-native/versions/**/*',
'coverage/**/*',
'test/typescript/**/*',
],
overrides: [
{
Expand Down
55 changes: 52 additions & 3 deletions .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
- uses: actions/cache@v3
id: cache
with:
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
- uses: actions/cache@v3
id: cache
with:
Expand All @@ -97,6 +97,16 @@ jobs:
run: yarn install
- name: Build
run: yarn build
- name: Archive dist
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
- name: Archive ts3.8
uses: actions/upload-artifact@v3
with:
name: ts3.8
path: ts3.8
- name: Pack
run: yarn pack
- name: Archive Artifacts
Expand All @@ -106,6 +116,45 @@ jobs:
path: |
${{ github.workspace }}/*.tgz
job_type_check:
name: Type Check Typescript 3.8
runs-on: ubuntu-latest
needs: [job_build]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/cache@v3
id: cache
with:
path: test/typescript/ts3.8/node_modules
key: ${{ runner.os }}-${{ github.sha }}-ts3.8
- name: Download dist
uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Download ts3.8
uses: actions/download-artifact@v3
with:
name: ts3.8
path: ts3.8
- name: Install Global Dependencies
run: yarn global add yalc
- name: Publish SDK
run: yalc publish
- name: Install SDK
working-directory: test/typescript/ts3.8
run: yalc add @sentry/react-native
- name: Install Dependencies
if: ${{ steps.cache.outputs['cache-hit'] != 'true' }}
working-directory: test/typescript/ts3.8
run: yarn install
- name: Type Check
working-directory: test/typescript/ts3.8
run: yarn type-check

job_bundle:
name: Bundle
runs-on: ubuntu-latest
Expand All @@ -120,7 +169,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '14'
node-version: 16
- name: Cache Dependencies
uses: actions/cache@v3
id: cache
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "14"
node-version: 16
- uses: actions/setup-java@v3
with:
java-version: "11"
Expand All @@ -165,7 +165,7 @@ jobs:
run: yalc publish
- uses: actions/setup-node@v3
with:
node-version: "16"
node-version: 16
- uses: actions/cache@v3
id: app-plain-cache
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
build/
DerivedData
dist
ts3.8
coverage

## Various settings
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!CHANGELOG.md
!README.md
!/dist/**/*
!ts3.8/**/*
!RNSentry.podspec
!sentry.gradle
!react-native.config.js
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Unreleased

### Features

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

### Fixes
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
"description": "Official Sentry SDK for react-native",
"typings": "dist/js/index.d.ts",
"types": "dist/js/index.d.ts",
"typesVersions": {
"<4.1": { "*": ["ts3.8/*"] }
},
"typescript": {
"definition": "dist/js/index.d.ts"
},
"main": "dist/js/index.js",
"scripts": {
"build": "yarn build:sdk && yarn build:tools",
"build": "yarn build:sdk && yarn downlevel && yarn build:tools",
"build:sdk": "tsc -p tsconfig.build.json",
"build:sdk:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"build:tools": "tsc -p tsconfig.build.tools.json",
"downlevel": "downlevel-dts dist ts3.8/dist --to=3.8",
"clean": "rimraf dist coverage",
"test": "jest",
"fix": "yarn fix:eslint && yarn fix:prettier",
Expand Down Expand Up @@ -64,6 +68,7 @@
"@types/jest": "^29.2.5",
"@types/react": "^18.0.25",
"babel-jest": "^29.3.1",
"downlevel-dts": "^0.11.0",
"eslint": "^7.6.0",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-native": "^3.8.1",
Expand All @@ -75,7 +80,7 @@
"replace-in-file": "^6.0.0",
"rimraf": "^4.1.1",
"ts-jest": "^29.0.5",
"typescript": "3.8.3"
"typescript": "4.1.3"
},
"rnpm": {
"commands": {},
Expand Down
2 changes: 1 addition & 1 deletion src/js/sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function init(passedOptions: ReactNativeOptions): void {
/**
* Inits the Sentry React Native SDK with automatic instrumentation and wrapped features.
*/
export function wrap<P>(
export function wrap<P extends JSX.IntrinsicAttributes>(
RootComponent: React.ComponentType<P>,
options?: ReactNativeWrapperOptions
): React.ComponentType<P> {
Expand Down
2 changes: 1 addition & 1 deletion src/js/tracing/reactnativenavigation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Transaction as TransactionType, TransactionContext } from '@sentry/types';
import { logger } from '@sentry/utils';
import type { EmitterSubscription } from 'react-native';
import type { EmitterSubscription } from 'react-native/Libraries/vendor/emitter/EventEmitter';

import type { OnConfirmRoute, TransactionCreator } from './routingInstrumentation';
import { InternalRoutingInstrumentation } from './routingInstrumentation';
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"appium-xcuitest-driver": "^4.16.6",
"babel-jest": "^29.3.1",
"jest": "^29.3.1",
"typescript": "3.8.3",
"typescript": "4.1.3",
"webdriverio": "7.26.0"
}
}
8 changes: 4 additions & 4 deletions test/e2e/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6251,10 +6251,10 @@ type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"

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

ua-parser-js@^1.0.1:
version "1.0.32"
Expand Down
2 changes: 2 additions & 0 deletions test/typescript/ts3.8/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// we need to import the SDK to ensure tsc check the types
import * as _Sentry from '@sentry/react-native';
20 changes: 20 additions & 0 deletions test/typescript/ts3.8/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "sentry-react-native-ts-3-8-test",
"version": "0.0.0",
"description": "Sentry React Native TypeScript 3.8 Test",
"main": "index.ts",
"scripts": {
"type-check": "tsc --project tsconfig.build.json"
},
"license": "MIT",
"devDependencies": {
"@types/react": "17.0.58",
"@types/react-native": "0.65.30",
"typescript": "3.8.3"
},
"dependencies": {
"@sentry/react-native": "file:.yalc/@sentry/react-native",
"react": "17.0.2",
"react-native": "0.65.3"
}
}
13 changes: 13 additions & 0 deletions test/typescript/ts3.8/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"include": [
"index.ts",
],
"compilerOptions": {
"skipLibCheck": false,
"noEmit": true,
"types": [],
"jsx": "react-native",
"target": "es6",
"moduleResolution": "node",
},
}
Loading

0 comments on commit 3ffcddd

Please sign in to comment.