@nx/vite 23.0.0-beta.16 → 23.0.0-beta.18

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/migrations.json CHANGED
@@ -31,7 +31,7 @@
31
31
  "vitest": ">=4.0.0"
32
32
  },
33
33
  "description": "Create AI Instructions to help migrate users workspaces past breaking changes for Vitest 4.",
34
- "implementation": "./src/migrations/update-22-2-0/create-ai-instructions-for-vitest-4"
34
+ "prompt": "./src/migrations/update-22-2-0/ai-instructions-for-vitest-4.md"
35
35
  },
36
36
  "migrate-vitest-to-vitest-package": {
37
37
  "version": "22.2.0-beta.2",
@@ -57,7 +57,7 @@
57
57
  "vite": ">=8.0.0"
58
58
  },
59
59
  "description": "Create AI Instructions to help migrate users workspaces past breaking changes for Vite 8.",
60
- "implementation": "./src/migrations/update-23-0-0/create-ai-instructions-for-vite-8"
60
+ "prompt": "./src/migrations/update-23-0-0/ai-instructions-for-vite-8.md"
61
61
  }
62
62
  },
63
63
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/vite",
3
- "version": "23.0.0-beta.16",
3
+ "version": "23.0.0-beta.18",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for building and testing applications using Vite",
6
6
  "repository": {
@@ -31,11 +31,11 @@
31
31
  "migrations": "./migrations.json"
32
32
  },
33
33
  "dependencies": {
34
- "@nx/devkit": "23.0.0-beta.16",
34
+ "@nx/devkit": "23.0.0-beta.18",
35
35
  "@phenomnomnominal/tsquery": "~6.2.0",
36
36
  "enquirer": "~2.3.6",
37
- "@nx/js": "23.0.0-beta.16",
38
- "@nx/vitest": "23.0.0-beta.16",
37
+ "@nx/js": "23.0.0-beta.18",
38
+ "@nx/vitest": "23.0.0-beta.18",
39
39
  "picomatch": "4.0.4",
40
40
  "tsconfig-paths": "^4.1.2",
41
41
  "semver": "^7.6.3",
@@ -43,7 +43,8 @@
43
43
  "ajv": "^8.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "nx": "23.0.0-beta.16"
46
+ "@nx/eslint": "23.0.0-beta.18",
47
+ "nx": "23.0.0-beta.18"
47
48
  },
48
49
  "peerDependencies": {
49
50
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
@@ -95,7 +95,7 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
95
95
  includeLib: schema.includeLib,
96
96
  includeVitest: schema.includeVitest,
97
97
  inSourceTests: schema.inSourceTests,
98
- rollupOptionsExternal: [
98
+ rolldownOptionsExternal: [
99
99
  "'react'",
100
100
  "'react-dom'",
101
101
  "'react/jsx-runtime'",
@@ -42,11 +42,11 @@ async function default_1(tree) {
42
42
  return;
43
43
  }
44
44
  (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
45
- const { addIgnoresToLintConfig, isEslintConfigSupported } = await Promise.resolve().then(() => __importStar(require('@nx/eslint/src/generators/utils/eslint-file')));
45
+ const { addIgnoresToLintConfig, isEslintConfigSupported } = await Promise.resolve().then(() => __importStar(require('@nx/eslint/internal')));
46
46
  if (!isEslintConfigSupported(tree)) {
47
47
  return;
48
48
  }
49
- const { useFlatConfig } = await Promise.resolve().then(() => __importStar(require('@nx/eslint/src/utils/flat-config')));
49
+ const { useFlatConfig } = await Promise.resolve().then(() => __importStar(require('@nx/eslint/internal')));
50
50
  const isUsingFlatConfig = useFlatConfig(tree);
51
51
  if (isUsingFlatConfig) {
52
52
  // using flat config, so we update the root eslint config
@@ -1 +1 @@
1
- {"version":3,"file":"rename-rollup-options-to-rolldown-options.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/migrations/update-23-0-0/rename-rollup-options-to-rolldown-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAU1E,wBAA8B,oCAAoC,CAAC,IAAI,EAAE,IAAI,iBAqC5E"}
1
+ {"version":3,"file":"rename-rollup-options-to-rolldown-options.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/migrations/update-23-0-0/rename-rollup-options-to-rolldown-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAY1E,wBAA8B,oCAAoC,CAAC,IAAI,EAAE,IAAI,iBA8C5E"}
@@ -4,7 +4,9 @@ exports.default = renameRollupOptionsToRolldownOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const tsquery_1 = require("@phenomnomnominal/tsquery");
6
6
  const picomatch = require("picomatch");
7
- const ROLLUP_OPTIONS_IDENTIFIER_SELECTOR = 'PropertyAssignment > Identifier[name=rollupOptions]';
7
+ // Matches both bare-key form (rollupOptions: ...) and quoted-key form
8
+ // ('rollupOptions': ...) so configs written with JSON-style quoting are caught.
9
+ const ROLLUP_OPTIONS_SELECTOR = 'PropertyAssignment > :matches(Identifier[name=rollupOptions], StringLiteral[value=rollupOptions])';
8
10
  const VITE_CONFIG_GLOB = '**/vite.*config*.{js,ts,mjs,mts,cjs,cts}';
9
11
  async function renameRollupOptionsToRolldownOptions(tree) {
10
12
  const matchVite = picomatch(VITE_CONFIG_GLOB);
@@ -13,22 +15,31 @@ async function renameRollupOptionsToRolldownOptions(tree) {
13
15
  return;
14
16
  }
15
17
  const contents = tree.read(filePath, 'utf-8');
18
+ if (!contents)
19
+ return;
16
20
  if (!contents.includes('rollupOptions')) {
17
21
  return;
18
22
  }
19
23
  const sourceFile = (0, tsquery_1.ast)(contents);
20
- const identifiers = (0, tsquery_1.query)(sourceFile, ROLLUP_OPTIONS_IDENTIFIER_SELECTOR);
21
- if (identifiers.length === 0) {
24
+ // Extra .text filter guards against the outer-PropertyAssignment descendant
25
+ // trap: ensures the matched node's own name is `rollupOptions`, not a
26
+ // nested node that merely contains an identifier with that name.
27
+ const nodes = (0, tsquery_1.query)(sourceFile, ROLLUP_OPTIONS_SELECTOR).filter((node) => node.text === 'rollupOptions');
28
+ if (nodes.length === 0) {
22
29
  return;
23
30
  }
24
31
  // Replace from end-to-start so positions stay valid as we mutate.
25
32
  let updated = contents;
26
- for (let i = identifiers.length - 1; i >= 0; i--) {
27
- const node = identifiers[i];
28
- updated =
29
- updated.slice(0, node.getStart()) +
30
- 'rolldownOptions' +
31
- updated.slice(node.getEnd());
33
+ for (let i = nodes.length - 1; i >= 0; i--) {
34
+ const node = nodes[i];
35
+ const start = node.getStart();
36
+ const end = node.getEnd();
37
+ // Preserve quote style for StringLiteral keys ('rollupOptions' or "rollupOptions").
38
+ const quoteChar = updated[start];
39
+ const replacement = quoteChar === "'" || quoteChar === '"'
40
+ ? `${quoteChar}rolldownOptions${quoteChar}`
41
+ : 'rolldownOptions';
42
+ updated = updated.slice(0, start) + replacement + updated.slice(end);
32
43
  }
33
44
  tree.write(filePath, updated);
34
45
  });
@@ -29,7 +29,7 @@ export interface ViteConfigFileOptions {
29
29
  includeVitest?: boolean;
30
30
  inSourceTests?: boolean;
31
31
  testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
32
- rollupOptionsExternal?: string[];
32
+ rolldownOptionsExternal?: string[];
33
33
  imports?: string[];
34
34
  plugins?: string[];
35
35
  coverageProvider?: 'v8' | 'istanbul' | 'custom';
@@ -1 +1 @@
1
- {"version":3,"file":"generator-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/vite/src/utils/generator-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAML,mBAAmB,EACnB,IAAI,EAGL,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAGtF,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAC5D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAC3D,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACrE,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnE,wBAAgB,kCAAkC,CAAC,OAAO,EAAE;IAC1D,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,CAAC;CAC3C,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAkDA;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gCAAgC,EACzC,MAAM,EAAE,MAAM,QA+Bf;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gCAAgC,EACzC,MAAM,EAAE,MAAM,QAyBf;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gCAAgC,EACzC,WAAW,EAAE,MAAM,QAqCpB;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gCAAgC,QA0C1C;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,qBAAqB,CAAC,EAAE,MAAM,QAa/B;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gCAAgC,QA0D1C;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,cAAc,GAAG,MAAM,CAAC;IAC3E,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,CAAC,EAAE,IAAI,GAAG,UAAU,GAAG,QAAQ,CAAC;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,qBAAqB,EAC9B,UAAU,EAAE,OAAO,EACnB,4BAA4B,CAAC,EAAE,WAAW,EAC1C,cAAc,CAAC,EAAE,OAAO,QA4LzB;AAMD,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAUR;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,UAgBhB;AAED,wBAAsB,oCAAoC,CACxD,+BAA+B,EAAE,WAAW,EAC5C,sBAAsB,EAAE,sBAAsB,EAC9C,oBAAoB,EAAE,oBAAoB,iBA4B3C;AAoCD,wBAAsB,0BAA0B,CAAC,WAAW,EAAE,MAAM,iBA4BnE"}
1
+ {"version":3,"file":"generator-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/vite/src/utils/generator-utils.ts"],"names":[],"mappings":"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"}
@@ -271,9 +271,9 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
271
271
  // Don't forget to update your package.json as well.
272
272
  formats: ['es' as const]
273
273
  },
274
- rollupOptions: {
274
+ rolldownOptions: {
275
275
  // External packages that should not be bundled into your library.
276
- external: [${options.rollupOptionsExternal ?? ''}]
276
+ external: [${options.rolldownOptionsExternal ?? ''}]
277
277
  },
278
278
  },`
279
279
  : ` build: {
@@ -470,8 +470,8 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
470
470
  fileName: 'index',
471
471
  formats: ['es'],
472
472
  },
473
- rollupOptions: {
474
- external: options.rollupOptionsExternal ?? [],
473
+ rolldownOptions: {
474
+ external: options.rolldownOptionsExternal ?? [],
475
475
  },
476
476
  outDir: buildOutDir,
477
477
  reportCompressedSize: true,
@@ -57,11 +57,11 @@ async function ignoreViteTempFilesInEslintConfig(tree, projectRoot) {
57
57
  return;
58
58
  }
59
59
  (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
60
- const { addIgnoresToLintConfig, isEslintConfigSupported } = await Promise.resolve().then(() => __importStar(require('@nx/eslint/src/generators/utils/eslint-file')));
60
+ const { addIgnoresToLintConfig, isEslintConfigSupported } = await Promise.resolve().then(() => __importStar(require('@nx/eslint/internal')));
61
61
  if (!isEslintConfigSupported(tree)) {
62
62
  return;
63
63
  }
64
- const { useFlatConfig } = await Promise.resolve().then(() => __importStar(require('@nx/eslint/src/utils/flat-config')));
64
+ const { useFlatConfig } = await Promise.resolve().then(() => __importStar(require('@nx/eslint/internal')));
65
65
  const isUsingFlatConfig = useFlatConfig(tree);
66
66
  if (!projectRoot && !isUsingFlatConfig) {
67
67
  // root eslintrc files ignore all files and the root eslintrc files add
@@ -5,8 +5,8 @@ export declare const conditionalConfig = "\n /// <reference types=\"vitest\"
5
5
  export declare const configNoDefineConfig = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\n export default {\n plugins: [\n react(),\n nxViteTsPaths(),\n ],\n };\n ";
6
6
  export declare const noBuildOptionsHasTestOption = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\n export default defineConfig({\n \n cacheDir: '../../node_modules/.vitest',\n plugins: [\n react(),\n nxViteTsPaths(),\n ],\n\n test: {\n globals: true,\n environment: 'jsdom',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n },\n\n });\n ";
7
7
  export declare const someBuildOptionsSomeTestOption = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\n export default defineConfig({\n plugins: [\n react(),\n nxViteTsPaths(),\n ],\n\n test: {\n my: 'option',\n },\n\n build: {\n my: 'option',\n }\n\n });\n ";
8
- export declare const hasEverything = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n import dts from 'vite-plugin-dts';\n import { joinPathFragments } from '@nx/devkit';\n\n export default defineConfig({\n cacheDir: '../../node_modules/.vitest',\n plugins: [\n dts({ entryRoot: 'src', tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true }),\n react(),\n nxViteTsPaths(),\n ],\n \n // Configuration for building your library.\n // See: https://vite.dev/guide/build.html#library-mode\n build: {\n lib: {\n // Could also be a dictionary or array of multiple entry points.\n entry: 'src/index.ts',\n name: 'pure-libs-react-vite',\n fileName: 'index',\n // Change this to the formats you want to support.\n // Don't forget to update your package.json as well.\n formats: ['es'],\n },\n rollupOptions: {\n // External packages that should not be bundled into your library.\n external: ['react', 'react-dom', 'react/jsx-runtime'],\n },\n },\n \n test: {\n globals: true,\n environment: 'jsdom',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n },\n });\n ";
9
- export declare const buildOption = "\n // Configuration for building your library.\n // See: https://vite.dev/guide/build.html#library-mode\n build: {\n lib: {\n // Could also be a dictionary or array of multiple entry points.\n entry: 'src/index.ts',\n name: 'my-app',\n fileName: 'index',\n // Change this to the formats you want to support.\n // Don't forget to update your package.json as well.\n formats: ['es']\n },\n rollupOptions: {\n // External packages that should not be bundled into your library.\n external: ['react', 'react-dom', 'react/jsx-runtime']\n }\n },";
8
+ export declare const hasEverything = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n import dts from 'vite-plugin-dts';\n import { joinPathFragments } from '@nx/devkit';\n\n export default defineConfig({\n cacheDir: '../../node_modules/.vitest',\n plugins: [\n dts({ entryRoot: 'src', tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true }),\n react(),\n nxViteTsPaths(),\n ],\n \n // Configuration for building your library.\n // See: https://vite.dev/guide/build.html#library-mode\n build: {\n lib: {\n // Could also be a dictionary or array of multiple entry points.\n entry: 'src/index.ts',\n name: 'pure-libs-react-vite',\n fileName: 'index',\n // Change this to the formats you want to support.\n // Don't forget to update your package.json as well.\n formats: ['es'],\n },\n rolldownOptions: {\n // External packages that should not be bundled into your library.\n external: ['react', 'react-dom', 'react/jsx-runtime'],\n },\n },\n \n test: {\n globals: true,\n environment: 'jsdom',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n },\n });\n ";
9
+ export declare const buildOption = "\n // Configuration for building your library.\n // See: https://vite.dev/guide/build.html#library-mode\n build: {\n lib: {\n // Could also be a dictionary or array of multiple entry points.\n entry: 'src/index.ts',\n name: 'my-app',\n fileName: 'index',\n // Change this to the formats you want to support.\n // Don't forget to update your package.json as well.\n formats: ['es']\n },\n rolldownOptions: {\n // External packages that should not be bundled into your library.\n external: ['react', 'react-dom', 'react/jsx-runtime']\n }\n },";
10
10
  export declare const buildOptionObject: {
11
11
  lib: {
12
12
  entry: string;
@@ -14,7 +14,7 @@ export declare const buildOptionObject: {
14
14
  fileName: string;
15
15
  formats: string[];
16
16
  };
17
- rollupOptions: {
17
+ rolldownOptions: {
18
18
  external: string[];
19
19
  };
20
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"test-vite-configs.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/utils/test-files/test-vite-configs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,iiBAoBtB,CAAC;AAEN,eAAO,MAAM,gBAAgB,mlBAwBxB,CAAC;AAEN,eAAO,MAAM,qBAAqB,oQAO7B,CAAC;AAEN,eAAO,MAAM,iBAAiB,4YAgBzB,CAAC;AAEN,eAAO,MAAM,oBAAoB,oUAY5B,CAAC;AAEN,eAAO,MAAM,2BAA2B,uiBAqBnC,CAAC;AAEN,eAAO,MAAM,8BAA8B,wbAqBtC,CAAC;AAEN,eAAO,MAAM,aAAa,k7CAwCrB,CAAC;AAEN,eAAO,MAAM,WAAW,8nBAiBjB,CAAC;AACR,eAAO,MAAM,iBAAiB;;;;;;;;;;CAU7B,CAAC;AAEF,eAAO,MAAM,UAAU,uJAIhB,CAAC;AAER,eAAO,MAAM,gBAAgB;;;;CAI5B,CAAC;AAEF,eAAO,MAAM,OAAO,UAGnB,CAAC;AAEF,eAAO,MAAM,OAAO,UAAiC,CAAC"}
1
+ {"version":3,"file":"test-vite-configs.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/utils/test-files/test-vite-configs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,iiBAoBtB,CAAC;AAEN,eAAO,MAAM,gBAAgB,mlBAwBxB,CAAC;AAEN,eAAO,MAAM,qBAAqB,oQAO7B,CAAC;AAEN,eAAO,MAAM,iBAAiB,4YAgBzB,CAAC;AAEN,eAAO,MAAM,oBAAoB,oUAY5B,CAAC;AAEN,eAAO,MAAM,2BAA2B,uiBAqBnC,CAAC;AAEN,eAAO,MAAM,8BAA8B,wbAqBtC,CAAC;AAEN,eAAO,MAAM,aAAa,o7CAwCrB,CAAC;AAEN,eAAO,MAAM,WAAW,goBAiBjB,CAAC;AACR,eAAO,MAAM,iBAAiB;;;;;;;;;;CAU7B,CAAC;AAEF,eAAO,MAAM,UAAU,uJAIhB,CAAC;AAER,eAAO,MAAM,gBAAgB;;;;CAI5B,CAAC;AAEF,eAAO,MAAM,OAAO,UAGnB,CAAC;AAEF,eAAO,MAAM,OAAO,UAAiC,CAAC"}
@@ -157,7 +157,7 @@ exports.hasEverything = `
157
157
  // Don't forget to update your package.json as well.
158
158
  formats: ['es'],
159
159
  },
160
- rollupOptions: {
160
+ rolldownOptions: {
161
161
  // External packages that should not be bundled into your library.
162
162
  external: ['react', 'react-dom', 'react/jsx-runtime'],
163
163
  },
@@ -183,7 +183,7 @@ exports.buildOption = `
183
183
  // Don't forget to update your package.json as well.
184
184
  formats: ['es']
185
185
  },
186
- rollupOptions: {
186
+ rolldownOptions: {
187
187
  // External packages that should not be bundled into your library.
188
188
  external: ['react', 'react-dom', 'react/jsx-runtime']
189
189
  }
@@ -195,7 +195,7 @@ exports.buildOptionObject = {
195
195
  fileName: 'index',
196
196
  formats: ['es'],
197
197
  },
198
- rollupOptions: {
198
+ rolldownOptions: {
199
199
  external: ['react', 'react-dom', 'react/jsx-runtime'],
200
200
  },
201
201
  };
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function createAiInstructionsForVitest(tree: Tree): Promise<string[]>;
3
- //# sourceMappingURL=create-ai-instructions-for-vitest-4.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-ai-instructions-for-vitest-4.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/migrations/update-22-2-0/create-ai-instructions-for-vitest-4.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,wBAA8B,6BAA6B,CAAC,IAAI,EAAE,IAAI,qBAerE"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = createAiInstructionsForVitest;
4
- const path_1 = require("path");
5
- const fs_1 = require("fs");
6
- async function createAiInstructionsForVitest(tree) {
7
- const pathToAiInstructions = (0, path_1.join)(__dirname, 'files', 'ai-instructions-for-vitest-4.md');
8
- if (!(0, fs_1.existsSync)(pathToAiInstructions)) {
9
- return;
10
- }
11
- const contents = (0, fs_1.readFileSync)(pathToAiInstructions);
12
- tree.write('tools/ai-migrations/MIGRATE_VITEST_4.md', contents);
13
- return [
14
- `We created 'tools/ai-migrations/MIGRATE_VITEST_4.md' with instructions for an AI Agent to help migrate your Vitest projects to Vitest 4.`,
15
- ];
16
- }
@@ -1,725 +0,0 @@
1
- # Vitest 4.0 Migration Instructions for LLM
2
-
3
- ## Overview
4
-
5
- These instructions guide you through migrating an Nx workspace containing multiple Vitest projects from Vitest 3.x to Vitest 4.0. Work systematically through each breaking change category.
6
-
7
- ## Pre-Migration Checklist
8
-
9
- 1. **Identify all Vitest projects**:
10
-
11
- ```bash
12
- nx show projects --with-target test
13
- ```
14
-
15
- 2. **Locate all Vitest configuration files**:
16
- - Search for `vitest.config.{ts,js,mjs}`
17
- - Search for `vitest.workspace.{ts,js,mjs}`
18
- - Check `project.json` files for inline Vitest configuration
19
-
20
- 3. **Identify affected code**:
21
- - Test files: `**/*.{spec,test}.{ts,js,tsx,jsx}`
22
- - Mock usage: Files using `vi.fn()`, `vi.spyOn()`, `vi.mock()`
23
- - Coverage configuration references
24
-
25
- ## Migration Steps by Category
26
-
27
- ### 1. Configuration File Updates
28
-
29
- #### 1.1 Coverage Configuration
30
-
31
- **Search Pattern**: `coverage` in all `vitest.config.*` files and `project.json` test target options
32
-
33
- **Changes Required**:
34
-
35
- ```typescript
36
- // ❌ BEFORE (Vitest 3.x)
37
- export default defineConfig({
38
- test: {
39
- coverage: {
40
- all: true,
41
- extensions: ['.ts', '.tsx'],
42
- ignoreEmptyLines: false,
43
- experimentalAstAwareRemapping: true,
44
- },
45
- },
46
- });
47
-
48
- // ✅ AFTER (Vitest 4.0)
49
- export default defineConfig({
50
- test: {
51
- coverage: {
52
- // Explicitly define files to include in coverage
53
- include: ['src/**/*.{ts,tsx}'],
54
- // Remove: all, extensions, ignoreEmptyLines, experimentalAstAwareRemapping
55
- },
56
- },
57
- });
58
- ```
59
-
60
- **Action Items**:
61
-
62
- - [ ] Remove `coverage.all` option
63
- - [ ] Remove `coverage.extensions` option
64
- - [ ] Remove `coverage.ignoreEmptyLines` option
65
- - [ ] Remove `coverage.experimentalAstAwareRemapping` option
66
- - [ ] Add explicit `coverage.include` patterns based on project structure
67
- - [ ] Update any documentation referencing these options
68
-
69
- #### 1.2 Pool Options Restructuring
70
-
71
- **Search Pattern**: `poolOptions`, `maxThreads`, `maxForks`, `singleThread`, `singleFork` in all Vitest config files
72
-
73
- **Changes Required**:
74
-
75
- ```typescript
76
- // ❌ BEFORE (Vitest 3.x)
77
- export default defineConfig({
78
- test: {
79
- maxThreads: 4,
80
- maxForks: 2,
81
- singleThread: false,
82
- poolOptions: {
83
- threads: {
84
- useAtomics: true,
85
- },
86
- vmThreads: {
87
- memoryLimit: '512MB',
88
- },
89
- },
90
- },
91
- });
92
-
93
- // ✅ AFTER (Vitest 4.0)
94
- export default defineConfig({
95
- test: {
96
- maxWorkers: 4, // Consolidates maxThreads and maxForks
97
- isolate: true, // Replaces singleThread: false
98
- // Remove: poolOptions, threads.useAtomics
99
- vmMemoryLimit: '512MB', // Moved to top-level
100
- },
101
- });
102
- ```
103
-
104
- **Action Items**:
105
-
106
- - [ ] Replace `maxThreads` and `maxForks` with single `maxWorkers` option
107
- - [ ] Replace `singleThread: true` or `singleFork: true` with `maxWorkers: 1, isolate: false`
108
- - [ ] Move all `poolOptions.*` nested options to top-level (e.g., `poolOptions.vmThreads.memoryLimit` → `vmMemoryLimit`)
109
- - [ ] Remove `threads.useAtomics` option
110
- - [ ] Update CI environment variables: `VITEST_MAX_THREADS` and `VITEST_MAX_FORKS` → `VITEST_MAX_WORKERS`
111
-
112
- #### 1.3 Workspace to Projects Rename
113
-
114
- **Search Pattern**: `workspace` property in Vitest config files
115
-
116
- **Changes Required**:
117
-
118
- ```typescript
119
- // ❌ BEFORE (Vitest 3.x)
120
- export default defineConfig({
121
- test: {
122
- workspace: ['apps/*', 'libs/*'],
123
- },
124
- });
125
-
126
- // ✅ AFTER (Vitest 4.0)
127
- export default defineConfig({
128
- test: {
129
- projects: ['apps/*', 'libs/*'],
130
- },
131
- });
132
- ```
133
-
134
- **Action Items**:
135
-
136
- - [ ] Rename `workspace` property to `projects` in all config files
137
- - [ ] Remove external workspace file references (must be inline in config)
138
- - [ ] Update `poolMatchGlobs` to use `projects` pattern matching instead
139
- - [ ] Update `environmentMatchGlobs` to use `projects` pattern matching instead
140
-
141
- #### 1.4 Browser Configuration
142
-
143
- **Search Pattern**: `browser.provider`, `browser.testerScripts`, imports from `@vitest/browser`
144
-
145
- **Changes Required**:
146
-
147
- ```typescript
148
- // ❌ BEFORE (Vitest 3.x)
149
- export default defineConfig({
150
- test: {
151
- browser: {
152
- enabled: true,
153
- provider: 'playwright', // String value
154
- testerScripts: ['./setup.js'],
155
- },
156
- },
157
- });
158
-
159
- // Import changes
160
- import { page } from '@vitest/browser';
161
-
162
- // ✅ AFTER (Vitest 4.0)
163
- export default defineConfig({
164
- test: {
165
- browser: {
166
- enabled: true,
167
- provider: { name: 'playwright' }, // Object value
168
- testerHtmlPath: './test-setup.html', // Renamed from testerScripts
169
- },
170
- },
171
- });
172
-
173
- // Import changes
174
- import { page } from 'vitest/browser';
175
- ```
176
-
177
- **Action Items**:
178
-
179
- - [ ] Convert `browser.provider` string values to object format: `{ name: 'provider-name' }`
180
- - [ ] Replace `browser.testerScripts` with `browser.testerHtmlPath`
181
- - [ ] Update all imports from `@vitest/browser` to `vitest/browser`
182
- - [ ] Remove `@vitest/browser` from dependencies if no longer needed
183
-
184
- #### 1.5 Deprecated Configuration Options
185
-
186
- **Search Pattern**: `deps.external`, `deps.inline`, `deps.fallbackCJS` in config files
187
-
188
- **Changes Required**:
189
-
190
- ```typescript
191
- // ❌ BEFORE (Vitest 3.x)
192
- export default defineConfig({
193
- test: {
194
- deps: {
195
- external: ['some-package'],
196
- inline: ['inline-package'],
197
- fallbackCJS: true,
198
- },
199
- },
200
- });
201
-
202
- // ✅ AFTER (Vitest 4.0)
203
- export default defineConfig({
204
- test: {
205
- server: {
206
- deps: {
207
- external: ['some-package'],
208
- inline: ['inline-package'],
209
- fallbackCJS: true,
210
- },
211
- },
212
- },
213
- });
214
- ```
215
-
216
- **Action Items**:
217
-
218
- - [ ] Move `deps.*` options under `server.deps` namespace
219
- - [ ] Remove `poolMatchGlobs` (use `projects` with conditions instead)
220
- - [ ] Remove `environmentMatchGlobs` (use `projects` with conditions instead)
221
-
222
- ### 2. Test Code Updates
223
-
224
- #### 2.1 Mock Function Name Changes
225
-
226
- **Search Pattern**: `.getMockName()` calls in test files
227
-
228
- **Changes Required**:
229
-
230
- ```typescript
231
- // ❌ BEFORE (Vitest 3.x)
232
- const mockFn = vi.fn();
233
- expect(mockFn.getMockName()).toBe('spy'); // Old default
234
-
235
- // ✅ AFTER (Vitest 4.0)
236
- const mockFn = vi.fn();
237
- expect(mockFn.getMockName()).toBe('vi.fn()'); // New default
238
-
239
- // If you need custom names, set them explicitly
240
- const namedMock = vi.fn().mockName('myCustomName');
241
- expect(namedMock.getMockName()).toBe('myCustomName');
242
- ```
243
-
244
- **Action Items**:
245
-
246
- - [ ] Update test assertions checking default mock names from `'spy'` to `'vi.fn()'`
247
- - [ ] Add explicit `.mockName()` calls where specific names are required
248
-
249
- #### 2.2 Mock Invocation Call Order
250
-
251
- **Search Pattern**: `.mock.invocationCallOrder` in test files
252
-
253
- **Changes Required**:
254
-
255
- ```typescript
256
- // ❌ BEFORE (Vitest 3.x)
257
- const mockFn = vi.fn();
258
- mockFn();
259
- expect(mockFn.mock.invocationCallOrder[0]).toBe(0); // Started at 0
260
-
261
- // ✅ AFTER (Vitest 4.0)
262
- const mockFn = vi.fn();
263
- mockFn();
264
- expect(mockFn.mock.invocationCallOrder[0]).toBe(1); // Now starts at 1 (Jest-compatible)
265
- ```
266
-
267
- **Action Items**:
268
-
269
- - [ ] Update assertions on `invocationCallOrder` to account for 1-based indexing
270
- - [ ] Search for off-by-one errors in call order comparisons
271
-
272
- #### 2.3 Constructor Spies and Mocks
273
-
274
- **Search Pattern**: `vi.spyOn` on constructors, `vi.fn()` used as constructors
275
-
276
- **Changes Required**:
277
-
278
- ```typescript
279
- // ❌ BEFORE (Vitest 3.x) - Arrow function constructors might have worked
280
- const MockConstructor = vi.fn(() => ({ value: 42 }));
281
- new MockConstructor(); // May have worked in v3
282
-
283
- // ✅ AFTER (Vitest 4.0) - Must use function or class
284
- const MockConstructor = vi.fn(function () {
285
- return { value: 42 };
286
- });
287
- new MockConstructor(); // Correctly supports 'new'
288
-
289
- // Or use class syntax
290
- class MockClass {
291
- value = 42;
292
- }
293
- const MockConstructor = vi.fn(MockClass);
294
- ```
295
-
296
- **Action Items**:
297
-
298
- - [ ] Convert arrow function mocks used as constructors to `function` keyword or `class` syntax
299
- - [ ] Test all constructor spies to ensure `new` keyword works correctly
300
- - [ ] Update any mocks that expect constructor behavior
301
-
302
- #### 2.4 RestoreAllMocks Behavior
303
-
304
- **Search Pattern**: `vi.restoreAllMocks()` in test files
305
-
306
- **Changes Required**:
307
-
308
- ```typescript
309
- // ❌ BEFORE (Vitest 3.x)
310
- vi.mock('./module', () => ({ fn: vi.fn() }));
311
- vi.restoreAllMocks(); // Would restore automocks
312
-
313
- // ✅ AFTER (Vitest 4.0)
314
- vi.mock('./module', () => ({ fn: vi.fn() }));
315
- vi.restoreAllMocks(); // Only restores manual spies, NOT automocks
316
-
317
- // To reset automocks, use:
318
- vi.unmock('./module');
319
- // or
320
- vi.resetModules();
321
- ```
322
-
323
- **Action Items**:
324
-
325
- - [ ] Review all `vi.restoreAllMocks()` usage
326
- - [ ] Add explicit `vi.unmock()` or `vi.resetModules()` calls for automocked modules
327
- - [ ] Ensure test isolation is maintained after this change
328
-
329
- #### 2.5 SpyOn Return Value Changes
330
-
331
- **Search Pattern**: `vi.spyOn()` on already mocked functions
332
-
333
- **Changes Required**:
334
-
335
- ```typescript
336
- // ❌ BEFORE (Vitest 3.x)
337
- const mock = vi.fn();
338
- const spy = vi.spyOn({ method: mock }, 'method');
339
- // spy !== mock (created new spy)
340
-
341
- // ✅ AFTER (Vitest 4.0)
342
- const mock = vi.fn();
343
- const spy = vi.spyOn({ method: mock }, 'method');
344
- // spy === mock (returns same instance)
345
- ```
346
-
347
- **Action Items**:
348
-
349
- - [ ] Review code that creates spies on existing mocks
350
- - [ ] Remove redundant spy creation if same instance is returned
351
- - [ ] Update assertions that check spy identity
352
-
353
- #### 2.6 Automock Behavior Changes
354
-
355
- **Search Pattern**: `vi.mock()` with factory functions, `.mockRestore()` on automocks
356
-
357
- **Changes Required**:
358
-
359
- ```typescript
360
- // ❌ BEFORE (Vitest 3.x)
361
- vi.mock('./utils', () => ({
362
- get value() {
363
- return 42;
364
- }, // Would call getter
365
- }));
366
-
367
- import { value } from './utils';
368
- console.log(value); // Would execute getter logic
369
-
370
- // Restore might have worked
371
- const spy = vi.spyOn(obj, 'method');
372
- spy.mockRestore(); // Might work on automocks
373
-
374
- // ✅ AFTER (Vitest 4.0)
375
- vi.mock('./utils', () => ({
376
- get value() {
377
- return 42;
378
- },
379
- }));
380
-
381
- import { value } from './utils';
382
- console.log(value); // Returns undefined (doesn't call getter)
383
-
384
- // Explicitly return value if needed
385
- vi.mock('./utils', () => ({
386
- value: 42, // Not a getter
387
- }));
388
-
389
- // mockRestore no longer works on automocks
390
- const spy = vi.spyOn(obj, 'method');
391
- spy.mockRestore(); // Throws error if method is automocked
392
-
393
- // Use unmock instead
394
- vi.unmock('./module');
395
- ```
396
-
397
- **Action Items**:
398
-
399
- - [ ] Convert automocked getters to plain property values where needed
400
- - [ ] Remove `.mockRestore()` calls on automocked methods
401
- - [ ] Use `vi.unmock()` to clear automocks instead
402
- - [ ] Test instance method isolation (they now share state with prototype)
403
-
404
- #### 2.7 Settled Results Immediate Population
405
-
406
- **Search Pattern**: `.mock.settledResults` in test files
407
-
408
- **Changes Required**:
409
-
410
- ```typescript
411
- // ✅ AFTER (Vitest 4.0)
412
- const asyncMock = vi.fn(async () => 'result');
413
- const promise = asyncMock();
414
-
415
- // settledResults is immediately populated with 'incomplete' status
416
- expect(asyncMock.mock.settledResults[0]).toEqual({
417
- type: 'incomplete',
418
- value: undefined,
419
- });
420
-
421
- // After promise resolves
422
- await promise;
423
- expect(asyncMock.mock.settledResults[0]).toEqual({
424
- type: 'fulfilled',
425
- value: 'result',
426
- });
427
- ```
428
-
429
- **Action Items**:
430
-
431
- - [ ] Update tests that check `settledResults` before promise resolution
432
- - [ ] Handle `'incomplete'` status in assertions
433
- - [ ] Ensure tests properly await promises before checking settled results
434
-
435
- ### 3. Reporter and CLI Changes
436
-
437
- #### 3.1 Reporter API Changes
438
-
439
- **Search Pattern**: Custom reporters, `onCollected`, `onTaskUpdate`, `onFinished`
440
-
441
- **Changes Required**:
442
-
443
- ```typescript
444
- // ❌ BEFORE (Vitest 3.x)
445
- export default {
446
- onCollected(files) {
447
- // Handle collected files
448
- },
449
- onTaskUpdate(task) {
450
- // Handle task update
451
- },
452
- onFinished(files) {
453
- // Handle completion
454
- },
455
- };
456
-
457
- // ✅ AFTER (Vitest 4.0)
458
- // Use new reporter API - consult Vitest 4 docs for replacement methods
459
- ```
460
-
461
- **Action Items**:
462
-
463
- - [ ] Review custom reporters for removed API usage
464
- - [ ] Consult Vitest 4 documentation for new reporter API
465
- - [ ] Update or rewrite custom reporters to use new APIs
466
-
467
- #### 3.2 Built-in Reporter Changes
468
-
469
- **Search Pattern**: `reporters: ['basic']`, `reporters: ['verbose']`
470
-
471
- **Changes Required**:
472
-
473
- ```typescript
474
- // ❌ BEFORE (Vitest 3.x)
475
- export default defineConfig({
476
- test: {
477
- reporters: ['basic'],
478
- },
479
- });
480
-
481
- // ✅ AFTER (Vitest 4.0)
482
- export default defineConfig({
483
- test: {
484
- reporters: [['default', { summary: false }]], // Equivalent to 'basic'
485
- },
486
- });
487
-
488
- // For verbose (tree output)
489
- reporters: ['tree']; // Use 'tree' for hierarchical output
490
- ```
491
-
492
- **Action Items**:
493
-
494
- - [ ] Replace `'basic'` reporter with `['default', { summary: false }]`
495
- - [ ] Replace `'verbose'` reporter with `'tree'` for hierarchical output
496
- - [ ] Update CI configuration if reporters are specified there
497
-
498
- ### 4. Snapshot Changes
499
-
500
- #### 4.1 Custom Elements Shadow Root
501
-
502
- **Search Pattern**: Snapshot tests involving custom elements or Web Components
503
-
504
- **Changes Required**:
505
-
506
- ```typescript
507
- // ✅ AFTER (Vitest 4.0)
508
- // Shadow root contents now printed by default in snapshots
509
-
510
- // If you want old behavior (don't print shadow root):
511
- export default defineConfig({
512
- test: {
513
- printShadowRoot: false,
514
- },
515
- });
516
- ```
517
-
518
- **Action Items**:
519
-
520
- - [ ] Review snapshot tests for custom elements
521
- - [ ] Update snapshots if shadow root contents are now included
522
- - [ ] Add `printShadowRoot: false` if old behavior is required
523
-
524
- ### 5. Environment Variable Updates
525
-
526
- **Search Pattern**: CI/CD configuration files, `.env` files, documentation
527
-
528
- **Changes Required**:
529
-
530
- ```bash
531
- # ❌ BEFORE (Vitest 3.x)
532
- VITEST_MAX_THREADS=4
533
- VITEST_MAX_FORKS=2
534
- VITE_NODE_DEPS_MODULE_DIRECTORIES=/custom/path
535
-
536
- # ✅ AFTER (Vitest 4.0)
537
- VITEST_MAX_WORKERS=4
538
- VITEST_MODULE_DIRECTORIES=/custom/path
539
- ```
540
-
541
- **Action Items**:
542
-
543
- - [ ] Update CI/CD pipeline environment variables
544
- - [ ] Update `.env` files
545
- - [ ] Update documentation referencing old environment variables
546
- - [ ] Search for `VITEST_MAX_THREADS`, `VITEST_MAX_FORKS`, `VITE_NODE_DEPS_MODULE_DIRECTORIES`
547
-
548
- ### 6. Advanced: Module Runner Changes
549
-
550
- **Search Pattern**: `vitest/execute`, `__vitest_executor`, `vite-node`
551
-
552
- **Changes Required**:
553
-
554
- ```typescript
555
- // ❌ BEFORE (Vitest 3.x)
556
- import { execute } from 'vitest/execute';
557
- // Access to __vitest_executor
558
-
559
- // ✅ AFTER (Vitest 4.0)
560
- // Use Vite's Module Runner API instead
561
- // Consult Vite Module Runner documentation
562
- ```
563
-
564
- **Action Items**:
565
-
566
- - [ ] If using `vitest/execute`, migrate to Vite Module Runner
567
- - [ ] Remove dependencies on `__vitest_executor`
568
- - [ ] Update custom pool implementations (complete rewrite needed)
569
-
570
- ### 7. Type Definition Updates
571
-
572
- **Search Pattern**: TypeScript imports from `vitest`, type errors after upgrade
573
-
574
- **Changes Required**:
575
-
576
- ```typescript
577
- // All deprecated type exports removed
578
- // If you get TypeScript errors about missing types:
579
- // - Check if you're using deprecated type names
580
- // - Update to current type names from Vitest 4 API
581
- // - Remove explicit @types/node if it was only needed due to Vitest bug
582
- ```
583
-
584
- **Action Items**:
585
-
586
- - [ ] Run TypeScript compilation on all test files
587
- - [ ] Fix any type errors related to removed Vitest type definitions
588
- - [ ] Review `@types/node` usage (may no longer be accidentally included)
589
-
590
- ## Post-Migration Validation
591
-
592
- ### 1. Run Tests Per Project
593
-
594
- ```bash
595
- # Test each project individually
596
- nx run-many -t test -p PROJECT_NAME
597
- ```
598
-
599
- ### 2. Run All Tests
600
-
601
- ```bash
602
- # Run tests across all affected projects
603
- nx affected -t test
604
- ```
605
-
606
- ### 3. Check Coverage
607
-
608
- ```bash
609
- # Verify coverage generation works with new config
610
- nx affected -t test --coverage
611
- ```
612
-
613
- ### 4. Validate CI Pipeline
614
-
615
- ```bash
616
- # Run full CI validation
617
- nx prepush
618
- ```
619
-
620
- ### 5. Review Migration Checklist
621
-
622
- - [ ] All configuration files updated
623
- - [ ] All test files pass
624
- - [ ] Coverage reports generate correctly
625
- - [ ] CI/CD pipeline runs successfully
626
- - [ ] Environment variables updated
627
- - [ ] Documentation updated
628
- - [ ] No deprecated API warnings in console
629
-
630
- ## Common Issues and Solutions
631
-
632
- ### Issue: Coverage includes too many files
633
-
634
- **Solution**: Add explicit `coverage.include` patterns to match your source files
635
-
636
- ### Issue: Tests fail with "arrow function constructors not supported"
637
-
638
- **Solution**: Convert arrow functions used as constructors to `function` keyword or `class` syntax
639
-
640
- ### Issue: Automocks not resetting between tests
641
-
642
- **Solution**: Use `vi.unmock()` or `vi.resetModules()` instead of `vi.restoreAllMocks()`
643
-
644
- ### Issue: Mock call order assertions failing
645
-
646
- **Solution**: Update to 1-based indexing for `invocationCallOrder`
647
-
648
- ### Issue: Browser tests failing after upgrade
649
-
650
- **Solution**: Check browser provider is object format and imports use `vitest/browser`
651
-
652
- ### Issue: TypeScript errors in test files
653
-
654
- **Solution**: Update to new type definitions and remove usage of deprecated types
655
-
656
- ## Files to Review
657
-
658
- Create a checklist of all files that need review:
659
-
660
- ```bash
661
- # Configuration files
662
- find . -name "vitest.config.*" -o -name "vitest.workspace.*"
663
- find . -name "project.json" -exec grep -l "vitest" {} \;
664
-
665
- # Test files
666
- find . -name "*.spec.*" -o -name "*.test.*"
667
-
668
- # Files with mock usage
669
- rg "vi\.(fn|spyOn|mock|restoreAllMocks)" --type ts --type tsx --type js
670
-
671
- # Files with coverage config
672
- rg "coverage\.(all|extensions|ignoreEmptyLines)" --type ts --type js
673
-
674
- # CI configuration
675
- find . -name ".github/workflows/*.yml" -o -name ".gitlab-ci.yml" -o -name "azure-pipelines.yml"
676
- ```
677
-
678
- ## Migration Strategy for Large Workspaces
679
-
680
- 1. **Migrate in phases**: Start with a small project, validate, then expand
681
- 2. **Use feature branches**: Create separate branches for different migration aspects
682
- 3. **Run tests frequently**: After each configuration change, run affected tests
683
- 4. **Document issues**: Keep track of project-specific issues and solutions
684
- 5. **Automate where possible**: Create codemods for repetitive changes
685
-
686
- ## Useful Commands During Migration
687
-
688
- ```bash
689
- # Find all vitest configurations
690
- nx show projects --with-target test
691
-
692
- # Test specific project after changes
693
- nx test PROJECT_NAME
694
-
695
- # Test all affected
696
- nx affected -t test
697
-
698
- # View project details
699
- nx show project PROJECT_NAME --web
700
-
701
- # Clear Nx cache if needed
702
- nx reset
703
- ```
704
-
705
- ## Guard Rails
706
-
707
- DO NOT
708
-
709
- - Force tests to pass by removing test logic and replacing it with `expect(true).toBe(true)`
710
- - Remove assertions
711
- - Add additional mocks that force tests to pass
712
-
713
- ---
714
-
715
- ## Notes for LLM Execution
716
-
717
- When executing this migration:
718
-
719
- 1. **Work systematically**: Complete one category before moving to the next
720
- 2. **Test after each change**: Don't batch all changes without validation
721
- 3. **Keep user informed**: Report progress through each section
722
- 4. **Handle errors promptly**: If tests fail, fix immediately before proceeding
723
- 5. **Update documentation**: Note any workspace-specific patterns or issues
724
- 6. **Create meaningful commits**: Group related changes together with clear messages
725
- 7. **Use TodoWrite tool**: Track migration progress for visibility
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function createAiInstructionsForVite8(tree: Tree): Promise<string[]>;
3
- //# sourceMappingURL=create-ai-instructions-for-vite-8.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-ai-instructions-for-vite-8.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/migrations/update-23-0-0/create-ai-instructions-for-vite-8.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,wBAA8B,4BAA4B,CAAC,IAAI,EAAE,IAAI,qBAepE"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = createAiInstructionsForVite8;
4
- const path_1 = require("path");
5
- const fs_1 = require("fs");
6
- async function createAiInstructionsForVite8(tree) {
7
- const pathToAiInstructions = (0, path_1.join)(__dirname, 'files', 'ai-instructions-for-vite-8.md');
8
- if (!(0, fs_1.existsSync)(pathToAiInstructions)) {
9
- return;
10
- }
11
- const contents = (0, fs_1.readFileSync)(pathToAiInstructions);
12
- tree.write('tools/ai-migrations/MIGRATE_VITE_8.md', contents);
13
- return [
14
- `We created 'tools/ai-migrations/MIGRATE_VITE_8.md' with instructions for an AI Agent to help migrate your Vite projects to Vite 8.`,
15
- ];
16
- }
@@ -1,250 +0,0 @@
1
- # Vite 8 Migration Instructions for LLM
2
-
3
- ## Overview
4
-
5
- These instructions guide you through migrating an Nx workspace from Vite 7 to Vite 8. Vite 8 swaps Rollup for Rolldown as its bundler and updates a number of plugin APIs. Work through each section in order and run tests after each change.
6
-
7
- ## Pre-Migration Checklist
8
-
9
- 1. **Identify all Vite-using projects**:
10
-
11
- ```bash
12
- nx show projects --with-target build
13
- nx show projects --with-target serve
14
- ```
15
-
16
- 2. **Locate all Vite configuration files**:
17
- - Search for `vite.config.{ts,js,mts,mjs,cts,cjs}`
18
- - Check `project.json` files for inline Vite-related options
19
-
20
- 3. **Cypress Component Testing**: Cypress >= 15.14.0 supports Vite 8. The `nx migrate` step bumps Cypress automatically. If you have explicitly pinned Cypress below 15.14.0, upgrade it before bumping Vite.
21
-
22
- ## Migration Steps by Category
23
-
24
- ### 1. Rename `rollupOptions` to `rolldownOptions`
25
-
26
- The `nx migrate` codemod handles this automatically for `vite.config.{ts,js,mts,mjs,cts,cjs}` files. If you have `rollupOptions` declared elsewhere (e.g., in helper modules imported by your config), rename them by hand.
27
-
28
- **Search Pattern**: `rollupOptions` in any TypeScript/JavaScript file
29
-
30
- ```typescript
31
- // ❌ BEFORE (Vite 7)
32
- export default defineConfig({
33
- build: {
34
- rollupOptions: {
35
- external: ['react'],
36
- output: { manualChunks: { vendor: ['react', 'react-dom'] } },
37
- },
38
- },
39
- });
40
-
41
- // ✅ AFTER (Vite 8)
42
- export default defineConfig({
43
- build: {
44
- rolldownOptions: {
45
- external: ['react'],
46
- output: { manualChunks: { vendor: ['react', 'react-dom'] } },
47
- },
48
- },
49
- });
50
- ```
51
-
52
- **Action Items**:
53
-
54
- - [ ] Verify the codemod picked up every config file (`rg "rollupOptions"` should return zero hits inside vite configs)
55
- - [ ] Rename any `rollupOptions` in helper modules or shared config builders
56
- - [ ] Update CI scripts that parse `build.rollupOptions` (e.g., custom bundle-size assertions)
57
-
58
- ### 2. `@vitejs/plugin-react` v6 (Oxc Replaces Babel)
59
-
60
- `@vitejs/plugin-react@^6` is required for Vite 8 and uses [Oxc](https://oxc.rs/) instead of Babel for JSX transformation. The plugin's `babel` option is gone.
61
-
62
- ```typescript
63
- // ❌ BEFORE (Vite 7, plugin-react v4)
64
- import react from '@vitejs/plugin-react';
65
-
66
- export default defineConfig({
67
- plugins: [
68
- react({
69
- babel: {
70
- plugins: ['babel-plugin-styled-components'],
71
- },
72
- }),
73
- ],
74
- });
75
-
76
- // ✅ AFTER (Vite 8, plugin-react v6)
77
- import react from '@vitejs/plugin-react';
78
-
79
- export default defineConfig({
80
- plugins: [react()],
81
- });
82
- ```
83
-
84
- **Action Items**:
85
-
86
- - [ ] Remove `babel` options from `react()` plugin invocations
87
- - [ ] If you depended on a Babel plugin (e.g., styled-components, emotion, relay), find an Oxc-compatible replacement or switch to `@vitejs/plugin-react-swc` (still Babel-free). There is no drop-in for arbitrary Babel plugins.
88
- - [ ] If you cannot drop your Babel plugin, stay on Vite 7 + plugin-react v4 for now (see "Project-Level Vite 7 Pinning")
89
- - [ ] Run `pnpm install` (or your package manager equivalent) so the new plugin-react version resolves
90
-
91
- ### 3. Angular + Vitest: Add `@oxc-project/runtime`
92
-
93
- `@angular/build` depends on `rolldown`, which injects `@oxc-project/runtime` helpers at transform time but does not declare it as a dependency. Angular projects using Vitest will fail at runtime unless `@oxc-project/runtime` is installed explicitly.
94
-
95
- **Search Pattern**: Projects using both `@angular/build` and Vitest
96
-
97
- ```bash
98
- rg "@angular/build" package.json
99
- rg "@nx/vitest:test|@nx/vite:test" --type json
100
- ```
101
-
102
- **Action Items**:
103
-
104
- - [ ] For each Angular project with Vitest, add `@oxc-project/runtime` to root `devDependencies`
105
- - [ ] Run `pnpm install` (or equivalent)
106
- - [ ] Run the project's tests to confirm the helper resolves at runtime
107
-
108
- ### 4. Type Resolution Under `moduleResolution: "node"`
109
-
110
- Vite 8 ships its types only via conditional `exports` (it dropped the top-level `types` field that Vite 7 carried), which TypeScript cannot resolve under `moduleResolution: "node"`. Symptoms include type errors on `defineConfig`, `UserConfig`, or plugin return types.
111
-
112
- **Action Items**:
113
-
114
- - [ ] Update affected `tsconfig*.json` files: `"moduleResolution": "bundler"` (recommended) or `"node16"`/`"nodenext"`
115
- - [ ] If you cannot change `moduleResolution`, narrow the impact with explicit `as any` casts at vite imports. The Nx-generated configs already do this in a handful of places.
116
- - [ ] Run `tsc --noEmit` after the change to confirm types resolve cleanly
117
-
118
- ### 5. Bundle Validation Scripts
119
-
120
- Rolldown produces different chunk and module counts than Rollup for the same input. Custom build validation (e.g., "bundle has exactly N chunks") will need to be re-baselined.
121
-
122
- **Action Items**:
123
-
124
- - [ ] Identify scripts that assert chunk/module counts or names
125
- - [ ] Re-run the build and update expected values
126
- - [ ] Prefer asserting on size budgets over exact counts going forward
127
-
128
- ### 6. Project-Level Vite 7 Pinning (Custom Babel Plugins)
129
-
130
- If a project depends on a Babel plugin that has no Oxc equivalent, pin that project to Vite 7.
131
-
132
- ```jsonc
133
- // package.json (workspace root)
134
- {
135
- "devDependencies": {
136
- "vite": "^7.1.0",
137
- "@vitejs/plugin-react": "^4.3.0",
138
- },
139
- }
140
- ```
141
-
142
- If only some projects need to stay on 7 while the rest move to 8, use your package manager's overrides feature:
143
-
144
- - pnpm: `pnpm.overrides` in root `package.json`
145
- - npm/yarn: `overrides`/`resolutions`
146
-
147
- **Action Items**:
148
-
149
- - [ ] Document which projects are pinned to Vite 7 and why
150
- - [ ] Track Oxc plugin equivalents so you can unpin later
151
-
152
- ## Post-Migration Validation
153
-
154
- ### 1. Run Tests Per Project
155
-
156
- ```bash
157
- nx run-many -t test -p PROJECT_NAME
158
- ```
159
-
160
- ### 2. Build All Affected Projects
161
-
162
- ```bash
163
- nx affected -t build
164
- ```
165
-
166
- ### 3. Validate Dev Server
167
-
168
- ```bash
169
- nx serve PROJECT_NAME
170
- ```
171
-
172
- Open the app and verify HMR still works for changes in source files.
173
-
174
- ### 4. Validate CI Pipeline
175
-
176
- ```bash
177
- nx prepush
178
- ```
179
-
180
- ### 5. Review Migration Checklist
181
-
182
- - [ ] All `rollupOptions` references renamed to `rolldownOptions`
183
- - [ ] `@vitejs/plugin-react` upgraded to v6 (or pinned to v4 with a documented reason)
184
- - [ ] No `babel: { ... }` options remain in `react()` calls (or those projects are pinned to Vite 7)
185
- - [ ] Angular + Vitest projects have `@oxc-project/runtime` installed
186
- - [ ] Cypress upgraded by `nx migrate` (>= 15.14.0 for Vite 8 support)
187
- - [ ] `tsc --noEmit` passes on all affected projects
188
- - [ ] Build, test, and dev-server commands all succeed
189
-
190
- ## Common Issues and Solutions
191
-
192
- ### Issue: `Cannot find name 'rollupOptions'` or build options ignored
193
-
194
- **Solution**: Rename to `rolldownOptions`. Vite 8 still accepts `rollupOptions` as a deprecated alias (it copies the value to `rolldownOptions` and logs a deprecation warning), but mixing both at the same level may cause precedence surprises (`rolldownOptions` wins).
195
-
196
- ### Issue: Babel plugin no longer applied (e.g., styled-components classNames missing)
197
-
198
- **Solution**: `@vitejs/plugin-react@6` removed Babel. Find an Oxc-compatible alternative, switch to `@vitejs/plugin-react-swc`, or pin to Vite 7 + plugin-react v4.
199
-
200
- ### Issue: Angular + Vitest fails with `Cannot find module '@oxc-project/runtime/...'`
201
-
202
- **Solution**: Add `@oxc-project/runtime` to root `devDependencies` and reinstall.
203
-
204
- ### Issue: Type errors on `defineConfig`, `UserConfig`, or `Plugin` imports from vite
205
-
206
- **Solution**: Set `moduleResolution: "bundler"` in your tsconfig (or `nodenext` if you need Node-style resolution).
207
-
208
- ### Issue: Cypress CT fails to start under Vite 8
209
-
210
- **Solution**: Confirm `cypress >= 15.14.0` is installed (Vite 8 support landed in that release). `nx migrate` bumps Cypress automatically; if you pinned it lower in `package.json`, remove the pin and reinstall.
211
-
212
- ### Issue: Bundle-size or chunk-count assertions fail after upgrade
213
-
214
- **Solution**: Rolldown chunks differently than Rollup. Re-baseline expected values.
215
-
216
- ## Files to Review
217
-
218
- ```bash
219
- # Vite config files
220
- find . -name "vite.config.*" -not -path "*/node_modules/*"
221
-
222
- # Cypress component testing setup
223
- rg "@nx/(angular|react|next|remix)/plugins/component-testing"
224
-
225
- # Babel plugin usage in plugin-react
226
- rg "@vitejs/plugin-react.*babel|babel:\s*\{" --type ts --type js
227
-
228
- # Angular projects with Vitest
229
- rg "@angular/build" -l package.json
230
- ```
231
-
232
- ## Guard Rails
233
-
234
- DO NOT
235
-
236
- - Force tests to pass by removing assertions or replacing them with `expect(true).toBe(true)`
237
- - Strip `react()` plugin options without finding an equivalent for what they did
238
- - Roll Cypress back below 15.14.0 after the migrate. Older Cypress fails to start under Vite 8.
239
-
240
- ---
241
-
242
- ## Notes for LLM Execution
243
-
244
- When executing this migration:
245
-
246
- 1. **Work systematically**: Complete one category before moving to the next
247
- 2. **Test after each change**: Build and test affected projects after each step
248
- 3. **Keep user informed**: Report which categories applied and which were skipped
249
- 4. **Use TodoWrite tool**: Track migration progress for visibility
250
- 5. **Stop and ask** if a project depends on a Babel plugin with no Oxc equivalent. Pinning to Vite 7 is a workspace decision.