From e91218f662a448d7d6ce29914b43541da5c8bb95 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 5 Mar 2017 20:48:32 +0000 Subject: [PATCH 1/3] Fix ejecting for a scoped react-scripts fork We shouldn't hardcode react-scripts because fork name might differ. We also shouldn't rely on it being an immediate child because scoped packages are a level deeper. --- packages/react-scripts/config/paths.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 7ad1fc95c89..7ec4da99727 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -97,7 +97,7 @@ function resolveOwn(relativePath) { // config before eject: we're in ./node_modules/react-scripts/config/ module.exports = { appPath: resolveApp('.'), - ownPath: resolveApp('node_modules/react-scripts'), + ownPath: resolveOwn('.'), appBuild: resolveApp('build'), appPublic: resolveApp('public'), appHtml: resolveApp('public/index.html'), From 991714f5a5c96a4b5fae1c37401b35bd6f2dc859 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 5 Mar 2017 20:51:16 +0000 Subject: [PATCH 2/3] Clarify that own* properties only exist before ejecting --- packages/react-scripts/config/paths.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 7ec4da99727..2a714c1394d 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -83,7 +83,6 @@ module.exports = { yarnLockFile: resolveApp('yarn.lock'), testsSetup: resolveApp('src/setupTests.js'), appNodeModules: resolveApp('node_modules'), - ownNodeModules: resolveApp('node_modules'), nodePaths: nodePaths, publicUrl: getPublicUrl(resolveApp('package.json')), servedPath: getServedPath(resolveApp('package.json')) @@ -97,7 +96,6 @@ function resolveOwn(relativePath) { // config before eject: we're in ./node_modules/react-scripts/config/ module.exports = { appPath: resolveApp('.'), - ownPath: resolveOwn('.'), appBuild: resolveApp('build'), appPublic: resolveApp('public'), appHtml: resolveApp('public/index.html'), @@ -107,11 +105,12 @@ module.exports = { yarnLockFile: resolveApp('yarn.lock'), testsSetup: resolveApp('src/setupTests.js'), appNodeModules: resolveApp('node_modules'), - // this is empty with npm3 but node resolution searches higher anyway: - ownNodeModules: resolveOwn('node_modules'), nodePaths: nodePaths, publicUrl: getPublicUrl(resolveApp('package.json')), - servedPath: getServedPath(resolveApp('package.json')) + servedPath: getServedPath(resolveApp('package.json')), + // These properties only exist before ejecting: + ownPath: resolveOwn('.'), + ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3 }; var reactScriptsPath = path.resolve('node_modules/react-scripts'); @@ -121,7 +120,6 @@ var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactSc if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) { module.exports = { appPath: resolveApp('.'), - ownPath: resolveOwn('.'), appBuild: resolveOwn('../../build'), appPublic: resolveOwn('template/public'), appHtml: resolveOwn('template/public/index.html'), @@ -131,10 +129,12 @@ if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-script yarnLockFile: resolveOwn('template/yarn.lock'), testsSetup: resolveOwn('template/src/setupTests.js'), appNodeModules: resolveOwn('node_modules'), - ownNodeModules: resolveOwn('node_modules'), nodePaths: nodePaths, publicUrl: getPublicUrl(resolveOwn('package.json')), - servedPath: getServedPath(resolveOwn('package.json')) + servedPath: getServedPath(resolveOwn('package.json')), + // These properties only exist before ejecting: + ownPath: resolveOwn('.'), + ownNodeModules: resolveOwn('node_modules'), }; } // @remove-on-eject-end From 55fccd858ee1d2a1e8e902236ac0fa99c2efb2ea Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 5 Mar 2017 20:37:12 +0000 Subject: [PATCH 3/3] Read script names from own bin instead of guessing This fixes ejecting from a fork that uses a different bin script name. --- packages/react-scripts/scripts/eject.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 0358d4256f4..b79d1e0d4d2 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -120,14 +120,17 @@ prompt( console.log(cyan('Updating the scripts')); delete appPackage.scripts['eject']; Object.keys(appPackage.scripts).forEach(function (key) { - appPackage.scripts[key] = appPackage.scripts[key] - .replace(/react-scripts (\w+)/g, 'node scripts/$1.js'); - console.log( - ' Replacing ' + - cyan('"react-scripts ' + key + '"') + - ' with ' + - cyan('"node scripts/' + key + '.js"') - ); + 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"') + ); + }); }); console.log();