Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit ddbdbe2

Browse files
committed
feat: use find-webpack to handle ejected react-scripts too
1 parent 33a5353 commit ddbdbe2

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

package-lock.json

Lines changed: 30 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"@cypress/webpack-preprocessor": "4.1.3",
102102
"babel-plugin-istanbul": "6.0.0",
103103
"debug": "4.1.1",
104-
"find-yarn-workspace-root": "1.2.1"
104+
"find-webpack": "1.1.0"
105105
},
106106
"release": {
107107
"branches": [

plugins/cra-v3/file-preprocessor.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
const debug = require('debug')('cypress-react-unit-test')
2-
const path = require('path')
3-
const findYarnWorkspaceRoot = require('find-yarn-workspace-root')
2+
const findWebpack = require('find-webpack')
43
const webpack = require('@cypress/webpack-preprocessor')
54

6-
const webpackConfigPath = path.resolve(
7-
findYarnWorkspaceRoot() || process.cwd(),
8-
'node_modules',
9-
'react-scripts',
10-
'config',
11-
'webpack.config.js',
12-
)
13-
14-
debug('path to react-scripts own webpack.config.js: %s', webpackConfigPath)
15-
16-
// Do this as the first thing so that any code reading it knows the right env.
17-
process.env.BABEL_ENV = 'development'
18-
process.env.NODE_ENV = 'development'
19-
205
// note: modifies the argument object in place
216
const addCypressToEslintRules = webpackOptions => {
227
if (webpackOptions.module && Array.isArray(webpackOptions.module.rules)) {
@@ -89,8 +74,14 @@ const addCodeCoverage = webpackOptions => {
8974
const getWebpackOptions = opts => {
9075
debug('top level opts %o', opts)
9176

92-
const webpackFactory = require(webpackConfigPath)
93-
const webpackOptions = webpackFactory('development')
77+
const webpackOptions = findWebpack.getWebpackOptions()
78+
if (!webpackOptions) {
79+
console.error('⚠️ Could not find Webpack options, using defaults')
80+
return {
81+
webpackOptions: webpack.defaultOptions,
82+
watchOptions: {},
83+
}
84+
}
9485
debug('webpack options: %o', webpackOptions)
9586

9687
// remove bunch of options, we just need to bundle spec files

0 commit comments

Comments
 (0)