Skip to content

Commit fa2878d

Browse files
ThewBearVanuan
authored andcommitted
Make @typescript-eslint an optional peer dependency
1 parent c87ab79 commit fa2878d

File tree

7 files changed

+30
-10
lines changed

7 files changed

+30
-10
lines changed

docusaurus/docs/adding-typescript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ yarn create react-app my-app --template typescript
2626
To add [TypeScript](https://www.typescriptlang.org/) to a Create React App project, first install it:
2727

2828
```sh
29-
npm install --save typescript @types/node @types/react @types/react-dom @types/jest
29+
npm install --save typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser @types/node @types/react @types/react-dom @types/jest
3030

3131
# or
3232

33-
yarn add typescript @types/node @types/react @types/react-dom @types/jest
33+
yarn add typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser @types/node @types/react @types/react-dom @types/jest
3434
```
3535

3636
Next, rename any file to be a TypeScript file (e.g. `src/index.js` to `src/index.tsx`) and **restart your development server**!

packages/cra-template-typescript/template.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"@types/react": "^16.9.0",
99
"@types/react-dom": "^16.9.0",
1010
"@types/jest": "^25.0.0",
11-
"typescript": "^3.8.0"
11+
"typescript": "^3.8.0",
12+
"@typescript-eslint/eslint-plugin": "^2.28.0",
13+
"@typescript-eslint/parser": "^2.28.0"
1214
}
1315
}
1416
}

packages/eslint-config-react-app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you want to use this ESLint configuration in a project not built with Create
1919
First, install this package, ESLint and the necessary plugins.
2020

2121
```sh
22-
npm install --save-dev eslint-config-react-app @typescript-eslint/eslint-plugin@2.x @typescript-eslint/parser@2.x babel-eslint@10.x eslint@6.x eslint-plugin-flowtype@4.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@2.x
22+
npm install --save-dev eslint-config-react-app babel-eslint@10.x eslint@6.x eslint-plugin-flowtype@4.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@2.x
2323
```
2424

2525
Then create a file named `.eslintrc.json` with following contents in the root folder of your project:

packages/eslint-config-react-app/package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525
"eslint-plugin-react": "7.x",
2626
"eslint-plugin-react-hooks": "1.x || 2.x || 3.x || 4.x"
2727
},
28+
"peerDependenciesMeta": {
29+
"@typescript-eslint/eslint-plugin": {
30+
"optional": true
31+
},
32+
"@typescript-eslint/parser": {
33+
"optional": true
34+
}
35+
},
2836
"dependencies": {
29-
"confusing-browser-globals": "^1.0.9"
37+
"confusing-browser-globals": "^1.0.9",
38+
"resolve": "^1.16.0"
3039
}
3140
}

packages/react-scripts/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
"@babel/core": "7.10.1",
3232
"@pmmmwh/react-refresh-webpack-plugin": "0.3.2",
3333
"@svgr/webpack": "5.4.0",
34-
"@typescript-eslint/eslint-plugin": "^2.10.0",
35-
"@typescript-eslint/parser": "^2.10.0",
3634
"babel-eslint": "10.1.0",
3735
"babel-jest": "^26.0.1",
3836
"babel-loader": "8.1.0",
@@ -92,11 +90,19 @@
9290
"fsevents": "^2.1.3"
9391
},
9492
"peerDependencies": {
95-
"typescript": "^3.2.1"
93+
"typescript": "^3.2.1",
94+
"@typescript-eslint/eslint-plugin": "^2.28.0",
95+
"@typescript-eslint/parser": "^2.28.0"
9696
},
9797
"peerDependenciesMeta": {
9898
"typescript": {
9999
"optional": true
100+
},
101+
"@typescript-eslint/eslint-plugin": {
102+
"optional": true
103+
},
104+
"@typescript-eslint/parser": {
105+
"optional": true
100106
}
101107
},
102108
"browserslist": {

test/fixtures/typescript-advanced/index.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const testSetup = require('../__shared__/test-setup');
22

33
test('builds in development', async () => {
4-
const { fulfilled } = await testSetup.scripts.start({ smoke: true });
4+
const { fulfilled, stderr } = await testSetup.scripts.start({ smoke: true });
5+
expect(stderr).toBe("We detected TypeScript in your project (src/App.test.ts) and created a tsconfig.json file for you.\n");
56
expect(fulfilled).toBe(true);
67
});
78
test('builds in production', async () => {

test/fixtures/typescript-advanced/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"@types/jest": "*",
66
"react": "*",
77
"react-dom": "*",
8-
"typescript": "3.7.2"
8+
"typescript": "3.7.2",
9+
"@typescript-eslint/eslint-plugin": "^2.28.0",
10+
"@typescript-eslint/parser": "^2.28.0"
911
}
1012
}

0 commit comments

Comments
 (0)