@cypress/webpack-dev-server 5.1.4 → 5.1.5

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.`);
@@ -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.1.5",
4
4
  "description": "Launches Webpack Dev Server for Component Testing",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -13,8 +13,8 @@
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",
@@ -24,6 +24,7 @@
24
24
  "semver": "^7.7.1",
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;