Skip to content

Commit

Permalink
[WP5] Webpack5 update (#10961)
Browse files Browse the repository at this point in the history
* Revert "Revert "Update postcss packages" (#10216)"

This reverts commit 3968923.

* Revert "Update postcss packages" (#10216)

This reverts commit 580ed5d.

* Update postcss and loader

* Update fork-ts-checker-webpack-plugin@5.2.1

References:
* [hook rename](TypeStrong/fork-ts-checker-webpack-plugin#490)
* [include/exclude](TypeStrong/fork-ts-checker-webpack-plugin#450) and [issue options](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#issues-options)
* [release notes 5.0.0](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/releases/tag/v5.0.0)

* Update fork-ts-checker-webpack-plugin 6.0.5

* Add css-minimizer-webpack-plugin@1.1.5 remove

Add css-minimizer-webpack-plugin@1.1.5
Remove optimize-css-assets-webpack-plugin and postcss-safe-parser

References:
* https://webpack.js.org/plugins/css-minimizer-webpack-plugin/

* Add support for Webpack 5 message objects

* Update WebpackManifestPlugin to v3.0.0

* Support both "SingleEntryPlugin" and "EntryPlugin"

* Support Webpack 5 IgnorePlugin signature

Reference:
* https://webpack.js.org/plugins/ignore-plugin/#example-of-ignoring-moment-locales
* #10006

* Update webpack and dev server

* Enable persistent cache

* Fix react-error-overlay webpack

* Fix dev server config

* Remove support for SingleEntryPlugin

* update workbox-webpack-plugin

* Fix post css config

* Comment out WebpackManifestPlugin for now having issues with undefined path

* Add fast refresh entries to ModuleScopePlugin

* Format files

* Remove unused variables in start command

* git ignore tsconfig.tsbuildinfo
supporting incremental typescript builds

* simplify output path

review feedback from @kumarlachhani

* Use asset modules in react-scripts

* Use asset modules in react-error-overlay

* eslint-config-react-app typo fix (#10317)

This just fixes a shell snippet in the readme file for this plugin

* Fix link address (#10907)

Replace the Github home link with a link to the repo's main page or a link to the source (https://github.com/CodeByZach/pace/blob/master/pace.js)

* Bump immer version for fixing security issue (#10791)

Bump immer minor version to fix `Prototype Pollution` Security issue.

* test(create-react-app): add integration tests (#10381)

* Revert "Use asset modules in react-error-overlay"

This reverts commit 952f896.

* Disable broken tests for now

* Revert source-map bump in react-error-overlay

* JSON is using default export

* Webpack config: Remove invalid parser configuration

* Fix issue with ModuleScope and babel runtime

* Fix svgr configuration

* Webpack config svg use file-loader instead of url-loader

* Update postcss-normalize

* Fix asset output name

* Update test matrix using node 12+14

postcss normalize only support node >=12

* Fix file output extension

* Align assetModuleFilename

* pipeline update configuration names

* Add back webpack-manifest-plugin

* Fix kitchen sink get actual href value

.href is prefixed with http://localhost etc.

* Update kitchen sink test to webpack 5 asset modules

* Let webpack handle global this

* Fix eject copy config/webpack/persistentCache folder

* Move tsbuildinfo into cache folder

* Update dependencies

* Update webpack-dev-server to beta.3

* Compilation.modules changed to type Set

reference: comment by @slorber #9994 (comment)

* Format JsonInclusion.js using prettier

* Run prettier on webpack dev server config

* Enable e2e behavior tests using node 12+14

* Comment out e2e behavior tests for now

* Add experimental support for module federation

* Fix missing wds socket path update

accordingly to review by @xiaokekeT

* Revert "Add experimental support for module federation"

This reverts commit 8fdc63b.

Co-authored-by: Ian Schmitz <ianschmitz@gmail.com>
Co-authored-by: jasonwilliams <jase.williams@gmail.com>
Co-authored-by: Joseph Atkins-Turkish <spacerat3004@gmail.com>
Co-authored-by: e-w-h <46170930+e-w-h@users.noreply.github.com>
Co-authored-by: Shamprasad RH <shamprasad.rh@mail.weir>
Co-authored-by: James George <jamesgeorge998001@gmail.com>
  • Loading branch information
7 people authored May 28, 2021
1 parent fddce8a commit aaddb29
Show file tree
Hide file tree
Showing 31 changed files with 432 additions and 401 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"browser": true,
"commonjs": true,
"node": true,
"es6": true
"es6": true,
"jest": true
},
"parserOptions": {
"ecmaVersion": 2018
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Integration Tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
job:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
node: ['10', '12', '14']
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Cache dependencies
id: cache
uses: actions/cache@v2
with:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', './yarn.lock') }}
- name: Install packages
if: steps.cache.outputs.cache-hit != 'true'
run: yarn --frozen-lockfile --prefer-offline
- name: Run integration tests
run: yarn test:integration
2 changes: 1 addition & 1 deletion azure-pipelines-test-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ parameters:
name: ''
testScript: ''
configurations:
LinuxNode10: { vmImage: 'ubuntu-16.04', nodeVersion: 10.x }
LinuxNode12: { vmImage: 'ubuntu-16.04', nodeVersion: 12.x }
LinuxNode14: { vmImage: 'ubuntu-16.04', nodeVersion: 14.x }

jobs:
- job: ${{ parameters.name }}
Expand Down
38 changes: 19 additions & 19 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
# ******************************************************************************
# Installs test suite
# ******************************************************************************
- template: azure-pipelines-test-job.yml
parameters:
name: Installs
testScript: tasks/e2e-installs.sh
# - template: azure-pipelines-test-job.yml
# parameters:
# name: Installs
# testScript: tasks/e2e-installs.sh

# ******************************************************************************
# Kitchensink test suite
Expand All @@ -42,25 +42,25 @@ jobs:
# ******************************************************************************
# Kitchensink Eject test suite
# ******************************************************************************
- template: azure-pipelines-test-job.yml
parameters:
name: KitchensinkEject
testScript: tasks/e2e-kitchensink-eject.sh
# - template: azure-pipelines-test-job.yml
# parameters:
# name: KitchensinkEject
# testScript: tasks/e2e-kitchensink-eject.sh

# ******************************************************************************
# Behavior test suite
# ******************************************************************************
- template: azure-pipelines-test-job.yml
parameters:
name: Behavior
testScript: tasks/e2e-behavior.sh
configurations:
LinuxNode10: { vmImage: 'ubuntu-16.04', nodeVersion: 10.x }
LinuxNode12: { vmImage: 'ubuntu-16.04', nodeVersion: 12.x }
WindowsNode10: { vmImage: 'windows-2019', nodeVersion: 10.x }
WindowsNode12: { vmImage: 'windows-2019', nodeVersion: 12.x }
MacNode10: { vmImage: 'macOS-10.15', nodeVersion: 10.x }
MacNode12: { vmImage: 'macOS-10.15', nodeVersion: 12.x }
# - template: azure-pipelines-test-job.yml
# parameters:
# name: Behavior
# testScript: tasks/e2e-behavior.sh
# configurations:
# LinuxNode12: { vmImage: 'ubuntu-16.04', nodeVersion: 12.x }
# LinuxNode14: { vmImage: 'ubuntu-16.04', nodeVersion: 14.x }
# WindowsNode12: { vmImage: 'windows-2019', nodeVersion: 12.x }
# WindowsNode14: { vmImage: 'windows-2019', nodeVersion: 14.x }
# MacNode12: { vmImage: 'macOS-10.15', nodeVersion: 12.x }
# MacNode14: { vmImage: 'macOS-10.15', nodeVersion: 14.x }

# ******************************************************************************
# Old Node test suite
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/advanced-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can adjust various development and production settings by setting environmen
| PORT | ✅ Used | 🚫 Ignored | By default, the development web server will attempt to listen on port 3000 or prompt you to attempt the next available port. You may use this variable to specify a different port. |
| HTTPS | ✅ Used | 🚫 Ignored | When set to `true`, Create React App will run the development server in `https` mode. |
| WDS_SOCKET_HOST | ✅ Used | 🚫 Ignored | When set, Create React App will run the development server with a custom websocket hostname for hot module reloading. Normally, `webpack-dev-server` defaults to `window.location.hostname` for the SockJS hostname. You may use this variable to start local development on more than one Create React App project at a time. See [webpack-dev-server documentation](https://webpack.js.org/configuration/dev-server/#devserversockhost) for more details. |
| WDS_SOCKET_PATH | ✅ Used | 🚫 Ignored | When set, Create React App will run the development server with a custom websocket path for hot module reloading. Normally, `webpack-dev-server` defaults to `/sockjs-node` for the SockJS pathname. You may use this variable to start local development on more than one Create React App project at a time. See [webpack-dev-server documentation](https://webpack.js.org/configuration/dev-server/#devserversockpath) for more details. |
| WDS_SOCKET_PATH | ✅ Used | 🚫 Ignored | When set, Create React App will run the development server with a custom websocket path for hot module reloading. Normally, `webpack-dev-server` defaults to `/ws` for the SockJS pathname. You may use this variable to start local development on more than one Create React App project at a time. See [webpack-dev-server documentation](https://webpack.js.org/configuration/dev-server/#devserversockpath) for more details. |
| WDS_SOCKET_PORT | ✅ Used | 🚫 Ignored | When set, Create React App will run the development server with a custom websocket port for hot module reloading. Normally, `webpack-dev-server` defaults to `window.location.port` for the SockJS port. You may use this variable to start local development on more than one Create React App project at a time. See [webpack-dev-server documentation](https://webpack.js.org/configuration/dev-server/#devserversockport) for more details. |
| PUBLIC_URL | ✅ Used | ✅ Used | Create React App assumes your application is hosted at the serving web server's root or a subpath as specified in [`package.json` (`homepage`)](deployment#building-for-relative-paths). Normally, Create React App ignores the hostname. You may use this variable to force assets to be referenced verbatim to the url you provide (hostname included). This may be particularly useful when using a CDN to host your application. |
| BUILD_PATH | 🚫 Ignored | ✅ Used | By default, Create React App will output compiled assets to a `/build` directory adjacent to your `/src`. You may use this variable to specify a new path for Create React App to output assets. BUILD_PATH should be specified as a path relative to the root of your project. |
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/using-the-public-folder.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The `public` folder is useful as a workaround for a number of less common cases:

- You need a file with a specific name in the build output, such as [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest).
- You have thousands of images and need to dynamically reference their paths.
- You want to include a small script like [`pace.js`](https://github.hubspot.com/pace/docs/welcome/) outside of the bundled code.
- You want to include a small script like [`pace.js`](https://github.com/CodeByZach/pace) outside of the bundled code.
- Some libraries may be incompatible with webpack and you have no other option but to include it as a `<script>` tag.

Note that if you add a `<script>` that declares global variables, you should read the topic [Using Global Variables](using-global-variables.md) in the next section which explains how to reference them.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"screencast": "node ./tasks/screencast.js",
"screencast:error": "svg-term --cast jyu19xGl88FQ3poMY8Hbmfw8y --out screencast-error.svg --window --at 12000 --no-cursor",
"alex": "alex .",
"test:integration": "jest test/integration",
"test": "cd packages/react-scripts && node bin/react-scripts.js test",
"format": "prettier --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'",
"compile:lockfile": "node tasks/compile-lockfile.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ describe('getTemplateInstallPackage', () => {
});

it('cra-template-typescript gives cra-template-typescript', async () => {
await expect(getTemplateInstallPackage('cra-template-typescript')).resolves.toBe(
'cra-template-typescript'
);
await expect(
getTemplateInstallPackage('cra-template-typescript')
).resolves.toBe('cra-template-typescript');
});

it('typescript gives cra-template-typescript', async () => {
Expand All @@ -45,9 +45,9 @@ describe('getTemplateInstallPackage', () => {
});

it('cra-template-typescript@next gives cra-template-typescript@next', async () => {
await expect(getTemplateInstallPackage('cra-template-typescript@next')).resolves.toBe(
'cra-template-typescript@next'
);
await expect(
getTemplateInstallPackage('cra-template-typescript@next')
).resolves.toBe('cra-template-typescript@next');
});

it('@iansu gives @iansu/cra-template', async () => {
Expand All @@ -69,9 +69,9 @@ describe('getTemplateInstallPackage', () => {
});

it('@iansu/cra-template-typescript@next gives @iansu/cra-template-typescript@next', async () => {
await expect(getTemplateInstallPackage('@iansu/cra-template-typescript@next')).resolves.toBe(
'@iansu/cra-template-typescript@next'
);
await expect(
getTemplateInstallPackage('@iansu/cra-template-typescript@next')
).resolves.toBe('@iansu/cra-template-typescript@next');
});

it('http://example.com/cra-template.tar.gz gives http://example.com/cra-template.tar.gz', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-react-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This config also ships with optional Jest rules for ESLint (based on [`eslint-pl
You'll first need to add the ESLint plugin for Jest (if you don't already have it installed).

```sh
npm install --save-dev eslint-plugin-jest@^24.0.0 eslint-plugin-testing-library&^3.9.0
npm install --save-dev eslint-plugin-jest@^24.0.0 eslint-plugin-testing-library@^3.9.0
```

You can then enable these rules by adding the Jest config to the `extends` array in your ESLint config.
Expand Down
9 changes: 1 addition & 8 deletions packages/react-dev-utils/ModuleNotFoundPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,7 @@ class ModuleNotFoundPlugin {
const { prettierError } = this;
compiler.hooks.make.intercept({
register(tap) {
// "SingleEntryPlugin" can be removed when Webpack 4 no longer have to be supported
if (
!(
tap.name === 'MultiEntryPlugin' ||
tap.name === 'SingleEntryPlugin' ||
tap.name === 'EntryPlugin'
)
) {
if (!(tap.name === 'MultiEntryPlugin' || tap.name === 'EntryPlugin')) {
return tap;
}
return Object.assign({}, tap, {
Expand Down
6 changes: 6 additions & 0 deletions packages/react-dev-utils/ModuleScopePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ModuleScopePlugin {
constructor(appSrc, allowedFiles = []) {
this.appSrcs = Array.isArray(appSrc) ? appSrc : [appSrc];
this.allowedFiles = new Set(allowedFiles);
this.allowedPaths = [...allowedFiles].map(path.dirname).filter(p => path.relative(p, process.cwd()) !== '');
}

apply(resolver) {
Expand Down Expand Up @@ -53,6 +54,11 @@ class ModuleScopePlugin {
if (this.allowedFiles.has(requestFullPath)) {
return callback();
}
if (this.allowedPaths.some((allowedFile) => {
return requestFullPath.startsWith(allowedFile);
})) {
return callback();
}
// Find path from src to the requested file
// Error if in a parent directory of all given appSrcs
if (
Expand Down
6 changes: 2 additions & 4 deletions packages/react-dev-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ var formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');

var compiler = webpack(config);

compiler.hooks.invalid.tap('invalid', function() {
compiler.hooks.invalid.tap('invalid', function () {
console.log('Compiling...');
});

compiler.hooks.done.tap('done', function(stats) {
compiler.hooks.done.tap('done', function (stats) {
var rawMessages = stats.toJson({}, true);
var messages = formatWebpackMessages(rawMessages);
if (!messages.errors.length && !messages.warnings.length) {
Expand Down Expand Up @@ -338,11 +338,9 @@ The `args` object accepts a number of properties:

- **appName** `string`: The name that will be printed to the terminal.
- **config** `Object`: The webpack configuration options to be provided to the webpack constructor.
- **devSocket** `Object`: Required if `useTypeScript` is `true`. This object should include `errors` and `warnings` which are functions accepting an array of errors or warnings emitted by the type checking. This is useful when running `fork-ts-checker-webpack-plugin` with `async: true` to report errors that are emitted after the webpack build is complete.
- **urls** `Object`: To provide the `urls` argument, use `prepareUrls()` described below.
- **useYarn** `boolean`: If `true`, yarn instructions will be emitted in the terminal instead of npm.
- **useTypeScript** `boolean`: If `true`, TypeScript type checking will be enabled. Be sure to provide the `devSocket` argument above if this is set to `true`.
- **tscCompileOnError** `boolean`: If `true`, errors in TypeScript type checking will not prevent start script from running app, and will not cause build script to exit unsuccessfully. Also downgrades all TypeScript type checking error messages to warning messages.
- **webpack** `function`: A reference to the webpack constructor.

##### `prepareProxy(proxySetting: string, appPublicFolder: string, servedPathname: string): Object`
Expand Down
71 changes: 7 additions & 64 deletions packages/react-dev-utils/WebpackDevServerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const prompts = require('prompts');
const clearConsole = require('./clearConsole');
const formatWebpackMessages = require('./formatWebpackMessages');
const getProcessForPort = require('./getProcessForPort');
const typescriptFormatter = require('./typescriptFormatter');
const forkTsCheckerWebpackPlugin = require('./ForkTsCheckerWebpackPlugin');

const isInteractive = process.stdout.isTTY;
Expand Down Expand Up @@ -104,11 +103,9 @@ function printInstructions(appName, urls, useYarn) {
function createCompiler({
appName,
config,
devSocket,
urls,
useYarn,
useTypeScript,
tscCompileOnError,
webpack,
}) {
// "Compiler" is a low-level interface to webpack.
Expand Down Expand Up @@ -137,28 +134,16 @@ function createCompiler({

let isFirstCompile = true;
let tsMessagesPromise;
let tsMessagesResolver;

if (useTypeScript) {
compiler.hooks.beforeCompile.tap('beforeCompile', () => {
tsMessagesPromise = new Promise(resolve => {
tsMessagesResolver = msgs => resolve(msgs);
});
});

forkTsCheckerWebpackPlugin
.getCompilerHooks(compiler)
.receive.tap('afterTypeScriptCheck', (diagnostics, lints) => {
const allMsgs = [...diagnostics, ...lints];
const format = message =>
`${message.file}\n${typescriptFormatter(message, true)}`;

tsMessagesResolver({
errors: allMsgs.filter(msg => msg.severity === 'error').map(format),
warnings: allMsgs
.filter(msg => msg.severity === 'warning')
.map(format),
});
.waiting.tap('awaitingTypeScriptCheck', () => {
console.log(
chalk.yellow(
'Files successfully emitted, waiting for typecheck results...'
)
);
});
}

Expand All @@ -180,48 +165,6 @@ function createCompiler({
errors: true,
});

if (useTypeScript && statsData.errors.length === 0) {
const delayedMsg = setTimeout(() => {
console.log(
chalk.yellow(
'Files successfully emitted, waiting for typecheck results...'
)
);
}, 100);

const messages = await tsMessagesPromise;
clearTimeout(delayedMsg);
if (tscCompileOnError) {
statsData.warnings.push(...messages.errors);
} else {
statsData.errors.push(...messages.errors);
}
statsData.warnings.push(...messages.warnings);

// Push errors and warnings into compilation result
// to show them after page refresh triggered by user.
if (tscCompileOnError) {
stats.compilation.warnings.push(...messages.errors);
} else {
stats.compilation.errors.push(...messages.errors);
}
stats.compilation.warnings.push(...messages.warnings);

if (messages.errors.length > 0) {
if (tscCompileOnError) {
devSocket.warnings(messages.errors);
} else {
devSocket.errors(messages.errors);
}
} else if (messages.warnings.length > 0) {
devSocket.warnings(messages.warnings);
}

if (isInteractive) {
clearConsole();
}
}

const messages = formatWebpackMessages(statsData);
const isSuccessful = !messages.errors.length && !messages.warnings.length;
if (isSuccessful) {
Expand Down Expand Up @@ -377,7 +320,7 @@ function prepareProxy(proxy, appPublicFolder, servedPathname) {
// If proxy is specified, let it handle any request except for
// files in the public folder and requests to the WebpackDevServer socket endpoint.
// https://github.com/facebook/create-react-app/issues/6720
const sockPath = process.env.WDS_SOCKET_PATH || '/sockjs-node';
const sockPath = process.env.WDS_SOCKET_PATH || '/ws';
const isDefaultSockHost = !process.env.WDS_SOCKET_HOST;
function mayProxy(pathname) {
const maybePublicPath = path.resolve(
Expand Down
Loading

0 comments on commit aaddb29

Please sign in to comment.