Skip to content

Commit 0512cd6

Browse files
authored
Bump fixture dependency versions (#20397)
* Bump all versions * Switch to CJS mode * Revert "Switch to CJS mode" This reverts commit b3c4fd9. * Fix ES mode * Add nodemon to restart the server on edits * Ignore /server/ from compilation
1 parent b66ae09 commit 0512cd6

15 files changed

+5861
-3313
lines changed

fixtures/flight/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# production
1212
/build
1313
/dist
14+
.eslintcache
1415

1516
# misc
1617
.DS_Store

fixtures/flight/config/env.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ if (!NODE_ENV) {
1717
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
1818
const dotenvFiles = [
1919
`${paths.dotenv}.${NODE_ENV}.local`,
20-
`${paths.dotenv}.${NODE_ENV}`,
2120
// Don't include `.env.local` for `test` environment
2221
// since normally you expect tests to produce the same
2322
// results for everyone
2423
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
24+
`${paths.dotenv}.${NODE_ENV}`,
2525
paths.dotenv,
2626
].filter(Boolean);
2727

@@ -46,7 +46,7 @@ dotenvFiles.forEach(dotenvFile => {
4646
// It works similar to `NODE_PATH` in Node itself:
4747
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
4848
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
49-
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
49+
// Otherwise, we risk importing Node.js core modules into an app instead of webpack shims.
5050
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
5151
// We also resolve them to make sure all tools using them work consistently.
5252
const appDirectory = fs.realpathSync(process.cwd());
@@ -57,7 +57,7 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '')
5757
.join(path.delimiter);
5858

5959
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
60-
// injected into the application via DefinePlugin in Webpack configuration.
60+
// injected into the application via DefinePlugin in webpack configuration.
6161
const REACT_APP = /^REACT_APP_/i;
6262

6363
function getClientEnvironment(publicUrl) {
@@ -77,9 +77,22 @@ function getClientEnvironment(publicUrl) {
7777
// This should only be used as an escape hatch. Normally you would put
7878
// images into the `src` and `import` them in code to get their paths.
7979
PUBLIC_URL: publicUrl,
80+
// We support configuring the sockjs pathname during development.
81+
// These settings let a developer run multiple simultaneous projects.
82+
// They are used as the connection `hostname`, `pathname` and `port`
83+
// in webpackHotDevClient. They are used as the `sockHost`, `sockPath`
84+
// and `sockPort` options in webpack-dev-server.
85+
WDS_SOCKET_HOST: process.env.WDS_SOCKET_HOST,
86+
WDS_SOCKET_PATH: process.env.WDS_SOCKET_PATH,
87+
WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
88+
// Whether or not react-refresh is enabled.
89+
// react-refresh is not 100% stable at this time,
90+
// which is why it's disabled by default.
91+
// It is defined here so it is available in the webpackHotDevClient.
92+
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
8093
}
8194
);
82-
// Stringify all values so we can feed into Webpack DefinePlugin
95+
// Stringify all values so we can feed into webpack DefinePlugin
8396
const stringified = {
8497
'process.env': Object.keys(raw).reduce((env, key) => {
8598
env[key] = JSON.stringify(raw[key]);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const crypto = require('crypto');
6+
const chalk = require('react-dev-utils/chalk');
7+
const paths = require('./paths');
8+
9+
// Ensure the certificate and key provided are valid and if not
10+
// throw an easy to debug error
11+
function validateKeyAndCerts({cert, key, keyFile, crtFile}) {
12+
let encrypted;
13+
try {
14+
// publicEncrypt will throw an error with an invalid cert
15+
encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
16+
} catch (err) {
17+
throw new Error(
18+
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
19+
);
20+
}
21+
22+
try {
23+
// privateDecrypt will throw an error with an invalid key
24+
crypto.privateDecrypt(key, encrypted);
25+
} catch (err) {
26+
throw new Error(
27+
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
28+
err.message
29+
}`
30+
);
31+
}
32+
}
33+
34+
// Read file and throw an error if it doesn't exist
35+
function readEnvFile(file, type) {
36+
if (!fs.existsSync(file)) {
37+
throw new Error(
38+
`You specified ${chalk.cyan(
39+
type
40+
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`
41+
);
42+
}
43+
return fs.readFileSync(file);
44+
}
45+
46+
// Get the https config
47+
// Return cert files if provided in env, otherwise just true or false
48+
function getHttpsConfig() {
49+
const {SSL_CRT_FILE, SSL_KEY_FILE, HTTPS} = process.env;
50+
const isHttps = HTTPS === 'true';
51+
52+
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
53+
const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
54+
const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
55+
const config = {
56+
cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
57+
key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
58+
};
59+
60+
validateKeyAndCerts({...config, keyFile, crtFile});
61+
return config;
62+
}
63+
return isHttps;
64+
}
65+
66+
module.exports = getHttpsConfig;

fixtures/flight/config/jest/cssTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
// This is a custom Jest transformer turning style imports into empty objects.
4-
// https://jestjs.io/docs/en/webpack.html
4+
// http://facebook.github.io/jest/docs/en/webpack.html
55

66
module.exports = {
77
process() {

fixtures/flight/config/jest/fileTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const path = require('path');
44
const camelcase = require('camelcase');
55

66
// This is a custom Jest transformer turning file imports into filenames.
7-
// https://jestjs.io/docs/en/webpack.html
7+
// http://facebook.github.io/jest/docs/en/webpack.html
88

99
module.exports = {
1010
process(src, filename) {

fixtures/flight/config/modules.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,8 @@ const resolve = require('resolve');
1414
function getAdditionalModulePaths(options = {}) {
1515
const baseUrl = options.baseUrl;
1616

17-
// We need to explicitly check for null and undefined (and not a falsy value) because
18-
// TypeScript treats an empty string as `.`.
19-
if (baseUrl == null) {
20-
// If there's no baseUrl set we respect NODE_PATH
21-
// Note that NODE_PATH is deprecated and will be removed
22-
// in the next major release of create-react-app.
23-
24-
const nodePath = process.env.NODE_PATH || '';
25-
return nodePath.split(path.delimiter).filter(Boolean);
17+
if (!baseUrl) {
18+
return '';
2619
}
2720

2821
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
@@ -93,7 +86,7 @@ function getJestAliases(options = {}) {
9386

9487
if (path.relative(paths.appPath, baseUrlResolved) === '') {
9588
return {
96-
'src/(.*)$': '<rootDir>/src/$1',
89+
'^src/(.*)$': '<rootDir>/src/$1',
9790
};
9891
}
9992
}

fixtures/flight/config/paths.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,24 @@
22

33
const path = require('path');
44
const fs = require('fs');
5-
const url = require('url');
5+
const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
66

77
// Make sure any symlinks in the project folder are resolved:
88
// https://github.com/facebook/create-react-app/issues/637
99
const appDirectory = fs.realpathSync(process.cwd());
1010
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
1111

12-
const envPublicUrl = process.env.PUBLIC_URL;
13-
14-
function ensureSlash(inputPath, needsSlash) {
15-
const hasSlash = inputPath.endsWith('/');
16-
if (hasSlash && !needsSlash) {
17-
return inputPath.substr(0, inputPath.length - 1);
18-
} else if (!hasSlash && needsSlash) {
19-
return `${inputPath}/`;
20-
} else {
21-
return inputPath;
22-
}
23-
}
24-
25-
const getPublicUrl = appPackageJson =>
26-
envPublicUrl || require(appPackageJson).homepage;
27-
2812
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
2913
// "public path" at which the app is served.
30-
// Webpack needs to know it to put the right <script> hrefs into HTML even in
14+
// webpack needs to know it to put the right <script> hrefs into HTML even in
3115
// single-page apps that may serve index.html for nested URLs like /todos/42.
3216
// We can't use a relative path in HTML because we don't want to load something
3317
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
34-
function getServedPath(appPackageJson) {
35-
const publicUrl = getPublicUrl(appPackageJson);
36-
const servedUrl =
37-
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
38-
return ensureSlash(servedUrl, true);
39-
}
18+
const publicUrlOrPath = getPublicUrlOrPath(
19+
process.env.NODE_ENV === 'development',
20+
require(resolveApp('package.json')).homepage,
21+
process.env.PUBLIC_URL
22+
);
4023

4124
const moduleFileExtensions = [
4225
'web.mjs',
@@ -81,8 +64,8 @@ module.exports = {
8164
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
8265
proxySetup: resolveApp('src/setupProxy.js'),
8366
appNodeModules: resolveApp('node_modules'),
84-
publicUrl: getPublicUrl(resolveApp('package.json')),
85-
servedPath: getServedPath(resolveApp('package.json')),
67+
swSrc: resolveModule(resolveApp, 'src/service-worker'),
68+
publicUrlOrPath,
8669
};
8770

8871
module.exports.moduleFileExtensions = moduleFileExtensions;

0 commit comments

Comments
 (0)