@cypress/webpack-dev-server 2.2.0 → 2.4.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
@@ -71,7 +71,7 @@ We then merge the sourced config with the user's webpack config, and layer on ou
71
71
 
72
72
  ## License
73
73
 
74
- [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/master/LICENSE)
74
+ [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/develop/LICENSE)
75
75
 
76
76
  This project is licensed under the terms of the [MIT license](/LICENSE).
77
77
 
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CypressCTWebpackPlugin = exports.normalizeError = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
6
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
7
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
8
  const normalizeError = (error) => {
9
9
  return typeof error === 'string' ? error : error.message;
10
10
  };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createWebpackDevServer = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
6
  const makeWebpackConfig_1 = require("./makeWebpackConfig");
7
7
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:start');
8
8
  async function createWebpackDevServer(config) {
@@ -23,11 +23,14 @@ exports.createWebpackDevServer = createWebpackDevServer;
23
23
  function webpackDevServer4(config, compiler, finalWebpackConfig) {
24
24
  var _a;
25
25
  const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config;
26
+ const isOpenMode = !config.devServerConfig.cypressConfig.isTextTerminal;
26
27
  const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module;
27
28
  const webpackDevServerConfig = Object.assign(Object.assign({ host: '127.0.0.1', port: 'auto' }, finalWebpackConfig === null || finalWebpackConfig === void 0 ? void 0 : finalWebpackConfig.devServer), { devMiddleware: {
28
29
  publicPath: devServerPublicPathRoute,
29
30
  stats: (_a = finalWebpackConfig.stats) !== null && _a !== void 0 ? _a : 'minimal',
30
- }, hot: false });
31
+ }, hot: false,
32
+ // Only enable file watching & reload when executing tests in `open` mode
33
+ liveReload: isOpenMode });
31
34
  const server = new WebpackDevServer(webpackDevServerConfig, compiler);
32
35
  return {
33
36
  server,
@@ -37,10 +40,13 @@ function webpackDevServer4(config, compiler, finalWebpackConfig) {
37
40
  function webpackDevServer3(config, compiler, finalWebpackConfig) {
38
41
  var _a, _b;
39
42
  const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config;
43
+ const isOpenMode = !config.devServerConfig.cypressConfig.isTextTerminal;
40
44
  const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module;
41
45
  const webpackDevServerConfig = Object.assign(Object.assign({}, (_a = finalWebpackConfig.devServer) !== null && _a !== void 0 ? _a : {}), { hot: false,
42
46
  // @ts-ignore ignore webpack-dev-server v3 type errors
43
- inline: false, publicPath: devServerPublicPathRoute, noInfo: false, stats: (_b = finalWebpackConfig.stats) !== null && _b !== void 0 ? _b : 'minimal' });
47
+ inline: false, publicPath: devServerPublicPathRoute, noInfo: false, stats: (_b = finalWebpackConfig.stats) !== null && _b !== void 0 ? _b : 'minimal',
48
+ // Only enable file watching & reload when executing tests in `open` mode
49
+ liveReload: isOpenMode });
44
50
  const server = new WebpackDevServer(compiler, webpackDevServerConfig);
45
51
  return {
46
52
  server,
@@ -1,17 +1,27 @@
1
1
  /// <reference types="cypress" />
2
+ /// <reference types="cypress" />
2
3
  /// <reference types="node" />
3
4
  import type { Configuration } from 'webpack';
4
5
  import { SourceRelativeWebpackResult } from './helpers/sourceRelativeWebpackModules';
6
+ export declare type Frameworks = Extract<Cypress.DevServerConfigOptions, {
7
+ bundler: 'webpack';
8
+ }>['framework'];
9
+ declare type FrameworkConfig = {
10
+ framework?: Exclude<Frameworks, 'angular'>;
11
+ } | {
12
+ framework: 'angular';
13
+ options?: {
14
+ projectConfig: Cypress.AngularDevServerProjectConfig;
15
+ };
16
+ };
17
+ export declare type ConfigHandler = Partial<Configuration> | (() => Partial<Configuration> | Promise<Partial<Configuration>>);
5
18
  export declare type WebpackDevServerConfig = {
6
19
  specs: Cypress.Spec[];
7
20
  cypressConfig: Cypress.PluginConfigOptions;
8
21
  devServerEvents: NodeJS.EventEmitter;
9
22
  onConfigNotFound?: (devServer: 'webpack', cwd: string, lookedIn: string[]) => void;
10
- } & {
11
- framework?: typeof ALL_FRAMEWORKS[number];
12
- webpackConfig?: unknown;
13
- };
14
- export declare const ALL_FRAMEWORKS: readonly ["create-react-app", "nuxt", "react", "vue-cli", "next", "vue", "angular"];
23
+ webpackConfig?: ConfigHandler;
24
+ } & FrameworkConfig;
15
25
  /**
16
26
  * import { devServer } from '@cypress/webpack-dev-server'
17
27
  *
@@ -25,7 +35,7 @@ export declare namespace devServer {
25
35
  var create: (devServerConfig: WebpackDevServerConfig) => Promise<{
26
36
  server: unknown;
27
37
  compiler: object;
28
- version: 4 | 3;
38
+ version: 3 | 4;
29
39
  }>;
30
40
  }
31
41
  export declare type PresetHandlerResult = {
package/dist/devServer.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  /// <reference types="cypress" />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.devServer = exports.ALL_FRAMEWORKS = void 0;
4
+ exports.devServer = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const createWebpackDevServer_1 = require("./createWebpackDevServer");
7
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
7
+ const debug_1 = tslib_1.__importDefault(require("debug"));
8
8
  const vueCliHandler_1 = require("./helpers/vueCliHandler");
9
9
  const nuxtHandler_1 = require("./helpers/nuxtHandler");
10
10
  const createReactAppHandler_1 = require("./helpers/createReactAppHandler");
@@ -12,7 +12,6 @@ const nextHandler_1 = require("./helpers/nextHandler");
12
12
  const sourceRelativeWebpackModules_1 = require("./helpers/sourceRelativeWebpackModules");
13
13
  const angularHandler_1 = require("./helpers/angularHandler");
14
14
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:devServer');
15
- exports.ALL_FRAMEWORKS = ['create-react-app', 'nuxt', 'react', 'vue-cli', 'next', 'vue', 'angular'];
16
15
  /**
17
16
  * import { devServer } from '@cypress/webpack-dev-server'
18
17
  *
@@ -70,17 +69,18 @@ async function getPreset(devServerConfig) {
70
69
  case 'nuxt':
71
70
  return await (0, nuxtHandler_1.nuxtHandler)(devServerConfig);
72
71
  case 'vue-cli':
73
- return (0, vueCliHandler_1.vueCliHandler)(devServerConfig);
72
+ return await (0, vueCliHandler_1.vueCliHandler)(devServerConfig);
74
73
  case 'next':
75
74
  return await (0, nextHandler_1.nextHandler)(devServerConfig);
76
75
  case 'angular':
77
76
  return await (0, angularHandler_1.angularHandler)(devServerConfig);
78
77
  case 'react':
79
78
  case 'vue':
79
+ case 'svelte':
80
80
  case undefined:
81
81
  return { sourceWebpackModulesResult: (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig) };
82
82
  default:
83
- throw new Error(`Unexpected framework ${devServerConfig.framework}, expected one of ${exports.ALL_FRAMEWORKS.join(', ')}`);
83
+ throw new Error(`Unexpected framework ${devServerConfig.framework}, please visit https://docs.cypress.io/guides/component-testing/component-framework-configuration to see a list of supported frameworks`);
84
84
  }
85
85
  }
86
86
  /**
@@ -1,21 +1,22 @@
1
+ /// <reference types="cypress" />
1
2
  import type { PresetHandlerResult, WebpackDevServerConfig } from '../devServer';
3
+ export declare type BuildOptions = Record<string, any>;
4
+ export declare type AngularWebpackDevServerConfig = Extract<WebpackDevServerConfig, {
5
+ framework: 'angular';
6
+ }>;
7
+ declare type Configurations = {
8
+ configurations?: {
9
+ [configuration: string]: BuildOptions;
10
+ };
11
+ };
2
12
  export declare type AngularJsonProjectConfig = {
3
13
  projectType: string;
4
14
  root: string;
5
15
  sourceRoot: string;
6
16
  architect: {
7
17
  build: {
8
- options: {
9
- [key: string]: any;
10
- } & {
11
- polyfills?: string;
12
- };
13
- configurations?: {
14
- [configuration: string]: {
15
- [key: string]: any;
16
- };
17
- };
18
- };
18
+ options: BuildOptions;
19
+ } & Configurations;
19
20
  };
20
21
  };
21
22
  declare type AngularJson = {
@@ -24,13 +25,12 @@ declare type AngularJson = {
24
25
  [project: string]: AngularJsonProjectConfig;
25
26
  };
26
27
  };
27
- export declare function angularHandler(devServerConfig: WebpackDevServerConfig): Promise<PresetHandlerResult>;
28
- export declare function getAngularBuildOptions(projectConfig: AngularJsonProjectConfig, tsConfig: string): {
28
+ export declare function getProjectConfig(projectRoot: string): Promise<Cypress.AngularDevServerProjectConfig>;
29
+ export declare function getAngularBuildOptions(buildOptions: BuildOptions, tsConfig: string): {
29
30
  tsConfig: string;
30
31
  aot: boolean;
31
32
  outputHashing: string;
32
33
  budgets: undefined;
33
- polyfills?: string | undefined;
34
34
  outputPath: string;
35
35
  assets: never[];
36
36
  styles: never[];
@@ -68,7 +68,7 @@ export declare function getAngularBuildOptions(projectConfig: AngularJsonProject
68
68
  sourceMap: boolean;
69
69
  namedChunks: boolean;
70
70
  };
71
- export declare function generateTsConfig(devServerConfig: WebpackDevServerConfig, projectConfig: AngularJsonProjectConfig): Promise<string>;
71
+ export declare function generateTsConfig(devServerConfig: AngularWebpackDevServerConfig, buildOptions: BuildOptions): Promise<string>;
72
72
  export declare function getTempDir(): Promise<string>;
73
73
  export declare function getAngularCliModules(projectRoot: string): Promise<{
74
74
  generateBrowserWebpackConfigFromContext: any;
@@ -77,4 +77,5 @@ export declare function getAngularCliModules(projectRoot: string): Promise<{
77
77
  }>;
78
78
  export declare function getAngularJson(projectRoot: string): Promise<AngularJson>;
79
79
  export declare const toPosix: (filePath: string) => string;
80
+ export declare function angularHandler(devServerConfig: AngularWebpackDevServerConfig): Promise<PresetHandlerResult>;
80
81
  export {};
@@ -1,46 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toPosix = exports.getAngularJson = exports.getAngularCliModules = exports.getTempDir = exports.generateTsConfig = exports.getAngularBuildOptions = exports.angularHandler = void 0;
3
+ exports.angularHandler = exports.toPosix = exports.getAngularJson = exports.getAngularCliModules = exports.getTempDir = exports.generateTsConfig = exports.getAngularBuildOptions = exports.getProjectConfig = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const fs = (0, tslib_1.__importStar)(require("fs-extra"));
5
+ const fs = tslib_1.__importStar(require("fs-extra"));
6
6
  const os_1 = require("os");
7
- const path = (0, tslib_1.__importStar)(require("path"));
7
+ const path = tslib_1.__importStar(require("path"));
8
8
  const url_1 = require("url");
9
9
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
10
10
  const dynamicImport = new Function('specifier', 'return import(specifier)');
11
- async function angularHandler(devServerConfig) {
12
- const webpackConfig = await getAngularCliWebpackConfig(devServerConfig);
13
- return { frameworkConfig: webpackConfig, sourceWebpackModulesResult: (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig) };
14
- }
15
- exports.angularHandler = angularHandler;
16
- async function getAngularCliWebpackConfig(devServerConfig) {
17
- const { projectRoot } = devServerConfig.cypressConfig;
18
- const { generateBrowserWebpackConfigFromContext, getCommonConfig, getStylesConfig, } = await getAngularCliModules(projectRoot);
11
+ async function getProjectConfig(projectRoot) {
12
+ var _a;
19
13
  const angularJson = await getAngularJson(projectRoot);
20
14
  let { defaultProject } = angularJson;
21
15
  if (!defaultProject) {
22
16
  defaultProject = Object.keys(angularJson.projects).find((name) => angularJson.projects[name].projectType === 'application');
23
17
  if (!defaultProject) {
24
- throw new Error('Could not find a project with projectType "application" in "angular.json"');
18
+ throw new Error('Could not find a project with projectType "application" in "angular.json". Visit https://docs.cypress.io/guides/references/configuration#Options-API to see how to pass in a custom project configuration');
25
19
  }
26
20
  }
27
21
  const defaultProjectConfig = angularJson.projects[defaultProject];
28
- const tsConfig = await generateTsConfig(devServerConfig, defaultProjectConfig);
29
- const buildOptions = getAngularBuildOptions(defaultProjectConfig, tsConfig);
30
- const context = createFakeContext(projectRoot, defaultProject, defaultProjectConfig);
31
- const { config } = await generateBrowserWebpackConfigFromContext(buildOptions, context, (wco) => [getCommonConfig(wco), getStylesConfig(wco)]);
32
- delete config.entry.main;
33
- return config;
22
+ const { architect, root, sourceRoot } = defaultProjectConfig;
23
+ const { build } = architect;
24
+ return {
25
+ root,
26
+ sourceRoot,
27
+ buildOptions: Object.assign(Object.assign({}, build.options), ((_a = build.configurations) === null || _a === void 0 ? void 0 : _a.development) || {}),
28
+ };
34
29
  }
35
- function getAngularBuildOptions(projectConfig, tsConfig) {
36
- var _a;
30
+ exports.getProjectConfig = getProjectConfig;
31
+ function getAngularBuildOptions(buildOptions, tsConfig) {
37
32
  // Default options are derived from the @angular-devkit/build-angular browser builder, with some options from
38
33
  // the serve builder thrown in for development.
39
34
  // see: https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/build_angular/src/builders/browser/schema.json
40
- return Object.assign(Object.assign(Object.assign({ outputPath: 'dist/angular-app', assets: [], styles: [], scripts: [], fileReplacements: [], inlineStyleLanguage: 'css', stylePreprocessorOptions: { includePaths: [] }, resourcesOutputPath: undefined, commonChunk: true, baseHref: undefined, deployUrl: undefined, verbose: false, progress: false, i18nMissingTranslation: 'warning', i18nDuplicateTranslation: 'warning', localize: undefined, watch: true, poll: undefined, deleteOutputPath: true, preserveSymlinks: undefined, showCircularDependencies: false, subresourceIntegrity: false, serviceWorker: false, ngswConfigPath: undefined, statsJson: false, webWorkerTsConfig: undefined, crossOrigin: 'none', allowedCommonJsDependencies: [], buildOptimizer: false, optimization: false, vendorChunk: true, extractLicenses: false, sourceMap: true, namedChunks: true }, projectConfig.architect.build.options), ((_a = projectConfig.architect.build.configurations) === null || _a === void 0 ? void 0 : _a.development) || {}), { tsConfig, aot: false, outputHashing: 'none', budgets: undefined });
35
+ return Object.assign(Object.assign({ outputPath: 'dist/angular-app', assets: [], styles: [], scripts: [], fileReplacements: [], inlineStyleLanguage: 'css', stylePreprocessorOptions: { includePaths: [] }, resourcesOutputPath: undefined, commonChunk: true, baseHref: undefined, deployUrl: undefined, verbose: false, progress: false, i18nMissingTranslation: 'warning', i18nDuplicateTranslation: 'warning', localize: undefined, watch: true, poll: undefined, deleteOutputPath: true, preserveSymlinks: undefined, showCircularDependencies: false, subresourceIntegrity: false, serviceWorker: false, ngswConfigPath: undefined, statsJson: false, webWorkerTsConfig: undefined, crossOrigin: 'none', allowedCommonJsDependencies: [], buildOptimizer: false, optimization: false, vendorChunk: true, extractLicenses: false, sourceMap: true, namedChunks: true }, buildOptions), { tsConfig, aot: false, outputHashing: 'none', budgets: undefined });
41
36
  }
42
37
  exports.getAngularBuildOptions = getAngularBuildOptions;
43
- async function generateTsConfig(devServerConfig, projectConfig) {
38
+ async function generateTsConfig(devServerConfig, buildOptions) {
39
+ var _a;
44
40
  const { cypressConfig } = devServerConfig;
45
41
  const { projectRoot } = cypressConfig;
46
42
  const specPattern = Array.isArray(cypressConfig.specPattern) ? cypressConfig.specPattern : [cypressConfig.specPattern];
@@ -49,14 +45,16 @@ async function generateTsConfig(devServerConfig, projectConfig) {
49
45
  if (cypressConfig.supportFile) {
50
46
  includePaths.push((0, exports.toPosix)(cypressConfig.supportFile));
51
47
  }
52
- if (projectConfig.architect.build.options.polyfills) {
53
- const polyfills = getProjectFilePath(projectConfig.architect.build.options.polyfills);
54
- includePaths.push(polyfills);
48
+ if (buildOptions.polyfills) {
49
+ const polyfills = Array.isArray(buildOptions.polyfills)
50
+ ? buildOptions.polyfills.filter((p) => { var _a, _b; return ((_a = devServerConfig.options) === null || _a === void 0 ? void 0 : _a.projectConfig.sourceRoot) && p.startsWith((_b = devServerConfig.options) === null || _b === void 0 ? void 0 : _b.projectConfig.sourceRoot); })
51
+ : [buildOptions.polyfills];
52
+ includePaths.push(...polyfills.map((p) => getProjectFilePath(p)));
55
53
  }
56
54
  const cypressTypes = getProjectFilePath('node_modules', 'cypress', 'types', 'index.d.ts');
57
55
  includePaths.push(cypressTypes);
58
56
  const tsConfigContent = JSON.stringify({
59
- extends: getProjectFilePath('tsconfig.json'),
57
+ extends: getProjectFilePath((_a = buildOptions.tsConfig) !== null && _a !== void 0 ? _a : 'tsconfig.json'),
60
58
  compilerOptions: {
61
59
  outDir: getProjectFilePath('out-tsc/cy'),
62
60
  allowSyntheticDefaultImports: true,
@@ -107,13 +105,17 @@ async function getAngularJson(projectRoot) {
107
105
  return JSON.parse(angularJson);
108
106
  }
109
107
  exports.getAngularJson = getAngularJson;
110
- function createFakeContext(projectRoot, defaultProject, defaultProjectConfig) {
108
+ function createFakeContext(projectRoot, defaultProjectConfig) {
111
109
  const logger = {
112
- createChild: () => ({}),
110
+ createChild: () => {
111
+ return {
112
+ warn: () => { },
113
+ };
114
+ },
113
115
  };
114
116
  const context = {
115
117
  target: {
116
- project: defaultProject,
118
+ project: 'angular',
117
119
  },
118
120
  workspaceRoot: projectRoot,
119
121
  getProjectMetadata: () => {
@@ -129,3 +131,29 @@ function createFakeContext(projectRoot, defaultProject, defaultProjectConfig) {
129
131
  }
130
132
  const toPosix = (filePath) => filePath.split(path.sep).join(path.posix.sep);
131
133
  exports.toPosix = toPosix;
134
+ async function getAngularCliWebpackConfig(devServerConfig) {
135
+ var _a;
136
+ const { projectRoot } = devServerConfig.cypressConfig;
137
+ const { generateBrowserWebpackConfigFromContext, getCommonConfig, getStylesConfig, } = await getAngularCliModules(projectRoot);
138
+ // normalize
139
+ const projectConfig = ((_a = devServerConfig.options) === null || _a === void 0 ? void 0 : _a.projectConfig) || await getProjectConfig(projectRoot);
140
+ const tsConfig = await generateTsConfig(devServerConfig, projectConfig.buildOptions);
141
+ const buildOptions = getAngularBuildOptions(projectConfig.buildOptions, tsConfig);
142
+ const context = createFakeContext(projectRoot, projectConfig);
143
+ const { config } = await generateBrowserWebpackConfigFromContext(buildOptions, context, (wco) => [getCommonConfig(wco), getStylesConfig(wco)]);
144
+ delete config.entry.main;
145
+ return config;
146
+ }
147
+ function removeSourceMapPlugin(config) {
148
+ var _a;
149
+ config.plugins = (_a = config.plugins) === null || _a === void 0 ? void 0 : _a.filter((plugin) => {
150
+ var _a;
151
+ return ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.constructor) === null || _a === void 0 ? void 0 : _a.name) !== 'SourceMapDevToolPlugin';
152
+ });
153
+ }
154
+ async function angularHandler(devServerConfig) {
155
+ const webpackConfig = await getAngularCliWebpackConfig(devServerConfig);
156
+ removeSourceMapPlugin(webpackConfig);
157
+ return { frameworkConfig: webpackConfig, sourceWebpackModulesResult: (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig) };
158
+ }
159
+ exports.angularHandler = angularHandler;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactScriptsFiveModifications = exports.cypressGlobals = exports.createReactAppHandler = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
6
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
7
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
8
8
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:create-react-app');
9
9
  /**
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.allCssTests = exports.nextHandler = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
6
- const module_1 = (0, tslib_1.__importDefault)(require("module"));
7
- const fs = (0, tslib_1.__importStar)(require("fs"));
8
- const path = (0, tslib_1.__importStar)(require("path"));
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
+ const module_1 = tslib_1.__importDefault(require("module"));
7
+ const fs = tslib_1.__importStar(require("fs"));
8
+ const path = tslib_1.__importStar(require("path"));
9
9
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
10
10
  const debug = (0, debug_1.default)('cypress:webpack-dev-server-fresh:nextHandler');
11
11
  async function nextHandler(devServerConfig) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nuxtHandler = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
6
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
7
7
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:nuxtHandler');
8
8
  async function nuxtHandler(devServerConfig) {
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.restoreLoadHook = exports.getMajorVersion = exports.sourceDefaultWebpackDependencies = exports.sourceHtmlWebpackPlugin = exports.sourceWebpackDevServer = exports.sourceWebpack = exports.sourceFramework = exports.cypressWebpackPath = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const module_1 = (0, tslib_1.__importDefault)(require("module"));
6
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
7
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
5
+ const module_1 = tslib_1.__importDefault(require("module"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const debug_1 = tslib_1.__importDefault(require("debug"));
8
8
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:sourceRelativeWebpackModules');
9
9
  const originalModuleLoad = module_1.default._load;
10
10
  const originalModuleResolveFilename = module_1.default._resolveFilename;
@@ -24,6 +24,7 @@ const frameworkWebpackMapper = {
24
24
  vue: undefined,
25
25
  next: 'next',
26
26
  'angular': '@angular-devkit/build-angular',
27
+ 'svelte': undefined,
27
28
  };
28
29
  // Source the users framework from the provided projectRoot. The framework, if available, will serve
29
30
  // as the resolve base for webpack dependency resolution.
@@ -1,2 +1,2 @@
1
1
  import type { PresetHandlerResult, WebpackDevServerConfig } from '../devServer';
2
- export declare function vueCliHandler(devServerConfig: WebpackDevServerConfig): PresetHandlerResult;
2
+ export declare function vueCliHandler(devServerConfig: WebpackDevServerConfig): Promise<PresetHandlerResult>;
@@ -2,22 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vueCliHandler = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
6
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
7
7
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:vueCliHandler');
8
- function vueCliHandler(devServerConfig) {
8
+ async function vueCliHandler(devServerConfig) {
9
9
  const sourceWebpackModulesResult = (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig);
10
10
  try {
11
- const config = require.resolve('@vue/cli-service/webpack.config', {
11
+ const Service = require(require.resolve('@vue/cli-service', {
12
12
  paths: [devServerConfig.cypressConfig.projectRoot],
13
- });
14
- const webpackConfig = require(config);
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();
15
17
  debug('webpack config %o', webpackConfig);
16
18
  return { frameworkConfig: webpackConfig, sourceWebpackModulesResult };
17
19
  }
18
20
  catch (e) {
19
21
  console.error(e); // eslint-disable-line no-console
20
- throw Error(`Error loading @vue/cli-service/webpack.config.js. Looked in ${require.resolve.paths(devServerConfig.cypressConfig.projectRoot)}`);
22
+ throw Error(`Error loading @vue/cli-service/lib/Service or resolving WebpackConfig. Looked in ${require.resolve.paths(devServerConfig.cypressConfig.projectRoot)}`);
21
23
  }
22
24
  }
23
25
  exports.vueCliHandler = vueCliHandler;
package/dist/loader.js CHANGED
@@ -3,8 +3,8 @@
3
3
  /// <reference types="cypress" />
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  const tslib_1 = require("tslib");
6
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
7
- const path = (0, tslib_1.__importStar)(require("path"));
6
+ const debug_1 = tslib_1.__importDefault(require("debug"));
7
+ const path = tslib_1.__importStar(require("path"));
8
8
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:webpack');
9
9
  /**
10
10
  * @param {ComponentSpec} file spec to create import string from.
@@ -18,7 +18,9 @@ const makeImport = (file, filename, chunkName, projectRoot) => {
18
18
  return `"${filename}": {
19
19
  shouldLoad: () => document.location.pathname.includes("${encodeURI(file.absolute)}"),
20
20
  load: () => import("${file.absolute}" ${magicComments}),
21
- chunkName: "${chunkName}",
21
+ absolute: "${file.absolute.split(path.sep).join(path.posix.sep)}",
22
+ relative: "${file.relative.split(path.sep).join(path.posix.sep)}",
23
+ relativeUrl: "/__cypress/src/${chunkName}.js",
22
24
  }`;
23
25
  };
24
26
  /**
@@ -53,8 +55,8 @@ function loader() {
53
55
  ctx.cacheable(false);
54
56
  const { files, projectRoot, supportFile } = ctx._cypress;
55
57
  const supportFileAbsolutePath = supportFile ? JSON.stringify(path.resolve(projectRoot, supportFile)) : undefined;
56
- return `
57
- var loadSupportFile = ${supportFile ? `() => import(${supportFileAbsolutePath})` : `() => Promise.resolve()`}
58
+ const supportFileRelativePath = supportFile ? JSON.stringify(path.relative(projectRoot, supportFileAbsolutePath || '')) : undefined;
59
+ const result = `
58
60
  var allTheSpecs = ${buildSpecs(projectRoot, files)};
59
61
 
60
62
  var { init } = require(${JSON.stringify(require.resolve('./aut-runner'))})
@@ -62,12 +64,23 @@ function loader() {
62
64
  var scriptLoaders = Object.values(allTheSpecs).reduce(
63
65
  (accSpecLoaders, specLoader) => {
64
66
  if (specLoader.shouldLoad()) {
65
- accSpecLoaders.push(specLoader.load)
67
+ accSpecLoaders.push(specLoader)
66
68
  }
67
69
  return accSpecLoaders
68
- }, [loadSupportFile])
70
+ }, [])
71
+
72
+ if (${!!supportFile}) {
73
+ var supportFile = {
74
+ absolute: ${supportFileAbsolutePath},
75
+ relative: ${supportFileRelativePath},
76
+ relativeUrl: "/__cypress/src/cypress-support-file.js",
77
+ load: () => import(${supportFileAbsolutePath} /* webpackChunkName: "cypress-support-file" */),
78
+ }
79
+ scriptLoaders.unshift(supportFile)
80
+ }
69
81
 
70
82
  init(scriptLoaders)
71
83
  `;
84
+ return result;
72
85
  }
73
86
  exports.default = loader;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeDefaultWebpackConfig = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
6
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const debug_1 = tslib_1.__importDefault(require("debug"));
7
7
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:makeDefaultWebpackConfig');
8
8
  const OUTPUT_PATH = path_1.default.join(__dirname, 'dist');
9
9
  /**
@@ -13,23 +13,40 @@ const OUTPUT_PATH = path_1.default.join(__dirname, 'dist');
13
13
  function makeDefaultWebpackConfig(config) {
14
14
  const { module: _HtmlWebpackPlugin, packageJson: { version }, importPath, } = config.sourceWebpackModulesResult.htmlWebpackPlugin;
15
15
  const indexHtmlFile = config.devServerConfig.cypressConfig.indexHtmlFile;
16
+ const isRunMode = config.devServerConfig.cypressConfig.isTextTerminal;
16
17
  const HtmlWebpackPlugin = _HtmlWebpackPlugin;
17
18
  debug(`Using HtmlWebpackPlugin version ${version} from ${importPath}`);
19
+ const optimization = {};
20
+ if (config.sourceWebpackModulesResult.webpack.majorVersion === 5) {
21
+ optimization.emitOnErrors = true;
22
+ }
23
+ else {
24
+ optimization.noEmitOnErrors = false;
25
+ }
26
+ // To prevent files from being tree shaken by webpack, we set optimization.sideEffects: false ensuring that
27
+ // webpack does not recognize the sideEffects flag in the package.json and thus files are not unintentionally
28
+ // dropped during testing in production mode.
29
+ optimization.sideEffects = false;
18
30
  const finalConfig = {
19
31
  mode: 'development',
20
- optimization: {
21
- splitChunks: {
32
+ optimization: Object.assign(Object.assign({}, optimization), { splitChunks: {
22
33
  chunks: 'all',
23
- },
24
- },
34
+ } }),
25
35
  output: {
26
36
  filename: '[name].js',
27
37
  path: OUTPUT_PATH,
28
38
  },
29
39
  plugins: [
30
- new HtmlWebpackPlugin(Object.assign({ template: indexHtmlFile }, (config.devServerConfig.framework === 'angular' ? { scriptLoading: 'module' } : {}))),
40
+ new HtmlWebpackPlugin(Object.assign({ template: indexHtmlFile }, (config.devServerConfig.framework === 'angular' ? { scriptLoading: 'module', base: '/__cypress/src/' } : {}))),
31
41
  ],
42
+ devtool: 'inline-source-map',
32
43
  };
44
+ if (isRunMode) {
45
+ // Disable file watching when executing tests in `run` mode
46
+ finalConfig.watchOptions = {
47
+ ignored: '**/*',
48
+ };
49
+ }
33
50
  if (config.sourceWebpackModulesResult.webpackDevServer.majorVersion === 4) {
34
51
  return Object.assign(Object.assign({}, finalConfig), { devServer: {
35
52
  client: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeWebpackConfig = exports.CYPRESS_WEBPACK_ENTRYPOINT = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const debug_1 = require("debug");
6
- const path = (0, tslib_1.__importStar)(require("path"));
6
+ const path = tslib_1.__importStar(require("path"));
7
7
  const webpack_merge_1 = require("webpack-merge");
8
8
  const local_pkg_1 = require("local-pkg");
9
9
  const makeDefaultWebpackConfig_1 = require("./makeDefaultWebpackConfig");
@@ -65,7 +65,7 @@ function modifyWebpackConfigForCypress(webpackConfig) {
65
65
  * to pass to the sourced webpack function
66
66
  */
67
67
  async function makeWebpackConfig(config) {
68
- var _a, _b;
68
+ var _a, _b, _c;
69
69
  const { module: webpack } = config.sourceWebpackModulesResult.webpack;
70
70
  let userWebpackConfig = config.devServerConfig.webpackConfig;
71
71
  const frameworkWebpackConfig = config.frameworkConfig;
@@ -96,6 +96,9 @@ async function makeWebpackConfig(config) {
96
96
  }
97
97
  }
98
98
  }
99
+ userWebpackConfig = typeof userWebpackConfig === 'function'
100
+ ? await userWebpackConfig()
101
+ : userWebpackConfig;
99
102
  const userAndFrameworkWebpackConfig = modifyWebpackConfigForCypress((0, webpack_merge_1.merge)(frameworkWebpackConfig !== null && frameworkWebpackConfig !== void 0 ? frameworkWebpackConfig : {}, userWebpackConfig !== null && userWebpackConfig !== void 0 ? userWebpackConfig : {}));
100
103
  debug(`User passed in user and framework webpack config with values %o`, userAndFrameworkWebpackConfig);
101
104
  debug(`New webpack entries %o`, files);
@@ -122,6 +125,10 @@ async function makeWebpackConfig(config) {
122
125
  ],
123
126
  };
124
127
  const mergedConfig = (0, webpack_merge_1.merge)(userAndFrameworkWebpackConfig, (0, makeDefaultWebpackConfig_1.makeDefaultWebpackConfig)(config), dynamicWebpackConfig);
128
+ // Some frameworks (like Next.js) change this value which changes the path we would need to use to fetch our spec.
129
+ // (eg, http://localhost:xxxx/<dev-server-public-path>/static/chunks/spec-<x>.js). Deleting this key to normalize
130
+ // the spec URL to `*/spec-<x>.js` which we need to know up-front so we can fetch the sourcemaps.
131
+ (_c = mergedConfig.output) === null || _c === void 0 ? true : delete _c.chunkFilename;
125
132
  // Angular loads global styles and polyfills via script injection in the index.html
126
133
  if (framework === 'angular') {
127
134
  mergedConfig.entry = Object.assign(Object.assign({}, mergedConfig.entry || {}), { 'cypress-entry': exports.CYPRESS_WEBPACK_ENTRYPOINT });
@@ -4,10 +4,10 @@ exports.measureWebpackPerformance = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  /* eslint-disable no-restricted-syntax */
6
6
  /* eslint-disable no-console */
7
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
8
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
9
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
10
- const speed_measure_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("speed-measure-webpack-plugin"));
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
+ const fs_1 = tslib_1.__importDefault(require("fs"));
9
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
+ const speed_measure_webpack_plugin_1 = tslib_1.__importDefault(require("speed-measure-webpack-plugin"));
11
11
  /**
12
12
  * @internal
13
13
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/webpack-dev-server",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Launches Webpack Dev Server for Component Testing",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -37,7 +37,7 @@
37
37
  "proxyquire": "2.1.3",
38
38
  "sinon": "^13.0.1",
39
39
  "snap-shot-it": "^7.9.6",
40
- "ts-node": "^10.2.1",
40
+ "ts-node": "^10.9.1",
41
41
  "webpack": "npm:webpack@^5",
42
42
  "webpack-4": "npm:webpack@^4",
43
43
  "webpack-dev-server-3": "npm:webpack-dev-server@^3"
@@ -50,7 +50,7 @@
50
50
  "type": "git",
51
51
  "url": "https://github.com/cypress-io/cypress.git"
52
52
  },
53
- "homepage": "https://github.com/cypress-io/cypress/tree/master/npm/webpack-dev-server#readme",
53
+ "homepage": "https://github.com/cypress-io/cypress/tree/develop/npm/webpack-dev-server#readme",
54
54
  "bugs": "https://github.com/cypress-io/cypress/issues/new?template=1-bug-report.md",
55
55
  "publishConfig": {
56
56
  "access": "public"