@nx/vite 24.0.0-beta.2 → 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.
- 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-tsconfig-paths.plugin.d.ts +5 -7
- package/dist/plugins/nx-tsconfig-paths.plugin.js +6 -247
- package/dist/src/generators/configuration/configuration.js +2 -39
- 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 +34 -45
- package/dist/src/utils/deprecation.d.ts +2 -9
- package/dist/src/utils/deprecation.js +5 -35
- 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 +0 -10
- package/dist/src/utils/generator-utils.js +36 -106
- 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 +6 -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
|
@@ -1,17 +1 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';
|
|
3
|
-
/**
|
|
4
|
-
* Returns the path to the vite config file or undefined when not found.
|
|
5
|
-
*/
|
|
6
|
-
export declare function normalizeViteConfigFilePath(contextRoot: string, projectRoot: string, configFile?: string): string | undefined;
|
|
7
1
|
export declare function getProjectTsConfigPath(projectRoot: string): string | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* Returns the path to the proxy configuration file or undefined when not found.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getViteServerProxyConfigPath(nxProxyConfig: string | undefined, context: ExecutorContext): string | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* Builds the options for the vite dev server.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getViteServerOptions(options: ViteDevServerExecutorOptions, context: ExecutorContext): Promise<Record<string, unknown>>;
|
|
16
|
-
export declare function getProxyConfig(context: ExecutorContext, proxyConfig?: string): Record<string, string | unknown> | undefined;
|
|
17
|
-
export declare function getNxTargetOptions(target: string, context: ExecutorContext): any;
|
|
@@ -1,32 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeViteConfigFilePath = normalizeViteConfigFilePath;
|
|
4
3
|
exports.getProjectTsConfigPath = getProjectTsConfigPath;
|
|
5
|
-
exports.getViteServerProxyConfigPath = getViteServerProxyConfigPath;
|
|
6
|
-
exports.getViteServerOptions = getViteServerOptions;
|
|
7
|
-
exports.getProxyConfig = getProxyConfig;
|
|
8
|
-
exports.getNxTargetOptions = getNxTargetOptions;
|
|
9
4
|
const devkit_1 = require("@nx/devkit");
|
|
10
5
|
const fs_1 = require("fs");
|
|
11
|
-
const executor_utils_1 = require("./executor-utils");
|
|
12
|
-
/**
|
|
13
|
-
* Returns the path to the vite config file or undefined when not found.
|
|
14
|
-
*/
|
|
15
|
-
function normalizeViteConfigFilePath(contextRoot, projectRoot, configFile) {
|
|
16
|
-
if (configFile) {
|
|
17
|
-
const normalized = (0, devkit_1.joinPathFragments)(contextRoot, configFile);
|
|
18
|
-
if (!(0, fs_1.existsSync)(normalized)) {
|
|
19
|
-
throw new Error(`Could not find vite config at provided path "${normalized}".`);
|
|
20
|
-
}
|
|
21
|
-
return normalized;
|
|
22
|
-
}
|
|
23
|
-
const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];
|
|
24
|
-
for (const ext of allowsExt) {
|
|
25
|
-
if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(contextRoot, projectRoot, `vite.config.${ext}`))) {
|
|
26
|
-
return (0, devkit_1.joinPathFragments)(contextRoot, projectRoot, `vite.config.${ext}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
6
|
function getProjectTsConfigPath(projectRoot) {
|
|
31
7
|
return (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'tsconfig.app.json'))
|
|
32
8
|
? (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.app.json')
|
|
@@ -36,52 +12,3 @@ function getProjectTsConfigPath(projectRoot) {
|
|
|
36
12
|
? (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json')
|
|
37
13
|
: undefined;
|
|
38
14
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns the path to the proxy configuration file or undefined when not found.
|
|
41
|
-
*/
|
|
42
|
-
function getViteServerProxyConfigPath(nxProxyConfig, context) {
|
|
43
|
-
if (nxProxyConfig) {
|
|
44
|
-
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
45
|
-
const proxyConfigPath = nxProxyConfig
|
|
46
|
-
? (0, devkit_1.joinPathFragments)(context.root, nxProxyConfig)
|
|
47
|
-
: (0, devkit_1.joinPathFragments)(projectRoot, 'proxy.conf.json');
|
|
48
|
-
if ((0, fs_1.existsSync)(proxyConfigPath)) {
|
|
49
|
-
return proxyConfigPath;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Builds the options for the vite dev server.
|
|
55
|
-
*/
|
|
56
|
-
async function getViteServerOptions(options, context) {
|
|
57
|
-
// returns vite ServerOptions
|
|
58
|
-
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
59
|
-
const { searchForWorkspaceRoot } = await (0, executor_utils_1.loadViteDynamicImport)();
|
|
60
|
-
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
61
|
-
const serverOptions = {
|
|
62
|
-
fs: {
|
|
63
|
-
allow: [
|
|
64
|
-
searchForWorkspaceRoot((0, devkit_1.joinPathFragments)(projectRoot)),
|
|
65
|
-
(0, devkit_1.joinPathFragments)(context.root, 'node_modules/vite'),
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
const proxyConfigPath = getViteServerProxyConfigPath(options.proxyConfig, context);
|
|
70
|
-
if (proxyConfigPath) {
|
|
71
|
-
devkit_1.logger.info(`Loading proxy configuration from: ${proxyConfigPath}`);
|
|
72
|
-
serverOptions.proxy = require(proxyConfigPath);
|
|
73
|
-
}
|
|
74
|
-
return serverOptions;
|
|
75
|
-
}
|
|
76
|
-
function getProxyConfig(context, proxyConfig) {
|
|
77
|
-
const proxyConfigPath = getViteServerProxyConfigPath(proxyConfig, context);
|
|
78
|
-
if (proxyConfigPath) {
|
|
79
|
-
devkit_1.logger.info(`Loading proxy configuration from: ${proxyConfigPath}`);
|
|
80
|
-
return require(proxyConfigPath);
|
|
81
|
-
}
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
function getNxTargetOptions(target, context) {
|
|
85
|
-
const targetObj = (0, devkit_1.parseTargetString)(target, context);
|
|
86
|
-
return (0, devkit_1.readTargetOptions)(targetObj, context);
|
|
87
|
-
}
|
|
@@ -10,3 +10,5 @@ export declare const vitePluginReactSwcVersion = "^4.3.0";
|
|
|
10
10
|
export declare const vitePluginDtsVersion = "~4.5.0";
|
|
11
11
|
export declare const ajvVersion = "^8.0.0";
|
|
12
12
|
export declare const jitiVersion = "2.4.2";
|
|
13
|
+
export declare const viteTsconfigPathsVersion = "~4.3.2";
|
|
14
|
+
export declare const viteStaticCopyVersion = "^3.3.0";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jitiVersion = exports.ajvVersion = exports.vitePluginDtsVersion = exports.vitePluginReactSwcVersion = exports.vitePluginReactV4Version = exports.vitePluginReactVersion = exports.minSupportedViteVersion = exports.viteV5Version = exports.viteV6Version = exports.viteV7Version = exports.viteVersion = exports.nxVersion = void 0;
|
|
3
|
+
exports.viteStaticCopyVersion = exports.viteTsconfigPathsVersion = exports.jitiVersion = exports.ajvVersion = exports.vitePluginDtsVersion = exports.vitePluginReactSwcVersion = exports.vitePluginReactV4Version = exports.vitePluginReactVersion = exports.minSupportedViteVersion = exports.viteV5Version = exports.viteV6Version = exports.viteV7Version = exports.viteVersion = exports.nxVersion = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
exports.nxVersion = require((0, path_1.join)('@nx/vite', 'package.json')).version;
|
|
6
6
|
exports.viteVersion = '^8.0.0';
|
|
@@ -19,3 +19,5 @@ exports.vitePluginReactSwcVersion = '^4.3.0';
|
|
|
19
19
|
exports.vitePluginDtsVersion = '~4.5.0';
|
|
20
20
|
exports.ajvVersion = '^8.0.0';
|
|
21
21
|
exports.jitiVersion = '2.4.2';
|
|
22
|
+
exports.viteTsconfigPathsVersion = '~4.3.2';
|
|
23
|
+
exports.viteStaticCopyVersion = '^3.3.0';
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { TargetFlags } from './generator-utils';
|
|
3
|
-
export declare function ensureViteConfigIsCorrect(tree: Tree, path: string, buildConfigString: string, buildConfigObject: {}, imports: string[], plugins: string[], testConfigString: string, testConfigObject: {}, cacheDir: string, projectAlreadyHasViteTargets?: TargetFlags): boolean;
|
|
3
|
+
export declare function ensureViteConfigIsCorrect(tree: Tree, path: string, buildConfigString: string, buildConfigObject: {}, imports: string[], plugins: string[], testConfigString: string, testConfigObject: {}, cacheDir: string, projectAlreadyHasViteTargets?: TargetFlags, resolveTsconfigPaths?: boolean): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Enables Vite's native `resolve.tsconfigPaths`, which replaced the removed
|
|
6
|
+
* `nxViteTsPaths` plugin. Returns the file unchanged when it is already set or
|
|
7
|
+
* when the config's shape hides the object we would have to edit.
|
|
8
|
+
*/
|
|
9
|
+
export declare function addTsconfigPathsResolution(appFileContent: string): string;
|
|
10
|
+
export declare function hasTsconfigPathsResolution(content: string): boolean;
|
|
11
|
+
export declare function addTsconfigPathsPlugin(content: string, commonJs?: boolean): string;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureViteConfigIsCorrect = ensureViteConfigIsCorrect;
|
|
4
|
+
exports.addTsconfigPathsResolution = addTsconfigPathsResolution;
|
|
5
|
+
exports.hasTsconfigPathsResolution = hasTsconfigPathsResolution;
|
|
6
|
+
exports.addTsconfigPathsPlugin = addTsconfigPathsPlugin;
|
|
4
7
|
const devkit_1 = require("@nx/devkit");
|
|
5
8
|
const js_1 = require("@nx/js");
|
|
6
|
-
function ensureViteConfigIsCorrect(tree, path, buildConfigString, buildConfigObject, imports, plugins, testConfigString, testConfigObject, cacheDir, projectAlreadyHasViteTargets) {
|
|
9
|
+
function ensureViteConfigIsCorrect(tree, path, buildConfigString, buildConfigObject, imports, plugins, testConfigString, testConfigObject, cacheDir, projectAlreadyHasViteTargets, resolveTsconfigPaths) {
|
|
7
10
|
const fileContent = tree.read(path, 'utf-8');
|
|
8
11
|
let updatedContent = undefined;
|
|
9
12
|
if (!projectAlreadyHasViteTargets?.test && testConfigString?.length) {
|
|
@@ -18,6 +21,9 @@ function ensureViteConfigIsCorrect(tree, path, buildConfigString, buildConfigObj
|
|
|
18
21
|
if (cacheDir?.length) {
|
|
19
22
|
updatedContent = handleCacheDirNode(updatedContent ?? fileContent, cacheDir);
|
|
20
23
|
}
|
|
24
|
+
if (resolveTsconfigPaths) {
|
|
25
|
+
updatedContent = addTsconfigPathsResolution(updatedContent ?? fileContent);
|
|
26
|
+
}
|
|
21
27
|
if (updatedContent) {
|
|
22
28
|
tree.write(path, updatedContent);
|
|
23
29
|
return true;
|
|
@@ -301,6 +307,142 @@ function filterImport(appFileContent, imports) {
|
|
|
301
307
|
return !importsArrayExisting?.includes(importString);
|
|
302
308
|
});
|
|
303
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Enables Vite's native `resolve.tsconfigPaths`, which replaced the removed
|
|
312
|
+
* `nxViteTsPaths` plugin. Returns the file unchanged when it is already set or
|
|
313
|
+
* when the config's shape hides the object we would have to edit.
|
|
314
|
+
*/
|
|
315
|
+
function addTsconfigPathsResolution(appFileContent) {
|
|
316
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
317
|
+
const tsModule = require('typescript');
|
|
318
|
+
const file = tsquery.ast(appFileContent);
|
|
319
|
+
const config = findConfigObject(tsModule, tsquery, file);
|
|
320
|
+
if (!config || config.properties.some(tsModule.isSpreadAssignment))
|
|
321
|
+
return appFileContent;
|
|
322
|
+
const existingResolve = config.properties.find((prop) => tsModule.isPropertyAssignment(prop) &&
|
|
323
|
+
stripQuotes(prop.name.getText()) === 'resolve');
|
|
324
|
+
if (existingResolve) {
|
|
325
|
+
const target = existingResolve.initializer;
|
|
326
|
+
if (!tsModule.isObjectLiteralExpression(target) ||
|
|
327
|
+
target.properties.some(tsModule.isSpreadAssignment))
|
|
328
|
+
return appFileContent;
|
|
329
|
+
if (target.properties.some((prop) => prop.name && stripQuotes(prop.name.getText()) === 'tsconfigPaths')) {
|
|
330
|
+
return appFileContent;
|
|
331
|
+
}
|
|
332
|
+
return (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
333
|
+
{
|
|
334
|
+
type: devkit_1.ChangeType.Insert,
|
|
335
|
+
index: target.getStart() + 1,
|
|
336
|
+
text: `\n tsconfigPaths: true,`,
|
|
337
|
+
},
|
|
338
|
+
]);
|
|
339
|
+
}
|
|
340
|
+
return (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
341
|
+
{
|
|
342
|
+
type: devkit_1.ChangeType.Insert,
|
|
343
|
+
index: config.getStart() + 1,
|
|
344
|
+
text: `\n resolve: {\n tsconfigPaths: true,\n },`,
|
|
345
|
+
},
|
|
346
|
+
]);
|
|
347
|
+
}
|
|
348
|
+
function hasTsconfigPathsResolution(content) {
|
|
349
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
350
|
+
const tsModule = require('typescript');
|
|
351
|
+
const config = findConfigObject(tsModule, tsquery, tsquery.ast(content));
|
|
352
|
+
if (!config || config.properties.some(tsModule.isSpreadAssignment))
|
|
353
|
+
return false;
|
|
354
|
+
const resolve = config.properties.find((prop) => tsModule.isPropertyAssignment(prop) &&
|
|
355
|
+
stripQuotes(prop.name.getText()) === 'resolve');
|
|
356
|
+
if (!resolve ||
|
|
357
|
+
!tsModule.isPropertyAssignment(resolve) ||
|
|
358
|
+
!tsModule.isObjectLiteralExpression(resolve.initializer))
|
|
359
|
+
return false;
|
|
360
|
+
if (resolve.initializer.properties.some(tsModule.isSpreadAssignment))
|
|
361
|
+
return false;
|
|
362
|
+
return resolve.initializer.properties.some((prop) => tsModule.isPropertyAssignment(prop) &&
|
|
363
|
+
stripQuotes(prop.name.getText()) === 'tsconfigPaths' &&
|
|
364
|
+
prop.initializer.kind === tsModule.SyntaxKind.TrueKeyword);
|
|
365
|
+
}
|
|
366
|
+
function addTsconfigPathsPlugin(content, commonJs = false) {
|
|
367
|
+
if (content.includes('vite-tsconfig-paths'))
|
|
368
|
+
return content;
|
|
369
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
370
|
+
const tsModule = require('typescript');
|
|
371
|
+
const config = findConfigObject(tsModule, tsquery, tsquery.ast(content));
|
|
372
|
+
if (!config || config.properties.some(tsModule.isSpreadAssignment))
|
|
373
|
+
return content;
|
|
374
|
+
const plugins = config.properties.find((prop) => prop.name && stripQuotes(prop.name.getText()) === 'plugins');
|
|
375
|
+
if (plugins &&
|
|
376
|
+
(!tsModule.isPropertyAssignment(plugins) ||
|
|
377
|
+
!tsModule.isArrayLiteralExpression(plugins.initializer)))
|
|
378
|
+
return content;
|
|
379
|
+
const changes = [
|
|
380
|
+
{
|
|
381
|
+
type: devkit_1.ChangeType.Insert,
|
|
382
|
+
index: plugins
|
|
383
|
+
? plugins.initializer.getStart() + 1
|
|
384
|
+
: config.getStart() + 1,
|
|
385
|
+
text: plugins
|
|
386
|
+
? 'tsconfigPaths({ loose: true }), '
|
|
387
|
+
: '\nplugins: [tsconfigPaths({ loose: true })],',
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
type: devkit_1.ChangeType.Insert,
|
|
391
|
+
index: 0,
|
|
392
|
+
text: commonJs
|
|
393
|
+
? "const tsconfigPaths = require('vite-tsconfig-paths').default;\n"
|
|
394
|
+
: "import tsconfigPaths from 'vite-tsconfig-paths';\n",
|
|
395
|
+
},
|
|
396
|
+
];
|
|
397
|
+
return (0, devkit_1.applyChangesToString)(content, changes);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* The object literal a Vite config ultimately exports. Handles `defineConfig`
|
|
401
|
+
* called with an object or with a factory, and a bare default export. Returns
|
|
402
|
+
* undefined when the config is assembled somewhere we cannot follow.
|
|
403
|
+
*/
|
|
404
|
+
function findConfigObject(tsModule, tsquery, file) {
|
|
405
|
+
const exportAssignment = tsquery.query(file, 'ExportAssignment')[0];
|
|
406
|
+
if (exportAssignment) {
|
|
407
|
+
return unwrapConfigExpression(tsModule, exportAssignment.expression);
|
|
408
|
+
}
|
|
409
|
+
const moduleExports = tsquery.query(file, 'BinaryExpression').find((node) => node.left.getText() === 'module.exports' &&
|
|
410
|
+
node.operatorToken.kind === tsModule.SyntaxKind.EqualsToken);
|
|
411
|
+
return moduleExports
|
|
412
|
+
? unwrapConfigExpression(tsModule, moduleExports.right)
|
|
413
|
+
: undefined;
|
|
414
|
+
}
|
|
415
|
+
function unwrapConfigExpression(tsModule, node) {
|
|
416
|
+
if (!node)
|
|
417
|
+
return undefined;
|
|
418
|
+
if (tsModule.isParenthesizedExpression(node)) {
|
|
419
|
+
return unwrapConfigExpression(tsModule, node.expression);
|
|
420
|
+
}
|
|
421
|
+
if (tsModule.isObjectLiteralExpression(node))
|
|
422
|
+
return node;
|
|
423
|
+
if (tsModule.isCallExpression(node) &&
|
|
424
|
+
node.expression.getText() === 'defineConfig') {
|
|
425
|
+
return unwrapConfigExpression(tsModule, node.arguments[0]);
|
|
426
|
+
}
|
|
427
|
+
if (tsModule.isArrowFunction(node) || tsModule.isFunctionExpression(node)) {
|
|
428
|
+
if (!tsModule.isBlock(node.body)) {
|
|
429
|
+
return unwrapConfigExpression(tsModule, node.body);
|
|
430
|
+
}
|
|
431
|
+
// Only a single, unconditional return is safe to edit.
|
|
432
|
+
if (node.body.statements.some((statement) => !tsModule.isReturnStatement(statement) &&
|
|
433
|
+
!tsModule.isVariableStatement(statement) &&
|
|
434
|
+
!tsModule.isExpressionStatement(statement)))
|
|
435
|
+
return undefined;
|
|
436
|
+
const returns = node.body.statements.filter(tsModule.isReturnStatement);
|
|
437
|
+
return returns.length === 1
|
|
438
|
+
? unwrapConfigExpression(tsModule, returns[0].expression)
|
|
439
|
+
: undefined;
|
|
440
|
+
}
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
function stripQuotes(text) {
|
|
444
|
+
return text.replace(/^['"`]|['"`]$/g, '');
|
|
445
|
+
}
|
|
304
446
|
function handleCacheDirNode(appFileContent, cacheDir) {
|
|
305
447
|
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
306
448
|
const file = tsquery.ast(appFileContent);
|
package/executors.json
CHANGED
|
@@ -1,36 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"builders": {
|
|
3
|
-
|
|
4
|
-
"implementation": "./dist/src/executors/dev-server/compat",
|
|
5
|
-
"schema": "./dist/src/executors/dev-server/schema.json",
|
|
6
|
-
"description": "Vite dev server."
|
|
7
|
-
},
|
|
8
|
-
"build": {
|
|
9
|
-
"implementation": "./dist/src/executors/build/compat",
|
|
10
|
-
"schema": "./dist/src/executors/build/schema.json",
|
|
11
|
-
"description": "Build with Vite."
|
|
12
|
-
},
|
|
13
|
-
"preview-server": {
|
|
14
|
-
"implementation": "./dist/src/executors/preview-server/compat",
|
|
15
|
-
"schema": "./dist/src/executors/preview-server/schema.json",
|
|
16
|
-
"description": "Vite preview server"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"executors": {
|
|
20
|
-
"dev-server": {
|
|
21
|
-
"implementation": "./dist/src/executors/dev-server/dev-server.impl",
|
|
22
|
-
"schema": "./dist/src/executors/dev-server/schema.json",
|
|
23
|
-
"description": "Vite dev server."
|
|
24
|
-
},
|
|
25
|
-
"build": {
|
|
26
|
-
"implementation": "./dist/src/executors/build/build.impl",
|
|
27
|
-
"schema": "./dist/src/executors/build/schema.json",
|
|
28
|
-
"description": "Build with Vite."
|
|
29
|
-
},
|
|
30
|
-
"preview-server": {
|
|
31
|
-
"implementation": "./dist/src/executors/preview-server/preview-server.impl",
|
|
32
|
-
"schema": "./dist/src/executors/preview-server/schema.json",
|
|
33
|
-
"description": "Vite preview server"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
2
|
+
"builders": {},
|
|
3
|
+
"executors": {}
|
|
36
4
|
}
|
package/generators.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"setup-paths-plugin": {
|
|
20
20
|
"factory": "./dist/src/generators/setup-paths-plugin/setup-paths-plugin",
|
|
21
21
|
"schema": "./dist/src/generators/setup-paths-plugin/schema.json",
|
|
22
|
-
"description": "
|
|
22
|
+
"description": "Enables Vite's native tsconfig paths resolution to support workspace libraries."
|
|
23
23
|
},
|
|
24
24
|
"convert-to-inferred": {
|
|
25
25
|
"factory": "./dist/src/generators/convert-to-inferred/convert-to-inferred",
|
package/migrations.json
CHANGED
|
@@ -59,6 +59,25 @@
|
|
|
59
59
|
"description": "Rename imports of `createNodesV2` from `@nx/vite/plugin` to the canonical `createNodes` export.",
|
|
60
60
|
"implementation": "./dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes",
|
|
61
61
|
"documentation": "./dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.md"
|
|
62
|
+
},
|
|
63
|
+
"remove-deprecated-executors": {
|
|
64
|
+
"version": "24.0.0-beta.3",
|
|
65
|
+
"description": "Converts targets using the removed `@nx/vite` executors, and `@nx/vitest:test` targets, to inferred tasks; an AI prompt finishes the targets the converter cannot convert safely and validates the project graph.",
|
|
66
|
+
"implementation": "./dist/src/migrations/update-24-0-0/remove-deprecated-executors",
|
|
67
|
+
"prompt": "./dist/src/migrations/update-24-0-0/finish-inferred-conversion.md",
|
|
68
|
+
"documentation": "./dist/src/migrations/update-24-0-0/remove-deprecated-executors.md"
|
|
69
|
+
},
|
|
70
|
+
"update-24-0-0-migrate-config-helpers": {
|
|
71
|
+
"version": "24.0.0-beta.3",
|
|
72
|
+
"description": "Replace `nxViteTsPaths` with Vite's native `resolve.tsconfigPaths`, then migrate the remaining deprecated vite configuration helpers while preserving custom behavior.",
|
|
73
|
+
"implementation": "./dist/src/migrations/update-24-0-0/migrate-nx-vite-ts-paths",
|
|
74
|
+
"prompt": "./dist/src/migrations/update-24-0-0/migrate-config-helpers.md"
|
|
75
|
+
},
|
|
76
|
+
"update-24-0-0-register-typescript-plugin-for-typecheck": {
|
|
77
|
+
"version": "24.0.0-beta.3",
|
|
78
|
+
"description": "Register @nx/js/typescript with its typecheck target in workspaces that use @nx/vite/plugin without it, since @nx/vite/plugin no longer infers typecheck targets except for Vue projects.",
|
|
79
|
+
"implementation": "./dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck",
|
|
80
|
+
"documentation": "./dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.md"
|
|
62
81
|
}
|
|
63
82
|
},
|
|
64
83
|
"packageJsonUpdates": {
|
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.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -94,19 +94,18 @@
|
|
|
94
94
|
"supportsOptionalMigrations": true
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@nx/devkit": "24.0.0-beta.
|
|
97
|
+
"@nx/devkit": "24.0.0-beta.3",
|
|
98
98
|
"@phenomnomnominal/tsquery": "~6.2.0",
|
|
99
|
-
"@nx/js": "24.0.0-beta.
|
|
100
|
-
"@nx/vitest": "24.0.0-beta.
|
|
99
|
+
"@nx/js": "24.0.0-beta.3",
|
|
100
|
+
"@nx/vitest": "24.0.0-beta.3",
|
|
101
101
|
"picomatch": "4.0.4",
|
|
102
|
-
"tsconfig-paths": "^4.1.2",
|
|
103
102
|
"semver": "^7.6.3",
|
|
104
103
|
"tslib": "^2.3.0",
|
|
105
104
|
"ajv": "^8.0.0"
|
|
106
105
|
},
|
|
107
106
|
"devDependencies": {
|
|
108
|
-
"@nx/eslint": "24.0.0-beta.
|
|
109
|
-
"nx": "24.0.0-beta.
|
|
107
|
+
"@nx/eslint": "24.0.0-beta.3",
|
|
108
|
+
"nx": "24.0.0-beta.3"
|
|
110
109
|
},
|
|
111
110
|
"peerDependencies": {
|
|
112
111
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { ViteBuildExecutorOptions } from './schema';
|
|
3
|
-
export declare function viteBuildExecutor(options: Record<string, any> & ViteBuildExecutorOptions, context: ExecutorContext): AsyncGenerator<{
|
|
4
|
-
success: boolean;
|
|
5
|
-
outfile?: string;
|
|
6
|
-
}, any, any>;
|
|
7
|
-
export declare function getBuildExtraArgs(options: ViteBuildExecutorOptions): Promise<{
|
|
8
|
-
buildOptions: Record<string, unknown>;
|
|
9
|
-
otherOptions: Record<string, any>;
|
|
10
|
-
}>;
|
|
11
|
-
export default viteBuildExecutor;
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.viteBuildExecutor = viteBuildExecutor;
|
|
4
|
-
exports.getBuildExtraArgs = getBuildExtraArgs;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const internal_1 = require("@nx/devkit/internal");
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const options_utils_1 = require("../../utils/options-utils");
|
|
9
|
-
const schema_json_1 = tslib_1.__importDefault(require("./schema.json"));
|
|
10
|
-
const js_1 = require("@nx/js");
|
|
11
|
-
const fs_1 = require("fs");
|
|
12
|
-
const path_1 = require("path");
|
|
13
|
-
const executor_utils_1 = require("../../utils/executor-utils");
|
|
14
|
-
const deprecation_1 = require("../../utils/deprecation");
|
|
15
|
-
const internal_2 = require("@nx/js/internal");
|
|
16
|
-
async function* viteBuildExecutor(options, context) {
|
|
17
|
-
(0, deprecation_1.warnViteBuildExecutorDeprecation)();
|
|
18
|
-
process.env.VITE_CJS_IGNORE_WARNING = 'true';
|
|
19
|
-
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
20
|
-
const { mergeConfig, build, resolveConfig, createBuilder } = await (0, executor_utils_1.loadViteDynamicImport)();
|
|
21
|
-
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
22
|
-
const tsConfigForBuild = (0, executor_utils_1.createBuildableTsConfig)(projectRoot, options, context);
|
|
23
|
-
const viteConfigPath = (0, options_utils_1.normalizeViteConfigFilePath)(context.root, projectRoot, options.configFile);
|
|
24
|
-
const root = projectRoot === '.' || projectRoot === ''
|
|
25
|
-
? process.cwd()
|
|
26
|
-
: (0, path_1.relative)(context.cwd, (0, devkit_1.joinPathFragments)(context.root, projectRoot));
|
|
27
|
-
const { buildOptions, otherOptions } = await getBuildExtraArgs(options);
|
|
28
|
-
const defaultMode = otherOptions?.mode ?? 'production';
|
|
29
|
-
const resolved = await resolveConfig({
|
|
30
|
-
configFile: viteConfigPath,
|
|
31
|
-
mode: defaultMode,
|
|
32
|
-
}, 'build', defaultMode, process.env.NODE_ENV ?? defaultMode);
|
|
33
|
-
const outDir = (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(projectRoot), options.outputPath) ??
|
|
34
|
-
resolved?.build?.outDir;
|
|
35
|
-
const buildConfig = mergeConfig({
|
|
36
|
-
// This should not be needed as it's going to be set in vite.config.ts
|
|
37
|
-
// but leaving it here in case someone did not migrate correctly
|
|
38
|
-
root: resolved.root ?? root,
|
|
39
|
-
configFile: viteConfigPath,
|
|
40
|
-
}, {
|
|
41
|
-
build: {
|
|
42
|
-
outDir,
|
|
43
|
-
...buildOptions,
|
|
44
|
-
},
|
|
45
|
-
...otherOptions,
|
|
46
|
-
});
|
|
47
|
-
// New TS Solution already has a typecheck target
|
|
48
|
-
if (!options.skipTypeCheck && !(0, internal_2.isUsingTsSolutionSetup)()) {
|
|
49
|
-
await (0, executor_utils_1.validateTypes)({
|
|
50
|
-
workspaceRoot: context.root,
|
|
51
|
-
tsconfig: tsConfigForBuild,
|
|
52
|
-
isVueProject: Boolean(resolved.plugins?.find((plugin) => typeof plugin === 'object' && plugin?.name === 'vite:vue')),
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
const builder = createBuilder !== undefined && options.useEnvironmentsApi
|
|
56
|
-
? await createBuilder(buildConfig)
|
|
57
|
-
: // This is needed to ensure support for Vite 5
|
|
58
|
-
{
|
|
59
|
-
build: (inlineConfig) => build(inlineConfig),
|
|
60
|
-
environments: { build: buildConfig },
|
|
61
|
-
};
|
|
62
|
-
let iterables = [];
|
|
63
|
-
for (const env of Object.values(builder.environments)) {
|
|
64
|
-
// Overwrite the resolved build config with executor options (e.g. outDir).
|
|
65
|
-
// Skip when using the builder API (Vite 8+) as the builder already
|
|
66
|
-
// resolves environment configs correctly and overwriting would clobber
|
|
67
|
-
// environment-specific options like rollupOptions/rolldownOptions.
|
|
68
|
-
if (env.config?.build && !options.useEnvironmentsApi) {
|
|
69
|
-
env.config.build = {
|
|
70
|
-
...env.config.build,
|
|
71
|
-
...buildConfig.build,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
const watcherOrOutput = await builder.build(env);
|
|
75
|
-
const libraryPackageJson = (0, path_1.resolve)(projectRoot, 'package.json');
|
|
76
|
-
const rootPackageJson = (0, path_1.resolve)(context.root, 'package.json');
|
|
77
|
-
// Here, we want the outdir relative to the workspace root.
|
|
78
|
-
// So, we calculate the relative path from the workspace root to the outdir.
|
|
79
|
-
const absoluteOutDir = (0, path_1.resolve)((0, path_1.resolve)(context.root, projectRoot), outDir);
|
|
80
|
-
const outDirRelativeToWorkspaceRoot = (0, path_1.relative)(context.root, absoluteOutDir);
|
|
81
|
-
const distPackageJson = (0, path_1.resolve)(outDirRelativeToWorkspaceRoot, 'package.json');
|
|
82
|
-
// Generate a package.json if option has been set.
|
|
83
|
-
if (options.generatePackageJson) {
|
|
84
|
-
if (context.projectGraph.nodes[context.projectName].type !== 'app') {
|
|
85
|
-
devkit_1.logger.warn((0, devkit_1.stripIndents) `The project ${context.projectName} is using the 'generatePackageJson' option which is deprecated for library projects. It should only be used for applications.
|
|
86
|
-
For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/nx-api/eslint-plugin/documents/dependency-checks).`);
|
|
87
|
-
}
|
|
88
|
-
const builtPackageJson = (0, js_1.createPackageJson)(context.projectName, context.projectGraph, {
|
|
89
|
-
target: context.targetName,
|
|
90
|
-
root: context.root,
|
|
91
|
-
isProduction: !options.includeDevDependenciesInPackageJson, // By default we remove devDependencies since this is a production build.
|
|
92
|
-
skipOverrides: options.skipOverrides,
|
|
93
|
-
skipPackageManager: options.skipPackageManager,
|
|
94
|
-
});
|
|
95
|
-
builtPackageJson.type ??= 'module';
|
|
96
|
-
const packageManager = (0, devkit_1.detectPackageManager)(context.root);
|
|
97
|
-
(0, js_1.generatePrunedDeployOutput)(builtPackageJson, context.projectGraph, projectRoot, {
|
|
98
|
-
outputDirectory: outDirRelativeToWorkspaceRoot,
|
|
99
|
-
packageManager,
|
|
100
|
-
workspaceRoot: context.root,
|
|
101
|
-
});
|
|
102
|
-
(0, devkit_1.writeJsonFile)(`${outDirRelativeToWorkspaceRoot}/package.json`, builtPackageJson);
|
|
103
|
-
}
|
|
104
|
-
// For buildable libs, copy package.json if it exists.
|
|
105
|
-
else if (options.generatePackageJson !== false &&
|
|
106
|
-
!(0, fs_1.existsSync)(distPackageJson) &&
|
|
107
|
-
(0, fs_1.existsSync)(libraryPackageJson) &&
|
|
108
|
-
rootPackageJson !== libraryPackageJson) {
|
|
109
|
-
await (0, js_1.copyAssets)({
|
|
110
|
-
outputPath: outDirRelativeToWorkspaceRoot,
|
|
111
|
-
assets: [
|
|
112
|
-
{
|
|
113
|
-
input: projectRoot,
|
|
114
|
-
output: '.',
|
|
115
|
-
glob: 'package.json',
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
}, context);
|
|
119
|
-
}
|
|
120
|
-
const iterable = (0, internal_1.createAsyncIterable)(({ next, done }) => {
|
|
121
|
-
if ('on' in watcherOrOutput) {
|
|
122
|
-
let success = true;
|
|
123
|
-
watcherOrOutput.on('event', (event) => {
|
|
124
|
-
if (event.code === 'START') {
|
|
125
|
-
success = true;
|
|
126
|
-
}
|
|
127
|
-
else if (event.code === 'ERROR') {
|
|
128
|
-
success = false;
|
|
129
|
-
}
|
|
130
|
-
else if (event.code === 'END') {
|
|
131
|
-
next({ success });
|
|
132
|
-
}
|
|
133
|
-
// result must be closed when present.
|
|
134
|
-
// see https://rollupjs.org/guide/en/#rollupwatch
|
|
135
|
-
if ('result' in event && event.result) {
|
|
136
|
-
event.result.close();
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
const output = watcherOrOutput?.['output'] || watcherOrOutput?.[0]?.output;
|
|
142
|
-
const fileName = output?.[0]?.fileName || 'main.cjs';
|
|
143
|
-
const outfile = (0, path_1.resolve)(outDirRelativeToWorkspaceRoot, fileName);
|
|
144
|
-
next({ success: true, outfile });
|
|
145
|
-
done();
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
iterables.push(iterable);
|
|
149
|
-
}
|
|
150
|
-
return yield* (0, internal_1.combineAsyncIterables)(iterables.shift(), ...(iterables ?? []));
|
|
151
|
-
}
|
|
152
|
-
async function getBuildExtraArgs(options) {
|
|
153
|
-
// support passing extra args to vite cli
|
|
154
|
-
const extraArgs = {};
|
|
155
|
-
for (const key of Object.keys(options)) {
|
|
156
|
-
if (!schema_json_1.default.properties[key]) {
|
|
157
|
-
extraArgs[key] = options[key];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const buildOptions = {};
|
|
161
|
-
const buildSchemaKeys = [
|
|
162
|
-
'target',
|
|
163
|
-
'polyfillModulePreload',
|
|
164
|
-
'modulePreload',
|
|
165
|
-
'outDir',
|
|
166
|
-
'assetsDir',
|
|
167
|
-
'assetsInlineLimit',
|
|
168
|
-
'cssCodeSplit',
|
|
169
|
-
'cssTarget',
|
|
170
|
-
'cssMinify',
|
|
171
|
-
'sourcemap',
|
|
172
|
-
'minify',
|
|
173
|
-
'terserOptions',
|
|
174
|
-
'rollupOptions',
|
|
175
|
-
'rolldownOptions',
|
|
176
|
-
'commonjsOptions',
|
|
177
|
-
'dynamicImportVarsOptions',
|
|
178
|
-
'write',
|
|
179
|
-
'emptyOutDir',
|
|
180
|
-
'copyPublicDir',
|
|
181
|
-
'manifest',
|
|
182
|
-
'lib',
|
|
183
|
-
'ssr',
|
|
184
|
-
'ssrManifest',
|
|
185
|
-
'ssrEmitAssets',
|
|
186
|
-
'reportCompressedSize',
|
|
187
|
-
'chunkSizeWarningLimit',
|
|
188
|
-
'watch',
|
|
189
|
-
];
|
|
190
|
-
const otherOptions = {};
|
|
191
|
-
for (const key of Object.keys(extraArgs)) {
|
|
192
|
-
if (buildSchemaKeys.includes(key)) {
|
|
193
|
-
buildOptions[key] = extraArgs[key];
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
otherOptions[key] = extraArgs[key];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
buildOptions['watch'] = options.watch ?? undefined;
|
|
200
|
-
return {
|
|
201
|
-
buildOptions,
|
|
202
|
-
otherOptions,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
exports.default = viteBuildExecutor;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const build_impl_1 = tslib_1.__importDefault(require("./build.impl"));
|
|
6
|
-
exports.default = (0, devkit_1.convertNxExecutor)(build_impl_1.default);
|