mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-05-12 11:51:04 +08:00
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.
This commit is contained in:
27
packages/react-scripts/scripts/eject.js
vendored
27
packages/react-scripts/scripts/eject.js
vendored
@@ -223,6 +223,33 @@ inquirer
|
||||
);
|
||||
console.log();
|
||||
|
||||
if (fs.existsSync(paths.appTypeDeclarations)) {
|
||||
try {
|
||||
// Read app declarations file
|
||||
let content = fs.readFileSync(paths.appTypeDeclarations, 'utf8');
|
||||
const ownContent =
|
||||
fs.readFileSync(paths.ownTypeDeclarations, 'utf8').trim() + os.EOL;
|
||||
|
||||
// Remove react-scripts reference since they're getting a copy of the types in their project
|
||||
content =
|
||||
content
|
||||
// Remove react-scripts types
|
||||
.replace(
|
||||
/^\s*\/\/\/\s*<reference\s+types.+?"react-scripts".*\/>.*(?:\n|$)/gm,
|
||||
''
|
||||
)
|
||||
.trim() + os.EOL;
|
||||
|
||||
fs.writeFileSync(
|
||||
paths.appTypeDeclarations,
|
||||
(ownContent + os.EOL + content).trim() + os.EOL
|
||||
);
|
||||
} catch (e) {
|
||||
// It's not essential that this succeeds, the TypeScript user should
|
||||
// be able to re-create these types with ease.
|
||||
}
|
||||
}
|
||||
|
||||
// "Don't destroy what isn't ours"
|
||||
if (ownPath.indexOf(appPath) === 0) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user