@cypress/vite-dev-server 5.2.0 → 5.2.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.
@@ -10,26 +10,31 @@ const CypressSourcemap = (options, vite) => {
10
10
  enforce: 'post',
11
11
  transform(code, id, options) {
12
12
  try {
13
- if (/\.js$/i.test(id) && !/\/\/# sourceMappingURL=/i.test(code)) {
13
+ // Remove query parameters from the id. This is necessary because some files
14
+ // have a cache buster query parameter (e.g. `?v=12345`)
15
+ const queryParameterLessId = id.split('?')[0];
16
+ // Check if the file has a JavaScript extension and does not have an inlined sourcemap
17
+ if (/\.(js|jsx|ts|tsx|vue|svelte|mjs|cjs)$/i.test(queryParameterLessId) && !/\/\/# sourceMappingURL=data/i.test(code)) {
14
18
  /*
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*
19
+ The Vite dev server and plugins automatically generate sourcemaps for most files, but there are
20
+ some files that don't have sourcemaps generated for them or are not inlined. We utilize a 'post' plugin
21
+ here and manually append the sourcemap content to the code in these cases. We *should*
26
22
  be able to pass the sourcemap along using the `map` attribute in the return value, but Babel-based
27
23
  plugins don't work with this which causes sourcemaps to break for files that go through common
28
24
  plugins like `@vitejs/plugin-react`. By manually appending the sourcemap at this point in time
29
25
  Babel-transformed files end up with correct sourcemaps.
30
26
  */
31
27
  const sourcemap = this.getCombinedSourcemap();
32
- code += `\n//# sourceMappingURL=${sourcemap.toUrl()}`;
28
+ const sourcemapUrl = sourcemap.toUrl();
29
+ if (/\/\/# sourceMappingURL=/i.test(code)) {
30
+ // If the code already has a sourceMappingURL, it is not an inlined sourcemap
31
+ // and we should replace it with the new sourcemap
32
+ code = code.replace(/\/\/# sourceMappingURL=(.*)$/m, `//# sourceMappingURL=${sourcemapUrl}`);
33
+ }
34
+ else {
35
+ // If the code does not have a sourceMappingURL, we should append the new sourcemap
36
+ code += `\n//# sourceMappingURL=${sourcemapUrl}`;
37
+ }
33
38
  return {
34
39
  code,
35
40
  map: { mappings: '' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/vite-dev-server",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "Launches Vite Dev Server for Component Testing",
5
5
  "main": "index.js",
6
6
  "scripts": {