From 61cfcecc1719109dfd30d35e62379809ca069cdb Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Mon, 1 May 2017 10:18:36 -0400 Subject: [PATCH 01/11] when build is failing due to ESLint errors, filter warnings out --- packages/react-scripts/scripts/build.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index fe4ec959d4d..dd20e5ea760 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -90,14 +90,14 @@ function build(previousFileSizes) { if (stats.compilation.errors.length) { printErrors('Failed to compile.', stats.compilation.errors); process.exit(1); - } - - if (process.env.CI && stats.compilation.warnings.length) { - printErrors( - 'Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.', - stats.compilation.warnings - ); - process.exit(1); + } else { + if (stats.compilation.warnings.length) { + printErrors( + 'Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.', + stats.compilation.warnings + ); + if (process.env.CI) process.exit(1); + } } console.log(chalk.green('Compiled successfully.')); From bdabc3e1181a797573295e77f5b2e207ce95b143 Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Fri, 5 May 2017 15:52:01 -0400 Subject: [PATCH 02/11] Ejecting should ensure you have clean git status --- packages/react-scripts/scripts/eject.js | 157 +++++++++++++----------- 1 file changed, 85 insertions(+), 72 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index e07a57ba5e7..1aaf8ccfdc8 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -1,4 +1,3 @@ -// @remove-file-on-eject /** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. @@ -9,23 +8,16 @@ */ 'use strict'; -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -const fs = require('fs-extra'); -const path = require('path'); -const spawnSync = require('cross-spawn').sync; -const chalk = require('chalk'); -const prompt = require('react-dev-utils/prompt'); -const paths = require('../config/paths'); -const createJestConfig = require('./utils/createJestConfig'); - -const green = chalk.green; -const cyan = chalk.cyan; +var createJestConfig = require('../utils/createJestConfig'); +var fs = require('fs-extra'); +var path = require('path'); +const { exec, execSync } = require('child_process'); +var paths = require('../config/paths'); +var prompt = require('react-dev-utils/prompt'); +var spawnSync = require('cross-spawn').sync; +var chalk = require('chalk'); +var green = chalk.green; +var cyan = chalk.cyan; prompt( 'Are you sure you want to eject? This action is permanent.', @@ -36,15 +28,38 @@ prompt( process.exit(1); } + function statusSync() { + let stdout = execSync(`git status -s`).toString(); + let status = { dirty: 0, untracked: 0 }; + stdout.trim().split(/\r?\n/).forEach(file => { + if (file.substr(0, 2) === '??') status.untracked++; + else status.dirty++; + }); + return status; + } + const git = fs.existsSync(path.join(process.cwd(), '.git')); + const status = statusSync(); + + if (git && status.dirty) { + console.error( + `Git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}.` + + 'We cannot continue as you would lose all the changes in that file or directory. ' + + 'Please push commit before and run this command again.' + ); + process.exit(1); + } + console.log('Ejecting...'); - const ownPath = paths.ownPath; - const appPath = paths.appPath; + var ownPath = paths.ownPath; + var appPath = paths.appPath; function verifyAbsent(file) { if (fs.existsSync(path.join(appPath, file))) { console.error( - `\`${file}\` already exists in your app folder. We cannot ` + + '`' + + file + + '` already exists in your app folder. We cannot ' + 'continue as you would lose all the changes in that file or directory. ' + 'Please move or delete it (maybe make a copy for backup) and run this ' + 'command again.' @@ -53,42 +68,36 @@ prompt( } } - const folders = ['config', 'config/jest', 'scripts', 'scripts/utils']; - - // Make shallow array of files paths - const files = folders.reduce( - (files, folder) => { - return files.concat( - fs - .readdirSync(path.join(ownPath, folder)) - // set full path - .map(file => path.join(ownPath, folder, file)) - // omit dirs from file list - .filter(file => fs.lstatSync(file).isFile()) - ); - }, - [] - ); + var folders = ['config', path.join('config', 'jest'), 'scripts']; + + var files = [ + path.join('config', 'env.js'), + path.join('config', 'paths.js'), + path.join('config', 'polyfills.js'), + path.join('config', 'webpack.config.dev.js'), + path.join('config', 'webpack.config.prod.js'), + path.join('config', 'jest', 'cssTransform.js'), + path.join('config', 'jest', 'fileTransform.js'), + path.join('scripts', 'build.js'), + path.join('scripts', 'start.js'), + path.join('scripts', 'test.js'), + ]; // Ensure that the app folder is clean and we won't override any files folders.forEach(verifyAbsent); files.forEach(verifyAbsent); - console.log(); - console.log(cyan(`Copying files into ${appPath}`)); - - folders.forEach(folder => { + // Copy the files over + folders.forEach(function(folder) { fs.mkdirSync(path.join(appPath, folder)); }); - files.forEach(file => { - let content = fs.readFileSync(file, 'utf8'); - - // Skip flagged files - if (content.match(/\/\/ @remove-file-on-eject/)) { - return; - } - content = content + console.log(); + console.log(cyan('Copying files into ' + appPath)); + files.forEach(function(file) { + console.log(' Adding ' + cyan(file) + ' to the project'); + var content = fs + .readFileSync(path.join(ownPath, file), 'utf8') // Remove dead code from .js files on eject .replace( /\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/mg, @@ -100,45 +109,53 @@ prompt( '' ) .trim() + '\n'; - console.log(` Adding ${cyan(file.replace(ownPath, ''))} to the project`); - fs.writeFileSync(file.replace(ownPath, appPath), content); + fs.writeFileSync(path.join(appPath, file), content); }); console.log(); - const ownPackage = require(path.join(ownPath, 'package.json')); - const appPackage = require(path.join(appPath, 'package.json')); + var ownPackage = require(path.join(ownPath, 'package.json')); + var appPackage = require(path.join(appPath, 'package.json')); + var babelConfig = JSON.parse( + fs.readFileSync(path.join(ownPath, 'babelrc'), 'utf8') + ); + var eslintConfig = JSON.parse( + fs.readFileSync(path.join(ownPath, 'eslintrc'), 'utf8') + ); console.log(cyan('Updating the dependencies')); - const ownPackageName = ownPackage.name; + var ownPackageName = ownPackage.name; if (appPackage.devDependencies[ownPackageName]) { - console.log(` Removing ${cyan(ownPackageName)} from devDependencies`); + console.log(' Removing ' + cyan(ownPackageName) + ' from devDependencies'); delete appPackage.devDependencies[ownPackageName]; } if (appPackage.dependencies[ownPackageName]) { - console.log(` Removing ${cyan(ownPackageName)} from dependencies`); + console.log(' Removing ' + cyan(ownPackageName) + ' from dependencies'); delete appPackage.dependencies[ownPackageName]; } - Object.keys(ownPackage.dependencies).forEach(key => { + Object.keys(ownPackage.dependencies).forEach(function(key) { // For some reason optionalDependencies end up in dependencies after install if (ownPackage.optionalDependencies[key]) { return; } - console.log(` Adding ${cyan(key)} to devDependencies`); + console.log(' Adding ' + cyan(key) + ' to devDependencies'); appPackage.devDependencies[key] = ownPackage.dependencies[key]; }); console.log(); console.log(cyan('Updating the scripts')); delete appPackage.scripts['eject']; - Object.keys(appPackage.scripts).forEach(key => { - Object.keys(ownPackage.bin).forEach(binKey => { - const regex = new RegExp(binKey + ' (\\w+)', 'g'); + Object.keys(appPackage.scripts).forEach(function(key) { + Object.keys(ownPackage.bin).forEach(function(binKey) { + var regex = new RegExp(binKey + ' (\\w+)', 'g'); appPackage.scripts[key] = appPackage.scripts[key].replace( regex, 'node scripts/$1.js' ); console.log( - ` Replacing ${cyan(`"${binKey} ${key}"`)} with ${cyan(`"node scripts/${key}.js"`)}` + ' Replacing ' + + cyan('"' + binKey + ' ' + key + '"') + + ' with ' + + cyan('"node scripts/' + key + '.js"') ); }); }); @@ -146,7 +163,7 @@ prompt( console.log(); console.log(cyan('Configuring package.json')); // Add Jest config - console.log(` Adding ${cyan('Jest')} configuration`); + console.log(' Adding ' + cyan('Jest') + ' configuration'); appPackage.jest = createJestConfig( filePath => path.posix.join('', filePath), null, @@ -154,16 +171,12 @@ prompt( ); // Add Babel config - console.log(` Adding ${cyan('Babel')} preset`); - appPackage.babel = { - presets: ['react-app'], - }; + console.log(' Adding ' + cyan('Babel') + ' preset'); + appPackage.babel = babelConfig; // Add ESlint config - console.log(` Adding ${cyan('ESLint')} configuration`); - appPackage.eslintConfig = { - extends: 'react-app', - }; + console.log(' Adding ' + cyan('ESLint') + ' configuration'); + appPackage.eslintConfig = eslintConfig; fs.writeFileSync( path.join(appPath, 'package.json'), @@ -175,7 +188,7 @@ prompt( if (ownPath.indexOf(appPath) === 0) { try { // remove react-scripts and react-scripts binaries from app node_modules - Object.keys(ownPackage.bin).forEach(binKey => { + Object.keys(ownPackage.bin).forEach(function(binKey) { fs.removeSync(path.join(appPath, 'node_modules', '.bin', binKey)); }); fs.removeSync(ownPath); From 6ff17aec57a921cbb2a87b6ba99838804d1e2032 Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Fri, 5 May 2017 15:56:47 -0400 Subject: [PATCH 03/11] Ejecting should ensure you have clean git status --- packages/react-scripts/scripts/eject.js | 135 +++++++++++++----------- 1 file changed, 72 insertions(+), 63 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 1aaf8ccfdc8..5d06c26945c 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -1,3 +1,4 @@ +// @remove-file-on-eject /** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. @@ -8,16 +9,24 @@ */ 'use strict'; -var createJestConfig = require('../utils/createJestConfig'); -var fs = require('fs-extra'); -var path = require('path'); +// Makes the script crash on unhandled rejections instead of silently +// ignoring them. In the future, promise rejections that are not handled will +// terminate the Node.js process with a non-zero exit code. +process.on('unhandledRejection', err => { + throw err; +}); + +const fs = require('fs-extra'); +const path = require('path'); +const spawnSync = require('cross-spawn').sync; +const chalk = require('chalk'); +const prompt = require('react-dev-utils/prompt'); const { exec, execSync } = require('child_process'); -var paths = require('../config/paths'); -var prompt = require('react-dev-utils/prompt'); -var spawnSync = require('cross-spawn').sync; -var chalk = require('chalk'); -var green = chalk.green; -var cyan = chalk.cyan; +const paths = require('../config/paths'); +const createJestConfig = require('./utils/createJestConfig'); + +const green = chalk.green; +const cyan = chalk.cyan; prompt( 'Are you sure you want to eject? This action is permanent.', @@ -51,15 +60,13 @@ prompt( console.log('Ejecting...'); - var ownPath = paths.ownPath; - var appPath = paths.appPath; + const ownPath = paths.ownPath; + const appPath = paths.appPath; function verifyAbsent(file) { if (fs.existsSync(path.join(appPath, file))) { console.error( - '`' + - file + - '` already exists in your app folder. We cannot ' + + `\`${file}\` already exists in your app folder. We cannot ` + 'continue as you would lose all the changes in that file or directory. ' + 'Please move or delete it (maybe make a copy for backup) and run this ' + 'command again.' @@ -68,36 +75,42 @@ prompt( } } - var folders = ['config', path.join('config', 'jest'), 'scripts']; - - var files = [ - path.join('config', 'env.js'), - path.join('config', 'paths.js'), - path.join('config', 'polyfills.js'), - path.join('config', 'webpack.config.dev.js'), - path.join('config', 'webpack.config.prod.js'), - path.join('config', 'jest', 'cssTransform.js'), - path.join('config', 'jest', 'fileTransform.js'), - path.join('scripts', 'build.js'), - path.join('scripts', 'start.js'), - path.join('scripts', 'test.js'), - ]; + const folders = ['config', 'config/jest', 'scripts', 'scripts/utils']; + + // Make shallow array of files paths + const files = folders.reduce( + (files, folder) => { + return files.concat( + fs + .readdirSync(path.join(ownPath, folder)) + // set full path + .map(file => path.join(ownPath, folder, file)) + // omit dirs from file list + .filter(file => fs.lstatSync(file).isFile()) + ); + }, + [] + ); // Ensure that the app folder is clean and we won't override any files folders.forEach(verifyAbsent); files.forEach(verifyAbsent); - // Copy the files over - folders.forEach(function(folder) { + console.log(); + console.log(cyan(`Copying files into ${appPath}`)); + + folders.forEach(folder => { fs.mkdirSync(path.join(appPath, folder)); }); - console.log(); - console.log(cyan('Copying files into ' + appPath)); - files.forEach(function(file) { - console.log(' Adding ' + cyan(file) + ' to the project'); - var content = fs - .readFileSync(path.join(ownPath, file), 'utf8') + files.forEach(file => { + let content = fs.readFileSync(file, 'utf8'); + + // Skip flagged files + if (content.match(/\/\/ @remove-file-on-eject/)) { + return; + } + content = content // Remove dead code from .js files on eject .replace( /\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/mg, @@ -109,53 +122,45 @@ prompt( '' ) .trim() + '\n'; - fs.writeFileSync(path.join(appPath, file), content); + console.log(` Adding ${cyan(file.replace(ownPath, ''))} to the project`); + fs.writeFileSync(file.replace(ownPath, appPath), content); }); console.log(); - var ownPackage = require(path.join(ownPath, 'package.json')); - var appPackage = require(path.join(appPath, 'package.json')); - var babelConfig = JSON.parse( - fs.readFileSync(path.join(ownPath, 'babelrc'), 'utf8') - ); - var eslintConfig = JSON.parse( - fs.readFileSync(path.join(ownPath, 'eslintrc'), 'utf8') - ); + const ownPackage = require(path.join(ownPath, 'package.json')); + const appPackage = require(path.join(appPath, 'package.json')); console.log(cyan('Updating the dependencies')); - var ownPackageName = ownPackage.name; + const ownPackageName = ownPackage.name; if (appPackage.devDependencies[ownPackageName]) { - console.log(' Removing ' + cyan(ownPackageName) + ' from devDependencies'); + console.log(` Removing ${cyan(ownPackageName)} from devDependencies`); delete appPackage.devDependencies[ownPackageName]; } if (appPackage.dependencies[ownPackageName]) { - console.log(' Removing ' + cyan(ownPackageName) + ' from dependencies'); + console.log(` Removing ${cyan(ownPackageName)} from dependencies`); delete appPackage.dependencies[ownPackageName]; } - Object.keys(ownPackage.dependencies).forEach(function(key) { + Object.keys(ownPackage.dependencies).forEach(key => { // For some reason optionalDependencies end up in dependencies after install if (ownPackage.optionalDependencies[key]) { return; } - console.log(' Adding ' + cyan(key) + ' to devDependencies'); + console.log(` Adding ${cyan(key)} to devDependencies`); appPackage.devDependencies[key] = ownPackage.dependencies[key]; }); console.log(); console.log(cyan('Updating the scripts')); delete appPackage.scripts['eject']; - Object.keys(appPackage.scripts).forEach(function(key) { - Object.keys(ownPackage.bin).forEach(function(binKey) { - var regex = new RegExp(binKey + ' (\\w+)', 'g'); + Object.keys(appPackage.scripts).forEach(key => { + Object.keys(ownPackage.bin).forEach(binKey => { + const regex = new RegExp(binKey + ' (\\w+)', 'g'); appPackage.scripts[key] = appPackage.scripts[key].replace( regex, 'node scripts/$1.js' ); console.log( - ' Replacing ' + - cyan('"' + binKey + ' ' + key + '"') + - ' with ' + - cyan('"node scripts/' + key + '.js"') + ` Replacing ${cyan(`"${binKey} ${key}"`)} with ${cyan(`"node scripts/${key}.js"`)}` ); }); }); @@ -163,7 +168,7 @@ prompt( console.log(); console.log(cyan('Configuring package.json')); // Add Jest config - console.log(' Adding ' + cyan('Jest') + ' configuration'); + console.log(` Adding ${cyan('Jest')} configuration`); appPackage.jest = createJestConfig( filePath => path.posix.join('', filePath), null, @@ -171,12 +176,16 @@ prompt( ); // Add Babel config - console.log(' Adding ' + cyan('Babel') + ' preset'); - appPackage.babel = babelConfig; + console.log(` Adding ${cyan('Babel')} preset`); + appPackage.babel = { + presets: ['react-app'], + }; // Add ESlint config - console.log(' Adding ' + cyan('ESLint') + ' configuration'); - appPackage.eslintConfig = eslintConfig; + console.log(` Adding ${cyan('ESLint')} configuration`); + appPackage.eslintConfig = { + extends: 'react-app', + }; fs.writeFileSync( path.join(appPath, 'package.json'), @@ -188,7 +197,7 @@ prompt( if (ownPath.indexOf(appPath) === 0) { try { // remove react-scripts and react-scripts binaries from app node_modules - Object.keys(ownPackage.bin).forEach(function(binKey) { + Object.keys(ownPackage.bin).forEach(binKey => { fs.removeSync(path.join(appPath, 'node_modules', '.bin', binKey)); }); fs.removeSync(ownPath); From eca2714f94cbbac7b900facc3962d67551482fc7 Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Fri, 5 May 2017 16:01:09 -0400 Subject: [PATCH 04/11] comment indication --- packages/react-scripts/scripts/eject.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 5d06c26945c..0a28e98a143 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -21,7 +21,7 @@ const path = require('path'); const spawnSync = require('cross-spawn').sync; const chalk = require('chalk'); const prompt = require('react-dev-utils/prompt'); -const { exec, execSync } = require('child_process'); +const { execSync } = require('child_process'); const paths = require('../config/paths'); const createJestConfig = require('./utils/createJestConfig'); @@ -37,6 +37,7 @@ prompt( process.exit(1); } + // Make sure there are no dirty git status function statusSync() { let stdout = execSync(`git status -s`).toString(); let status = { dirty: 0, untracked: 0 }; From 8be4f32176d8e407a576aaaba344f006ea0f22d9 Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Fri, 5 May 2017 18:32:38 -0400 Subject: [PATCH 05/11] fixed es6 const {} issue for version less than node 7 --- packages/react-scripts/scripts/eject.js | 43 +++++++++++++------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 0a28e98a143..95a654ab25a 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -21,7 +21,7 @@ const path = require('path'); const spawnSync = require('cross-spawn').sync; const chalk = require('chalk'); const prompt = require('react-dev-utils/prompt'); -const { execSync } = require('child_process'); +const execSync = require('child_process').execSync; const paths = require('../config/paths'); const createJestConfig = require('./utils/createJestConfig'); @@ -37,26 +37,29 @@ prompt( process.exit(1); } - // Make sure there are no dirty git status - function statusSync() { - let stdout = execSync(`git status -s`).toString(); - let status = { dirty: 0, untracked: 0 }; - stdout.trim().split(/\r?\n/).forEach(file => { - if (file.substr(0, 2) === '??') status.untracked++; - else status.dirty++; - }); - return status; - } const git = fs.existsSync(path.join(process.cwd(), '.git')); - const status = statusSync(); - - if (git && status.dirty) { - console.error( - `Git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}.` + - 'We cannot continue as you would lose all the changes in that file or directory. ' + - 'Please push commit before and run this command again.' - ); - process.exit(1); + + if (git) { + // Make sure there are no dirty git status + function statusSync() { + let stdout = execSync(`git status -s`).toString(); + let status = { dirty: 0, untracked: 0 }; + stdout.trim().split(/\r?\n/).forEach(file => { + if (file.substr(0, 2) === '??') status.untracked++; + else status.dirty++; + }); + return status; + } + + let status = statusSync(); + if (status.dirty) { + console.error( + `Git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}. ` + + 'We cannot continue as you would lose all the changes in that file or directory. ' + + 'Please push commit before and run this command again.' + ); + process.exit(1); + } } console.log('Ejecting...'); From 0d68efe802910897eb9608775c39b18b77fc7e1c Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Fri, 5 May 2017 18:38:46 -0400 Subject: [PATCH 06/11] fix no-inner-declarations of function --- packages/react-scripts/scripts/eject.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 95a654ab25a..b47a760881a 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -37,20 +37,20 @@ prompt( process.exit(1); } + // Make sure there are no dirty git status const git = fs.existsSync(path.join(process.cwd(), '.git')); - if (git) { - // Make sure there are no dirty git status - function statusSync() { - let stdout = execSync(`git status -s`).toString(); - let status = { dirty: 0, untracked: 0 }; - stdout.trim().split(/\r?\n/).forEach(file => { - if (file.substr(0, 2) === '??') status.untracked++; - else status.dirty++; - }); - return status; - } + function statusSync() { + let stdout = execSync(`git status -s`).toString(); + let status = { dirty: 0, untracked: 0 }; + stdout.trim().split(/\r?\n/).forEach(file => { + if (file.substr(0, 2) === '??') status.untracked++; + else status.dirty++; + }); + return status; + } + if (git) { let status = statusSync(); if (status.dirty) { console.error( From fe3bb7fcdf3d3bd8694aceb005c8c31558f85032 Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Fri, 5 May 2017 19:40:57 -0400 Subject: [PATCH 07/11] remove checking .git directory --- packages/react-scripts/scripts/eject.js | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index b47a760881a..90019ac4f85 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -38,28 +38,28 @@ prompt( } // Make sure there are no dirty git status - const git = fs.existsSync(path.join(process.cwd(), '.git')); - function statusSync() { - let stdout = execSync(`git status -s`).toString(); - let status = { dirty: 0, untracked: 0 }; - stdout.trim().split(/\r?\n/).forEach(file => { - if (file.substr(0, 2) === '??') status.untracked++; - else status.dirty++; - }); - return status; + try { + let stdout = execSync(`git status -s`).toString(); + let status = { dirty: 0, untracked: 0 }; + stdout.trim().split(/\r?\n/).forEach(file => { + if (file.substr(0, 2) === '??') status.untracked++; + else status.dirty++; + }); + return status; + } catch (e) { + return false; + } } - if (git) { - let status = statusSync(); - if (status.dirty) { - console.error( - `Git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}. ` + - 'We cannot continue as you would lose all the changes in that file or directory. ' + - 'Please push commit before and run this command again.' - ); - process.exit(1); - } + const status = statusSync(); + if (status && status.dirty) { + console.error( + `Git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}. ` + + 'We cannot continue as you would lose all the changes in that file or directory. ' + + 'Please push commit before and run this command again.' + ); + process.exit(1); } console.log('Ejecting...'); From cf57f57348fab32dd941eb3431b8231853284a56 Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Mon, 8 May 2017 11:28:01 -0400 Subject: [PATCH 08/11] Give the output in an easy-to-parse format for scripts --- packages/react-scripts/scripts/eject.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 90019ac4f85..1128bdd8096 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -40,7 +40,7 @@ prompt( // Make sure there are no dirty git status function statusSync() { try { - let stdout = execSync(`git status -s`).toString(); + let stdout = execSync(`git status --porcelain`).toString(); let status = { dirty: 0, untracked: 0 }; stdout.trim().split(/\r?\n/).forEach(file => { if (file.substr(0, 2) === '??') status.untracked++; From e7e03925caa819be785949efd636e3040e4695d6 Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Tue, 16 May 2017 22:11:58 -0400 Subject: [PATCH 09/11] improved error message --- packages/react-scripts/scripts/eject.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 1128bdd8096..3df89afa33a 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -55,9 +55,9 @@ prompt( const status = statusSync(); if (status && status.dirty) { console.error( - `Git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}. ` + - 'We cannot continue as you would lose all the changes in that file or directory. ' + - 'Please push commit before and run this command again.' + `This git repository has ${status.dirty} ${status.dirty > 1 ? 'files' : 'file'} with uncommitted changes.` + + 'Ejecting would cause these files to be overwritten. ' + + 'Please commit your changes with `git commit` and then run this command again.' ); process.exit(1); } From a72073c892db319c658c7b47b4416e55b8fa6082 Mon Sep 17 00:00:00 2001 From: milocosmopolitan Date: Tue, 16 May 2017 22:23:17 -0400 Subject: [PATCH 10/11] count dirty files only --- packages/react-scripts/scripts/eject.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 3df89afa33a..105daf03cd2 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -41,22 +41,21 @@ prompt( function statusSync() { try { let stdout = execSync(`git status --porcelain`).toString(); - let status = { dirty: 0, untracked: 0 }; - stdout.trim().split(/\r?\n/).forEach(file => { - if (file.substr(0, 2) === '??') status.untracked++; - else status.dirty++; - }); + let status = stdout + .trim() + .split(/\r?\n/) + .filter(file => file.substr(0, 2) === '??').length; return status; } catch (e) { return false; } } - const status = statusSync(); - if (status && status.dirty) { + const dirtyStatus = statusSync(); + if (dirtyStatus) { console.error( - `This git repository has ${status.dirty} ${status.dirty > 1 ? 'files' : 'file'} with uncommitted changes.` + - 'Ejecting would cause these files to be overwritten. ' + + `This git repository has ${dirtyStatus} ${dirtyStatus > 1 ? 'files' : 'file'} with uncommitted changes.\n` + + 'Ejecting would cause these files to be overwritten. \n' + 'Please commit your changes with `git commit` and then run this command again.' ); process.exit(1); From ad7cd2c83880cf4c847a0d1f6e3017cf0c9be52c Mon Sep 17 00:00:00 2001 From: Milo Kang Date: Thu, 18 May 2017 23:36:11 -0400 Subject: [PATCH 11/11] Update build.js --- packages/react-scripts/scripts/build.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index faafabed335..9cafb493ef7 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -87,14 +87,6 @@ function build(previousFileSizes) { if (stats.compilation.errors.length) { printErrors('Failed to compile.', stats.compilation.errors); process.exit(1); - } else { - if (stats.compilation.warnings.length) { - printErrors( - 'Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.', - stats.compilation.warnings - ); - if (process.env.CI) process.exit(1); - } } console.log(chalk.green('Compiled successfully.'));