@nx/vite 23.1.0-pr.36127.e594f53 → 23.1.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,16 @@ export interface nxViteTsPathsOptions {
24
24
  * @default true
25
25
  */
26
26
  buildLibsFromSource?: boolean;
27
+ /**
28
+ * The target to use for building the library dependencies.
29
+ * @default 'build'
30
+ */
31
+ buildTarget?: string;
32
+ /**
33
+ * The target to use for testing the library.
34
+ * @default 'test'
35
+ */
36
+ testTarget?: string;
27
37
  }
28
38
  /**
29
39
  * @deprecated Will be removed in Nx v24. Replace with `tsconfigPaths()` from
@@ -40,6 +40,8 @@ function nxViteTsPaths(options = {}) {
40
40
  '.less',
41
41
  ];
42
42
  options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];
43
+ options.buildTarget ??= 'build';
44
+ options.testTarget ??= 'test';
43
45
  options.buildLibsFromSource ??= true;
44
46
  let projectRoot = '';
45
47
  let projectRootFromWorkspaceRoot;
@@ -63,8 +65,8 @@ function nxViteTsPaths(options = {}) {
63
65
  // When using incremental building and the serve target is called
64
66
  // we need to get the deps for the 'build' target instead.
65
67
  const depsBuildTarget = process.env.NX_TASK_TARGET_TARGET === 'serve' ||
66
- process.env.NX_TASK_TARGET_TARGET === 'test'
67
- ? 'build'
68
+ process.env.NX_TASK_TARGET_TARGET === options.testTarget
69
+ ? options.buildTarget
68
70
  : process.env.NX_TASK_TARGET_TARGET;
69
71
  const { dependencies } = (0, internal_1.calculateProjectBuildableDependencies)(undefined, projectGraph, devkit_1.workspaceRoot, process.env.NX_TASK_TARGET_PROJECT, depsBuildTarget, process.env.NX_TASK_TARGET_CONFIGURATION);
70
72
  if (process.env.NX_GENERATED_TSCONFIG_PATH) {
@@ -77,14 +79,14 @@ function nxViteTsPaths(options = {}) {
77
79
  // It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).
78
80
  foundTsConfigPath = (0, internal_1.createTmpTsConfig)(foundTsConfigPath, devkit_1.workspaceRoot, (0, node_path_1.relative)(devkit_1.workspaceRoot, projectRoot), dependencies, true);
79
81
  process.env.NX_GENERATED_TSCONFIG_PATH = foundTsConfigPath;
80
- }
81
- if (config.command === 'serve') {
82
- const buildableLibraryDependencies = dependencies
83
- .filter((dep) => dep.node.type === 'lib')
84
- .map((dep) => dep.node.name)
85
- .join(',');
86
- const buildCommand = `npx nx run-many --target=${depsBuildTarget} --projects=${buildableLibraryDependencies}`;
87
- config.plugins.push((0, nx_vite_build_coordination_plugin_1.nxViteBuildCoordinationPlugin)({ buildCommand }));
82
+ if (config.command === 'serve') {
83
+ const buildableLibraryDependencies = dependencies
84
+ .filter((dep) => dep.node.type === 'lib')
85
+ .map((dep) => dep.node.name)
86
+ .join(',');
87
+ const buildCommand = `${(0, devkit_1.getPackageManagerCommand)().exec} nx run-many --target=${depsBuildTarget} --projects=${buildableLibraryDependencies}`;
88
+ config.plugins.push((0, nx_vite_build_coordination_plugin_1.nxViteBuildCoordinationPlugin)({ buildCommand }));
89
+ }
88
90
  }
89
91
  }
90
92
  const parsed = (0, tsconfig_paths_1.loadConfig)(foundTsConfigPath);
@@ -184,15 +186,20 @@ function nxViteTsPaths(options = {}) {
184
186
  const normalizedImport = alias.replace(/\/\*$/, '');
185
187
  if (importPath === normalizedImport ||
186
188
  importPath.startsWith(normalizedImport + '/')) {
187
- const joinedPath = (0, devkit_1.joinPathFragments)(tsconfig.absoluteBaseUrl, paths[0].replace(/\/\*$/, ''));
188
- resolvedFile = (0, nx_tsconfig_paths_find_file_1.findFile)(importPath.replace(normalizedImport, joinedPath), options.extensions);
189
- if (resolvedFile === undefined &&
190
- options.extensions.some((ext) => importPath.endsWith(ext))) {
191
- const foundExtension = options.extensions.find((ext) => importPath.endsWith(ext));
192
- const pathWithoutExtension = importPath
193
- .replace(normalizedImport, joinedPath)
194
- .slice(0, -foundExtension.length);
195
- resolvedFile = (0, nx_tsconfig_paths_find_file_1.findFile)(pathWithoutExtension, options.extensions);
189
+ for (const path of paths) {
190
+ const joinedPath = (0, devkit_1.joinPathFragments)(tsconfig.absoluteBaseUrl, path.replace(/\/\*$/, ''));
191
+ resolvedFile = (0, nx_tsconfig_paths_find_file_1.findFile)(importPath.replace(normalizedImport, joinedPath), options.extensions);
192
+ if (resolvedFile === undefined &&
193
+ options.extensions.some((ext) => importPath.endsWith(ext))) {
194
+ const foundExtension = options.extensions.find((ext) => importPath.endsWith(ext));
195
+ const pathWithoutExtension = importPath
196
+ .replace(normalizedImport, joinedPath)
197
+ .slice(0, -foundExtension.length);
198
+ resolvedFile = (0, nx_tsconfig_paths_find_file_1.findFile)(pathWithoutExtension, options.extensions);
199
+ }
200
+ if (resolvedFile !== undefined) {
201
+ return resolvedFile;
202
+ }
196
203
  }
197
204
  }
198
205
  }
@@ -9,24 +9,44 @@ function nxViteBuildCoordinationPlugin(options) {
9
9
  let activeBuildProcess;
10
10
  let unregisterFileWatcher;
11
11
  async function buildChangedProjects() {
12
- await new Promise((res) => {
13
- activeBuildProcess = (0, child_process_1.exec)(options.buildCommand, {
14
- windowsHide: true,
15
- });
16
- activeBuildProcess.stdout.pipe(process.stdout);
17
- activeBuildProcess.stderr.pipe(process.stderr);
18
- activeBuildProcess.on('exit', () => {
19
- res();
20
- });
21
- activeBuildProcess.on('error', () => {
22
- res();
23
- });
12
+ const buildProcess = (0, child_process_1.exec)(options.buildCommand, {
13
+ windowsHide: true,
24
14
  });
25
- activeBuildProcess = undefined;
15
+ activeBuildProcess = buildProcess;
16
+ try {
17
+ await new Promise((res, rej) => {
18
+ buildProcess.stdout.pipe(process.stdout);
19
+ buildProcess.stderr.pipe(process.stderr);
20
+ buildProcess.on('exit', (code, signal) => {
21
+ // A build killed by the file watcher (new changes arrived) is not a failure.
22
+ if (buildProcess.killed || signal || code === 0) {
23
+ res();
24
+ }
25
+ else {
26
+ rej(new Error(`Build failed with exit code ${code}`));
27
+ }
28
+ });
29
+ buildProcess.on('error', (error) => {
30
+ rej(error);
31
+ });
32
+ });
33
+ }
34
+ finally {
35
+ if (activeBuildProcess === buildProcess) {
36
+ activeBuildProcess = undefined;
37
+ }
38
+ }
26
39
  }
27
40
  function createFileWatcher() {
28
- const runner = new watch_1.BatchFunctionRunner(() => buildChangedProjects());
29
- return client_1.daemonClient.registerFileWatcher({ watchProjects: 'all' }, (err, { changedProjects, changedFiles }) => {
41
+ // Failed rebuilds in watch mode should not crash the dev server. Log and
42
+ // keep watching so the next file change can rebuild.
43
+ const runner = new watch_1.BatchFunctionRunner(() => buildChangedProjects().catch((error) => {
44
+ output_1.output.error({
45
+ title: 'Failed to rebuild projects. Fix the errors and save again.',
46
+ bodyLines: error?.message ? [error.message] : undefined,
47
+ });
48
+ }));
49
+ return client_1.daemonClient.registerFileWatcher({ watchProjects: 'all' }, (err, data) => {
30
50
  if (err === 'reconnecting') {
31
51
  // Silent - daemon restarts automatically on lockfile changes
32
52
  return;
@@ -50,7 +70,10 @@ function nxViteBuildCoordinationPlugin(options) {
50
70
  activeBuildProcess.kill(2);
51
71
  activeBuildProcess = undefined;
52
72
  }
53
- runner.enqueue(changedProjects, changedFiles);
73
+ if (data) {
74
+ const { changedProjects, changedFiles } = data;
75
+ runner.enqueue(changedProjects, changedFiles);
76
+ }
54
77
  });
55
78
  }
56
79
  let firstBuildStart = true;
@@ -120,6 +120,10 @@ function migrateTargetDefaults(tree) {
120
120
  }
121
121
  let hasChanges = false;
122
122
  for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
123
+ if (Array.isArray(targetConfig)) {
124
+ // This migration predates the filtered array value form; values are plain objects here.
125
+ continue;
126
+ }
123
127
  // Pattern A: Executor-keyed (e.g., "@nx/vite:test": { ... })
124
128
  if (targetOrExecutor === '@nx/vite:test') {
125
129
  // Move config to new executor key
@@ -110,6 +110,10 @@ function migrateTargetDefaults(tree) {
110
110
  }
111
111
  let hasChanges = false;
112
112
  for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
113
+ if (Array.isArray(targetConfig)) {
114
+ // This migration predates the filtered array value form; values are plain objects here.
115
+ continue;
116
+ }
113
117
  if (targetOrExecutor === '@nx/vite:test') {
114
118
  nxJson.targetDefaults['@nx/vitest:test'] ??= {};
115
119
  Object.assign(nxJson.targetDefaults['@nx/vitest:test'], targetConfig);
@@ -5,7 +5,7 @@ export declare function warnViteBuildExecutorDeprecation(): void;
5
5
  export declare function warnViteDevServerExecutorDeprecation(): void;
6
6
  export declare function warnVitePreviewServerExecutorDeprecation(): void;
7
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/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/configure-vite for details.";
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.";
10
10
  export declare function warnNxViteTsPathsDeprecation(): void;
11
11
  export declare function warnNxCopyAssetsPluginDeprecation(): void;
@@ -36,8 +36,8 @@ function warnViteExecutorGenerating() {
36
36
  // tsconfig, so the community `vite-tsconfig-paths` package handles path
37
37
  // resolution end-to-end. Asset copying is covered by Vite's native
38
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/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/configure-vite for details.";
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.";
41
41
  let nxViteTsPathsWarned = false;
42
42
  let nxCopyAssetsPluginWarned = false;
43
43
  // Warn-once per process so users don't see the message repeated on every
@@ -7,13 +7,12 @@ const internal_1 = require("@nx/devkit/internal");
7
7
  async function getViteE2EWebServerInfo(tree, projectName, configFilePath, isPluginBeingAdded, e2ePortOverride, e2eCIPortOverride) {
8
8
  const nxJson = (0, devkit_1.readNxJson)(tree);
9
9
  let e2ePort = e2ePortOverride ?? 4200;
10
- if ((nxJson.targetDefaults?.['dev'] &&
11
- nxJson.targetDefaults?.['dev'].options?.port) ||
12
- (nxJson.targetDefaults?.['serve'] &&
13
- nxJson.targetDefaults?.['serve'].options?.port)) {
14
- e2ePort =
15
- nxJson.targetDefaults?.['dev'].options?.port ??
16
- nxJson.targetDefaults?.['serve'].options?.port;
10
+ const devPort = (0, internal_1.readTargetDefaultsForTarget)('dev', nxJson.targetDefaults)
11
+ ?.options?.port;
12
+ const servePort = (0, internal_1.readTargetDefaultsForTarget)('serve', nxJson.targetDefaults)
13
+ ?.options?.port;
14
+ if (devPort || servePort) {
15
+ e2ePort = devPort ?? servePort;
17
16
  }
18
17
  return (0, internal_1.getE2EWebServerInfo)(tree, projectName, {
19
18
  plugin: '@nx/vite/plugin',
@@ -17,6 +17,10 @@ async function validateTypes(opts) {
17
17
  ? opts.tsconfig
18
18
  : (0, path_1.join)(opts.workspaceRoot, opts.tsconfig),
19
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,
20
24
  });
21
25
  await (0, js_1.printDiagnostics)(result.errors, result.warnings);
22
26
  if (result.errors.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/vite",
3
- "version": "23.1.0-pr.36127.e594f53",
3
+ "version": "23.1.0-rc.0",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -101,13 +101,13 @@
101
101
  "semver": "^7.6.3",
102
102
  "tslib": "^2.3.0",
103
103
  "ajv": "^8.0.0",
104
- "@nx/devkit": "23.1.0-pr.36127.e594f53",
105
- "@nx/js": "23.1.0-pr.36127.e594f53",
106
- "@nx/vitest": "23.1.0-pr.36127.e594f53"
104
+ "@nx/devkit": "23.1.0-rc.0",
105
+ "@nx/vitest": "23.1.0-rc.0",
106
+ "@nx/js": "23.1.0-rc.0"
107
107
  },
108
108
  "devDependencies": {
109
- "@nx/eslint": "23.1.0-pr.36127.e594f53",
110
- "nx": "23.1.0-pr.36127.e594f53"
109
+ "@nx/eslint": "23.1.0-rc.0",
110
+ "nx": "23.1.0-rc.0"
111
111
  },
112
112
  "peerDependencies": {
113
113
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"