@nx/vite 23.1.0-pr.36127.8b9019b → 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.
- package/dist/plugins/nx-tsconfig-paths.plugin.d.ts +10 -0
- package/dist/plugins/nx-tsconfig-paths.plugin.js +26 -19
- package/dist/plugins/nx-vite-build-coordination.plugin.js +39 -16
- package/dist/src/migrations/update-22-2-0/migrate-vitest-to-vitest-package.js +4 -0
- package/dist/src/migrations/update-23-0-0/ensure-vitest-package-migration.js +4 -0
- package/dist/src/plugins/plugin.js +1 -1
- package/dist/src/utils/deprecation.d.ts +2 -2
- package/dist/src/utils/deprecation.js +2 -2
- package/dist/src/utils/e2e-web-server-info-utils.js +6 -7
- package/dist/src/utils/executor-utils.js +4 -0
- package/package.json +6 -6
|
@@ -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 ===
|
|
67
|
-
?
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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 =
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -145,7 +145,7 @@ async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFi
|
|
|
145
145
|
if (tsConfigFiles.length) {
|
|
146
146
|
const tsConfigToUse = ['tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json'].find((t) => tsConfigFiles.includes(t)) ?? tsConfigFiles[0];
|
|
147
147
|
// Check if the project uses Vue plugin
|
|
148
|
-
const hasVuePlugin = viteBuildConfig.plugins?.some((p) => p.name === 'vite:vue');
|
|
148
|
+
const hasVuePlugin = viteBuildConfig.plugins?.some((p) => p.name === 'vite:vue' || p.name === 'vite:vue2');
|
|
149
149
|
// Explicit `compiler` option wins over inference so users can override
|
|
150
150
|
// when their setup isn't detected (e.g. custom/non-standard Vue plugin).
|
|
151
151
|
const resolvedCompiler = options.compiler ?? (hasVuePlugin ? 'vue-tsc' : 'tsc');
|
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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-
|
|
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-
|
|
105
|
-
"@nx/
|
|
106
|
-
"@nx/
|
|
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-
|
|
110
|
-
"nx": "23.1.0-
|
|
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"
|