Skip to content

Commit 7a6c78c

Browse files
committed
breaking: remove webpack built-ins shimmed in from webpack 4 to 5 upgrade as they should no longer be needed for most users
1 parent 088c40d commit 7a6c78c

File tree

27 files changed

+2060
-267
lines changed

27 files changed

+2060
-267
lines changed

.circleci/cache-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Bump this version to force CI to re-create the cache from scratch.
22

3-
5-12-2025
3+
5-21-2025

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ _Released 07/01/2025 (PENDING)_
1313
- The Cypress configuration wizard for Component Testing supports TypeScript 5.0 or greater. Addresses [#31187](https://github.com/cypress-io/cypress/issues/31187).
1414
- `@cypress/webpack-dev-server` and `@cypress/webpack-preprocessor` no longer support `webpack` version 4. Addresses [#31344](https://github.com/cypress-io/cypress/issues/31344). If you still need to use `webpack` version 4, please see our [migration guide](https://docs.cypress.io/app/references/migration-guide#Migrating-to-Cypress-150).
1515
- `@cypress/webpack-dev-server` no longer supports `webpack-dev-server` version 4. Addresses [#31605](https://github.com/cypress-io/cypress/issues/31605). If you still need to use `webpack-dev-server` version 4, please see our [migration guide](https://docs.cypress.io/app/references/migration-guide#Migrating-to-Cypress-150).
16+
- `@cypress/webpack-batteries-included-preprocessor` no longer ships with browser built-ins that came by default with Webpack 4. Please see [resolve.fallback](https://webpack.js.org/configuration/resolve/#resolvefallback) for a list of available built-ins, as well as the [`@cypress/webpack-batteries-included-preprocessor` README](../npm/webpack-batteries-included-preprocessor/README.md) for how to add built-ins to the preprocessor.
1617

1718
**Features:**
1819

npm/webpack-batteries-included-preprocessor/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ npm install --save-dev @cypress/webpack-batteries-included-preprocessor @cypress
2222

2323
## Usage
2424

25-
In your project's [plugins file](https://on.cypress.io/guides/tooling/plugins-guide.html):
25+
In your project's [cypress.config.js file](https://on.cypress.io/guides/tooling/plugins-guide.html):
2626

2727
```javascript
2828
const webpackPreprocessor = require('@cypress/webpack-batteries-included-preprocessor')
@@ -44,6 +44,29 @@ module.exports = (on) => {
4444
}
4545
```
4646

47+
As for version `4.x.x`, webpack built-ins are no longer shipped by default with `@cypress/webpack-batteries-included-preprocessor`. If you need to install built-ins, you can always get the default `@cypress/webpack-batteries-included-preprocessor` webpack options the preprocessor ships with and decorate them:
48+
49+
```javascript
50+
const webpackPreprocessor = require('@cypress/webpack-batteries-included-preprocessor')
51+
52+
function getWebpackOptions () {
53+
const options = webpackPreprocessor.getFullWebpackOptions()
54+
55+
// add built-ins as needed
56+
options.resolve.fallback.path = require.resolve('path-browserify')
57+
58+
return options
59+
}
60+
61+
module.exports = (on) => {
62+
on('file:preprocessor', webpackPreprocessor({
63+
webpackOptions: getWebpackOptions()
64+
}))
65+
}
66+
```
67+
68+
Please see [resolve.fallback](see https://webpack.js.org/configuration/resolve/#resolvefallback) for more information on what built-ins can be shimmed.
69+
4770
Other than the `typescript` option, this preprocessor supports the same options as [@cypress/webpack-preprocessor](https://github.com/cypress-io/cypress/tree/develop/npm/webpack-preprocessor#readme), so see its [README](https://github.com/cypress-io/cypress/tree/develop/npm/webpack-preprocessor#readme) for more information.
4871

4972
## Debugging

npm/webpack-batteries-included-preprocessor/index.js

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require('path')
2-
const webpack = require('webpack')
32
const Debug = require('debug')
43
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
54
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
@@ -120,24 +119,6 @@ const getDefaultWebpackOptions = () => {
120119
}],
121120
},
122121
plugins: [
123-
new webpack.ProvidePlugin({
124-
Buffer: ['buffer', 'Buffer'],
125-
// As of Webpack 5, a new option called resolve.fullySpecified, was added.
126-
// This option means that a full path, in particular to .mjs / .js files
127-
// in ESM packages must have the full path of an import specified.
128-
// Otherwise, compilation fails as this option defaults to true.
129-
// This means we need to adjust our global injections to always
130-
// resolve to include the full file extension if a file resolution is provided.
131-
// @see https://github.com/cypress-io/cypress/issues/27599
132-
// @see https://webpack.js.org/configuration/module/#resolvefullyspecified
133-
134-
// Due to Pnp compatibility issues, we want to make sure that we resolve to the 'process' library installed with the binary,
135-
// which should resolve on leaf app/packages/server/node_modules/@cypress/webpack-batteries-included-preprocessor and up the tree.
136-
// In other words, we want to resolve 'process' that is installed with cypress (or the package itself, i.e. @cypress/webpack-batteries-included-preprocessor)
137-
// and not in the user's node_modules directory as it may not exist.
138-
// @see https://github.com/cypress-io/cypress/issues/27947.
139-
process: require.resolve('process/browser.js'),
140-
}),
141122
// If the user is trying to debug their bundle, we'll add the BundleAnalyzerPlugin
142123
// to see the size of the support file (first bundle when running `cypress open`)
143124
// and spec files (subsequent bundles when running `cypress open`)
@@ -146,42 +127,42 @@ const getDefaultWebpackOptions = () => {
146127
resolve: {
147128
extensions: ['.js', '.json', '.jsx', '.mjs', '.coffee'],
148129
fallback: {
149-
assert: require.resolve('assert/'),
150-
buffer: require.resolve('buffer/'),
130+
assert: false,
131+
buffer: false,
151132
child_process: false,
152133
cluster: false,
153134
console: false,
154-
constants: require.resolve('constants-browserify'),
155-
crypto: require.resolve('crypto-browserify'),
135+
constants: false,
136+
crypto: false,
156137
dgram: false,
157138
dns: false,
158-
domain: require.resolve('domain-browser'),
159-
events: require.resolve('events/'),
139+
domain: false,
140+
events: false,
160141
fs: false,
161-
http: require.resolve('stream-http'),
162-
https: require.resolve('https-browserify'),
142+
http: false,
143+
https: false,
163144
http2: false,
164145
inspector: false,
165146
module: false,
166147
net: false,
167-
os: require.resolve('os-browserify/browser'),
168-
path: require.resolve('path-browserify'),
148+
os: false,
149+
path: false,
169150
perf_hooks: false,
170-
punycode: require.resolve('punycode/'),
171-
process: require.resolve('process/browser.js'),
172-
querystring: require.resolve('querystring-es3'),
151+
punycode: false,
152+
process: false,
153+
querystring: false,
173154
readline: false,
174155
repl: false,
175-
stream: require.resolve('stream-browserify'),
176-
string_decoder: require.resolve('string_decoder/'),
177-
sys: require.resolve('util/'),
178-
timers: require.resolve('timers-browserify'),
156+
stream: false,
157+
string_decoder: false,
158+
sys: false,
159+
timers: false,
179160
tls: false,
180-
tty: require.resolve('tty-browserify'),
181-
url: require.resolve('url/'),
182-
util: require.resolve('util/'),
183-
vm: require.resolve('vm-browserify'),
184-
zlib: require.resolve('browserify-zlib'),
161+
tty: false,
162+
url: false,
163+
util: false,
164+
vm: false,
165+
zlib: false,
185166
},
186167
plugins: [],
187168
},

npm/webpack-batteries-included-preprocessor/package.json

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,14 @@
1515
"@babel/preset-env": "^7.25.3",
1616
"@babel/preset-react": "^7.24.7",
1717
"@babel/runtime": "^7.25.0",
18-
"assert": "^2.0.0",
1918
"babel-loader": "^10.0.0",
2019
"babel-plugin-add-module-exports": "^1.0.2",
21-
"browserify-zlib": "^0.2.0",
22-
"buffer": "^6.0.3",
2320
"coffee-loader": "^4.0.0",
2421
"coffeescript": "2.6.0",
25-
"constants-browserify": "^1.0.0",
26-
"crypto-browserify": "^3.12.0",
2722
"debug": "^4.3.4",
28-
"domain-browser": "^4.22.0",
29-
"events": "^3.3.0",
3023
"get-tsconfig": "^4.10.0",
31-
"https-browserify": "^1.0.0",
32-
"os-browserify": "^0.3.0",
33-
"path-browserify": "^1.0.1",
34-
"process": "^0.11.10",
35-
"punycode": "^2.3.0",
36-
"querystring-es3": "^0.2.1",
37-
"stream-browserify": "^3.0.0",
38-
"stream-http": "^3.2.0",
39-
"string_decoder": "1.3.0",
40-
"timers-browserify": "^2.0.12",
4124
"ts-loader": "9.5.2",
4225
"tsconfig-paths-webpack-plugin": "^3.5.2",
43-
"tty-browserify": "^0.0.1",
44-
"url": "^0.11.1",
45-
"util": "^0.12.5",
46-
"vm-browserify": "^1.1.2",
4726
"webpack": "^5.88.2",
4827
"webpack-bundle-analyzer": "4.10.2"
4928
},

npm/webpack-batteries-included-preprocessor/test/e2e/features.spec.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ describe('webpack-batteries-included-preprocessor features', () => {
6060
await runAndEval('node_shim_spec.js')
6161
})
6262

63-
it('shims node builtins', async () => {
64-
await runAndEval('node_builtins_spec.js')
65-
})
66-
6763
it('outputs inline source map', async () => {
6864
const outputPath = await run('es_features_spec.js')
6965
const contents = await fs.readFile(outputPath)

npm/webpack-batteries-included-preprocessor/test/fixtures/node_builtins_spec.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

npm/webpack-batteries-included-preprocessor/test/unit/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe('webpack-batteries-included-preprocessor', () => {
4040
preprocessor = require('../../index')
4141
const result = preprocessor.getFullWebpackOptions('file/path', 'typescript/path')
4242

43-
expect(result.plugins).to.have.length(2)
44-
expect(result.plugins[1].constructor.name).to.equal('BundleAnalyzerPlugin')
43+
expect(result.plugins).to.have.length(1)
44+
expect(result.plugins[0].constructor.name).to.equal('BundleAnalyzerPlugin')
4545
Debug.disable()
4646
})
4747
})

npm/webpack-dev-server/test/devServer-unit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('devServer', function () {
4040
// Writing to disk includes the correct source map size, where the difference will be made up from stat size vs parsed size
4141
// This is critical if a user is trying to debug to determine if they have large source maps or other large files in their dev-server under test
4242
describe('writes to disk if DEBUG=cypress-verbose:webpack-dev-server:bundle-analyzer is set', async () => {
43-
const WEBPACK_DEV_SERVER_VERSIONS: (4 | 5)[] = [4, 5]
43+
const WEBPACK_DEV_SERVER_VERSIONS: (5)[] = [5]
4444

4545
beforeEach(() => {
4646
debug.enable('cypress-verbose:webpack-dev-server:bundle-analyzer')

npm/webpack-dev-server/test/makeWebpackConfig.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ describe('makeWebpackConfig', () => {
341341
// Gives users a diagnostic output with webpack-bundle-analyzer to get a visible representation of their webpack bundle, which they can send to us
342342
// to give us an idea what issues they may be experiencing
343343
describe('enables webpack-bundle-analyzer if DEBUG=cypress-verbose:webpack-dev-server:bundle-analyzer is set', async () => {
344-
const WEBPACK_VERSIONS: (4 | 5)[] = [4, 5]
344+
const WEBPACK_VERSIONS: (5)[] = [5]
345345

346346
beforeEach(() => {
347347
debug.enable('cypress-verbose:webpack-dev-server:bundle-analyzer')

packages/launchpad/cypress.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { defineConfig } from 'cypress'
22
import { snapshotCypressDirectory } from './cypress/tasks/snapshotsScaffold'
33
import { uninstallDependenciesInScaffoldedProject } from './cypress/tasks/uninstallDependenciesInScaffoldedProject'
4+
import wbip from '@cypress/webpack-batteries-included-preprocessor'
5+
6+
function getWebpackOptions () {
7+
const options = wbip.getFullWebpackOptions()
8+
9+
// our tests need the path built-in for testing, so we need to shim it here into the webpack config
10+
options.resolve.fallback.path = require.resolve('path-browserify')
11+
12+
return options
13+
}
414

515
export default defineConfig({
616
projectId: 'ypt4pf',
@@ -37,6 +47,8 @@ export default defineConfig({
3747
uninstallDependenciesInScaffoldedProject,
3848
})
3949

50+
on('file:preprocessor', wbip({ webpackOptions: getWebpackOptions(), typescript: require.resolve('typescript') }))
51+
4052
return await e2ePluginSetup(on, config)
4153
},
4254
},

packages/launchpad/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"human-interval": "1.0.0",
6767
"javascript-time-ago": "2.3.8",
6868
"markdown-it": "13.0.1",
69+
"path-browserify": "1.0.1",
6970
"rollup-plugin-polyfill-node": "^0.7.0",
7071
"sinon": "13.0.2",
7172
"type-fest": "^2.3.4",

packages/server/lib/plugins/child/run_plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class RunPlugins {
256256
...tsPath && { typescript: tsPath },
257257
}
258258

259-
debug('creating webpack preprocessor with options %o', options)
259+
debug('creating webpack batteries included preprocessor with options %o', options)
260260

261261
const webpackPreprocessor = require('@cypress/webpack-batteries-included-preprocessor')
262262

packages/web-config/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@svgr/webpack": "8.0.1",
1717
"@types/webpack": "^5.28.1",
1818
"arraybuffer-loader": "1.0.8",
19+
"assert": "2.0.0",
1920
"autoprefixer": "10.4.20",
2021
"babel-loader": "10.0.0",
2122
"browser-resolve": "2.0.0",

packages/web-config/webpack.config.base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const getCommonConfig = () => {
121121
extensions: ['.ts', '.js', '.jsx', '.tsx', '.scss', '.json'],
122122
// see https://gist.github.com/ef4/d2cf5672a93cf241fd47c020b9b3066a for polyfill migration details
123123
fallback: {
124+
assert: require.resolve('assert/'),
124125
buffer: require.resolve('buffer/'),
125126
child_process: false,
126127
fs: false,

system-tests/projects/e2e/cypress/e2e/node_builtins.cy.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)