@cypress/vite-dev-server 5.2.0 → 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/README.md CHANGED
@@ -12,7 +12,7 @@ import { defineConfig } from 'cypress'
12
12
  export default defineConfig({
13
13
  component: {
14
14
  devServer: {
15
- framework: 'create-react-app',
15
+ framework: 'react',
16
16
  bundler: 'vite',
17
17
  // viteConfig?: Will try to infer, if passed it will be used as is
18
18
  }
@@ -51,10 +51,11 @@ We then merge the sourced config with the user's vite config, and layer on our o
51
51
 
52
52
  ## Compatibility
53
53
 
54
- | @cypress/vite-dev-server | cypress |
55
- | ------------------------ | ------- |
56
- | <= v2 | <= v9 |
57
- | >= v3 | >= v10 |
54
+ | @cypress/vite-dev-server | cypress |
55
+ | ------------------------ | ------------- |
56
+ | <= v2 | <= v9 |
57
+ | >= v3 <= v5 | >= v10 <= v13 |
58
+ | >= v6 | >= v14 |
58
59
 
59
60
  #### `devServerPublicPathRoute` for Vite v5
60
61
 
@@ -1,6 +1,6 @@
1
1
  /// <reference types="cypress" />
2
2
  /// <reference types="node" />
3
- import type { UserConfig } from 'vite-5';
3
+ import type { UserConfig } from 'vite-6';
4
4
  declare const ALL_FRAMEWORKS: readonly ["react", "vue"];
5
5
  type ConfigHandler = UserConfig | (() => UserConfig | Promise<UserConfig>);
6
6
  export type ViteDevServerConfig = {
@@ -14,6 +14,6 @@ export type ViteDevServerConfig = {
14
14
  };
15
15
  export declare function devServer(config: ViteDevServerConfig): Promise<Cypress.ResolvedDevServerConfig>;
16
16
  export declare namespace devServer {
17
- var create: (devServerConfig: ViteDevServerConfig, vite: typeof import("vite-5")) => Promise<import("vite-5").ViteDevServer>;
17
+ var create: (devServerConfig: ViteDevServerConfig, vite: typeof import("vite-6")) => Promise<import("vite-6").ViteDevServer>;
18
18
  }
19
19
  export {};
package/dist/getVite.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { ViteDevServerConfig } from './devServer';
2
- export type Vite = typeof import('vite-5');
2
+ export type Vite = typeof import('vite-6');
3
3
  export declare function getVite(config: ViteDevServerConfig): Vite;
@@ -1,4 +1,4 @@
1
- import type { PluginOption } from 'vite-5';
1
+ import type { PluginOption } from 'vite-6';
2
2
  import type { Vite } from '../getVite';
3
3
  import type { ViteDevServerConfig } from '../devServer';
4
4
  export declare const Cypress: (options: ViteDevServerConfig, vite: Vite) => PluginOption;
@@ -23,7 +23,11 @@ const Cypress = (options, vite) => {
23
23
  // TODO: use async fs methods here
24
24
  // eslint-disable-next-line no-restricted-syntax
25
25
  let loader = fs_1.default.readFileSync(INIT_FILEPATH, 'utf8');
26
- devServerEvents.on('dev-server:specs:changed', (specs) => {
26
+ devServerEvents.on('dev-server:specs:changed', ({ specs, options }) => {
27
+ if (options === null || options === void 0 ? void 0 : options.neededForJustInTimeCompile) {
28
+ // if an option is needed for just in time compile, no-op as this isn't supported in vite
29
+ return;
30
+ }
27
31
  debug(`dev-server:secs:changed: ${specs.map((spec) => spec.relative)}`);
28
32
  specsPathsSet = getSpecsPathsSet(specs);
29
33
  });
@@ -63,12 +67,7 @@ const Cypress = (options, vite) => {
63
67
  },
64
68
  configureServer: async (server) => {
65
69
  server.middlewares.use(`${base}index.html`, async (req, res) => {
66
- let transformedIndexHtml = await server.transformIndexHtml(base, '');
67
- const viteImport = `<script type="module" src="${options.cypressConfig.devServerPublicPathRoute}/@vite/client"></script>`;
68
- // If we're doing cy-in-cy, we need to be able to access the Cypress instance from the parent frame.
69
- if (process.env.CYPRESS_INTERNAL_VITE_OPEN_MODE_TESTING) {
70
- transformedIndexHtml = transformedIndexHtml.replace(viteImport, `<script>document.domain = 'localhost';</script>${viteImport}`);
71
- }
70
+ const transformedIndexHtml = await server.transformIndexHtml(base, '');
72
71
  return res.end(transformedIndexHtml);
73
72
  });
74
73
  },
@@ -1,4 +1,4 @@
1
- import type { PluginOption } from 'vite-5';
1
+ import type { PluginOption } from 'vite-6';
2
2
  import type { Vite } from '../getVite';
3
3
  import type { ViteDevServerConfig } from '../devServer';
4
4
  export declare const CypressSourcemap: (options: ViteDevServerConfig, vite: Vite) => PluginOption;
@@ -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: '' },
@@ -1,4 +1,4 @@
1
- import type { InlineConfig } from 'vite-5';
1
+ import type { InlineConfig } from 'vite-6';
2
2
  import type { ViteDevServerConfig } from './devServer';
3
3
  import type { Vite } from './getVite';
4
4
  export declare const createViteDevServerConfig: (config: ViteDevServerConfig, vite: Vite) => Promise<InlineConfig>;
@@ -52,7 +52,7 @@ const createViteDevServerConfig = async (config, vite) => {
52
52
  exports.createViteDevServerConfig = createViteDevServerConfig;
53
53
  function makeCypressViteConfig(config, vite) {
54
54
  var _a, _b, _c;
55
- const { cypressConfig: { experimentalJustInTimeCompile, port, projectRoot, devServerPublicPathRoute, supportFile, cypressBinaryRoot, isTextTerminal, }, specs, } = config;
55
+ const { cypressConfig: { port, projectRoot, devServerPublicPathRoute, supportFile, cypressBinaryRoot, isTextTerminal, }, specs, } = config;
56
56
  const vitePort = port !== null && port !== void 0 ? port : undefined;
57
57
  // Vite caches its output in the .vite directory in the node_modules where vite lives.
58
58
  // So we want to find that node_modules path and ensure it's added to the "allow" list
@@ -95,7 +95,7 @@ function makeCypressViteConfig(config, vite) {
95
95
  // Supported from Vite v3 - add null check for v2 users.
96
96
  (_a = vite.searchForWorkspaceRoot) === null || _a === void 0 ? void 0 : _a.call(vite, process.cwd()),
97
97
  ],
98
- }, port: vitePort, host: '127.0.0.1' }, (isTextTerminal && !experimentalJustInTimeCompile
98
+ }, port: vitePort, host: '127.0.0.1' }, (isTextTerminal
99
99
  ? { watch: { ignored: '**/*' }, hmr: false }
100
100
  : {})),
101
101
  plugins: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/vite-dev-server",
3
- "version": "5.2.0",
3
+ "version": "6.0.0",
4
4
  "description": "Launches Vite Dev Server for Component Testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,6 +29,7 @@
29
29
  "ts-node": "^10.9.2",
30
30
  "vite-4": "npm:vite@^4.5.3",
31
31
  "vite-5": "npm:vite@^5.2.8",
32
+ "vite-6": "npm:vite@^6.0.0",
32
33
  "vite-plugin-inspect": "0.8.4"
33
34
  },
34
35
  "files": [