@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.
Files changed (74) hide show
  1. package/dist/executors.d.ts +0 -3
  2. package/dist/executors.js +0 -7
  3. package/dist/plugins/nx-copy-assets.plugin.d.ts +4 -5
  4. package/dist/plugins/nx-copy-assets.plugin.js +5 -49
  5. package/dist/plugins/nx-ready-signal.plugin.d.ts +8 -0
  6. package/dist/plugins/nx-ready-signal.plugin.js +41 -0
  7. package/dist/plugins/nx-tsconfig-paths.plugin.d.ts +5 -7
  8. package/dist/plugins/nx-tsconfig-paths.plugin.js +6 -247
  9. package/dist/ready-check.d.ts +1 -0
  10. package/dist/ready-check.js +9 -0
  11. package/dist/src/generators/configuration/configuration.js +2 -39
  12. package/dist/src/generators/configuration/lib/convert-non-vite.js +1 -0
  13. package/dist/src/generators/configuration/schema.d.ts +0 -1
  14. package/dist/src/generators/convert-to-inferred/lib/build-post-target-transformer.d.ts +0 -1
  15. package/dist/src/generators/convert-to-inferred/lib/build-post-target-transformer.js +3 -66
  16. package/dist/src/generators/init/init.js +20 -32
  17. package/dist/src/generators/init/schema.d.ts +0 -1
  18. package/dist/src/generators/init/schema.json +1 -1
  19. package/dist/src/generators/setup-paths-plugin/schema.d.ts +0 -1
  20. package/dist/src/generators/setup-paths-plugin/schema.json +2 -2
  21. package/dist/src/generators/setup-paths-plugin/setup-paths-plugin.js +16 -91
  22. package/dist/src/migrations/update-23-0-0/ai-instructions-for-vitest-3.md +5 -5
  23. package/dist/src/migrations/update-23-0-0/ai-instructions-for-vitest-4.md +6 -6
  24. package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +12 -0
  25. package/dist/src/migrations/update-24-0-0/migrate-config-helpers.md +86 -0
  26. package/dist/src/migrations/update-24-0-0/migrate-nx-vite-ts-paths.d.ts +2 -0
  27. package/dist/src/migrations/update-24-0-0/migrate-nx-vite-ts-paths.js +154 -0
  28. package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.d.ts +4 -0
  29. package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.js +11 -0
  30. package/dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.md +37 -0
  31. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
  32. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +46 -0
  33. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +71 -0
  34. package/dist/src/plugins/plugin.d.ts +9 -5
  35. package/dist/src/plugins/plugin.js +56 -49
  36. package/dist/src/utils/deprecation.d.ts +2 -9
  37. package/dist/src/utils/deprecation.js +5 -35
  38. package/dist/src/utils/dev-server-ready-check.d.ts +27 -0
  39. package/dist/src/utils/dev-server-ready-check.js +174 -0
  40. package/dist/src/utils/e2e-web-server-info-utils.d.ts +2 -2
  41. package/dist/src/utils/e2e-web-server-info-utils.js +4 -4
  42. package/dist/src/utils/executor-utils.d.ts +0 -10
  43. package/dist/src/utils/executor-utils.js +0 -51
  44. package/dist/src/utils/generator-utils.d.ts +1 -10
  45. package/dist/src/utils/generator-utils.js +62 -114
  46. package/dist/src/utils/options-utils.d.ts +0 -16
  47. package/dist/src/utils/options-utils.js +0 -73
  48. package/dist/src/utils/versions.d.ts +2 -0
  49. package/dist/src/utils/versions.js +3 -1
  50. package/dist/src/utils/vite-config-edit-utils.d.ts +9 -1
  51. package/dist/src/utils/vite-config-edit-utils.js +143 -1
  52. package/executors.json +2 -34
  53. package/generators.json +1 -1
  54. package/migrations.json +19 -0
  55. package/package.json +22 -7
  56. package/dist/src/executors/build/build.impl.d.ts +0 -11
  57. package/dist/src/executors/build/build.impl.js +0 -205
  58. package/dist/src/executors/build/compat.d.ts +0 -2
  59. package/dist/src/executors/build/compat.js +0 -6
  60. package/dist/src/executors/build/schema.json +0 -82
  61. package/dist/src/executors/dev-server/compat.d.ts +0 -2
  62. package/dist/src/executors/dev-server/compat.js +0 -6
  63. package/dist/src/executors/dev-server/dev-server.impl.d.ts +0 -7
  64. package/dist/src/executors/dev-server/dev-server.impl.js +0 -137
  65. package/dist/src/executors/dev-server/schema.json +0 -40
  66. package/dist/src/executors/preview-server/compat.d.ts +0 -2
  67. package/dist/src/executors/preview-server/compat.js +0 -6
  68. package/dist/src/executors/preview-server/preview-server.impl.d.ts +0 -7
  69. package/dist/src/executors/preview-server/preview-server.impl.js +0 -184
  70. package/dist/src/executors/preview-server/schema.json +0 -44
  71. package/dist/src/utils/nx-tsconfig-paths-find-file.d.ts +0 -2
  72. package/dist/src/utils/nx-tsconfig-paths-find-file.js +0 -22
  73. package/dist/src/utils/nx-tsconfig-paths-load-file.d.ts +0 -12
  74. package/dist/src/utils/nx-tsconfig-paths-load-file.js +0 -71
@@ -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
- "dev-server": {
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": "Sets up the nxViteTsPaths plugin to enable support for workspace libraries."
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.2",
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,19 +110,18 @@
94
110
  "supportsOptionalMigrations": true
95
111
  },
96
112
  "dependencies": {
97
- "@nx/devkit": "24.0.0-beta.2",
113
+ "@nx/devkit": "24.0.0-beta.4",
98
114
  "@phenomnomnominal/tsquery": "~6.2.0",
99
- "@nx/js": "24.0.0-beta.2",
100
- "@nx/vitest": "24.0.0-beta.2",
115
+ "@nx/js": "24.0.0-beta.4",
116
+ "@nx/vitest": "24.0.0-beta.4",
101
117
  "picomatch": "4.0.4",
102
- "tsconfig-paths": "^4.1.2",
103
118
  "semver": "^7.6.3",
104
119
  "tslib": "^2.3.0",
105
120
  "ajv": "^8.0.0"
106
121
  },
107
122
  "devDependencies": {
108
- "@nx/eslint": "24.0.0-beta.2",
109
- "nx": "24.0.0-beta.2"
123
+ "@nx/eslint": "24.0.0-beta.4",
124
+ "nx": "24.0.0-beta.4"
110
125
  },
111
126
  "peerDependencies": {
112
127
  "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,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -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);
@@ -1,82 +0,0 @@
1
- {
2
- "version": 2,
3
- "outputCapture": "direct-nodejs",
4
- "title": "Vite Prod Builder",
5
- "cli": "nx",
6
- "description": "Builds a Vite application for production.",
7
- "type": "object",
8
- "x-deprecated": "The `@nx/vite:build` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vite:convert-to-inferred` to migrate to the `@nx/vite/plugin` inferred plugin. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.",
9
- "presets": [
10
- {
11
- "name": "Default minimum setup",
12
- "keys": []
13
- }
14
- ],
15
- "properties": {
16
- "outputPath": {
17
- "type": "string",
18
- "description": "The output path of the generated files.",
19
- "x-completion-type": "directory",
20
- "x-priority": "important"
21
- },
22
- "buildLibsFromSource": {
23
- "type": "boolean",
24
- "description": "Read buildable libraries from source instead of building them separately.",
25
- "default": true
26
- },
27
- "skipTypeCheck": {
28
- "type": "boolean",
29
- "description": "Skip type-checking via TypeScript. Skipping type-checking speeds up the build but type errors are not caught.",
30
- "default": false
31
- },
32
- "tsConfig": {
33
- "type": "string",
34
- "description": "The path to custom tsconfig file for type-checking when skipTypeCheck is false. Required when tsconfig file is not at the projectRoot level.",
35
- "x-completion-type": "file",
36
- "x-completion-glob": "tsconfig.*.json"
37
- },
38
- "configFile": {
39
- "type": "string",
40
- "description": "The name of the Vite configuration file.",
41
- "x-completion-type": "file",
42
- "x-completion-glob": "vite.config.@(js|ts)"
43
- },
44
- "watch": {
45
- "description": "Enable re-building when files change.",
46
- "oneOf": [
47
- {
48
- "type": "boolean"
49
- },
50
- {
51
- "type": "object"
52
- }
53
- ],
54
- "default": false
55
- },
56
- "generatePackageJson": {
57
- "description": "Generate a package.json for the build output.",
58
- "type": "boolean"
59
- },
60
- "includeDevDependenciesInPackageJson": {
61
- "description": "Include devDependencies in the generated package.json.",
62
- "type": "boolean"
63
- },
64
- "skipOverrides": {
65
- "type": "boolean",
66
- "description": "Do not add a `overrides` and `resolutions` entries to the generated package.json file. Only works in conjunction with `generatePackageJson` option."
67
- },
68
- "skipPackageManager": {
69
- "type": "boolean",
70
- "description": "Do not add a `packageManager` entry to the generated package.json file. Only works in conjunction with `generatePackageJson` option."
71
- },
72
- "useEnvironmentsApi": {
73
- "alias": "app",
74
- "type": "boolean",
75
- "description": "Use the new Environments API for building multiple environments at once. Only works with Vite 6.0.0 or higher.",
76
- "default": false
77
- }
78
- },
79
- "definitions": {},
80
- "required": [],
81
- "examplesFile": "../../../docs/build-examples.md"
82
- }
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;