From cd2edf7cca0d5cda12ad09b24e32083802f733bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magn=C3=BAs=20=C3=96rn=20Gylfason?= Date: Fri, 30 Jun 2017 21:25:01 +0000 Subject: [PATCH 1/3] don't delete error logs --- packages/create-react-app/createReactApp.js | 34 +++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 4509b49788d..0ffa9e9ab6c 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -51,6 +51,12 @@ const hyperquest = require('hyperquest'); const packageJson = require('./package.json'); +/* +These files should be allowed to remain on a failed install, +but then silently removed during the next create. +*/ +const remnantFiles = ['npm-debug.log', 'yarn-error.log', 'yarn-debug.log']; + let projectName; const program = new commander.Command(packageJson.name) @@ -319,22 +325,12 @@ function run( console.log(); // On 'exit' we will delete these files from target directory. - const knownGeneratedFiles = [ - 'package.json', - 'npm-debug.log', - 'yarn-error.log', - 'yarn-debug.log', - 'node_modules', - ]; + const knownGeneratedFiles = ['package.json', 'node_modules']; const currentFiles = fs.readdirSync(path.join(root)); currentFiles.forEach(file => { knownGeneratedFiles.forEach(fileToMatch => { - // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files - // and the rest of knownGeneratedFiles. - if ( - (fileToMatch.match(/.log/g) && file.indexOf(fileToMatch) === 0) || - file === fileToMatch - ) { + // This remove all of knownGeneratedFiles. + if (file === fileToMatch) { console.log(`Deleting generated file... ${chalk.cyan(file)}`); fs.removeSync(path.join(root, file)); } @@ -569,9 +565,21 @@ function setCaretRangeForRuntimeDeps(packageName) { } // If project only contains files generated by GH, it’s safe. +// Also, if project contains remnant error logs from a previous +// installation, lets remove them now. // We also special case IJ-based products .idea because it integrates with CRA: // https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094 function isSafeToCreateProjectIn(root) { + const currentFiles = fs.readdirSync(path.join(root)); + currentFiles.forEach(file => { + remnantFiles.forEach(fileToMatch => { + // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files + if (fileToMatch.match(/.log/g) && file.indexOf(fileToMatch) === 0) { + fs.removeSync(path.join(root, file)); + } + }); + }); + const validFiles = [ '.DS_Store', 'Thumbs.db', From daa2de53b7fc7f58174534be5ef9679183e7bfa9 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 20 Jan 2018 18:45:09 +0000 Subject: [PATCH 2/3] Style nit --- packages/create-react-app/createReactApp.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 5e483b9e5fc..cde4c982ada 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -52,10 +52,8 @@ const os = require('os'); const packageJson = require('./package.json'); -/* -These files should be allowed to remain on a failed install, -but then silently removed during the next create. -*/ +// These files should be allowed to remain on a failed install, +// but then silently removed during the next create. const remnantFiles = ['npm-debug.log', 'yarn-error.log', 'yarn-debug.log']; let projectName; From 4aab51ee88208e85a6da3ce110d03a8463ea1fc6 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 20 Jan 2018 18:58:56 +0000 Subject: [PATCH 3/3] Fix the logic --- packages/create-react-app/createReactApp.js | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index cde4c982ada..10935928b4c 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -54,7 +54,11 @@ const packageJson = require('./package.json'); // These files should be allowed to remain on a failed install, // but then silently removed during the next create. -const remnantFiles = ['npm-debug.log', 'yarn-error.log', 'yarn-debug.log']; +const errorLogFilePatterns = [ + 'npm-debug.log', + 'yarn-error.log', + 'yarn-debug.log', +]; let projectName; @@ -363,7 +367,7 @@ function run( if (!remainingFiles.length) { // Delete target folder if empty console.log( - `Deleting ${chalk.cyan(`${appName} /`)} from ${chalk.cyan( + `Deleting ${chalk.cyan(`${appName}/`)} from ${chalk.cyan( path.resolve(root, '..') )}` ); @@ -630,8 +634,12 @@ function isSafeToCreateProjectIn(root, name) { const conflicts = fs .readdirSync(root) - .filter(file => !validFiles.includes(file)); - + .filter(file => !validFiles.includes(file)) + // Don't treat log files from previous installation as conflicts + .filter( + file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0) + ); + if (conflicts.length > 0) { console.log( `The directory ${chalk.green(name)} contains files that could conflict:` @@ -648,17 +656,17 @@ function isSafeToCreateProjectIn(root, name) { return false; } - // remove any remnant files from a previous installation + // Remove any remnant files from a previous installation const currentFiles = fs.readdirSync(path.join(root)); currentFiles.forEach(file => { - remnantFiles.forEach(fileToMatch => { + errorLogFilePatterns.forEach(errorLogFilePattern => { // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files - if (fileToMatch.match(/.log/g) && file.indexOf(fileToMatch) === 0) { + if (file.indexOf(errorLogFilePattern) === 0) { fs.removeSync(path.join(root, file)); } }); }); - return true + return true; } function getProxy() {