@cypress/webpack-dev-server 3.4.1 → 3.5.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.
@@ -5,6 +5,7 @@ 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 semver_1 = require("semver");
8
9
  const dynamic_import_1 = require("../dynamic-import");
9
10
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
10
11
  const debug_1 = tslib_1.__importDefault(require("debug"));
@@ -54,17 +55,21 @@ async function generateTsConfig(devServerConfig, buildOptions) {
54
55
  : [buildOptions.polyfills];
55
56
  includePaths.push(...polyfills.map((p) => getProjectFilePath(workspaceRoot, p)));
56
57
  }
57
- const cypressTypes = getProjectFilePath(workspaceRoot, 'node_modules', 'cypress', 'types', 'index.d.ts');
58
- includePaths.push(cypressTypes);
58
+ const typeRoots = [
59
+ getProjectFilePath(workspaceRoot, 'node_modules'),
60
+ ];
61
+ const types = ['cypress'];
59
62
  const tsConfigContent = JSON.stringify({
60
63
  extends: getProjectFilePath(projectRoot, (_a = buildOptions.tsConfig) !== null && _a !== void 0 ? _a : 'tsconfig.json'),
61
64
  compilerOptions: {
62
65
  outDir: getProjectFilePath(projectRoot, 'out-tsc/cy'),
63
66
  allowSyntheticDefaultImports: true,
64
67
  skipLibCheck: true,
68
+ types,
69
+ typeRoots,
65
70
  },
66
71
  include: includePaths,
67
- });
72
+ }, null, 2);
68
73
  const tsConfigPath = path.join(await getTempDir(), 'tsconfig.json');
69
74
  await fs.writeFile(tsConfigPath, tsConfigContent);
70
75
  return tsConfigPath;
@@ -77,10 +82,19 @@ async function getTempDir() {
77
82
  }
78
83
  exports.getTempDir = getTempDir;
79
84
  async function getAngularCliModules(projectRoot) {
85
+ let angularVersion;
86
+ try {
87
+ angularVersion = await getInstalledPackageVersion('@angular-devkit/core', projectRoot);
88
+ }
89
+ catch (_a) {
90
+ throw new Error(`Could not resolve "@angular-devkit/core". Do you have it installed?`);
91
+ }
80
92
  const angularCLiModules = [
81
93
  '@angular-devkit/build-angular/src/utils/webpack-browser-config.js',
82
- '@angular-devkit/build-angular/src/webpack/configs/common.js',
83
- '@angular-devkit/build-angular/src/webpack/configs/styles.js',
94
+ // in Angular 16.1 the locations of these files below were changed
95
+ ...((0, semver_1.gte)(angularVersion, '16.1.0')
96
+ ? ['@angular-devkit/build-angular/src/tools/webpack/configs/common.js', '@angular-devkit/build-angular/src/tools/webpack/configs/styles.js']
97
+ : ['@angular-devkit/build-angular/src/webpack/configs/common.js', '@angular-devkit/build-angular/src/webpack/configs/styles.js']),
84
98
  '@angular-devkit/core/src/index.js',
85
99
  ];
86
100
  const [{ generateBrowserWebpackConfigFromContext }, { getCommonConfig }, { getStylesConfig }, { logging },] = await Promise.all(angularCLiModules.map((dep) => {
@@ -100,6 +114,11 @@ async function getAngularCliModules(projectRoot) {
100
114
  };
101
115
  }
102
116
  exports.getAngularCliModules = getAngularCliModules;
117
+ async function getInstalledPackageVersion(pkgName, projectRoot) {
118
+ const packageJsonPath = require.resolve(`${pkgName}/package.json`, { paths: [projectRoot] });
119
+ const { version } = JSON.parse(await fs.readFile(packageJsonPath, { encoding: 'utf-8' }));
120
+ return version;
121
+ }
103
122
  async function getAngularJson(projectRoot) {
104
123
  const { findUp } = await (0, dynamic_import_1.dynamicImport)('find-up');
105
124
  const angularJsonPath = await findUp('angular.json', { cwd: projectRoot });
@@ -144,26 +163,31 @@ async function getAngularCliWebpackConfig(devServerConfig) {
144
163
  const buildOptions = getAngularBuildOptions(projectConfig.buildOptions, tsConfig);
145
164
  const context = createFakeContext(projectConfig.buildOptions.workspaceRoot || projectRoot, projectConfig, logging);
146
165
  const { config } = await generateBrowserWebpackConfigFromContext(buildOptions, context, (wco) => {
147
- const stylesConfig = getStylesConfig(wco);
148
- // We modify resolve-url-loader and set `root` to be `projectRoot` + `sourceRoot` to ensure
149
- // imports in scss, sass, etc are correctly resolved.
150
- // https://github.com/cypress-io/cypress/issues/24272
151
- stylesConfig.module.rules.forEach((rule) => {
152
- var _a;
153
- (_a = rule.rules) === null || _a === void 0 ? void 0 : _a.forEach((ruleSet) => {
154
- if (!Array.isArray(ruleSet.use)) {
155
- return;
156
- }
157
- ruleSet.use.map((loader) => {
158
- var _a;
159
- if (typeof loader !== 'object' || typeof loader.options !== 'object' || !((_a = loader.loader) === null || _a === void 0 ? void 0 : _a.includes('resolve-url-loader'))) {
166
+ // Starting in Angular 16, the `getStylesConfig` function returns a `Promise`.
167
+ // We wrap it with `Promise.resolve` so we support older version of Angular
168
+ // returning a non-Promise result.
169
+ const stylesConfig = Promise.resolve(getStylesConfig(wco)).then((config) => {
170
+ // We modify resolve-url-loader and set `root` to be `projectRoot` + `sourceRoot` to ensure
171
+ // imports in scss, sass, etc are correctly resolved.
172
+ // https://github.com/cypress-io/cypress/issues/24272
173
+ config.module.rules.forEach((rule) => {
174
+ var _a;
175
+ (_a = rule.rules) === null || _a === void 0 ? void 0 : _a.forEach((ruleSet) => {
176
+ if (!Array.isArray(ruleSet.use)) {
160
177
  return;
161
178
  }
162
- const root = projectConfig.buildOptions.workspaceRoot || path.join(devServerConfig.cypressConfig.projectRoot, projectConfig.sourceRoot);
163
- debug('Adding root %s to resolve-url-loader options', root);
164
- loader.options.root = root;
179
+ ruleSet.use.map((loader) => {
180
+ var _a;
181
+ if (typeof loader !== 'object' || typeof loader.options !== 'object' || !((_a = loader.loader) === null || _a === void 0 ? void 0 : _a.includes('resolve-url-loader'))) {
182
+ return;
183
+ }
184
+ const root = projectConfig.buildOptions.workspaceRoot || path.join(devServerConfig.cypressConfig.projectRoot, projectConfig.sourceRoot);
185
+ debug('Adding root %s to resolve-url-loader options', root);
186
+ loader.options.root = root;
187
+ });
165
188
  });
166
189
  });
190
+ return config;
167
191
  });
168
192
  return [getCommonConfig(wco), stylesConfig];
169
193
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/webpack-dev-server",
3
- "version": "3.4.1",
3
+ "version": "3.5.1",
4
4
  "description": "Launches Webpack Dev Server for Component Testing",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@
23
23
  "html-webpack-plugin-4": "npm:html-webpack-plugin@^4",
24
24
  "html-webpack-plugin-5": "npm:html-webpack-plugin@^5",
25
25
  "local-pkg": "0.4.1",
26
+ "semver": "^7.5.3",
26
27
  "speed-measure-webpack-plugin": "1.4.2",
27
28
  "tslib": "^2.3.1",
28
29
  "webpack-dev-server": "^4.7.4",