From 0512cd6a261eb738059aac4769ea31e66aab2065 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 8 Dec 2020 01:23:49 +0000 Subject: [PATCH] Bump fixture dependency versions (#20397) * Bump all versions * Switch to CJS mode * Revert "Switch to CJS mode" This reverts commit b3c4fd92dcef6ecb4116fc66f674ae88aad3c582. * Fix ES mode * Add nodemon to restart the server on edits * Ignore /server/ from compilation --- fixtures/flight/.gitignore | 1 + fixtures/flight/config/env.js | 21 +- fixtures/flight/config/getHttpsConfig.js | 66 + fixtures/flight/config/jest/cssTransform.js | 2 +- fixtures/flight/config/jest/fileTransform.js | 2 +- fixtures/flight/config/modules.js | 13 +- fixtures/flight/config/paths.js | 35 +- fixtures/flight/config/webpack.config.js | 302 +- .../flight/config/webpackDevServer.config.js | 58 +- fixtures/flight/package.json | 128 +- fixtures/flight/scripts/build.js | 43 +- fixtures/flight/scripts/start.js | 37 +- fixtures/flight/server/cli.server.js | 21 +- fixtures/flight/server/handler.server.js | 10 +- fixtures/flight/yarn.lock | 8435 +++++++++++------ 15 files changed, 5861 insertions(+), 3313 deletions(-) create mode 100644 fixtures/flight/config/getHttpsConfig.js diff --git a/fixtures/flight/.gitignore b/fixtures/flight/.gitignore index 800f3a80c3481..0852d35565e81 100644 --- a/fixtures/flight/.gitignore +++ b/fixtures/flight/.gitignore @@ -11,6 +11,7 @@ # production /build /dist +.eslintcache # misc .DS_Store diff --git a/fixtures/flight/config/env.js b/fixtures/flight/config/env.js index 940be1eb1159e..56ac7fbd0e75e 100644 --- a/fixtures/flight/config/env.js +++ b/fixtures/flight/config/env.js @@ -17,11 +17,11 @@ if (!NODE_ENV) { // /~https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use const dotenvFiles = [ `${paths.dotenv}.${NODE_ENV}.local`, - `${paths.dotenv}.${NODE_ENV}`, // Don't include `.env.local` for `test` environment // since normally you expect tests to produce the same // results for everyone NODE_ENV !== 'test' && `${paths.dotenv}.local`, + `${paths.dotenv}.${NODE_ENV}`, paths.dotenv, ].filter(Boolean); @@ -46,7 +46,7 @@ dotenvFiles.forEach(dotenvFile => { // It works similar to `NODE_PATH` in Node itself: // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. -// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. +// Otherwise, we risk importing Node.js core modules into an app instead of webpack shims. // /~https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421 // We also resolve them to make sure all tools using them work consistently. const appDirectory = fs.realpathSync(process.cwd()); @@ -57,7 +57,7 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '') .join(path.delimiter); // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be -// injected into the application via DefinePlugin in Webpack configuration. +// injected into the application via DefinePlugin in webpack configuration. const REACT_APP = /^REACT_APP_/i; function getClientEnvironment(publicUrl) { @@ -77,9 +77,22 @@ function getClientEnvironment(publicUrl) { // This should only be used as an escape hatch. Normally you would put // images into the `src` and `import` them in code to get their paths. PUBLIC_URL: publicUrl, + // We support configuring the sockjs pathname during development. + // These settings let a developer run multiple simultaneous projects. + // They are used as the connection `hostname`, `pathname` and `port` + // in webpackHotDevClient. They are used as the `sockHost`, `sockPath` + // and `sockPort` options in webpack-dev-server. + WDS_SOCKET_HOST: process.env.WDS_SOCKET_HOST, + WDS_SOCKET_PATH: process.env.WDS_SOCKET_PATH, + WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT, + // Whether or not react-refresh is enabled. + // react-refresh is not 100% stable at this time, + // which is why it's disabled by default. + // It is defined here so it is available in the webpackHotDevClient. + FAST_REFRESH: process.env.FAST_REFRESH !== 'false', } ); - // Stringify all values so we can feed into Webpack DefinePlugin + // Stringify all values so we can feed into webpack DefinePlugin const stringified = { 'process.env': Object.keys(raw).reduce((env, key) => { env[key] = JSON.stringify(raw[key]); diff --git a/fixtures/flight/config/getHttpsConfig.js b/fixtures/flight/config/getHttpsConfig.js new file mode 100644 index 0000000000000..2120a07ec331b --- /dev/null +++ b/fixtures/flight/config/getHttpsConfig.js @@ -0,0 +1,66 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const crypto = require('crypto'); +const chalk = require('react-dev-utils/chalk'); +const paths = require('./paths'); + +// Ensure the certificate and key provided are valid and if not +// throw an easy to debug error +function validateKeyAndCerts({cert, key, keyFile, crtFile}) { + let encrypted; + try { + // publicEncrypt will throw an error with an invalid cert + encrypted = crypto.publicEncrypt(cert, Buffer.from('test')); + } catch (err) { + throw new Error( + `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}` + ); + } + + try { + // privateDecrypt will throw an error with an invalid key + crypto.privateDecrypt(key, encrypted); + } catch (err) { + throw new Error( + `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${ + err.message + }` + ); + } +} + +// Read file and throw an error if it doesn't exist +function readEnvFile(file, type) { + if (!fs.existsSync(file)) { + throw new Error( + `You specified ${chalk.cyan( + type + )} in your env, but the file "${chalk.yellow(file)}" can't be found.` + ); + } + return fs.readFileSync(file); +} + +// Get the https config +// Return cert files if provided in env, otherwise just true or false +function getHttpsConfig() { + const {SSL_CRT_FILE, SSL_KEY_FILE, HTTPS} = process.env; + const isHttps = HTTPS === 'true'; + + if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) { + const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE); + const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE); + const config = { + cert: readEnvFile(crtFile, 'SSL_CRT_FILE'), + key: readEnvFile(keyFile, 'SSL_KEY_FILE'), + }; + + validateKeyAndCerts({...config, keyFile, crtFile}); + return config; + } + return isHttps; +} + +module.exports = getHttpsConfig; diff --git a/fixtures/flight/config/jest/cssTransform.js b/fixtures/flight/config/jest/cssTransform.js index 35fe644d7e034..8f65114812a4e 100644 --- a/fixtures/flight/config/jest/cssTransform.js +++ b/fixtures/flight/config/jest/cssTransform.js @@ -1,7 +1,7 @@ 'use strict'; // This is a custom Jest transformer turning style imports into empty objects. -// https://jestjs.io/docs/en/webpack.html +// http://facebook.github.io/jest/docs/en/webpack.html module.exports = { process() { diff --git a/fixtures/flight/config/jest/fileTransform.js b/fixtures/flight/config/jest/fileTransform.js index 3ce5e04c6e436..aab67618c38b4 100644 --- a/fixtures/flight/config/jest/fileTransform.js +++ b/fixtures/flight/config/jest/fileTransform.js @@ -4,7 +4,7 @@ const path = require('path'); const camelcase = require('camelcase'); // This is a custom Jest transformer turning file imports into filenames. -// https://jestjs.io/docs/en/webpack.html +// http://facebook.github.io/jest/docs/en/webpack.html module.exports = { process(src, filename) { diff --git a/fixtures/flight/config/modules.js b/fixtures/flight/config/modules.js index c84210a8f4fef..d63e41d78dc7e 100644 --- a/fixtures/flight/config/modules.js +++ b/fixtures/flight/config/modules.js @@ -14,15 +14,8 @@ const resolve = require('resolve'); function getAdditionalModulePaths(options = {}) { const baseUrl = options.baseUrl; - // We need to explicitly check for null and undefined (and not a falsy value) because - // TypeScript treats an empty string as `.`. - if (baseUrl == null) { - // If there's no baseUrl set we respect NODE_PATH - // Note that NODE_PATH is deprecated and will be removed - // in the next major release of create-react-app. - - const nodePath = process.env.NODE_PATH || ''; - return nodePath.split(path.delimiter).filter(Boolean); + if (!baseUrl) { + return ''; } const baseUrlResolved = path.resolve(paths.appPath, baseUrl); @@ -93,7 +86,7 @@ function getJestAliases(options = {}) { if (path.relative(paths.appPath, baseUrlResolved) === '') { return { - 'src/(.*)$': '/src/$1', + '^src/(.*)$': '/src/$1', }; } } diff --git a/fixtures/flight/config/paths.js b/fixtures/flight/config/paths.js index df5eb072bbd49..20c5e12018038 100644 --- a/fixtures/flight/config/paths.js +++ b/fixtures/flight/config/paths.js @@ -2,41 +2,24 @@ const path = require('path'); const fs = require('fs'); -const url = require('url'); +const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath'); // Make sure any symlinks in the project folder are resolved: // /~https://github.com/facebook/create-react-app/issues/637 const appDirectory = fs.realpathSync(process.cwd()); const resolveApp = relativePath => path.resolve(appDirectory, relativePath); -const envPublicUrl = process.env.PUBLIC_URL; - -function ensureSlash(inputPath, needsSlash) { - const hasSlash = inputPath.endsWith('/'); - if (hasSlash && !needsSlash) { - return inputPath.substr(0, inputPath.length - 1); - } else if (!hasSlash && needsSlash) { - return `${inputPath}/`; - } else { - return inputPath; - } -} - -const getPublicUrl = appPackageJson => - envPublicUrl || require(appPackageJson).homepage; - // We use `PUBLIC_URL` environment variable or "homepage" field to infer // "public path" at which the app is served. -// Webpack needs to know it to put the right