@@ -52,6 +52,14 @@ const os = require('os');
52
52
53
53
const packageJson = require ( './package.json' ) ;
54
54
55
+ // These files should be allowed to remain on a failed install,
56
+ // but then silently removed during the next create.
57
+ const errorLogFilePatterns = [
58
+ 'npm-debug.log' ,
59
+ 'yarn-error.log' ,
60
+ 'yarn-debug.log' ,
61
+ ] ;
62
+
55
63
let projectName ;
56
64
57
65
const program = new commander . Command ( packageJson . name )
@@ -344,22 +352,12 @@ function run(
344
352
console . log ( ) ;
345
353
346
354
// On 'exit' we will delete these files from target directory.
347
- const knownGeneratedFiles = [
348
- 'package.json' ,
349
- 'npm-debug.log' ,
350
- 'yarn-error.log' ,
351
- 'yarn-debug.log' ,
352
- 'node_modules' ,
353
- ] ;
355
+ const knownGeneratedFiles = [ 'package.json' , 'node_modules' ] ;
354
356
const currentFiles = fs . readdirSync ( path . join ( root ) ) ;
355
357
currentFiles . forEach ( file => {
356
358
knownGeneratedFiles . forEach ( fileToMatch => {
357
- // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
358
- // and the rest of knownGeneratedFiles.
359
- if (
360
- ( fileToMatch . match ( / .l o g / g) && file . indexOf ( fileToMatch ) === 0 ) ||
361
- file === fileToMatch
362
- ) {
359
+ // This remove all of knownGeneratedFiles.
360
+ if ( file === fileToMatch ) {
363
361
console . log ( `Deleting generated file... ${ chalk . cyan ( file ) } ` ) ;
364
362
fs . removeSync ( path . join ( root , file ) ) ;
365
363
}
@@ -369,7 +367,7 @@ function run(
369
367
if ( ! remainingFiles . length ) {
370
368
// Delete target folder if empty
371
369
console . log (
372
- `Deleting ${ chalk . cyan ( `${ appName } /` ) } from ${ chalk . cyan (
370
+ `Deleting ${ chalk . cyan ( `${ appName } /` ) } from ${ chalk . cyan (
373
371
path . resolve ( root , '..' )
374
372
) } `
375
373
) ;
@@ -608,6 +606,8 @@ function setCaretRangeForRuntimeDeps(packageName) {
608
606
}
609
607
610
608
// If project only contains files generated by GH, it’s safe.
609
+ // Also, if project contains remnant error logs from a previous
610
+ // installation, lets remove them now.
611
611
// We also special case IJ-based products .idea because it integrates with CRA:
612
612
// https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094
613
613
function isSafeToCreateProjectIn ( root , name ) {
@@ -634,24 +634,39 @@ function isSafeToCreateProjectIn(root, name) {
634
634
635
635
const conflicts = fs
636
636
. readdirSync ( root )
637
- . filter ( file => ! validFiles . includes ( file ) ) ;
638
- if ( conflicts . length < 1 ) {
639
- return true ;
640
- }
637
+ . filter ( file => ! validFiles . includes ( file ) )
638
+ // Don't treat log files from previous installation as conflicts
639
+ . filter (
640
+ file => ! errorLogFilePatterns . some ( pattern => file . indexOf ( pattern ) === 0 )
641
+ ) ;
641
642
642
- console . log (
643
- `The directory ${ chalk . green ( name ) } contains files that could conflict:`
644
- ) ;
645
- console . log ( ) ;
646
- for ( const file of conflicts ) {
647
- console . log ( ` ${ file } ` ) ;
643
+ if ( conflicts . length > 0 ) {
644
+ console . log (
645
+ `The directory ${ chalk . green ( name ) } contains files that could conflict:`
646
+ ) ;
647
+ console . log ( ) ;
648
+ for ( const file of conflicts ) {
649
+ console . log ( ` ${ file } ` ) ;
650
+ }
651
+ console . log ( ) ;
652
+ console . log (
653
+ 'Either try using a new directory name, or remove the files listed above.'
654
+ ) ;
655
+
656
+ return false ;
648
657
}
649
- console . log ( ) ;
650
- console . log (
651
- 'Either try using a new directory name, or remove the files listed above.'
652
- ) ;
653
658
654
- return false ;
659
+ // Remove any remnant files from a previous installation
660
+ const currentFiles = fs . readdirSync ( path . join ( root ) ) ;
661
+ currentFiles . forEach ( file => {
662
+ errorLogFilePatterns . forEach ( errorLogFilePattern => {
663
+ // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
664
+ if ( file . indexOf ( errorLogFilePattern ) === 0 ) {
665
+ fs . removeSync ( path . join ( root , file ) ) ;
666
+ }
667
+ } ) ;
668
+ } ) ;
669
+ return true ;
655
670
}
656
671
657
672
function getProxy ( ) {
0 commit comments