@cypress/webpack-dev-server 2.5.0 → 3.0.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.
- package/dist/devServer.js +1 -1
- package/dist/dynamic-import.d.ts +2 -0
- package/dist/dynamic-import.js +15 -0
- package/dist/helpers/angularHandler.js +6 -7
- package/dist/makeDefaultWebpackConfig.d.ts +3 -1
- package/dist/makeDefaultWebpackConfig.js +35 -23
- package/dist/makeWebpackConfig.d.ts +2 -1
- package/dist/makeWebpackConfig.js +9 -42
- package/package.json +1 -1
- package/dist/measureWebpackPerformance.d.ts +0 -1
- package/dist/measureWebpackPerformance.js +0 -58
package/dist/devServer.js
CHANGED
|
@@ -80,7 +80,7 @@ async function getPreset(devServerConfig) {
|
|
|
80
80
|
case undefined:
|
|
81
81
|
return { sourceWebpackModulesResult: (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig) };
|
|
82
82
|
default:
|
|
83
|
-
throw new Error(`Unexpected framework ${devServerConfig.framework}, please visit https://
|
|
83
|
+
throw new Error(`Unexpected framework ${devServerConfig.framework}, please visit https://on.cypress.io/component-framework-configuration to see a list of supported frameworks`);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|
|
@@ -5,9 +5,8 @@ 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
|
|
8
|
+
const dynamic_import_1 = require("../dynamic-import");
|
|
9
9
|
const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
|
|
10
|
-
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
11
10
|
async function getProjectConfig(projectRoot) {
|
|
12
11
|
var _a;
|
|
13
12
|
const angularJson = await getAngularJson(projectRoot);
|
|
@@ -74,15 +73,15 @@ async function getTempDir() {
|
|
|
74
73
|
}
|
|
75
74
|
exports.getTempDir = getTempDir;
|
|
76
75
|
async function getAngularCliModules(projectRoot) {
|
|
77
|
-
const
|
|
76
|
+
const angularCLiModules = [
|
|
78
77
|
'@angular-devkit/build-angular/src/utils/webpack-browser-config.js',
|
|
79
78
|
'@angular-devkit/build-angular/src/webpack/configs/common.js',
|
|
80
79
|
'@angular-devkit/build-angular/src/webpack/configs/styles.js',
|
|
81
|
-
]
|
|
80
|
+
];
|
|
81
|
+
const [{ generateBrowserWebpackConfigFromContext }, { getCommonConfig }, { getStylesConfig },] = await Promise.all(angularCLiModules.map((dep) => {
|
|
82
82
|
try {
|
|
83
83
|
const depPath = require.resolve(dep, { paths: [projectRoot] });
|
|
84
|
-
|
|
85
|
-
return dynamicImport(url);
|
|
84
|
+
return (0, dynamic_import_1.dynamicAbsoluteImport)(depPath);
|
|
86
85
|
}
|
|
87
86
|
catch (e) {
|
|
88
87
|
throw new Error(`Could not resolve "${dep}". Do you have "@angular-devkit/build-angular" installed?`);
|
|
@@ -96,7 +95,7 @@ async function getAngularCliModules(projectRoot) {
|
|
|
96
95
|
}
|
|
97
96
|
exports.getAngularCliModules = getAngularCliModules;
|
|
98
97
|
async function getAngularJson(projectRoot) {
|
|
99
|
-
const { findUp } = await dynamicImport('find-up');
|
|
98
|
+
const { findUp } = await (0, dynamic_import_1.dynamicImport)('find-up');
|
|
100
99
|
const angularJsonPath = await findUp('angular.json', { cwd: projectRoot });
|
|
101
100
|
if (!angularJsonPath) {
|
|
102
101
|
throw new Error(`Could not find angular.json. Looked in ${projectRoot} and up.`);
|
|
@@ -1,43 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.makeCypressWebpackConfig = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
6
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
7
|
+
const CypressCTWebpackPlugin_1 = require("./CypressCTWebpackPlugin");
|
|
7
8
|
const debug = (0, debug_1.default)('cypress:webpack-dev-server:makeDefaultWebpackConfig');
|
|
8
9
|
const OUTPUT_PATH = path_1.default.join(__dirname, 'dist');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
const OsSeparatorRE = RegExp(`\\${path_1.default.sep}`, 'g');
|
|
11
|
+
const posixSeparator = '/';
|
|
12
|
+
function makeCypressWebpackConfig(config) {
|
|
13
|
+
const { devServerConfig: { cypressConfig: { projectRoot, devServerPublicPathRoute, supportFile, indexHtmlFile, isTextTerminal: isRunMode, }, specs: files, devServerEvents, framework, }, sourceWebpackModulesResult: { webpack: { module: webpack, majorVersion: webpackMajorVersion, }, htmlWebpackPlugin: { module: HtmlWebpackPlugin, majorVersion: htmlWebpackPluginVersion, importPath: htmlWebpackPluginImportPath, }, webpackDevServer: { majorVersion: webpackDevServerMajorVersion, }, }, } = config;
|
|
14
|
+
debug(`Using HtmlWebpackPlugin version ${htmlWebpackPluginVersion} from ${htmlWebpackPluginImportPath}`);
|
|
15
|
+
const optimization = {
|
|
16
|
+
// To prevent files from being tree shaken by webpack, we set optimization.sideEffects: false ensuring that
|
|
17
|
+
// webpack does not recognize the sideEffects flag in the package.json and thus files are not unintentionally
|
|
18
|
+
// dropped during testing in production mode.
|
|
19
|
+
sideEffects: false,
|
|
20
|
+
splitChunks: {
|
|
21
|
+
chunks: 'all',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
if (webpackMajorVersion === 5) {
|
|
21
25
|
optimization.emitOnErrors = true;
|
|
22
26
|
}
|
|
23
27
|
else {
|
|
24
28
|
optimization.noEmitOnErrors = false;
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const publicPath = (path_1.default.sep === posixSeparator)
|
|
31
|
+
? path_1.default.join(devServerPublicPathRoute, posixSeparator)
|
|
32
|
+
// The second line here replaces backslashes on windows with posix compatible slash
|
|
33
|
+
// See https://github.com/cypress-io/cypress/issues/16097
|
|
34
|
+
: path_1.default.join(devServerPublicPathRoute, posixSeparator)
|
|
35
|
+
.replace(OsSeparatorRE, posixSeparator);
|
|
30
36
|
const finalConfig = {
|
|
31
37
|
mode: 'development',
|
|
32
|
-
optimization
|
|
33
|
-
chunks: 'all',
|
|
34
|
-
} }),
|
|
38
|
+
optimization,
|
|
35
39
|
output: {
|
|
36
40
|
filename: '[name].js',
|
|
37
41
|
path: OUTPUT_PATH,
|
|
42
|
+
publicPath,
|
|
38
43
|
},
|
|
39
44
|
plugins: [
|
|
40
|
-
new HtmlWebpackPlugin(Object.assign({ template: indexHtmlFile }, (
|
|
45
|
+
new HtmlWebpackPlugin(Object.assign({ template: indexHtmlFile }, (framework === 'angular' ? { scriptLoading: 'module', base: '/__cypress/src/' } : {}))),
|
|
46
|
+
new CypressCTWebpackPlugin_1.CypressCTWebpackPlugin({
|
|
47
|
+
files,
|
|
48
|
+
projectRoot,
|
|
49
|
+
devServerEvents,
|
|
50
|
+
supportFile,
|
|
51
|
+
webpack,
|
|
52
|
+
}),
|
|
41
53
|
],
|
|
42
54
|
devtool: 'inline-source-map',
|
|
43
55
|
};
|
|
@@ -47,7 +59,7 @@ function makeDefaultWebpackConfig(config) {
|
|
|
47
59
|
ignored: '**/*',
|
|
48
60
|
};
|
|
49
61
|
}
|
|
50
|
-
if (
|
|
62
|
+
if (webpackDevServerMajorVersion === 4) {
|
|
51
63
|
return Object.assign(Object.assign({}, finalConfig), { devServer: {
|
|
52
64
|
client: {
|
|
53
65
|
overlay: false,
|
|
@@ -59,4 +71,4 @@ function makeDefaultWebpackConfig(config) {
|
|
|
59
71
|
overlay: false,
|
|
60
72
|
} });
|
|
61
73
|
}
|
|
62
|
-
exports.
|
|
74
|
+
exports.makeCypressWebpackConfig = makeCypressWebpackConfig;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { Configuration } from 'webpack';
|
|
1
2
|
import type { CreateFinalWebpackConfig } from './createWebpackDevServer';
|
|
2
3
|
export declare const CYPRESS_WEBPACK_ENTRYPOINT: string;
|
|
3
4
|
/**
|
|
4
5
|
* Creates a webpack 4/5 compatible webpack "configuration"
|
|
5
6
|
* to pass to the sourced webpack function
|
|
6
7
|
*/
|
|
7
|
-
export declare function makeWebpackConfig(config: CreateFinalWebpackConfig): Promise<
|
|
8
|
+
export declare function makeWebpackConfig(config: CreateFinalWebpackConfig): Promise<Configuration>;
|
|
@@ -7,8 +7,8 @@ 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");
|
|
10
|
-
const CypressCTWebpackPlugin_1 = require("./CypressCTWebpackPlugin");
|
|
11
10
|
const constants_1 = require("./constants");
|
|
11
|
+
const dynamic_import_1 = require("./dynamic-import");
|
|
12
12
|
const debug = (0, debug_1.debug)('cypress:webpack-dev-server:makeWebpackConfig');
|
|
13
13
|
const removeList = [
|
|
14
14
|
// We provide a webpack-html-plugin config pinned to a specific version (4.x)
|
|
@@ -33,8 +33,6 @@ const removeList = [
|
|
|
33
33
|
if (process.platform === 'linux') {
|
|
34
34
|
removeList.push('CaseSensitivePathsPlugin');
|
|
35
35
|
}
|
|
36
|
-
const OsSeparatorRE = RegExp(`\\${path.sep}`, 'g');
|
|
37
|
-
const posixSeparator = '/';
|
|
38
36
|
exports.CYPRESS_WEBPACK_ENTRYPOINT = path.resolve(__dirname, 'browser.js');
|
|
39
37
|
/**
|
|
40
38
|
* Removes and/or modifies certain plugins known to conflict
|
|
@@ -43,14 +41,7 @@ exports.CYPRESS_WEBPACK_ENTRYPOINT = path.resolve(__dirname, 'browser.js');
|
|
|
43
41
|
function modifyWebpackConfigForCypress(webpackConfig) {
|
|
44
42
|
var _a;
|
|
45
43
|
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
|
-
});
|
|
44
|
+
webpackConfig.plugins = webpackConfig.plugins.filter((plugin) => !removeList.includes(plugin.constructor.name));
|
|
54
45
|
}
|
|
55
46
|
if (typeof ((_a = webpackConfig === null || webpackConfig === void 0 ? void 0 : webpackConfig.module) === null || _a === void 0 ? void 0 : _a.unsafeCache) === 'function') {
|
|
56
47
|
const originalCachePredicate = webpackConfig.module.unsafeCache;
|
|
@@ -60,21 +51,22 @@ function modifyWebpackConfigForCypress(webpackConfig) {
|
|
|
60
51
|
}
|
|
61
52
|
return webpackConfig;
|
|
62
53
|
}
|
|
54
|
+
async function getWebpackConfigFromProjectRoot(projectRoot) {
|
|
55
|
+
const { findUp } = await (0, dynamic_import_1.dynamicImport)('find-up');
|
|
56
|
+
return await findUp(constants_1.configFiles, { cwd: projectRoot });
|
|
57
|
+
}
|
|
63
58
|
/**
|
|
64
59
|
* Creates a webpack 4/5 compatible webpack "configuration"
|
|
65
60
|
* to pass to the sourced webpack function
|
|
66
61
|
*/
|
|
67
62
|
async function makeWebpackConfig(config) {
|
|
68
63
|
var _a, _b, _c;
|
|
69
|
-
const { module: webpack } = config.sourceWebpackModulesResult.webpack;
|
|
70
64
|
let userWebpackConfig = config.devServerConfig.webpackConfig;
|
|
71
65
|
const frameworkWebpackConfig = config.frameworkConfig;
|
|
72
|
-
const { cypressConfig: { projectRoot,
|
|
73
|
-
let configFile = undefined;
|
|
66
|
+
const { cypressConfig: { projectRoot, supportFile, }, specs: files, framework, } = config.devServerConfig;
|
|
74
67
|
if (!userWebpackConfig && !frameworkWebpackConfig) {
|
|
75
68
|
debug('Not user or framework webpack config received. Trying to automatically source it');
|
|
76
|
-
const
|
|
77
|
-
configFile = await findUp(constants_1.configFiles, { cwd: projectRoot });
|
|
69
|
+
const configFile = await getWebpackConfigFromProjectRoot(projectRoot);
|
|
78
70
|
if (configFile) {
|
|
79
71
|
debug('found webpack config %s', configFile);
|
|
80
72
|
const sourcedConfig = await (0, local_pkg_1.importModule)(configFile);
|
|
@@ -104,27 +96,7 @@ async function makeWebpackConfig(config) {
|
|
|
104
96
|
debug(`New webpack entries %o`, files);
|
|
105
97
|
debug(`Project root`, projectRoot);
|
|
106
98
|
debug(`Support file`, supportFile);
|
|
107
|
-
const
|
|
108
|
-
? path.join(devServerPublicPathRoute, posixSeparator)
|
|
109
|
-
// The second line here replaces backslashes on windows with posix compatible slash
|
|
110
|
-
// See https://github.com/cypress-io/cypress/issues/16097
|
|
111
|
-
: path.join(devServerPublicPathRoute, posixSeparator)
|
|
112
|
-
.replace(OsSeparatorRE, posixSeparator);
|
|
113
|
-
const dynamicWebpackConfig = {
|
|
114
|
-
output: {
|
|
115
|
-
publicPath,
|
|
116
|
-
},
|
|
117
|
-
plugins: [
|
|
118
|
-
new CypressCTWebpackPlugin_1.CypressCTWebpackPlugin({
|
|
119
|
-
files,
|
|
120
|
-
projectRoot,
|
|
121
|
-
devServerEvents,
|
|
122
|
-
supportFile,
|
|
123
|
-
webpack,
|
|
124
|
-
}),
|
|
125
|
-
],
|
|
126
|
-
};
|
|
127
|
-
const mergedConfig = (0, webpack_merge_1.merge)(userAndFrameworkWebpackConfig, (0, makeDefaultWebpackConfig_1.makeDefaultWebpackConfig)(config), dynamicWebpackConfig);
|
|
99
|
+
const mergedConfig = (0, webpack_merge_1.merge)(userAndFrameworkWebpackConfig, (0, makeDefaultWebpackConfig_1.makeCypressWebpackConfig)(config));
|
|
128
100
|
// Some frameworks (like Next.js) change this value which changes the path we would need to use to fetch our spec.
|
|
129
101
|
// (eg, http://localhost:xxxx/<dev-server-public-path>/static/chunks/spec-<x>.js). Deleting this key to normalize
|
|
130
102
|
// the spec URL to `*/spec-<x>.js` which we need to know up-front so we can fetch the sourcemaps.
|
|
@@ -137,11 +109,6 @@ async function makeWebpackConfig(config) {
|
|
|
137
109
|
mergedConfig.entry = exports.CYPRESS_WEBPACK_ENTRYPOINT;
|
|
138
110
|
}
|
|
139
111
|
debug('Merged webpack config %o', mergedConfig);
|
|
140
|
-
if (process.env.WEBPACK_PERF_MEASURE) {
|
|
141
|
-
// only for debugging
|
|
142
|
-
const { measureWebpackPerformance } = require('./measureWebpackPerformance');
|
|
143
|
-
return measureWebpackPerformance(mergedConfig);
|
|
144
|
-
}
|
|
145
112
|
return mergedConfig;
|
|
146
113
|
}
|
|
147
114
|
exports.makeWebpackConfig = makeWebpackConfig;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.measureWebpackPerformance = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
/* eslint-disable no-restricted-syntax */
|
|
6
|
-
/* eslint-disable no-console */
|
|
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
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
function measureWebpackPerformance(webpackConfig) {
|
|
15
|
-
if (!process.env.WEBPACK_PERF_MEASURE) {
|
|
16
|
-
throw new Error('Performance monitoring is possible only with WEBPACK_PERF_MEASURE env variable set');
|
|
17
|
-
}
|
|
18
|
-
const compareWithPrevious = process.env.WEBPACK_PERF_MEASURE_COMPARE;
|
|
19
|
-
function percentageDiff(a, b) {
|
|
20
|
-
return ((a - b) / a) * 100;
|
|
21
|
-
}
|
|
22
|
-
const compareOutput = (output) => {
|
|
23
|
-
const statsPath = path_1.default.resolve(__dirname, '..', '__perf-stats', `${compareWithPrevious}.json`);
|
|
24
|
-
if (!fs_1.default.existsSync(statsPath) || process.env.WEBPACK_PERF_MEASURE_UPDATE) {
|
|
25
|
-
return fs_1.default.writeFileSync(statsPath, output, { encoding: 'utf-8' });
|
|
26
|
-
}
|
|
27
|
-
const newStats = JSON.parse(output);
|
|
28
|
-
const oldStats = require(statsPath);
|
|
29
|
-
const totalPercentageDiff = percentageDiff(oldStats.misc.compileTime, newStats.misc.compileTime);
|
|
30
|
-
const printResult = (result) => {
|
|
31
|
-
const delimiter = new Array(process.stdout.columns).fill('═').join('');
|
|
32
|
-
console.log(delimiter);
|
|
33
|
-
console.log(`${chalk_1.default.bold('WEBPACK_PERF_MEASURE')}`);
|
|
34
|
-
console.log(`Before: ${chalk_1.default.bold(oldStats.misc.compileTime / 1000)}s`);
|
|
35
|
-
console.log(`After: ${chalk_1.default.bold(newStats.misc.compileTime / 1000)}s`);
|
|
36
|
-
console.log(result);
|
|
37
|
-
console.log(delimiter);
|
|
38
|
-
};
|
|
39
|
-
if (Math.abs(totalPercentageDiff) < 5) {
|
|
40
|
-
printResult('No sufficient build time difference');
|
|
41
|
-
}
|
|
42
|
-
else if (totalPercentageDiff > 0) {
|
|
43
|
-
printResult(`New build is faster: ${chalk_1.default.green.bold(`+${Math.round(totalPercentageDiff)}%`)}`);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
printResult(`New build is slower: ${chalk_1.default.red.bold(`${Math.round(totalPercentageDiff)}%`)}`);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const smp = compareWithPrevious ?
|
|
50
|
-
new speed_measure_webpack_plugin_1.default({
|
|
51
|
-
outputFormat: 'json',
|
|
52
|
-
outputTarget: compareOutput,
|
|
53
|
-
})
|
|
54
|
-
: new speed_measure_webpack_plugin_1.default();
|
|
55
|
-
// @ts-expect-error
|
|
56
|
-
return smp.wrap(webpackConfig);
|
|
57
|
-
}
|
|
58
|
-
exports.measureWebpackPerformance = measureWebpackPerformance;
|