-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: react-scripts. allow parametrise webpack config path
- Loading branch information
Showing
4 changed files
with
100 additions
and
83 deletions.
There are no files selected for viewing
84 changes: 4 additions & 80 deletions
84
npm/react/plugins/react-scripts/findReactScriptsWebpackConfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const debug = require('debug')('@cypress/react') | ||
|
||
const addCypressToWebpackEslintRulesInPlace = (webpackOptions) => { | ||
const globalsToAdd = ['cy', 'Cypress', 'before', 'after', 'context'] | ||
|
||
if (webpackOptions.module && Array.isArray(webpackOptions.module.rules)) { | ||
const modulePre = webpackOptions.module.rules.find( | ||
(rule) => rule.enforce === 'pre', | ||
) | ||
|
||
if (modulePre && Array.isArray(modulePre.use)) { | ||
debug('found Pre block %o', modulePre) | ||
|
||
const useEslintLoader = modulePre.use.find( | ||
(use) => use.loader && use.loader.includes('eslint-loader'), | ||
) | ||
|
||
if (useEslintLoader) { | ||
debug('found useEslintLoader %o', useEslintLoader) | ||
|
||
if (useEslintLoader.options) { | ||
if (Array.isArray(useEslintLoader.options.globals)) { | ||
debug( | ||
'adding cy to existing globals %o', | ||
useEslintLoader.options.globals, | ||
) | ||
|
||
useEslintLoader.options.globals.push(...globalsToAdd) | ||
} else { | ||
debug('setting new list of globals with cy and Cypress') | ||
useEslintLoader.options.globals = globalsToAdd | ||
} | ||
|
||
debug('updated globals %o', useEslintLoader.options.globals) | ||
} else { | ||
debug('eslint loader does not have options ⚠️') | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = { addCypressToWebpackEslintRulesInPlace } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters