Skip to content

Commit 777e70a

Browse files
OwenFloodJohnNilsson
authored andcommitted
List conflicting files when initializing app (#2785)
* change error wording and list conflicting files when initializing app * update code * Update createReactApp.js
1 parent c3f4b7c commit 777e70a

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

packages/create-react-app/createReactApp.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,7 @@ function createApp(name, verbose, version, template) {
143143

144144
checkAppName(appName);
145145
fs.ensureDirSync(name);
146-
if (!isSafeToCreateProjectIn(root)) {
147-
console.log(
148-
`The directory ${chalk.green(name)} contains files that could conflict.`
149-
);
150-
console.log('Try using a new directory name.');
146+
if (!isSafeToCreateProjectIn(root, name)) {
151147
process.exit(1);
152148
}
153149

@@ -571,7 +567,7 @@ function setCaretRangeForRuntimeDeps(packageName) {
571567
// If project only contains files generated by GH, it’s safe.
572568
// We also special case IJ-based products .idea because it integrates with CRA:
573569
// https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094
574-
function isSafeToCreateProjectIn(root) {
570+
function isSafeToCreateProjectIn(root, name) {
575571
const validFiles = [
576572
'.DS_Store',
577573
'Thumbs.db',
@@ -585,7 +581,28 @@ function isSafeToCreateProjectIn(root) {
585581
'.hgignore',
586582
'.hgcheck',
587583
];
588-
return fs.readdirSync(root).every(file => validFiles.indexOf(file) >= 0);
584+
console.log();
585+
586+
const conflicts = fs
587+
.readdirSync(root)
588+
.filter(file => !validFiles.includes(file));
589+
if (conflicts.length < 1) {
590+
return true;
591+
}
592+
593+
console.log(
594+
`The directory ${chalk.green(name)} contains files that could conflict:`
595+
);
596+
console.log();
597+
for (const file of conflicts) {
598+
console.log(` ${file}`);
599+
}
600+
console.log();
601+
console.log(
602+
'Either try using a new directory name, or remove the files listed above.'
603+
);
604+
605+
return false;
589606
}
590607

591608
function checkIfOnline(useYarn) {

0 commit comments

Comments
 (0)