Unverified Commit 29e06fc9 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub
Browse files

Follow-up: use private registry (#3746)

* Convert e2e-installs

* Convert kitchensink tests

* Upgrade npm for kitchensink
parent 75d71e15
Showing with 59 additions and 88 deletions
+59 -88
...@@ -14,13 +14,12 @@ cd "$(dirname "$0")" ...@@ -14,13 +14,12 @@ cd "$(dirname "$0")"
# CLI and app temporary locations # CLI and app temporary locations
# http://unix.stackexchange.com/a/84980 # 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_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'`
function cleanup { function cleanup {
echo 'Cleaning up.' echo 'Cleaning up.'
cd "$root_path" cd "$root_path"
rm -rf "$temp_cli_path" "$temp_app_path" rm -rf "$temp_app_path"
} }
# Error messages are redirected to stderr # Error messages are redirected to stderr
...@@ -55,10 +54,6 @@ function checkDependencies { ...@@ -55,10 +54,6 @@ function checkDependencies {
fi 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 # Exit the script with a helpful error message when any error is encountered
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
...@@ -72,6 +67,12 @@ set -x ...@@ -72,6 +67,12 @@ set -x
cd .. cd ..
root_path=$PWD root_path=$PWD
if hash npm 2>/dev/null
then
npm i -g npm@latest
npm cache clean || npm cache verify
fi
# Prevent bootstrap, we only want top-level dependencies # Prevent bootstrap, we only want top-level dependencies
cp package.json package.json.bak cp package.json package.json.bak
grep -v "postinstall" package.json > temp && mv temp package.json grep -v "postinstall" package.json > temp && mv temp package.json
...@@ -86,23 +87,32 @@ yarn run build:prod ...@@ -86,23 +87,32 @@ yarn run build:prod
cd ../.. cd ../..
# ****************************************************************************** # ******************************************************************************
# First, pack and install create-react-app. # First, publish the monorepo.
# ****************************************************************************** # ******************************************************************************
# Pack CLI # Start local registry
cd "$root_path"/packages/create-react-app tmp_registry_log=`mktemp`
cli_path=$PWD/`npm pack` nohup npx verdaccio@2.7.2 &>$tmp_registry_log &
# Wait for `verdaccio` to boot
grep -q 'http address' <(tail -f $tmp_registry_log)
# Set registry to local registry
npm set registry http://localhost:4873
yarn config set registry http://localhost:4873
# Login so we can publish packages
npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r http://localhost:4873 --quotes
# Install the CLI in a temporary location # Publish the monorepo
cd "$temp_cli_path" git clean -f
yarn add "$cli_path" ./tasks/release.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest
# ****************************************************************************** # ******************************************************************************
# Test --scripts-version with a version number # Test --scripts-version with a version number
# ****************************************************************************** # ******************************************************************************
cd "$temp_app_path" cd "$temp_app_path"
create_react_app --scripts-version=1.0.17 test-app-version-number npx create-react-app --scripts-version=1.0.17 test-app-version-number
cd test-app-version-number cd test-app-version-number
# Check corresponding scripts version is installed. # Check corresponding scripts version is installed.
...@@ -115,7 +125,7 @@ checkDependencies ...@@ -115,7 +125,7 @@ checkDependencies
# ****************************************************************************** # ******************************************************************************
cd "$temp_app_path" cd "$temp_app_path"
create_react_app --use-npm --scripts-version=1.0.17 test-use-npm-flag npx create-react-app --use-npm --scripts-version=1.0.17 test-use-npm-flag
cd test-use-npm-flag cd test-use-npm-flag
# Check corresponding scripts version is installed. # Check corresponding scripts version is installed.
...@@ -129,7 +139,7 @@ checkDependencies ...@@ -129,7 +139,7 @@ checkDependencies
# ****************************************************************************** # ******************************************************************************
cd "$temp_app_path" cd "$temp_app_path"
create_react_app --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-1.0.17.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 cd test-app-tarball-url
# Check corresponding scripts version is installed. # Check corresponding scripts version is installed.
...@@ -142,7 +152,7 @@ checkDependencies ...@@ -142,7 +152,7 @@ checkDependencies
# ****************************************************************************** # ******************************************************************************
cd "$temp_app_path" 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 cd test-app-fork
# Check corresponding scripts version is installed. # Check corresponding scripts version is installed.
...@@ -154,7 +164,7 @@ exists node_modules/react-scripts-fork ...@@ -154,7 +164,7 @@ exists node_modules/react-scripts-fork
cd "$temp_app_path" cd "$temp_app_path"
# we will install a non-existing package to simulate a failed installataion. # 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 # confirm that the project folder was deleted
test ! -d test-app-should-not-exist test ! -d test-app-should-not-exist
...@@ -166,7 +176,7 @@ cd "$temp_app_path" ...@@ -166,7 +176,7 @@ cd "$temp_app_path"
mkdir test-app-should-remain mkdir test-app-should-remain
echo '## Hello' > ./test-app-should-remain/README.md echo '## Hello' > ./test-app-should-remain/README.md
# we will install a non-existing package to simulate a failed installataion. # 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 # confirm the file exist
test -e test-app-should-remain/README.md test -e test-app-should-remain/README.md
# confirm only README.md is the only file in the directory # confirm only README.md is the only file in the directory
...@@ -180,7 +190,7 @@ fi ...@@ -180,7 +190,7 @@ fi
cd $temp_app_path 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 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 cd test-app-scoped-fork-tgz
# Check corresponding scripts version is installed. # Check corresponding scripts version is installed.
...@@ -195,20 +205,20 @@ cd "$temp_app_path" ...@@ -195,20 +205,20 @@ cd "$temp_app_path"
mkdir test-app-nested-paths-t1 mkdir test-app-nested-paths-t1
cd test-app-nested-paths-t1 cd test-app-nested-paths-t1
mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd 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 cd test-app-nested-paths-t1/aa/bb/cc/dd
yarn start --smoke-test yarn start --smoke-test
# Testing a path that does not exist # Testing a path that does not exist
cd "$temp_app_path" 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 cd test-app-nested-paths-t2/aa/bb/cc/dd
yarn start --smoke-test yarn start --smoke-test
# Testing a path that is half exists # Testing a path that is half exists
cd "$temp_app_path" cd "$temp_app_path"
mkdir -p test-app-nested-paths-t3/aa 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 cd test-app-nested-paths-t3/aa/bb/cc/dd
yarn start --smoke-test yarn start --smoke-test
......
...@@ -14,7 +14,6 @@ cd "$(dirname "$0")" ...@@ -14,7 +14,6 @@ cd "$(dirname "$0")"
# CLI, app, and test module temporary locations # CLI, app, and test module temporary locations
# http://unix.stackexchange.com/a/84980 # 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_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'` temp_module_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_module_path'`
...@@ -23,7 +22,7 @@ function cleanup { ...@@ -23,7 +22,7 @@ function cleanup {
ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -9 ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -9
cd "$root_path" cd "$root_path"
# TODO: fix "Device or resource busy" and remove ``|| $CI` # 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
} }
# Error messages are redirected to stderr # Error messages are redirected to stderr
...@@ -40,30 +39,6 @@ function handle_exit { ...@@ -40,30 +39,6 @@ function handle_exit {
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/
yarn --production
# 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. # Check for the existence of one or more files.
function exists { function exists {
for f in $*; do for f in $*; do
...@@ -84,6 +59,12 @@ set -x ...@@ -84,6 +59,12 @@ set -x
cd .. cd ..
root_path=$PWD root_path=$PWD
if hash npm 2>/dev/null
then
npm i -g npm@latest
npm cache clean || npm cache verify
fi
# Prevent bootstrap, we only want top-level dependencies # Prevent bootstrap, we only want top-level dependencies
cp package.json package.json.bak cp package.json package.json.bak
grep -v "postinstall" package.json > temp && mv temp package.json grep -v "postinstall" package.json > temp && mv temp package.json
...@@ -98,41 +79,33 @@ yarn build:prod ...@@ -98,41 +79,33 @@ yarn build:prod
cd ../.. cd ../..
# ****************************************************************************** # ******************************************************************************
# First, pack react-scripts and create-react-app so we can use them. # First, publish the monorepo.
# ****************************************************************************** # ******************************************************************************
# Pack CLI # Start local registry
cd "$root_path"/packages/create-react-app tmp_registry_log=`mktemp`
cli_path=$PWD/`npm pack` nohup npx verdaccio@2.7.2 &>$tmp_registry_log &
# Wait for `verdaccio` to boot
# Go to react-scripts grep -q 'http address' <(tail -f $tmp_registry_log)
cd "$root_path"/packages/react-scripts
# 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 # Set registry to local registry
# of those packages. npm set registry http://localhost:4873
node "$root_path"/tasks/replace-own-deps.js yarn config set registry http://localhost:4873
# Finally, pack react-scripts # Login so we can publish packages
scripts_path="$root_path"/packages/react-scripts/`npm pack` npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r http://localhost:4873 --quotes
# Restore package.json # Publish the monorepo
rm package.json git clean -f
mv package.json.orig package.json ./tasks/release.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"
yarn add "$cli_path"
# Install the app in a temporary location # Install the app in a temporary location
cd $temp_app_path 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 # Install the test module
cd "$temp_module_path" cd "$temp_module_path"
...@@ -146,14 +119,8 @@ yarn add test-integrity@^2.0.1 ...@@ -146,14 +119,8 @@ yarn add test-integrity@^2.0.1
# Enter the app directory # Enter the app directory
cd "$temp_app_path/test-kitchensink" 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 # 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 # Test the build
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
...@@ -198,16 +165,10 @@ E2E_FILE=./build/index.html \ ...@@ -198,16 +165,10 @@ E2E_FILE=./build/index.html \
# ****************************************************************************** # ******************************************************************************
# Eject... # Eject...
echo yes | npm run eject echo yes | yarn eject
# ...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 # 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 # Test the build
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment