@cypress/webpack-dev-server 1.8.4 → 2.0.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +47 -81
  3. package/dist/CypressCTWebpackPlugin.d.ts +15 -0
  4. package/dist/CypressCTWebpackPlugin.js +103 -0
  5. package/dist/aut-runner.js +1 -0
  6. package/dist/constants.d.ts +1 -0
  7. package/dist/constants.js +9 -0
  8. package/dist/createWebpackDevServer.d.ts +26 -0
  9. package/dist/createWebpackDevServer.js +49 -0
  10. package/dist/devServer.d.ts +35 -0
  11. package/dist/devServer.js +103 -0
  12. package/dist/helpers/createReactAppHandler.d.ts +8 -0
  13. package/dist/helpers/createReactAppHandler.js +300 -0
  14. package/dist/helpers/nextHandler.d.ts +2 -0
  15. package/dist/helpers/nextHandler.js +197 -0
  16. package/dist/helpers/nuxtHandler.d.ts +2 -0
  17. package/dist/helpers/nuxtHandler.js +27 -0
  18. package/dist/helpers/sourceRelativeWebpackModules.d.ts +46 -0
  19. package/dist/helpers/sourceRelativeWebpackModules.js +197 -0
  20. package/dist/helpers/vueCliHandler.d.ts +2 -0
  21. package/dist/helpers/vueCliHandler.js +23 -0
  22. package/dist/index.d.ts +3 -15
  23. package/dist/index.js +4 -63
  24. package/dist/loader.d.ts +1 -3
  25. package/dist/loader.js +8 -28
  26. package/dist/makeDefaultWebpackConfig.d.ts +1 -0
  27. package/dist/makeDefaultWebpackConfig.js +48 -0
  28. package/dist/makeWebpackConfig.d.ts +6 -16
  29. package/dist/makeWebpackConfig.js +120 -93
  30. package/dist/measureWebpackPerformance.d.ts +1 -2
  31. package/dist/measureWebpackPerformance.js +10 -8
  32. package/package.json +34 -26
  33. package/dist/plugin.d.ts +0 -45
  34. package/dist/plugin.js +0 -84
  35. package/dist/startServer.d.ts +0 -13
  36. package/dist/startServer.js +0 -75
  37. package/dist/webpack.config.d.ts +0 -2
  38. package/dist/webpack.config.js +0 -24
  39. package/dist/webpackDevServerFacts.d.ts +0 -6
  40. package/dist/webpackDevServerFacts.js +0 -19
  41. package/index-template.html +0 -12
@@ -1,107 +1,134 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
2
  Object.defineProperty(exports, "__esModule", { value: true });
34
3
  exports.makeWebpackConfig = void 0;
4
+ const tslib_1 = require("tslib");
35
5
  const debug_1 = require("debug");
36
- const path = __importStar(require("path"));
6
+ const path = (0, tslib_1.__importStar)(require("path"));
37
7
  const webpack_merge_1 = require("webpack-merge");
38
- const webpack_config_1 = __importDefault(require("./webpack.config"));
39
- const plugin_1 = __importDefault(require("./plugin"));
8
+ const local_pkg_1 = require("local-pkg");
9
+ const makeDefaultWebpackConfig_1 = require("./makeDefaultWebpackConfig");
10
+ const CypressCTWebpackPlugin_1 = require("./CypressCTWebpackPlugin");
11
+ const constants_1 = require("./constants");
40
12
  const debug = (0, debug_1.debug)('cypress:webpack-dev-server:makeWebpackConfig');
41
- const removeList = ['HtmlWebpackPlugin', 'PreloadPlugin', 'HtmlPwaPlugin'];
13
+ const removeList = [
14
+ // We provide a webpack-html-plugin config pinned to a specific version (4.x)
15
+ // that we have tested and are confident works with all common configurations.
16
+ // https://github.com/cypress-io/cypress/issues/15865
17
+ 'HtmlWebpackPlugin',
18
+ // This plugin is an optimization for HtmlWebpackPlugin for use in
19
+ // production environments, not relevant for testing.
20
+ 'PreloadPlugin',
21
+ // Another optimization not relevant in a testing environment.
22
+ 'HtmlPwaPlugin',
23
+ // We already reload when webpack recompiles (via listeners on
24
+ // devServerEvents). Removing this plugin can prevent double-refreshes
25
+ // in some setups.
26
+ 'HotModuleReplacementPlugin',
27
+ ];
28
+ // CaseSensitivePathsPlugin checks the paths of every loaded module to enforce
29
+ // case sensitivity - this helps developers on mac catch issues that will bite
30
+ // them later, but on linux the OS already does this by default. The plugin
31
+ // is somewhat slow, accounting for ~15% of compile time on a couple of CRA
32
+ // based projects (where it's included by default) tested.
33
+ if (process.platform === 'linux') {
34
+ removeList.push('CaseSensitivePathsPlugin');
35
+ }
42
36
  const OsSeparatorRE = RegExp(`\\${path.sep}`, 'g');
43
37
  const posixSeparator = '/';
44
- function makeWebpackConfig(userWebpackConfig, options) {
38
+ const CYPRESS_WEBPACK_ENTRYPOINT = path.resolve(__dirname, 'browser.js');
39
+ /**
40
+ * Removes and/or modifies certain plugins known to conflict
41
+ * when used with cypress/webpack-dev-server.
42
+ */
43
+ function modifyWebpackConfigForCypress(webpackConfig) {
45
44
  var _a;
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const { projectRoot, devServerPublicPathRoute, files, supportFile, devServerEvents, template } = options;
48
- debug(`User passed in webpack config with values %o`, userWebpackConfig);
49
- debug(`New webpack entries %o`, files);
50
- debug(`Project root`, projectRoot);
51
- debug(`Support file`, supportFile);
52
- const entry = path.resolve(__dirname, './browser.js');
53
- const publicPath = (path.sep === posixSeparator)
54
- ? path.join(devServerPublicPathRoute, posixSeparator)
55
- // The second line here replaces backslashes on windows with posix compatible slash
56
- // See https://github.com/cypress-io/cypress/issues/16097
57
- : path.join(devServerPublicPathRoute, posixSeparator)
58
- .replace(OsSeparatorRE, posixSeparator);
59
- const dynamicWebpackConfig = {
60
- output: {
61
- publicPath,
62
- },
63
- plugins: [
64
- new plugin_1.default({
65
- files,
66
- projectRoot,
67
- devServerEvents,
68
- supportFile,
69
- }),
70
- ],
45
+ if (webpackConfig === null || webpackConfig === void 0 ? void 0 : webpackConfig.plugins) {
46
+ webpackConfig.plugins = webpackConfig.plugins.filter((plugin) => {
47
+ if (removeList.includes(plugin.constructor.name)) {
48
+ /* eslint-disable no-console */
49
+ console.warn(`[@cypress/webpack-dev-server]: removing ${plugin.constructor.name} from configuration.`);
50
+ return false;
51
+ }
52
+ return true;
53
+ });
54
+ }
55
+ if (typeof ((_a = webpackConfig === null || webpackConfig === void 0 ? void 0 : webpackConfig.module) === null || _a === void 0 ? void 0 : _a.unsafeCache) === 'function') {
56
+ const originalCachePredicate = webpackConfig.module.unsafeCache;
57
+ webpackConfig.module.unsafeCache = (module) => {
58
+ return originalCachePredicate(module) && !/[\\/]webpack-dev-server[\\/]dist[\\/]browser\.js/.test(module.resource);
71
59
  };
72
- // certain plugins conflict with HtmlWebpackPlugin and cause
73
- // problems for some setups.
74
- // most of these are application optimizations that are not relevant in a
75
- // testing environment.
76
- // remove those plugins to ensure a smooth configuration experience.
77
- // we provide a webpack-html-plugin config pinned to a specific version (4.x)
78
- // that we have tested and are confident works with all common configurations.
79
- // https://github.com/cypress-io/cypress/issues/15865
80
- if (userWebpackConfig === null || userWebpackConfig === void 0 ? void 0 : userWebpackConfig.plugins) {
81
- userWebpackConfig.plugins = userWebpackConfig.plugins.filter((plugin) => {
82
- if (removeList.includes(plugin.constructor.name)) {
83
- /* eslint-disable no-console */
84
- console.warn(`[@cypress/webpack-dev-server]: removing ${plugin.constructor.name} from configuration.`);
85
- return false;
86
- }
87
- return true;
88
- });
89
- }
90
- if (typeof ((_a = userWebpackConfig === null || userWebpackConfig === void 0 ? void 0 : userWebpackConfig.module) === null || _a === void 0 ? void 0 : _a.unsafeCache) === 'function') {
91
- const originalCachePredicate = userWebpackConfig.module.unsafeCache;
92
- userWebpackConfig.module.unsafeCache = (module) => {
93
- return originalCachePredicate(module) && !/[\\/]webpack-dev-server[\\/]dist[\\/]browser\.js/.test(module.resource);
94
- };
60
+ }
61
+ return webpackConfig;
62
+ }
63
+ /**
64
+ * Creates a webpack 4/5 compatible webpack "configuration"
65
+ * to pass to the sourced webpack function
66
+ */
67
+ async function makeWebpackConfig(config) {
68
+ var _a, _b;
69
+ const { module: webpack } = config.sourceWebpackModulesResult.webpack;
70
+ let userWebpackConfig = config.devServerConfig.webpackConfig;
71
+ const frameworkWebpackConfig = config.frameworkConfig;
72
+ const { cypressConfig: { projectRoot, devServerPublicPathRoute, supportFile, }, specs: files, devServerEvents, } = config.devServerConfig;
73
+ let configFile = undefined;
74
+ if (!userWebpackConfig && !frameworkWebpackConfig) {
75
+ debug('Not user or framework webpack config received. Trying to automatically source it');
76
+ const { default: findUp } = await (0, local_pkg_1.importModule)('find-up');
77
+ configFile = await findUp(constants_1.configFiles, { cwd: projectRoot });
78
+ if (configFile) {
79
+ debug('found webpack config %s', configFile);
80
+ const sourcedConfig = await (0, local_pkg_1.importModule)(configFile);
81
+ debug('config contains %o', sourcedConfig);
82
+ if (sourcedConfig && typeof sourcedConfig === 'object') {
83
+ userWebpackConfig = (_a = sourcedConfig.default) !== null && _a !== void 0 ? _a : sourcedConfig;
84
+ }
95
85
  }
96
- const mergedConfig = (0, webpack_merge_1.merge)(userWebpackConfig, (0, webpack_config_1.default)(template), dynamicWebpackConfig);
97
- mergedConfig.entry = entry;
98
- debug('Merged webpack config %o', mergedConfig);
99
- if (process.env.WEBPACK_PERF_MEASURE) {
100
- // only for debugging
101
- const { measureWebpackPerformance } = require('./measureWebpackPerformance');
102
- return measureWebpackPerformance(mergedConfig);
86
+ if (!userWebpackConfig) {
87
+ debug('could not find webpack.config!');
88
+ if ((_b = config.devServerConfig) === null || _b === void 0 ? void 0 : _b.onConfigNotFound) {
89
+ config.devServerConfig.onConfigNotFound('webpack', projectRoot, constants_1.configFiles);
90
+ // The config process will be killed from the parent, but we want to early exit so we don't get
91
+ // any additional errors related to not having a config
92
+ process.exit(0);
93
+ }
94
+ else {
95
+ throw new Error(`Your Cypress devServer config is missing a required webpackConfig property, since we could not automatically detect one.\nPlease add one to your ${config.devServerConfig.cypressConfig.configFile}`);
96
+ }
103
97
  }
104
- return mergedConfig;
105
- });
98
+ }
99
+ const userAndFrameworkWebpackConfig = modifyWebpackConfigForCypress((0, webpack_merge_1.merge)(frameworkWebpackConfig !== null && frameworkWebpackConfig !== void 0 ? frameworkWebpackConfig : {}, userWebpackConfig !== null && userWebpackConfig !== void 0 ? userWebpackConfig : {}));
100
+ debug(`User passed in user and framework webpack config with values %o`, userAndFrameworkWebpackConfig);
101
+ debug(`New webpack entries %o`, files);
102
+ debug(`Project root`, projectRoot);
103
+ debug(`Support file`, supportFile);
104
+ const publicPath = (path.sep === posixSeparator)
105
+ ? path.join(devServerPublicPathRoute, posixSeparator)
106
+ // The second line here replaces backslashes on windows with posix compatible slash
107
+ // See https://github.com/cypress-io/cypress/issues/16097
108
+ : path.join(devServerPublicPathRoute, posixSeparator)
109
+ .replace(OsSeparatorRE, posixSeparator);
110
+ const dynamicWebpackConfig = {
111
+ output: {
112
+ publicPath,
113
+ },
114
+ plugins: [
115
+ new CypressCTWebpackPlugin_1.CypressCTWebpackPlugin({
116
+ files,
117
+ projectRoot,
118
+ devServerEvents,
119
+ supportFile,
120
+ webpack,
121
+ }),
122
+ ],
123
+ };
124
+ const mergedConfig = (0, webpack_merge_1.merge)(userAndFrameworkWebpackConfig, (0, makeDefaultWebpackConfig_1.makeDefaultWebpackConfig)(config), dynamicWebpackConfig);
125
+ mergedConfig.entry = CYPRESS_WEBPACK_ENTRYPOINT;
126
+ debug('Merged webpack config %o', mergedConfig);
127
+ if (process.env.WEBPACK_PERF_MEASURE) {
128
+ // only for debugging
129
+ const { measureWebpackPerformance } = require('./measureWebpackPerformance');
130
+ return measureWebpackPerformance(mergedConfig);
131
+ }
132
+ return mergedConfig;
106
133
  }
107
134
  exports.makeWebpackConfig = makeWebpackConfig;
@@ -1,2 +1 @@
1
- import type { Configuration } from 'webpack';
2
- export declare function measureWebpackPerformance(webpackConfig: Configuration): Configuration;
1
+ export {};
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.measureWebpackPerformance = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const chalk_1 = __importDefault(require("chalk"));
10
- // @ts-ignore
11
- const speed_measure_webpack_plugin_1 = __importDefault(require("speed-measure-webpack-plugin"));
4
+ const tslib_1 = require("tslib");
5
+ /* eslint-disable no-console */
6
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
7
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
8
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
9
+ const speed_measure_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("speed-measure-webpack-plugin"));
10
+ /**
11
+ * @internal
12
+ */
12
13
  function measureWebpackPerformance(webpackConfig) {
13
14
  if (!process.env.WEBPACK_PERF_MEASURE) {
14
15
  throw new Error('Performance monitoring is possible only with WEBPACK_PERF_MEASURE env variable set');
@@ -50,6 +51,7 @@ function measureWebpackPerformance(webpackConfig) {
50
51
  outputTarget: compareOutput,
51
52
  })
52
53
  : new speed_measure_webpack_plugin_1.default();
54
+ // @ts-expect-error
53
55
  return smp.wrap(webpackConfig);
54
56
  }
55
57
  exports.measureWebpackPerformance = measureWebpackPerformance;
package/package.json CHANGED
@@ -1,41 +1,49 @@
1
1
  {
2
2
  "name": "@cypress/webpack-dev-server",
3
- "version": "1.8.4",
3
+ "version": "2.0.0",
4
4
  "description": "Launches Webpack Dev Server for Component Testing",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "build": "tsc",
8
- "build-prod": "tsc",
9
- "test": "node ./test-deps.js",
10
- "test-all": "tsc && mocha -r @packages/ts/register test/**/*.spec.ts test/*.spec.ts --exit",
11
- "watch": "tsc -w"
7
+ "prebuild": "rimraf dist",
8
+ "build": "tsc || echo 'built, with type errors'",
9
+ "build-prod": "yarn build",
10
+ "check-ts": "tsc --noEmit",
11
+ "dev": "tsc --watch",
12
+ "clean": "rimraf dist",
13
+ "cypress:run": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome",
14
+ "cypress:run-cypress-in-cypress": "cross-env HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
15
+ "cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
16
+ "test": "yarn test-unit",
17
+ "test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js"
12
18
  },
13
19
  "dependencies": {
14
- "debug": "^4.3.2",
15
- "lodash": "^4.17.21",
16
- "semver": "^7.3.4",
20
+ "find-up": "6.3.0",
21
+ "fs-extra": "9.1.0",
22
+ "html-webpack-plugin-4": "npm:html-webpack-plugin@^4",
23
+ "html-webpack-plugin-5": "npm:html-webpack-plugin@^5",
24
+ "local-pkg": "0.4.1",
25
+ "speed-measure-webpack-plugin": "1.4.2",
26
+ "tslib": "^2.3.1",
27
+ "webpack-dev-server": "^4.7.4",
17
28
  "webpack-merge": "^5.4.0"
18
29
  },
19
30
  "devDependencies": {
20
- "@types/webpack": ">=4",
21
- "@types/webpack-dev-server": "^4.0.0",
22
- "chai": "^4.2.0",
23
- "html-webpack-plugin": "4.x",
24
- "mocha": "^8.1.3",
25
- "snap-shot-it": "7.9.3",
26
- "speed-measure-webpack-plugin": "1.4.2",
27
- "typescript": "^4.2.3",
28
- "webpack": "^4.44.2",
29
- "webpack-dev-server": "^4.0.0"
30
- },
31
- "peerDependencies": {
32
- "html-webpack-plugin": ">=4",
33
- "webpack": ">=4",
34
- "webpack-dev-server": ">=3.0.0"
31
+ "@types/proxyquire": "^1.3.28",
32
+ "@types/speed-measure-webpack-plugin": "^1.3.4",
33
+ "@types/webpack-dev-server-3": "npm:@types/webpack-dev-server@^3",
34
+ "chai": "^4.3.6",
35
+ "dedent": "^0.7.0",
36
+ "mocha": "^9.2.2",
37
+ "proxyquire": "2.1.3",
38
+ "sinon": "^13.0.1",
39
+ "snap-shot-it": "^7.9.6",
40
+ "ts-node": "^10.2.1",
41
+ "webpack": "npm:webpack@^5",
42
+ "webpack-4": "npm:webpack@^4",
43
+ "webpack-dev-server-3": "npm:webpack-dev-server@^3"
35
44
  },
36
45
  "files": [
37
- "dist",
38
- "index-template.html"
46
+ "dist"
39
47
  ],
40
48
  "license": "MIT",
41
49
  "repository": {
package/dist/plugin.d.ts DELETED
@@ -1,45 +0,0 @@
1
- /// <reference types="cypress" />
2
- /// <reference types="node" />
3
- import { Compiler } from 'webpack';
4
- import { EventEmitter } from 'events';
5
- import { PathLike } from 'fs';
6
- import type { Compilation } from 'webpack';
7
- declare type UtimesSync = (path: PathLike, atime: string | number | Date, mtime: string | number | Date) => void;
8
- export interface CypressCTOptionsPluginOptions {
9
- files: Cypress.Cypress['spec'][];
10
- projectRoot: string;
11
- supportFile: string;
12
- devServerEvents?: EventEmitter;
13
- }
14
- export declare type CypressCTOptionsPluginOptionsWithEmitter = CypressCTOptionsPluginOptions & {
15
- devServerEvents: EventEmitter;
16
- };
17
- export interface CypressCTWebpackContext {
18
- _cypress: CypressCTOptionsPluginOptions;
19
- }
20
- export declare type Webpack45Compilation = Compilation & {
21
- inputFileSystem: {
22
- fileSystem: {
23
- utimesSync: UtimesSync;
24
- };
25
- };
26
- };
27
- export declare const normalizeError: (error: Error | string) => string;
28
- export default class CypressCTOptionsPlugin {
29
- private files;
30
- private supportFile;
31
- private errorEmitted;
32
- private readonly projectRoot;
33
- private readonly devServerEvents;
34
- constructor(options: CypressCTOptionsPluginOptionsWithEmitter);
35
- private pluginFunc;
36
- private setupCustomHMR;
37
- /**
38
- *
39
- * @param compilation webpack 4 `compilation.Compilation`, webpack 5
40
- * `Compilation`
41
- */
42
- private plugin;
43
- apply(compiler: Compiler): void;
44
- }
45
- export {};
package/dist/plugin.js DELETED
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeError = void 0;
7
- const webpack_1 = __importDefault(require("webpack"));
8
- const lodash_1 = __importDefault(require("lodash"));
9
- const semver_1 = __importDefault(require("semver"));
10
- const fs_1 = __importDefault(require("fs"));
11
- const path_1 = __importDefault(require("path"));
12
- const normalizeError = (error) => {
13
- return typeof error === 'string' ? error : error.message;
14
- };
15
- exports.normalizeError = normalizeError;
16
- class CypressCTOptionsPlugin {
17
- constructor(options) {
18
- this.files = [];
19
- this.errorEmitted = false;
20
- this.pluginFunc = (context) => {
21
- context._cypress = {
22
- files: this.files,
23
- projectRoot: this.projectRoot,
24
- supportFile: this.supportFile,
25
- };
26
- };
27
- this.setupCustomHMR = (compiler) => {
28
- compiler.hooks.afterCompile.tap('CypressCTOptionsPlugin', (compilation) => {
29
- const stats = compilation.getStats();
30
- if (stats.hasErrors()) {
31
- this.errorEmitted = true;
32
- // webpack 4: string[]
33
- // webpack 5: Error[]
34
- const errors = stats.toJson().errors;
35
- if (!errors || !errors.length) {
36
- return;
37
- }
38
- this.devServerEvents.emit('dev-server:compile:error', (0, exports.normalizeError)(errors[0]));
39
- }
40
- else if (this.errorEmitted) {
41
- // compilation succeed but assets haven't emitted to the output yet
42
- this.devServerEvents.emit('dev-server:compile:error', null);
43
- }
44
- });
45
- compiler.hooks.afterEmit.tap('CypressCTOptionsPlugin', (compilation) => {
46
- if (!compilation.getStats().hasErrors()) {
47
- this.devServerEvents.emit('dev-server:compile:success');
48
- }
49
- });
50
- };
51
- /**
52
- *
53
- * @param compilation webpack 4 `compilation.Compilation`, webpack 5
54
- * `Compilation`
55
- */
56
- this.plugin = (compilation) => {
57
- this.devServerEvents.on('dev-server:specs:changed', (specs) => {
58
- if (lodash_1.default.isEqual(specs, this.files))
59
- return;
60
- this.files = specs;
61
- const inputFileSystem = compilation.inputFileSystem;
62
- const utimesSync = semver_1.default.gt('4.0.0', webpack_1.default.version) ? inputFileSystem.fileSystem.utimesSync : fs_1.default.utimesSync;
63
- utimesSync(path_1.default.resolve(__dirname, 'browser.js'), new Date(), new Date());
64
- });
65
- // Webpack 5
66
- /* istanbul ignore next */
67
- if ('NormalModule' in webpack_1.default) {
68
- webpack_1.default.NormalModule.getCompilationHooks(compilation).loader.tap('CypressCTOptionsPlugin', (context) => this.pluginFunc(context));
69
- return;
70
- }
71
- // Webpack 4
72
- compilation.hooks.normalModuleLoader.tap('CypressCTOptionsPlugin', (context) => this.pluginFunc(context));
73
- };
74
- this.files = options.files;
75
- this.supportFile = options.supportFile;
76
- this.projectRoot = options.projectRoot;
77
- this.devServerEvents = options.devServerEvents;
78
- }
79
- apply(compiler) {
80
- this.setupCustomHMR(compiler);
81
- compiler.hooks.compilation.tap('CypressCTOptionsPlugin', (compilation) => this.plugin(compilation));
82
- }
83
- }
84
- exports.default = CypressCTOptionsPlugin;
@@ -1,13 +0,0 @@
1
- /// <reference types="cypress" />
2
- import webpack from 'webpack';
3
- import WebpackDevServer from 'webpack-dev-server';
4
- import { UserWebpackDevServerOptions } from './makeWebpackConfig';
5
- export interface StartDevServer extends UserWebpackDevServerOptions {
6
- options: Cypress.DevServerConfig;
7
- webpackConfig?: WebpackConfigurationWithDevServer;
8
- template?: string;
9
- }
10
- export interface WebpackConfigurationWithDevServer extends webpack.Configuration {
11
- devServer?: WebpackDevServer.Configuration;
12
- }
13
- export declare function start({ webpackConfig: userWebpackConfig, template, options, ...userOptions }: StartDevServer, exitProcess?: (code?: number | undefined) => never): Promise<WebpackDevServer>;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.start = void 0;
27
- const debug_1 = __importDefault(require("debug"));
28
- const webpack_1 = __importDefault(require("webpack"));
29
- const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
30
- const makeWebpackConfig_1 = require("./makeWebpackConfig");
31
- const webpackDevServerFacts_1 = require("./webpackDevServerFacts");
32
- const debug = (0, debug_1.default)('cypress:webpack-dev-server:start');
33
- function start(_a, exitProcess = process.exit) {
34
- var { webpackConfig: userWebpackConfig, template, options } = _a, userOptions = __rest(_a, ["webpackConfig", "template", "options"]);
35
- return __awaiter(this, void 0, void 0, function* () {
36
- if (!userWebpackConfig) {
37
- debug('User did not pass in any webpack configuration');
38
- }
39
- const { projectRoot, devServerPublicPathRoute, isTextTerminal } = options.config;
40
- const webpackConfig = yield (0, makeWebpackConfig_1.makeWebpackConfig)(userWebpackConfig || {}, Object.assign({ files: options.specs, template,
41
- projectRoot,
42
- devServerPublicPathRoute, devServerEvents: options.devServerEvents, supportFile: options.config.supportFile, isOpenMode: !isTextTerminal }, userOptions));
43
- debug('compiling webpack');
44
- const compiler = (0, webpack_1.default)(webpackConfig);
45
- // When compiling in run mode
46
- // Stop the clock early, no need to run all the tests on a failed build
47
- if (isTextTerminal) {
48
- compiler.hooks.done.tap('cyCustomErrorBuild', function (stats) {
49
- if (stats.hasErrors()) {
50
- exitProcess(1);
51
- }
52
- });
53
- }
54
- debug('starting webpack dev server');
55
- let webpackDevServerConfig = Object.assign(Object.assign({}, ((userWebpackConfig === null || userWebpackConfig === void 0 ? void 0 : userWebpackConfig.devServer) || {})), { hot: false });
56
- if (webpackDevServerFacts_1.webpackDevServerFacts.isV3()) {
57
- debug('using webpack-dev-server v3');
58
- webpackDevServerConfig = Object.assign(Object.assign({}, webpackDevServerConfig), {
59
- // @ts-ignore ignore webpack-dev-server v3 type errors
60
- inline: false, publicPath: devServerPublicPathRoute, noInfo: false });
61
- // @ts-ignore ignore webpack-dev-server v3 type errors
62
- return new webpack_dev_server_1.default(compiler, webpackDevServerConfig);
63
- }
64
- if (webpackDevServerFacts_1.webpackDevServerFacts.isV4()) {
65
- debug('using webpack-dev-server v4');
66
- webpackDevServerConfig = Object.assign(Object.assign({ host: 'localhost', port: 'auto' }, userWebpackConfig === null || userWebpackConfig === void 0 ? void 0 : userWebpackConfig.devServer), { devMiddleware: {
67
- publicPath: devServerPublicPathRoute,
68
- }, hot: false });
69
- // @ts-ignore Webpack types are clashing between Webpack and WebpackDevServer
70
- return new webpack_dev_server_1.default(webpackDevServerConfig, compiler);
71
- }
72
- throw webpackDevServerFacts_1.webpackDevServerFacts.unsupported();
73
- });
74
- }
75
- exports.start = start;
@@ -1,2 +0,0 @@
1
- declare function _exports(template?: string | undefined): import('webpack').Configuration;
2
- export = _exports;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- const path = require('path');
3
- const HtmlWebpackPlugin = require('html-webpack-plugin');
4
- /**
5
- * @param {string} [template] - base template to use
6
- * @returns {import('webpack').Configuration}
7
- */
8
- module.exports = function makeDefaultConfig(template) {
9
- return {
10
- mode: 'development',
11
- optimization: {
12
- splitChunks: {
13
- chunks: 'all',
14
- },
15
- },
16
- output: {
17
- filename: '[name].js',
18
- path: path.resolve(__dirname, 'dist'),
19
- },
20
- plugins: [new HtmlWebpackPlugin({
21
- template: template || path.resolve(__dirname, '..', 'index-template.html'),
22
- })],
23
- };
24
- };
@@ -1,6 +0,0 @@
1
- export declare const webpackDevServerFacts: {
2
- version: string;
3
- isV3(version?: string): boolean;
4
- isV4(version?: string): boolean;
5
- unsupported(): Error;
6
- };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.webpackDevServerFacts = void 0;
7
- const package_json_1 = __importDefault(require("webpack-dev-server/package.json"));
8
- exports.webpackDevServerFacts = {
9
- version: package_json_1.default.version,
10
- isV3(version = package_json_1.default.version) {
11
- return /^3\./.test(version);
12
- },
13
- isV4(version = package_json_1.default.version) {
14
- return /^4\./.test(version);
15
- },
16
- unsupported() {
17
- return Error(`@cypress/webpack-dev-server only supports webpack-dev-server v3 and v4. Found: ${exports.webpackDevServerFacts.version}.`);
18
- },
19
- };
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
- <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
- <title>Components App</title>
8
- </head>
9
- <body>
10
- <div id="__cy_root"></div>
11
- </body>
12
- </html>