Skip to content

Commit 18e56da

Browse files
bmuenzenmeyermrmckeb
authored andcommitted
fix: proactively append to .gitignore during init (facebook#8028)
1 parent 30eaab4 commit 18e56da

File tree

1 file changed

+9
-12
lines changed
  • packages/react-scripts/scripts

1 file changed

+9
-12
lines changed

Diff for: packages/react-scripts/scripts/init.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,20 @@ module.exports = function(
190190
}
191191
}
192192

193-
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
194-
// See: https://github.com/npm/npm/issues/1862
195-
try {
193+
const gitignoreExists = fs.existsSync(path.join(appPath, '.gitignore'));
194+
if (gitignoreExists) {
195+
// Append if there's already a `.gitignore` file there
196+
const data = fs.readFileSync(path.join(appPath, 'gitignore'));
197+
fs.appendFileSync(path.join(appPath, '.gitignore'), data);
198+
fs.unlinkSync(path.join(appPath, 'gitignore'));
199+
} else {
200+
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
201+
// See: https://github.com/npm/npm/issues/1862
196202
fs.moveSync(
197203
path.join(appPath, 'gitignore'),
198204
path.join(appPath, '.gitignore'),
199205
[]
200206
);
201-
} catch (err) {
202-
// Append if there's already a `.gitignore` file there
203-
if (err.code === 'EEXIST') {
204-
const data = fs.readFileSync(path.join(appPath, 'gitignore'));
205-
fs.appendFileSync(path.join(appPath, '.gitignore'), data);
206-
fs.unlinkSync(path.join(appPath, 'gitignore'));
207-
} else {
208-
throw err;
209-
}
210207
}
211208

212209
let command;

0 commit comments

Comments
 (0)