Skip to content

Use a better* solution for the missing CMD file issue on Windows #3829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,23 @@ inquirer
// https://github.com/facebookincubator/create-react-app/pull/3806#issuecomment-357781035
// Yarn is diligent about cleaning up after itself, but this causes the react-scripts.cmd file
// to be deleted while it is running. This trips Windows up after the eject completes.
// We'll read the batch file and later "write it back" to match npm behavior.
// We'll reduce the the batch file to a single line to avoid CMD tripping over the file going missing.
try {
windowsCmdFileContent = fs.readFileSync(windowsCmdFilePath);
windowsCmdFileContent = fs
.readFileSync(windowsCmdFilePath)
.toString('ansi');
windowsCmdFileContent =
windowsCmdFileContent
.replace(/(\()\r\n\s*|\s*\r\n\s*(\))/g, '$1$2')
.replace(/\s*\r\n\s*/g, ' & ') + ' & EXIT';
fs.writeFileSync(windowsCmdFilePath, windowsCmdFileContent);
} catch (err) {
// If this fails we're not worse off than if we didn't try to fix it.
}
}

console.log(cyan('Running yarn...'));
spawnSync('yarnpkg', ['--cwd', process.cwd()], { stdio: 'inherit' });

if (windowsCmdFileContent && !fs.existsSync(windowsCmdFilePath)) {
try {
fs.writeFileSync(windowsCmdFilePath, windowsCmdFileContent);
} catch (err) {
// If this fails we're not worse off than if we didn't try to fix it.
}
}
} else {
console.log(cyan('Running npm install...'));
spawnSync('npm', ['install', '--loglevel', 'error'], {
Expand Down