diff --git a/.travis.yml b/.travis.yml index 167fc436b..551340900 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,9 @@ --- -# Use Ubuntu Precise instead of new default Trusty which cause build fail -# with pre installed yarn v0.17.8 -# https://github.com/facebookincubator/create-react-app/issues/3054 -# TODO: remove after Trusty environment is updated with a lastet version of yarn -dist: precise +dist: trusty language: node_js node_js: - - 6 - 8 + - 9 cache: directories: - node_modules @@ -16,13 +12,17 @@ cache: install: true script: - 'if [ $TEST_SUITE = "simple" ]; then tasks/e2e-simple.sh; fi' + - 'if [ $TEST_SUITE = "kitchensink" ]; then tasks/e2e-kitchensink.sh; fi' + - 'if [ $TEST_SUITE = "old-node" ]; then tasks/e2e-old-node.sh; fi' + # Disabled for the moment, since it requires additional work to be done. + # - 'if [ $TEST_SUITE = "installs" ]; then tasks/e2e-installs.sh; fi' env: - global: - - USE_YARN=no matrix: - TEST_SUITE=simple - - TEST_SUITE=install -# There's a weird Yarn/Lerna bug related to prerelease versions. -# TODO: reenable after we ship 1.0. -# - node_js: 6 -# env: USE_YARN=yes TEST_SUITE=simple + - TEST_SUITE=kitchensink + # See comment above + # - TEST_SUITE=installs +matrix: + include: + - node_js: 6 + env: TEST_SUITE=kitchensink \ No newline at end of file diff --git a/package.json b/package.json index 596eaa1ad..e02a51dba 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,19 @@ { "private": true, + "workspaces": [ + "packages/*" + ], "scripts": { - "build": "node packages/react-scripts/scripts/build.js", + "build": "cd packages/react-scripts && node scripts/build.js", "changelog": "lerna-changelog", - "create-react-app": "tasks/cra.sh", + "create-react-app": "node tasks/cra.js", "e2e": "tasks/e2e-simple.sh", "e2e:docker": "tasks/local-test.sh", - "postinstall": "node bootstrap.js && cd packages/react-error-overlay/ && npm run build:prod", - "publish": "tasks/release.sh", - "start": "node packages/react-scripts/scripts/start.js", - "test": "node packages/react-scripts/scripts/test.js --env=jsdom", - "format": "prettier --trailing-comma es5 --single-quote --write \"packages/*/*.js\" \"packages/*/!(node_modules)/**/*.js\"", + "postinstall": "cd packages/react-error-overlay/ && yarn build:prod", + "publish": "tasks/publish.sh", + "start": "cd packages/react-scripts && node scripts/start.js", + "test": "cd packages/react-scripts && node scripts/test.js --env=jsdom", + "format": "prettier --trailing-comma es5 --single-quote --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'", "precommit": "lint-staged" }, "devDependencies": { @@ -20,10 +23,10 @@ "@types/react-dom": "^15.5.0", "eslint": "^4.4.1", "husky": "^0.13.2", - "lerna": "^2.0.0", + "lerna": "2.6.0", "lerna-changelog": "^0.6.0", "lint-staged": "^3.3.1", - "prettier": "^1.5.2" + "prettier": "1.6.1" }, "lint-staged": { "*.js": [ diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index 8adff62fa..eab07c1be 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -56,7 +56,7 @@ "text-table": "0.2.0" }, "devDependencies": { - "jest": "20.0.4" + "jest": "22.4.2" }, "scripts": { "test": "jest" diff --git a/packages/react-error-overlay/package.json b/packages/react-error-overlay/package.json index 87099dd5e..fe6c7fd68 100644 --- a/packages/react-error-overlay/package.json +++ b/packages/react-error-overlay/package.json @@ -48,7 +48,7 @@ "eslint-plugin-react": "7.1.0", "flow-bin": "^0.63.1", "html-entities": "1.2.1", - "jest": "20.0.4", + "jest": "22.4.2", "jest-fetch-mock": "1.2.1", "object-assign": "4.1.1", "promise": "8.0.1", diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 46d9cbee4..131ba2997 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -35,7 +35,7 @@ "fork-ts-checker-webpack-plugin": "^0.2.8", "fs-extra": "3.0.1", "html-webpack-plugin": "2.29.0", - "jest": "22.1.4", + "jest": "22.4.2", "object-assign": "4.1.1", "postcss-flexbugs-fixes": "3.2.0", "postcss-loader": "2.0.8", diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index f352a5448..d1150a874 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -14,13 +14,17 @@ cd "$(dirname "$0")" # CLI and app temporary locations # http://unix.stackexchange.com/a/84980 -temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'` temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'` +custom_registry_url=http://localhost:4873 +original_npm_registry_url=`npm get registry` +original_yarn_registry_url=`yarn config get registry` function cleanup { echo 'Cleaning up.' cd "$root_path" - rm -rf "$temp_cli_path" "$temp_app_path" + rm -rf "$temp_app_path" + npm set registry "$original_npm_registry_url" + yarn config set registry "$original_yarn_registry_url" } # Error messages are redirected to stderr @@ -55,10 +59,6 @@ function checkDependencies { fi } -function create_react_app { - node "$temp_cli_path"/node_modules/create-react-app/index.js $* -} - # Exit the script with a helpful error message when any error is encountered trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR @@ -72,77 +72,61 @@ set -x cd .. root_path=$PWD -# Clear cache to avoid issues with incorrect packages being used -if hash yarnpkg 2>/dev/null -then - # AppVeyor uses an old version of yarn. - # Once updated to 0.24.3 or above, the workaround can be removed - # and replaced with `yarnpkg cache clean` - # Issues: - # https://github.com/yarnpkg/yarn/issues/2591 - # https://github.com/appveyor/ci/issues/1576 - # https://github.com/facebookincubator/create-react-app/pull/2400 - # When removing workaround, you may run into - # https://github.com/facebookincubator/create-react-app/issues/2030 - case "$(uname -s)" in - *CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;; - *) yarn=yarnpkg;; - esac - $yarn cache clean -fi - if hash npm 2>/dev/null then - # npm 5 is too buggy right now - if [ $(npm -v | head -c 1) -eq 5 ]; then - npm i -g npm@^4.x - fi; + npm i -g npm@latest npm cache clean || npm cache verify fi -# Prevent bootstrap, we only want top-level dependencies -cp package.json package.json.bak -grep -v "postinstall" package.json > temp && mv temp package.json -npm install -mv package.json.bak package.json +# Bootstrap monorepo +yarn -if [ "$USE_YARN" = "yes" ] -then - # Install Yarn so that the test can use it to install packages. - npm install -g yarn - yarn cache clean -fi +# ****************************************************************************** +# First, publish the monorepo. +# ****************************************************************************** + +# Start local registry +tmp_registry_log=`mktemp` +nohup npx verdaccio@2.7.2 &>$tmp_registry_log & +# Wait for `verdaccio` to boot +grep -q 'http address' <(tail -f $tmp_registry_log) -# We removed the postinstall, so do it manually -node bootstrap.js +# Set registry to local registry +npm set registry "$custom_registry_url" +yarn config set registry "$custom_registry_url" -cd packages/react-error-overlay/ -npm run build:prod -cd ../.. +# Login so we can publish packages +npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r "$custom_registry_url" --quotes + +# Publish the monorepo +git clean -df +./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest # ****************************************************************************** -# First, pack and install create-react-app. +# Test --scripts-version with a version number # ****************************************************************************** -# Pack CLI -cd "$root_path"/packages/create-react-app -cli_path=$PWD/`npm pack` +cd "$temp_app_path" +npx create-react-app --scripts-version=1.0.17 test-app-version-number +cd test-app-version-number -# Install the CLI in a temporary location -cd "$temp_cli_path" -npm install "$cli_path" +# Check corresponding scripts version is installed. +exists node_modules/react-scripts +grep '"version": "1.0.17"' node_modules/react-scripts/package.json +checkDependencies # ****************************************************************************** -# Test --scripts-version with a version number +# Test --use-npm flag # ****************************************************************************** cd "$temp_app_path" -create_react_app --scripts-version=0.4.0 test-app-version-number -cd test-app-version-number +npx create-react-app --use-npm --scripts-version=1.0.17 test-use-npm-flag +cd test-use-npm-flag # Check corresponding scripts version is installed. exists node_modules/react-scripts -grep '"version": "0.4.0"' node_modules/react-scripts/package.json +[ ! -e "yarn.lock" ] && echo "yarn.lock correctly does not exist" +grep '"version": "1.0.17"' node_modules/react-scripts/package.json checkDependencies # ****************************************************************************** @@ -150,12 +134,12 @@ checkDependencies # ****************************************************************************** cd "$temp_app_path" -create_react_app --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-0.4.0.tgz test-app-tarball-url +npx create-react-app --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-1.0.17.tgz test-app-tarball-url cd test-app-tarball-url # Check corresponding scripts version is installed. exists node_modules/react-scripts -grep '"version": "0.4.0"' node_modules/react-scripts/package.json +grep '"version": "1.0.17"' node_modules/react-scripts/package.json checkDependencies # ****************************************************************************** @@ -163,7 +147,7 @@ checkDependencies # ****************************************************************************** cd "$temp_app_path" -create_react_app --scripts-version=react-scripts-fork test-app-fork +npx create-react-app --scripts-version=react-scripts-fork test-app-fork cd test-app-fork # Check corresponding scripts version is installed. @@ -175,7 +159,7 @@ exists node_modules/react-scripts-fork cd "$temp_app_path" # we will install a non-existing package to simulate a failed installataion. -create_react_app --scripts-version=`date +%s` test-app-should-not-exist || true +npx create-react-app --scripts-version=`date +%s` test-app-should-not-exist || true # confirm that the project folder was deleted test ! -d test-app-should-not-exist @@ -187,7 +171,7 @@ cd "$temp_app_path" mkdir test-app-should-remain echo '## Hello' > ./test-app-should-remain/README.md # we will install a non-existing package to simulate a failed installataion. -create_react_app --scripts-version=`date +%s` test-app-should-remain || true +npx create-react-app --scripts-version=`date +%s` test-app-should-remain || true # confirm the file exist test -e test-app-should-remain/README.md # confirm only README.md is the only file in the directory @@ -201,7 +185,7 @@ fi cd $temp_app_path curl "https://registry.npmjs.org/@enoah_netzach/react-scripts/-/react-scripts-0.9.0.tgz" -o enoah-scripts-0.9.0.tgz -create_react_app --scripts-version=$temp_app_path/enoah-scripts-0.9.0.tgz test-app-scoped-fork-tgz +npx create-react-app --scripts-version=$temp_app_path/enoah-scripts-0.9.0.tgz test-app-scoped-fork-tgz cd test-app-scoped-fork-tgz # Check corresponding scripts version is installed. @@ -216,22 +200,22 @@ cd "$temp_app_path" mkdir test-app-nested-paths-t1 cd test-app-nested-paths-t1 mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd -create_react_app test-app-nested-paths-t1/aa/bb/cc/dd +npx create-react-app test-app-nested-paths-t1/aa/bb/cc/dd cd test-app-nested-paths-t1/aa/bb/cc/dd -npm start -- --smoke-test +yarn start --smoke-test # Testing a path that does not exist cd "$temp_app_path" -create_react_app test-app-nested-paths-t2/aa/bb/cc/dd +npx create-react-app test-app-nested-paths-t2/aa/bb/cc/dd cd test-app-nested-paths-t2/aa/bb/cc/dd -npm start -- --smoke-test +yarn start --smoke-test # Testing a path that is half exists cd "$temp_app_path" mkdir -p test-app-nested-paths-t3/aa -create_react_app test-app-nested-paths-t3/aa/bb/cc/dd +npx create-react-app test-app-nested-paths-t3/aa/bb/cc/dd cd test-app-nested-paths-t3/aa/bb/cc/dd -npm start -- --smoke-test +yarn start --smoke-test # Cleanup -cleanup +cleanup \ No newline at end of file diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index c1167c1de..1aa55a907 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -14,16 +14,20 @@ cd "$(dirname "$0")" # CLI, app, and test module temporary locations # http://unix.stackexchange.com/a/84980 -temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'` temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'` temp_module_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_module_path'` +custom_registry_url=http://localhost:4873 +original_npm_registry_url=`npm get registry` +original_yarn_registry_url=`yarn config get registry` function cleanup { echo 'Cleaning up.' ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -9 cd "$root_path" # TODO: fix "Device or resource busy" and remove ``|| $CI` - rm -rf "$temp_cli_path" "$temp_app_path" "$temp_module_path" || $CI + rm -rf "$temp_app_path" "$temp_module_path" || $CI + npm set registry "$original_npm_registry_url" + yarn config set registry "$original_yarn_registry_url" } # Error messages are redirected to stderr @@ -40,35 +44,6 @@ function handle_exit { exit } -function create_react_app { - node "$temp_cli_path"/node_modules/create-react-app/index.js "$@" -} - -function install_package { - local pkg=$(basename $1) - - # Clean target (for safety) - rm -rf node_modules/$pkg/ - rm -rf node_modules/**/$pkg/ - - # Copy package into node_modules/ ignoring installed deps - # rsync -a ${1%/} node_modules/ --exclude node_modules - cp -R ${1%/} node_modules/ - rm -rf node_modules/$pkg/node_modules/ - - # Install `dependencies` - cd node_modules/$pkg/ - if [ "$USE_YARN" = "yes" ] - then - yarn install --production - else - npm install --only=production - fi - # Remove our packages to ensure side-by-side versions are used (which we link) - rm -rf node_modules/{babel-preset-react-app,eslint-config-react-app,react-dev-utils,react-error-overlay,react-scripts} - cd ../.. -} - # Check for the existence of one or more files. function exists { for f in $*; do @@ -89,94 +64,47 @@ set -x cd .. root_path=$PWD -# Clear cache to avoid issues with incorrect packages being used -if hash yarnpkg 2>/dev/null -then - # AppVeyor uses an old version of yarn. - # Once updated to 0.24.3 or above, the workaround can be removed - # and replaced with `yarnpkg cache clean` - # Issues: - # https://github.com/yarnpkg/yarn/issues/2591 - # https://github.com/appveyor/ci/issues/1576 - # https://github.com/facebookincubator/create-react-app/pull/2400 - # When removing workaround, you may run into - # https://github.com/facebookincubator/create-react-app/issues/2030 - case "$(uname -s)" in - *CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;; - *) yarn=yarnpkg;; - esac - $yarn cache clean -fi - if hash npm 2>/dev/null then - # npm 5 is too buggy right now - if [ $(npm -v | head -c 1) -eq 5 ]; then - npm i -g npm@^4.x - fi; + npm i -g npm@latest npm cache clean || npm cache verify fi -# Prevent bootstrap, we only want top-level dependencies -cp package.json package.json.bak -grep -v "postinstall" package.json > temp && mv temp package.json -npm install -mv package.json.bak package.json - -if [ "$USE_YARN" = "yes" ] -then - # Install Yarn so that the test can use it to install packages. - npm install -g yarn - yarn cache clean -fi - -# We removed the postinstall, so do it manually -node bootstrap.js - -cd packages/react-error-overlay/ -npm run build:prod -cd ../.. +# Bootstrap monorepo +yarn # ****************************************************************************** -# First, pack react-scripts and create-react-app so we can use them. +# First, publish the monorepo. # ****************************************************************************** -# Pack CLI -cd "$root_path"/packages/create-react-app -cli_path=$PWD/`npm pack` - -# Go to react-scripts -cd "$root_path"/packages/react-scripts +# Start local registry +tmp_registry_log=`mktemp` +nohup npx verdaccio@2.7.2 &>$tmp_registry_log & +# Wait for `verdaccio` to boot +grep -q 'http address' <(tail -f $tmp_registry_log) -# Save package.json because we're going to touch it -cp package.json package.json.orig +# Set registry to local registry +npm set registry "$custom_registry_url" +yarn config set registry "$custom_registry_url" -# Replace own dependencies (those in the `packages` dir) with the local paths -# of those packages. -node "$root_path"/tasks/replace-own-deps.js +# Login so we can publish packages +npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r "$custom_registry_url" --quotes -# Finally, pack react-scripts -scripts_path="$root_path"/packages/react-scripts/`npm pack` - -# Restore package.json -rm package.json -mv package.json.orig package.json +# Publish the monorepo +git clean -df +./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest # ****************************************************************************** -# Now that we have packed them, create a clean app folder and install them. +# Now that we have published them, create a clean app folder and install them. # ****************************************************************************** -# Install the CLI in a temporary location -cd "$temp_cli_path" -npm install "$cli_path" - # Install the app in a temporary location cd $temp_app_path -create_react_app --scripts-version="$scripts_path" --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink test-kitchensink +npx create-react-app --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink test-kitchensink # Install the test module cd "$temp_module_path" -npm install test-integrity@^2.0.1 +yarn add test-integrity@^2.0.1 # ****************************************************************************** # Now that we used create-react-app to create an app depending on react-scripts, @@ -186,20 +114,14 @@ npm install test-integrity@^2.0.1 # Enter the app directory cd "$temp_app_path/test-kitchensink" -# Link to our preset -install_package "$root_path"/packages/babel-preset-react-app -# Link to error overlay package because now it's a dependency -# of react-dev-utils and not react-scripts -install_package "$root_path"/packages/react-error-overlay - # Link to test module -install_package "$temp_module_path/node_modules/test-integrity" +npm link "$temp_module_path/node_modules/test-integrity" # Test the build REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ NODE_PATH=src \ PUBLIC_URL=http://www.example.org/spa/ \ - npm run build + yarn build # Check for expected output exists build/*.html @@ -210,22 +132,15 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ CI=true \ NODE_PATH=src \ NODE_ENV=test \ - npm test -- --no-cache --testPathPattern=src + yarn test --no-cache --testPathPattern=src # Test "development" environment tmp_server_log=`mktemp` PORT=3001 \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ NODE_PATH=src \ - nohup npm start &>$tmp_server_log & -while true -do - if grep -q 'You can now view' $tmp_server_log; then - break - else - sleep 1 - fi -done + nohup yarn start &>$tmp_server_log & +grep -q 'You can now view' <(tail -f $tmp_server_log) E2E_URL="http://localhost:3001" \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ CI=true NODE_PATH=src \ @@ -247,28 +162,14 @@ E2E_FILE=./build/index.html \ # Eject... echo yes | npm run eject -# Ensure Yarn is ran after eject; at the time of this commit, we don't run Yarn -# after ejecting. Soon, we may only skip Yarn on Windows. Let's try to remove -# this in the near future. -if hash yarnpkg 2>/dev/null -then - yarn install --check-files -fi - -# ...but still link to the local packages -install_package "$root_path"/packages/babel-preset-react-app -install_package "$root_path"/packages/eslint-config-react-app -install_package "$root_path"/packages/react-error-overlay -install_package "$root_path"/packages/react-dev-utils - # Link to test module -install_package "$temp_module_path/node_modules/test-integrity" +npm link "$temp_module_path/node_modules/test-integrity" # Test the build REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ NODE_PATH=src \ PUBLIC_URL=http://www.example.org/spa/ \ - npm run build + yarn build # Check for expected output exists build/*.html @@ -279,22 +180,15 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ CI=true \ NODE_PATH=src \ NODE_ENV=test \ - npm test -- --no-cache --testPathPattern=src + yarn test --no-cache --testPathPattern=src # Test "development" environment tmp_server_log=`mktemp` PORT=3002 \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ NODE_PATH=src \ - nohup npm start &>$tmp_server_log & -while true -do - if grep -q 'You can now view' $tmp_server_log; then - break - else - sleep 1 - fi -done + nohup yarn start &>$tmp_server_log & +grep -q 'You can now view' <(tail -f $tmp_server_log) E2E_URL="http://localhost:3002" \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ CI=true NODE_PATH=src \ @@ -310,4 +204,4 @@ E2E_FILE=./build/index.html \ node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js # Cleanup -cleanup +cleanup \ No newline at end of file diff --git a/tasks/e2e-old-node.sh b/tasks/e2e-old-node.sh index 8245dd24e..2d0345ba0 100755 --- a/tasks/e2e-old-node.sh +++ b/tasks/e2e-old-node.sh @@ -58,4 +58,4 @@ err_output=`node "$root_path"/packages/create-react-app/index.js test-node-versi [[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1 # Cleanup -cleanup +cleanup \ No newline at end of file diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 04781ebaf..a1eecbaf0 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -12,17 +12,21 @@ # Start in tasks/ even if run from root directory cd "$(dirname "$0")" -# CLI and app temporary locations +# App temporary location # http://unix.stackexchange.com/a/84980 -temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'` temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'` +custom_registry_url=http://localhost:4873 +original_npm_registry_url=`npm get registry` +original_yarn_registry_url=`yarn config get registry` function cleanup { echo 'Cleaning up.' cd "$root_path" # Uncomment when snapshot testing is enabled by default: # rm ./packages/react-scripts/template/src/__snapshots__/App.test.js.snap - rm -rf "$temp_cli_path" $temp_app_path + rm -rf "$temp_app_path" + npm set registry "$original_npm_registry_url" + yarn config set registry "$original_yarn_registry_url" } # Error messages are redirected to stderr @@ -39,35 +43,6 @@ function handle_exit { exit } -function create_react_app { - node "$temp_cli_path"/node_modules/create-react-app/index.js "$@" -} - -function install_package { - local pkg=$(basename $1) - - # Clean target (for safety) - rm -rf node_modules/$pkg/ - rm -rf node_modules/**/$pkg/ - - # Copy package into node_modules/ ignoring installed deps - # rsync -a ${1%/} node_modules/ --exclude node_modules - cp -R ${1%/} node_modules/ - rm -rf node_modules/$pkg/node_modules/ - - # Install `dependencies` - cd node_modules/$pkg/ - if [ "$USE_YARN" = "yes" ] - then - yarn install --production - else - npm install --only=production - fi - # Remove our packages to ensure side-by-side versions are used (which we link) - rm -rf node_modules/{babel-preset-react-app,eslint-config-react-app,react-dev-utils,react-error-overlay,react-scripts} - cd ../.. -} - # Check for the existence of one or more files. function exists { for f in $*; do @@ -88,65 +63,40 @@ set -x cd .. root_path=$PWD -# Clear cache to avoid issues with incorrect packages being used -if hash yarnpkg 2>/dev/null -then - # AppVeyor uses an old version of yarn. - # Once updated to 0.24.3 or above, the workaround can be removed - # and replaced with `yarnpkg cache clean` - # Issues: - # https://github.com/yarnpkg/yarn/issues/2591 - # https://github.com/appveyor/ci/issues/1576 - # https://github.com/facebookincubator/create-react-app/pull/2400 - # When removing workaround, you may run into - # https://github.com/facebookincubator/create-react-app/issues/2030 - case "$(uname -s)" in - *CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;; - *) yarn=yarnpkg;; - esac - $yarn cache clean +# Make sure we don't introduce accidental references to PATENTS. +EXPECTED='packages/react-error-overlay/fixtures/bundle.mjs +packages/react-error-overlay/fixtures/bundle.mjs.map +packages/react-error-overlay/fixtures/bundle_u.mjs +packages/react-error-overlay/fixtures/bundle_u.mjs.map +tasks/e2e-simple.sh' +ACTUAL=$(git grep -l PATENTS) +if [ "$EXPECTED" != "$ACTUAL" ]; then + echo "PATENTS crept into some new files?" + diff -u <(echo "$EXPECTED") <(echo "$ACTUAL") || true + exit 1 fi if hash npm 2>/dev/null then - # npm 5 is too buggy right now - if [ $(npm -v | head -c 1) -eq 5 ]; then - npm i -g npm@^4.x - fi; + npm i -g npm@latest npm cache clean || npm cache verify fi -# Prevent bootstrap, we only want top-level dependencies -cp package.json package.json.bak -grep -v "postinstall" package.json > temp && mv temp package.json -npm install -mv package.json.bak package.json - -# We need to install create-react-app deps to test it -cd "$root_path"/packages/create-react-app -npm install -cd "$root_path" - -# If the node version is < 6, the script should just give an error. -nodeVersion=`node --version | cut -d v -f2` -nodeMajor=`echo $nodeVersion | cut -d. -f1` -nodeMinor=`echo $nodeVersion | cut -d. -f2` -if [[ nodeMajor -lt 6 ]] -then - cd $temp_app_path - err_output=`node "$root_path"/packages/create-react-app/index.js test-node-version 2>&1 > /dev/null || echo ''` - [[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1 -fi +# Bootstrap monorepo +yarn -if [ "$USE_YARN" = "yes" ] -then - # Install Yarn so that the test can use it to install packages. - npm install -g yarn - yarn cache clean -fi +# Start local registry +tmp_registry_log=`mktemp` +nohup npx verdaccio@2.7.2 &>$tmp_registry_log & +# Wait for `verdaccio` to boot +grep -q 'http address' <(tail -f $tmp_registry_log) -# We removed the postinstall, so do it manually here -node bootstrap.js +# Set registry to local registry +npm set registry "$custom_registry_url" +yarn config set registry "$custom_registry_url" + +# Login so we can publish packages +npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r "$custom_registry_url" --quotes # Lint own code ./node_modules/.bin/eslint --max-warnings 0 packages/babel-preset-react-app/ @@ -156,8 +106,16 @@ node bootstrap.js ./node_modules/.bin/eslint --max-warnings 0 packages/react-scripts/ cd packages/react-error-overlay/ ./node_modules/.bin/eslint --max-warnings 0 src/ -npm test -npm run build:prod +yarn test + +if [ $APPVEYOR != 'True' ]; then + # Flow started hanging on AppVeyor after we moved to Yarn Workspaces :-( + yarn flow +fi + +cd ../.. +cd packages/react-dev-utils/ +yarn test cd ../.. # ****************************************************************************** @@ -166,7 +124,7 @@ cd ../.. # ****************************************************************************** # Test local build command -npm run build +yarn build # Check for expected output exists build/*.html exists build/static/js/*.js @@ -175,55 +133,25 @@ exists build/static/media/*.svg exists build/favicon.ico # Run tests with CI flag -CI=true npm test +CI=true yarn test # Uncomment when snapshot testing is enabled by default: # exists template/src/__snapshots__/App.test.js.snap # Test local start command -npm start -- --smoke-test - -# ****************************************************************************** -# Next, pack react-scripts and create-react-app so we can verify they work. -# ****************************************************************************** - -# Pack CLI -cd "$root_path"/packages/create-react-app -cli_path=$PWD/`npm pack` - -# Go to react-scripts -cd "$root_path"/packages/react-scripts +yarn start --smoke-test -# Save package.json because we're going to touch it -cp package.json package.json.orig - -# Replace own dependencies (those in the `packages` dir) with the local paths -# of those packages. -node "$root_path"/tasks/replace-own-deps.js - -# Finally, pack react-scripts -scripts_path="$root_path"/packages/react-scripts/`npm pack` - -# Restore package.json -rm package.json -mv package.json.orig package.json +git clean -df +./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest # ****************************************************************************** -# Now that we have packed them, create a clean app folder and install them. +# Install react-scripts prerelease via create-react-app prerelease. # ****************************************************************************** -# Install the CLI in a temporary location -cd "$temp_cli_path" - -# Initialize package.json before installing the CLI because npm will not install -# the CLI properly in the temporary location if it is missing. -npm init --yes - -# Now we can install the CLI from the local package. -npm install "$cli_path" - # Install the app in a temporary location cd $temp_app_path -create_react_app --scripts-version="$scripts_path" test-app +npx create-react-app test-app --scripts-version=react-scripts-ts + +# TODO: verify we installed prerelease # ****************************************************************************** # Now that we used create-react-app to create an app depending on react-scripts, @@ -240,24 +168,24 @@ function verify_env_url { # Test relative path build awk -v n=2 -v s=" \"homepage\": \".\"," 'NR == n {print s} {print}' package.json > tmp && mv tmp package.json - npm run build + yarn build # Disabled until this can be tested # grep -F -R --exclude=*.map "../../static/" build/ -q; test $? -eq 0 || exit 1 grep -F -R --exclude=*.map "\"./static/" build/ -q; test $? -eq 0 || exit 1 grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1 - PUBLIC_URL="/anabsolute" npm run build + PUBLIC_URL="/anabsolute" yarn build grep -F -R --exclude=*.map "/anabsolute/static/" build/ -q; test $? -eq 0 || exit 1 grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1 # Test absolute path build sed "2s/.*/ \"homepage\": \"\/testingpath\",/" package.json > tmp && mv tmp package.json - npm run build + yarn build grep -F -R --exclude=*.map "/testingpath/static/" build/ -q; test $? -eq 0 || exit 1 grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1 - PUBLIC_URL="https://www.example.net/overridetest" npm run build + PUBLIC_URL="https://www.example.net/overridetest" yarn build grep -F -R --exclude=*.map "https://www.example.net/overridetest/static/" build/ -q; test $? -eq 0 || exit 1 grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1 grep -F -R --exclude=*.map "testingpath/static" build/ -q; test $? -eq 1 || exit 1 @@ -265,11 +193,11 @@ function verify_env_url { # Test absolute url build sed "2s/.*/ \"homepage\": \"https:\/\/www.example.net\/testingpath\",/" package.json > tmp && mv tmp package.json - npm run build + yarn build grep -F -R --exclude=*.map "/testingpath/static/" build/ -q; test $? -eq 0 || exit 1 grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1 - PUBLIC_URL="https://www.example.net/overridetest" npm run build + PUBLIC_URL="https://www.example.net/overridetest" yarn build grep -F -R --exclude=*.map "https://www.example.net/overridetest/static/" build/ -q; test $? -eq 0 || exit 1 grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1 grep -F -R --exclude=*.map "testingpath/static" build/ -q; test $? -eq 1 || exit 1 @@ -283,14 +211,14 @@ function verify_module_scope { # Create stub json file echo "{}" >> sample.json - # Save App.js, we're going to modify it + # Save App.tsx, we're going to modify it cp src/App.tsx src/App.tsx.bak # Add an out of scope import - echo "import sampleJson from '../sample.json'" | cat - src/App.tsx > src/App.tsx.temp && mv src/App.tsx.temp src/App.tsx + echo "import sampleJson from '../sample'" | cat - src/App.tsx > src/App.tsx.temp && mv src/App.tsx.temp src/App.tsx # Make sure the build fails - npm run build; test $? -eq 1 || exit 1 + yarn build; test $? -eq 1 || exit 1 # TODO: check for error message # Restore App.tsx @@ -302,9 +230,8 @@ function verify_module_scope { cd test-app # Test the build -npm run build +yarn build # Check for expected output -pwd exists build/*.html exists build/static/js/*.js exists build/static/css/*.css @@ -312,12 +239,12 @@ exists build/static/media/*.svg exists build/favicon.ico # Run tests with CI flag -CI=true npm test +CI=true yarn test # Uncomment when snapshot testing is enabled by default: -# exists src/__snapshots__/App.test.tsx.snap +# exists src/__snapshots__/App.test.js.snap # Test the server -npm start -- --smoke-test +yarn start --smoke-test # Test environment handling verify_env_url @@ -332,21 +259,8 @@ verify_module_scope # Eject... echo yes | npm run eject -# Ensure Yarn is ran after eject; at the time of this commit, we don't run Yarn -# after ejecting. Soon, we may only skip Yarn on Windows. Let's try to remove -# this in the near future. -if hash yarnpkg 2>/dev/null -then - yarnpkg install --check-files -fi - -# ...but still link to the local packages -install_package "$root_path"/packages/babel-preset-react-app -install_package "$root_path"/packages/eslint-config-react-app -install_package "$root_path"/packages/react-dev-utils - # Test the build -npm run build +yarn build # Check for expected output exists build/*.html exists build/static/js/*.js @@ -355,15 +269,15 @@ exists build/static/media/*.svg exists build/favicon.ico # Run tests, overring the watch option to disable it. -# `CI=true npm test` won't work here because `npm test` becomes just `jest`. +# `CI=true yarn test` won't work here because `yarn test` becomes just `jest`. # We should either teach Jest to respect CI env variable, or make # `scripts/test.js` survive ejection (right now it doesn't). -npm test -- --watch=no +yarn test --watch=no # Uncomment when snapshot testing is enabled by default: # exists src/__snapshots__/App.test.js.snap # Test the server -npm start -- --smoke-test +yarn start --smoke-test # Test environment handling verify_env_url @@ -372,4 +286,4 @@ verify_env_url verify_module_scope # Cleanup -cleanup +cleanup \ No newline at end of file diff --git a/tasks/local-test.sh b/tasks/local-test.sh index 8ce44b640..1cab41f67 100755 --- a/tasks/local-test.sh +++ b/tasks/local-test.sh @@ -11,7 +11,6 @@ function print_help { echo " --node-version the node version to use while testing [6]" echo " --git-branch the git branch to checkout for testing [the current one]" echo " --test-suite which test suite to use ('simple', installs', 'kitchensink', 'all') ['all']" - echo " --yarn if present, use yarn as the package manager" echo " --interactive gain a bash shell after the test run" echo " --help print this message and exit" echo "" @@ -22,7 +21,6 @@ cd $(dirname $0) node_version=6 current_git_branch=`git rev-parse --abbrev-ref HEAD` git_branch=${current_git_branch} -use_yarn=no test_suite=all interactive=false @@ -36,9 +34,6 @@ while [ "$1" != "" ]; do shift git_branch=$1 ;; - "--yarn") - use_yarn=yes - ;; "--test-suite") shift test_suite=$1 @@ -107,11 +102,10 @@ CMD docker run \ --env CI=true \ --env NPM_CONFIG_QUIET=true \ - --env USE_YARN=${use_yarn} \ --tty \ --user node \ --volume ${PWD}/..:/var/create-react-app \ --workdir /home/node \ $([[ ${interactive} == 'true' ]] && echo '--interactive') \ node:${node_version} \ - bash -c "${command}" + bash -c "${command}" \ No newline at end of file