Skip to content

Commit ea00d4f

Browse files
committed
Merge branch '3.2.0'
2 parents 55b8f14 + 6865029 commit ea00d4f

25 files changed

+455
-166
lines changed

packages/react-scripts/LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2013-present, Facebook, Inc.
3+
Some files: Copyright (c) 2013-present, Facebook, Inc.
4+
Some files: Copyright (c) 2019-present, https://github.com/devloco
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

packages/react-scripts/bin/react-scripts.js

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,35 @@ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
2626

2727
script = script.replace(/cra/, ''); // wptheme -- added
2828

29-
switch (script) {
30-
case 'build':
31-
case 'eject':
32-
case 'start':
33-
case 'test': {
34-
const result = spawn.sync(
35-
'node',
36-
nodeArgs
37-
.concat(require.resolve('../scripts/' + script))
38-
.concat(args.slice(scriptIndex + 1)),
39-
{ stdio: 'inherit' }
40-
);
41-
if (result.signal) {
42-
if (result.signal === 'SIGKILL') {
43-
console.log(
44-
'The build failed because the process exited too early. ' +
45-
'This probably means the system ran out of memory or someone called ' +
46-
'`kill -9` on the process.'
47-
);
48-
} else if (result.signal === 'SIGTERM') {
49-
console.log(
50-
'The build failed because the process exited too early. ' +
51-
'Someone might have called `kill` or `killall`, or the system could ' +
52-
'be shutting down.'
53-
);
54-
}
55-
process.exit(1);
29+
if (['build', 'eject', 'start', 'test'].includes(script)) {
30+
const result = spawn.sync(
31+
'node',
32+
nodeArgs
33+
.concat(require.resolve('../scripts/' + script))
34+
.concat(args.slice(scriptIndex + 1)),
35+
{ stdio: 'inherit' }
36+
);
37+
if (result.signal) {
38+
if (result.signal === 'SIGKILL') {
39+
console.log(
40+
'The build failed because the process exited too early. ' +
41+
'This probably means the system ran out of memory or someone called ' +
42+
'`kill -9` on the process.'
43+
);
44+
} else if (result.signal === 'SIGTERM') {
45+
console.log(
46+
'The build failed because the process exited too early. ' +
47+
'Someone might have called `kill` or `killall`, or the system could ' +
48+
'be shutting down.'
49+
);
5650
}
57-
process.exit(result.status);
58-
break;
51+
process.exit(1);
5952
}
60-
default:
61-
console.log('Unknown script "' + script + '".');
62-
console.log('Perhaps you need to update react-scripts?');
63-
console.log(
64-
'See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases'
65-
);
66-
break;
53+
process.exit(result.status);
54+
} else {
55+
console.log('Unknown script "' + script + '".');
56+
console.log('Perhaps you need to update react-scripts?');
57+
console.log(
58+
'See: https://github.com/devloco/create-react-wptheme#updating-existing-themes'
59+
);
6760
}
Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
#!/usr/bin/env node
22
/**
3-
* Copyright (c) 2018-present, https://github.com/devloco
3+
* Copyright (c) 2019-present, https://github.com/devloco
44
*
55
* This source code is licensed under the MIT license found in the
66
* LICENSE file in the root directory of this source tree.
77
*/
88

99
'use strict';
1010

11+
// Makes the script crash on unhandled rejections instead of silently
12+
// ignoring them. In the future, promise rejections that are not handled will
13+
// terminate the Node.js process with a non-zero exit code.
14+
process.on('unhandledRejection', err => {
15+
throw err;
16+
});
17+
1118
const spawn = require('react-dev-utils/crossSpawn');
1219
const args = process.argv.slice(2);
1320

1421
const scriptIndex = args.findIndex(
1522
x => x === 'build' || x === 'start' || x === 'wpbuild' || x === 'wpstart'
1623
);
24+
let script = scriptIndex === -1 ? args[0] : args[scriptIndex]; // wptheme -- change to "let" to allow modification...
1725
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
1826

19-
let script = scriptIndex === -1 ? args[0] : args[scriptIndex];
2027
if (!script.startsWith('wp')) {
2128
script = `wp${script}`;
2229
}
2330

24-
switch (script) {
25-
case 'wpbuild':
26-
case 'wpstart': {
27-
const result = spawn.sync(
28-
'node',
29-
nodeArgs
30-
.concat(require.resolve('../scripts/' + script))
31-
.concat(args.slice(scriptIndex + 1)),
32-
{ stdio: 'inherit' }
33-
);
34-
if (result.signal) {
35-
if (result.signal === 'SIGKILL') {
36-
console.log('The build failed because the process exited too early.');
37-
console.log(
38-
'This probably means the system ran out of memory or someone called `kill -9` on the process.'
39-
);
40-
} else if (result.signal === 'SIGTERM') {
41-
console.log('The build failed because the process exited too early.');
42-
console.log(
43-
'Someone might have called `kill` or `killall`, or the system could be shutting down.'
44-
);
45-
}
46-
47-
process.exit(1);
31+
if (['wpbuild', 'wpstart'].includes(script)) {
32+
const result = spawn.sync(
33+
'node',
34+
nodeArgs
35+
.concat(require.resolve('../scripts/' + script))
36+
.concat(args.slice(scriptIndex + 1)),
37+
{ stdio: 'inherit' }
38+
);
39+
if (result.signal) {
40+
if (result.signal === 'SIGKILL') {
41+
console.log(
42+
'The build failed because the process exited too early. ' +
43+
'This probably means the system ran out of memory or someone called ' +
44+
'`kill -9` on the process.'
45+
);
46+
} else if (result.signal === 'SIGTERM') {
47+
console.log(
48+
'The build failed because the process exited too early. ' +
49+
'Someone might have called `kill` or `killall`, or the system could ' +
50+
'be shutting down.'
51+
);
4852
}
49-
50-
process.exit(result.status);
51-
break;
53+
process.exit(1);
5254
}
53-
default:
54-
console.log('Unknown script "' + script + '".');
55-
console.log(
56-
"The original create-react-scripts commands are still available but must be prefixed with 'cra' (e.g. crastart, craeject, etc.)."
57-
);
58-
break;
55+
process.exit(result.status);
56+
} else {
57+
console.log('Unknown script "' + script + '".');
58+
// console.log('Perhaps you need to update react-scripts?');
59+
console.log(
60+
"The original create-react-scripts commands are still available but must be prefixed with 'cra' (e.g. crastart, craeject, etc.)."
61+
);
5962
}

packages/react-scripts/config/jest/fileTransform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ module.exports = {
1313
if (filename.match(/\.svg$/)) {
1414
// Based on how SVGR generates a component name:
1515
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
16-
const pascalCaseFileName = camelcase(path.parse(filename).name, {
16+
const pascalCaseFilename = camelcase(path.parse(filename).name, {
1717
pascalCase: true,
1818
});
19-
const componentName = `Svg${pascalCaseFileName}`;
19+
const componentName = `Svg${pascalCaseFilename}`;
2020
return `const React = require('react');
2121
module.exports = {
2222
__esModule: true,
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2019-present, https://github.com/devloco
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
// @remove-on-eject-end
9+
'use strict';
10+
11+
const fs = require('fs');
12+
const path = require('path');
13+
const paths = require('./paths-wptheme');
14+
const chalk = require('react-dev-utils/chalk');
15+
const resolve = require('resolve');
16+
17+
/**
18+
* Get additional module paths based on the baseUrl of a compilerOptions object.
19+
*
20+
* @param {Object} options
21+
*/
22+
function getAdditionalModulePaths(options = {}) {
23+
const baseUrl = options.baseUrl;
24+
25+
// We need to explicitly check for null and undefined (and not a falsy value) because
26+
// TypeScript treats an empty string as `.`.
27+
if (baseUrl == null) {
28+
// If there's no baseUrl set we respect NODE_PATH
29+
// Note that NODE_PATH is deprecated and will be removed
30+
// in the next major release of create-react-app.
31+
32+
const nodePath = process.env.NODE_PATH || '';
33+
return nodePath.split(path.delimiter).filter(Boolean);
34+
}
35+
36+
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
37+
38+
// We don't need to do anything if `baseUrl` is set to `node_modules`. This is
39+
// the default behavior.
40+
if (path.relative(paths.appNodeModules, baseUrlResolved) === '') {
41+
return null;
42+
}
43+
44+
// Allow the user set the `baseUrl` to `appSrc`.
45+
if (path.relative(paths.appSrc, baseUrlResolved) === '') {
46+
return [paths.appSrc];
47+
}
48+
49+
// If the path is equal to the root directory we ignore it here.
50+
// We don't want to allow importing from the root directly as source files are
51+
// not transpiled outside of `src`. We do allow importing them with the
52+
// absolute path (e.g. `src/Components/Button.js`) but we set that up with
53+
// an alias.
54+
if (path.relative(paths.appPath, baseUrlResolved) === '') {
55+
return null;
56+
}
57+
58+
// Otherwise, throw an error.
59+
throw new Error(
60+
chalk.red.bold(
61+
"Your project's `baseUrl` can only be set to `src` or `node_modules`." +
62+
' Create React App does not support other values at this time.'
63+
)
64+
);
65+
}
66+
67+
/**
68+
* Get webpack aliases based on the baseUrl of a compilerOptions object.
69+
*
70+
* @param {*} options
71+
*/
72+
function getWebpackAliases(options = {}) {
73+
const baseUrl = options.baseUrl;
74+
75+
if (!baseUrl) {
76+
return {};
77+
}
78+
79+
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
80+
81+
if (path.relative(paths.appPath, baseUrlResolved) === '') {
82+
return {
83+
src: paths.appSrc,
84+
};
85+
}
86+
}
87+
88+
/**
89+
* Get jest aliases based on the baseUrl of a compilerOptions object.
90+
*
91+
* @param {*} options
92+
*/
93+
function getJestAliases(options = {}) {
94+
const baseUrl = options.baseUrl;
95+
96+
if (!baseUrl) {
97+
return {};
98+
}
99+
100+
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
101+
102+
if (path.relative(paths.appPath, baseUrlResolved) === '') {
103+
return {
104+
'src/(.*)$': '<rootDir>/src/$1',
105+
};
106+
}
107+
}
108+
109+
function getModules() {
110+
// Check if TypeScript is setup
111+
const hasTsConfig = fs.existsSync(paths.appTsConfig);
112+
const hasJsConfig = fs.existsSync(paths.appJsConfig);
113+
114+
if (hasTsConfig && hasJsConfig) {
115+
throw new Error(
116+
'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.'
117+
);
118+
}
119+
120+
let config;
121+
122+
// If there's a tsconfig.json we assume it's a
123+
// TypeScript project and set up the config
124+
// based on tsconfig.json
125+
if (hasTsConfig) {
126+
const ts = require(resolve.sync('typescript', {
127+
basedir: paths.appNodeModules,
128+
}));
129+
config = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile).config;
130+
// Otherwise we'll check if there is jsconfig.json
131+
// for non TS projects.
132+
} else if (hasJsConfig) {
133+
config = require(paths.appJsConfig);
134+
}
135+
136+
config = config || {};
137+
const options = config.compilerOptions || {};
138+
139+
const additionalModulePaths = getAdditionalModulePaths(options);
140+
141+
return {
142+
additionalModulePaths: additionalModulePaths,
143+
webpackAliases: getWebpackAliases(options),
144+
jestAliases: getJestAliases(options),
145+
hasTsConfig,
146+
};
147+
}
148+
149+
module.exports = getModules();

0 commit comments

Comments
 (0)