Skip to content

Commit 1e15dc4

Browse files
committed
3.3.0
1 parent 0a1443d commit 1e15dc4

5 files changed

Lines changed: 128 additions & 24 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ if (['wpbuild', 'wpstart'].includes(script)) {
5757
console.log('Unknown script "' + script + '".');
5858
// console.log('Perhaps you need to update react-scripts?');
5959
console.log(
60-
"The original create-react-scripts commands are still available but must be prefixed with 'cra' (e.g. crastart, craeject, etc.)."
60+
"The original create-react-app script commands are still available but must be prefixed with 'cra' (e.g. crastart, craeject, etc.)."
6161
);
6262
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2015-present, Facebook, Inc.
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+
15+
// Make sure that including paths.js after env.js will read .env variables.
16+
delete require.cache[require.resolve('./paths-wptheme')];
17+
18+
const NODE_ENV = process.env.NODE_ENV;
19+
if (!NODE_ENV) {
20+
throw new Error(
21+
'The NODE_ENV environment variable is required but was not specified.'
22+
);
23+
}
24+
25+
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
26+
const dotenvFiles = [
27+
`${paths.dotenv}.${NODE_ENV}.local`,
28+
`${paths.dotenv}.${NODE_ENV}`,
29+
// Don't include `.env.local` for `test` environment
30+
// since normally you expect tests to produce the same
31+
// results for everyone
32+
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
33+
paths.dotenv,
34+
].filter(Boolean);
35+
36+
// Load environment variables from .env* files. Suppress warnings using silent
37+
// if this file is missing. dotenv will never modify any environment variables
38+
// that have already been set. Variable expansion is supported in .env files.
39+
// https://github.com/motdotla/dotenv
40+
// https://github.com/motdotla/dotenv-expand
41+
dotenvFiles.forEach(dotenvFile => {
42+
if (fs.existsSync(dotenvFile)) {
43+
require('dotenv-expand')(
44+
require('dotenv').config({
45+
path: dotenvFile,
46+
})
47+
);
48+
}
49+
});
50+
51+
// We support resolving modules according to `NODE_PATH`.
52+
// This lets you use absolute paths in imports inside large monorepos:
53+
// https://github.com/facebook/create-react-app/issues/253.
54+
// It works similar to `NODE_PATH` in Node itself:
55+
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
56+
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
57+
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
58+
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
59+
// We also resolve them to make sure all tools using them work consistently.
60+
const appDirectory = fs.realpathSync(process.cwd());
61+
process.env.NODE_PATH = (process.env.NODE_PATH || '')
62+
.split(path.delimiter)
63+
.filter(folder => folder && !path.isAbsolute(folder))
64+
.map(folder => path.resolve(appDirectory, folder))
65+
.join(path.delimiter);
66+
67+
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
68+
// injected into the application via DefinePlugin in Webpack configuration.
69+
const REACT_APP = /^REACT_APP_/i;
70+
71+
function getClientEnvironment(publicUrl) {
72+
const raw = Object.keys(process.env)
73+
.filter(key => REACT_APP.test(key))
74+
.reduce(
75+
(env, key) => {
76+
env[key] = process.env[key];
77+
return env;
78+
},
79+
{
80+
// Useful for determining whether we’re running in production mode.
81+
// Most importantly, it switches React into the correct mode.
82+
NODE_ENV: process.env.NODE_ENV || 'development',
83+
// Useful for resolving the correct path to static assets in `public`.
84+
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
85+
// This should only be used as an escape hatch. Normally you would put
86+
// images into the `src` and `import` them in code to get their paths.
87+
PUBLIC_URL: publicUrl,
88+
}
89+
);
90+
// Stringify all values so we can feed into Webpack DefinePlugin
91+
const stringified = {
92+
'process.env': Object.keys(raw).reduce((env, key) => {
93+
env[key] = JSON.stringify(raw[key]);
94+
return env;
95+
}, {}),
96+
};
97+
98+
return { raw, stringified };
99+
}
100+
101+
module.exports = getClientEnvironment;

packages/react-scripts/config/modules-wptheme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function getJestAliases(options = {}) {
101101

102102
if (path.relative(paths.appPath, baseUrlResolved) === '') {
103103
return {
104-
'src/(.*)$': '<rootDir>/src/$1',
104+
'^src/(.*)$': '<rootDir>/src/$1',
105105
};
106106
}
107107
}

packages/react-scripts/config/paths-wptheme.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,28 @@ if (
132132
!reactScriptsLinked &&
133133
__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
134134
) {
135+
const templatePath = '../cra-template/template';
135136
module.exports = {
136-
dotenv: resolveOwn('template/.env'),
137+
dotenv: resolveOwn(`${templatePath}/.env`),
137138
appPath: resolveApp('.'),
138139
appBuild: resolveOwn('../../build'),
139-
appPublic: resolveOwn('template/public'),
140-
appHtml: resolveOwn('template/public/index.php'),
141-
appIndexJs: resolveModule(resolveOwn, 'template/src/index'),
140+
appPublic: resolveOwn(`${templatePath}/public`),
141+
appHtml: resolveOwn(`${templatePath}/public/index.php`),
142+
appIndexJs: resolveModule(resolveOwn, `${templatePath}/src/index`),
142143
appPackageJson: resolveOwn('package.json'),
143-
appSrc: resolveOwn('template/src'),
144-
appTsConfig: resolveOwn('template/tsconfig.json'),
145-
appJsConfig: resolveOwn('template/jsconfig.json'),
146-
yarnLockFile: resolveOwn('template/yarn.lock'),
147-
testsSetup: resolveModule(resolveOwn, 'template/src/setupTests'),
148-
proxySetup: resolveOwn('template/src/setupProxy.js'),
144+
appSrc: resolveOwn(`${templatePath}/src`),
145+
appTsConfig: resolveOwn(`${templatePath}/tsconfig.json`),
146+
appJsConfig: resolveOwn(`${templatePath}/jsconfig.json`),
147+
yarnLockFile: resolveOwn(`${templatePath}/yarn.lock`),
148+
testsSetup: resolveModule(resolveOwn, `${templatePath}/src/setupTests`),
149+
proxySetup: resolveOwn(`${templatePath}/src/setupProxy.js`),
149150
appNodeModules: resolveOwn('node_modules'),
150151
publicUrl: getPublicUrl(resolveOwn('package.json')),
151152
servedPath: getServedPath(resolveOwn('package.json')),
152153
// These properties only exist before ejecting:
153154
ownPath: resolveOwn('.'),
154155
ownNodeModules: resolveOwn('node_modules'),
155-
appTypeDeclarations: resolveOwn('template/src/react-app-env.d.ts'),
156+
appTypeDeclarations: resolveOwn(`${templatePath}/src/react-app-env.d.ts`),
156157
ownTypeDeclarations: resolveOwn('lib/react-app.d.ts'),
157158
};
158159
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2929
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
3030
const paths = require('./paths-wptheme'); // wptheme modified
3131
const modules = require('./modules-wptheme'); // wptheme modified
32-
const getClientEnvironment = require('./env');
32+
const getClientEnvironment = require('./env-wptheme'); // wptheme modified
3333
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
3434
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
3535
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
36-
const eslint = require('eslint');
3736
// @remove-on-eject-begin
37+
const eslint = require('eslint');
3838
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3939
// @remove-on-eject-end
4040
const postcssNormalize = require('postcss-normalize');
@@ -514,11 +514,11 @@ module.exports = function(webpackEnv) {
514514
]
515515
),
516516
// @remove-on-eject-end
517-
// If an error happens in a package, it's possible to be
518-
// because it was compiled. Thus, we don't want the browser
519-
// debugger to show the original code. Instead, the code
520-
// being evaluated would be much more helpful.
521-
sourceMaps: false,
517+
// Babel sourcemaps are needed for debugging into node_modules
518+
// code. Without the options below, debuggers like VSCode
519+
// show incorrect code and set breakpoints on the wrong lines.
520+
sourceMaps: shouldUseSourceMap,
521+
inputSourceMap: shouldUseSourceMap,
522522
},
523523
},
524524
// "postcss" loader applies autoprefixer to our CSS.
@@ -548,8 +548,9 @@ module.exports = function(webpackEnv) {
548548
use: getStyleLoaders({
549549
importLoaders: 1,
550550
sourceMap: isEnvProduction && shouldUseSourceMap,
551-
modules: true,
552-
getLocalIdent: getCSSModuleLocalIdent,
551+
modules: {
552+
getLocalIdent: getCSSModuleLocalIdent,
553+
},
553554
}),
554555
},
555556
// Opt-in support for SASS (using .scss or .sass extensions).
@@ -579,8 +580,9 @@ module.exports = function(webpackEnv) {
579580
{
580581
importLoaders: 2,
581582
sourceMap: isEnvProduction && shouldUseSourceMap,
582-
modules: true,
583-
getLocalIdent: getCSSModuleLocalIdent,
583+
modules: {
584+
getLocalIdent: getCSSModuleLocalIdent,
585+
},
584586
},
585587
'sass-loader'
586588
),

0 commit comments

Comments
 (0)