@cypress/webpack-dev-server 5.6.2 → 6.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.
- package/dist/CypressCTWebpackPlugin.js +69 -65
- package/dist/createWebpackDevServer.js +16 -6
- package/dist/devServer.js +1 -1
- package/dist/helpers/angularHandler.js +52 -16
- package/dist/helpers/nextHandler.js +36 -69
- package/dist/helpers/sourceRelativeWebpackModules.d.ts +0 -1
- package/dist/helpers/sourceRelativeWebpackModules.js +7 -11
- package/dist/makeDefaultWebpackConfig.js +17 -6
- package/dist/makeWebpackConfig.js +10 -9
- package/package.json +3 -3
|
@@ -11,72 +11,14 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
13
|
class CypressCTWebpackPlugin {
|
|
14
|
+
files = [];
|
|
15
|
+
supportFile;
|
|
16
|
+
compilation = null;
|
|
17
|
+
webpack;
|
|
18
|
+
indexHtmlFile;
|
|
19
|
+
projectRoot;
|
|
20
|
+
devServerEvents;
|
|
14
21
|
constructor(options) {
|
|
15
|
-
this.files = [];
|
|
16
|
-
this.compilation = null;
|
|
17
|
-
this.addLoaderContext = (loaderContext, module) => {
|
|
18
|
-
loaderContext._cypress = {
|
|
19
|
-
files: this.files,
|
|
20
|
-
projectRoot: this.projectRoot,
|
|
21
|
-
supportFile: this.supportFile,
|
|
22
|
-
indexHtmlFile: this.indexHtmlFile,
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
this.beforeCompile = async (compilationParams, callback) => {
|
|
26
|
-
if (!this.compilation) {
|
|
27
|
-
callback();
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
// Ensure we don't try to load files that have been removed from the file system
|
|
31
|
-
// but have not yet been detected by the onSpecsChange handler
|
|
32
|
-
const foundFiles = (await Promise.all(this.files.map(async (file) => {
|
|
33
|
-
try {
|
|
34
|
-
const exists = await fs_extra_1.default.pathExists(file.absolute);
|
|
35
|
-
return exists ? file : null;
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
})));
|
|
41
|
-
this.files = foundFiles.filter((file) => file !== null);
|
|
42
|
-
callback();
|
|
43
|
-
};
|
|
44
|
-
/*
|
|
45
|
-
* `webpack --watch` watches the existing specs and their dependencies for changes.
|
|
46
|
-
* When new specs are created, we need to trigger a recompilation to add the new specs
|
|
47
|
-
* as dependencies. This hook informs webpack that `component-index.html` has been "updated on disk",
|
|
48
|
-
* causing a recompilation (and pulling the new specs in as dependencies). We use the component
|
|
49
|
-
* index file because we know that it will be there since the project is using Component Testing.
|
|
50
|
-
*
|
|
51
|
-
* We were using `browser.js` before to cause a recompilation but we ran into an
|
|
52
|
-
* issue with MacOS Ventura that will not allow us to write to files inside of our application bundle.
|
|
53
|
-
*
|
|
54
|
-
* See https://github.com/cypress-io/cypress/issues/24398
|
|
55
|
-
*/
|
|
56
|
-
this.onSpecsChange = async ({ specs, options }) => {
|
|
57
|
-
var _a;
|
|
58
|
-
if (!this.compilation || lodash_1.default.isEqual(specs, this.files)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this.files = specs;
|
|
62
|
-
const inputFileSystem = this.compilation.inputFileSystem;
|
|
63
|
-
// TODO: don't use a sync fs method here
|
|
64
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
65
|
-
const utimesSync = (_a = inputFileSystem.utimesSync) !== null && _a !== void 0 ? _a : fs_extra_1.default.utimesSync;
|
|
66
|
-
const indexHtmlFilePath = path_1.default.isAbsolute(this.indexHtmlFile) ? this.indexHtmlFile : path_1.default.join(this.projectRoot, this.indexHtmlFile);
|
|
67
|
-
utimesSync(indexHtmlFilePath, new Date(), new Date());
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* The webpack compiler generates a new `compilation` each time it compiles, so
|
|
71
|
-
* we have to apply hooks to it fresh each time
|
|
72
|
-
*
|
|
73
|
-
* @param compilation webpack 5 `Compilation`
|
|
74
|
-
*/
|
|
75
|
-
this.addCompilationHooks = (compilation) => {
|
|
76
|
-
this.compilation = compilation;
|
|
77
|
-
const loader = this.webpack.NormalModule.getCompilationHooks(compilation).loader;
|
|
78
|
-
loader.tap('CypressCTPlugin', this.addLoaderContext);
|
|
79
|
-
};
|
|
80
22
|
this.files = options.files;
|
|
81
23
|
this.supportFile = options.supportFile;
|
|
82
24
|
this.projectRoot = options.projectRoot;
|
|
@@ -84,6 +26,68 @@ class CypressCTWebpackPlugin {
|
|
|
84
26
|
this.webpack = options.webpack;
|
|
85
27
|
this.indexHtmlFile = options.indexHtmlFile;
|
|
86
28
|
}
|
|
29
|
+
addLoaderContext = (loaderContext, module) => {
|
|
30
|
+
loaderContext._cypress = {
|
|
31
|
+
files: this.files,
|
|
32
|
+
projectRoot: this.projectRoot,
|
|
33
|
+
supportFile: this.supportFile,
|
|
34
|
+
indexHtmlFile: this.indexHtmlFile,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
beforeCompile = async (compilationParams, callback) => {
|
|
38
|
+
if (!this.compilation) {
|
|
39
|
+
callback();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Ensure we don't try to load files that have been removed from the file system
|
|
43
|
+
// but have not yet been detected by the onSpecsChange handler
|
|
44
|
+
const foundFiles = (await Promise.all(this.files.map(async (file) => {
|
|
45
|
+
try {
|
|
46
|
+
const exists = await fs_extra_1.default.pathExists(file.absolute);
|
|
47
|
+
return exists ? file : null;
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
})));
|
|
53
|
+
this.files = foundFiles.filter((file) => file !== null);
|
|
54
|
+
callback();
|
|
55
|
+
};
|
|
56
|
+
/*
|
|
57
|
+
* `webpack --watch` watches the existing specs and their dependencies for changes.
|
|
58
|
+
* When new specs are created, we need to trigger a recompilation to add the new specs
|
|
59
|
+
* as dependencies. This hook informs webpack that `component-index.html` has been "updated on disk",
|
|
60
|
+
* causing a recompilation (and pulling the new specs in as dependencies). We use the component
|
|
61
|
+
* index file because we know that it will be there since the project is using Component Testing.
|
|
62
|
+
*
|
|
63
|
+
* We were using `browser.js` before to cause a recompilation but we ran into an
|
|
64
|
+
* issue with MacOS Ventura that will not allow us to write to files inside of our application bundle.
|
|
65
|
+
*
|
|
66
|
+
* See https://github.com/cypress-io/cypress/issues/24398
|
|
67
|
+
*/
|
|
68
|
+
onSpecsChange = async ({ specs, options }) => {
|
|
69
|
+
if (!this.compilation || lodash_1.default.isEqual(specs, this.files)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.files = specs;
|
|
73
|
+
const inputFileSystem = this.compilation.inputFileSystem;
|
|
74
|
+
// TODO: don't use a sync fs method here
|
|
75
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
76
|
+
const utimesSync = inputFileSystem.utimesSync ?? fs_extra_1.default.utimesSync;
|
|
77
|
+
const indexHtmlFilePath = path_1.default.isAbsolute(this.indexHtmlFile) ? this.indexHtmlFile : path_1.default.join(this.projectRoot, this.indexHtmlFile);
|
|
78
|
+
utimesSync(indexHtmlFilePath, new Date(), new Date());
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The webpack compiler generates a new `compilation` each time it compiles, so
|
|
82
|
+
* we have to apply hooks to it fresh each time
|
|
83
|
+
*
|
|
84
|
+
* @param compilation webpack 5 `Compilation`
|
|
85
|
+
*/
|
|
86
|
+
addCompilationHooks = (compilation) => {
|
|
87
|
+
this.compilation = compilation;
|
|
88
|
+
const loader = this.webpack.NormalModule.getCompilationHooks(compilation).loader;
|
|
89
|
+
loader.tap('CypressCTPlugin', this.addLoaderContext);
|
|
90
|
+
};
|
|
87
91
|
/**
|
|
88
92
|
* The plugin's entrypoint, called once by webpack when the compiler is initialized.
|
|
89
93
|
*/
|
|
@@ -18,16 +18,26 @@ async function createWebpackDevServer(config) {
|
|
|
18
18
|
}
|
|
19
19
|
exports.createWebpackDevServer = createWebpackDevServer;
|
|
20
20
|
function webpackDevServer5(config, compiler, finalWebpackConfig) {
|
|
21
|
-
var _a;
|
|
22
21
|
const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config;
|
|
23
22
|
const isOpenMode = !config.devServerConfig.cypressConfig.isTextTerminal;
|
|
24
23
|
const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module;
|
|
25
|
-
const webpackDevServerConfig =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const webpackDevServerConfig = {
|
|
25
|
+
host: '127.0.0.1',
|
|
26
|
+
port: 'auto',
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
...finalWebpackConfig?.devServer,
|
|
29
|
+
devMiddleware: {
|
|
30
|
+
publicPath: devServerPublicPathRoute,
|
|
31
|
+
stats: finalWebpackConfig.stats ?? 'minimal',
|
|
32
|
+
...((0, util_1.isWebpackBundleAnalyzerEnabled)() ? {
|
|
33
|
+
// the bundle needs to be written to disk in order to determine source map sizes
|
|
34
|
+
writeToDisk: true,
|
|
35
|
+
} : {}),
|
|
36
|
+
},
|
|
37
|
+
hot: false,
|
|
29
38
|
// Only enable file watching & reload when executing tests in `open` mode
|
|
30
|
-
liveReload: isOpenMode
|
|
39
|
+
liveReload: isOpenMode,
|
|
40
|
+
};
|
|
31
41
|
debug(WebpackDevServer);
|
|
32
42
|
debug(webpackDevServerConfig);
|
|
33
43
|
const server = new WebpackDevServer(webpackDevServerConfig, compiler);
|
package/dist/devServer.js
CHANGED
|
@@ -30,7 +30,7 @@ function devServer(devServerConfig) {
|
|
|
30
30
|
// Close is for unit testing only. We kill this child process which will handle the closing of the server
|
|
31
31
|
close: async (done) => {
|
|
32
32
|
debug('closing dev server');
|
|
33
|
-
result.server.stop().then(() => done
|
|
33
|
+
result.server.stop().then(() => done?.()).catch(done).finally(() => {
|
|
34
34
|
debug('closed dev server');
|
|
35
35
|
});
|
|
36
36
|
},
|
|
@@ -11,7 +11,6 @@ const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
|
11
11
|
const debugPrefix = 'cypress:webpack-dev-server:angularHandler';
|
|
12
12
|
const debug = (0, debug_1.default)(debugPrefix);
|
|
13
13
|
async function getProjectConfig(projectRoot) {
|
|
14
|
-
var _a;
|
|
15
14
|
const angularJson = await getAngularJson(projectRoot);
|
|
16
15
|
let { defaultProject } = angularJson;
|
|
17
16
|
if (!defaultProject) {
|
|
@@ -26,7 +25,10 @@ async function getProjectConfig(projectRoot) {
|
|
|
26
25
|
return {
|
|
27
26
|
root,
|
|
28
27
|
sourceRoot,
|
|
29
|
-
buildOptions:
|
|
28
|
+
buildOptions: {
|
|
29
|
+
...build.options,
|
|
30
|
+
...build.configurations?.development || {},
|
|
31
|
+
},
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
exports.getProjectConfig = getProjectConfig;
|
|
@@ -34,11 +36,50 @@ function getAngularBuildOptions(buildOptions, tsConfig) {
|
|
|
34
36
|
// Default options are derived from the @angular-devkit/build-angular browser builder, with some options from
|
|
35
37
|
// the serve builder thrown in for development.
|
|
36
38
|
// see: https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/build_angular/src/builders/browser/schema.json
|
|
37
|
-
return
|
|
39
|
+
return {
|
|
40
|
+
outputPath: 'dist/angular-app',
|
|
41
|
+
assets: [],
|
|
42
|
+
styles: [],
|
|
43
|
+
scripts: [],
|
|
44
|
+
fileReplacements: [],
|
|
45
|
+
inlineStyleLanguage: 'css',
|
|
46
|
+
stylePreprocessorOptions: { includePaths: [] },
|
|
47
|
+
resourcesOutputPath: undefined,
|
|
48
|
+
commonChunk: true,
|
|
49
|
+
baseHref: undefined,
|
|
50
|
+
deployUrl: undefined,
|
|
51
|
+
verbose: false,
|
|
52
|
+
progress: false,
|
|
53
|
+
i18nMissingTranslation: 'warning',
|
|
54
|
+
i18nDuplicateTranslation: 'warning',
|
|
55
|
+
localize: undefined,
|
|
56
|
+
watch: true,
|
|
57
|
+
poll: undefined,
|
|
58
|
+
deleteOutputPath: true,
|
|
59
|
+
preserveSymlinks: undefined,
|
|
60
|
+
showCircularDependencies: false,
|
|
61
|
+
subresourceIntegrity: false,
|
|
62
|
+
serviceWorker: false,
|
|
63
|
+
ngswConfigPath: undefined,
|
|
64
|
+
statsJson: false,
|
|
65
|
+
webWorkerTsConfig: undefined,
|
|
66
|
+
crossOrigin: 'none',
|
|
67
|
+
allowedCommonJsDependencies: [], // Add Cypress 'browser.js' entry point to ignore "CommonJS or AMD dependencies can cause optimization bailouts." warning
|
|
68
|
+
buildOptimizer: false,
|
|
69
|
+
optimization: false,
|
|
70
|
+
vendorChunk: true,
|
|
71
|
+
extractLicenses: false,
|
|
72
|
+
sourceMap: true,
|
|
73
|
+
namedChunks: true,
|
|
74
|
+
...buildOptions,
|
|
75
|
+
tsConfig,
|
|
76
|
+
aot: false,
|
|
77
|
+
outputHashing: 'none',
|
|
78
|
+
budgets: undefined,
|
|
79
|
+
};
|
|
38
80
|
}
|
|
39
81
|
exports.getAngularBuildOptions = getAngularBuildOptions;
|
|
40
82
|
async function generateTsConfig(devServerConfig, buildOptions) {
|
|
41
|
-
var _a;
|
|
42
83
|
const { cypressConfig } = devServerConfig;
|
|
43
84
|
const { projectRoot } = cypressConfig;
|
|
44
85
|
const { workspaceRoot = projectRoot } = buildOptions;
|
|
@@ -50,7 +91,7 @@ async function generateTsConfig(devServerConfig, buildOptions) {
|
|
|
50
91
|
}
|
|
51
92
|
if (buildOptions.polyfills) {
|
|
52
93
|
const polyfills = Array.isArray(buildOptions.polyfills)
|
|
53
|
-
? buildOptions.polyfills.filter((p) =>
|
|
94
|
+
? buildOptions.polyfills.filter((p) => devServerConfig.options?.projectConfig.sourceRoot && p.startsWith(devServerConfig.options?.projectConfig.sourceRoot))
|
|
54
95
|
: [buildOptions.polyfills];
|
|
55
96
|
includePaths.push(...polyfills.map((p) => getProjectFilePath(workspaceRoot, p)));
|
|
56
97
|
}
|
|
@@ -59,7 +100,7 @@ async function generateTsConfig(devServerConfig, buildOptions) {
|
|
|
59
100
|
];
|
|
60
101
|
const types = ['cypress'];
|
|
61
102
|
const tsConfigContent = JSON.stringify({
|
|
62
|
-
extends: getProjectFilePath(projectRoot,
|
|
103
|
+
extends: getProjectFilePath(projectRoot, buildOptions.tsConfig ?? 'tsconfig.json'),
|
|
63
104
|
compilerOptions: {
|
|
64
105
|
outDir: getProjectFilePath(projectRoot, 'out-tsc/cy'),
|
|
65
106
|
allowSyntheticDefaultImports: true,
|
|
@@ -154,11 +195,10 @@ function createFakeContext(projectRoot, defaultProjectConfig, logging) {
|
|
|
154
195
|
const toPosix = (filePath) => filePath.split(path.sep).join(path.posix.sep);
|
|
155
196
|
exports.toPosix = toPosix;
|
|
156
197
|
async function getAngularCliWebpackConfig(devServerConfig) {
|
|
157
|
-
var _a;
|
|
158
198
|
const { projectRoot } = devServerConfig.cypressConfig;
|
|
159
199
|
const { generateBrowserWebpackConfigFromContext, getCommonConfig, getStylesConfig, logging, } = await getAngularCliModules(projectRoot);
|
|
160
200
|
// normalize
|
|
161
|
-
const projectConfig =
|
|
201
|
+
const projectConfig = devServerConfig.options?.projectConfig || await getProjectConfig(projectRoot);
|
|
162
202
|
const tsConfig = await generateTsConfig(devServerConfig, projectConfig.buildOptions);
|
|
163
203
|
const buildOptions = getAngularBuildOptions(projectConfig.buildOptions, tsConfig);
|
|
164
204
|
const context = createFakeContext(projectConfig.buildOptions.workspaceRoot || projectRoot, projectConfig, logging);
|
|
@@ -171,14 +211,12 @@ async function getAngularCliWebpackConfig(devServerConfig) {
|
|
|
171
211
|
// imports in scss, sass, etc are correctly resolved.
|
|
172
212
|
// https://github.com/cypress-io/cypress/issues/24272
|
|
173
213
|
config.module.rules.forEach((rule) => {
|
|
174
|
-
|
|
175
|
-
(_a = rule.rules) === null || _a === void 0 ? void 0 : _a.forEach((ruleSet) => {
|
|
214
|
+
rule.rules?.forEach((ruleSet) => {
|
|
176
215
|
if (!Array.isArray(ruleSet.use)) {
|
|
177
216
|
return;
|
|
178
217
|
}
|
|
179
218
|
ruleSet.use.map((loader) => {
|
|
180
|
-
|
|
181
|
-
if (typeof loader !== 'object' || typeof loader.options !== 'object' || !((_a = loader.loader) === null || _a === void 0 ? void 0 : _a.includes('resolve-url-loader'))) {
|
|
219
|
+
if (typeof loader !== 'object' || typeof loader.options !== 'object' || !loader.loader?.includes('resolve-url-loader')) {
|
|
182
220
|
return;
|
|
183
221
|
}
|
|
184
222
|
const root = projectConfig.buildOptions.workspaceRoot || path.join(devServerConfig.cypressConfig.projectRoot, projectConfig.sourceRoot);
|
|
@@ -202,10 +240,8 @@ async function getAngularCliWebpackConfig(devServerConfig) {
|
|
|
202
240
|
return config;
|
|
203
241
|
}
|
|
204
242
|
function removeSourceMapPlugin(config) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var _a;
|
|
208
|
-
return ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.constructor) === null || _a === void 0 ? void 0 : _a.name) !== 'SourceMapDevToolPlugin';
|
|
243
|
+
config.plugins = config.plugins?.filter((plugin) => {
|
|
244
|
+
return plugin?.constructor?.name !== 'SourceMapDevToolPlugin';
|
|
209
245
|
});
|
|
210
246
|
}
|
|
211
247
|
async function angularHandler(devServerConfig) {
|
|
@@ -12,7 +12,7 @@ const debug = (0, debug_1.default)('cypress:webpack-dev-server-fresh:nextHandler
|
|
|
12
12
|
async function nextHandler(devServerConfig) {
|
|
13
13
|
const webpackConfig = await loadWebpackConfig(devServerConfig);
|
|
14
14
|
debug('resolved next.js webpack config %o', webpackConfig);
|
|
15
|
-
|
|
15
|
+
checkNodeVersion(webpackConfig, devServerConfig.cypressConfig);
|
|
16
16
|
watchEntryPoint(webpackConfig);
|
|
17
17
|
allowGlobalStylesImports(webpackConfig);
|
|
18
18
|
changeNextCachePath(webpackConfig);
|
|
@@ -26,7 +26,6 @@ exports.nextHandler = nextHandler;
|
|
|
26
26
|
* `getNextJsBaseWebpackConfig` acquires the webpackConfig dependent on the next.config.js
|
|
27
27
|
*/
|
|
28
28
|
async function getNextJsPackages(devServerConfig) {
|
|
29
|
-
var _a, _b, _c, _d, _e, _f;
|
|
30
29
|
const resolvePaths = { paths: [devServerConfig.cypressConfig.projectRoot] };
|
|
31
30
|
const packages = {};
|
|
32
31
|
// Starting with Next.js 16.0.3, we need to proactively install SWC bindings
|
|
@@ -38,42 +37,42 @@ async function getNextJsPackages(devServerConfig) {
|
|
|
38
37
|
}
|
|
39
38
|
catch (e) {
|
|
40
39
|
// installBindings doesn't exist in Next.js < 16.0.3, which is fine
|
|
41
|
-
debug('installBindings not available (Next.js < 16.0.3): %s',
|
|
40
|
+
debug('installBindings not available (Next.js < 16.0.3): %s', e.message ?? e);
|
|
42
41
|
}
|
|
43
42
|
try {
|
|
44
43
|
const loadConfigPath = require.resolve('next/dist/server/config', resolvePaths);
|
|
45
44
|
packages.loadConfig = require(loadConfigPath).default;
|
|
46
45
|
}
|
|
47
46
|
catch (e) {
|
|
48
|
-
throw new Error(`Failed to load "next/dist/server/config" with error: ${
|
|
47
|
+
throw new Error(`Failed to load "next/dist/server/config" with error: ${e.message ?? e}`);
|
|
49
48
|
}
|
|
50
49
|
try {
|
|
51
50
|
const getNextJsBaseWebpackConfigPath = require.resolve('next/dist/build/webpack-config', resolvePaths);
|
|
52
51
|
packages.getNextJsBaseWebpackConfig = require(getNextJsBaseWebpackConfigPath).default;
|
|
53
52
|
}
|
|
54
53
|
catch (e) {
|
|
55
|
-
throw new Error(`Failed to load "next/dist/build/webpack-config" with error: ${
|
|
54
|
+
throw new Error(`Failed to load "next/dist/build/webpack-config" with error: ${e.message ?? e}`);
|
|
56
55
|
}
|
|
57
56
|
try {
|
|
58
57
|
const loadJsConfigPath = require.resolve('next/dist/build/load-jsconfig', resolvePaths);
|
|
59
58
|
packages.nextLoadJsConfig = require(loadJsConfigPath).default;
|
|
60
59
|
}
|
|
61
60
|
catch (e) {
|
|
62
|
-
throw new Error(`Failed to load "next/dist/build/load-jsconfig" with error: ${
|
|
61
|
+
throw new Error(`Failed to load "next/dist/build/load-jsconfig" with error: ${e.message ?? e}`);
|
|
63
62
|
}
|
|
64
63
|
// Does not exist prior to Next 13.
|
|
65
64
|
try {
|
|
66
65
|
const getUtilsPath = require.resolve('next/dist/build/utils', resolvePaths);
|
|
67
|
-
packages.getSupportedBrowsers =
|
|
66
|
+
packages.getSupportedBrowsers = require(getUtilsPath).getSupportedBrowsers ?? (() => Promise.resolve([]));
|
|
68
67
|
}
|
|
69
68
|
catch (e) {
|
|
70
|
-
throw new Error(`Failed to load "next/dist/build/utils" with error: ${
|
|
69
|
+
throw new Error(`Failed to load "next/dist/build/utils" with error: ${e.message ?? e}`);
|
|
71
70
|
}
|
|
72
71
|
return packages;
|
|
73
72
|
}
|
|
74
73
|
/**
|
|
75
74
|
* Types for `getNextJsBaseWebpackConfig` based on version:
|
|
76
|
-
* -
|
|
75
|
+
* - v15.0.0 and v16.0.0
|
|
77
76
|
[
|
|
78
77
|
dir: string,
|
|
79
78
|
options: {
|
|
@@ -116,41 +115,37 @@ async function loadWebpackConfig(devServerConfig) {
|
|
|
116
115
|
const { loadConfig, getNextJsBaseWebpackConfig, nextLoadJsConfig, getSupportedBrowsers } = await getNextJsPackages(devServerConfig);
|
|
117
116
|
const nextConfig = await loadConfig('development', devServerConfig.cypressConfig.projectRoot);
|
|
118
117
|
const runWebpackSpan = getRunWebpackSpan(devServerConfig);
|
|
119
|
-
const
|
|
120
|
-
const jsConfigResult = await (nextLoadJsConfig === null || nextLoadJsConfig === void 0 ? void 0 : nextLoadJsConfig(devServerConfig.cypressConfig.projectRoot, nextConfig));
|
|
118
|
+
const jsConfigResult = await nextLoadJsConfig?.(devServerConfig.cypressConfig.projectRoot, nextConfig);
|
|
121
119
|
const supportedBrowsers = await getSupportedBrowsers(devServerConfig.cypressConfig.projectRoot, true, nextConfig);
|
|
122
|
-
const webpackConfig = await getNextJsBaseWebpackConfig(devServerConfig.cypressConfig.projectRoot,
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
const webpackConfig = await getNextJsBaseWebpackConfig(devServerConfig.cypressConfig.projectRoot, {
|
|
121
|
+
buildId: `@cypress/react-${Math.random().toString()}`,
|
|
122
|
+
config: nextConfig,
|
|
123
|
+
dev: true,
|
|
124
|
+
pagesDir: await findPagesDir(devServerConfig.cypressConfig.projectRoot),
|
|
125
|
+
entrypoints: {},
|
|
126
|
+
rewrites: { fallback: [], afterFiles: [], beforeFiles: [] },
|
|
127
|
+
...runWebpackSpan,
|
|
125
128
|
// Client webpack config for Next.js > 12.1.5
|
|
126
|
-
compilerType: 'client',
|
|
127
|
-
// Required for Next.js > 13
|
|
128
|
-
hasReactRoot: Boolean(reactVersion && reactVersion >= 18),
|
|
129
|
+
compilerType: 'client',
|
|
129
130
|
// Required for Next.js > 13.2.0 to respect TS/JS config
|
|
130
|
-
jsConfig: jsConfigResult.jsConfig,
|
|
131
|
+
jsConfig: jsConfigResult.jsConfig,
|
|
131
132
|
// Required for Next.js > 13.2.0 to respect tsconfig.compilerOptions.baseUrl
|
|
132
|
-
resolvedBaseUrl: jsConfigResult.resolvedBaseUrl,
|
|
133
|
+
resolvedBaseUrl: jsConfigResult.resolvedBaseUrl,
|
|
133
134
|
// Added in Next.js 13, passed via `...info`: https://github.com/vercel/next.js/pull/45637/files
|
|
134
|
-
supportedBrowsers
|
|
135
|
+
supportedBrowsers,
|
|
136
|
+
});
|
|
135
137
|
return webpackConfig;
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
138
|
-
*
|
|
139
|
-
* due to SWC certificate issues.
|
|
140
|
+
* Compilation will fail if user has `nodeVersion: "bundled"` set due to SWC certificate issues.
|
|
140
141
|
*/
|
|
141
|
-
function
|
|
142
|
-
var _a, _b;
|
|
143
|
-
const hasSWCLoader = (_b = (_a = webpackConfig.module) === null || _a === void 0 ? void 0 : _a.rules) === null || _b === void 0 ? void 0 : _b.some((rule) => {
|
|
144
|
-
var _a;
|
|
145
|
-
return typeof rule !== 'string' && ((_a = rule.oneOf) === null || _a === void 0 ? void 0 : _a.some((oneOf) => { var _a; return ((_a = oneOf.use) === null || _a === void 0 ? void 0 : _a.loader) === 'next-swc-loader'; }));
|
|
146
|
-
});
|
|
142
|
+
function checkNodeVersion(_webpackConfig, cypressConfig) {
|
|
147
143
|
// "resolvedNodePath" is only set when using the user's Node.js, which is required to compile Next.js with SWC optimizations
|
|
148
144
|
// If it is not set, they have either explicitly set "nodeVersion" to "bundled" or are are using Cypress < 9.0.0 where it was set to "bundled" by default
|
|
149
145
|
// @ts-expect-error nodeVersion has been removed as of 13.0.0 however this plugin can be used with many versions of cypress
|
|
150
|
-
if (
|
|
146
|
+
if (cypressConfig.nodeVersion === 'bundled') {
|
|
151
147
|
throw new Error(`Cypress cannot compile your Next.js application when "nodeVersion" is set to "bundled". Please remove this option from your Cypress configuration file.`);
|
|
152
148
|
}
|
|
153
|
-
return false;
|
|
154
149
|
}
|
|
155
150
|
const exists = async (file) => {
|
|
156
151
|
try {
|
|
@@ -178,24 +173,12 @@ async function findPagesDir(projectRoot) {
|
|
|
178
173
|
}
|
|
179
174
|
return projectRoot;
|
|
180
175
|
}
|
|
181
|
-
//
|
|
182
|
-
// 'next/dist/telemetry/trace/trace' only exists since v10.0.9
|
|
183
|
-
// and our peerDeps support back to v8 so try-catch this import
|
|
184
|
-
// Starting from 12.0 trace is now located in 'next/dist/trace/trace'
|
|
176
|
+
// 'next/dist/trace/trace' has been the trace location since Next.js 12.0
|
|
185
177
|
function getRunWebpackSpan(devServerConfig) {
|
|
186
|
-
let trace;
|
|
187
178
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return { runWebpackSpan: trace('cypress') };
|
|
192
|
-
}
|
|
193
|
-
catch (_) {
|
|
194
|
-
// @ts-ignore
|
|
195
|
-
const traceImportPath = require.resolve('next/dist/trace/trace', { paths: [devServerConfig.cypressConfig.projectRoot] });
|
|
196
|
-
trace = require(traceImportPath).trace;
|
|
197
|
-
return { runWebpackSpan: trace('cypress') };
|
|
198
|
-
}
|
|
179
|
+
const traceImportPath = require.resolve('next/dist/trace/trace', { paths: [devServerConfig.cypressConfig.projectRoot] });
|
|
180
|
+
const trace = require(traceImportPath).trace;
|
|
181
|
+
return { runWebpackSpan: trace('cypress') };
|
|
199
182
|
}
|
|
200
183
|
catch (_) {
|
|
201
184
|
return {};
|
|
@@ -239,19 +222,11 @@ function sourceNextWebpack(devServerConfig, framework) {
|
|
|
239
222
|
const packageJson = require(webpackJsonPath);
|
|
240
223
|
webpack.importPath = importPath;
|
|
241
224
|
// The package.json of "next/dist/compiled/webpack/package.json" has no version so we supply the version for later use
|
|
242
|
-
webpack.packageJson =
|
|
225
|
+
webpack.packageJson = { ...packageJson, version: '5' };
|
|
243
226
|
webpack.module = webpackModule.webpack;
|
|
244
227
|
webpack.majorVersion = (0, sourceRelativeWebpackModules_1.getMajorVersion)(webpack.packageJson, [5]);
|
|
245
228
|
debug('NextWebpack: Successfully loaded NextWebpack - %o', webpack);
|
|
246
229
|
module_1.default._load = function (request, parent, isMain) {
|
|
247
|
-
// Next with webpack@4 doesn't ship certain dependencies that HtmlWebpackPlugin requires, so we patch the resolution through to our bundled version
|
|
248
|
-
if ((request === 'webpack' || request.startsWith('webpack/')) && webpack.majorVersion === 4) {
|
|
249
|
-
const resolvePath = require.resolve(request, {
|
|
250
|
-
paths: [(0, sourceRelativeWebpackModules_1.cypressWebpackPath)(devServerConfig)],
|
|
251
|
-
});
|
|
252
|
-
debug('NextWebpack: Module._load for webpack@4 - %s', resolvePath);
|
|
253
|
-
return originalModuleLoad(resolvePath, parent, isMain);
|
|
254
|
-
}
|
|
255
230
|
if (request === 'webpack' || request.startsWith('webpack/')) {
|
|
256
231
|
const resolvePath = require.resolve(request, {
|
|
257
232
|
paths: [framework.importPath],
|
|
@@ -267,7 +242,10 @@ function sourceNextWebpack(devServerConfig, framework) {
|
|
|
267
242
|
// for changes to 'dist/browser.js' in order to detect new specs that have been added
|
|
268
243
|
function watchEntryPoint(webpackConfig) {
|
|
269
244
|
if (webpackConfig.watchOptions && Array.isArray(webpackConfig.watchOptions.ignored)) {
|
|
270
|
-
webpackConfig.watchOptions =
|
|
245
|
+
webpackConfig.watchOptions = {
|
|
246
|
+
...webpackConfig.watchOptions,
|
|
247
|
+
ignored: [...webpackConfig.watchOptions.ignored.filter((pattern) => !/node_modules/.test(pattern)), '**/node_modules/!(@cypress/webpack-dev-server/dist/browser.js)**'],
|
|
248
|
+
};
|
|
271
249
|
debug('found options next.js watchOptions.ignored %o', webpackConfig.watchOptions.ignored);
|
|
272
250
|
}
|
|
273
251
|
}
|
|
@@ -284,12 +262,11 @@ exports.allCssTests = [...globalCssRe, ...globalCssModulesRe];
|
|
|
284
262
|
// see: https://github.com/cypress-io/cypress/issues/22525
|
|
285
263
|
// Motivated by: https://github.com/bem/next-global-css
|
|
286
264
|
function allowGlobalStylesImports(webpackConfig) {
|
|
287
|
-
|
|
288
|
-
const rules = ((_a = webpackConfig.module) === null || _a === void 0 ? void 0 : _a.rules) || [];
|
|
265
|
+
const rules = webpackConfig.module?.rules || [];
|
|
289
266
|
for (const rule of rules) {
|
|
290
267
|
if (typeof rule !== 'string' && rule.oneOf) {
|
|
291
268
|
for (const oneOf of rule.oneOf) {
|
|
292
|
-
if (oneOf.test && exports.allCssTests.some((re) =>
|
|
269
|
+
if (oneOf.test && exports.allCssTests.some((re) => re.source === oneOf.test?.source)) {
|
|
293
270
|
delete oneOf.issuer;
|
|
294
271
|
}
|
|
295
272
|
}
|
|
@@ -305,13 +282,3 @@ function changeNextCachePath(webpackConfig) {
|
|
|
305
282
|
debug('Changing Next cache path from %s to %s', cacheDirectory, webpackConfig.cache.cacheDirectory);
|
|
306
283
|
}
|
|
307
284
|
}
|
|
308
|
-
function getReactVersion(projectRoot) {
|
|
309
|
-
try {
|
|
310
|
-
const reactPackageJsonPath = require.resolve('react/package.json', { paths: [projectRoot] });
|
|
311
|
-
const { version } = require(reactPackageJsonPath);
|
|
312
|
-
return Number(version.split('.')[0]);
|
|
313
|
-
}
|
|
314
|
-
catch (e) {
|
|
315
|
-
debug('Failed to source react with error: ', e);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
@@ -36,7 +36,6 @@ export interface SourceRelativeWebpackResult {
|
|
|
36
36
|
webpackDevServer: SourcedWebpackDevServer;
|
|
37
37
|
htmlWebpackPlugin: SourcedHtmlWebpackPlugin;
|
|
38
38
|
}
|
|
39
|
-
export declare const cypressWebpackPath: (config: WebpackDevServerConfig) => string;
|
|
40
39
|
export declare function sourceFramework(config: WebpackDevServerConfig): SourcedDependency | null;
|
|
41
40
|
export declare function sourceWebpackDevServer(config: WebpackDevServerConfig, webpackMajorVersion: 4 | 5, framework?: SourcedDependency | null): SourcedWebpackDevServer;
|
|
42
41
|
export declare function sourceHtmlWebpackPlugin(config: WebpackDevServerConfig, framework: SourcedDependency | null, webpack: SourcedWebpack): SourcedHtmlWebpackPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.restoreLoadHook = exports.getMajorVersion = exports.sourceDefaultWebpackDependencies = exports.sourceHtmlWebpackPlugin = exports.sourceWebpackDevServer = exports.sourceFramework =
|
|
3
|
+
exports.restoreLoadHook = exports.getMajorVersion = exports.sourceDefaultWebpackDependencies = exports.sourceHtmlWebpackPlugin = exports.sourceWebpackDevServer = exports.sourceFramework = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const module_1 = tslib_1.__importDefault(require("module"));
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -8,14 +8,13 @@ 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;
|
|
11
|
-
// We ship webpack
|
|
11
|
+
// We ship webpack as part of '@cypress/webpack-batteries-included-preprocessor'. The path to this module
|
|
12
12
|
// serves as our fallback.
|
|
13
13
|
const cypressWebpackPath = (config) => {
|
|
14
14
|
return require.resolve('@cypress/webpack-batteries-included-preprocessor', {
|
|
15
15
|
paths: [config.cypressConfig.cypressBinaryRoot],
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
|
-
exports.cypressWebpackPath = cypressWebpackPath;
|
|
19
18
|
const frameworkWebpackMapper = {
|
|
20
19
|
react: undefined,
|
|
21
20
|
vue: undefined,
|
|
@@ -60,8 +59,7 @@ exports.sourceFramework = sourceFramework;
|
|
|
60
59
|
// so that other packages that import webpack resolve to the version we found.
|
|
61
60
|
// If none is found, we fallback to the bundled version in '@cypress/webpack-batteries-included-preprocessor'.
|
|
62
61
|
function sourceWebpack(config, framework) {
|
|
63
|
-
|
|
64
|
-
const searchRoot = (_a = framework === null || framework === void 0 ? void 0 : framework.importPath) !== null && _a !== void 0 ? _a : config.cypressConfig.projectRoot;
|
|
62
|
+
const searchRoot = framework?.importPath ?? config.cypressConfig.projectRoot;
|
|
65
63
|
debug('Webpack: Attempting to source webpack from %s', searchRoot);
|
|
66
64
|
const webpack = {};
|
|
67
65
|
let webpackJsonPath;
|
|
@@ -77,7 +75,7 @@ function sourceWebpack(config, framework) {
|
|
|
77
75
|
}
|
|
78
76
|
debug('Webpack: Falling back to bundled version');
|
|
79
77
|
webpackJsonPath = require.resolve('webpack/package.json', {
|
|
80
|
-
paths: [
|
|
78
|
+
paths: [cypressWebpackPath(config)],
|
|
81
79
|
});
|
|
82
80
|
}
|
|
83
81
|
webpack.importPath = path_1.default.dirname(webpackJsonPath);
|
|
@@ -96,7 +94,7 @@ function sourceWebpack(config, framework) {
|
|
|
96
94
|
return originalModuleLoad(request, parent, isMain);
|
|
97
95
|
};
|
|
98
96
|
module_1.default._resolveFilename = function (request, parent, isMain, options) {
|
|
99
|
-
if (request === 'webpack' || request.startsWith('webpack/') && !
|
|
97
|
+
if (request === 'webpack' || request.startsWith('webpack/') && !options?.paths) {
|
|
100
98
|
const resolveFilename = originalModuleResolveFilename(request, parent, isMain, {
|
|
101
99
|
paths: [webpack.importPath],
|
|
102
100
|
});
|
|
@@ -110,8 +108,7 @@ function sourceWebpack(config, framework) {
|
|
|
110
108
|
// Source the webpack-dev-server module from the provided framework or projectRoot.
|
|
111
109
|
// If none is found, we fallback to the version bundled with this package.
|
|
112
110
|
function sourceWebpackDevServer(config, webpackMajorVersion, framework) {
|
|
113
|
-
|
|
114
|
-
const searchRoot = (_a = framework === null || framework === void 0 ? void 0 : framework.importPath) !== null && _a !== void 0 ? _a : config.cypressConfig.projectRoot;
|
|
111
|
+
const searchRoot = framework?.importPath ?? config.cypressConfig.projectRoot;
|
|
115
112
|
debug('WebpackDevServer: Attempting to source webpack-dev-server from %s', searchRoot);
|
|
116
113
|
const webpackDevServer = {};
|
|
117
114
|
let webpackDevServerJsonPath;
|
|
@@ -143,8 +140,7 @@ exports.sourceWebpackDevServer = sourceWebpackDevServer;
|
|
|
143
140
|
// We ship v5 of 'html-webpack-plugin' by aliasing the package with the major version (check package.json). This allows
|
|
144
141
|
// us to support newer major versions of 'html-webpack-plugin' easily'.
|
|
145
142
|
function sourceHtmlWebpackPlugin(config, framework, webpack) {
|
|
146
|
-
|
|
147
|
-
const searchRoot = (_a = framework === null || framework === void 0 ? void 0 : framework.importPath) !== null && _a !== void 0 ? _a : config.cypressConfig.projectRoot;
|
|
143
|
+
const searchRoot = framework?.importPath ?? config.cypressConfig.projectRoot;
|
|
148
144
|
debug('HtmlWebpackPlugin: Attempting to source html-webpack-plugin from %s', searchRoot);
|
|
149
145
|
const htmlWebpackPlugin = {};
|
|
150
146
|
let htmlWebpackPluginJsonPath;
|
|
@@ -13,7 +13,7 @@ const OsSeparatorRE = RegExp(`\\${path_1.default.sep}`, 'g');
|
|
|
13
13
|
const posixSeparator = '/';
|
|
14
14
|
function makeCypressWebpackConfig(config) {
|
|
15
15
|
const { devServerConfig: { cypressConfig: { justInTimeCompile, port, 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;
|
|
16
|
-
const webpackDevServerPort = port
|
|
16
|
+
const webpackDevServerPort = port ?? undefined;
|
|
17
17
|
debug(`Using HtmlWebpackPlugin version ${htmlWebpackPluginVersion} from ${htmlWebpackPluginImportPath}`);
|
|
18
18
|
const optimization = {
|
|
19
19
|
// To prevent files from being tree shaken by webpack, we set optimization.sideEffects: false ensuring that
|
|
@@ -45,7 +45,12 @@ function makeCypressWebpackConfig(config) {
|
|
|
45
45
|
publicPath,
|
|
46
46
|
},
|
|
47
47
|
plugins: [
|
|
48
|
-
new HtmlWebpackPlugin(
|
|
48
|
+
new HtmlWebpackPlugin({
|
|
49
|
+
template: indexHtmlFile ? path_1.default.isAbsolute(indexHtmlFile) ? indexHtmlFile : path_1.default.join(projectRoot, indexHtmlFile) : undefined,
|
|
50
|
+
// Angular generates all of it's scripts with <script type="module">. Live-reloading breaks without this option.
|
|
51
|
+
// We need to manually set the base here to `/__cypress/src/` so that static assets load with our proxy
|
|
52
|
+
...(framework === 'angular' ? { scriptLoading: 'module', base: '/__cypress/src/' } : {}),
|
|
53
|
+
}),
|
|
49
54
|
new CypressCTWebpackPlugin_1.CypressCTWebpackPlugin({
|
|
50
55
|
files,
|
|
51
56
|
projectRoot,
|
|
@@ -70,19 +75,25 @@ function makeCypressWebpackConfig(config) {
|
|
|
70
75
|
};
|
|
71
76
|
}
|
|
72
77
|
if (webpackDevServerMajorVersion === 4) {
|
|
73
|
-
return
|
|
78
|
+
return {
|
|
79
|
+
...finalConfig,
|
|
80
|
+
devServer: {
|
|
74
81
|
port: webpackDevServerPort,
|
|
75
82
|
client: {
|
|
76
83
|
overlay: false,
|
|
77
84
|
},
|
|
78
|
-
}
|
|
85
|
+
},
|
|
86
|
+
};
|
|
79
87
|
}
|
|
80
88
|
// default is webpack-dev-server v5
|
|
81
|
-
return
|
|
89
|
+
return {
|
|
90
|
+
...finalConfig,
|
|
91
|
+
devServer: {
|
|
82
92
|
port: webpackDevServerPort,
|
|
83
93
|
client: {
|
|
84
94
|
overlay: false,
|
|
85
95
|
},
|
|
86
|
-
}
|
|
96
|
+
},
|
|
97
|
+
};
|
|
87
98
|
}
|
|
88
99
|
exports.makeCypressWebpackConfig = makeCypressWebpackConfig;
|
|
@@ -38,11 +38,10 @@ exports.CYPRESS_WEBPACK_ENTRYPOINT = path.resolve(__dirname, 'browser.js');
|
|
|
38
38
|
* when used with cypress/webpack-dev-server.
|
|
39
39
|
*/
|
|
40
40
|
function modifyWebpackConfigForCypress(webpackConfig) {
|
|
41
|
-
|
|
42
|
-
if (webpackConfig === null || webpackConfig === void 0 ? void 0 : webpackConfig.plugins) {
|
|
41
|
+
if (webpackConfig?.plugins) {
|
|
43
42
|
webpackConfig.plugins = webpackConfig.plugins.filter((plugin) => !removeList.includes(plugin.constructor.name));
|
|
44
43
|
}
|
|
45
|
-
if (typeof
|
|
44
|
+
if (typeof webpackConfig?.module?.unsafeCache === 'function') {
|
|
46
45
|
const originalCachePredicate = webpackConfig.module.unsafeCache;
|
|
47
46
|
webpackConfig.module.unsafeCache = (module) => {
|
|
48
47
|
return originalCachePredicate(module) && !/[\\/]webpack-dev-server[\\/]dist[\\/]browser\.js/.test(module.resource);
|
|
@@ -64,7 +63,6 @@ async function getWebpackConfigFromProjectRoot(projectRoot) {
|
|
|
64
63
|
* to pass to the sourced webpack function
|
|
65
64
|
*/
|
|
66
65
|
async function makeWebpackConfig(config) {
|
|
67
|
-
var _a, _b, _c;
|
|
68
66
|
let userWebpackConfig = config.devServerConfig.webpackConfig;
|
|
69
67
|
const frameworkWebpackConfig = config.frameworkConfig;
|
|
70
68
|
const { cypressConfig: { projectRoot, supportFile, justInTimeCompile, }, framework, } = config.devServerConfig;
|
|
@@ -77,12 +75,12 @@ async function makeWebpackConfig(config) {
|
|
|
77
75
|
const sourcedConfig = await (0, local_pkg_1.importModule)(configFile);
|
|
78
76
|
debug('config contains %o', sourcedConfig);
|
|
79
77
|
if (sourcedConfig && typeof sourcedConfig === 'object') {
|
|
80
|
-
userWebpackConfig =
|
|
78
|
+
userWebpackConfig = sourcedConfig.default ?? sourcedConfig;
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
if (!userWebpackConfig) {
|
|
84
82
|
debug('could not find webpack.config!');
|
|
85
|
-
if (
|
|
83
|
+
if (config.devServerConfig?.onConfigNotFound) {
|
|
86
84
|
config.devServerConfig.onConfigNotFound('webpack', projectRoot, constants_1.configFiles);
|
|
87
85
|
// The config process will be killed from the parent, but we want to early exit so we don't get
|
|
88
86
|
// any additional errors related to not having a config
|
|
@@ -96,7 +94,7 @@ async function makeWebpackConfig(config) {
|
|
|
96
94
|
userWebpackConfig = typeof userWebpackConfig === 'function'
|
|
97
95
|
? await userWebpackConfig()
|
|
98
96
|
: userWebpackConfig;
|
|
99
|
-
const userAndFrameworkWebpackConfig = modifyWebpackConfigForCypress((0, webpack_merge_1.merge)(frameworkWebpackConfig
|
|
97
|
+
const userAndFrameworkWebpackConfig = modifyWebpackConfigForCypress((0, webpack_merge_1.merge)(frameworkWebpackConfig ?? {}, userWebpackConfig ?? {}));
|
|
100
98
|
debug(`User passed in user and framework webpack config with values %o`, userAndFrameworkWebpackConfig);
|
|
101
99
|
debug(`New webpack entries %o`, config.devServerConfig.specs);
|
|
102
100
|
debug(`Project root`, projectRoot);
|
|
@@ -105,10 +103,13 @@ async function makeWebpackConfig(config) {
|
|
|
105
103
|
// Some frameworks (like Next.js) change this value which changes the path we would need to use to fetch our spec.
|
|
106
104
|
// (eg, http://localhost:xxxx/<dev-server-public-path>/static/chunks/spec-<x>.js). Deleting this key to normalize
|
|
107
105
|
// the spec URL to `*/spec-<x>.js` which we need to know up-front so we can fetch the sourcemaps.
|
|
108
|
-
|
|
106
|
+
delete mergedConfig.output?.chunkFilename;
|
|
109
107
|
// Angular loads global styles and polyfills via script injection in the index.html
|
|
110
108
|
if (framework === 'angular') {
|
|
111
|
-
mergedConfig.entry =
|
|
109
|
+
mergedConfig.entry = {
|
|
110
|
+
...mergedConfig.entry || {},
|
|
111
|
+
'cypress-entry': exports.CYPRESS_WEBPACK_ENTRYPOINT,
|
|
112
|
+
};
|
|
112
113
|
}
|
|
113
114
|
else {
|
|
114
115
|
mergedConfig.entry = exports.CYPRESS_WEBPACK_ENTRYPOINT;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cypress/webpack-dev-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Launches Webpack Dev Server for Component Testing",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
"local-pkg": "0.4.1",
|
|
24
24
|
"semver": "^7.7.3",
|
|
25
25
|
"tslib": "^2.3.1",
|
|
26
|
-
"tsx": "^4.
|
|
26
|
+
"tsx": "^4.23.12",
|
|
27
27
|
"webpack-bundle-analyzer": "4.10.2",
|
|
28
28
|
"webpack-dev-server": "^5.1.0",
|
|
29
29
|
"webpack-merge": "^5.4.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "
|
|
32
|
+
"@types/node": "24.10.1",
|
|
33
33
|
"@types/webpack-bundle-analyzer": "4.7.0",
|
|
34
34
|
"cross-env": "7.0.3",
|
|
35
35
|
"dedent": "^0.7.0",
|