@cypress/webpack-dev-server 6.1.2 → 6.2.1

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
@@ -53,6 +53,7 @@ This module should be primarily covered by system-tests / open-mode tests. All s
53
53
 
54
54
  - webpack4_wds4-react
55
55
  - webpack5_wds5-react
56
+ - webpack5_wds6-react
56
57
  - webpack4_wds4-next-11
57
58
 
58
59
  ## Architecture
@@ -1,12 +1,13 @@
1
1
  /// <reference types="cypress" />
2
2
  /// <reference types="node" />
3
+ import type webpack from 'webpack';
3
4
  import type { EventEmitter } from 'events';
4
5
  interface CypressCTWebpackPluginOptions {
5
6
  files: Cypress.Cypress['spec'][];
6
7
  projectRoot: string;
7
8
  supportFile: string | false;
8
9
  devServerEvents: EventEmitter;
9
- webpack: Function;
10
+ webpack: typeof webpack;
10
11
  indexHtmlFile: string;
11
12
  }
12
13
  type CypressCTContextOptions = Omit<CypressCTWebpackPluginOptions, 'devServerEvents' | 'webpack'>;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
- /* eslint-env browser */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.init = void 0;
5
4
  function init(importPromises, parent = (window.opener || window.parent)) {
6
- // @ts-expect-error
5
+ // @ts-expect-error - Cypress is attached to the window at runtime and is not on the Window type
7
6
  const Cypress = window.Cypress = parent.Cypress;
8
7
  if (!Cypress) {
9
8
  throw new Error('Tests cannot run without a reference to Cypress!');
@@ -10,8 +10,8 @@ async function createWebpackDevServer(config) {
10
10
  const { sourceWebpackModulesResult: { webpack: { module: webpack, }, webpackDevServer: { majorVersion: webpackDevServerMajorVersion, }, }, } = config;
11
11
  const finalWebpackConfig = await (0, makeWebpackConfig_1.makeWebpackConfig)(config);
12
12
  const webpackCompiler = webpack(finalWebpackConfig);
13
- if (webpackDevServerMajorVersion === 5) {
14
- debug('using webpack-dev-server v5');
13
+ if (webpackDevServerMajorVersion === 5 || webpackDevServerMajorVersion === 6) {
14
+ debug(`using webpack-dev-server v${webpackDevServerMajorVersion}`);
15
15
  return webpackDevServer5(config, webpackCompiler, finalWebpackConfig);
16
16
  }
17
17
  throw new Error(`Unsupported webpackDevServer version ${webpackDevServerMajorVersion}`);
@@ -24,8 +24,7 @@ function webpackDevServer5(config, compiler, finalWebpackConfig) {
24
24
  const webpackDevServerConfig = {
25
25
  host: '127.0.0.1',
26
26
  port: 'auto',
27
- // @ts-ignore
28
- ...finalWebpackConfig?.devServer,
27
+ ...finalWebpackConfig.devServer,
29
28
  devMiddleware: {
30
29
  publicPath: devServerPublicPathRoute,
31
30
  stats: finalWebpackConfig.stats ?? 'minimal',
@@ -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: 4 | 5;
37
+ version: 4 | 5 | 6;
38
38
  }>;
39
39
  }
40
40
  export type PresetHandlerResult = {
@@ -8,6 +8,7 @@ const os_1 = require("os");
8
8
  const path = tslib_1.__importStar(require("path"));
9
9
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
10
10
  const debug_1 = tslib_1.__importDefault(require("debug"));
11
+ const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
11
12
  const debugPrefix = 'cypress:webpack-dev-server:angularHandler';
12
13
  const debug = (0, debug_1.default)(debugPrefix);
13
14
  async function getProjectConfig(projectRoot) {
@@ -85,7 +86,14 @@ async function generateTsConfig(devServerConfig, buildOptions) {
85
86
  const { workspaceRoot = projectRoot } = buildOptions;
86
87
  const specPattern = Array.isArray(cypressConfig.specPattern) ? cypressConfig.specPattern : [cypressConfig.specPattern];
87
88
  const getProjectFilePath = (...fileParts) => (0, exports.toPosix)(path.join(...fileParts));
88
- const includePaths = [...specPattern.map((pattern) => getProjectFilePath(projectRoot, pattern))];
89
+ // `**/*.cy.{ts,tsx}` becomes `**/*.cy.ts` and `**/*.cy.tsx`. TypeScript's
90
+ // `include` only understands `*`, `?` and `**/`, so a brace pattern, such as
91
+ // the default specPattern, would match no files. Expanding before joining
92
+ // projectRoot keeps braces in the project's own path literal. The result
93
+ // stays a list of globs rather than files because @ngtools/webpack re-reads
94
+ // `include` on every rebuild, which is how it picks up a newly created spec.
95
+ const expandedSpecPatterns = new Set(specPattern.flatMap((pattern) => micromatch_1.default.braces(pattern, { expand: true })));
96
+ const includePaths = [...expandedSpecPatterns].map((pattern) => getProjectFilePath(projectRoot, pattern));
89
97
  if (cypressConfig.supportFile) {
90
98
  includePaths.push((0, exports.toPosix)(cypressConfig.supportFile));
91
99
  }
@@ -145,7 +153,7 @@ async function getAngularCliModules(projectRoot) {
145
153
  return module;
146
154
  }
147
155
  catch (e) {
148
- throw new Error(`Could not resolve "${dep}". Do you have "@angular-devkit/build-angular" and "@angular-devkit/core" installed?`);
156
+ throw new Error(`Could not resolve "${dep}". Do you have "@angular-devkit/build-angular" and "@angular-devkit/core" installed?`, { cause: e });
149
157
  }
150
158
  }));
151
159
  return {
@@ -44,21 +44,21 @@ async function getNextJsPackages(devServerConfig) {
44
44
  packages.loadConfig = require(loadConfigPath).default;
45
45
  }
46
46
  catch (e) {
47
- throw new Error(`Failed to load "next/dist/server/config" with error: ${e.message ?? e}`);
47
+ throw new Error(`Failed to load "next/dist/server/config" with error: ${e.message ?? e}`, { cause: e });
48
48
  }
49
49
  try {
50
50
  const getNextJsBaseWebpackConfigPath = require.resolve('next/dist/build/webpack-config', resolvePaths);
51
51
  packages.getNextJsBaseWebpackConfig = require(getNextJsBaseWebpackConfigPath).default;
52
52
  }
53
53
  catch (e) {
54
- throw new Error(`Failed to load "next/dist/build/webpack-config" with error: ${e.message ?? e}`);
54
+ throw new Error(`Failed to load "next/dist/build/webpack-config" with error: ${e.message ?? e}`, { cause: e });
55
55
  }
56
56
  try {
57
57
  const loadJsConfigPath = require.resolve('next/dist/build/load-jsconfig', resolvePaths);
58
58
  packages.nextLoadJsConfig = require(loadJsConfigPath).default;
59
59
  }
60
60
  catch (e) {
61
- throw new Error(`Failed to load "next/dist/build/load-jsconfig" with error: ${e.message ?? e}`);
61
+ throw new Error(`Failed to load "next/dist/build/load-jsconfig" with error: ${e.message ?? e}`, { cause: e });
62
62
  }
63
63
  // Does not exist prior to Next 13.
64
64
  try {
@@ -66,7 +66,7 @@ async function getNextJsPackages(devServerConfig) {
66
66
  packages.getSupportedBrowsers = require(getUtilsPath).getSupportedBrowsers ?? (() => Promise.resolve([]));
67
67
  }
68
68
  catch (e) {
69
- throw new Error(`Failed to load "next/dist/build/utils" with error: ${e.message ?? e}`);
69
+ throw new Error(`Failed to load "next/dist/build/utils" with error: ${e.message ?? e}`, { cause: e });
70
70
  }
71
71
  return packages;
72
72
  }
@@ -188,7 +188,7 @@ const originalModuleLoad = module_1.default._load;
188
188
  function sourceNextWebpackDeps(devServerConfig) {
189
189
  const framework = (0, sourceRelativeWebpackModules_1.sourceFramework)(devServerConfig);
190
190
  const webpack = sourceNextWebpack(devServerConfig, framework);
191
- const webpackDevServer = (0, sourceRelativeWebpackModules_1.sourceWebpackDevServer)(devServerConfig, webpack.majorVersion, framework);
191
+ const webpackDevServer = (0, sourceRelativeWebpackModules_1.sourceWebpackDevServer)(devServerConfig, webpack, framework);
192
192
  const htmlWebpackPlugin = (0, sourceRelativeWebpackModules_1.sourceHtmlWebpackPlugin)(devServerConfig, framework, webpack);
193
193
  return {
194
194
  framework,
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import Module from 'module';
3
3
  import type { WebpackDevServerConfig } from '../devServer';
4
+ import type webpack from 'webpack';
4
5
  export type ModuleClass = typeof Module & {
5
6
  _load(id: string, parent: Module, isMain: boolean): any;
6
7
  _resolveFilename(request: string, parent: Module, isMain: boolean, options?: {
@@ -17,14 +18,14 @@ export interface SourcedDependency {
17
18
  packageJson: PackageJson;
18
19
  }
19
20
  export interface SourcedWebpack extends SourcedDependency {
20
- module: Function;
21
+ module: typeof webpack;
21
22
  majorVersion: 4 | 5;
22
23
  }
23
24
  interface SourcedWebpackDevServer extends SourcedDependency {
24
25
  module: {
25
26
  new (...args: unknown[]): unknown;
26
27
  };
27
- majorVersion: 4 | 5;
28
+ majorVersion: 4 | 5 | 6;
28
29
  }
29
30
  interface SourcedHtmlWebpackPlugin extends SourcedDependency {
30
31
  module: unknown;
@@ -37,7 +38,7 @@ export interface SourceRelativeWebpackResult {
37
38
  htmlWebpackPlugin: SourcedHtmlWebpackPlugin;
38
39
  }
39
40
  export declare function sourceFramework(config: WebpackDevServerConfig): SourcedDependency | null;
40
- export declare function sourceWebpackDevServer(config: WebpackDevServerConfig, webpackMajorVersion: 4 | 5, framework?: SourcedDependency | null): SourcedWebpackDevServer;
41
+ export declare function sourceWebpackDevServer(config: WebpackDevServerConfig, webpack: SourcedWebpack, framework?: SourcedDependency | null): SourcedWebpackDevServer;
41
42
  export declare function sourceHtmlWebpackPlugin(config: WebpackDevServerConfig, framework: SourcedDependency | null, webpack: SourcedWebpack): SourcedHtmlWebpackPlugin;
42
43
  export declare function sourceDefaultWebpackDependencies(config: WebpackDevServerConfig): SourceRelativeWebpackResult;
43
44
  export declare function getMajorVersion<T extends number>(json: PackageJson, acceptedVersions: T[]): T;
@@ -5,12 +5,20 @@ const tslib_1 = require("tslib");
5
5
  const module_1 = tslib_1.__importDefault(require("module"));
6
6
  const path_1 = tslib_1.__importDefault(require("path"));
7
7
  const debug_1 = tslib_1.__importDefault(require("debug"));
8
+ const semver_1 = tslib_1.__importDefault(require("semver"));
8
9
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:sourceRelativeWebpackModules');
10
+ class CypressWebpackDevServerError extends Error {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = 'CypressWebpackDevServerError';
14
+ }
15
+ }
9
16
  const originalModuleLoad = module_1.default._load;
10
17
  const originalModuleResolveFilename = module_1.default._resolveFilename;
11
18
  // We ship webpack as part of '@cypress/webpack-batteries-included-preprocessor'. The path to this module
12
19
  // serves as our fallback.
13
20
  const cypressWebpackPath = (config) => {
21
+ // eslint-disable-next-line n/no-extraneous-require -- resolved from the Cypress binary, which ships it
14
22
  return require.resolve('@cypress/webpack-batteries-included-preprocessor', {
15
23
  paths: [config.cypressConfig.cypressBinaryRoot],
16
24
  });
@@ -107,7 +115,7 @@ function sourceWebpack(config, framework) {
107
115
  }
108
116
  // Source the webpack-dev-server module from the provided framework or projectRoot.
109
117
  // If none is found, we fallback to the version bundled with this package.
110
- function sourceWebpackDevServer(config, webpackMajorVersion, framework) {
118
+ function sourceWebpackDevServer(config, webpack, framework) {
111
119
  const searchRoot = framework?.importPath ?? config.cypressConfig.projectRoot;
112
120
  debug('WebpackDevServer: Attempting to source webpack-dev-server from %s', searchRoot);
113
121
  const webpackDevServer = {};
@@ -130,8 +138,14 @@ function sourceWebpackDevServer(config, webpackMajorVersion, framework) {
130
138
  webpackDevServer.importPath = path_1.default.dirname(webpackDevServerJsonPath);
131
139
  webpackDevServer.packageJson = require(webpackDevServerJsonPath);
132
140
  webpackDevServer.module = require(webpackDevServer.importPath);
133
- webpackDevServer.majorVersion = getMajorVersion(webpackDevServer.packageJson, [5]);
141
+ webpackDevServer.majorVersion = getMajorVersion(webpackDevServer.packageJson, [5, 6]);
134
142
  debug('WebpackDevServer: Successfully sourced webpack-dev-server - %o', webpackDevServer);
143
+ // Next.js's compiled webpack only reports '5' as its version, so the minimum can't be checked there
144
+ if (webpackDevServer.majorVersion === 6 && semver_1.default.valid(webpack.packageJson.version) && semver_1.default.lt(webpack.packageJson.version, '5.101.0')) {
145
+ throw new CypressWebpackDevServerError('Incompatible versions of webpack and webpack-dev-server!\n' +
146
+ `webpack-dev-server ${webpackDevServer.packageJson.version} requires webpack 5.101.0 or newer, but found webpack ${webpack.packageJson.version}.\n` +
147
+ 'Upgrade webpack to 5.101.0 or newer, or install webpack-dev-server 5 to use with @cypress/webpack-dev-server.');
148
+ }
135
149
  return webpackDevServer;
136
150
  }
137
151
  exports.sourceWebpackDevServer = sourceWebpackDevServer;
@@ -145,6 +159,7 @@ function sourceHtmlWebpackPlugin(config, framework, webpack) {
145
159
  const htmlWebpackPlugin = {};
146
160
  let htmlWebpackPluginJsonPath;
147
161
  try {
162
+ // eslint-disable-next-line n/no-extraneous-require -- sourced from the user's project, like webpack itself
148
163
  htmlWebpackPluginJsonPath = require.resolve('html-webpack-plugin/package.json', {
149
164
  paths: [searchRoot],
150
165
  });
@@ -167,10 +182,10 @@ function sourceHtmlWebpackPlugin(config, framework, webpack) {
167
182
  ],
168
183
  });
169
184
  }
170
- htmlWebpackPlugin.importPath = path_1.default.dirname(htmlWebpackPluginJsonPath),
171
- htmlWebpackPlugin.packageJson = require(htmlWebpackPluginJsonPath),
172
- htmlWebpackPlugin.module = require(htmlWebpackPlugin.importPath),
173
- htmlWebpackPlugin.majorVersion = getMajorVersion(htmlWebpackPlugin.packageJson, [4, 5]);
185
+ htmlWebpackPlugin.importPath = path_1.default.dirname(htmlWebpackPluginJsonPath);
186
+ htmlWebpackPlugin.packageJson = require(htmlWebpackPluginJsonPath);
187
+ htmlWebpackPlugin.module = require(htmlWebpackPlugin.importPath);
188
+ htmlWebpackPlugin.majorVersion = getMajorVersion(htmlWebpackPlugin.packageJson, [4, 5]);
174
189
  debug('HtmlWebpackPlugin: Successfully sourced html-webpack-plugin - %o', htmlWebpackPlugin);
175
190
  return htmlWebpackPlugin;
176
191
  }
@@ -179,7 +194,7 @@ exports.sourceHtmlWebpackPlugin = sourceHtmlWebpackPlugin;
179
194
  function sourceDefaultWebpackDependencies(config) {
180
195
  const framework = sourceFramework(config);
181
196
  const webpack = sourceWebpack(config, framework);
182
- const webpackDevServer = sourceWebpackDevServer(config, webpack.majorVersion, framework);
197
+ const webpackDevServer = sourceWebpackDevServer(config, webpack, framework);
183
198
  const htmlWebpackPlugin = sourceHtmlWebpackPlugin(config, framework, webpack);
184
199
  return {
185
200
  framework,
package/package.json CHANGED
@@ -1,26 +1,40 @@
1
1
  {
2
2
  "name": "@cypress/webpack-dev-server",
3
- "version": "6.1.2",
3
+ "version": "6.2.1",
4
4
  "description": "Launches Webpack Dev Server for Component Testing",
5
+ "homepage": "https://github.com/cypress-io/cypress/tree/develop/npm/webpack-dev-server#readme",
6
+ "bugs": "https://github.com/cypress-io/cypress/issues/new?template=1-bug-report.md",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/cypress-io/cypress.git"
10
+ },
11
+ "license": "MIT",
5
12
  "main": "dist/index.js",
13
+ "files": [
14
+ "dist"
15
+ ],
6
16
  "scripts": {
7
17
  "prebuild": "rimraf dist",
8
18
  "build": "tsc || echo 'built, with type errors'",
9
- "check-ts": "tsc --noEmit",
19
+ "check-ts": "tsc --noEmit && tsc --project cypress/tsconfig.json",
10
20
  "clean": "rimraf dist",
11
21
  "cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project . --expose INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=true",
12
22
  "cypress:run": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome --expose INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=true",
13
23
  "cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
14
24
  "dev": "tsc --watch",
15
- "lint": "eslint --ext .js,.ts,.json, .",
25
+ "lint": "eslint",
16
26
  "test": "vitest run",
17
27
  "test-debug": "vitest --inspect-brk --no-file-parallelism --test-timeout=0"
18
28
  },
29
+ "lint-staged": {
30
+ "**/*.{js,jsx,ts,tsx,json}": "eslint --fix --no-warn-ignored"
31
+ },
19
32
  "dependencies": {
20
33
  "find-up": "6.3.0",
21
34
  "fs-extra": "9.1.0",
22
35
  "html-webpack-plugin-5": "npm:html-webpack-plugin@^5",
23
36
  "local-pkg": "0.4.1",
37
+ "micromatch": "^4.0.8",
24
38
  "semver": "^7.7.3",
25
39
  "tslib": "^2.3.1",
26
40
  "tsx": "^4.23.12",
@@ -29,26 +43,23 @@
29
43
  "webpack-merge": "^5.4.0"
30
44
  },
31
45
  "devDependencies": {
46
+ "@angular-devkit/core": "^21.2.7",
47
+ "@packages/eslint-config": "0.0.0-development",
48
+ "@types/micromatch": "4.0.10",
32
49
  "@types/node": "24.10.1",
50
+ "@types/semver": "^7.5.0",
33
51
  "@types/webpack-bundle-analyzer": "4.7.0",
34
52
  "cross-env": "7.0.3",
35
53
  "dedent": "^0.7.0",
54
+ "eslint": "^10.14.0",
55
+ "jiti": "^2.4.2",
36
56
  "vitest": "^3.2.4",
37
- "webpack": "npm:webpack@^5"
57
+ "webpack": "npm:webpack@^5",
58
+ "webpack-dev-server-6": "npm:webpack-dev-server@^6"
38
59
  },
39
60
  "peerDependencies": {
40
61
  "cypress": ">=15.0.0"
41
62
  },
42
- "files": [
43
- "dist"
44
- ],
45
- "license": "MIT",
46
- "repository": {
47
- "type": "git",
48
- "url": "git+https://github.com/cypress-io/cypress.git"
49
- },
50
- "homepage": "https://github.com/cypress-io/cypress/tree/develop/npm/webpack-dev-server#readme",
51
- "bugs": "https://github.com/cypress-io/cypress/issues/new?template=1-bug-report.md",
52
63
  "publishConfig": {
53
64
  "access": "public"
54
65
  },