@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
@@ -1,6 +1,3 @@
1
1
  export { type ViteBuildExecutorOptions } from './src/executors/build/schema';
2
- export { viteBuildExecutor } from './src/executors/build/build.impl';
3
2
  export { type ViteDevServerExecutorOptions } from './src/executors/dev-server/schema';
4
- export { viteDevServerExecutor } from './src/executors/dev-server/dev-server.impl';
5
3
  export { type VitePreviewServerExecutorOptions } from './src/executors/preview-server/schema';
6
- export { vitePreviewServerExecutor } from './src/executors/preview-server/preview-server.impl';
package/dist/executors.js CHANGED
@@ -1,9 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vitePreviewServerExecutor = exports.viteDevServerExecutor = exports.viteBuildExecutor = void 0;
4
- var build_impl_1 = require("./src/executors/build/build.impl");
5
- Object.defineProperty(exports, "viteBuildExecutor", { enumerable: true, get: function () { return build_impl_1.viteBuildExecutor; } });
6
- var dev_server_impl_1 = require("./src/executors/dev-server/dev-server.impl");
7
- Object.defineProperty(exports, "viteDevServerExecutor", { enumerable: true, get: function () { return dev_server_impl_1.viteDevServerExecutor; } });
8
- var preview_server_impl_1 = require("./src/executors/preview-server/preview-server.impl");
9
- Object.defineProperty(exports, "vitePreviewServerExecutor", { enumerable: true, get: function () { return preview_server_impl_1.vitePreviewServerExecutor; } });
@@ -1,9 +1,8 @@
1
1
  import type { Plugin } from 'vite';
2
- import { AssetGlob } from '@nx/js/internal';
2
+ import type { AssetGlob } from '@nx/js/internal';
3
3
  /**
4
- * @deprecated Will be removed in Nx v24. Use Vite's native `publicDir` option
5
- * for static assets, or the `vite-plugin-static-copy` package for anything
6
- * that needs glob-based copying. See
7
- * https://nx.dev/docs/technologies/build-tools/vite/configure-vite for details.
4
+ * @deprecated Use Vite's `publicDir` option or
5
+ * `vite-plugin-static-copy`.
6
+ * This inert stub will be removed in Nx v25.
8
7
  */
9
8
  export declare function nxCopyAssetsPlugin(_assets: (string | AssetGlob)[]): Plugin;
@@ -1,58 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxCopyAssetsPlugin = nxCopyAssetsPlugin;
4
- const node_path_1 = require("node:path");
5
- const devkit_1 = require("@nx/devkit");
6
- const internal_1 = require("@nx/js/internal");
7
4
  const deprecation_1 = require("../src/utils/deprecation");
5
+ // TODO(v25): remove the inert config-helper stubs in this file.
8
6
  /**
9
- * @deprecated Will be removed in Nx v24. Use Vite's native `publicDir` option
10
- * for static assets, or the `vite-plugin-static-copy` package for anything
11
- * that needs glob-based copying. See
12
- * https://nx.dev/docs/technologies/build-tools/vite/configure-vite for details.
7
+ * @deprecated Use Vite's `publicDir` option or
8
+ * `vite-plugin-static-copy`.
9
+ * This inert stub will be removed in Nx v25.
13
10
  */
14
11
  function nxCopyAssetsPlugin(_assets) {
15
12
  (0, deprecation_1.warnNxCopyAssetsPluginDeprecation)();
16
- let config;
17
- let handler;
18
- let dispose;
19
- if (global.NX_GRAPH_CREATION)
20
- return;
21
- return {
22
- name: 'nx-copy-assets-plugin',
23
- configResolved(_config) {
24
- config = _config;
25
- },
26
- async buildStart() {
27
- const relativeProjectRoot = (0, node_path_1.relative)(devkit_1.workspaceRoot, config.root);
28
- const assets = _assets.map((a) => {
29
- if (typeof a === 'string') {
30
- return (0, devkit_1.joinPathFragments)(relativeProjectRoot, a);
31
- }
32
- else {
33
- return {
34
- ...a,
35
- input: (0, devkit_1.joinPathFragments)(relativeProjectRoot, a.input),
36
- };
37
- }
38
- });
39
- handler = new internal_1.CopyAssetsHandler({
40
- rootDir: devkit_1.workspaceRoot,
41
- projectDir: config.root,
42
- outputDir: config.build.outDir.startsWith(config.root)
43
- ? config.build.outDir
44
- : (0, node_path_1.join)(config.root, config.build.outDir),
45
- assets,
46
- });
47
- if (this.meta.watchMode && (0, devkit_1.isDaemonEnabled)()) {
48
- dispose = await handler.watchAndProcessOnAssetChange();
49
- }
50
- },
51
- async writeBundle() {
52
- await handler.processAllAssetsOnce();
53
- },
54
- async closeWatcher() {
55
- dispose == null ? void 0 : dispose();
56
- },
57
- };
13
+ return { name: 'nx-copy-assets-plugin' };
58
14
  }
@@ -1,4 +1,4 @@
1
- import { Plugin } from 'vite';
1
+ import type { Plugin } from 'vite';
2
2
  export interface nxViteTsPathsOptions {
3
3
  /**
4
4
  * Enable debug logging
@@ -36,10 +36,8 @@ export interface nxViteTsPathsOptions {
36
36
  testTarget?: string;
37
37
  }
38
38
  /**
39
- * @deprecated Will be removed in Nx v24. Replace with `tsconfigPaths()` from
40
- * the `vite-tsconfig-paths` package. The inferred `@nx/vite/plugin` already
41
- * ensures projects extend the workspace base tsconfig, so the community
42
- * plugin handles monorepo path resolution end-to-end. See
43
- * https://nx.dev/docs/technologies/build-tools/vite/configure-vite for details.
39
+ * @deprecated Use Vite's `resolve.tsconfigPaths` (Vite 8+) or
40
+ * `tsconfigPaths()` from `vite-tsconfig-paths`.
41
+ * This inert stub will be removed in Nx v25.
44
42
  */
45
- export declare function nxViteTsPaths(options?: nxViteTsPathsOptions): Plugin;
43
+ export declare function nxViteTsPaths(_options?: nxViteTsPathsOptions): Plugin;
@@ -1,255 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxViteTsPaths = nxViteTsPaths;
4
- const devkit_1 = require("@nx/devkit");
5
- const internal_1 = require("@nx/js/internal");
6
- const js_1 = require("@nx/js");
7
- const node_fs_1 = require("node:fs");
8
- const node_path_1 = require("node:path");
9
- const tsconfig_paths_1 = require("tsconfig-paths");
10
4
  const deprecation_1 = require("../src/utils/deprecation");
11
- const nx_tsconfig_paths_load_file_1 = require("../src/utils/nx-tsconfig-paths-load-file");
12
- const options_utils_1 = require("../src/utils/options-utils");
13
- const nx_vite_build_coordination_plugin_1 = require("./nx-vite-build-coordination.plugin");
5
+ // TODO(v25): remove the inert config-helper stubs in this file.
14
6
  /**
15
- * @deprecated Will be removed in Nx v24. Replace with `tsconfigPaths()` from
16
- * the `vite-tsconfig-paths` package. The inferred `@nx/vite/plugin` already
17
- * ensures projects extend the workspace base tsconfig, so the community
18
- * plugin handles monorepo path resolution end-to-end. See
19
- * https://nx.dev/docs/technologies/build-tools/vite/configure-vite for details.
7
+ * @deprecated Use Vite's `resolve.tsconfigPaths` (Vite 8+) or
8
+ * `tsconfigPaths()` from `vite-tsconfig-paths`.
9
+ * This inert stub will be removed in Nx v25.
20
10
  */
21
- function nxViteTsPaths(options = {}) {
11
+ function nxViteTsPaths(_options = {}) {
22
12
  (0, deprecation_1.warnNxViteTsPathsDeprecation)();
23
- let foundTsConfigPath;
24
- let tsConfigPathsLoaded = false;
25
- let matchTsPathEsm;
26
- let matchTsPathEsmExact;
27
- let matchTsPathFallback;
28
- let matchTsPathFallbackExact;
29
- let tsConfigPathsEsm;
30
- let tsConfigPathsFallback;
31
- options.extensions ??= [
32
- '.ts',
33
- '.tsx',
34
- '.js',
35
- '.jsx',
36
- '.json',
37
- '.mts',
38
- '.mjs',
39
- '.cts',
40
- '.cjs',
41
- '.css',
42
- '.scss',
43
- '.less',
44
- ];
45
- options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];
46
- options.buildTarget ??= 'build';
47
- options.testTarget ??= 'test';
48
- options.buildLibsFromSource ??= true;
49
- let projectRoot = '';
50
- let projectRootFromWorkspaceRoot;
51
- return {
52
- name: 'nx-vite-ts-paths',
53
- // Ensure the resolveId aspect of the plugin is called before vite's internal resolver
54
- // Otherwise, issues can arise with Yarn Workspaces and Pnpm Workspaces
55
- enforce: 'pre',
56
- async configResolved(config) {
57
- projectRoot = config.root;
58
- projectRootFromWorkspaceRoot = (0, node_path_1.relative)(devkit_1.workspaceRoot, projectRoot);
59
- tsConfigPathsLoaded = false;
60
- foundTsConfigPath = getTsConfig(process.env.NX_TSCONFIG_PATH ??
61
- (0, node_path_1.join)(devkit_1.workspaceRoot, 'tmp', projectRootFromWorkspaceRoot, process.env.NX_TASK_TARGET_TARGET ?? 'build', 'tsconfig.generated.json'));
62
- if (!foundTsConfigPath)
63
- return;
64
- if (!options.buildLibsFromSource && !global.NX_GRAPH_CREATION) {
65
- const projectGraph = await (0, devkit_1.createProjectGraphAsync)({
66
- exitOnError: false,
67
- resetDaemonClient: true,
68
- });
69
- // When using incremental building and the serve target is called
70
- // we need to get the deps for the 'build' target instead.
71
- const depsBuildTarget = process.env.NX_TASK_TARGET_TARGET === 'serve' ||
72
- process.env.NX_TASK_TARGET_TARGET === options.testTarget
73
- ? options.buildTarget
74
- : process.env.NX_TASK_TARGET_TARGET;
75
- const { dependencies } = (0, internal_1.calculateProjectBuildableDependencies)(undefined, projectGraph, devkit_1.workspaceRoot, process.env.NX_TASK_TARGET_PROJECT, depsBuildTarget, process.env.NX_TASK_TARGET_CONFIGURATION);
76
- if (process.env.NX_GENERATED_TSCONFIG_PATH) {
77
- // This is needed for vitest browser mode because it runs two vite dev servers
78
- // so we want to reuse the same tsconfig file for both servers
79
- foundTsConfigPath = process.env.NX_GENERATED_TSCONFIG_PATH;
80
- }
81
- else {
82
- // This tsconfig is used via the Vite ts paths plugin.
83
- // It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).
84
- foundTsConfigPath = (0, internal_1.createTmpTsConfig)(foundTsConfigPath, devkit_1.workspaceRoot, (0, node_path_1.relative)(devkit_1.workspaceRoot, projectRoot), dependencies, true);
85
- process.env.NX_GENERATED_TSCONFIG_PATH = foundTsConfigPath;
86
- if (config.command === 'serve') {
87
- const buildableLibraryDependencies = dependencies
88
- .filter((dep) => dep.node.type === 'lib')
89
- .map((dep) => dep.node.name)
90
- .join(',');
91
- const buildCommand = `${(0, devkit_1.getPackageManagerCommand)().exec} nx run-many --target=${depsBuildTarget} --projects=${buildableLibraryDependencies}`;
92
- config.plugins.push((0, nx_vite_build_coordination_plugin_1.nxViteBuildCoordinationPlugin)({ buildCommand }));
93
- }
94
- }
95
- }
96
- // Graph construction resolves every config and never a module, so the
97
- // parsing waits for the first `resolveId` there.
98
- if (!global.NX_GRAPH_CREATION)
99
- loadTsConfigPaths();
100
- },
101
- resolveId(importPath) {
102
- // Let other resolvers handle this path.
103
- if (!foundTsConfigPath)
104
- return null;
105
- // Skip absolute and root-relative paths — these are filesystem paths,
106
- // not TypeScript import specifiers. In Vite, `/foo` is a project-root-
107
- // relative URL and must be resolved by Vite's built-in resolver, not
108
- // by tsconfig path mapping (which would incorrectly use baseUrl).
109
- if (importPath.startsWith('/'))
110
- return null;
111
- if (!tsConfigPathsLoaded)
112
- loadTsConfigPaths();
113
- let resolvedFile;
114
- try {
115
- resolvedFile =
116
- matchTsPathEsmExact(importPath) ??
117
- loadFileFromExactAlias(tsConfigPathsEsm, importPath) ??
118
- matchTsPathEsm(importPath);
119
- }
120
- catch (e) {
121
- logIt('Using fallback path matching.');
122
- resolvedFile =
123
- matchTsPathFallbackExact?.(importPath) ??
124
- loadFileFromExactAlias(tsConfigPathsFallback, importPath) ??
125
- matchTsPathFallback?.(importPath);
126
- }
127
- if (!resolvedFile || !(0, node_fs_1.existsSync)(resolvedFile)) {
128
- if (tsConfigPathsEsm || tsConfigPathsFallback) {
129
- logIt(`Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`);
130
- // The tsconfig the project builds with need not extend the
131
- // root-level one, so the second pass covers aliases only the
132
- // root-level config declares.
133
- resolvedFile =
134
- loadFileFromPathsWithLogging(tsConfigPathsEsm, importPath) ||
135
- loadFileFromPathsWithLogging(tsConfigPathsFallback, importPath);
136
- }
137
- else {
138
- logIt(`Unable to resolve ${importPath} with tsconfig paths`);
139
- }
140
- }
141
- logIt(`Resolved ${importPath} to ${resolvedFile}`);
142
- // Returning null defers to other resolveId functions and eventually the default resolution behavior
143
- // https://rollupjs.org/plugin-development/#resolveid
144
- return resolvedFile || null;
145
- },
146
- async writeBundle(options) {
147
- if ((0, internal_1.isUsingTsSolutionSetup)())
148
- return;
149
- const outDir = options.dir || 'dist';
150
- const src = (0, node_path_1.resolve)(projectRoot, 'package.json');
151
- const dest = (0, node_path_1.join)(outDir, 'package.json');
152
- if ((0, node_fs_1.existsSync)(src) && !(0, node_fs_1.existsSync)(dest)) {
153
- try {
154
- (0, node_fs_1.copyFileSync)(src, dest);
155
- }
156
- catch (err) {
157
- console.error('Error copying package.json:', err);
158
- }
159
- }
160
- },
161
- };
162
- function loadTsConfigPaths() {
163
- const parsed = (0, tsconfig_paths_1.loadConfig)(foundTsConfigPath);
164
- logIt('first parsed tsconfig: ', parsed);
165
- if (parsed.resultType === 'failed') {
166
- throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);
167
- }
168
- // `loadConfig` derives `absoluteBaseUrl` from the leaf tsconfig, but
169
- // `paths` resolve against the config that declared them.
170
- const pathsBaseUrl = (0, js_1.resolvePathsBaseUrl)(foundTsConfigPath);
171
- tsConfigPathsEsm = { ...parsed, absoluteBaseUrl: pathsBaseUrl };
172
- matchTsPathEsm = (0, tsconfig_paths_1.createMatchPath)(pathsBaseUrl, parsed.paths, options.mainFields);
173
- matchTsPathEsmExact = createExactMatchPath(pathsBaseUrl, parsed.paths, options.mainFields);
174
- const rootLevelTsConfig = getTsConfig((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.base.json'));
175
- // A workspace may have no root-level tsconfig at all. Passing no path to
176
- // `loadConfig` makes it search upwards from the cwd instead, which finds
177
- // an unrelated tsconfig whose directory is not this workspace.
178
- if (rootLevelTsConfig) {
179
- const rootLevelParsed = (0, tsconfig_paths_1.loadConfig)(rootLevelTsConfig);
180
- logIt('fallback parsed tsconfig: ', rootLevelParsed);
181
- if (rootLevelParsed.resultType === 'success') {
182
- const rootLevelPathsBaseUrl = (0, js_1.resolvePathsBaseUrl)(rootLevelTsConfig);
183
- tsConfigPathsFallback = {
184
- ...rootLevelParsed,
185
- absoluteBaseUrl: rootLevelPathsBaseUrl,
186
- };
187
- matchTsPathFallback = (0, tsconfig_paths_1.createMatchPath)(rootLevelPathsBaseUrl, rootLevelParsed.paths, ['main', 'module']);
188
- matchTsPathFallbackExact = createExactMatchPath(rootLevelPathsBaseUrl, rootLevelParsed.paths, ['main', 'module']);
189
- }
190
- }
191
- tsConfigPathsLoaded = true;
192
- }
193
- function getTsConfig(preferredTsConfigPath) {
194
- const projectTsConfigPath = (0, options_utils_1.getProjectTsConfigPath)(projectRootFromWorkspaceRoot);
195
- return [
196
- (0, node_path_1.resolve)(preferredTsConfigPath),
197
- projectTsConfigPath
198
- ? (0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, projectTsConfigPath))
199
- : null,
200
- (0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.base.json')),
201
- (0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.json')),
202
- (0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'jsconfig.json')),
203
- ]
204
- .filter(Boolean)
205
- .find((tsPath) => {
206
- if ((0, node_fs_1.existsSync)(tsPath)) {
207
- logIt('Found tsconfig at', tsPath);
208
- return tsPath;
209
- }
210
- });
211
- }
212
- function logIt(...msg) {
213
- if (process.env.NX_VERBOSE_LOGGING === 'true' && options?.debug !== false) {
214
- console.debug('\n[Nx Vite TsPaths]', ...msg);
215
- }
216
- }
217
- /**
218
- * Resolves an import that names an alias exactly, through that alias alone.
219
- *
220
- * The matcher above already covers a mapped path that names a file or a
221
- * package entry, so this is what finds an `index` or supplies the extension.
222
- * Restricting it to the one alias keeps it from answering with a wildcard,
223
- * which is the last resort's job.
224
- */
225
- function loadFileFromExactAlias(tsconfig, importPath) {
226
- // An own-property check, because an import named after an `Object`
227
- // prototype member (`constructor`, `toString`) would otherwise read the
228
- // inherited value and hand a non-array on to the resolver.
229
- if (!tsconfig || !Object.hasOwn(tsconfig.paths, importPath)) {
230
- return undefined;
231
- }
232
- return (0, nx_tsconfig_paths_load_file_1.loadFileFromPaths)({ ...tsconfig, paths: { [importPath]: tsconfig.paths[importPath] } }, importPath, options.extensions);
233
- }
234
- function loadFileFromPathsWithLogging(tsconfig, importPath) {
235
- // The root-level tsconfig is optional: a workspace without one leaves
236
- // `tsConfigPathsFallback` unset, and the import has to defer to Vite.
237
- if (!tsconfig)
238
- return undefined;
239
- logIt(`Trying to resolve file from config in ${tsconfig.configFileAbsolutePath}`);
240
- return (0, nx_tsconfig_paths_load_file_1.loadFileFromPaths)(tsconfig, importPath, options.extensions);
241
- }
242
- }
243
- /**
244
- * Matcher over the non-wildcard aliases alone, to run before the full one.
245
- *
246
- * `tsconfig-paths` ranks an alias by the length of the text before its `*`,
247
- * counting one without a `*` as zero, so an exact alias sorts no higher than
248
- * any wildcard. TypeScript matches an exact alias first.
249
- */
250
- function createExactMatchPath(absoluteBaseUrl, paths, mainFields) {
251
- const exactPaths = Object.fromEntries(Object.entries(paths).filter(([alias]) => !alias.includes('*')));
252
- // The match-all `*` entry would resolve any import against `baseUrl` before
253
- // the wildcard aliases of the full matcher get their turn.
254
- return (0, tsconfig_paths_1.createMatchPath)(absoluteBaseUrl, exactPaths, mainFields, false);
13
+ return { name: 'nx-vite-ts-paths' };
255
14
  }
@@ -9,16 +9,12 @@ const internal_1 = require("@nx/js/internal");
9
9
  const posix_1 = require("node:path/posix");
10
10
  const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
11
11
  const assert_supported_vite_version_1 = require("../../utils/assert-supported-vite-version");
12
- const deprecation_1 = require("../../utils/deprecation");
13
12
  const generator_utils_1 = require("../../utils/generator-utils");
14
13
  const versions_1 = require("../../utils/versions");
15
14
  const init_1 = tslib_1.__importDefault(require("../init/init"));
16
15
  const convert_non_vite_1 = require("./lib/convert-non-vite");
17
16
  function viteConfigurationGenerator(host, schema) {
18
- return viteConfigurationGeneratorInternal(host, {
19
- addPlugin: false,
20
- ...schema,
21
- });
17
+ return viteConfigurationGeneratorInternal(host, schema);
22
18
  }
23
19
  async function viteConfigurationGeneratorInternal(tree, schema) {
24
20
  (0, assert_supported_vite_version_1.assertSupportedViteVersion)(tree);
@@ -30,11 +26,6 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
30
26
  // Setting default to jsdom since it is the most common use case (React, Web).
31
27
  // The @nx/js:lib generator specifically sets this to node to be more generic.
32
28
  schema.testEnvironment ??= 'jsdom';
33
- /**
34
- * This is for when we are converting an existing project
35
- * to use the vite executors.
36
- */
37
- let projectAlreadyHasViteTargets = {};
38
29
  if (!schema.newProject) {
39
30
  await (0, convert_non_vite_1.convertNonVite)(tree, schema, projectRoot, projectType, targets);
40
31
  }
@@ -51,33 +42,6 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
51
42
  });
52
43
  tasks.push(initTask);
53
44
  tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, schema));
54
- const nxJson = (0, devkit_1.readNxJson)(tree);
55
- const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
56
- nxJson.useInferencePlugins !== false;
57
- schema.addPlugin ??= addPluginDefault;
58
- const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
59
- ? p === '@nx/vite/plugin'
60
- : p.plugin === '@nx/vite/plugin');
61
- if (!hasPlugin) {
62
- const willScaffoldExecutorTargets = !projectAlreadyHasViteTargets.build ||
63
- (!schema.includeLib &&
64
- (!projectAlreadyHasViteTargets.serve ||
65
- !projectAlreadyHasViteTargets.preview));
66
- if (willScaffoldExecutorTargets) {
67
- (0, deprecation_1.warnViteExecutorGenerating)();
68
- }
69
- if (!projectAlreadyHasViteTargets.build) {
70
- (0, generator_utils_1.addBuildTarget)(tree, schema, 'build');
71
- }
72
- if (!schema.includeLib) {
73
- if (!projectAlreadyHasViteTargets.serve) {
74
- (0, generator_utils_1.addServeTarget)(tree, schema, 'serve');
75
- }
76
- if (!projectAlreadyHasViteTargets.preview) {
77
- (0, generator_utils_1.addPreviewTarget)(tree, schema, 'preview');
78
- }
79
- }
80
- }
81
45
  if (projectType === 'library') {
82
46
  // update tsconfig.lib.json to include vite/client
83
47
  (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.lib.json'), (json) => {
@@ -113,7 +77,7 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
113
77
  }, false, undefined);
114
78
  }
115
79
  else {
116
- (0, generator_utils_1.createOrEditViteConfig)(tree, { ...schema, useEsmExtension: true }, false, projectAlreadyHasViteTargets);
80
+ (0, generator_utils_1.createOrEditViteConfig)(tree, { ...schema, useEsmExtension: true }, false);
117
81
  }
118
82
  }
119
83
  if (schema.includeVitest) {
@@ -129,7 +93,6 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
129
93
  skipViteConfig: true,
130
94
  testTarget: 'test',
131
95
  skipFormat: true,
132
- addPlugin: schema.addPlugin,
133
96
  compiler: schema.compiler,
134
97
  projectType,
135
98
  testEnvironment: schema.testEnvironment,
@@ -10,7 +10,6 @@ export interface ViteConfigurationGeneratorSchema {
10
10
  testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
11
11
  port?: number;
12
12
  // Internal options
13
- addPlugin?: boolean;
14
13
  projectType?: 'application' | 'library';
15
14
  previewPort?: number;
16
15
  useViteV7?: boolean;
@@ -3,4 +3,3 @@ export declare function buildPostTargetTransformer(target: TargetConfiguration,
3
3
  projectName: string;
4
4
  root: string;
5
5
  }, inferredTargetConfiguration: TargetConfiguration): TargetConfiguration<any>;
6
- export declare function moveBuildLibsFromSourceToViteConfig(tree: Tree, configPath: string): void;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildPostTargetTransformer = buildPostTargetTransformer;
4
- exports.moveBuildLibsFromSourceToViteConfig = moveBuildLibsFromSourceToViteConfig;
5
4
  const internal_1 = require("@nx/devkit/internal");
6
5
  const devkit_1 = require("@nx/devkit");
7
- const tsquery_1 = require("@phenomnomnominal/tsquery");
8
- const posix_1 = require("path/posix");
9
6
  const utils_1 = require("./utils");
10
7
  function buildPostTargetTransformer(target, tree, projectDetails, inferredTargetConfiguration) {
11
8
  let viteConfigPath = (0, utils_1.getViteConfigPath)(tree, projectDetails.root);
@@ -16,15 +13,7 @@ function buildPostTargetTransformer(target, tree, projectDetails, inferredTarget
16
13
  for (const configurationName in target.configurations) {
17
14
  const configuration = target.configurations[configurationName];
18
15
  configValues[configurationName] = {};
19
- let configurationConfigFile = viteConfigPath;
20
- if (configuration.configFile) {
21
- if ('buildLibsFromSource' in target.options) {
22
- configuration.buildLibsFromSource =
23
- target.options.buildLibsFromSource;
24
- }
25
- configurationConfigFile = configuration.configFile;
26
- }
27
- removePropertiesFromTargetOptions(tree, configuration, configurationConfigFile, projectDetails.root, configValues[configurationName], configuration.configFile && configuration.configFile !== viteConfigPath);
16
+ removePropertiesFromTargetOptions(configuration, projectDetails.root, configValues[configurationName]);
28
17
  }
29
18
  for (const configurationName in target.configurations) {
30
19
  const configuration = target.configurations[configurationName];
@@ -50,7 +39,7 @@ function buildPostTargetTransformer(target, tree, projectDetails, inferredTarget
50
39
  if (target.options.configFile) {
51
40
  viteConfigPath = target.options.configFile;
52
41
  }
53
- removePropertiesFromTargetOptions(tree, target.options, viteConfigPath, projectDetails.root, configValues['default'], true);
42
+ removePropertiesFromTargetOptions(target.options, projectDetails.root, configValues['default']);
54
43
  }
55
44
  if (target.outputs) {
56
45
  (0, internal_1.processTargetOutputs)(target, [{ newName: 'outDir', oldName: 'outputPath' }], inferredTargetConfiguration, {
@@ -65,7 +54,7 @@ function buildPostTargetTransformer(target, tree, projectDetails, inferredTarget
65
54
  (0, utils_1.addConfigValuesToViteConfig)(tree, viteConfigPath, configValues);
66
55
  return target;
67
56
  }
68
- function removePropertiesFromTargetOptions(tree, targetOptions, viteConfigPath, projectRoot, configValues, needsAstTransform = false) {
57
+ function removePropertiesFromTargetOptions(targetOptions, projectRoot, configValues) {
69
58
  if ('configFile' in targetOptions) {
70
59
  targetOptions.config = (0, utils_1.toProjectRelativePath)(targetOptions.configFile, projectRoot);
71
60
  delete targetOptions.configFile;
@@ -75,10 +64,6 @@ function removePropertiesFromTargetOptions(tree, targetOptions, viteConfigPath,
75
64
  delete targetOptions.outputPath;
76
65
  }
77
66
  if ('buildLibsFromSource' in targetOptions) {
78
- configValues['buildLibsFromSource'] = targetOptions.buildLibsFromSource;
79
- if (needsAstTransform) {
80
- moveBuildLibsFromSourceToViteConfig(tree, viteConfigPath);
81
- }
82
67
  delete targetOptions.buildLibsFromSource;
83
68
  }
84
69
  if ('skipTypeCheck' in targetOptions) {
@@ -94,51 +79,3 @@ function removePropertiesFromTargetOptions(tree, targetOptions, viteConfigPath,
94
79
  delete targetOptions.tsConfig;
95
80
  }
96
81
  }
97
- function moveBuildLibsFromSourceToViteConfig(tree, configPath) {
98
- const PLUGINS_PROPERTY_SELECTOR = 'PropertyAssignment:has(Identifier[name=plugins])';
99
- const PLUGINS_NX_VITE_TS_PATHS_SELECTOR = 'PropertyAssignment:has(Identifier[name=plugins]) CallExpression:has(Identifier[name=nxViteTsPaths])';
100
- const BUILD_LIBS_FROM_SOURCE_SELECTOR = 'PropertyAssignment:has(Identifier[name=plugins]) CallExpression:has(Identifier[name=nxViteTsPaths]) ObjectLiteralExpression > PropertyAssignment:has(Identifier[name=buildLibsFromSource])';
101
- const nxViteTsPathsImport = (0, posix_1.extname)(configPath) === 'js'
102
- ? 'const {nxViteTsPaths} = require("@nx/vite/plugins/nx-tsconfig-paths.plugin");'
103
- : 'import { nxViteTsPaths } from "@nx/vite/plugins/nx-tsconfig-paths.plugin";';
104
- const plugin = `nxViteTsPaths({ buildLibsFromSource: options.buildLibsFromSource }),`;
105
- const viteConfigContents = tree.read(configPath, 'utf-8');
106
- let newViteConfigContents = viteConfigContents;
107
- const sourceFile = (0, tsquery_1.ast)(viteConfigContents);
108
- const buildLibsFromSourceNodes = (0, tsquery_1.query)(sourceFile, BUILD_LIBS_FROM_SOURCE_SELECTOR);
109
- if (buildLibsFromSourceNodes.length > 0) {
110
- return;
111
- }
112
- const nxViteTsPathsNodes = (0, tsquery_1.query)(sourceFile, PLUGINS_NX_VITE_TS_PATHS_SELECTOR);
113
- if (nxViteTsPathsNodes.length === 0) {
114
- const pluginsNodes = (0, tsquery_1.query)(sourceFile, PLUGINS_PROPERTY_SELECTOR);
115
- if (pluginsNodes.length === 0) {
116
- // Add plugin property
117
- const configNodes = (0, tsquery_1.query)(sourceFile, 'CallExpression:has(Identifier[name=defineConfig]) > ObjectLiteralExpression');
118
- if (configNodes.length === 0) {
119
- return;
120
- }
121
- newViteConfigContents = `${nxViteTsPathsImport}\n${viteConfigContents.slice(0, configNodes[0].getStart() + 1)}plugins: [${plugin}],${viteConfigContents.slice(configNodes[0].getStart() + 1)}`;
122
- }
123
- else {
124
- // Add nxViteTsPaths plugin
125
- const pluginsArrayNodes = (0, tsquery_1.query)(pluginsNodes[0], 'ArrayLiteralExpression');
126
- if (pluginsArrayNodes.length === 0) {
127
- return;
128
- }
129
- newViteConfigContents = `${nxViteTsPathsImport}\n${viteConfigContents.slice(0, pluginsArrayNodes[0].getStart() + 1)}${plugin}${viteConfigContents.slice(pluginsArrayNodes[0].getStart() + 1)}`;
130
- }
131
- }
132
- else {
133
- const pluginOptionsNodes = (0, tsquery_1.query)(nxViteTsPathsNodes[0], 'ObjectLiteralExpression');
134
- if (pluginOptionsNodes.length === 0) {
135
- // Add the options
136
- newViteConfigContents = `${viteConfigContents.slice(0, nxViteTsPathsNodes[0].getStart())}${plugin}${viteConfigContents.slice(nxViteTsPathsNodes[0].getEnd())}`;
137
- }
138
- else {
139
- // update the object
140
- newViteConfigContents = `${viteConfigContents.slice(0, pluginOptionsNodes[0].getStart() + 1)}buildLibsFromSource: options.buildLibsFromSource, ${viteConfigContents.slice(pluginOptionsNodes[0].getStart() + 1)}`;
141
- }
142
- }
143
- tree.write(configPath, newViteConfigContents);
144
- }