@cypress/vite-dev-server 5.0.6 → 5.1.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
@@ -56,10 +56,25 @@ We then merge the sourced config with the user's vite config, and layer on our o
56
56
  | <= v2 | <= v9 |
57
57
  | >= v3 | >= v10 |
58
58
 
59
+ #### `devServerPublicPathRoute` for Vite v5
60
+
61
+ If using Vite version 5, setting `devServerPublicPathRoute` may be needed if directly referencing public path url assets in components under test. This is due to Cypress using its own public path, `/__cypress/src`, when running component tests. This can be configured within the `component` namespace below if you wish you set your public path to be the same as your app:
62
+
63
+ ```ts
64
+ import { defineConfig } from 'cypress'
65
+
66
+ export default defineConfig({
67
+ component: {
68
+ // If wanting a publicPath the same as the default in Vite 5
69
+ devServerPublicPathRoute: ''
70
+ }
71
+ })
72
+ ```
73
+
59
74
  ## License
60
75
 
61
76
  [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/develop/LICENSE)
62
77
 
63
78
  This project is licensed under the terms of the [MIT license](/LICENSE).
64
79
 
65
- ## [Changelog](./CHANGELOG.md)
80
+ ## [Changelog](./CHANGELOG.md)
@@ -13,6 +13,14 @@ const supportFile = CypressInstance.config('supportFile')
13
13
  const projectRoot = CypressInstance.config('projectRoot')
14
14
  const devServerPublicPathRoute = CypressInstance.config('devServerPublicPathRoute')
15
15
 
16
+ let devServerPublicPathBase = devServerPublicPathRoute
17
+
18
+ // In the case the devServerPublicPathRoute is set to the root, make sure we configure the loaders correctly to load relative paths
19
+ // This can be a case in vite 5 if a user wishes to have the same public path as their app (which is quite common)
20
+ if (devServerPublicPathRoute === '') {
21
+ devServerPublicPathBase = '.'
22
+ }
23
+
16
24
  if (supportFile) {
17
25
  let supportRelativeToProjectRoot = supportFile.replace(projectRoot, '')
18
26
 
@@ -20,15 +28,22 @@ if (supportFile) {
20
28
  const platformProjectRoot = projectRoot.replaceAll('/', '\\')
21
29
 
22
30
  supportRelativeToProjectRoot = supportFile.replace(platformProjectRoot, '')
31
+
32
+ // Support relative path (as well as in some cases absolute path) lookup is done with unix style operators.
33
+ supportRelativeToProjectRoot = supportRelativeToProjectRoot.replaceAll('\\', '/')
23
34
  }
24
35
 
25
- // We need a slash before /cypress/supportFile.js, this happens by default
26
- // with the current string replacement logic.
36
+ // We need a slash before /cypress/supportFile.js if the devServerPublicPathRoute is populated, this happens by default
37
+ // with the current string replacement logic. Otherwise, we need to specify the relative path to look up if devServerPublicPathRoute
38
+ // is not defined as it would be in the base directory
39
+
40
+ const relativeUrl = `${devServerPublicPathBase}${supportRelativeToProjectRoot}`
41
+
27
42
  importsToLoad.push({
28
- load: () => import(`${devServerPublicPathRoute}${supportRelativeToProjectRoot}`),
43
+ load: () => import(relativeUrl),
29
44
  absolute: supportFile,
30
45
  relative: supportRelativeToProjectRoot,
31
- relativeUrl: `${devServerPublicPathRoute}${supportRelativeToProjectRoot}`,
46
+ relativeUrl,
32
47
  })
33
48
  }
34
49
 
@@ -36,7 +51,7 @@ if (supportFile) {
36
51
  // So we use the "@fs" bit to load the test file using its absolute path
37
52
  // Normalize path to not include a leading slash (different on Win32 vs Unix)
38
53
  const normalizedAbsolutePath = CypressInstance.spec.absolute.replace(/^\//, '')
39
- const testFileAbsolutePathRoute = `${devServerPublicPathRoute}/@fs/${normalizedAbsolutePath}`
54
+ const testFileAbsolutePathRoute = `${devServerPublicPathBase}/@fs/${normalizedAbsolutePath}`
40
55
 
41
56
  /* Spec file import logic */
42
57
  // We need a slash before /src/my-spec.js, this does not happen by default.
@@ -1,7 +1,6 @@
1
1
  /// <reference types="cypress" />
2
- /// <reference types="cypress" />
3
2
  /// <reference types="node" />
4
- import type { UserConfig } from 'vite';
3
+ import type { UserConfig } from 'vite-5';
5
4
  declare const ALL_FRAMEWORKS: readonly ["react", "vue"];
6
5
  declare type ConfigHandler = UserConfig | (() => UserConfig | Promise<UserConfig>);
7
6
  export declare type ViteDevServerConfig = {
@@ -15,6 +14,6 @@ export declare type ViteDevServerConfig = {
15
14
  };
16
15
  export declare function devServer(config: ViteDevServerConfig): Promise<Cypress.ResolvedDevServerConfig>;
17
16
  export declare namespace devServer {
18
- var create: (devServerConfig: ViteDevServerConfig, vite: typeof import("vite")) => Promise<import("vite").ViteDevServer>;
17
+ var create: (devServerConfig: ViteDevServerConfig, vite: typeof import("vite-5")) => Promise<import("vite-5").ViteDevServer>;
19
18
  }
20
19
  export {};
package/dist/devServer.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.devServer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const debug_1 = tslib_1.__importDefault(require("debug"));
6
+ const major_1 = tslib_1.__importDefault(require("semver/functions/major"));
6
7
  const getVite_1 = require("./getVite");
7
8
  const resolveConfig_1 = require("./resolveConfig");
8
9
  const debug = (0, debug_1.default)('cypress:vite-dev-server:devServer');
@@ -10,6 +11,14 @@ const ALL_FRAMEWORKS = ['react', 'vue'];
10
11
  async function devServer(config) {
11
12
  // This has to be the first thing we do as we need to source vite from their project's dependencies
12
13
  const vite = (0, getVite_1.getVite)(config);
14
+ let majorVersion = undefined;
15
+ if (vite.version) {
16
+ majorVersion = (0, major_1.default)(vite.version);
17
+ debug(`Found vite version v${majorVersion}`);
18
+ }
19
+ else {
20
+ debug(`vite version not found`);
21
+ }
13
22
  debug('Creating Vite Server');
14
23
  const server = await devServer.create(config, vite);
15
24
  debug('Vite server created');
package/dist/getVite.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { ViteDevServerConfig } from './devServer';
2
- export declare type Vite = typeof import('vite');
2
+ export declare type Vite = typeof import('vite-5');
3
3
  export declare function getVite(config: ViteDevServerConfig): Vite;
@@ -1,4 +1,4 @@
1
- import type { Plugin } from 'vite';
1
+ import type { PluginOption } from 'vite-5';
2
2
  import type { Vite } from '../getVite';
3
3
  import type { ViteDevServerConfig } from '../devServer';
4
- export declare const Cypress: (options: ViteDevServerConfig, vite: Vite) => Plugin;
4
+ export declare const Cypress: (options: ViteDevServerConfig, vite: Vite) => PluginOption;
@@ -33,7 +33,7 @@ const Cypress = (options, vite) => {
33
33
  base = config.base;
34
34
  },
35
35
  async transformIndexHtml(html) {
36
- // it's possibe other plugins have modified the HTML
36
+ // it's possible other plugins have modified the HTML
37
37
  // before we get to. For example vitejs/plugin-react will
38
38
  // add a preamble. We do our best to look at the HTML we
39
39
  // receive and inject it.
@@ -1,4 +1,4 @@
1
- import type { Plugin } from 'vite';
1
+ import type { PluginOption } from 'vite-5';
2
2
  import type { Vite } from '../getVite';
3
3
  import type { ViteDevServerConfig } from '../devServer';
4
- export declare const CypressSourcemap: (options: ViteDevServerConfig, vite: Vite) => Plugin;
4
+ export declare const CypressSourcemap: (options: ViteDevServerConfig, vite: Vite) => PluginOption;
@@ -1,4 +1,4 @@
1
- import type { InlineConfig } from 'vite';
1
+ import type { InlineConfig } from 'vite-5';
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>;
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "@cypress/vite-dev-server",
3
- "version": "5.0.6",
3
+ "version": "5.1.0",
4
4
  "description": "Launches Vite Dev Server for Component Testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "build": "tsc || echo 'built, with type errors'",
8
- "build-prod": "tsc || echo 'built, with type errors'",
9
8
  "check-ts": "tsc --noEmit",
9
+ "cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
10
10
  "cypress:run": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome",
11
11
  "cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
12
- "cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
13
- "watch": "tsc -w",
12
+ "lint": "eslint --ext .js,.ts,.json, .",
14
13
  "test": "yarn test-unit",
15
14
  "test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js",
16
- "lint": "eslint --ext .js,.ts,.json, ."
15
+ "watch": "tsc -w"
17
16
  },
18
17
  "dependencies": {
19
18
  "debug": "^4.3.4",
@@ -23,12 +22,14 @@
23
22
  },
24
23
  "devDependencies": {
25
24
  "chai": "^4.3.6",
25
+ "decache": "^4.6.2",
26
26
  "dedent": "^0.7.0",
27
27
  "mocha": "^9.2.2",
28
28
  "sinon": "^13.0.1",
29
- "ts-node": "^10.9.1",
30
- "vite": "4.3.2",
31
- "vite-plugin-inspect": "0.7.24"
29
+ "ts-node": "^10.9.2",
30
+ "vite-4": "npm:vite@^4.5.2",
31
+ "vite-5": "npm:vite@^5.2.8",
32
+ "vite-plugin-inspect": "0.8.4"
32
33
  },
33
34
  "files": [
34
35
  "dist",
@@ -46,5 +47,14 @@
46
47
  "module": "dist/index.js",
47
48
  "publishConfig": {
48
49
  "access": "public"
50
+ },
51
+ "nx": {
52
+ "targets": {
53
+ "build": {
54
+ "outputs": [
55
+ "{projectRoot}/dist"
56
+ ]
57
+ }
58
+ }
49
59
  }
50
60
  }