@nx/vite 24.0.0-beta.2 → 24.0.0-beta.4
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/executors.d.ts +0 -3
- package/dist/executors.js +0 -7
- package/dist/plugins/nx-copy-assets.plugin.d.ts +4 -5
- package/dist/plugins/nx-copy-assets.plugin.js +5 -49
- package/dist/plugins/nx-ready-signal.plugin.d.ts +8 -0
- package/dist/plugins/nx-ready-signal.plugin.js +41 -0
- package/dist/plugins/nx-tsconfig-paths.plugin.d.ts +5 -7
- package/dist/plugins/nx-tsconfig-paths.plugin.js +6 -247
- package/dist/ready-check.d.ts +1 -0
- package/dist/ready-check.js +9 -0
- package/dist/src/generators/configuration/configuration.js +2 -39
- package/dist/src/generators/configuration/lib/convert-non-vite.js +1 -0
- package/dist/src/generators/configuration/schema.d.ts +0 -1
- package/dist/src/generators/convert-to-inferred/lib/build-post-target-transformer.d.ts +0 -1
- package/dist/src/generators/convert-to-inferred/lib/build-post-target-transformer.js +3 -66
- package/dist/src/generators/init/init.js +20 -32
- package/dist/src/generators/init/schema.d.ts +0 -1
- package/dist/src/generators/init/schema.json +1 -1
- package/dist/src/generators/setup-paths-plugin/schema.d.ts +0 -1
- package/dist/src/generators/setup-paths-plugin/schema.json +2 -2
- package/dist/src/generators/setup-paths-plugin/setup-paths-plugin.js +16 -91
- package/dist/src/migrations/update-23-0-0/ai-instructions-for-vitest-3.md +5 -5
- package/dist/src/migrations/update-23-0-0/ai-instructions-for-vitest-4.md +6 -6
- package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +12 -0
- package/dist/src/migrations/update-24-0-0/migrate-config-helpers.md +86 -0
- package/dist/src/migrations/update-24-0-0/migrate-nx-vite-ts-paths.d.ts +2 -0
- package/dist/src/migrations/update-24-0-0/migrate-nx-vite-ts-paths.js +154 -0
- package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.d.ts +4 -0
- package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.js +11 -0
- package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.md +37 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +46 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +71 -0
- package/dist/src/plugins/plugin.d.ts +9 -5
- package/dist/src/plugins/plugin.js +56 -49
- package/dist/src/utils/deprecation.d.ts +2 -9
- package/dist/src/utils/deprecation.js +5 -35
- package/dist/src/utils/dev-server-ready-check.d.ts +27 -0
- package/dist/src/utils/dev-server-ready-check.js +174 -0
- package/dist/src/utils/e2e-web-server-info-utils.d.ts +2 -2
- package/dist/src/utils/e2e-web-server-info-utils.js +4 -4
- package/dist/src/utils/executor-utils.d.ts +0 -10
- package/dist/src/utils/executor-utils.js +0 -51
- package/dist/src/utils/generator-utils.d.ts +1 -10
- package/dist/src/utils/generator-utils.js +62 -114
- package/dist/src/utils/options-utils.d.ts +0 -16
- package/dist/src/utils/options-utils.js +0 -73
- package/dist/src/utils/versions.d.ts +2 -0
- package/dist/src/utils/versions.js +3 -1
- package/dist/src/utils/vite-config-edit-utils.d.ts +9 -1
- package/dist/src/utils/vite-config-edit-utils.js +143 -1
- package/executors.json +2 -34
- package/generators.json +1 -1
- package/migrations.json +19 -0
- package/package.json +22 -7
- package/dist/src/executors/build/build.impl.d.ts +0 -11
- package/dist/src/executors/build/build.impl.js +0 -205
- package/dist/src/executors/build/compat.d.ts +0 -2
- package/dist/src/executors/build/compat.js +0 -6
- package/dist/src/executors/build/schema.json +0 -82
- package/dist/src/executors/dev-server/compat.d.ts +0 -2
- package/dist/src/executors/dev-server/compat.js +0 -6
- package/dist/src/executors/dev-server/dev-server.impl.d.ts +0 -7
- package/dist/src/executors/dev-server/dev-server.impl.js +0 -137
- package/dist/src/executors/dev-server/schema.json +0 -40
- package/dist/src/executors/preview-server/compat.d.ts +0 -2
- package/dist/src/executors/preview-server/compat.js +0 -6
- package/dist/src/executors/preview-server/preview-server.impl.d.ts +0 -7
- package/dist/src/executors/preview-server/preview-server.impl.js +0 -184
- package/dist/src/executors/preview-server/schema.json +0 -44
- package/dist/src/utils/nx-tsconfig-paths-find-file.d.ts +0 -2
- package/dist/src/utils/nx-tsconfig-paths-find-file.js +0 -22
- package/dist/src/utils/nx-tsconfig-paths-load-file.d.ts +0 -12
- package/dist/src/utils/nx-tsconfig-paths-load-file.js +0 -71
package/dist/executors.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
-
|
|
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
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AddressInfo } from 'net';
|
|
2
|
+
import type { Plugin } from 'vite';
|
|
3
|
+
/**
|
|
4
|
+
* Reports the dev or preview server's address to an Nx task whose readyWhen
|
|
5
|
+
* is `signal`, once the server listens. Does nothing outside such a task.
|
|
6
|
+
*/
|
|
7
|
+
export declare function nxReadySignal(): Plugin;
|
|
8
|
+
export declare function getServerUrl(address: AddressInfo | string | null, https: boolean): string | undefined;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nxReadySignal = nxReadySignal;
|
|
4
|
+
exports.getServerUrl = getServerUrl;
|
|
5
|
+
/**
|
|
6
|
+
* Reports the dev or preview server's address to an Nx task whose readyWhen
|
|
7
|
+
* is `signal`, once the server listens. Does nothing outside such a task.
|
|
8
|
+
*/
|
|
9
|
+
function nxReadySignal() {
|
|
10
|
+
return {
|
|
11
|
+
// No `apply`, so inference finds it in the config Vite resolves for a
|
|
12
|
+
// build. Its hooks only run for the dev and preview servers.
|
|
13
|
+
name: 'nx-ready-signal',
|
|
14
|
+
configureServer(server) {
|
|
15
|
+
report(server.httpServer, !!server.config.server.https);
|
|
16
|
+
},
|
|
17
|
+
configurePreviewServer(server) {
|
|
18
|
+
report(server.httpServer, !!server.config.preview.https);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function report(httpServer, https) {
|
|
23
|
+
if (!httpServer || !process.env.NX_READY_SIGNAL_SOCKET) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const { signalTaskReady } = require('@nx/devkit');
|
|
27
|
+
httpServer.once('listening', () => {
|
|
28
|
+
signalTaskReady({ url: getServerUrl(httpServer.address(), https) });
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function getServerUrl(address, https) {
|
|
32
|
+
if (!address || typeof address === 'string') {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const host = address.address === '::' || address.address === '0.0.0.0'
|
|
36
|
+
? 'localhost'
|
|
37
|
+
: address.family === 'IPv6'
|
|
38
|
+
? `[${address.address}]`
|
|
39
|
+
: address.address;
|
|
40
|
+
return `${https ? 'https' : 'http'}://${host}:${address.port}/`;
|
|
41
|
+
}
|
|
@@ -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
|
|
40
|
-
*
|
|
41
|
-
*
|
|
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(
|
|
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
|
-
|
|
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
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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(
|
|
11
|
+
function nxViteTsPaths(_options = {}) {
|
|
22
12
|
(0, deprecation_1.warnNxViteTsPathsDeprecation)();
|
|
23
|
-
|
|
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
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function waitForDevServer(configPath: string, command: 'serve' | 'preview'): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForDevServer = waitForDevServer;
|
|
4
|
+
const dev_server_ready_check_1 = require("./src/utils/dev-server-ready-check");
|
|
5
|
+
async function waitForDevServer(configPath, command) {
|
|
6
|
+
await (0, dev_server_ready_check_1.waitForViteServer)(configPath, command);
|
|
7
|
+
// Config hooks can leave handles open, such as vite-plugin-checker's workers
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
@@ -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
|
|
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,
|
|
@@ -6,6 +6,7 @@ const find_vite_config_1 = require("../../../utils/find-vite-config");
|
|
|
6
6
|
const generator_utils_1 = require("../../../utils/generator-utils");
|
|
7
7
|
const internal_1 = require("@nx/js/internal");
|
|
8
8
|
async function convertNonVite(tree, schema, projectRoot, _projectType, targets) {
|
|
9
|
+
(0, generator_utils_1.assertNoRemovedExecutorTargets)(schema.project, targets);
|
|
9
10
|
// Check if it has vite
|
|
10
11
|
const hasViteConfig = (0, find_vite_config_1.findViteConfig)(tree, projectRoot);
|
|
11
12
|
const hasIndexHtmlAtRoot = tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'index.html'));
|
|
@@ -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;
|