Skip to content

Commit

Permalink
fix: use sourced webpack IgnorePlugin (#22763)
Browse files Browse the repository at this point in the history
* fix: use sourced webpack Ignore Plugin

* type webpack

* revert

* use better types for module in source webpack

* fix wds types

Co-authored-by: Lachlan Miller <[email protected]>
  • Loading branch information
ZachJW34 and lmiller1990 authored Jul 13, 2022
1 parent 48f5fd5 commit 9ec43b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/src/createWebpackDevServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debugLib from 'debug'
import type { Configuration } from 'webpack-dev-server-3'
import type { Configuration } from 'webpack-dev-server'

import type { WebpackDevServerConfig } from './devServer'
import type { SourceRelativeWebpackResult } from './helpers/sourceRelativeWebpackModules'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ export interface SourcedDependency {
packageJson: PackageJson
}

export type WebpackModule = typeof import('webpack')

export interface SourcedWebpack extends SourcedDependency {
module: Function
module: WebpackModule
majorVersion: 4 | 5
}

export type WebpackDevServerModule = typeof import('webpack-dev-server')

export interface SourcedWebpackDevServer extends SourcedDependency {
module: {
new (...args: unknown[]): unknown
}
module: WebpackDevServerModule
majorVersion: 3 | 4
}

Expand Down
8 changes: 4 additions & 4 deletions npm/webpack-dev-server/src/makeWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import * as path from 'path'
import { merge } from 'webpack-merge'
import { importModule } from 'local-pkg'
import type { Configuration } from 'webpack'
import { IgnorePlugin } from 'webpack'
import { makeDefaultWebpackConfig } from './makeDefaultWebpackConfig'
import { CypressCTWebpackPlugin } from './CypressCTWebpackPlugin'
import type { CreateFinalWebpackConfig } from './createWebpackDevServer'
import { configFiles } from './constants'
import type { WebpackConfiguration } from 'webpack-dev-server'
import type { WebpackModule } from './helpers/sourceRelativeWebpackModules'

const debug = debugFn('cypress:webpack-dev-server:makeWebpackConfig')

Expand Down Expand Up @@ -82,7 +82,7 @@ function modifyWebpackConfigForCypress (webpackConfig: Partial<Configuration>) {
* different between the two, so we check which version of webpack
* we are using and match the API.
*/
function maybeGetReactIgnorePlugin (projectRoot: string) {
function maybeGetReactIgnorePlugin (projectRoot: string, webpack: WebpackModule) {
try {
const reactDom = require(require.resolve('react-dom/package.json', { paths: [projectRoot] }))
const majorVersion = major(reactDom?.default?.version || reactDom?.version)
Expand All @@ -94,7 +94,7 @@ function maybeGetReactIgnorePlugin (projectRoot: string) {
debug('ignoring react-dom/client ', majorVersion)

// https://webpack.js.org/plugins/ignore-plugin/
return new IgnorePlugin({
return new webpack.IgnorePlugin({
resourceRegExp: /react-dom\/client$/,
contextRegExp: /cypress/,
})
Expand Down Expand Up @@ -188,7 +188,7 @@ export async function makeWebpackConfig (
// If React version is <= 17, we need to ignore the `react-dom/client` reference
// in cypress/react, since that's a new, non-backwards compatible module that will
// cause webpack compilation to fail.
const reactIgnorePlugin = maybeGetReactIgnorePlugin(projectRoot)
const reactIgnorePlugin = maybeGetReactIgnorePlugin(projectRoot, webpack)

if (reactIgnorePlugin && dynamicWebpackConfig.plugins) {
dynamicWebpackConfig.plugins.push(reactIgnorePlugin)
Expand Down

3 comments on commit 9ec43b4

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9ec43b4 Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.1/linux-x64/lmiller/21381-react-18-with-ignore-9ec43b4b0ca4051cc8258d8c1701723dad818a70/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9ec43b4 Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.1/darwin-arm64/lmiller/21381-react-18-with-ignore-9ec43b4b0ca4051cc8258d8c1701723dad818a70/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9ec43b4 Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.1/darwin-x64/lmiller/21381-react-18-with-ignore-9ec43b4b0ca4051cc8258d8c1701723dad818a70/cypress.tgz

Please sign in to comment.