@cypress/vite-dev-server 3.2.0 → 3.3.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/plugins/cypress.js
CHANGED
|
@@ -72,27 +72,6 @@ const Cypress = (options, vite) => {
|
|
|
72
72
|
return res.end(transformedIndexHtml);
|
|
73
73
|
});
|
|
74
74
|
},
|
|
75
|
-
transform(code, id, options) {
|
|
76
|
-
try {
|
|
77
|
-
if (/\.js$/i.test(id) && !/\/\/# sourceMappingURL=/i.test(code)) {
|
|
78
|
-
// The Vite dev server and plugins automatically transpile TS and JSX files, which results in sourcemaps being generated
|
|
79
|
-
// and included in output. However, Vite serves up `esnext`-compliant Javascript which means many JS files won't be
|
|
80
|
-
// transpiled and won't supply a sourcemap - this prevents Cypress from providing codeFrames in the event of an error.
|
|
81
|
-
//
|
|
82
|
-
// A sourcemap is generated by Vite for JS files (just not included) which is in effect an "identity" sourcemap mapping
|
|
83
|
-
// 1-to-1 to the output file. We can grab this and pass it along as a sourcemap we want Vite to embed into the output,
|
|
84
|
-
// giving Cypress a sourcemap to use for codeFrame lookups.
|
|
85
|
-
// @see https://rollupjs.org/guide/en/#thisgetcombinedsourcemap
|
|
86
|
-
return {
|
|
87
|
-
code,
|
|
88
|
-
map: this.getCombinedSourcemap(),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (_err) {
|
|
93
|
-
debug('Failed to propagate sourcemap for %s: %o', id, _err);
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
75
|
handleHotUpdate: ({ server, file }) => {
|
|
97
76
|
debug('handleHotUpdate - file', file);
|
|
98
77
|
// If the user provided IndexHtml is changed, do a full-reload
|
package/dist/plugins/index.d.ts
CHANGED
package/dist/plugins/index.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CypressSourcemap = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
+
const debug = (0, debug_1.default)('cypress:vite-dev-server:plugins:sourcemap');
|
|
7
|
+
const CypressSourcemap = (options, vite) => {
|
|
8
|
+
return {
|
|
9
|
+
name: 'cypress:sourcemap',
|
|
10
|
+
enforce: 'post',
|
|
11
|
+
transform(code, id, options) {
|
|
12
|
+
try {
|
|
13
|
+
if (/\.js$/i.test(id) && !/\/\/# sourceMappingURL=/i.test(code)) {
|
|
14
|
+
/*
|
|
15
|
+
The Vite dev server and plugins automatically generate sourcemaps for most files, but they are
|
|
16
|
+
only included in the served files if any transpilation actually occurred (JSX, TS, etc). This
|
|
17
|
+
means that files that are "pure" JS won't include sourcemaps, so JS spec files that don't require
|
|
18
|
+
transpilation won't get code frames in the runner.
|
|
19
|
+
|
|
20
|
+
A sourcemap for these files is generated (just not served) which is in effect an "identity"
|
|
21
|
+
sourcemap mapping 1-to-1 to the output file. We can grab this and pass it along as a sourcemap
|
|
22
|
+
we want Vite to embed into the output, giving Cypress a sourcemap to use for codeFrame lookups.
|
|
23
|
+
@see https://rollupjs.org/guide/en/#thisgetcombinedsourcemap
|
|
24
|
+
|
|
25
|
+
We utilize a 'post' plugin here and manually append the sourcemap content to the code. We *should*
|
|
26
|
+
be able to pass the sourcemap along using the `map` attribute in the return value, but Babel-based
|
|
27
|
+
plugins don't work with this which causes sourcemaps to break for files that go through common
|
|
28
|
+
plugins like `@vitejs/plugin-react`. By manually appending the sourcemap at this point in time
|
|
29
|
+
Babel-transformed files end up with correct sourcemaps.
|
|
30
|
+
*/
|
|
31
|
+
const sourcemap = this.getCombinedSourcemap();
|
|
32
|
+
code += `\n//# sourceMappingURL=${sourcemap.toUrl()}`;
|
|
33
|
+
return {
|
|
34
|
+
code,
|
|
35
|
+
map: { mappings: '' },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (_err) {
|
|
40
|
+
debug('Failed to propagate sourcemap for %s: %o', id, _err);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
exports.CypressSourcemap = CypressSourcemap;
|
package/dist/resolveConfig.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InlineConfig } from 'vite';
|
|
1
2
|
import type { ViteDevServerConfig } from './devServer';
|
|
2
3
|
import type { Vite } from './getVite';
|
|
3
|
-
export declare const createViteDevServerConfig: (config: ViteDevServerConfig, vite: Vite) => Promise<
|
|
4
|
+
export declare const createViteDevServerConfig: (config: ViteDevServerConfig, vite: Vite) => Promise<InlineConfig>;
|
package/dist/resolveConfig.js
CHANGED
|
@@ -84,8 +84,16 @@ const createViteDevServerConfig = async (config, vite) => {
|
|
|
84
84
|
plugins: [
|
|
85
85
|
(0, index_1.Cypress)(config, vite),
|
|
86
86
|
(0, index_1.CypressInspect)(config),
|
|
87
|
+
(0, index_1.CypressSourcemap)(config, vite),
|
|
87
88
|
].filter((p) => p != null),
|
|
88
89
|
};
|
|
90
|
+
if (config.cypressConfig.isTextTerminal) {
|
|
91
|
+
viteBaseConfig.server = Object.assign(Object.assign({}, (viteBaseConfig.server || {})), {
|
|
92
|
+
// Disable file watching and HMR when executing tests in `run` mode
|
|
93
|
+
watch: {
|
|
94
|
+
ignored: '**/*',
|
|
95
|
+
}, hmr: false });
|
|
96
|
+
}
|
|
89
97
|
let resolvedOverrides = {};
|
|
90
98
|
if (typeof viteOverrides === 'function') {
|
|
91
99
|
resolvedOverrides = await viteOverrides();
|