Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Commit 8e3ab21

Browse files
Rebase TypeScript changes
1 parent 5aaea56 commit 8e3ab21

16 files changed

+254
-77
lines changed

Diff for: package.json

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"precommit": "lint-staged"
1515
},
1616
"devDependencies": {
17+
"@types/jest": "^21.1.5",
18+
"@types/node": "^8.0.47",
19+
"@types/react": "^16.0.20",
20+
"@types/react-dom": "^16.0.2",
1721
"eslint": "^4.4.1",
1822
"husky": "^0.13.2",
1923
"lerna": "^2.0.0",

Diff for: packages/react-dev-utils/WebpackDevServerUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function createCompiler(webpack, config, appName, urls, useYarn) {
185185
);
186186
console.log(
187187
'To ignore, add ' +
188-
chalk.cyan('// eslint-disable-next-line') +
188+
chalk.cyan('// tslint:disable-next-line') +
189189
' to the line before.\n'
190190
);
191191
}

Diff for: packages/react-scripts/config/paths.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ module.exports = {
5252
appBuild: resolveApp('build'),
5353
appPublic: resolveApp('public'),
5454
appHtml: resolveApp('public/index.html'),
55-
appIndexJs: resolveApp('src/index.js'),
55+
appIndexJs: resolveApp('src/index.tsx'),
5656
appPackageJson: resolveApp('package.json'),
5757
appSrc: resolveApp('src'),
5858
yarnLockFile: resolveApp('yarn.lock'),
59-
testsSetup: resolveApp('src/setupTests.js'),
59+
testsSetup: resolveApp('src/setupTests.ts'),
6060
appNodeModules: resolveApp('node_modules'),
61+
appTsConfig: resolveApp('tsconfig.json'),
6162
publicUrl: getPublicUrl(resolveApp('package.json')),
6263
servedPath: getServedPath(resolveApp('package.json')),
6364
};
@@ -72,12 +73,14 @@ module.exports = {
7273
appBuild: resolveApp('build'),
7374
appPublic: resolveApp('public'),
7475
appHtml: resolveApp('public/index.html'),
75-
appIndexJs: resolveApp('src/index.js'),
76+
appIndexJs: resolveApp('src/index.tsx'),
7677
appPackageJson: resolveApp('package.json'),
7778
appSrc: resolveApp('src'),
7879
yarnLockFile: resolveApp('yarn.lock'),
79-
testsSetup: resolveApp('src/setupTests.js'),
80+
testsSetup: resolveApp('src/setupTests.ts'),
8081
appNodeModules: resolveApp('node_modules'),
82+
appTsConfig: resolveApp('tsconfig.json'),
83+
appTsTestConfig: resolveApp('tsconfig.test.json'),
8184
publicUrl: getPublicUrl(resolveApp('package.json')),
8285
servedPath: getServedPath(resolveApp('package.json')),
8386
// These properties only exist before ejecting:
@@ -102,12 +105,14 @@ if (
102105
appBuild: resolveOwn('../../build'),
103106
appPublic: resolveOwn('template/public'),
104107
appHtml: resolveOwn('template/public/index.html'),
105-
appIndexJs: resolveOwn('template/src/index.js'),
108+
appIndexJs: resolveOwn('template/src/index.tsx'),
106109
appPackageJson: resolveOwn('package.json'),
107110
appSrc: resolveOwn('template/src'),
108111
yarnLockFile: resolveOwn('template/yarn.lock'),
109-
testsSetup: resolveOwn('template/src/setupTests.js'),
112+
testsSetup: resolveOwn('template/src/setupTests.ts'),
110113
appNodeModules: resolveOwn('node_modules'),
114+
appTsConfig: resolveOwn('template/tsconfig.json'),
115+
appTsTestConfig: resolveOwn('template/tsconfig.test.json'),
111116
publicUrl: getPublicUrl(resolveOwn('package.json')),
112117
servedPath: getServedPath(resolveOwn('package.json')),
113118
// These properties only exist before ejecting:

Diff for: packages/react-scripts/config/webpack.config.dev.js

+15-19
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
1515
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1616
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1717
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
18-
const eslintFormatter = require('react-dev-utils/eslintFormatter');
1918
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2019
const getClientEnvironment = require('./env');
2120
const paths = require('./paths');
@@ -90,7 +89,7 @@ module.exports = {
9089
// https://github.com/facebookincubator/create-react-app/issues/290
9190
// `web` extension prefixes have been added for better support
9291
// for React Native Web.
93-
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
92+
extensions: ['.web.ts', '.ts', '.web.tsx', '.tsx', '.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
9493
alias: {
9594
// @remove-on-eject-begin
9695
// Resolve Babel runtime relative to react-scripts.
@@ -124,24 +123,15 @@ module.exports = {
124123
// First, run the linter.
125124
// It's important to do this before Babel processes the JS.
126125
{
127-
test: /\.(js|jsx|mjs)$/,
126+
test: /\.(ts|tsx)$/,
127+
loader: require.resolve('tslint-loader'),
128+
enforce: 'pre',
129+
include: paths.appSrc,
130+
},
131+
{
132+
test: /\.js$/,
133+
loader: require.resolve('source-map-loader'),
128134
enforce: 'pre',
129-
use: [
130-
{
131-
options: {
132-
formatter: eslintFormatter,
133-
eslintPath: require.resolve('eslint'),
134-
// @remove-on-eject-begin
135-
baseConfig: {
136-
extends: [require.resolve('eslint-config-react-app')],
137-
},
138-
ignore: false,
139-
useEslintrc: false,
140-
// @remove-on-eject-end
141-
},
142-
loader: require.resolve('eslint-loader'),
143-
},
144-
],
145135
include: paths.appSrc,
146136
},
147137
{
@@ -160,6 +150,12 @@ module.exports = {
160150
name: 'static/media/[name].[hash:8].[ext]',
161151
},
162152
},
153+
// Compile .tsx?
154+
{
155+
test: /\.(ts|tsx)$/,
156+
include: paths.appSrc,
157+
loader: require.resolve('ts-loader'),
158+
},
163159
// Process JS with Babel.
164160
{
165161
test: /\.(js|jsx|mjs)$/,

Diff for: packages/react-scripts/config/webpack.config.prod.js

+15-21
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
1616
const ManifestPlugin = require('webpack-manifest-plugin');
1717
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1818
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
19-
const eslintFormatter = require('react-dev-utils/eslintFormatter');
2019
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2120
const paths = require('./paths');
2221
const getClientEnvironment = require('./env');
@@ -96,7 +95,7 @@ module.exports = {
9695
// https://github.com/facebookincubator/create-react-app/issues/290
9796
// `web` extension prefixes have been added for better support
9897
// for React Native Web.
99-
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
98+
extensions: ['.web.ts', '.ts', '.web.tsx', '.tsx', '.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
10099
alias: {
101100
// @remove-on-eject-begin
102101
// Resolve Babel runtime relative to react-scripts.
@@ -130,26 +129,15 @@ module.exports = {
130129
// First, run the linter.
131130
// It's important to do this before Babel processes the JS.
132131
{
133-
test: /\.(js|jsx|mjs)$/,
132+
test: /\.(ts|tsx)$/,
133+
loader: require.resolve('tslint-loader'),
134+
enforce: 'pre',
135+
include: paths.appSrc,
136+
},
137+
{
138+
test: /\.js$/,
139+
loader: require.resolve('source-map-loader'),
134140
enforce: 'pre',
135-
use: [
136-
{
137-
options: {
138-
formatter: eslintFormatter,
139-
eslintPath: require.resolve('eslint'),
140-
// @remove-on-eject-begin
141-
// TODO: consider separate config for production,
142-
// e.g. to enable no-console and no-debugger only in production.
143-
baseConfig: {
144-
extends: [require.resolve('eslint-config-react-app')],
145-
},
146-
ignore: false,
147-
useEslintrc: false,
148-
// @remove-on-eject-end
149-
},
150-
loader: require.resolve('eslint-loader'),
151-
},
152-
],
153141
include: paths.appSrc,
154142
},
155143
{
@@ -167,6 +155,12 @@ module.exports = {
167155
name: 'static/media/[name].[hash:8].[ext]',
168156
},
169157
},
158+
//Compile .tsx?
159+
{
160+
test: /\.(ts|tsx)$/,
161+
include: paths.appSrc,
162+
loader: require.resolve('ts-loader')
163+
},
170164
// Process JS with Babel.
171165
{
172166
test: /\.(js|jsx|mjs)$/,
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import * as React from 'react';
9+
import * as ReactDOM from 'react-dom';
10+
import App from './App';
11+
12+
ReactDOM.render(<App />, document.getElementById('root'));
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "build/dist",
4+
"module": "esnext",
5+
"target": "es5",
6+
"lib": ["es6", "dom"],
7+
"sourceMap": true,
8+
"allowJs": true,
9+
"jsx": "react",
10+
"moduleResolution": "node",
11+
"rootDir": "src",
12+
"forceConsistentCasingInFileNames": true,
13+
"noImplicitReturns": true,
14+
"noImplicitThis": true,
15+
"noImplicitAny": true,
16+
"strictNullChecks": true,
17+
"suppressImplicitAnyIndexErrors": true,
18+
"noUnusedLocals": true
19+
},
20+
"exclude": [
21+
"node_modules",
22+
"build",
23+
"scripts",
24+
"acceptance-tests",
25+
"webpack",
26+
"jest",
27+
"src/setupTests.ts",
28+
"config",
29+
"integration"
30+
]
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs"
5+
}
6+
}
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"extends": ["tslint-react"],
3+
"rules": {
4+
"align": [
5+
true,
6+
"parameters",
7+
"arguments",
8+
"statements"
9+
],
10+
"ban": false,
11+
"class-name": true,
12+
"comment-format": [
13+
true,
14+
"check-space"
15+
],
16+
"curly": true,
17+
"eofline": false,
18+
"forin": true,
19+
"indent": [ true, "spaces" ],
20+
"interface-name": [true, "never-prefix"],
21+
"jsdoc-format": true,
22+
"jsx-no-lambda": false,
23+
"jsx-no-multiline-js": false,
24+
"label-position": true,
25+
"max-line-length": [ true, 120 ],
26+
"member-ordering": [
27+
true,
28+
"public-before-private",
29+
"static-before-instance",
30+
"variables-before-functions"
31+
],
32+
"no-any": true,
33+
"no-arg": true,
34+
"no-bitwise": true,
35+
"no-console": [
36+
true,
37+
"log",
38+
"error",
39+
"debug",
40+
"info",
41+
"time",
42+
"timeEnd",
43+
"trace"
44+
],
45+
"no-consecutive-blank-lines": true,
46+
"no-construct": true,
47+
"no-debugger": true,
48+
"no-duplicate-variable": true,
49+
"no-empty": true,
50+
"no-eval": true,
51+
"no-shadowed-variable": true,
52+
"no-string-literal": true,
53+
"no-switch-case-fall-through": true,
54+
"no-trailing-whitespace": false,
55+
"no-unused-expression": true,
56+
"no-use-before-declare": true,
57+
"one-line": [
58+
true,
59+
"check-catch",
60+
"check-else",
61+
"check-open-brace",
62+
"check-whitespace"
63+
],
64+
"quotemark": [true, "single", "jsx-double"],
65+
"radix": true,
66+
"semicolon": [true, "always"],
67+
"switch-default": true,
68+
69+
"trailing-comma": [false],
70+
71+
"triple-equals": [ true, "allow-null-check" ],
72+
"typedef": [
73+
true,
74+
"parameter",
75+
"property-declaration"
76+
],
77+
"typedef-whitespace": [
78+
true,
79+
{
80+
"call-signature": "nospace",
81+
"index-signature": "nospace",
82+
"parameter": "nospace",
83+
"property-declaration": "nospace",
84+
"variable-declaration": "nospace"
85+
}
86+
],
87+
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
88+
"whitespace": [
89+
true,
90+
"check-branch",
91+
"check-decl",
92+
"check-module",
93+
"check-operator",
94+
"check-separator",
95+
"check-type",
96+
"check-typecast"
97+
]
98+
}
99+
}

0 commit comments

Comments
 (0)