@cypress/webpack-dev-server 3.11.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,7 +12,7 @@ import { defineConfig } from 'cypress'
12
12
  export default defineConfig({
13
13
  component: {
14
14
  devServer: {
15
- framework: 'create-react-app',
15
+ framework: 'react',
16
16
  bundler: 'webpack',
17
17
  // webpackConfig?: Will try to infer, if passed it will be used as is
18
18
  }
@@ -31,7 +31,7 @@ export default defineConfig({
31
31
  devServer(devServerConfig) {
32
32
  return devServer({
33
33
  ...devServerConfig,
34
- framework: 'create-react-app',
34
+ framework: 'react',
35
35
  webpackConfig: require('./webpack.config.js')
36
36
  })
37
37
  }
@@ -47,11 +47,9 @@ This module should be primarily covered by system-tests / open-mode tests. All s
47
47
 
48
48
  `webpack${major}_wds${devServerMajor}-$framework{-$variant}`
49
49
 
50
- - webpack4_wds3-react
50
+ - webpack4_wds4-react
51
51
  - webpack5_wds5-react
52
52
  - webpack4_wds4-next-11
53
- - webpack5_wds3-next-12
54
- - webpack4_wds4-create-react-app
55
53
 
56
54
  ## Architecture
57
55
 
@@ -65,11 +63,11 @@ We then merge the sourced config with the user's webpack config, and layer on ou
65
63
 
66
64
  ## Compatibility
67
65
 
68
- | @cypress/webpack-dev-server | cypress |
69
- | --------------------------- | ------- |
70
- | <= v1 | <= v9 |
71
- | >= v2 | >= v10 |
72
- | >= v4 | >= v13 |
66
+ | @cypress/webpack-dev-server | cypress |
67
+ | ---------------------------- | -------------- |
68
+ | <= v1 | <= v9 |
69
+ | >= v2 <= v3 | >= v10 <= v13 |
70
+ | >= v4 | >= v14 |
73
71
 
74
72
  ## License
75
73
 
@@ -57,7 +57,7 @@ class CypressCTWebpackPlugin {
57
57
  *
58
58
  * See https://github.com/cypress-io/cypress/issues/24398
59
59
  */
60
- this.onSpecsChange = async (specs) => {
60
+ this.onSpecsChange = async ({ specs, options }) => {
61
61
  var _a;
62
62
  if (!this.compilation || lodash_1.default.isEqual(specs, this.files)) {
63
63
  return;
@@ -17,10 +17,6 @@ async function createWebpackDevServer(config) {
17
17
  debug('using webpack-dev-server v4');
18
18
  return webpackDevServer4(config, webpackCompiler, finalWebpackConfig);
19
19
  }
20
- if (webpackDevServerMajorVersion === 3) {
21
- debug('using webpack-dev-server v3');
22
- return webpackDevServer3(config, webpackCompiler, finalWebpackConfig);
23
- }
24
20
  throw new Error(`Unsupported webpackDevServer version ${webpackDevServerMajorVersion}`);
25
21
  }
26
22
  exports.createWebpackDevServer = createWebpackDevServer;
@@ -61,19 +57,3 @@ function webpackDevServer4(config, compiler, finalWebpackConfig) {
61
57
  compiler,
62
58
  };
63
59
  }
64
- function webpackDevServer3(config, compiler, finalWebpackConfig) {
65
- var _a, _b;
66
- const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config;
67
- const isOpenMode = !config.devServerConfig.cypressConfig.isTextTerminal;
68
- const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module;
69
- const webpackDevServerConfig = Object.assign(Object.assign({}, (_a = finalWebpackConfig.devServer) !== null && _a !== void 0 ? _a : {}), { hot: false,
70
- // @ts-ignore ignore webpack-dev-server v3 type errors
71
- inline: false, publicPath: devServerPublicPathRoute, noInfo: false, stats: (_b = finalWebpackConfig.stats) !== null && _b !== void 0 ? _b : 'minimal',
72
- // Only enable file watching & reload when executing tests in `open` mode
73
- liveReload: isOpenMode });
74
- const server = new WebpackDevServer(compiler, webpackDevServerConfig);
75
- return {
76
- server,
77
- compiler,
78
- };
79
- }
@@ -34,7 +34,7 @@ export declare namespace devServer {
34
34
  var create: (devServerConfig: WebpackDevServerConfig) => Promise<{
35
35
  server: unknown;
36
36
  compiler: object;
37
- version: 3 | 4 | 5;
37
+ version: 4 | 5;
38
38
  }>;
39
39
  }
40
40
  export type PresetHandlerResult = {
package/dist/devServer.js CHANGED
@@ -5,9 +5,6 @@ exports.isThirdPartyDefinition = exports.devServer = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const createWebpackDevServer_1 = require("./createWebpackDevServer");
7
7
  const debug_1 = tslib_1.__importDefault(require("debug"));
8
- const vueCliHandler_1 = require("./helpers/vueCliHandler");
9
- const nuxtHandler_1 = require("./helpers/nuxtHandler");
10
- const createReactAppHandler_1 = require("./helpers/createReactAppHandler");
11
8
  const nextHandler_1 = require("./helpers/nextHandler");
12
9
  const sourceRelativeWebpackModules_1 = require("./helpers/sourceRelativeWebpackModules");
13
10
  const angularHandler_1 = require("./helpers/angularHandler");
@@ -22,30 +19,7 @@ const debug = (0, debug_1.default)('cypress:webpack-dev-server:devServer');
22
19
  */
23
20
  function devServer(devServerConfig) {
24
21
  return new Promise(async (resolve, reject) => {
25
- var _a;
26
22
  const result = await devServer.create(devServerConfig);
27
- // @ts-expect-error
28
- const { port } = (_a = result.server) === null || _a === void 0 ? void 0 : _a.options;
29
- if (result.version === 3) {
30
- const srv = result.server.listen(port || 0, '127.0.0.1', () => {
31
- const port = srv.address().port;
32
- debug('Component testing webpack server 3 started on port %s', port);
33
- resolve({
34
- port,
35
- // Close is for unit testing only. We kill this child process which will handle the closing of the server
36
- close: (done) => {
37
- srv.close((err) => {
38
- if (err) {
39
- debug('closing dev server, with error', err);
40
- }
41
- debug('closed dev server');
42
- done === null || done === void 0 ? void 0 : done(err);
43
- });
44
- },
45
- });
46
- });
47
- return;
48
- }
49
23
  result.server.start().then(() => {
50
24
  if (!result.server.options.port) {
51
25
  return reject(new Error(`Expected port ${result.server.options.port} to be a number`));
@@ -82,12 +56,6 @@ async function getPreset(devServerConfig) {
82
56
  return defaultWebpackModules();
83
57
  }
84
58
  switch (devServerConfig.framework) {
85
- case 'create-react-app':
86
- return (0, createReactAppHandler_1.createReactAppHandler)(devServerConfig);
87
- case 'nuxt':
88
- return await (0, nuxtHandler_1.nuxtHandler)(devServerConfig);
89
- case 'vue-cli':
90
- return await (0, vueCliHandler_1.vueCliHandler)(devServerConfig);
91
59
  case 'next':
92
60
  return await (0, nextHandler_1.nextHandler)(devServerConfig);
93
61
  case 'angular':
@@ -24,7 +24,7 @@ export interface SourcedWebpackDevServer extends SourcedDependency {
24
24
  module: {
25
25
  new (...args: unknown[]): unknown;
26
26
  };
27
- majorVersion: 3 | 4 | 5;
27
+ majorVersion: 4 | 5;
28
28
  }
29
29
  export interface SourcedHtmlWebpackPlugin extends SourcedDependency {
30
30
  module: unknown;
@@ -23,9 +23,6 @@ const cypressWebpackPath = (config) => {
23
23
  };
24
24
  exports.cypressWebpackPath = cypressWebpackPath;
25
25
  const frameworkWebpackMapper = {
26
- 'create-react-app': 'react-scripts',
27
- 'vue-cli': '@vue/cli-service',
28
- 'nuxt': '@nuxt/webpack',
29
26
  react: undefined,
30
27
  vue: undefined,
31
28
  next: 'next',
@@ -143,7 +140,7 @@ function sourceWebpackDevServer(config, webpackMajorVersion, framework) {
143
140
  webpackDevServer.importPath = path_1.default.dirname(webpackDevServerJsonPath);
144
141
  webpackDevServer.packageJson = require(webpackDevServerJsonPath);
145
142
  webpackDevServer.module = require(webpackDevServer.importPath);
146
- webpackDevServer.majorVersion = getMajorVersion(webpackDevServer.packageJson, [3, 4, 5]);
143
+ webpackDevServer.majorVersion = getMajorVersion(webpackDevServer.packageJson, [4, 5]);
147
144
  debug('WebpackDevServer: Successfully sourced webpack-dev-server - %o', webpackDevServer);
148
145
  if (webpackMajorVersion < 5 && webpackDevServer.majorVersion === 5) {
149
146
  const json = webpackDevServer.packageJson;
@@ -10,7 +10,7 @@ const OUTPUT_PATH = path_1.default.join(__dirname, 'dist');
10
10
  const OsSeparatorRE = RegExp(`\\${path_1.default.sep}`, 'g');
11
11
  const posixSeparator = '/';
12
12
  function makeCypressWebpackConfig(config) {
13
- const { devServerConfig: { cypressConfig: { experimentalJustInTimeCompile, port, projectRoot, devServerPublicPathRoute, supportFile, indexHtmlFile, isTextTerminal: isRunMode, }, specs: files, devServerEvents, framework, }, sourceWebpackModulesResult: { webpack: { module: webpack, majorVersion: webpackMajorVersion, }, htmlWebpackPlugin: { module: HtmlWebpackPlugin, majorVersion: htmlWebpackPluginVersion, importPath: htmlWebpackPluginImportPath, }, webpackDevServer: { majorVersion: webpackDevServerMajorVersion, }, }, } = config;
13
+ const { devServerConfig: { cypressConfig: { justInTimeCompile, port, projectRoot, devServerPublicPathRoute, supportFile, indexHtmlFile, isTextTerminal: isRunMode, }, specs: files, devServerEvents, framework, }, sourceWebpackModulesResult: { webpack: { module: webpack, majorVersion: webpackMajorVersion, }, htmlWebpackPlugin: { module: HtmlWebpackPlugin, majorVersion: htmlWebpackPluginVersion, importPath: htmlWebpackPluginImportPath, }, webpackDevServer: { majorVersion: webpackDevServerMajorVersion, }, }, } = config;
14
14
  const webpackDevServerPort = port !== null && port !== void 0 ? port : undefined;
15
15
  debug(`Using HtmlWebpackPlugin version ${htmlWebpackPluginVersion} from ${htmlWebpackPluginImportPath}`);
16
16
  const optimization = {
@@ -56,21 +56,13 @@ function makeCypressWebpackConfig(config) {
56
56
  devtool: 'inline-source-map',
57
57
  };
58
58
  if (isRunMode) {
59
- // if experimentalJustInTimeCompile is configured, we need to watch for file changes as the spec entries are going to be updated per test
60
- const ignored = experimentalJustInTimeCompile ? /node_modules/ : '**/*';
59
+ // if justInTimeCompile is configured, we need to watch for file changes as the spec entries are going to be updated per test
60
+ const ignored = justInTimeCompile ? /node_modules/ : '**/*';
61
61
  // Disable file watching when executing tests in `run` mode
62
62
  finalConfig.watchOptions = {
63
63
  ignored,
64
64
  };
65
65
  }
66
- if (webpackDevServerMajorVersion === 5) {
67
- return Object.assign(Object.assign({}, finalConfig), { devServer: {
68
- port: webpackDevServerPort,
69
- client: {
70
- overlay: false,
71
- },
72
- } });
73
- }
74
66
  if (webpackDevServerMajorVersion === 4) {
75
67
  return Object.assign(Object.assign({}, finalConfig), { devServer: {
76
68
  port: webpackDevServerPort,
@@ -79,10 +71,12 @@ function makeCypressWebpackConfig(config) {
79
71
  },
80
72
  } });
81
73
  }
82
- // @ts-ignore
74
+ // default is webpack-dev-server v5
83
75
  return Object.assign(Object.assign({}, finalConfig), { devServer: {
84
76
  port: webpackDevServerPort,
85
- overlay: false,
77
+ client: {
78
+ overlay: false,
79
+ },
86
80
  } });
87
81
  }
88
82
  exports.makeCypressWebpackConfig = makeCypressWebpackConfig;
@@ -63,7 +63,8 @@ async function makeWebpackConfig(config) {
63
63
  var _a, _b, _c;
64
64
  let userWebpackConfig = config.devServerConfig.webpackConfig;
65
65
  const frameworkWebpackConfig = config.frameworkConfig;
66
- const { cypressConfig: { projectRoot, supportFile, }, specs: files, framework, } = config.devServerConfig;
66
+ const { cypressConfig: { projectRoot, supportFile, justInTimeCompile, }, framework, } = config.devServerConfig;
67
+ config.devServerConfig.specs = justInTimeCompile ? [] : config.devServerConfig.specs;
67
68
  if (!userWebpackConfig && !frameworkWebpackConfig) {
68
69
  debug('Not user or framework webpack config received. Trying to automatically source it');
69
70
  const configFile = await getWebpackConfigFromProjectRoot(projectRoot);
@@ -93,7 +94,7 @@ async function makeWebpackConfig(config) {
93
94
  : userWebpackConfig;
94
95
  const userAndFrameworkWebpackConfig = modifyWebpackConfigForCypress((0, webpack_merge_1.merge)(frameworkWebpackConfig !== null && frameworkWebpackConfig !== void 0 ? frameworkWebpackConfig : {}, userWebpackConfig !== null && userWebpackConfig !== void 0 ? userWebpackConfig : {}));
95
96
  debug(`User passed in user and framework webpack config with values %o`, userAndFrameworkWebpackConfig);
96
- debug(`New webpack entries %o`, files);
97
+ debug(`New webpack entries %o`, config.devServerConfig.specs);
97
98
  debug(`Project root`, projectRoot);
98
99
  debug(`Support file`, supportFile);
99
100
  const mergedConfig = (0, webpack_merge_1.merge)(userAndFrameworkWebpackConfig, (0, makeDefaultWebpackConfig_1.makeCypressWebpackConfig)(config));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/webpack-dev-server",
3
- "version": "3.11.0",
3
+ "version": "4.0.0",
4
4
  "description": "Launches Webpack Dev Server for Component Testing",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -25,14 +25,13 @@
25
25
  "semver": "^7.5.3",
26
26
  "speed-measure-webpack-plugin": "1.4.2",
27
27
  "tslib": "^2.3.1",
28
- "webpack-dev-server": "^4.15.2",
28
+ "webpack-dev-server": "^5.1.0",
29
29
  "webpack-merge": "^5.4.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/node": "18.17.5",
32
+ "@types/node": "20.16.0",
33
33
  "@types/proxyquire": "^1.3.28",
34
34
  "@types/speed-measure-webpack-plugin": "^1.3.4",
35
- "@types/webpack-dev-server-3": "npm:@types/webpack-dev-server@^3",
36
35
  "chai": "^4.3.6",
37
36
  "dedent": "^0.7.0",
38
37
  "mocha": "^9.2.2",
@@ -42,8 +41,7 @@
42
41
  "ts-node": "^10.9.2",
43
42
  "webpack": "npm:webpack@^5",
44
43
  "webpack-4": "npm:webpack@^4",
45
- "webpack-dev-server-3": "npm:webpack-dev-server@^3",
46
- "webpack-dev-server-5": "npm:webpack-dev-server@^5"
44
+ "webpack-dev-server-4": "npm:webpack-dev-server@^4"
47
45
  },
48
46
  "files": [
49
47
  "dist"
@@ -1,8 +0,0 @@
1
- import type { Configuration } from 'webpack';
2
- import type { PresetHandlerResult, WebpackDevServerConfig } from '../devServer';
3
- /**
4
- * Sourcing the config for create-react-app
5
- */
6
- export declare function createReactAppHandler(devServerConfig: WebpackDevServerConfig): PresetHandlerResult;
7
- export declare const cypressGlobals: string[];
8
- export declare function reactScriptsFiveModifications(webpackConfig: Configuration): void;
@@ -1,303 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reactScriptsFiveModifications = exports.cypressGlobals = exports.createReactAppHandler = void 0;
4
- const tslib_1 = require("tslib");
5
- const debug_1 = tslib_1.__importDefault(require("debug"));
6
- const path_1 = tslib_1.__importDefault(require("path"));
7
- const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
8
- const debug = (0, debug_1.default)('cypress:webpack-dev-server:create-react-app');
9
- /**
10
- * Sourcing the config for create-react-app
11
- */
12
- function createReactAppHandler(devServerConfig) {
13
- const sourceWebpackModulesResult = (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig);
14
- // this is required because
15
- // 1) we use our own HMR and we don't need react-refresh transpiling overhead
16
- // 2) it doesn't work with process.env=test @see https://github.com/cypress-io/cypress-realworld-app/pull/832
17
- process.env.FAST_REFRESH = 'false';
18
- const webpackConfig = loadWebpackConfig(devServerConfig);
19
- addCypressToWebpackEslintRulesInPlace(webpackConfig);
20
- getTranspileFolders(devServerConfig.cypressConfig).forEach((folder) => {
21
- allowModuleSourceInPlace(folder, webpackConfig);
22
- addFolderToBabelLoaderTranspileInPlace(folder, webpackConfig);
23
- });
24
- if (sourceWebpackModulesResult.webpack.majorVersion === 5) {
25
- debug('Modifying configuration for react-scripts@5');
26
- reactScriptsFiveModifications(webpackConfig);
27
- }
28
- return {
29
- frameworkConfig: webpackConfig,
30
- sourceWebpackModulesResult,
31
- };
32
- }
33
- exports.createReactAppHandler = createReactAppHandler;
34
- function loadWebpackConfig(devServerConfig) {
35
- let webpackConfigPath;
36
- const envName = 'test';
37
- process.env.NODE_ENV = envName;
38
- process.env.BABEL_ENV = envName;
39
- try {
40
- // Search for react-scripts webpack config
41
- webpackConfigPath = require.resolve('react-scripts/config/webpack.config.js', {
42
- paths: [devServerConfig.cypressConfig.projectRoot],
43
- });
44
- debug('Found react-scripts webpack config at %s', webpackConfigPath);
45
- }
46
- catch (err) {
47
- // Might be an ejected cra app, search for common webpack configs
48
- const ejectedWebpackConfigPath = path_1.default.join(devServerConfig.cypressConfig.projectRoot, 'config', 'webpack.config.js');
49
- try {
50
- webpackConfigPath = require.resolve(ejectedWebpackConfigPath);
51
- }
52
- catch (err) {
53
- throw new Error(`Failed to find webpack at ${ejectedWebpackConfigPath}. We looked in this location as we could not find the "react-scripts" dependency and are assuming an ejected create-react-app.`);
54
- }
55
- }
56
- try {
57
- let webpackConfig = require(webpackConfigPath);
58
- if (webpackConfig.default) {
59
- // we probably loaded TS file
60
- debug('loaded webpack options has .default - taking that as the config');
61
- webpackConfig = webpackConfig.default;
62
- }
63
- if (typeof webpackConfig === 'function') {
64
- debug('calling webpack function with environment "%s"', envName);
65
- webpackConfig = webpackConfig('development');
66
- }
67
- return webpackConfig;
68
- }
69
- catch (err) {
70
- throw new Error(`Failed to require webpack config at ${webpackConfigPath} with error: ${err}`);
71
- }
72
- }
73
- exports.cypressGlobals = ['cy', 'Cypress', 'before', 'after', 'context'];
74
- function addCypressToWebpackEslintRulesInPlace(webpackConfig) {
75
- var _a, _b;
76
- const eslintPlugin = (_a = webpackConfig.plugins) === null || _a === void 0 ? void 0 : _a.find((plugin) => plugin.constructor.name === 'ESLintWebpackPlugin');
77
- if (eslintPlugin) {
78
- const cypressGlobalsRules = exports.cypressGlobals
79
- .reduce((acc, global) => {
80
- acc[global] = 'writable';
81
- return acc;
82
- }, {});
83
- eslintPlugin.options.baseConfig = Object.assign(Object.assign({}, eslintPlugin.options.baseConfig), { globals: Object.assign(Object.assign({}, (_b = eslintPlugin.options.baseConfig) === null || _b === void 0 ? void 0 : _b.globals), cypressGlobalsRules) });
84
- debug('Found ESLintWebpackPlugin, modified eslint config %o', eslintPlugin.options.baseConfig);
85
- }
86
- }
87
- function getTranspileFolders(cypressConfig) {
88
- var _a;
89
- const rawFolders = (_a = cypressConfig.addTranspiledFolders) !== null && _a !== void 0 ? _a : [];
90
- const folders = rawFolders.map((folder) => path_1.default.resolve(cypressConfig.projectRoot, folder));
91
- // ensure path is absolute
92
- const ensureAbs = (folder) => {
93
- if (!path_1.default.isAbsolute(folder)) {
94
- return path_1.default.resolve(folder);
95
- }
96
- return folder;
97
- };
98
- if (cypressConfig.fixturesFolder) {
99
- folders.push(ensureAbs(cypressConfig.fixturesFolder));
100
- }
101
- if (cypressConfig.supportFolder) {
102
- folders.push(ensureAbs(cypressConfig.supportFolder));
103
- }
104
- // attempt to add directories based on spec pattern
105
- let componentDirs = cypressConfig.specPattern || '';
106
- // can be string or array
107
- if (typeof componentDirs === 'string') {
108
- componentDirs = [componentDirs];
109
- }
110
- const dirsFromSpecPattern = componentDirs.reduce((acc, curr) => {
111
- // glob
112
- if (curr.includes('*')) {
113
- const parts = curr.slice(0, curr.indexOf('*') - 1);
114
- const joined = parts.split(path_1.default.sep);
115
- const dir = path_1.default.join(...joined);
116
- return acc.concat(path_1.default.resolve(cypressConfig.projectRoot, dir));
117
- }
118
- return acc;
119
- }, []);
120
- return folders.concat(...dirsFromSpecPattern, path_1.default.resolve('cypress'));
121
- }
122
- /**
123
- * Finds the ModuleScopePlugin plugin and adds given folder
124
- * to that list. This allows react-scripts to import folders
125
- * outside of the default "/src" folder.
126
- * WARNING modifies the input webpack options argument.
127
- * @see https://github.com/bahmutov/cypress-react-unit-test/issues/289
128
- * @param {string} folderName Folder to add, should be absolute
129
- */
130
- function allowModuleSourceInPlace(folderName, webpackConfig) {
131
- if (!folderName) {
132
- return;
133
- }
134
- if (!webpackConfig.resolve) {
135
- return;
136
- }
137
- if (!Array.isArray(webpackConfig.resolve.plugins)) {
138
- return;
139
- }
140
- const moduleSourcePlugin = webpackConfig.resolve.plugins.find((plugin) => {
141
- return typeof plugin !== 'string' && Array.isArray(plugin.appSrcs);
142
- });
143
- if (!moduleSourcePlugin) {
144
- debug('cannot find module source plugin');
145
- return;
146
- }
147
- debug('found module source plugin %o', moduleSourcePlugin);
148
- if (!moduleSourcePlugin.appSrcs.includes(folderName)) {
149
- moduleSourcePlugin.appSrcs.push(folderName);
150
- debug('added folder %s to allowed sources', folderName);
151
- }
152
- }
153
- /**
154
- * Returns true if the provided loader path includes "babel-loader".
155
- * Uses current OS path separator to split the loader path correctly.
156
- */
157
- const isBabelLoader = (loaderPath) => {
158
- if (!loaderPath) {
159
- return false;
160
- }
161
- const loaderPathParts = loaderPath.split(path_1.default.sep);
162
- return loaderPathParts.some((pathPart) => pathPart === 'babel-loader');
163
- };
164
- const findBabelRule = (webpackConfig) => {
165
- if (!webpackConfig) {
166
- return;
167
- }
168
- if (!webpackConfig.module) {
169
- return;
170
- }
171
- debug('webpackConfig.module %o', webpackConfig.module);
172
- if (!Array.isArray(webpackConfig.module.rules)) {
173
- return;
174
- }
175
- const oneOfRule = webpackConfig.module.rules.find((rule) => {
176
- return typeof rule !== 'string' && Array.isArray(rule.oneOf);
177
- });
178
- if (!oneOfRule || !oneOfRule.oneOf) {
179
- debug('could not find oneOfRule');
180
- return;
181
- }
182
- debug('looking through oneOf rules');
183
- debug('oneOfRule.oneOf %o', oneOfRule.oneOf);
184
- oneOfRule.oneOf.forEach((rule) => debug('rule %o', rule));
185
- const babelRule = oneOfRule.oneOf.find((rule) => rule.loader && isBabelLoader(rule.loader));
186
- return babelRule;
187
- };
188
- // see https://github.com/bahmutov/find-webpack/issues/7
189
- const findBabelLoaderRule = (webpackConfig) => {
190
- debug('looking for babel-loader rule');
191
- if (!webpackConfig) {
192
- return;
193
- }
194
- if (!webpackConfig.module) {
195
- return;
196
- }
197
- debug('webpackConfig.module %o', webpackConfig.module);
198
- if (!Array.isArray(webpackConfig.module.rules)) {
199
- return;
200
- }
201
- debug('webpack module rules');
202
- webpackConfig.module.rules.forEach((rule) => {
203
- debug('rule %o', rule);
204
- });
205
- const babelRule = webpackConfig.module.rules.find((rule) => typeof rule !== 'string' && rule.loader === 'babel-loader');
206
- if (!babelRule || !babelRule.test) {
207
- debug('could not find babel rule');
208
- return;
209
- }
210
- debug('found Babel rule that applies to %s', babelRule.test.toString());
211
- return babelRule;
212
- };
213
- const findBabelLoaderUseRule = (webpackConfig) => {
214
- var _a;
215
- debug('looking for babel-loader rule with use property');
216
- if (!webpackConfig) {
217
- return;
218
- }
219
- if (!webpackConfig.module) {
220
- return;
221
- }
222
- debug('webpackConfig.module %o', webpackConfig.module);
223
- if (!Array.isArray(webpackConfig.module.rules)) {
224
- return;
225
- }
226
- debug('webpack module rules');
227
- webpackConfig.module.rules.forEach((rule) => {
228
- debug('rule %o', rule);
229
- });
230
- const isBabelLoader = (rule) => { var _a; return ((_a = rule === null || rule === void 0 ? void 0 : rule.use) === null || _a === void 0 ? void 0 : _a.loader) === 'babel-loader'; };
231
- const isNextBabelLoader = (rule) => { var _a; return ((_a = rule === null || rule === void 0 ? void 0 : rule.use) === null || _a === void 0 ? void 0 : _a.loader) === 'next-babel-loader'; };
232
- const babelRule = webpackConfig.module.rules.find((rule) => isBabelLoader(rule) || isNextBabelLoader(rule));
233
- if (!babelRule) {
234
- debug('could not find babel rule');
235
- return;
236
- }
237
- debug('found Babel use rule that applies to %s', (_a = babelRule.test) === null || _a === void 0 ? void 0 : _a.toString());
238
- return babelRule.use;
239
- };
240
- const findBabelRuleWrap = (webpackConfig) => {
241
- let babelRule = findBabelRule(webpackConfig);
242
- if (!babelRule) {
243
- debug('could not find Babel rule using oneOf');
244
- babelRule = findBabelLoaderRule(webpackConfig);
245
- }
246
- if (!babelRule) {
247
- debug('could not find Babel rule directly');
248
- babelRule = findBabelLoaderUseRule(webpackConfig);
249
- }
250
- if (!babelRule) {
251
- debug('could not find Babel rule');
252
- return;
253
- }
254
- return babelRule;
255
- };
256
- function addFolderToBabelLoaderTranspileInPlace(folder, webpackConfig) {
257
- if (!folder) {
258
- debug('no extra folder to transpile using Babel');
259
- return;
260
- }
261
- debug('trying to transpile additional folder %s using Babel', folder);
262
- const babelRule = findBabelRuleWrap(webpackConfig);
263
- if (!babelRule) {
264
- debug('could not find Babel rule');
265
- return;
266
- }
267
- debug('babel rule %o', babelRule);
268
- if (!babelRule.include) {
269
- debug('could not find Babel include condition');
270
- return;
271
- }
272
- if (typeof babelRule.include === 'string') {
273
- babelRule.include = [babelRule.include];
274
- }
275
- if (babelRule.include.includes(folder)) {
276
- // do not double include the same folder
277
- debug('babel includes rule for folder %s', folder);
278
- return;
279
- }
280
- babelRule.include.push(folder);
281
- debug('added folder %s to babel rules', folder);
282
- }
283
- function reactScriptsFiveModifications(webpackConfig) {
284
- var _a;
285
- // React-Scripts sets the webpack target to ["browserslist"] which tells
286
- // webpack to target the browsers found within the browserslist config
287
- // depending on the environment (process.env.NODE_ENV). Since we set
288
- // process.env.NODE_ENV = "test", webpack is unable to find any browsers and errors.
289
- // We set BROWSERSLIST_ENV = "development" to override the default NODE_ENV search of browsers.
290
- if (!process.env.BROWSERSLIST_ENV) {
291
- process.env.BROWSERSLIST_ENV = 'development';
292
- }
293
- // We use the "development" configuration of the react-scripts webpack config.
294
- // There is a conflict when settings process.env.NODE_ENV = "test" since DefinePlugin
295
- // uses the "development" configuration and expects process.env.NODE_ENV = "development".
296
- const definePlugin = (_a = webpackConfig.plugins) === null || _a === void 0 ? void 0 : _a.find((plugin) => plugin.constructor.name === 'DefinePlugin');
297
- if (definePlugin) {
298
- const processEnv = definePlugin.definitions['process.env'];
299
- processEnv.NODE_ENV = JSON.stringify('development');
300
- debug('Found "DefinePlugin", modified "process.env" definition %o', processEnv);
301
- }
302
- }
303
- exports.reactScriptsFiveModifications = reactScriptsFiveModifications;
@@ -1,2 +0,0 @@
1
- import type { PresetHandlerResult, WebpackDevServerConfig } from '../devServer';
2
- export declare function nuxtHandler(devServerConfig: WebpackDevServerConfig): Promise<PresetHandlerResult>;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nuxtHandler = void 0;
4
- const tslib_1 = require("tslib");
5
- const debug_1 = tslib_1.__importDefault(require("debug"));
6
- const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
7
- const debug = (0, debug_1.default)('cypress:webpack-dev-server:nuxtHandler');
8
- async function nuxtHandler(devServerConfig) {
9
- const sourceWebpackModulesResult = (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig);
10
- try {
11
- const nuxt = require.resolve('nuxt', {
12
- paths: [devServerConfig.cypressConfig.projectRoot],
13
- });
14
- const { getWebpackConfig } = require(nuxt);
15
- const webpackConfig = await getWebpackConfig();
16
- // Nuxt has asset size warnings configured by default which will cause webpack overlays to appear
17
- // in the browser which we don't want.
18
- delete webpackConfig.performance;
19
- debug('webpack config %o', webpackConfig);
20
- return { frameworkConfig: webpackConfig, sourceWebpackModulesResult };
21
- }
22
- catch (e) {
23
- console.error(e); // eslint-disable-line no-console
24
- throw Error(`Error loading nuxt. Looked in ${require.resolve.paths(devServerConfig.cypressConfig.projectRoot)}`);
25
- }
26
- }
27
- exports.nuxtHandler = nuxtHandler;
@@ -1,2 +0,0 @@
1
- import type { PresetHandlerResult, WebpackDevServerConfig } from '../devServer';
2
- export declare function vueCliHandler(devServerConfig: WebpackDevServerConfig): Promise<PresetHandlerResult>;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vueCliHandler = void 0;
4
- const tslib_1 = require("tslib");
5
- const debug_1 = tslib_1.__importDefault(require("debug"));
6
- const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
7
- const debug = (0, debug_1.default)('cypress:webpack-dev-server:vueCliHandler');
8
- async function vueCliHandler(devServerConfig) {
9
- const sourceWebpackModulesResult = (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig);
10
- try {
11
- const Service = require(require.resolve('@vue/cli-service', {
12
- paths: [devServerConfig.cypressConfig.projectRoot],
13
- }));
14
- let service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd());
15
- await service.init(process.env.VUE_CLI_MODE || process.env.NODE_ENV);
16
- const webpackConfig = service.resolveWebpackConfig();
17
- debug('webpack config %o', webpackConfig);
18
- return { frameworkConfig: webpackConfig, sourceWebpackModulesResult };
19
- }
20
- catch (e) {
21
- console.error(e); // eslint-disable-line no-console
22
- throw Error(`Error loading @vue/cli-service/lib/Service or resolving WebpackConfig. Looked in ${require.resolve.paths(devServerConfig.cypressConfig.projectRoot)}`);
23
- }
24
- }
25
- exports.vueCliHandler = vueCliHandler;