@nx/nest 23.2.0-beta.7 → 23.2.0-beta.9

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.
@@ -7,6 +7,7 @@ const node_1 = require("@nx/node");
7
7
  const init_1 = require("../init/init");
8
8
  const lib_1 = require("./lib");
9
9
  const assert_supported_nestjs_version_1 = require("../../utils/assert-supported-nestjs-version");
10
+ const assert_vitest_supported_1 = require("../../utils/assert-vitest-supported");
10
11
  const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
11
12
  async function applicationGenerator(tree, rawOptions) {
12
13
  return await applicationGeneratorInternal(tree, {
@@ -18,6 +19,9 @@ async function applicationGenerator(tree, rawOptions) {
18
19
  async function applicationGeneratorInternal(tree, rawOptions) {
19
20
  (0, assert_supported_nestjs_version_1.assertSupportedNestJsVersion)(tree);
20
21
  const options = await (0, lib_1.normalizeOptions)(tree, rawOptions);
22
+ if (options.unitTestRunner === 'vitest') {
23
+ (0, assert_vitest_supported_1.assertVitestSupported)(tree);
24
+ }
21
25
  const tasks = [];
22
26
  const initTask = await (0, init_1.initGenerator)(tree, {
23
27
  skipPackageJson: options.skipPackageJson,
@@ -9,7 +9,7 @@ function createFiles(tree, options) {
9
9
  name: options.appProjectName,
10
10
  root: options.appProjectRoot,
11
11
  });
12
- if (options.unitTestRunner === 'jest') {
12
+ if (options.unitTestRunner !== 'none') {
13
13
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, '..', 'files', 'test'), (0, path_1.join)(options.appProjectRoot, 'src'), {
14
14
  tmpl: '',
15
15
  });
@@ -36,6 +36,7 @@ function toNodeApplicationGeneratorOptions(options) {
36
36
  directory: options.directory,
37
37
  frontendProject: options.frontendProject,
38
38
  linter: options.linter,
39
+ formatter: options.formatter,
39
40
  skipFormat: true,
40
41
  skipPackageJson: options.skipPackageJson,
41
42
  tags: options.tags,
@@ -5,10 +5,11 @@ export interface ApplicationGeneratorOptions {
5
5
  name?: string;
6
6
  frontendProject?: string;
7
7
  linter?: LinterType;
8
+ formatter?: 'none' | 'prettier' | 'oxfmt';
8
9
  skipFormat?: boolean;
9
10
  skipPackageJson?: boolean;
10
11
  tags?: string;
11
- unitTestRunner?: 'jest' | 'none';
12
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
12
13
  e2eTestRunner?: 'jest' | 'none';
13
14
  enableTypedLinting?: boolean;
14
15
  /**
@@ -39,10 +39,15 @@
39
39
  "enum": ["eslint", "oxlint", "none"],
40
40
  "x-priority": "important"
41
41
  },
42
+ "formatter": {
43
+ "description": "The tool to use for code formatting.",
44
+ "type": "string",
45
+ "enum": ["none", "prettier", "oxfmt"]
46
+ },
42
47
  "unitTestRunner": {
43
48
  "description": "Test runner to use for unit tests.",
44
49
  "type": "string",
45
- "enum": ["jest", "none"],
50
+ "enum": ["jest", "vitest", "none"],
46
51
  "default": "none",
47
52
  "x-prompt": "Which unit test runner would you like to use?"
48
53
  },
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -63,6 +63,9 @@ function toJsLibraryGeneratorOptions(options) {
63
63
  tags: options.tags,
64
64
  testEnvironment: options.testEnvironment,
65
65
  unitTestRunner: options.unitTestRunner,
66
+ // `deleteFiles` drops the generated spec, and a library without a
67
+ // controller or service is left with none at all.
68
+ passWithNoTests: true,
66
69
  enableTypedLinting: (0, internal_2.isTypedLintingEnabled)(options),
67
70
  addPlugin: options.addPlugin,
68
71
  useProjectJson: options.useProjectJson,
@@ -7,6 +7,7 @@ const internal_1 = require("@nx/devkit/internal");
7
7
  const devkit_1 = require("@nx/devkit");
8
8
  const js_1 = require("@nx/js");
9
9
  const assert_supported_nestjs_version_1 = require("../../utils/assert-supported-nestjs-version");
10
+ const assert_vitest_supported_1 = require("../../utils/assert-vitest-supported");
10
11
  const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
11
12
  const init_1 = tslib_1.__importDefault(require("../init/init"));
12
13
  const lib_1 = require("./lib");
@@ -20,6 +21,9 @@ async function libraryGenerator(tree, rawOptions) {
20
21
  async function libraryGeneratorInternal(tree, rawOptions) {
21
22
  (0, assert_supported_nestjs_version_1.assertSupportedNestJsVersion)(tree);
22
23
  const options = await (0, lib_1.normalizeOptions)(tree, rawOptions);
24
+ if (options.unitTestRunner === 'vitest') {
25
+ (0, assert_vitest_supported_1.assertVitestSupported)(tree);
26
+ }
23
27
  const jsLibraryTask = await (0, js_1.libraryGenerator)(tree, (0, lib_1.toJsLibraryGeneratorOptions)(options));
24
28
  updatePackageJson(tree, options);
25
29
  const initTask = await (0, init_1.default)(tree, rawOptions);
@@ -36,7 +36,7 @@
36
36
  "unitTestRunner": {
37
37
  "description": "Test runner to use for unit tests.",
38
38
  "type": "string",
39
- "enum": ["jest", "none"],
39
+ "enum": ["jest", "vitest", "none"],
40
40
  "default": "none",
41
41
  "x-prompt": "Which unit test runner would you like to use?",
42
42
  "x-priority": "important"
@@ -89,7 +89,7 @@
89
89
  "default": false
90
90
  },
91
91
  "testEnvironment": {
92
- "description": "The test environment for jest, for node applications this should stay as node unless doing DOM testing.",
92
+ "description": "The test environment for the unit test runner. For node applications this should stay as node unless doing DOM testing.",
93
93
  "type": "string",
94
94
  "enum": ["jsdom", "node"],
95
95
  "default": "node"
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -30,7 +30,7 @@
30
30
  "unitTestRunner": {
31
31
  "description": "Test runner to use for unit tests.",
32
32
  "type": "string",
33
- "enum": ["jest", "none"],
33
+ "enum": ["jest", "vitest", "none"],
34
34
  "default": "jest"
35
35
  },
36
36
  "type": {
@@ -34,7 +34,7 @@
34
34
  "unitTestRunner": {
35
35
  "description": "Test runner to use for unit tests.",
36
36
  "type": "string",
37
- "enum": ["jest", "none"],
37
+ "enum": ["jest", "vitest", "none"],
38
38
  "default": "jest"
39
39
  },
40
40
  "language": {
@@ -30,5 +30,5 @@ async function normalizeOptions(tree, options, normalizationOptions = {}) {
30
30
  };
31
31
  }
32
32
  function unitTestRunnerToSpec(unitTestRunner) {
33
- return unitTestRunner !== undefined ? unitTestRunner === 'jest' : undefined;
33
+ return unitTestRunner !== undefined ? unitTestRunner !== 'none' : undefined;
34
34
  }
@@ -1,5 +1,5 @@
1
1
  export type Language = 'js' | 'ts';
2
- export type UnitTestRunner = 'jest' | 'none';
2
+ export type UnitTestRunner = 'jest' | 'vitest' | 'none';
3
3
  export type NestSchematic = 'class' | 'controller' | 'decorator' | 'filter' | 'gateway' | 'guard' | 'interceptor' | 'interface' | 'middleware' | 'module' | 'pipe' | 'provider' | 'resolver' | 'resource' | 'service';
4
4
  export type TransportLayer = 'rest' | 'graphql-code-first' | 'graphql-schema-first' | 'microservice' | 'ws';
5
5
  export type NestGeneratorOptions = {
@@ -0,0 +1,10 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare const minSupportedViteMajorForVitest = 8;
3
+ /**
4
+ * Nest resolves constructor dependencies from `design:paramtypes`, which only
5
+ * exists when the transform honors `emitDecoratorMetadata`. Vite < 8 transforms
6
+ * TypeScript with esbuild, which drops it, so the injector sees no dependencies
7
+ * and every generated spec that injects a provider fails. Vite 8's oxc transform
8
+ * emits it.
9
+ */
10
+ export declare function assertVitestSupported(tree: Tree): void;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.minSupportedViteMajorForVitest = void 0;
4
+ exports.assertVitestSupported = assertVitestSupported;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const semver_1 = require("semver");
7
+ exports.minSupportedViteMajorForVitest = 8;
8
+ /**
9
+ * Nest resolves constructor dependencies from `design:paramtypes`, which only
10
+ * exists when the transform honors `emitDecoratorMetadata`. Vite < 8 transforms
11
+ * TypeScript with esbuild, which drops it, so the injector sees no dependencies
12
+ * and every generated spec that injects a provider fails. Vite 8's oxc transform
13
+ * emits it.
14
+ */
15
+ function assertVitestSupported(tree) {
16
+ const declaredVersion = (0, devkit_1.getDependencyVersionFromPackageJson)(tree, 'vite');
17
+ if (!declaredVersion) {
18
+ // Vite isn't installed yet, so @nx/vitest will install a supported major.
19
+ return;
20
+ }
21
+ const version = (0, semver_1.clean)(declaredVersion) ?? (0, semver_1.coerce)(declaredVersion)?.version;
22
+ // An unparseable range (workspace:, catalog:, a git url) isn't evidence of an
23
+ // unsupported version, so don't block on it.
24
+ if (!version || (0, semver_1.major)(version) >= exports.minSupportedViteMajorForVitest) {
25
+ return;
26
+ }
27
+ throw new Error(`Using vitest with @nx/nest requires Vite ${exports.minSupportedViteMajorForVitest} or later, but found Vite ${version}.\n` +
28
+ `Nest dependency injection needs "emitDecoratorMetadata", which the esbuild transform used by Vite < ${exports.minSupportedViteMajorForVitest} does not emit.\n` +
29
+ `Upgrade Vite, or generate with "--unitTestRunner=jest".`);
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/nest",
3
- "version": "23.2.0-beta.7",
3
+ "version": "23.2.0-beta.9",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -62,10 +62,10 @@
62
62
  "@nestjs/schematics": "^11.0.0",
63
63
  "semver": "^7.6.3",
64
64
  "tslib": "^2.3.0",
65
- "@nx/devkit": "23.2.0-beta.7",
66
- "@nx/js": "23.2.0-beta.7",
67
- "@nx/eslint": "23.2.0-beta.7",
68
- "@nx/node": "23.2.0-beta.7"
65
+ "@nx/devkit": "23.2.0-beta.9",
66
+ "@nx/js": "23.2.0-beta.9",
67
+ "@nx/eslint": "23.2.0-beta.9",
68
+ "@nx/node": "23.2.0-beta.9"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@nestjs/core": ">=10.0.0 <12.0.0",