@nx/vite 24.0.0-beta.3 → 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/plugins/nx-ready-signal.plugin.d.ts +8 -0
- package/dist/plugins/nx-ready-signal.plugin.js +41 -0
- package/dist/ready-check.d.ts +1 -0
- package/dist/ready-check.js +9 -0
- package/dist/src/generators/configuration/lib/convert-non-vite.js +1 -0
- package/dist/src/plugins/plugin.js +22 -4
- 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/generator-utils.d.ts +1 -0
- package/dist/src/utils/generator-utils.js +28 -10
- package/package.json +22 -6
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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'));
|
|
@@ -108,7 +108,8 @@ async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFi
|
|
|
108
108
|
targets[options.buildTargetName] = await buildTarget(options.buildTargetName, namedInputs, buildOutputs, projectRoot, isUsingTsSolutionSetup, pmc);
|
|
109
109
|
// If running in library mode, then there is nothing to serve.
|
|
110
110
|
if (!viteBuildConfig.build?.lib || hasServeConfig) {
|
|
111
|
-
const
|
|
111
|
+
const signals = !!viteBuildConfig.plugins?.some((p) => p.name === 'nx-ready-signal');
|
|
112
|
+
const devTarget = serveTarget(projectRoot, configFilePath, signals, isUsingTsSolutionSetup, pmc, namedInputs);
|
|
112
113
|
targets[options.serveTargetName] = {
|
|
113
114
|
...devTarget,
|
|
114
115
|
metadata: {
|
|
@@ -117,7 +118,7 @@ async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFi
|
|
|
117
118
|
},
|
|
118
119
|
};
|
|
119
120
|
targets[options.devTargetName] = devTarget;
|
|
120
|
-
targets[options.previewTargetName] = previewTarget(projectRoot, options.buildTargetName, pmc, namedInputs);
|
|
121
|
+
targets[options.previewTargetName] = previewTarget(projectRoot, configFilePath, signals, options.buildTargetName, pmc, namedInputs);
|
|
121
122
|
targets[options.serveStaticTargetName] = serveStaticTarget(options, isUsingTsSolutionSetup, namedInputs);
|
|
122
123
|
}
|
|
123
124
|
}
|
|
@@ -201,7 +202,7 @@ function buildInputs(namedInputs) {
|
|
|
201
202
|
},
|
|
202
203
|
];
|
|
203
204
|
}
|
|
204
|
-
function serveTarget(projectRoot, isUsingTsSolutionSetup, pmc, namedInputs) {
|
|
205
|
+
function serveTarget(projectRoot, configFilePath, signals, isUsingTsSolutionSetup, pmc, namedInputs) {
|
|
205
206
|
const targetConfig = {
|
|
206
207
|
continuous: true,
|
|
207
208
|
inputs: buildInputs(namedInputs),
|
|
@@ -209,6 +210,7 @@ function serveTarget(projectRoot, isUsingTsSolutionSetup, pmc, namedInputs) {
|
|
|
209
210
|
options: {
|
|
210
211
|
cwd: (0, devkit_1.joinPathFragments)(projectRoot),
|
|
211
212
|
},
|
|
213
|
+
readyWhen: getServerReadyWhen(configFilePath, 'serve', signals),
|
|
212
214
|
metadata: {
|
|
213
215
|
technologies: ['vite'],
|
|
214
216
|
description: `Starts Vite dev server`,
|
|
@@ -227,7 +229,7 @@ function serveTarget(projectRoot, isUsingTsSolutionSetup, pmc, namedInputs) {
|
|
|
227
229
|
}
|
|
228
230
|
return targetConfig;
|
|
229
231
|
}
|
|
230
|
-
function previewTarget(projectRoot, buildTargetName, pmc, namedInputs) {
|
|
232
|
+
function previewTarget(projectRoot, configFilePath, signals, buildTargetName, pmc, namedInputs) {
|
|
231
233
|
const targetConfig = {
|
|
232
234
|
continuous: true,
|
|
233
235
|
inputs: buildInputs(namedInputs),
|
|
@@ -236,6 +238,7 @@ function previewTarget(projectRoot, buildTargetName, pmc, namedInputs) {
|
|
|
236
238
|
options: {
|
|
237
239
|
cwd: (0, devkit_1.joinPathFragments)(projectRoot),
|
|
238
240
|
},
|
|
241
|
+
readyWhen: getServerReadyWhen(configFilePath, 'preview', signals),
|
|
239
242
|
metadata: {
|
|
240
243
|
technologies: ['vite'],
|
|
241
244
|
description: `Locally preview Vite production build`,
|
|
@@ -260,12 +263,27 @@ function serveStaticTarget(options, isUsingTsSolutionSetup, namedInputs) {
|
|
|
260
263
|
buildTarget: `${options.buildTargetName}`,
|
|
261
264
|
spa: true,
|
|
262
265
|
},
|
|
266
|
+
readyWhen: { port: '{options.port}', host: '{options.host ?? localhost}' },
|
|
263
267
|
};
|
|
264
268
|
if (isUsingTsSolutionSetup) {
|
|
265
269
|
targetConfig.syncGenerators = ['@nx/js:typescript-sync'];
|
|
266
270
|
}
|
|
267
271
|
return targetConfig;
|
|
268
272
|
}
|
|
273
|
+
// A config that loads nxReadySignal() reports when the server listens.
|
|
274
|
+
// Otherwise the check resolves the config when the task runs, with the task's
|
|
275
|
+
// env and options, and waits for the server's port.
|
|
276
|
+
function getServerReadyWhen(configFilePath, command, signals) {
|
|
277
|
+
return signals
|
|
278
|
+
? { signal: true }
|
|
279
|
+
: {
|
|
280
|
+
// Unquoted: the plugin's glob fixes the file name. Quote it if it ever
|
|
281
|
+
// becomes user-chosen, since the shell expands $, backticks and %.
|
|
282
|
+
command: `node -e "require('@nx/vite/ready-check').waitForDevServer(process.argv[1], '${command}')" ${(0, node_path_1.basename)(configFilePath)}`,
|
|
283
|
+
// Each attempt resolves the config
|
|
284
|
+
interval: 1000,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
269
287
|
function getOutputs(viteBuildConfig, projectRoot, workspaceRoot) {
|
|
270
288
|
// TODO(jack): Remove this cast when @nx/vite switches to moduleResolution:
|
|
271
289
|
// "nodenext". Vite 8's rolldown types are ESM-only (.d.mts) and not
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface ViteFlags {
|
|
2
|
+
port?: string;
|
|
3
|
+
host?: string | boolean;
|
|
4
|
+
mode?: string;
|
|
5
|
+
config?: string;
|
|
6
|
+
root?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The flags `vite` and `vite preview` get from the target's options, in the
|
|
10
|
+
* order run-commands passes them: named options, `args`, then overrides.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseViteFlags(options: Record<string, unknown>, command: 'serve' | 'preview'): ViteFlags;
|
|
13
|
+
export type ServerAddress = {
|
|
14
|
+
port: number;
|
|
15
|
+
host?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function getViteServerAddress(server: {
|
|
18
|
+
port?: unknown;
|
|
19
|
+
host?: unknown;
|
|
20
|
+
} | undefined, flags: ViteFlags, command: 'serve' | 'preview'): ServerAddress | null;
|
|
21
|
+
/**
|
|
22
|
+
* The readyWhen of the inferred serve and preview targets when the config
|
|
23
|
+
* doesn't load the signal plugin. Runs in the env and with the options of the
|
|
24
|
+
* task, resolves the config the way `vite` does, and waits for the server's
|
|
25
|
+
* port.
|
|
26
|
+
*/
|
|
27
|
+
export declare function waitForViteServer(configPath: string, command: 'serve' | 'preview'): Promise<void>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseViteFlags = parseViteFlags;
|
|
4
|
+
exports.getViteServerAddress = getViteServerAddress;
|
|
5
|
+
exports.waitForViteServer = waitForViteServer;
|
|
6
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
7
|
+
const net_1 = require("net");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const executor_utils_1 = require("./executor-utils");
|
|
10
|
+
// Vite's boolean options: the arg after one is positional, not its value
|
|
11
|
+
const GLOBAL_BOOLEAN_OPTIONS = ['clearScreen', 'h', 'help', 'v', 'version'];
|
|
12
|
+
const BOOLEAN_OPTIONS = {
|
|
13
|
+
serve: [
|
|
14
|
+
...GLOBAL_BOOLEAN_OPTIONS,
|
|
15
|
+
'cors',
|
|
16
|
+
'strictPort',
|
|
17
|
+
'force',
|
|
18
|
+
'experimentalBundle',
|
|
19
|
+
],
|
|
20
|
+
preview: [...GLOBAL_BOOLEAN_OPTIONS, 'strictPort'],
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The flags `vite` and `vite preview` get from the target's options, in the
|
|
24
|
+
* order run-commands passes them: named options, `args`, then overrides.
|
|
25
|
+
*/
|
|
26
|
+
function parseViteFlags(options, command) {
|
|
27
|
+
const args = Array.isArray(options.args)
|
|
28
|
+
? options.args.join(' ')
|
|
29
|
+
: typeof options.args === 'string'
|
|
30
|
+
? options.args
|
|
31
|
+
: '';
|
|
32
|
+
const unparsed = Array.isArray(options.__unparsed__)
|
|
33
|
+
? options.__unparsed__.map(String)
|
|
34
|
+
: [];
|
|
35
|
+
// run-commands skips a named option the overrides set, or that args set to
|
|
36
|
+
// another value, parsing both with nx's yargs-parser
|
|
37
|
+
const yargsParser = require(require.resolve('yargs-parser', {
|
|
38
|
+
paths: [(0, path_1.dirname)(require.resolve('nx/package.json'))],
|
|
39
|
+
}));
|
|
40
|
+
const overrides = yargsParser(unparsed, {
|
|
41
|
+
configuration: {
|
|
42
|
+
'parse-numbers': false,
|
|
43
|
+
'parse-positional-numbers': false,
|
|
44
|
+
'dot-notation': false,
|
|
45
|
+
'camel-case-expansion': false,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const fromArgs = args
|
|
49
|
+
? yargsParser(args.replace(/(^"|"$)/g, ''), {
|
|
50
|
+
configuration: { 'camel-case-expansion': true },
|
|
51
|
+
})
|
|
52
|
+
: {};
|
|
53
|
+
const named = Object.keys(options)
|
|
54
|
+
.filter((k) => ['port', 'host', 'mode', 'm', 'config', 'c'].includes(k) &&
|
|
55
|
+
typeof options[k] !== 'object' &&
|
|
56
|
+
overrides[k] === undefined &&
|
|
57
|
+
(!Object.hasOwn(fromArgs, k) || fromArgs[k] === options[k]))
|
|
58
|
+
.map((k) => `--${k}=${options[k]}`);
|
|
59
|
+
const { values, positionals } = parseArgv([...named, ...(0, internal_1.splitShellArgs)(args), ...unparsed], BOOLEAN_OPTIONS[command]);
|
|
60
|
+
// Vite keeps the values of whichever spelling of an option comes first
|
|
61
|
+
const last = (...names) => values.get([...values.keys()].find((k) => names.includes(k)))?.at(-1);
|
|
62
|
+
const asString = (value) => typeof value === 'string' ? value : undefined;
|
|
63
|
+
return {
|
|
64
|
+
port: asString(last('port')),
|
|
65
|
+
host: last('host'),
|
|
66
|
+
mode: asString(last('m', 'mode')),
|
|
67
|
+
config: asString(last('c', 'config')),
|
|
68
|
+
root: positionals[0],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
// A port of the mri parser Vite's CLI uses, keeping each option's values
|
|
72
|
+
function parseArgv(argv, booleans) {
|
|
73
|
+
const values = new Map();
|
|
74
|
+
const positionals = [];
|
|
75
|
+
const add = (name, value) => values.set(name, [...(values.get(name) ?? []), value]);
|
|
76
|
+
for (let i = 0; i < argv.length; i++) {
|
|
77
|
+
const arg = argv[i];
|
|
78
|
+
if (arg === '--')
|
|
79
|
+
break;
|
|
80
|
+
const dashes = arg.match(/^-*/)[0].length;
|
|
81
|
+
if (dashes === 0) {
|
|
82
|
+
positionals.push(arg);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (arg.startsWith('no-', dashes)) {
|
|
86
|
+
add(arg.slice(dashes + 3), false);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const eq = arg.indexOf('=', dashes + 1);
|
|
90
|
+
const name = arg.slice(dashes, eq === -1 ? undefined : eq);
|
|
91
|
+
const value = (eq === -1 ? '' : arg.slice(eq + 1)) ||
|
|
92
|
+
i + 1 === argv.length ||
|
|
93
|
+
argv[i + 1].startsWith('-') ||
|
|
94
|
+
argv[++i];
|
|
95
|
+
// `-abc` sets a, b and c, and the value goes to c
|
|
96
|
+
const names = dashes === 2 ? [name] : [...name];
|
|
97
|
+
names.forEach((n, j) => {
|
|
98
|
+
const v = j === names.length - 1 ? value : true;
|
|
99
|
+
if (typeof v === 'string' && booleans.includes(n)) {
|
|
100
|
+
if (v !== 'true' && v !== 'false')
|
|
101
|
+
positionals.push(v);
|
|
102
|
+
add(n, v !== 'false');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
add(n, v);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return { values, positionals };
|
|
110
|
+
}
|
|
111
|
+
// Vite's default ports: https://vite.dev/config/server-options#server-port
|
|
112
|
+
const DEFAULT_PORT = { serve: 5173, preview: 4173 };
|
|
113
|
+
function getViteServerAddress(server, flags, command) {
|
|
114
|
+
const port = Number(flags.port ?? server?.port ?? DEFAULT_PORT[command]);
|
|
115
|
+
if (!Number.isInteger(port) || port <= 0)
|
|
116
|
+
return null;
|
|
117
|
+
const host = flags.host ?? server?.host;
|
|
118
|
+
// `true` and the wildcards listen on every address, loopback included
|
|
119
|
+
return typeof host === 'string' &&
|
|
120
|
+
!['localhost', '0.0.0.0', '::'].includes(host)
|
|
121
|
+
? { port, host }
|
|
122
|
+
: { port };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The readyWhen of the inferred serve and preview targets when the config
|
|
126
|
+
* doesn't load the signal plugin. Runs in the env and with the options of the
|
|
127
|
+
* task, resolves the config the way `vite` does, and waits for the server's
|
|
128
|
+
* port.
|
|
129
|
+
*/
|
|
130
|
+
async function waitForViteServer(configPath, command) {
|
|
131
|
+
let options = {};
|
|
132
|
+
try {
|
|
133
|
+
options = JSON.parse(process.env.NX_TASK_OPTIONS ?? '{}');
|
|
134
|
+
}
|
|
135
|
+
catch { }
|
|
136
|
+
const flags = parseViteFlags(options, command);
|
|
137
|
+
process.chdir((0, path_1.resolve)(options.cwd ?? '.'));
|
|
138
|
+
const { resolveConfig } = await (0, executor_utils_1.loadViteDynamicImport)();
|
|
139
|
+
const inlineConfig = {
|
|
140
|
+
root: flags.root,
|
|
141
|
+
// With --root and no --config, Vite finds the config in the root, not in
|
|
142
|
+
// the task's cwd
|
|
143
|
+
configFile: flags.config ?? (flags.root ? undefined : configPath),
|
|
144
|
+
mode: flags.mode,
|
|
145
|
+
};
|
|
146
|
+
// The mode and NODE_ENV defaults of `vite` and `vite preview`
|
|
147
|
+
const config = command === 'preview'
|
|
148
|
+
? await resolveConfig(inlineConfig, 'serve', 'production', 'production', true)
|
|
149
|
+
: await resolveConfig(inlineConfig, 'serve');
|
|
150
|
+
const address = getViteServerAddress(command === 'preview'
|
|
151
|
+
? { ...config.preview, host: config.preview.host ?? config.server.host }
|
|
152
|
+
: config.server, flags, command);
|
|
153
|
+
if (address)
|
|
154
|
+
await waitForAddress(address);
|
|
155
|
+
}
|
|
156
|
+
async function waitForAddress({ port, host }) {
|
|
157
|
+
const hosts = host ? [host] : ['127.0.0.1', '::1'];
|
|
158
|
+
while (!(await Promise.any(hosts.map((h) => connects(port, h))).catch(() => false))) {
|
|
159
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function connects(port, host) {
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
const socket = (0, net_1.createConnection)({ port, host });
|
|
165
|
+
socket.once('connect', () => {
|
|
166
|
+
socket.destroy();
|
|
167
|
+
resolve(true);
|
|
168
|
+
});
|
|
169
|
+
socket.once('error', (e) => {
|
|
170
|
+
socket.destroy();
|
|
171
|
+
reject(e);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
@@ -10,6 +10,7 @@ export declare function findExistingJsBuildTargetInProject(targets: {
|
|
|
10
10
|
supported?: string;
|
|
11
11
|
unsupported?: string;
|
|
12
12
|
};
|
|
13
|
+
export declare function assertNoRemovedExecutorTargets(projectName: string, targets: Record<string, TargetConfiguration> | undefined): void;
|
|
13
14
|
export declare function editTsConfig(tree: Tree, options: ViteConfigurationGeneratorSchema): void;
|
|
14
15
|
export declare function deleteWebpackConfig(tree: Tree, projectRoot: string, webpackConfigFilePath?: string): void;
|
|
15
16
|
export declare function moveAndEditIndexHtml(tree: Tree, options: ViteConfigurationGeneratorSchema): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findExistingJsBuildTargetInProject = findExistingJsBuildTargetInProject;
|
|
4
|
+
exports.assertNoRemovedExecutorTargets = assertNoRemovedExecutorTargets;
|
|
4
5
|
exports.editTsConfig = editTsConfig;
|
|
5
6
|
exports.deleteWebpackConfig = deleteWebpackConfig;
|
|
6
7
|
exports.moveAndEditIndexHtml = moveAndEditIndexHtml;
|
|
@@ -18,7 +19,7 @@ const versions_1 = require("./versions");
|
|
|
18
19
|
function findExistingJsBuildTargetInProject(targets) {
|
|
19
20
|
const output = {};
|
|
20
21
|
const supportedExecutors = {
|
|
21
|
-
build: ['@nx/js:
|
|
22
|
+
build: ['@nx/js:swc'],
|
|
22
23
|
};
|
|
23
24
|
const unsupportedExecutors = [
|
|
24
25
|
'@nx/angular:ng-packagr-lite',
|
|
@@ -62,6 +63,24 @@ function findExistingJsBuildTargetInProject(targets) {
|
|
|
62
63
|
}
|
|
63
64
|
return output;
|
|
64
65
|
}
|
|
66
|
+
// A leftover target on one of these can't run, and it shadows the inferred
|
|
67
|
+
// target with the same name, so converting around it leaves a broken project.
|
|
68
|
+
const removedConvertibleExecutors = [
|
|
69
|
+
'@nx/rollup:rollup',
|
|
70
|
+
'@nx/vite:build',
|
|
71
|
+
'@nx/vite:dev-server',
|
|
72
|
+
'@nx/vite:preview-server',
|
|
73
|
+
'@nx/webpack:dev-server',
|
|
74
|
+
'@nx/webpack:webpack',
|
|
75
|
+
];
|
|
76
|
+
function assertNoRemovedExecutorTargets(projectName, targets) {
|
|
77
|
+
const removedTargets = Object.entries(targets ?? {})
|
|
78
|
+
.filter(([, target]) => removedConvertibleExecutors.includes(target.executor))
|
|
79
|
+
.map(([targetName, target]) => `${targetName} (${target.executor})`);
|
|
80
|
+
if (removedTargets.length) {
|
|
81
|
+
throw new Error(`The project ${projectName} has targets using removed executors: ${removedTargets.join(', ')}. Convert them to inferred targets first, for example with "nx g @nx/workspace:infer-targets --project=${projectName}".`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
65
84
|
function editTsConfig(tree, options) {
|
|
66
85
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
67
86
|
let tsconfigPath = (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json');
|
|
@@ -224,6 +243,11 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
224
243
|
if (!onlyVitest && options.includeLib) {
|
|
225
244
|
plugins.push(`dts({ entryRoot: 'src', tsconfigPath: path.join(import.meta.dirname, 'tsconfig.lib.json')${!isTsSolutionSetup ? ', pathsToAliases: false' : ''} })`);
|
|
226
245
|
}
|
|
246
|
+
// Lets the inferred serve and preview targets know when the server is up
|
|
247
|
+
if (!onlyVitest && !options.includeLib) {
|
|
248
|
+
imports.push(`import { nxReadySignal } from '@nx/vite/plugins/nx-ready-signal.plugin'`);
|
|
249
|
+
plugins.push('nxReadySignal()');
|
|
250
|
+
}
|
|
227
251
|
const reportsDirectory = isTsSolutionSetup
|
|
228
252
|
? './test-output/vitest/coverage'
|
|
229
253
|
: projectRoot === '.'
|
|
@@ -313,16 +337,10 @@ function normalizeViteConfigFilePathWithTree(tree, projectRoot, configFile) {
|
|
|
313
337
|
: undefined;
|
|
314
338
|
}
|
|
315
339
|
function getViteConfigPathForProject(tree, projectName, target) {
|
|
316
|
-
let viteConfigPath;
|
|
317
340
|
const { targets, root } = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
else {
|
|
322
|
-
const config = Object.values(targets).find((config) => config.executor === '@nrwl/nx:build' ||
|
|
323
|
-
config.executor === '@nrwl/vite:build');
|
|
324
|
-
viteConfigPath = config?.options?.configFile;
|
|
325
|
-
}
|
|
341
|
+
const viteConfigPath = target
|
|
342
|
+
? targets?.[target]?.options?.configFile
|
|
343
|
+
: undefined;
|
|
326
344
|
return normalizeViteConfigFilePathWithTree(tree, root, viteConfigPath);
|
|
327
345
|
}
|
|
328
346
|
async function handleUnsupportedUserProvidedTargets(userProvidedTargetIsUnsupported, userProvidedTargetName, validFoundTargetName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "24.0.0-beta.
|
|
3
|
+
"version": "24.0.0-beta.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -36,11 +36,17 @@
|
|
|
36
36
|
"plugins/nx-copy-assets.plugin": [
|
|
37
37
|
"dist/plugins/nx-copy-assets.plugin.d.ts"
|
|
38
38
|
],
|
|
39
|
+
"plugins/nx-ready-signal.plugin": [
|
|
40
|
+
"dist/plugins/nx-ready-signal.plugin.d.ts"
|
|
41
|
+
],
|
|
39
42
|
"plugins/nx-tsconfig-paths.plugin": [
|
|
40
43
|
"dist/plugins/nx-tsconfig-paths.plugin.d.ts"
|
|
41
44
|
],
|
|
42
45
|
"plugins/rollup-replace-files.plugin": [
|
|
43
46
|
"dist/plugins/rollup-replace-files.plugin.d.ts"
|
|
47
|
+
],
|
|
48
|
+
"ready-check": [
|
|
49
|
+
"dist/ready-check.d.ts"
|
|
44
50
|
]
|
|
45
51
|
}
|
|
46
52
|
},
|
|
@@ -59,6 +65,11 @@
|
|
|
59
65
|
"types": "./dist/plugin.d.ts",
|
|
60
66
|
"default": "./dist/plugin.js"
|
|
61
67
|
},
|
|
68
|
+
"./ready-check": {
|
|
69
|
+
"@nx/nx-source": "./ready-check.ts",
|
|
70
|
+
"types": "./dist/ready-check.d.ts",
|
|
71
|
+
"default": "./dist/ready-check.js"
|
|
72
|
+
},
|
|
62
73
|
"./executors": {
|
|
63
74
|
"@nx/nx-source": "./executors.ts",
|
|
64
75
|
"types": "./dist/executors.d.ts",
|
|
@@ -69,6 +80,11 @@
|
|
|
69
80
|
"types": "./dist/plugins/nx-copy-assets.plugin.d.ts",
|
|
70
81
|
"default": "./dist/plugins/nx-copy-assets.plugin.js"
|
|
71
82
|
},
|
|
83
|
+
"./plugins/nx-ready-signal.plugin": {
|
|
84
|
+
"@nx/nx-source": "./plugins/nx-ready-signal.plugin.ts",
|
|
85
|
+
"types": "./dist/plugins/nx-ready-signal.plugin.d.ts",
|
|
86
|
+
"default": "./dist/plugins/nx-ready-signal.plugin.js"
|
|
87
|
+
},
|
|
72
88
|
"./plugins/nx-tsconfig-paths.plugin": {
|
|
73
89
|
"@nx/nx-source": "./plugins/nx-tsconfig-paths.plugin.ts",
|
|
74
90
|
"types": "./dist/plugins/nx-tsconfig-paths.plugin.d.ts",
|
|
@@ -94,18 +110,18 @@
|
|
|
94
110
|
"supportsOptionalMigrations": true
|
|
95
111
|
},
|
|
96
112
|
"dependencies": {
|
|
97
|
-
"@nx/devkit": "24.0.0-beta.
|
|
113
|
+
"@nx/devkit": "24.0.0-beta.4",
|
|
98
114
|
"@phenomnomnominal/tsquery": "~6.2.0",
|
|
99
|
-
"@nx/js": "24.0.0-beta.
|
|
100
|
-
"@nx/vitest": "24.0.0-beta.
|
|
115
|
+
"@nx/js": "24.0.0-beta.4",
|
|
116
|
+
"@nx/vitest": "24.0.0-beta.4",
|
|
101
117
|
"picomatch": "4.0.4",
|
|
102
118
|
"semver": "^7.6.3",
|
|
103
119
|
"tslib": "^2.3.0",
|
|
104
120
|
"ajv": "^8.0.0"
|
|
105
121
|
},
|
|
106
122
|
"devDependencies": {
|
|
107
|
-
"@nx/eslint": "24.0.0-beta.
|
|
108
|
-
"nx": "24.0.0-beta.
|
|
123
|
+
"@nx/eslint": "24.0.0-beta.4",
|
|
124
|
+
"nx": "24.0.0-beta.4"
|
|
109
125
|
},
|
|
110
126
|
"peerDependencies": {
|
|
111
127
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|