Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack 5 #11201

Merged
merged 35 commits into from Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
aaddb29
[WP5] Webpack5 update (#10961)
raix May 28, 2021
da654e6
Update Webpack dependencies and fix minor issues (#11170)
Jul 12, 2021
6d3dbed
Merge branch 'main' into wp5
Jul 15, 2021
0a7b095
Merge branch 'main' into wp5
Jul 15, 2021
44c6958
Remove package-lock file
Jul 15, 2021
faf8b66
Drop node 10 and 12, add 16
Jul 15, 2021
b213cf3
Remove dependency check for babel-eslint
Jul 15, 2021
b5caccf
Use md5 for the environment config webpack 5 cache invalidation hash
Jul 15, 2021
f8e0fdb
compile lockfile
Jul 16, 2021
b41322a
Bump @babel/eslint-parser to 7.14.7
Jul 16, 2021
0508303
Fix missing @babel/eslint-parser dev dependency
Jul 16, 2021
18045c0
ModuleScopePlugin ignore @babel/runtime/helpers/esm/assertThisInitial…
Jul 16, 2021
af889e1
Move azurepipelines to ubuntu-latest
Jul 16, 2021
2d3639c
Webpack config remove requireEnsure
Jul 16, 2021
a7b4b6e
ModuleScopePlugin ignore @babel/runtime/regenerator
Jul 16, 2021
c3abea1
Update node-sass from v4 to v6 in fixtures
Jul 16, 2021
7130cdf
Update eslint to 7.30.0
Jul 16, 2021
6e10091
Fix eslint shareable config using rushstack/eslint-patch
Jul 17, 2021
a2df30e
Format eslint patch using prettier
Jul 17, 2021
0674cd7
Remove rest of `TSC_COMPILE_ON_ERROR`
Jul 17, 2021
09cb3d2
Fix html-webpack-plugin asset module support output
Jul 17, 2021
5bf34cd
Revert "Remove rest of `TSC_COMPILE_ON_ERROR`"
Jul 17, 2021
8cf9f02
Add ForkTsCheckerWarningWebpackPlugin to support TSC_COMPILE_ON_ERROR
Jul 17, 2021
892844e
Update css-loader, mini-css-extract-plugin, webpack-dev-server
Jul 20, 2021
a717786
Convert compileType to module in missing css-loaders
Jul 20, 2021
5a9d460
Use webpack hot client and error overlay
Jul 29, 2021
fea0a69
Eslint preset move patch to base
Jul 29, 2021
a23e653
Fix eslint apply patch in jest config
Jul 29, 2021
34326df
Update missing node checks and references to +14
Jul 30, 2021
a2c859a
Replace CaseSensitivePathsPlugin with eslint import rule
Aug 2, 2021
908b3c1
Fix react-error-overlay lint issue
Aug 2, 2021
2c77dd7
Ignore react-error-overlay lint issue
Aug 2, 2021
51eb804
Revert "Ignore react-error-overlay lint issue"
Aug 2, 2021
f9784bf
Revert "Fix react-error-overlay lint issue"
Aug 2, 2021
a702d6a
Revert "Replace CaseSensitivePathsPlugin with eslint import rule"
Aug 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
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
@@ -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']
raix marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
raix marked this conversation as resolved.
Show resolved Hide resolved
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
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 }
raix marked this conversation as resolved.
Show resolved Hide resolved

jobs:
- job: ${{ parameters.name }}
Expand Down
38 changes: 19 additions & 19 deletions azure-pipelines.yml
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
raix marked this conversation as resolved.
Show resolved Hide resolved
# 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
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
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
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
12 changes: 12 additions & 0 deletions packages/babel-preset-react-app/create.js
Expand Up @@ -146,12 +146,24 @@ module.exports = function (api, opts, env) {
// class { handleClick = () => { } }
// Enable loose mode to use assignment instead of defineProperty
// See discussion in https://github.com/facebook/create-react-app/issues/4263
// Note:
// 'loose' mode configuration must be the same for
// * @babel/plugin-proposal-class-properties
// * @babel/plugin-proposal-private-methods
// * @babel/plugin-proposal-private-property-in-object
// (when they are enabled)
[
require('@babel/plugin-proposal-class-properties').default,
{
loose: true,
},
],
[
require('@babel/plugin-proposal-private-methods').default,
{
loose: true,
},
],
// Adds Numeric Separators
require('@babel/plugin-proposal-numeric-separator').default,
// Polyfills the runtime needed for async/await, generators, and friends
Expand Down
29 changes: 15 additions & 14 deletions packages/babel-preset-react-app/package.json
Expand Up @@ -21,20 +21,21 @@
"test.js"
],
"dependencies": {
"@babel/core": "7.12.3",
"@babel/plugin-proposal-class-properties": "7.12.1",
"@babel/plugin-proposal-decorators": "7.12.1",
"@babel/plugin-proposal-nullish-coalescing-operator": "7.12.1",
"@babel/plugin-proposal-numeric-separator": "7.12.1",
"@babel/plugin-proposal-optional-chaining": "7.12.1",
"@babel/plugin-transform-flow-strip-types": "7.12.1",
"@babel/plugin-transform-react-display-name": "7.12.1",
"@babel/plugin-transform-runtime": "7.12.1",
"@babel/preset-env": "7.12.1",
"@babel/preset-react": "7.12.1",
"@babel/preset-typescript": "7.12.1",
"@babel/runtime": "7.12.1",
"babel-plugin-macros": "2.8.0",
"@babel/core": "7.14.6",
"@babel/plugin-proposal-class-properties": "7.14.5",
"@babel/plugin-proposal-decorators": "7.14.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "7.14.5",
"@babel/plugin-proposal-numeric-separator": "7.14.5",
"@babel/plugin-proposal-optional-chaining": "7.14.5",
"@babel/plugin-proposal-private-methods": "7.14.5",
"@babel/plugin-transform-flow-strip-types": "7.14.5",
"@babel/plugin-transform-react-display-name": "7.14.5",
"@babel/plugin-transform-runtime": "7.14.5",
"@babel/preset-env": "7.14.5",
"@babel/preset-react": "7.14.5",
"@babel/preset-typescript": "7.14.5",
"@babel/runtime": "7.14.5",
"babel-plugin-macros": "3.1.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.24"
}
}
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
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
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
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()) !== '');
raix marked this conversation as resolved.
Show resolved Hide resolved
}

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
31 changes: 2 additions & 29 deletions packages/react-dev-utils/README.md
Expand Up @@ -111,31 +111,6 @@ module.exports = {
};
```

#### `new WatchMissingNodeModulesPlugin(nodeModulesPath: string)`

This webpack plugin ensures `npm install <library>` forces a project rebuild.<br>
We’re not sure why this isn't webpack's default behavior.<br>
See [#186](https://github.com/facebook/create-react-app/issues/186) for details.

```js
var path = require('path');
var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');

// webpack config
module.exports = {
// ...
plugins: [
// ...
// If you require a missing module and then `npm install` it, you still have
// to restart the development server for webpack to discover it. This plugin
// makes the discovery automatic so you don't have to restart.
// See https://github.com/facebook/create-react-app/issues/186
new WatchMissingNodeModulesPlugin(path.resolve('node_modules')),
],
// ...
};
```

#### `checkRequiredFiles(files: Array<string>): boolean`

Makes sure that all passed files exist.<br>
Expand Down Expand Up @@ -231,11 +206,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 +313,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