@nx/vite 24.0.0-beta.1 → 24.0.0-beta.3

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.
Files changed (67) hide show
  1. package/dist/executors.d.ts +0 -3
  2. package/dist/executors.js +0 -7
  3. package/dist/plugins/nx-copy-assets.plugin.d.ts +4 -5
  4. package/dist/plugins/nx-copy-assets.plugin.js +5 -49
  5. package/dist/plugins/nx-tsconfig-paths.plugin.d.ts +5 -7
  6. package/dist/plugins/nx-tsconfig-paths.plugin.js +6 -247
  7. package/dist/src/generators/configuration/configuration.js +2 -39
  8. package/dist/src/generators/configuration/schema.d.ts +0 -1
  9. package/dist/src/generators/convert-to-inferred/lib/build-post-target-transformer.d.ts +0 -1
  10. package/dist/src/generators/convert-to-inferred/lib/build-post-target-transformer.js +3 -66
  11. package/dist/src/generators/init/init.js +20 -32
  12. package/dist/src/generators/init/schema.d.ts +0 -1
  13. package/dist/src/generators/init/schema.json +1 -1
  14. package/dist/src/generators/setup-paths-plugin/schema.d.ts +0 -1
  15. package/dist/src/generators/setup-paths-plugin/schema.json +2 -2
  16. package/dist/src/generators/setup-paths-plugin/setup-paths-plugin.js +16 -91
  17. package/dist/src/migrations/update-23-0-0/ai-instructions-for-vitest-3.md +5 -5
  18. package/dist/src/migrations/update-23-0-0/ai-instructions-for-vitest-4.md +6 -6
  19. package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +12 -0
  20. package/dist/src/migrations/update-24-0-0/migrate-config-helpers.md +86 -0
  21. package/dist/src/migrations/update-24-0-0/migrate-nx-vite-ts-paths.d.ts +2 -0
  22. package/dist/src/migrations/update-24-0-0/migrate-nx-vite-ts-paths.js +154 -0
  23. package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.d.ts +4 -0
  24. package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.js +11 -0
  25. package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.md +37 -0
  26. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
  27. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +46 -0
  28. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +71 -0
  29. package/dist/src/plugins/plugin.d.ts +9 -5
  30. package/dist/src/plugins/plugin.js +34 -45
  31. package/dist/src/utils/deprecation.d.ts +2 -9
  32. package/dist/src/utils/deprecation.js +5 -35
  33. package/dist/src/utils/e2e-web-server-info-utils.d.ts +2 -2
  34. package/dist/src/utils/e2e-web-server-info-utils.js +4 -4
  35. package/dist/src/utils/executor-utils.d.ts +0 -10
  36. package/dist/src/utils/executor-utils.js +0 -51
  37. package/dist/src/utils/generator-utils.d.ts +0 -10
  38. package/dist/src/utils/generator-utils.js +36 -106
  39. package/dist/src/utils/options-utils.d.ts +0 -16
  40. package/dist/src/utils/options-utils.js +0 -73
  41. package/dist/src/utils/versions.d.ts +2 -0
  42. package/dist/src/utils/versions.js +3 -1
  43. package/dist/src/utils/vite-config-edit-utils.d.ts +9 -1
  44. package/dist/src/utils/vite-config-edit-utils.js +143 -1
  45. package/executors.json +2 -34
  46. package/generators.json +1 -1
  47. package/migrations.json +19 -0
  48. package/package.json +6 -7
  49. package/dist/src/executors/build/build.impl.d.ts +0 -11
  50. package/dist/src/executors/build/build.impl.js +0 -205
  51. package/dist/src/executors/build/compat.d.ts +0 -2
  52. package/dist/src/executors/build/compat.js +0 -6
  53. package/dist/src/executors/build/schema.json +0 -82
  54. package/dist/src/executors/dev-server/compat.d.ts +0 -2
  55. package/dist/src/executors/dev-server/compat.js +0 -6
  56. package/dist/src/executors/dev-server/dev-server.impl.d.ts +0 -7
  57. package/dist/src/executors/dev-server/dev-server.impl.js +0 -137
  58. package/dist/src/executors/dev-server/schema.json +0 -40
  59. package/dist/src/executors/preview-server/compat.d.ts +0 -2
  60. package/dist/src/executors/preview-server/compat.js +0 -6
  61. package/dist/src/executors/preview-server/preview-server.impl.d.ts +0 -7
  62. package/dist/src/executors/preview-server/preview-server.impl.js +0 -184
  63. package/dist/src/executors/preview-server/schema.json +0 -44
  64. package/dist/src/utils/nx-tsconfig-paths-find-file.d.ts +0 -2
  65. package/dist/src/utils/nx-tsconfig-paths-find-file.js +0 -22
  66. package/dist/src/utils/nx-tsconfig-paths-load-file.d.ts +0 -12
  67. package/dist/src/utils/nx-tsconfig-paths-load-file.js +0 -71
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = update;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const internal_1 = require("@nx/devkit/internal");
6
+ const viteExecutors = [
7
+ '@nx/vite:build',
8
+ '@nx/vite:dev-server',
9
+ '@nx/vite:preview-server',
10
+ '@nrwl/vite:build',
11
+ '@nrwl/vite:dev-server',
12
+ '@nrwl/vite:preview-server',
13
+ ];
14
+ // Earlier @nx/vite migrations rewrite test targets to @nx/vitest:test, but on
15
+ // pnpm @nx/vitest is only transitive, so its own migration may never run.
16
+ const vitestExecutors = ['@nx/vitest:test', '@nx/vite:test', '@nrwl/vite:test'];
17
+ function update(tree) {
18
+ return (0, internal_1.migrateRemovedExecutors)(tree, [...viteExecutors, ...vitestExecutors], async (tree, options) => {
19
+ const executors = [...(0, devkit_1.getProjects)(tree).values()].flatMap((project) => Object.values(project.targets ?? {}).map((target) => target.executor));
20
+ if (executors.some((executor) => viteExecutors.includes(executor))) {
21
+ const { convertToInferred } = require('../../generators/convert-to-inferred/convert-to-inferred');
22
+ // The callback only prints the options the converter could not carry
23
+ // over; migrateRemovedExecutors discards it.
24
+ await skipUnmigrated(async () => {
25
+ const flushLogs = await convertToInferred(tree, options);
26
+ flushLogs();
27
+ });
28
+ }
29
+ if (executors.includes('@nx/vitest:test')) {
30
+ const { convertVitestToInferred } = require('@nx/vitest/internal');
31
+ await skipUnmigrated(() => convertVitestToInferred(tree, options));
32
+ }
33
+ });
34
+ }
35
+ // A converter that skips every target must not stop the other one; the
36
+ // leftover re-scan in migrateRemovedExecutors still names what it left.
37
+ async function skipUnmigrated(convert) {
38
+ try {
39
+ await convert();
40
+ }
41
+ catch (error) {
42
+ if (!(error instanceof internal_1.NoTargetsToMigrateError)) {
43
+ throw error;
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,71 @@
1
+ #### Convert `@nx/vite` and `@nx/vitest:test` targets to inferred tasks
2
+
3
+ Nx 24 removes the `@nx/vite:build`, `@nx/vite:dev-server` and `@nx/vite:preview-server` executors and their `@nrwl` aliases. The migration registers `@nx/vite/plugin` in `nx.json` and converts the targets that use those executors to inferred tasks. It moves build options into `vite.config.*`. It also converts `@nx/vitest:test` targets with the `@nx/vitest` converter, because `@nx/vitest` can be installed only as a transitive dependency and its own migration may not run. A target with nothing left to override is removed from project configuration. When several projects share the same remaining options, those options move to a `targetDefaults` entry scoped to the plugin. `targetDefaults` entries keyed by a removed executor are removed once no target uses that executor.
4
+
5
+ The migration lists the targets the converter cannot convert safely. In agentic runs, an AI prompt finishes them and validates the project graph.
6
+
7
+ #### Sample code changes
8
+
9
+ The `serve` and `preview` targets have no options that differ from the inferred targets, so they are removed.
10
+
11
+ ##### Before
12
+
13
+ ```json title="myapp/project.json"
14
+ {
15
+ "name": "myapp",
16
+ "targets": {
17
+ "build": {
18
+ "executor": "@nx/vite:build",
19
+ "outputs": ["{workspaceRoot}/dist/myapp"],
20
+ "options": {
21
+ "configFile": "myapp/vite.config.ts"
22
+ }
23
+ },
24
+ "serve": {
25
+ "executor": "@nx/vite:dev-server",
26
+ "options": {
27
+ "buildTarget": "myapp:build"
28
+ }
29
+ },
30
+ "preview": {
31
+ "executor": "@nx/vite:preview-server",
32
+ "options": {
33
+ "buildTarget": "myapp:build"
34
+ }
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ ##### After
41
+
42
+ ```json title="myapp/project.json"
43
+ {
44
+ "name": "myapp",
45
+ "targets": {
46
+ "build": {
47
+ "options": {
48
+ "config": "./vite.config.ts"
49
+ }
50
+ }
51
+ }
52
+ }
53
+ ```
54
+
55
+ ```json title="nx.json"
56
+ {
57
+ "plugins": [
58
+ {
59
+ "plugin": "@nx/vite/plugin",
60
+ "options": {
61
+ "buildTargetName": "build",
62
+ "devTargetName": "dev",
63
+ "previewTargetName": "preview",
64
+ "serveStaticTargetName": "serve-static",
65
+ "serveTargetName": "serve",
66
+ "typecheckTargetName": "typecheck"
67
+ }
68
+ }
69
+ ]
70
+ }
71
+ ```
@@ -8,12 +8,16 @@ export interface VitePluginOptions {
8
8
  devTargetName?: string;
9
9
  previewTargetName?: string;
10
10
  serveStaticTargetName?: string;
11
- typecheckTargetName?: string;
12
11
  /**
13
- * The compiler to use for type-checking. When unset, defaults to `vue-tsc`
14
- * for Vue projects (detected via the `vite:vue` plugin) and `tsc` otherwise.
15
- * Set to `tsgo` to use the TypeScript Go compiler (`@typescript/native-preview`),
16
- * or `vue-tsc` to force Vue-aware type-checking when auto-detection misses your setup.
12
+ * Name of the `vue-tsc` typecheck target inferred for Vue projects. Other
13
+ * projects get their typecheck target from `@nx/js/typescript`.
14
+ */
15
+ typecheckTargetName?: string | false;
16
+ /**
17
+ * The compiler used to typecheck Vue projects. Defaults to `vue-tsc` when the
18
+ * `vite:vue` plugin is detected. Set `vue-tsc` to force the target when
19
+ * detection misses your setup, or `tsc`/`tsgo` to skip it and rely on
20
+ * `@nx/js/typescript`.
17
21
  */
18
22
  compiler?: 'tsc' | 'tsgo' | 'vue-tsc';
19
23
  watchDepsTargetName?: string;
@@ -121,51 +121,40 @@ async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFi
121
121
  targets[options.serveStaticTargetName] = serveStaticTarget(options, isUsingTsSolutionSetup, namedInputs);
122
122
  }
123
123
  }
124
- if (tsConfigFiles.length) {
125
- const tsConfigToUse = ['tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json'].find((t) => tsConfigFiles.includes(t)) ?? tsConfigFiles[0];
126
- // Check if the project uses Vue plugin
127
- const hasVuePlugin = viteBuildConfig.plugins?.some((p) => p.name === 'vite:vue' || p.name === 'vite:vue2');
128
- // Explicit `compiler` option wins over inference so users can override
129
- // when their setup isn't detected (e.g. custom/non-standard Vue plugin).
130
- const resolvedCompiler = options.compiler ?? (hasVuePlugin ? 'vue-tsc' : 'tsc');
131
- const typeCheckCommand = resolvedCompiler;
132
- const typeCheckExternalDeps = resolvedCompiler === 'tsgo'
133
- ? ['@typescript/native-preview']
134
- : resolvedCompiler === 'vue-tsc'
135
- ? ['vue-tsc', 'typescript']
136
- : ['typescript'];
137
- targets[options.typecheckTargetName] = {
138
- cache: true,
139
- inputs: [
140
- ...('production' in namedInputs
141
- ? ['production', '^production']
142
- : ['default', '^default']),
143
- { externalDependencies: typeCheckExternalDeps },
144
- ],
145
- command: isUsingTsSolutionSetup
146
- ? `${typeCheckCommand} --build --emitDeclarationOnly`
147
- : `${typeCheckCommand} --noEmit -p ${tsConfigToUse}`,
148
- options: { cwd: (0, devkit_1.joinPathFragments)(projectRoot) },
149
- metadata: {
150
- description: `Runs type-checking for the project.`,
151
- technologies: hasVuePlugin ? ['typescript', 'vue'] : ['typescript'],
152
- help: {
153
- command: isUsingTsSolutionSetup
154
- ? `${pmc.exec} ${typeCheckCommand} --build --help`
155
- : `${pmc.exec} ${typeCheckCommand} -p ${tsConfigToUse} --help`,
156
- example: isUsingTsSolutionSetup
157
- ? { args: ['--force'] }
158
- : { options: { noEmit: true } },
159
- },
160
- },
161
- };
162
- if (isUsingTsSolutionSetup) {
163
- targets[options.typecheckTargetName].dependsOn = [
164
- `^${options.typecheckTargetName}`,
165
- ];
166
- targets[options.typecheckTargetName].syncGenerators = [
167
- '@nx/js:typescript-sync',
168
- ];
124
+ const hasVuePlugin = viteBuildConfig.plugins?.some((p) => p.name === 'vite:vue' || p.name === 'vite:vue2');
125
+ // @nx/js/typescript provides tsc typecheck targets but can't run vue-tsc.
126
+ const usesVueTsc = (options.compiler ?? (hasVuePlugin ? 'vue-tsc' : 'tsc')) === 'vue-tsc';
127
+ if (usesVueTsc &&
128
+ options.typecheckTargetName !== false &&
129
+ tsConfigFiles.length) {
130
+ const technologies = hasVuePlugin ? ['typescript', 'vue'] : ['typescript'];
131
+ const tsConfig = (0, internal_2.selectTypecheckTsConfig)(tsConfigFiles);
132
+ if (!isUsingTsSolutionSetup) {
133
+ if (tsConfig) {
134
+ targets[options.typecheckTargetName] = (0, internal_2.createTypecheckTarget)({
135
+ mode: 'noEmit',
136
+ projectRoot: (0, devkit_1.joinPathFragments)(projectRoot),
137
+ pmc,
138
+ tsConfig,
139
+ compiler: 'vue-tsc',
140
+ namedInputs,
141
+ technologies,
142
+ });
143
+ }
144
+ }
145
+ else if (tsConfigFiles.includes('tsconfig.json')) {
146
+ targets[options.typecheckTargetName] = (0, internal_2.createTypecheckTarget)({
147
+ mode: 'build',
148
+ projectRoot: (0, devkit_1.joinPathFragments)(projectRoot),
149
+ pmc,
150
+ compiler: 'vue-tsc',
151
+ targetName: options.typecheckTargetName,
152
+ buildTargetName: targets[options.buildTargetName]
153
+ ? options.buildTargetName
154
+ : undefined,
155
+ namedInputs,
156
+ technologies,
157
+ });
169
158
  }
170
159
  }
171
160
  (0, internal_2.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmc);
@@ -1,11 +1,4 @@
1
- export declare const VITE_BUILD_EXECUTOR_DEPRECATION_MESSAGE = "The `@nx/vite:build` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vite:convert-to-inferred` to migrate to the `@nx/vite/plugin` inferred targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.";
2
- export declare const VITE_DEV_SERVER_EXECUTOR_DEPRECATION_MESSAGE = "The `@nx/vite:dev-server` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vite:convert-to-inferred` to migrate to the `@nx/vite/plugin` inferred targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.";
3
- export declare const VITE_PREVIEW_SERVER_EXECUTOR_DEPRECATION_MESSAGE = "The `@nx/vite:preview-server` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vite:convert-to-inferred` to migrate to the `@nx/vite/plugin` inferred targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.";
4
- export declare function warnViteBuildExecutorDeprecation(): void;
5
- export declare function warnViteDevServerExecutorDeprecation(): void;
6
- export declare function warnVitePreviewServerExecutorDeprecation(): void;
7
- export declare function warnViteExecutorGenerating(): void;
8
- export declare const NX_VITE_TS_PATHS_DEPRECATION_MESSAGE = "The `nxViteTsPaths` plugin from `@nx/vite/plugins/nx-tsconfig-paths.plugin` is deprecated and will be removed in Nx v24. Replace it with `tsconfigPaths()` from the `vite-tsconfig-paths` package. See https://nx.dev/docs/technologies/build-tools/vite/guides/configure-vite for details.";
9
- export declare const NX_COPY_ASSETS_PLUGIN_DEPRECATION_MESSAGE = "The `nxCopyAssetsPlugin` plugin from `@nx/vite/plugins/nx-copy-assets.plugin` is deprecated and will be removed in Nx v24. Use Vite's native `publicDir` option or the `vite-plugin-static-copy` package instead. See https://nx.dev/docs/technologies/build-tools/vite/guides/configure-vite for details.";
1
+ export declare const NX_VITE_TS_PATHS_DEPRECATION_MESSAGE = "The `nxViteTsPaths` plugin from `@nx/vite/plugins/nx-tsconfig-paths.plugin` was removed in Nx v24. The remaining export is an inert compatibility stub and does not configure builds. Use native `resolve.tsconfigPaths` when supported by the installed Vite version, or a compatible `vite-tsconfig-paths` plugin. Follow the config-helper migration instructions generated by `nx migrate`.";
2
+ export declare const NX_COPY_ASSETS_PLUGIN_DEPRECATION_MESSAGE = "The `nxCopyAssetsPlugin` plugin from `@nx/vite/plugins/nx-copy-assets.plugin` was removed in Nx v24. The remaining export is an inert compatibility stub and does not configure builds. Preserve asset paths and watch behavior using native `publicDir`, a compatible `vite-plugin-static-copy`, or local configuration. Follow the config-helper migration instructions generated by `nx migrate`.";
10
3
  export declare function warnNxViteTsPathsDeprecation(): void;
11
4
  export declare function warnNxCopyAssetsPluginDeprecation(): void;
@@ -1,43 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NX_COPY_ASSETS_PLUGIN_DEPRECATION_MESSAGE = exports.NX_VITE_TS_PATHS_DEPRECATION_MESSAGE = exports.VITE_PREVIEW_SERVER_EXECUTOR_DEPRECATION_MESSAGE = exports.VITE_DEV_SERVER_EXECUTOR_DEPRECATION_MESSAGE = exports.VITE_BUILD_EXECUTOR_DEPRECATION_MESSAGE = void 0;
4
- exports.warnViteBuildExecutorDeprecation = warnViteBuildExecutorDeprecation;
5
- exports.warnViteDevServerExecutorDeprecation = warnViteDevServerExecutorDeprecation;
6
- exports.warnVitePreviewServerExecutorDeprecation = warnVitePreviewServerExecutorDeprecation;
7
- exports.warnViteExecutorGenerating = warnViteExecutorGenerating;
3
+ exports.NX_COPY_ASSETS_PLUGIN_DEPRECATION_MESSAGE = exports.NX_VITE_TS_PATHS_DEPRECATION_MESSAGE = void 0;
8
4
  exports.warnNxViteTsPathsDeprecation = warnNxViteTsPathsDeprecation;
9
5
  exports.warnNxCopyAssetsPluginDeprecation = warnNxCopyAssetsPluginDeprecation;
10
6
  const devkit_1 = require("@nx/devkit");
11
- // TODO(v24): Remove the @nx/vite:build, @nx/vite:dev-server, and
12
- // @nx/vite:preview-server executors. The inferred plugin (@nx/vite/plugin)
13
- // and the convert-to-inferred generator stay supported. (`@nx/vite:test`
14
- // is being deprecated in a separate change for the test-runner batch.)
15
- exports.VITE_BUILD_EXECUTOR_DEPRECATION_MESSAGE = 'The `@nx/vite:build` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vite:convert-to-inferred` to migrate to the `@nx/vite/plugin` inferred targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.';
16
- exports.VITE_DEV_SERVER_EXECUTOR_DEPRECATION_MESSAGE = 'The `@nx/vite:dev-server` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vite:convert-to-inferred` to migrate to the `@nx/vite/plugin` inferred targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.';
17
- exports.VITE_PREVIEW_SERVER_EXECUTOR_DEPRECATION_MESSAGE = 'The `@nx/vite:preview-server` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vite:convert-to-inferred` to migrate to the `@nx/vite/plugin` inferred targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.';
18
- function warnViteBuildExecutorDeprecation() {
19
- devkit_1.logger.warn(exports.VITE_BUILD_EXECUTOR_DEPRECATION_MESSAGE);
20
- }
21
- function warnViteDevServerExecutorDeprecation() {
22
- devkit_1.logger.warn(exports.VITE_DEV_SERVER_EXECUTOR_DEPRECATION_MESSAGE);
23
- }
24
- function warnVitePreviewServerExecutorDeprecation() {
25
- devkit_1.logger.warn(exports.VITE_PREVIEW_SERVER_EXECUTOR_DEPRECATION_MESSAGE);
26
- }
27
- // Fired when the @nx/vite:configuration generator is about to generate
28
- // targets that use the deprecated executors — i.e. when @nx/vite/plugin
29
- // isn't registered in nx.json. Surfaces the deprecation at generation time
30
- // rather than only when the user later runs the generated targets.
31
- function warnViteExecutorGenerating() {
32
- devkit_1.logger.warn('Generating targets that use the deprecated `@nx/vite:build`, `@nx/vite:dev-server`, and `@nx/vite:preview-server` executors. These executors will be removed in Nx v24. Run `nx g @nx/vite:convert-to-inferred` next to migrate these targets to the `@nx/vite/plugin` inferred plugin and prevent future generators from emitting executor targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.');
33
- }
34
- // TODO(v24): Remove `nxViteTsPaths` and `nxCopyAssetsPlugin` helpers.
35
- // The inferred `@nx/vite/plugin` already ensures projects extend the base
36
- // tsconfig, so the community `vite-tsconfig-paths` package handles path
37
- // resolution end-to-end. Asset copying is covered by Vite's native
38
- // `publicDir` option or the `vite-plugin-static-copy` package.
39
- exports.NX_VITE_TS_PATHS_DEPRECATION_MESSAGE = 'The `nxViteTsPaths` plugin from `@nx/vite/plugins/nx-tsconfig-paths.plugin` is deprecated and will be removed in Nx v24. Replace it with `tsconfigPaths()` from the `vite-tsconfig-paths` package. See https://nx.dev/docs/technologies/build-tools/vite/guides/configure-vite for details.';
40
- exports.NX_COPY_ASSETS_PLUGIN_DEPRECATION_MESSAGE = "The `nxCopyAssetsPlugin` plugin from `@nx/vite/plugins/nx-copy-assets.plugin` is deprecated and will be removed in Nx v24. Use Vite's native `publicDir` option or the `vite-plugin-static-copy` package instead. See https://nx.dev/docs/technologies/build-tools/vite/guides/configure-vite for details.";
7
+ // Helper behavior was removed in v24; exports remain only as inert stubs.
8
+ // Keep their imports loadable while existing Vite configs are migrated.
9
+ exports.NX_VITE_TS_PATHS_DEPRECATION_MESSAGE = 'The `nxViteTsPaths` plugin from `@nx/vite/plugins/nx-tsconfig-paths.plugin` was removed in Nx v24. The remaining export is an inert compatibility stub and does not configure builds. Use native `resolve.tsconfigPaths` when supported by the installed Vite version, or a compatible `vite-tsconfig-paths` plugin. Follow the config-helper migration instructions generated by `nx migrate`.';
10
+ exports.NX_COPY_ASSETS_PLUGIN_DEPRECATION_MESSAGE = 'The `nxCopyAssetsPlugin` plugin from `@nx/vite/plugins/nx-copy-assets.plugin` was removed in Nx v24. The remaining export is an inert compatibility stub and does not configure builds. Preserve asset paths and watch behavior using native `publicDir`, a compatible `vite-plugin-static-copy`, or local configuration. Follow the config-helper migration instructions generated by `nx migrate`.';
41
11
  let nxViteTsPathsWarned = false;
42
12
  let nxCopyAssetsPluginWarned = false;
43
13
  // Warn-once per process so users don't see the message repeated on every
@@ -1,3 +1,3 @@
1
1
  import { type Tree } from '@nx/devkit';
2
- export declare function getViteE2EWebServerInfo(tree: Tree, projectName: string, configFilePath: string, isPluginBeingAdded: boolean, e2ePortOverride?: number, e2eCIPortOverride?: number): Promise<import("@nx/devkit/internal").E2EWebServerDetails>;
3
- export declare function getReactRouterE2EWebServerInfo(tree: Tree, projectName: string, configFilePath: string, isPluginBeingAdded: boolean, e2ePortOverride?: number, e2eCIPortOverride?: number): Promise<import("@nx/devkit/internal").E2EWebServerDetails>;
2
+ export declare function getViteE2EWebServerInfo(tree: Tree, projectName: string, configFilePath: string, e2ePortOverride?: number, e2eCIPortOverride?: number): Promise<import("@nx/devkit/internal").E2EWebServerDetails>;
3
+ export declare function getReactRouterE2EWebServerInfo(tree: Tree, projectName: string, configFilePath: string, e2ePortOverride?: number, e2eCIPortOverride?: number): Promise<import("@nx/devkit/internal").E2EWebServerDetails>;
@@ -4,7 +4,7 @@ exports.getViteE2EWebServerInfo = getViteE2EWebServerInfo;
4
4
  exports.getReactRouterE2EWebServerInfo = getReactRouterE2EWebServerInfo;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const internal_1 = require("@nx/devkit/internal");
7
- async function getViteE2EWebServerInfo(tree, projectName, configFilePath, isPluginBeingAdded, e2ePortOverride, e2eCIPortOverride) {
7
+ async function getViteE2EWebServerInfo(tree, projectName, configFilePath, e2ePortOverride, e2eCIPortOverride) {
8
8
  const nxJson = (0, devkit_1.readNxJson)(tree);
9
9
  let e2ePort = e2ePortOverride ?? 4200;
10
10
  const devPort = (0, internal_1.readTargetDefaultsForTarget)('dev', nxJson.targetDefaults)
@@ -25,9 +25,9 @@ async function getViteE2EWebServerInfo(tree, projectName, configFilePath, isPlug
25
25
  defaultE2EWebServerAddress: `http://localhost:${e2ePort}`,
26
26
  defaultE2ECiBaseUrl: `http://localhost:${e2eCIPortOverride ?? 4300}`,
27
27
  defaultE2EPort: e2ePort,
28
- }, isPluginBeingAdded);
28
+ });
29
29
  }
30
- async function getReactRouterE2EWebServerInfo(tree, projectName, configFilePath, isPluginBeingAdded, e2ePortOverride, e2eCIPortOverride) {
30
+ async function getReactRouterE2EWebServerInfo(tree, projectName, configFilePath, e2ePortOverride, e2eCIPortOverride) {
31
31
  const e2ePort = e2ePortOverride ?? parseInt(process.env.PORT) ?? 4200;
32
32
  return await (0, internal_1.getE2EWebServerInfo)(tree, projectName, {
33
33
  plugin: '@nx/react/router-plugin',
@@ -40,5 +40,5 @@ async function getReactRouterE2EWebServerInfo(tree, projectName, configFilePath,
40
40
  defaultE2EWebServerAddress: `http://localhost:${e2ePort}`,
41
41
  defaultE2ECiBaseUrl: `http://localhost:${e2eCIPortOverride ?? 4200}`,
42
42
  defaultE2EPort: e2ePort,
43
- }, isPluginBeingAdded);
43
+ });
44
44
  }
@@ -1,11 +1 @@
1
- import { ExecutorContext } from '@nx/devkit';
2
- export declare function validateTypes(opts: {
3
- workspaceRoot: string;
4
- tsconfig: string;
5
- isVueProject?: boolean;
6
- }): Promise<void>;
7
- export declare function createBuildableTsConfig(projectRoot: string, options: {
8
- tsConfig?: string;
9
- buildLibsFromSource?: boolean;
10
- }, context: ExecutorContext): string;
11
1
  export declare function loadViteDynamicImport(): Promise<typeof import('vite')>;
@@ -1,57 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateTypes = validateTypes;
4
- exports.createBuildableTsConfig = createBuildableTsConfig;
5
3
  exports.loadViteDynamicImport = loadViteDynamicImport;
6
- const devkit_1 = require("@nx/devkit");
7
- const internal_1 = require("@nx/js/internal");
8
- const options_utils_1 = require("./options-utils");
9
- const node_child_process_1 = require("node:child_process");
10
- const js_1 = require("@nx/js");
11
- const path_1 = require("path");
12
- async function validateTypes(opts) {
13
- if (!opts.isVueProject) {
14
- const result = await (0, js_1.runTypeCheck)({
15
- workspaceRoot: opts.workspaceRoot,
16
- tsConfigPath: opts.tsconfig.startsWith(opts.workspaceRoot)
17
- ? opts.tsconfig
18
- : (0, path_1.join)(opts.workspaceRoot, opts.tsconfig),
19
- mode: 'noEmit',
20
- // TS 6 defaults rootDir to the tsconfig dir, so from-source workspace
21
- // libs (outside the project) trip TS6059. rootDir is emit-only and this
22
- // is noEmit, so widen it to the workspace root to clear the false error.
23
- rootDir: opts.workspaceRoot,
24
- });
25
- await (0, js_1.printDiagnostics)(result.errors, result.warnings);
26
- if (result.errors.length > 0) {
27
- throw new Error('Found type errors. See above.');
28
- }
29
- }
30
- else {
31
- const pm = (0, devkit_1.getPackageManagerCommand)();
32
- const cp = (0, node_child_process_1.execSync)(`${pm.exec} vue-tsc --noEmit -p ${opts.tsconfig} --composite false`, {
33
- cwd: opts.workspaceRoot,
34
- stdio: 'inherit',
35
- windowsHide: true,
36
- });
37
- }
38
- }
39
- function createBuildableTsConfig(projectRoot, options, context) {
40
- const tsConfig = options.tsConfig ?? (0, options_utils_1.getProjectTsConfigPath)(projectRoot);
41
- options['buildLibsFromSource'] ??= true;
42
- if (!options['buildLibsFromSource']) {
43
- const { dependencies } = (0, internal_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName,
44
- // When using incremental building and the serve target is called
45
- // we need to get the deps for the 'build' target instead.
46
- context.targetName === 'serve' ? 'build' : context.targetName, context.configurationName);
47
- // This tsconfig is used via the Vite ts paths plugin.
48
- // It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).
49
- const tmpTsConfigPath = (0, internal_1.createTmpTsConfig)(tsConfig, context.root, projectRoot, dependencies);
50
- process.env.NX_TSCONFIG_PATH = tmpTsConfigPath;
51
- return tmpTsConfigPath;
52
- }
53
- return tsConfig;
54
- }
55
4
  function loadViteDynamicImport() {
56
5
  return Function('return import("vite")')();
57
6
  }
@@ -10,16 +10,6 @@ export declare function findExistingJsBuildTargetInProject(targets: {
10
10
  supported?: string;
11
11
  unsupported?: string;
12
12
  };
13
- export declare function addBuildTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, target: string): void;
14
- export declare function addServeTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, target: string): void;
15
- /**
16
- * Adds a target for the preview server.
17
- *
18
- * @param tree
19
- * @param options
20
- * @param serveTarget An existing serve target.
21
- */
22
- export declare function addPreviewTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, serveTarget: string): void;
23
13
  export declare function editTsConfig(tree: Tree, options: ViteConfigurationGeneratorSchema): void;
24
14
  export declare function deleteWebpackConfig(tree: Tree, projectRoot: string, webpackConfigFilePath?: string): void;
25
15
  export declare function moveAndEditIndexHtml(tree: Tree, options: ViteConfigurationGeneratorSchema): void;
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findExistingJsBuildTargetInProject = findExistingJsBuildTargetInProject;
4
- exports.addBuildTarget = addBuildTarget;
5
- exports.addServeTarget = addServeTarget;
6
- exports.addPreviewTarget = addPreviewTarget;
7
4
  exports.editTsConfig = editTsConfig;
8
5
  exports.deleteWebpackConfig = deleteWebpackConfig;
9
6
  exports.moveAndEditIndexHtml = moveAndEditIndexHtml;
@@ -16,6 +13,8 @@ const internal_1 = require("@nx/devkit/internal");
16
13
  const devkit_1 = require("@nx/devkit");
17
14
  const internal_2 = require("@nx/js/internal");
18
15
  const vite_config_edit_utils_1 = require("./vite-config-edit-utils");
16
+ const version_utils_1 = require("./version-utils");
17
+ const versions_1 = require("./versions");
19
18
  function findExistingJsBuildTargetInProject(targets) {
20
19
  const output = {};
21
20
  const supportedExecutors = {
@@ -63,93 +62,6 @@ function findExistingJsBuildTargetInProject(targets) {
63
62
  }
64
63
  return output;
65
64
  }
66
- function addBuildTarget(tree, options, target) {
67
- (0, internal_1.addBuildTargetDefaults)(tree, '@nx/vite:build');
68
- const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
69
- const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(tree);
70
- const buildOptions = {
71
- outputPath: isTsSolutionSetup
72
- ? (0, devkit_1.joinPathFragments)(project.root, 'dist')
73
- : (0, devkit_1.joinPathFragments)('dist', project.root != '.' ? project.root : options.project),
74
- };
75
- project.targets ??= {};
76
- project.targets[target] = {
77
- executor: '@nx/vite:build',
78
- outputs: ['{options.outputPath}'],
79
- defaultConfiguration: 'production',
80
- options: buildOptions,
81
- configurations: {
82
- development: {
83
- mode: 'development',
84
- },
85
- production: {
86
- mode: 'production',
87
- },
88
- },
89
- };
90
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
91
- }
92
- function addServeTarget(tree, options, target) {
93
- const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
94
- project.targets ??= {};
95
- project.targets[target] = {
96
- executor: '@nx/vite:dev-server',
97
- defaultConfiguration: 'development',
98
- options: {
99
- buildTarget: `${options.project}:build`,
100
- },
101
- configurations: {
102
- development: {
103
- buildTarget: `${options.project}:build:development`,
104
- hmr: true,
105
- },
106
- production: {
107
- buildTarget: `${options.project}:build:production`,
108
- hmr: false,
109
- },
110
- },
111
- };
112
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
113
- }
114
- /**
115
- * Adds a target for the preview server.
116
- *
117
- * @param tree
118
- * @param options
119
- * @param serveTarget An existing serve target.
120
- */
121
- function addPreviewTarget(tree, options, serveTarget) {
122
- const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
123
- const previewOptions = {
124
- buildTarget: `${options.project}:build`,
125
- };
126
- project.targets ??= {};
127
- // Update the options from the passed serve target.
128
- if (project.targets[serveTarget]) {
129
- const target = project.targets[serveTarget];
130
- if (target.executor === '@nxext/vite:dev') {
131
- previewOptions.proxyConfig = target.options.proxyConfig;
132
- }
133
- previewOptions['https'] = target.options?.https;
134
- previewOptions['open'] = target.options?.open;
135
- }
136
- // Adds a preview target.
137
- project.targets.preview = {
138
- dependsOn: ['build'],
139
- executor: '@nx/vite:preview-server',
140
- defaultConfiguration: 'development',
141
- options: previewOptions,
142
- configurations: {
143
- development: {
144
- buildTarget: `${options.project}:build:development`,
145
- },
146
- production: {
147
- buildTarget: `${options.project}:build:production`,
148
- },
149
- },
150
- };
151
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
152
- }
153
65
  function editTsConfig(tree, options) {
154
66
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
155
67
  let tsconfigPath = (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json');
@@ -285,15 +197,30 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
285
197
  },`;
286
198
  const imports = options.imports ? [...options.imports] : [];
287
199
  const plugins = options.plugins ? [...options.plugins] : [];
200
+ const needsPaths = !isTsSolutionSetup;
201
+ const useNativePaths = needsPaths && ((0, version_utils_1.getInstalledViteMajorVersion)(tree) ?? 8) >= 8;
202
+ const dependencies = {};
203
+ if (needsPaths && !useNativePaths) {
204
+ imports.push(`import tsconfigPaths from 'vite-tsconfig-paths'`);
205
+ plugins.push('tsconfigPaths({ loose: true })');
206
+ dependencies['vite-tsconfig-paths'] = versions_1.viteTsconfigPathsVersion;
207
+ }
208
+ if (!onlyVitest && options.includeLib && !isTsSolutionSetup) {
209
+ plugins.push(`import('vite-plugin-static-copy').then(({ viteStaticCopy }) => viteStaticCopy({
210
+ targets: [
211
+ { src: '*.md', dest: '.' },
212
+ { src: 'package.json', dest: '.', overwrite: false },
213
+ ],
214
+ silent: true,
215
+ }))`);
216
+ dependencies['vite-plugin-static-copy'] = versions_1.viteStaticCopyVersion;
217
+ }
218
+ if (Object.keys(dependencies).length) {
219
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, dependencies, undefined, true);
220
+ }
288
221
  if (!onlyVitest && options.includeLib) {
289
222
  imports.push(`import dts from 'vite-plugin-dts'`, `import * as path from 'path'`);
290
223
  }
291
- if (!isTsSolutionSetup) {
292
- // TODO(v24): drop this branch; emit `tsconfigPaths()` from
293
- // `vite-tsconfig-paths` instead of the deprecated nx helpers.
294
- imports.push(`import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'`, `import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'`);
295
- plugins.push(`nxViteTsPaths()`, `nxCopyAssetsPlugin(['*.md'])`);
296
- }
297
224
  if (!onlyVitest && options.includeLib) {
298
225
  plugins.push(`dts({ entryRoot: 'src', tsconfigPath: path.join(import.meta.dirname, 'tsconfig.lib.json')${!isTsSolutionSetup ? ', pathsToAliases: false' : ''} })`);
299
226
  }
@@ -343,18 +270,21 @@ ${options.inSourceTests
343
270
  port: ${options.previewPort ?? 4300},
344
271
  host: 'localhost',
345
272
  },`;
346
- const workerOption = isTsSolutionSetup
347
- ? ` // Uncomment this if you are using workers.
273
+ const workerOption = ` // Uncomment this if you are using workers.
348
274
  // worker: {
349
275
  // plugins: [],
350
- // },`
351
- : ` // Uncomment this if you are using workers.
352
- // worker: {
353
- // plugins: () => [ nxViteTsPaths() ],
354
276
  // },`;
277
+ // Path-based workspace libraries need Vite's native tsconfig paths
278
+ // resolution, which is off by default. Workspaces on project references
279
+ // resolve through package.json instead.
280
+ const resolveOption = !useNativePaths
281
+ ? ''
282
+ : ` resolve: {
283
+ tsconfigPaths: true,
284
+ },`;
355
285
  const cacheDir = `cacheDir: '${normalizedJoinPaths((0, devkit_1.offsetFromRoot)(projectRoot), 'node_modules', '.vite', projectRoot === '.' ? options.project : projectRoot)}',`;
356
286
  if (tree.exists(viteConfigPath)) {
357
- handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, (0, devkit_1.offsetFromRoot)(projectRoot), projectAlreadyHasViteTargets);
287
+ handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, (0, devkit_1.offsetFromRoot)(projectRoot), projectAlreadyHasViteTargets, useNativePaths);
358
288
  return;
359
289
  }
360
290
  const viteConfigContent = `/// <reference types='vitest' />
@@ -363,7 +293,7 @@ ${imports.join(';\n')}${imports.length ? ';' : ''}
363
293
 
364
294
  export default defineConfig(() => ({
365
295
  root: import.meta.dirname,
366
- ${printOptions(cacheDir, devServerOption, previewServerOption, ` plugins: [${plugins.join(', ')}],`, workerOption, buildOption, defineOption, testOption)}
296
+ ${printOptions(cacheDir, devServerOption, previewServerOption, resolveOption, plugins.length ? ` plugins: [${plugins.join(', ')}],` : '', workerOption, buildOption, defineOption, testOption)}
367
297
  }));
368
298
  `.replace(/\s+(?=(\n|$))/gm, '\n');
369
299
  tree.write(viteConfigPath, viteConfigContent);
@@ -447,7 +377,7 @@ async function handleUnknownConfiguration(projectName) {
447
377
  `);
448
378
  }
449
379
  }
450
- function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, offsetFromRoot, projectAlreadyHasViteTargets) {
380
+ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, offsetFromRoot, projectAlreadyHasViteTargets, resolveTsconfigPaths) {
451
381
  if (projectAlreadyHasViteTargets?.build &&
452
382
  projectAlreadyHasViteTargets?.test) {
453
383
  return;
@@ -489,7 +419,7 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
489
419
  provider: `'${options.coverageProvider ?? 'v8'}'`,
490
420
  },
491
421
  };
492
- const changed = (0, vite_config_edit_utils_1.ensureViteConfigIsCorrect)(tree, viteConfigPath, buildOption, buildOptionObject, imports, plugins, testOption, testOptionObject, cacheDir, projectAlreadyHasViteTargets ?? {});
422
+ const changed = (0, vite_config_edit_utils_1.ensureViteConfigIsCorrect)(tree, viteConfigPath, buildOption, buildOptionObject, imports, plugins, testOption, testOptionObject, cacheDir, projectAlreadyHasViteTargets ?? {}, resolveTsconfigPaths);
493
423
  if (!changed) {
494
424
  devkit_1.logger.warn(`Make sure the following setting exists in your Vite configuration file (${viteConfigPath}):
495
425