From 938ff9daa650041f1a98b226c73f7c0d849fc3c0 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 21 Jul 2016 16:44:57 +0100 Subject: [PATCH] Misc fixes for Windows (#60) --- .travis.yml | 2 +- package.json | 37 +++++-------------------------- scripts/eject.js | 40 ++++++++++++++++++---------------- scripts/init.js | 6 +++--- scripts/start.js | 2 +- {tests => tasks}/e2e.sh | 0 tasks/release.sh | 48 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 55 deletions(-) rename {tests => tasks}/e2e.sh (100%) create mode 100644 tasks/release.sh diff --git a/.travis.yml b/.travis.yml index 742e1ad763d..3ed7097635b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ cache: directories: - global-cli/node_modules - node_modules -script: tests/e2e.sh +script: tasks/e2e.sh diff --git a/package.json b/package.json index 33ba2bd5ac6..b65e5100421 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "babel-preset-es2015": "6.9.0", "babel-preset-es2016": "6.11.3", "babel-preset-react": "6.11.1", - "chalk": "^1.1.3", + "chalk": "1.1.3", "cross-spawn": "4.0.0", "css-loader": "0.23.1", "eslint": "3.1.1", @@ -55,38 +55,11 @@ "webpack-dev-server": "1.14.1" }, "devDependencies": { + "bundle-deps": "^1.0.0", "react": "^15.2.1", "react-dom": "^15.2.1" }, - "bundledDependencies": [ - "autoprefixer", - "babel-core", - "babel-eslint", - "babel-loader", - "babel-plugin-syntax-trailing-function-commas", - "babel-plugin-transform-class-properties", - "babel-plugin-transform-object-rest-spread", - "babel-plugin-transform-react-constant-elements", - "babel-preset-es2015", - "babel-preset-es2016", - "babel-preset-react", - "chalk", - "cross-spawn", - "css-loader", - "eslint", - "eslint-loader", - "eslint-plugin-import", - "eslint-plugin-react", - "extract-text-webpack-plugin", - "file-loader", - "html-webpack-plugin", - "json-loader", - "opn", - "postcss-loader", - "rimraf", - "style-loader", - "url-loader", - "webpack", - "webpack-dev-server" - ] + "optionalDependencies": { + "fsevents": "1.0.14" + } } diff --git a/scripts/eject.js b/scripts/eject.js index a33b5e26c57..174f222f7c2 100644 --- a/scripts/eject.js +++ b/scripts/eject.js @@ -51,15 +51,15 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi // Ensure that the host folder is clean and we won't override any files files.forEach(function(file) { - if (fs.existsSync(path.join(hostPath, file))) { - console.error( - '`' + file + '` already exists in your app folder. We cannot ' + - 'continue as you would lose all the changes in that file or directory. ' + - 'Please delete it (maybe make a copy for backup) and run this ' + - 'command again.' - ); - process.exit(1); - } + if (fs.existsSync(path.join(hostPath, file))) { + console.error( + '`' + file + '` already exists in your app folder. We cannot ' + + 'continue as you would lose all the changes in that file or directory. ' + + 'Please delete it (maybe make a copy for backup) and run this ' + + 'command again.' + ); + process.exit(1); + } }); // Copy the files over @@ -67,11 +67,11 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi fs.mkdirSync(path.join(hostPath, 'scripts')); files.forEach(function(file) { - console.log('Copying ' + file + ' to ' + hostPath); - var content = fs.readFileSync(path.join(selfPath, file), 'utf8'); - // Remove license header - content = content.replace(/^\/\*\*(\*(?!\/)|[^*])*\*\//, '').trim() + '\n'; - fs.writeFileSync(path.join(hostPath, file), content); + console.log('Copying ' + file + ' to ' + hostPath); + var content = fs.readFileSync(path.join(selfPath, file), 'utf8'); + // Remove license header + content = content.replace(/^\/\*\*(\*(?!\/)|[^*])*\*\//, '').trim() + '\n'; + fs.writeFileSync(path.join(hostPath, file), content); }); console.log(); @@ -82,8 +82,12 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi delete hostPackage.devDependencies['react-scripts']; Object.keys(selfPackage.dependencies).forEach(function (key) { - console.log('Adding dependency: ' + key); - hostPackage.devDependencies[key] = selfPackage.dependencies[key]; + // For some reason optionalDependencies end up in dependencies after install + if (selfPackage.optionalDependencies[key]) { + return; + } + console.log('Adding dependency: ' + key); + hostPackage.devDependencies[key] = selfPackage.dependencies[key]; }); console.log('Updating scripts'); @@ -94,8 +98,8 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi console.log('Writing package.json'); fs.writeFileSync( - path.join(hostPath, 'package.json'), - JSON.stringify(hostPackage, null, 2) + path.join(hostPath, 'package.json'), + JSON.stringify(hostPackage, null, 2) ); console.log(); diff --git a/scripts/init.js b/scripts/init.js index 1b8c981cbbc..5bf839308c6 100644 --- a/scripts/init.js +++ b/scripts/init.js @@ -17,11 +17,11 @@ module.exports = function(hostPath, appName, verbose) { var hostPackage = require(path.join(hostPath, 'package.json')); var selfPackage = require(path.join(selfPath, 'package.json')); - // Copy over devDependencies + // Copy over some of the devDependencies hostPackage.dependencies = hostPackage.dependencies || {}; - for (var key in selfPackage.devDependencies) { + ['react', 'react-dom'].forEach(function (key) { hostPackage.dependencies[key] = selfPackage.devDependencies[key]; - } + }); // Setup the script rules hostPackage.scripts = {}; diff --git a/scripts/start.js b/scripts/start.js index 3e64e6b6383..30cea3d248d 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -52,7 +52,7 @@ function formatMessage(message) { 'Module not found:' ) // Internal stacks are generally useless so we strip them - .replace(/^\s*at\s.*\(.*:\d+:\d+\.*\).*\n/gm, '') // at ... (...:x:y) + .replace(/^\s*at\s.*:\d+:\d+[\s\)]*\n/gm, '') // at ... ...:x:y // Webpack loader names obscure CSS filenames .replace('./~/css-loader!./~/postcss-loader!', ''); } diff --git a/tests/e2e.sh b/tasks/e2e.sh similarity index 100% rename from tests/e2e.sh rename to tasks/e2e.sh diff --git a/tasks/release.sh b/tasks/release.sh new file mode 100644 index 00000000000..7e7ff7b9f07 --- /dev/null +++ b/tasks/release.sh @@ -0,0 +1,48 @@ +# Copyright (c) 2015-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +# Start in tests/ even if run from root directory +cd "$(dirname "$0")" + +# Exit the script on any command with non 0 return code +# We assume that all the commands in the pipeline set their return code +# properly and that we do not need to validate that the output is correct +set -e + +# Echo every command being executed +set -x + +# Go to root +cd .. + +# You can only release with npm >= 3 +if [ $(npm -v | head -c 1) -lt 3 ]; then + echo "Releasing requires npm >= 3. Aborting."; + exit 1; +fi; + +if [ -n "$(git status --porcelain)" ]; then + echo "Your git status is not clean. Aborting."; + exit 1; +fi + +# Force dedupe +npm dedupe + +# Don't bundle fsevents because it is optional and OS X-only +# Since it's in optionalDependencies, it will attempt install outside bundle +rm -rf node_modules/fsevents + +# This modifies package.json to copy all dependencies to bundledDependencies +# We will revert package.json back after release to avoid doing it every time +node ./node_modules/.bin/bundle-deps + +# Go! +npm publish "$@" + +# Discard changes to package.json +git checkout -- .