Skip to content

Commit 29e06fc

Browse files
authored
Follow-up: use private registry (#3746)
* Convert e2e-installs * Convert kitchensink tests * Upgrade npm for kitchensink
1 parent 75d71e1 commit 29e06fc

File tree

2 files changed

+59
-88
lines changed

2 files changed

+59
-88
lines changed

tasks/e2e-installs.sh

+33-23
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ cd "$(dirname "$0")"
1414

1515
# CLI and app temporary locations
1616
# http://unix.stackexchange.com/a/84980
17-
temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'`
1817
temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'`
1918

2019
function cleanup {
2120
echo 'Cleaning up.'
2221
cd "$root_path"
23-
rm -rf "$temp_cli_path" "$temp_app_path"
22+
rm -rf "$temp_app_path"
2423
}
2524

2625
# Error messages are redirected to stderr
@@ -55,10 +54,6 @@ function checkDependencies {
5554
fi
5655
}
5756

58-
function create_react_app {
59-
node "$temp_cli_path"/node_modules/create-react-app/index.js $*
60-
}
61-
6257
# Exit the script with a helpful error message when any error is encountered
6358
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
6459

@@ -72,6 +67,12 @@ set -x
7267
cd ..
7368
root_path=$PWD
7469

70+
if hash npm 2>/dev/null
71+
then
72+
npm i -g npm@latest
73+
npm cache clean || npm cache verify
74+
fi
75+
7576
# Prevent bootstrap, we only want top-level dependencies
7677
cp package.json package.json.bak
7778
grep -v "postinstall" package.json > temp && mv temp package.json
@@ -86,23 +87,32 @@ yarn run build:prod
8687
cd ../..
8788

8889
# ******************************************************************************
89-
# First, pack and install create-react-app.
90+
# First, publish the monorepo.
9091
# ******************************************************************************
9192

92-
# Pack CLI
93-
cd "$root_path"/packages/create-react-app
94-
cli_path=$PWD/`npm pack`
93+
# Start local registry
94+
tmp_registry_log=`mktemp`
95+
nohup npx verdaccio@2.7.2 &>$tmp_registry_log &
96+
# Wait for `verdaccio` to boot
97+
grep -q 'http address' <(tail -f $tmp_registry_log)
98+
99+
# Set registry to local registry
100+
npm set registry http://localhost:4873
101+
yarn config set registry http://localhost:4873
102+
103+
# Login so we can publish packages
104+
npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r http://localhost:4873 --quotes
95105

96-
# Install the CLI in a temporary location
97-
cd "$temp_cli_path"
98-
yarn add "$cli_path"
106+
# Publish the monorepo
107+
git clean -f
108+
./tasks/release.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest
99109

100110
# ******************************************************************************
101111
# Test --scripts-version with a version number
102112
# ******************************************************************************
103113

104114
cd "$temp_app_path"
105-
create_react_app --scripts-version=1.0.17 test-app-version-number
115+
npx create-react-app --scripts-version=1.0.17 test-app-version-number
106116
cd test-app-version-number
107117

108118
# Check corresponding scripts version is installed.
@@ -115,7 +125,7 @@ checkDependencies
115125
# ******************************************************************************
116126

117127
cd "$temp_app_path"
118-
create_react_app --use-npm --scripts-version=1.0.17 test-use-npm-flag
128+
npx create-react-app --use-npm --scripts-version=1.0.17 test-use-npm-flag
119129
cd test-use-npm-flag
120130

121131
# Check corresponding scripts version is installed.
@@ -129,7 +139,7 @@ checkDependencies
129139
# ******************************************************************************
130140

131141
cd "$temp_app_path"
132-
create_react_app --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-1.0.17.tgz test-app-tarball-url
142+
npx create-react-app --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-1.0.17.tgz test-app-tarball-url
133143
cd test-app-tarball-url
134144

135145
# Check corresponding scripts version is installed.
@@ -142,7 +152,7 @@ checkDependencies
142152
# ******************************************************************************
143153

144154
cd "$temp_app_path"
145-
create_react_app --scripts-version=react-scripts-fork test-app-fork
155+
npx create-react-app --scripts-version=react-scripts-fork test-app-fork
146156
cd test-app-fork
147157

148158
# Check corresponding scripts version is installed.
@@ -154,7 +164,7 @@ exists node_modules/react-scripts-fork
154164

155165
cd "$temp_app_path"
156166
# we will install a non-existing package to simulate a failed installataion.
157-
create_react_app --scripts-version=`date +%s` test-app-should-not-exist || true
167+
npx create-react-app --scripts-version=`date +%s` test-app-should-not-exist || true
158168
# confirm that the project folder was deleted
159169
test ! -d test-app-should-not-exist
160170

@@ -166,7 +176,7 @@ cd "$temp_app_path"
166176
mkdir test-app-should-remain
167177
echo '## Hello' > ./test-app-should-remain/README.md
168178
# we will install a non-existing package to simulate a failed installataion.
169-
create_react_app --scripts-version=`date +%s` test-app-should-remain || true
179+
npx create-react-app --scripts-version=`date +%s` test-app-should-remain || true
170180
# confirm the file exist
171181
test -e test-app-should-remain/README.md
172182
# confirm only README.md is the only file in the directory
@@ -180,7 +190,7 @@ fi
180190

181191
cd $temp_app_path
182192
curl "https://registry.npmjs.org/@enoah_netzach/react-scripts/-/react-scripts-0.9.0.tgz" -o enoah-scripts-0.9.0.tgz
183-
create_react_app --scripts-version=$temp_app_path/enoah-scripts-0.9.0.tgz test-app-scoped-fork-tgz
193+
npx create-react-app --scripts-version=$temp_app_path/enoah-scripts-0.9.0.tgz test-app-scoped-fork-tgz
184194
cd test-app-scoped-fork-tgz
185195

186196
# Check corresponding scripts version is installed.
@@ -195,20 +205,20 @@ cd "$temp_app_path"
195205
mkdir test-app-nested-paths-t1
196206
cd test-app-nested-paths-t1
197207
mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd
198-
create_react_app test-app-nested-paths-t1/aa/bb/cc/dd
208+
npx create-react-app test-app-nested-paths-t1/aa/bb/cc/dd
199209
cd test-app-nested-paths-t1/aa/bb/cc/dd
200210
yarn start --smoke-test
201211

202212
# Testing a path that does not exist
203213
cd "$temp_app_path"
204-
create_react_app test-app-nested-paths-t2/aa/bb/cc/dd
214+
npx create-react-app test-app-nested-paths-t2/aa/bb/cc/dd
205215
cd test-app-nested-paths-t2/aa/bb/cc/dd
206216
yarn start --smoke-test
207217

208218
# Testing a path that is half exists
209219
cd "$temp_app_path"
210220
mkdir -p test-app-nested-paths-t3/aa
211-
create_react_app test-app-nested-paths-t3/aa/bb/cc/dd
221+
npx create-react-app test-app-nested-paths-t3/aa/bb/cc/dd
212222
cd test-app-nested-paths-t3/aa/bb/cc/dd
213223
yarn start --smoke-test
214224

tasks/e2e-kitchensink.sh

+26-65
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ cd "$(dirname "$0")"
1414

1515
# CLI, app, and test module temporary locations
1616
# http://unix.stackexchange.com/a/84980
17-
temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'`
1817
temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'`
1918
temp_module_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_module_path'`
2019

@@ -23,7 +22,7 @@ function cleanup {
2322
ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -9
2423
cd "$root_path"
2524
# TODO: fix "Device or resource busy" and remove ``|| $CI`
26-
rm -rf "$temp_cli_path" "$temp_app_path" "$temp_module_path" || $CI
25+
rm -rf "$temp_app_path" "$temp_module_path" || $CI
2726
}
2827

2928
# Error messages are redirected to stderr
@@ -40,30 +39,6 @@ function handle_exit {
4039
exit
4140
}
4241

43-
function create_react_app {
44-
node "$temp_cli_path"/node_modules/create-react-app/index.js "$@"
45-
}
46-
47-
function install_package {
48-
local pkg=$(basename $1)
49-
50-
# Clean target (for safety)
51-
rm -rf node_modules/$pkg/
52-
rm -rf node_modules/**/$pkg/
53-
54-
# Copy package into node_modules/ ignoring installed deps
55-
# rsync -a ${1%/} node_modules/ --exclude node_modules
56-
cp -R ${1%/} node_modules/
57-
rm -rf node_modules/$pkg/node_modules/
58-
59-
# Install `dependencies`
60-
cd node_modules/$pkg/
61-
yarn --production
62-
# Remove our packages to ensure side-by-side versions are used (which we link)
63-
rm -rf node_modules/{babel-preset-react-app,eslint-config-react-app,react-dev-utils,react-error-overlay,react-scripts}
64-
cd ../..
65-
}
66-
6742
# Check for the existence of one or more files.
6843
function exists {
6944
for f in $*; do
@@ -84,6 +59,12 @@ set -x
8459
cd ..
8560
root_path=$PWD
8661

62+
if hash npm 2>/dev/null
63+
then
64+
npm i -g npm@latest
65+
npm cache clean || npm cache verify
66+
fi
67+
8768
# Prevent bootstrap, we only want top-level dependencies
8869
cp package.json package.json.bak
8970
grep -v "postinstall" package.json > temp && mv temp package.json
@@ -98,41 +79,33 @@ yarn build:prod
9879
cd ../..
9980

10081
# ******************************************************************************
101-
# First, pack react-scripts and create-react-app so we can use them.
82+
# First, publish the monorepo.
10283
# ******************************************************************************
10384

104-
# Pack CLI
105-
cd "$root_path"/packages/create-react-app
106-
cli_path=$PWD/`npm pack`
107-
108-
# Go to react-scripts
109-
cd "$root_path"/packages/react-scripts
110-
111-
# Save package.json because we're going to touch it
112-
cp package.json package.json.orig
85+
# Start local registry
86+
tmp_registry_log=`mktemp`
87+
nohup npx verdaccio@2.7.2 &>$tmp_registry_log &
88+
# Wait for `verdaccio` to boot
89+
grep -q 'http address' <(tail -f $tmp_registry_log)
11390

114-
# Replace own dependencies (those in the `packages` dir) with the local paths
115-
# of those packages.
116-
node "$root_path"/tasks/replace-own-deps.js
91+
# Set registry to local registry
92+
npm set registry http://localhost:4873
93+
yarn config set registry http://localhost:4873
11794

118-
# Finally, pack react-scripts
119-
scripts_path="$root_path"/packages/react-scripts/`npm pack`
95+
# Login so we can publish packages
96+
npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r http://localhost:4873 --quotes
12097

121-
# Restore package.json
122-
rm package.json
123-
mv package.json.orig package.json
98+
# Publish the monorepo
99+
git clean -f
100+
./tasks/release.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest
124101

125102
# ******************************************************************************
126-
# Now that we have packed them, create a clean app folder and install them.
103+
# Now that we have published them, create a clean app folder and install them.
127104
# ******************************************************************************
128105

129-
# Install the CLI in a temporary location
130-
cd "$temp_cli_path"
131-
yarn add "$cli_path"
132-
133106
# Install the app in a temporary location
134107
cd $temp_app_path
135-
create_react_app --scripts-version="$scripts_path" --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink test-kitchensink
108+
npx create-react-app --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink test-kitchensink
136109

137110
# Install the test module
138111
cd "$temp_module_path"
@@ -146,14 +119,8 @@ yarn add test-integrity@^2.0.1
146119
# Enter the app directory
147120
cd "$temp_app_path/test-kitchensink"
148121

149-
# Link to our preset
150-
install_package "$root_path"/packages/babel-preset-react-app
151-
# Link to error overlay package because now it's a dependency
152-
# of react-dev-utils and not react-scripts
153-
install_package "$root_path"/packages/react-error-overlay
154-
155122
# Link to test module
156-
install_package "$temp_module_path/node_modules/test-integrity"
123+
npm link "$temp_module_path/node_modules/test-integrity"
157124

158125
# Test the build
159126
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
@@ -198,16 +165,10 @@ E2E_FILE=./build/index.html \
198165
# ******************************************************************************
199166

200167
# Eject...
201-
echo yes | npm run eject
202-
203-
# ...but still link to the local packages
204-
install_package "$root_path"/packages/babel-preset-react-app
205-
install_package "$root_path"/packages/eslint-config-react-app
206-
install_package "$root_path"/packages/react-error-overlay
207-
install_package "$root_path"/packages/react-dev-utils
168+
echo yes | yarn eject
208169

209170
# Link to test module
210-
install_package "$temp_module_path/node_modules/test-integrity"
171+
npm link "$temp_module_path/node_modules/test-integrity"
211172

212173
# Test the build
213174
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \

0 commit comments

Comments
 (0)