Skip to content

Commit 19a8a96

Browse files
committed
Fix CI on Windows by writing .cmd file back
1 parent 89f9b66 commit 19a8a96

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/react-scripts/scripts/eject.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,35 @@ inquirer
237237
}
238238

239239
if (fs.existsSync(paths.yarnLockFile)) {
240+
const windowsCmdFilePath = path.join(
241+
appPath,
242+
'node_modules',
243+
'.bin',
244+
'react-scripts.cmd'
245+
);
246+
let windowsCmdFileContent;
247+
if (process.platform === 'win32') {
248+
// https://github.com/facebookincubator/create-react-app/pull/3806#issuecomment-357781035
249+
// Yarn is diligent about cleaning up after itself, but this causes the react-scripts.cmd file
250+
// to be deleted while it is running. This trips Windows up after the eject completes.
251+
// We'll read the batch file and later "write it back" to match npm behavior.
252+
try {
253+
windowsCmdFileContent = fs.readFileSync(windowsCmdFilePath);
254+
} catch (err) {
255+
// If this fails we're not worse off than if we didn't try to fix it.
256+
}
257+
}
258+
240259
console.log(cyan('Running yarn...'));
241260
spawnSync('yarnpkg', ['--cwd', process.cwd()], { stdio: 'inherit' });
261+
262+
if (windowsCmdFileContent && !fs.existsSync(windowsCmdFilePath)) {
263+
try {
264+
fs.writeFileSync(windowsCmdFilePath, windowsCmdFileContent);
265+
} catch (err) {
266+
// If this fails we're not worse off than if we didn't try to fix it.
267+
}
268+
}
242269
} else {
243270
console.log(cyan('Running npm install...'));
244271
spawnSync('npm', ['install', '--loglevel', 'error'], {

0 commit comments

Comments
 (0)