@cypress/webpack-dev-server 5.1.4 → 5.2.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.
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs-extra"));
6
6
  const os_1 = require("os");
7
7
  const path = tslib_1.__importStar(require("path"));
8
- const dynamic_import_1 = require("../dynamic-import");
9
8
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
10
9
  const debug_1 = tslib_1.__importDefault(require("debug"));
11
10
  const debugPrefix = 'cypress:webpack-dev-server:angularHandler';
@@ -88,10 +87,15 @@ async function getAngularCliModules(projectRoot) {
88
87
  '@angular-devkit/build-angular/src/tools/webpack/configs/styles.js',
89
88
  '@angular-devkit/core/src/index.js',
90
89
  ];
91
- const [{ generateBrowserWebpackConfigFromContext }, { getCommonConfig }, { getStylesConfig }, { logging },] = await Promise.all(angularCLiModules.map((dep) => {
90
+ const [{ generateBrowserWebpackConfigFromContext }, { getCommonConfig }, { getStylesConfig }, { logging },] = await Promise.all(angularCLiModules.map(async (dep) => {
92
91
  try {
93
92
  const depPath = require.resolve(dep, { paths: [projectRoot] });
94
- return (0, dynamic_import_1.dynamicAbsoluteImport)(depPath);
93
+ // NOTE: @cypress/webpack-dev-server is a CJS package, but we need to import some ESM files and absolute imports.
94
+ // since import statements in TypeScript will get transpiled down to CommonJS require statements, we want to use tsx to leverage
95
+ // an ESM style import here, which supports CommonJS and ESM.
96
+ const { tsImport } = require('tsx/esm/api');
97
+ const module = await tsImport(depPath, __filename);
98
+ return module;
95
99
  }
96
100
  catch (e) {
97
101
  throw new Error(`Could not resolve "${dep}". Do you have "@angular-devkit/build-angular" and "@angular-devkit/core" installed?`);
@@ -106,7 +110,11 @@ async function getAngularCliModules(projectRoot) {
106
110
  }
107
111
  exports.getAngularCliModules = getAngularCliModules;
108
112
  async function getAngularJson(projectRoot) {
109
- const { findUp } = await (0, dynamic_import_1.dynamicImport)('find-up');
113
+ // NOTE: @cypress/webpack-dev-server is a CJS package, but find-up +6.0.0 is an ESM only package.
114
+ // In order to dynamically import the find-up package, we need to use tsx to do so until @cypress/webpack-dev-server is an ESM-only package,
115
+ // which would be a breaking change to @cypress/webpack-dev-server and cypress.
116
+ const { tsImport } = require('tsx/esm/api');
117
+ const { findUp } = await tsImport('find-up', __filename);
110
118
  const angularJsonPath = await findUp('angular.json', { cwd: projectRoot });
111
119
  if (!angularJsonPath) {
112
120
  throw new Error(`Could not find angular.json. Looked in ${projectRoot} and up.`);
@@ -6,6 +6,7 @@ const debug_1 = tslib_1.__importDefault(require("debug"));
6
6
  const module_1 = tslib_1.__importDefault(require("module"));
7
7
  const fs = tslib_1.__importStar(require("fs"));
8
8
  const path = tslib_1.__importStar(require("path"));
9
+ const semver_1 = tslib_1.__importDefault(require("semver"));
9
10
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
10
11
  const debug = (0, debug_1.default)('cypress:webpack-dev-server-fresh:nextHandler');
11
12
  async function nextHandler(devServerConfig) {
@@ -61,71 +62,12 @@ function getNextJsPackages(devServerConfig) {
61
62
  }
62
63
  /**
63
64
  * Types for `getNextJsBaseWebpackConfig` based on version:
64
- * - v11.1.4
65
+ * - v14.0.0, v15.0.0, and v16.0.0
65
66
  [
66
67
  dir: string,
67
- options: {
68
- buildId: string
69
- config: NextConfigComplete
70
- dev?: boolean
71
- isServer?: boolean
72
- pagesDir: string
73
- target?: string
74
- reactProductionProfiling?: boolean
75
- entrypoints: WebpackEntrypoints
76
- rewrites: CustomRoutes['rewrites']
77
- isDevFallback?: boolean
78
- runWebpackSpan: Span
79
- }
80
- ]
81
-
82
- * - v12.0.0 = Same as v11.1.4
83
-
84
- * - v12.1.6
85
- [
86
- dir: string,
87
- options: {
88
- buildId: string
89
- config: NextConfigComplete
90
- compilerType: 'client' | 'server' | 'edge-server'
91
- dev?: boolean
92
- entrypoints: webpack5.EntryObject
93
- hasReactRoot: boolean
94
- isDevFallback?: boolean
95
- pagesDir: string
96
- reactProductionProfiling?: boolean
97
- rewrites: CustomRoutes['rewrites']
98
- runWebpackSpan: Span
99
- target?: string
100
- }
101
- ]
102
-
103
- * - v13.0.0
104
- [
105
- dir: string,
106
- options: {
107
- buildId: string
108
- config: NextConfigComplete
109
- compilerType: CompilerNameValues
110
- dev?: boolean
111
- entrypoints: webpack.EntryObject
112
- hasReactRoot: boolean
113
- isDevFallback?: boolean
114
- pagesDir?: string
115
- reactProductionProfiling?: boolean
116
- rewrites: CustomRoutes['rewrites']
117
- runWebpackSpan: Span
118
- target?: string
119
- appDir?: string
120
- middlewareMatchers?: MiddlewareMatcher[]
121
- }
122
- ]
123
-
124
- * - v13.0.1
125
- [
126
- dir: string,
127
- options: {
68
+ options: {
128
69
  buildId: string
70
+ encryptionKey: string
129
71
  config: NextConfigComplete
130
72
  compilerType: CompilerNameValues
131
73
  dev?: boolean
@@ -134,41 +76,27 @@ function getNextJsPackages(devServerConfig) {
134
76
  pagesDir?: string
135
77
  reactProductionProfiling?: boolean
136
78
  rewrites: CustomRoutes['rewrites']
79
+ originalRewrites?: CustomRoutes['rewrites']
80
+ originalRedirects?: CustomRoutes['redirects']
137
81
  runWebpackSpan: Span
138
- target?: string
139
82
  appDir?: string
140
- middlewareMatchers?: MiddlewareMatcher[]
141
- }
142
- ]
143
-
144
- * - v13.2.1
145
- [
146
- dir: string,
147
- options: {
148
- buildId: string
149
- config: NextConfigComplete
150
- compilerType: CompilerNameValues
151
- dev?: boolean
152
- entrypoints: webpack.EntryObject
153
- isDevFallback?: boolean
154
- pagesDir?: string
155
- reactProductionProfiling?: boolean
156
- rewrites: CustomRoutes['rewrites']
157
- runWebpackSpan: Span
158
- target?: string
159
- appDir?: string
160
- middlewareMatchers?: MiddlewareMatcher[]
161
- noMangling?: boolean
162
- jsConfig: any
163
- resolvedBaseUrl: string | undefined
164
- supportedBrowsers: string[] | undefined
165
- clientRouterFilters?: {
166
- staticFilter: ReturnType<
167
- import('../shared/lib/bloom-filter').BloomFilter['export']
168
- >
169
- dynamicFilter: ReturnType<
170
- import('../shared/lib/bloom-filter').BloomFilter['export']
171
- >
83
+ middlewareMatchers?: ProxyMatcher[]
84
+ noMangling?: boolean
85
+ jsConfig: any
86
+ jsConfigPath?: string
87
+ resolvedBaseUrl: ResolvedBaseUrl
88
+ supportedBrowsers: string[] | undefined
89
+ clientRouterFilters?: {
90
+ staticFilter: ReturnType<
91
+ import('../shared/lib/bloom-filter').BloomFilter['export']
92
+ >
93
+ dynamicFilter: ReturnType<
94
+ import('../shared/lib/bloom-filter').BloomFilter['export']
95
+ >
96
+ }
97
+ fetchCacheKeyPrefix?: string
98
+ isCompileMode?: boolean
99
+ previewProps: NonNullable<(typeof NextBuildContext)['previewProps']>;
172
100
  }
173
101
  }
174
102
  ]
@@ -186,7 +114,7 @@ async function loadWebpackConfig(devServerConfig) {
186
114
  // Client webpack config for Next.js > 12.1.5
187
115
  compilerType: 'client',
188
116
  // Required for Next.js > 13
189
- hasReactRoot: reactVersion === 18,
117
+ hasReactRoot: Boolean(reactVersion && reactVersion >= 18),
190
118
  // Required for Next.js > 13.2.0 to respect TS/JS config
191
119
  jsConfig: jsConfigResult.jsConfig,
192
120
  // Required for Next.js > 13.2.0 to respect tsconfig.compilerOptions.baseUrl
@@ -289,29 +217,20 @@ function sourceNextWebpack(devServerConfig, framework) {
289
217
  debug('NextWebpack: Failed to load NextWebpack - %s', e);
290
218
  throw e;
291
219
  }
292
- // Next 11 allows the choice of webpack@4 or webpack@5, depending on the "webpack5" property in their next.config.js
293
- // The webpackModule.init" for Next 11 returns a webpack@4 or webpack@4 compiler instance based on this boolean
294
- let webpack5 = true;
295
220
  const importPath = path.join(path.dirname(webpackJsonPath), 'webpack.js');
296
221
  const webpackModule = require(importPath);
297
- try {
298
- const nextConfig = require(path.resolve(devServerConfig.cypressConfig.projectRoot, 'next.config.js'));
299
- debug('NextWebpack: next.config.js found - %o', nextConfig);
300
- if (nextConfig.webpack5 === false) {
301
- webpack5 = false;
302
- }
303
- }
304
- catch (e) {
305
- // No next.config.js, assume webpack 5
222
+ // If Next.js is 16 and greater, webpack.js runs the required code previously inside init() on require().
223
+ // init() no longer exists and has the same affect on import, so we don't/can't invoke it
224
+ if (semver_1.default.lt(framework.packageJson.version, '16.0.0')) {
225
+ // for next 15 and down, we need to initialize the webpack module
226
+ webpackModule.init(true);
306
227
  }
307
- debug('NextWebpack: webpack5 - %s', webpack5);
308
- webpackModule.init(webpack5);
309
228
  const packageJson = require(webpackJsonPath);
310
229
  webpack.importPath = importPath;
311
230
  // The package.json of "next/dist/compiled/webpack/package.json" has no version so we supply the version for later use
312
- webpack.packageJson = Object.assign(Object.assign({}, packageJson), { version: webpack5 ? '5' : '4' });
231
+ webpack.packageJson = Object.assign(Object.assign({}, packageJson), { version: '5' });
313
232
  webpack.module = webpackModule.webpack;
314
- webpack.majorVersion = (0, sourceRelativeWebpackModules_1.getMajorVersion)(webpack.packageJson, [4, 5]);
233
+ webpack.majorVersion = (0, sourceRelativeWebpackModules_1.getMajorVersion)(webpack.packageJson, [5]);
315
234
  debug('NextWebpack: Successfully loaded NextWebpack - %o', webpack);
316
235
  module_1.default._load = function (request, parent, isMain) {
317
236
  // Next with webpack@4 doesn't ship certain dependencies that HtmlWebpackPlugin requires, so we patch the resolution through to our bundled version
@@ -8,7 +8,6 @@ const webpack_merge_1 = require("webpack-merge");
8
8
  const local_pkg_1 = require("local-pkg");
9
9
  const makeDefaultWebpackConfig_1 = require("./makeDefaultWebpackConfig");
10
10
  const constants_1 = require("./constants");
11
- const dynamic_import_1 = require("./dynamic-import");
12
11
  const debug = (0, debug_1.debug)('cypress:webpack-dev-server:makeWebpackConfig');
13
12
  const removeList = [
14
13
  // We provide a webpack-html-plugin config pinned to a specific version (4.x)
@@ -52,8 +51,13 @@ function modifyWebpackConfigForCypress(webpackConfig) {
52
51
  return webpackConfig;
53
52
  }
54
53
  async function getWebpackConfigFromProjectRoot(projectRoot) {
55
- const { findUp } = await (0, dynamic_import_1.dynamicImport)('find-up');
56
- return await findUp(constants_1.configFiles, { cwd: projectRoot });
54
+ // NOTE: @cypress/webpack-dev-server is a CJS package, but find-up +6.0.0 is an ESM only package.
55
+ // In order to dynamically import the find-up package, we need to use tsx to do so until @cypress/webpack-dev-server is an ESM-only package,
56
+ // which would be a breaking change to @cypress/webpack-dev-server and cypress.
57
+ const { tsImport } = require('tsx/esm/api');
58
+ const { findUp } = await tsImport('find-up', __filename);
59
+ const findUpResult = await findUp(constants_1.configFiles, { cwd: projectRoot });
60
+ return findUpResult;
57
61
  }
58
62
  /**
59
63
  * Creates a webpack 4/5 compatible webpack "configuration"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/webpack-dev-server",
3
- "version": "5.1.4",
3
+ "version": "5.2.0",
4
4
  "description": "Launches Webpack Dev Server for Component Testing",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -13,17 +13,18 @@
13
13
  "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
14
  "dev": "tsc --watch",
15
15
  "lint": "eslint --ext .js,.ts,.json, .",
16
- "test": "yarn test-unit",
17
- "test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js"
16
+ "test": "vitest run",
17
+ "test-debug": "vitest --inspect-brk --no-file-parallelism --test-timeout=0"
18
18
  },
19
19
  "dependencies": {
20
20
  "find-up": "6.3.0",
21
21
  "fs-extra": "9.1.0",
22
22
  "html-webpack-plugin-5": "npm:html-webpack-plugin@^5",
23
23
  "local-pkg": "0.4.1",
24
- "semver": "^7.7.1",
24
+ "semver": "^7.7.3",
25
25
  "speed-measure-webpack-plugin": "1.4.2",
26
26
  "tslib": "^2.3.1",
27
+ "tsx": "^4.20.6",
27
28
  "webpack-bundle-analyzer": "4.10.2",
28
29
  "webpack-dev-server": "^5.1.0",
29
30
  "webpack-merge": "^5.4.0"
@@ -32,13 +33,9 @@
32
33
  "@types/node": "22.18.7",
33
34
  "@types/speed-measure-webpack-plugin": "^1.3.4",
34
35
  "@types/webpack-bundle-analyzer": "4.7.0",
35
- "chai": "^4.3.6",
36
36
  "cross-env": "7.0.3",
37
37
  "dedent": "^0.7.0",
38
- "mocha": "^9.2.2",
39
- "sinon": "^13.0.1",
40
- "snap-shot-it": "^7.9.10",
41
- "ts-node": "^10.9.2",
38
+ "vitest": "^3.2.4",
42
39
  "webpack": "npm:webpack@^5"
43
40
  },
44
41
  "peerDependencies": {
@@ -1,2 +0,0 @@
1
- export declare const dynamicImport: <T>(module: string) => Promise<T>;
2
- export declare const dynamicAbsoluteImport: (filePath: string) => Promise<any>;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dynamicAbsoluteImport = exports.dynamicImport = void 0;
4
- const url_1 = require("url");
5
- // tsc will compile `import(...)` calls to require unless a different tsconfig.module value
6
- // is used (e.g. module=node16). To change this, we would also have to change the ts-node behavior when requiring the
7
- // Cypress config file. This hack for keeping dynamic imports from being converted works across all
8
- // of our supported node versions
9
- const _dynamicImport = new Function('specifier', 'return import(specifier)');
10
- const dynamicImport = (module) => _dynamicImport(module);
11
- exports.dynamicImport = dynamicImport;
12
- const dynamicAbsoluteImport = (filePath) => {
13
- return (0, exports.dynamicImport)((0, url_1.pathToFileURL)(filePath).href);
14
- };
15
- exports.dynamicAbsoluteImport = dynamicAbsoluteImport;