From 8b451517e6ce44133ac4578abbfc9a683eeadf7d Mon Sep 17 00:00:00 2001 From: jhe Date: Tue, 26 Jul 2016 10:24:14 +0100 Subject: [PATCH 1/2] eliminate dev-only code on eject --- config/paths.js | 12 ++++++++---- scripts/eject.js | 2 ++ scripts/start.js | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/config/paths.js b/config/paths.js index b0f94588adb..490c050912b 100644 --- a/config/paths.js +++ b/config/paths.js @@ -12,6 +12,11 @@ var path = require('path'); +function resolve(relativePath) { + return path.resolve(__dirname, relativePath); +} + +// Dead code on eject: start // True when used as a dependency, false after ejecting var isInNodeModules = ( 'node_modules' === @@ -23,10 +28,6 @@ var isInCreateReactAppSource = ( process.argv.some(arg => arg.indexOf('--debug-template') > -1) ); -function resolve(relativePath) { - return path.resolve(__dirname, relativePath); -} - if (isInCreateReactAppSource) { // create-react-app development: we're in ./config/ module.exports = { @@ -52,6 +53,8 @@ if (isInCreateReactAppSource) { }; } else { // after eject: we're in ./config/ +// Dead code on eject: end +// Dead code on eject: start module.exports = { appBuild: resolve('../build'), appHtml: resolve('../index.html'), @@ -61,4 +64,5 @@ if (isInCreateReactAppSource) { appNodeModules: resolve('../node_modules'), ownNodeModules: resolve('../node_modules') }; +// Dead code on eject: end } diff --git a/scripts/eject.js b/scripts/eject.js index b3d7b4ae60c..066689d0800 100644 --- a/scripts/eject.js +++ b/scripts/eject.js @@ -80,6 +80,8 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi .replace(/^\/\*\*(\*(?!\/)|[^*])*\*\//, '') // Remove license header from AppleScript .replace(/^--.*\n/gm, '') + // Remove dead code on eject + .replace(/\/\/ Dead code on eject: start([\s\S]*?)\/\/ Dead code on eject: end/g, '') .trim() + '\n'; fs.writeFileSync(path.join(appPath, file), content); }); diff --git a/scripts/start.js b/scripts/start.js index 81bed9f098e..25627ab02be 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -17,9 +17,10 @@ var config = require('../config/webpack.config.dev'); var execSync = require('child_process').execSync; var opn = require('opn'); -// TODO: hide this behind a flag and eliminate dead code on eject. +// hide this behind a flag and eliminate dead code on eject. // This shouldn't be exposed to the user. var handleCompile; +// Dead code on eject: start var isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1); if (isSmokeTest) { handleCompile = function (err, stats) { @@ -30,6 +31,7 @@ if (isSmokeTest) { } }; } +// Dead code on eject: end var friendlySyntaxErrorLabel = 'Syntax error:'; From 8277f213cd59a3a7b3b4ea3539ec7e743acfa963 Mon Sep 17 00:00:00 2001 From: jhe Date: Tue, 26 Jul 2016 10:42:42 +0100 Subject: [PATCH 2/2] fix: clean path block --- config/paths.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/paths.js b/config/paths.js index 490c050912b..d3fc01a29c5 100644 --- a/config/paths.js +++ b/config/paths.js @@ -54,7 +54,6 @@ if (isInCreateReactAppSource) { } else { // after eject: we're in ./config/ // Dead code on eject: end -// Dead code on eject: start module.exports = { appBuild: resolve('../build'), appHtml: resolve('../index.html'), @@ -64,5 +63,6 @@ if (isInCreateReactAppSource) { appNodeModules: resolve('../node_modules'), ownNodeModules: resolve('../node_modules') }; -// Dead code on eject: end +// Dead code on eject: start } +// Dead code on eject: end