Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6364bbf

Browse files
authored
Remove react-scripts type reference on eject (#5611)
* Remove react-scripts type reference on eject * Check for env file * Check eject for typescript * Shuffle appTypeDeclarations * Append internal types on eject * Ensure lib is published for types * Adjust comment * Don't add a bunch of new lines * File should exist and not be deleted * Add debug * Set file explicitly * Revert "Set file explicitly" This reverts commit bcd58a36cbd08a71af50b037d8f1fae6c595fb4e. * Copy file before destroying ourselves * Revert "Add debug" This reverts commit 0068ba81c6d79d99788877c9e1b618acd7412dce.
1 parent 2a7fd5a commit 6364bbf

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

‎packages/react-scripts/config/paths.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ module.exports = {
8484
appPackageJson: resolveApp('package.json'),
8585
appSrc: resolveApp('src'),
8686
appTsConfig: resolveApp('tsconfig.json'),
87-
appTypeDeclarations: resolveApp('src/react-app-env.d.ts'),
8887
yarnLockFile: resolveApp('yarn.lock'),
8988
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
9089
proxySetup: resolveApp('src/setupProxy.js'),
@@ -107,7 +106,6 @@ module.exports = {
107106
appPackageJson: resolveApp('package.json'),
108107
appSrc: resolveApp('src'),
109108
appTsConfig: resolveApp('tsconfig.json'),
110-
appTypeDeclarations: resolveApp('src/react-app-env.d.ts'),
111109
yarnLockFile: resolveApp('yarn.lock'),
112110
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
113111
proxySetup: resolveApp('src/setupProxy.js'),
@@ -117,6 +115,8 @@ module.exports = {
117115
// These properties only exist before ejecting:
118116
ownPath: resolveOwn('.'),
119117
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
118+
appTypeDeclarations: resolveApp('src/react-app-env.d.ts'),
119+
ownTypeDeclarations: resolveOwn('lib/react-app.d.ts'),
120120
};
121121

122122
const ownPackageJson = require('../package.json');
@@ -140,7 +140,6 @@ if (
140140
appPackageJson: resolveOwn('package.json'),
141141
appSrc: resolveOwn('template/src'),
142142
appTsConfig: resolveOwn('template/tsconfig.json'),
143-
appTypeDeclarations: resolveOwn('template/src/react-app-env.d.ts'),
144143
yarnLockFile: resolveOwn('template/yarn.lock'),
145144
testsSetup: resolveModule(resolveOwn, 'template/src/setupTests'),
146145
proxySetup: resolveOwn('template/src/setupProxy.js'),
@@ -150,6 +149,8 @@ if (
150149
// These properties only exist before ejecting:
151150
ownPath: resolveOwn('.'),
152151
ownNodeModules: resolveOwn('node_modules'),
152+
appTypeDeclarations: resolveOwn('template/src/react-app-env.d.ts'),
153+
ownTypeDeclarations: resolveOwn('lib/react-app.d.ts'),
153154
};
154155
}
155156
// @remove-on-eject-end
File renamed without changes.

‎packages/react-scripts/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"files": [
1414
"bin",
1515
"config",
16+
"lib",
1617
"scripts",
1718
"template",
1819
"template-typescript",
@@ -21,7 +22,7 @@
2122
"bin": {
2223
"react-scripts": "./bin/react-scripts.js"
2324
},
24-
"types": "./config/react-app.d.ts",
25+
"types": "./lib/react-app.d.ts",
2526
"dependencies": {
2627
"@babel/core": "7.1.0",
2728
"@svgr/webpack": "2.4.1",

‎packages/react-scripts/scripts/eject.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,33 @@ inquirer
223223
);
224224
console.log();
225225

226+
if (fs.existsSync(paths.appTypeDeclarations)) {
227+
try {
228+
// Read app declarations file
229+
let content = fs.readFileSync(paths.appTypeDeclarations, 'utf8');
230+
const ownContent =
231+
fs.readFileSync(paths.ownTypeDeclarations, 'utf8').trim() + os.EOL;
232+
233+
// Remove react-scripts reference since they're getting a copy of the types in their project
234+
content =
235+
content
236+
// Remove react-scripts types
237+
.replace(
238+
/^\s*\/\/\/\s*<reference\s+types.+?"react-scripts".*\/>.*(?:\n|$)/gm,
239+
''
240+
)
241+
.trim() + os.EOL;
242+
243+
fs.writeFileSync(
244+
paths.appTypeDeclarations,
245+
(ownContent + os.EOL + content).trim() + os.EOL
246+
);
247+
} catch (e) {
248+
// It's not essential that this succeeds, the TypeScript user should
249+
// be able to re-create these types with ease.
250+
}
251+
}
252+
226253
// "Don't destroy what isn't ours"
227254
if (ownPath.indexOf(appPath) === 0) {
228255
try {

‎tasks/e2e-installs.sh‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,27 @@ exists node_modules/react-scripts
170170
exists node_modules/typescript
171171
exists src/index.tsx
172172
exists tsconfig.json
173+
exists src/react-app-env.d.ts
173174
checkTypeScriptDependencies
174175

175176
# Check that the TypeScript template passes smoke tests, build, and normal tests
176177
yarn start --smoke-test
177178
yarn build
178179
CI=true yarn test
179180

181+
# Check eject behaves and works
182+
183+
# Eject...
184+
echo yes | npm run eject
185+
186+
# Ensure env file still exists
187+
exists src/react-app-env.d.ts
188+
189+
# Check that the TypeScript template passes ejected smoke tests, build, and normal tests
190+
yarn start --smoke-test
191+
yarn build
192+
CI=true yarn test
193+
180194
# ******************************************************************************
181195
# Test --scripts-version with a tarball url
182196
# ******************************************************************************

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /