mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-05-08 08:04:08 +08:00
Refine how TypeScript env types are handled (#5593)
* Specify types in package * Do not remove types file on eject * Stop copying types into generated project * Reference react and react-dom * Reference node types * Install node types as well * Restore copying * Add Node to the list of installed types * Reference Jest types * Remove jest types from install * Remove jest from CRA install * Remove Jest reference and let user do this themselves * Stop copying types file * Add types key to package.json * Add appTypeDeclarations and create when missing * Rename declarations file * Add Jest back to install instructions * Minimize diff
This commit is contained in:
@@ -238,21 +238,13 @@ function verifyTypeScriptSetup() {
|
||||
writeJson(paths.appTsConfig, appTsConfig);
|
||||
}
|
||||
|
||||
// Copy type declarations associated with this version of `react-scripts`
|
||||
const declaredTypes = path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'config',
|
||||
'react-app.d.ts'
|
||||
);
|
||||
const declaredTypesContent = fs
|
||||
.readFileSync(declaredTypes, 'utf8')
|
||||
.replace(/\/\/ @remove-file-on-eject\r?\n/, '');
|
||||
fs.writeFileSync(
|
||||
path.resolve(paths.appSrc, 'react-app.d.ts'),
|
||||
declaredTypesContent
|
||||
);
|
||||
// Reference `react-scripts` types
|
||||
if (!fs.existsSync(paths.appTypeDeclarations)) {
|
||||
fs.writeFileSync(
|
||||
paths.appTypeDeclarations,
|
||||
`/// <reference types="react-scripts" />${os.EOL}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = verifyTypeScriptSetup;
|
||||
|
||||
Reference in New Issue
Block a user