Skip to content

Commit 3437e65

Browse files
authored
Merge branch 'master' into use-offline-version-when-it-is-possible
2 parents efb8eea + 2b824d8 commit 3437e65

File tree

9 files changed

+131
-17
lines changed

9 files changed

+131
-17
lines changed

appveyor.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
environment:
2+
matrix:
3+
- nodejs_version: 6
4+
test_suite: "simple"
5+
- nodejs_version: 6
6+
test_suite: "installs"
7+
- nodejs_version: 6
8+
test_suite: "kitchensink"
9+
- nodejs_version: 4
10+
test_suite: "simple"
11+
- nodejs_version: 4
12+
test_suite: "installs"
13+
- nodejs_version: 4
14+
test_suite: "kitchensink"
15+
16+
cache:
17+
- node_modules
18+
- packages\react-scripts\node_modules
19+
20+
clone_depth: 50
21+
22+
branches:
23+
only:
24+
- master
25+
26+
matrix:
27+
fast_finish: true
28+
29+
platform:
30+
- x64
31+
32+
install:
33+
- ps: Install-Product node $env:nodejs_version $env:platform
34+
35+
build: off
36+
37+
test_script:
38+
- node --version
39+
- npm --version
40+
- sh tasks/e2e-%test_suite%.sh

packages/create-react-app/index.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'use strict';
4040

4141
var chalk = require('chalk');
42+
var validateProjectName = require("validate-npm-package-name");
4243

4344
var currentNodeVersion = process.versions.node;
4445
if (currentNodeVersion.split('.')[0] < 4) {
@@ -98,6 +99,14 @@ if (typeof projectName === 'undefined') {
9899
process.exit(1);
99100
}
100101

102+
function printValidationResults(results) {
103+
if (typeof results !== 'undefined') {
104+
results.forEach(function (error) {
105+
console.error(chalk.red(' * ' + error));
106+
});
107+
}
108+
}
109+
101110
var hiddenProgram = new commander.Command()
102111
.option('--internal-testing-template <path-to-template>', '(internal usage only, DO NOT RELY ON THIS) ' +
103112
'use a non-standard application template')
@@ -201,8 +210,9 @@ function run(root, appName, version, verbose, originalDirectory, template) {
201210
checkNodeVersion(packageName);
202211

203212
// Since react-scripts has been installed with --save
204-
// We need to move it into devDependencies and rewrite package.json
205-
moveReactScriptsToDev(packageName);
213+
// we need to move it into devDependencies and rewrite package.json
214+
// also ensure react dependencies have caret version range
215+
fixDependencies(packageName);
206216

207217
var scriptsPath = path.resolve(
208218
process.cwd(),
@@ -234,6 +244,7 @@ function run(root, appName, version, verbose, originalDirectory, template) {
234244
if (!remainingFiles.length) {
235245
// Delete target folder if empty
236246
console.log('Deleting', chalk.cyan(appName + '/'), 'from', chalk.cyan(path.resolve(root, '..')));
247+
process.chdir(path.resolve(root, '..'));
237248
fs.removeSync(path.join(root));
238249
}
239250
console.log('Done.');
@@ -317,11 +328,18 @@ function checkNodeVersion(packageName) {
317328
}
318329

319330
function checkAppName(appName) {
331+
var validationResult = validateProjectName(appName);
332+
if (!validationResult.validForNewPackages) {
333+
console.error('Could not create a project called ' + chalk.red('"' + appName + '"') + ' because of npm naming restrictions:');
334+
printValidationResults(validationResult.errors);
335+
printValidationResults(validationResult.warnings);
336+
process.exit(1);
337+
}
338+
320339
// TODO: there should be a single place that holds the dependencies
321340
var dependencies = ['react', 'react-dom'];
322341
var devDependencies = ['react-scripts'];
323342
var allDependencies = dependencies.concat(devDependencies).sort();
324-
325343
if (allDependencies.indexOf(appName) >= 0) {
326344
console.error(
327345
chalk.red(
@@ -339,7 +357,29 @@ function checkAppName(appName) {
339357
}
340358
}
341359

342-
function moveReactScriptsToDev(packageName) {
360+
function makeCaretRange(dependencies, name) {
361+
var version = dependencies[name];
362+
363+
if (typeof version === 'undefined') {
364+
console.error(
365+
chalk.red('Missing ' + name + ' dependency in package.json')
366+
);
367+
process.exit(1);
368+
}
369+
370+
var patchedVersion = '^' + version;
371+
372+
if (!semver.validRange(patchedVersion)) {
373+
console.error(
374+
'Unable to patch ' + name + ' dependency version because version ' + chalk.red(version) + ' will become invalid ' + chalk.red(patchedVersion)
375+
);
376+
patchedVersion = version;
377+
}
378+
379+
dependencies[name] = patchedVersion;
380+
}
381+
382+
function fixDependencies(packageName) {
343383
var packagePath = path.join(process.cwd(), 'package.json');
344384
var packageJson = require(packagePath);
345385

@@ -363,6 +403,9 @@ function moveReactScriptsToDev(packageName) {
363403
packageJson.devDependencies[packageName] = packageVersion;
364404
delete packageJson.dependencies[packageName];
365405

406+
makeCaretRange(packageJson.dependencies, 'react');
407+
makeCaretRange(packageJson.dependencies, 'react-dom');
408+
366409
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
367410
}
368411

packages/create-react-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"commander": "^2.9.0",
2525
"cross-spawn": "^4.0.0",
2626
"fs-extra": "^1.0.0",
27-
"semver": "^5.0.3"
27+
"semver": "^5.0.3",
28+
"validate-npm-package-name": "^3.0.0"
2829
}
2930
}

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,13 @@ module.exports = {
114114
test: /\.(js|jsx)$/,
115115
enforce: 'pre',
116116
use: [{
117+
// @remove-on-eject-begin
118+
// Point ESLint to our predefined config.
117119
options: {
118-
// @remove-on-eject-begin
119-
// Point ESLint to our predefined config.
120120
configFile: path.join(__dirname, '../.eslintrc'),
121-
useEslintrc: false,
122-
// @remove-on-eject-end
123-
cache: true
121+
useEslintrc: false
124122
},
123+
// @remove-on-eject-end
125124
loader: 'eslint-loader'
126125
}],
127126
include: paths.appSrc

packages/react-scripts/scripts/start.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ function addMiddleware(devServer) {
220220
onError: onProxyError(proxy),
221221
secure: false,
222222
changeOrigin: true,
223-
ws: true
223+
ws: true,
224+
xfwd: true
224225
});
225226
devServer.use(mayProxy, hpm);
226227

packages/react-scripts/template/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Then add the block below to your `launch.json` file and put it inside the `.vsco
269269
"request": "launch",
270270
"url": "http://localhost:3000",
271271
"webRoot": "${workspaceRoot}/src",
272-
"userDataDir": "${workspaceRoot}/.chrome",
272+
"userDataDir": "${workspaceRoot}/.vscode/chrome",
273273
"sourceMapPathOverrides": {
274274
"webpack:///src/*": "${webRoot}/*"
275275
}

tasks/e2e-installs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ cd $temp_app_path
127127
# we will install a non-existing package to simulate a failed installataion.
128128
create_react_app --scripts-version=`date +%s` test-app-should-not-exist || true
129129
# confirm that the project folder was deleted
130-
test ! -d test-app-should-not-exist
130+
# test ! -d test-app-should-not-exist
131131

132132
# ******************************************************************************
133133
# Test project folder is not deleted when creating app over existing folder

tasks/e2e-kitchensink.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'`
2121

2222
function cleanup {
2323
echo 'Cleaning up.'
24+
ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -s 9
2425
cd $root_path
25-
rm -rf $temp_cli_path $temp_app_path
26+
# TODO: fix "Device or resource busy" and remove ``|| $CI`
27+
rm -rf $temp_cli_path $temp_app_path || $CI
2628
}
2729

2830
# Error messages are redirected to stderr
@@ -143,12 +145,19 @@ PORT=3001 \
143145
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
144146
NODE_PATH=src \
145147
nohup npm start &>$tmp_server_log &
146-
grep -q 'The app is running at:' <(tail -f $tmp_server_log)
148+
while true
149+
do
150+
if grep -q 'The app is running at:' $tmp_server_log; then
151+
break
152+
else
153+
sleep 1
154+
fi
155+
done
147156
E2E_URL="http://localhost:3001" \
148157
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
149158
CI=true NODE_PATH=src \
150159
NODE_ENV=development \
151-
node node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
160+
node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
152161

153162
# Test "production" environment
154163
E2E_FILE=./build/index.html \
@@ -197,7 +206,14 @@ PORT=3002 \
197206
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
198207
NODE_PATH=src \
199208
nohup npm start &>$tmp_server_log &
200-
grep -q 'The app is running at:' <(tail -f $tmp_server_log)
209+
while true
210+
do
211+
if grep -q 'The app is running at:' $tmp_server_log; then
212+
break
213+
else
214+
sleep 1
215+
fi
216+
done
201217
E2E_URL="http://localhost:3002" \
202218
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
203219
CI=true NODE_PATH=src \

tasks/e2e-simple.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ set -x
6565
cd ..
6666
root_path=$PWD
6767

68+
# Prevent lerna bootstrap, we only want top-level dependencies
69+
cp package.json package.json.bak
70+
grep -v "lerna bootstrap" package.json > temp && mv temp package.json
71+
npm install
72+
mv package.json.bak package.json
73+
74+
# We need to install create-react-app deps to test it
75+
cd "$root_path"/packages/create-react-app
76+
npm install
77+
cd "$root_path"
78+
6879
# If the node version is < 4, the script should just give an error.
6980
if [[ `node --version | sed -e 's/^v//' -e 's/\..*//g'` -lt 4 ]]
7081
then
@@ -73,6 +84,9 @@ then
7384
[[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1
7485
fi
7586

87+
# Still use npm install instead of directly calling lerna bootstrap to test
88+
# postinstall script functionality (one npm install should result in a working
89+
# project)
7690
npm install
7791

7892
if [ "$USE_YARN" = "yes" ]

0 commit comments

Comments
 (0)