@nx/vitest 0.0.1-alpha.0

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/LICENSE +22 -0
  2. package/executors.json +10 -0
  3. package/generators.d.ts +4 -0
  4. package/generators.d.ts.map +1 -0
  5. package/generators.js +7 -0
  6. package/generators.json +18 -0
  7. package/index.d.ts +5 -0
  8. package/index.d.ts.map +1 -0
  9. package/index.js +9 -0
  10. package/migrations.json +9 -0
  11. package/package.json +69 -0
  12. package/project.json +52 -0
  13. package/src/executors/test/compat.d.ts +3 -0
  14. package/src/executors/test/compat.d.ts.map +1 -0
  15. package/src/executors/test/compat.js +5 -0
  16. package/src/executors/test/lib/nx-reporter.d.ts +19 -0
  17. package/src/executors/test/lib/nx-reporter.d.ts.map +1 -0
  18. package/src/executors/test/lib/nx-reporter.js +39 -0
  19. package/src/executors/test/lib/utils.d.ts +5 -0
  20. package/src/executors/test/lib/utils.d.ts.map +1 -0
  21. package/src/executors/test/lib/utils.js +68 -0
  22. package/src/executors/test/schema.d.ts +7 -0
  23. package/src/executors/test/schema.json +35 -0
  24. package/src/executors/test/vitest.impl.d.ts +7 -0
  25. package/src/executors/test/vitest.impl.d.ts.map +1 -0
  26. package/src/executors/test/vitest.impl.js +59 -0
  27. package/src/generators/configuration/configuration.d.ts +9 -0
  28. package/src/generators/configuration/configuration.d.ts.map +1 -0
  29. package/src/generators/configuration/configuration.js +284 -0
  30. package/src/generators/configuration/files/tsconfig.spec.json__tmpl__ +22 -0
  31. package/src/generators/configuration/schema.d.ts +16 -0
  32. package/src/generators/configuration/schema.json +65 -0
  33. package/src/generators/init/init.d.ts +8 -0
  34. package/src/generators/init/init.d.ts.map +1 -0
  35. package/src/generators/init/init.js +70 -0
  36. package/src/generators/init/schema.d.ts +11 -0
  37. package/src/generators/init/schema.json +41 -0
  38. package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts +3 -0
  39. package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts.map +1 -0
  40. package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.js +17 -0
  41. package/src/plugins/plugin.d.ts +19 -0
  42. package/src/plugins/plugin.d.ts.map +1 -0
  43. package/src/plugins/plugin.js +277 -0
  44. package/src/utils/detect-ui-framework.d.ts +2 -0
  45. package/src/utils/detect-ui-framework.d.ts.map +1 -0
  46. package/src/utils/detect-ui-framework.js +24 -0
  47. package/src/utils/ensure-dependencies.d.ts +9 -0
  48. package/src/utils/ensure-dependencies.d.ts.map +1 -0
  49. package/src/utils/ensure-dependencies.js +47 -0
  50. package/src/utils/executor-utils.d.ts +3 -0
  51. package/src/utils/executor-utils.d.ts.map +1 -0
  52. package/src/utils/executor-utils.js +10 -0
  53. package/src/utils/generator-utils.d.ts +35 -0
  54. package/src/utils/generator-utils.d.ts.map +1 -0
  55. package/src/utils/generator-utils.js +223 -0
  56. package/src/utils/ignore-vitest-temp-files.d.ts +5 -0
  57. package/src/utils/ignore-vitest-temp-files.d.ts.map +1 -0
  58. package/src/utils/ignore-vitest-temp-files.js +54 -0
  59. package/src/utils/options-utils.d.ts +8 -0
  60. package/src/utils/options-utils.d.ts.map +1 -0
  61. package/src/utils/options-utils.js +41 -0
  62. package/src/utils/version-utils.d.ts +16 -0
  63. package/src/utils/version-utils.d.ts.map +1 -0
  64. package/src/utils/version-utils.js +90 -0
  65. package/src/utils/versions.d.ts +23 -0
  66. package/src/utils/versions.d.ts.map +1 -0
  67. package/src/utils/versions.js +26 -0
  68. package/src/utils/vite-config-edit-utils.d.ts +4 -0
  69. package/src/utils/vite-config-edit-utils.d.ts.map +1 -0
  70. package/src/utils/vite-config-edit-utils.js +359 -0
  71. package/tsconfig.json +28 -0
  72. package/tsconfig.lib.json +20 -0
  73. package/tsconfig.lib.tsbuildinfo +1 -0
  74. package/tsconfig.spec.json +24 -0
@@ -0,0 +1,284 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configurationGenerator = configurationGenerator;
4
+ exports.configurationGeneratorInternal = configurationGeneratorInternal;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const js_1 = require("@nx/js");
7
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
+ const versions_1 = require("@nx/js/src/utils/versions");
9
+ const path_1 = require("path");
10
+ const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
11
+ const generator_utils_1 = require("../../utils/generator-utils");
12
+ const init_1 = require("../init/init");
13
+ const detect_ui_framework_1 = require("../../utils/detect-ui-framework");
14
+ const version_utils_1 = require("../../utils/version-utils");
15
+ const semver_1 = require("semver");
16
+ /**
17
+ * @param hasPlugin some frameworks (e.g. Nuxt) provide their own plugin. Their generators handle the plugin detection.
18
+ */
19
+ function configurationGenerator(tree, schema, hasPlugin = false) {
20
+ return configurationGeneratorInternal(tree, { addPlugin: false, ...schema }, hasPlugin);
21
+ }
22
+ async function configurationGeneratorInternal(tree, schema, hasPlugin = false) {
23
+ // Setting default to jsdom since it is the most common use case (React, Web).
24
+ // The @nx/js:lib generator specifically sets this to node to be more generic.
25
+ schema.testEnvironment ??= 'jsdom';
26
+ // Set the viteVersion to the installed version if it already exists in the workspace
27
+ const installedViteVersion = (0, version_utils_1.getInstalledViteMajorVersion)(tree);
28
+ schema.viteVersion ??= installedViteVersion;
29
+ const tasks = [];
30
+ const { root, projectType: _projectType } = (0, devkit_1.readProjectConfiguration)(tree, schema.project);
31
+ const projectType = schema.projectType ?? _projectType;
32
+ const uiFramework = schema.uiFramework ?? (await (0, detect_ui_framework_1.detectUiFramework)(schema.project));
33
+ const isRootProject = root === '.';
34
+ tasks.push(await (0, js_1.initGenerator)(tree, { ...schema, skipFormat: true }));
35
+ const initTask = await (0, init_1.default)(tree, {
36
+ skipFormat: true,
37
+ addPlugin: schema.addPlugin,
38
+ projectRoot: root,
39
+ viteVersion: schema.viteVersion,
40
+ });
41
+ tasks.push(initTask);
42
+ tasks.push(await (0, ensure_dependencies_1.ensureDependencies)(tree, { ...schema, uiFramework }));
43
+ (0, generator_utils_1.addOrChangeTestTarget)(tree, schema, hasPlugin);
44
+ if (!schema.skipViteConfig) {
45
+ if (uiFramework === 'angular') {
46
+ const relativeTestSetupPath = (0, devkit_1.joinPathFragments)('src', 'test-setup.ts');
47
+ const setupFile = (0, devkit_1.joinPathFragments)(root, relativeTestSetupPath);
48
+ if (!tree.exists(setupFile)) {
49
+ if (isAngularV20(tree)) {
50
+ tree.write(setupFile, `import '@angular/compiler';
51
+ import '@analogjs/vitest-angular/setup-zone';
52
+
53
+ import {
54
+ BrowserTestingModule,
55
+ platformBrowserTesting,
56
+ } from '@angular/platform-browser/testing';
57
+ import { getTestBed } from '@angular/core/testing';
58
+
59
+ getTestBed().initTestEnvironment(
60
+ BrowserTestingModule,
61
+ platformBrowserTesting()
62
+ );
63
+ `);
64
+ }
65
+ else {
66
+ tree.write(setupFile, `import '@analogjs/vitest-angular/setup-zone';
67
+
68
+ import {
69
+ BrowserDynamicTestingModule,
70
+ platformBrowserDynamicTesting,
71
+ } from '@angular/platform-browser-dynamic/testing';
72
+ import { getTestBed } from '@angular/core/testing';
73
+
74
+ getTestBed().initTestEnvironment(
75
+ BrowserDynamicTestingModule,
76
+ platformBrowserDynamicTesting()
77
+ );
78
+ `);
79
+ }
80
+ }
81
+ (0, generator_utils_1.createOrEditViteConfig)(tree, {
82
+ project: schema.project,
83
+ includeLib: false,
84
+ includeVitest: true,
85
+ inSourceTests: false,
86
+ imports: [`import angular from '@analogjs/vite-plugin-angular'`],
87
+ plugins: ['angular()'],
88
+ setupFile: relativeTestSetupPath,
89
+ useEsmExtension: true,
90
+ }, true);
91
+ }
92
+ else if (uiFramework === 'react') {
93
+ (0, generator_utils_1.createOrEditViteConfig)(tree, {
94
+ project: schema.project,
95
+ includeLib: (0, ts_solution_setup_1.getProjectType)(tree, root, projectType) === 'library',
96
+ includeVitest: true,
97
+ inSourceTests: schema.inSourceTests,
98
+ rollupOptionsExternal: [
99
+ "'react'",
100
+ "'react-dom'",
101
+ "'react/jsx-runtime'",
102
+ ],
103
+ imports: [
104
+ schema.compiler === 'swc'
105
+ ? `import react from '@vitejs/plugin-react-swc'`
106
+ : `import react from '@vitejs/plugin-react'`,
107
+ ],
108
+ plugins: ['react()'],
109
+ coverageProvider: schema.coverageProvider,
110
+ }, true);
111
+ }
112
+ else {
113
+ (0, generator_utils_1.createOrEditViteConfig)(tree, {
114
+ ...schema,
115
+ includeVitest: true,
116
+ includeLib: (0, ts_solution_setup_1.getProjectType)(tree, root, projectType) === 'library',
117
+ }, true);
118
+ }
119
+ }
120
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
121
+ createFiles(tree, schema, root, isTsSolutionSetup);
122
+ updateTsConfig(tree, schema, root, projectType);
123
+ if (isTsSolutionSetup) {
124
+ // in the TS solution setup, the test target depends on the build outputs
125
+ // so we need to setup the task pipeline accordingly
126
+ const nxJson = (0, devkit_1.readNxJson)(tree);
127
+ const testTarget = schema.testTarget ?? 'test';
128
+ nxJson.targetDefaults ??= {};
129
+ nxJson.targetDefaults[testTarget] ??= {};
130
+ nxJson.targetDefaults[testTarget].dependsOn ??= [];
131
+ nxJson.targetDefaults[testTarget].dependsOn = Array.from(new Set([...nxJson.targetDefaults[testTarget].dependsOn, '^build']));
132
+ (0, devkit_1.updateNxJson)(tree, nxJson);
133
+ }
134
+ const devDependencies = await getCoverageProviderDependency(tree, schema.coverageProvider);
135
+ devDependencies['@types/node'] = versions_1.typesNodeVersion;
136
+ const installDependenciesTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
137
+ tasks.push(installDependenciesTask);
138
+ // Setup workspace config file (https://vitest.dev/guide/workspace.html)
139
+ if (!isRootProject &&
140
+ !tree.exists(`vitest.workspace.ts`) &&
141
+ !tree.exists(`vitest.workspace.js`) &&
142
+ !tree.exists(`vitest.workspace.json`) &&
143
+ !tree.exists(`vitest.projects.ts`) &&
144
+ !tree.exists(`vitest.projects.js`) &&
145
+ !tree.exists(`vitest.projects.json`)) {
146
+ tree.write('vitest.workspace.ts', `export default ['**/vite.config.{mjs,js,ts,mts}', '**/vitest.config.{mjs,js,ts,mts}'];`);
147
+ }
148
+ if (!schema.skipFormat) {
149
+ await (0, devkit_1.formatFiles)(tree);
150
+ }
151
+ return (0, devkit_1.runTasksInSerial)(...tasks);
152
+ }
153
+ function updateTsConfig(tree, options, projectRoot, projectType) {
154
+ const setupFile = tryFindSetupFile(tree, projectRoot);
155
+ if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.spec.json'))) {
156
+ (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.spec.json'), (json) => {
157
+ if (!json.compilerOptions?.types?.includes('vitest')) {
158
+ if (json.compilerOptions?.types) {
159
+ json.compilerOptions.types.push('vitest');
160
+ }
161
+ else {
162
+ json.compilerOptions ??= {};
163
+ json.compilerOptions.types = ['vitest'];
164
+ }
165
+ }
166
+ if (setupFile) {
167
+ json.files = [...(json.files ?? []), setupFile];
168
+ }
169
+ return json;
170
+ });
171
+ (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json'), (json) => {
172
+ if (json.references &&
173
+ !json.references.some((r) => r.path === './tsconfig.spec.json')) {
174
+ json.references.push({
175
+ path: './tsconfig.spec.json',
176
+ });
177
+ }
178
+ return json;
179
+ });
180
+ }
181
+ else {
182
+ (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json'), (json) => {
183
+ if (!json.compilerOptions?.types?.includes('vitest')) {
184
+ if (json.compilerOptions?.types) {
185
+ json.compilerOptions.types.push('vitest');
186
+ }
187
+ else {
188
+ json.compilerOptions ??= {};
189
+ json.compilerOptions.types = ['vitest'];
190
+ }
191
+ }
192
+ return json;
193
+ });
194
+ }
195
+ let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, (0, ts_solution_setup_1.getProjectType)(tree, projectRoot, projectType) === 'application'
196
+ ? 'tsconfig.app.json'
197
+ : 'tsconfig.lib.json');
198
+ if (options.runtimeTsconfigFileName) {
199
+ runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, options.runtimeTsconfigFileName);
200
+ if (!tree.exists(runtimeTsconfigPath)) {
201
+ throw new Error(`Cannot find the specified runtimeTsConfigFileName ("${options.runtimeTsconfigFileName}") at the project root "${projectRoot}".`);
202
+ }
203
+ }
204
+ if (tree.exists(runtimeTsconfigPath)) {
205
+ (0, devkit_1.updateJson)(tree, runtimeTsconfigPath, (json) => {
206
+ if (options.inSourceTests) {
207
+ (json.compilerOptions.types ??= []).push('vitest/importMeta');
208
+ }
209
+ else {
210
+ const uniqueExclude = new Set([
211
+ ...(json.exclude || []),
212
+ 'vite.config.ts',
213
+ 'vite.config.mts',
214
+ 'vitest.config.ts',
215
+ 'vitest.config.mts',
216
+ 'src/**/*.test.ts',
217
+ 'src/**/*.spec.ts',
218
+ 'src/**/*.test.tsx',
219
+ 'src/**/*.spec.tsx',
220
+ 'src/**/*.test.js',
221
+ 'src/**/*.spec.js',
222
+ 'src/**/*.test.jsx',
223
+ 'src/**/*.spec.jsx',
224
+ ]);
225
+ json.exclude = [...uniqueExclude];
226
+ }
227
+ if (setupFile) {
228
+ json.exclude = [...(json.exclude ?? []), setupFile];
229
+ }
230
+ return json;
231
+ });
232
+ }
233
+ else {
234
+ devkit_1.logger.warn(`Couldn't find a runtime tsconfig file at ${runtimeTsconfigPath} to exclude the test files from. ` +
235
+ `If you're using a different filename for your runtime tsconfig, please provide it with the '--runtimeTsconfigFileName' flag.`);
236
+ }
237
+ }
238
+ function createFiles(tree, options, projectRoot, isTsSolutionSetup) {
239
+ const rootOffset = (0, devkit_1.offsetFromRoot)(projectRoot);
240
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectRoot, {
241
+ tmpl: '',
242
+ ...options,
243
+ projectRoot,
244
+ extendedConfig: isTsSolutionSetup
245
+ ? `${rootOffset}tsconfig.base.json`
246
+ : './tsconfig.json',
247
+ outDir: isTsSolutionSetup
248
+ ? `./out-tsc/vitest`
249
+ : `${rootOffset}dist/out-tsc`,
250
+ });
251
+ }
252
+ async function getCoverageProviderDependency(tree, coverageProvider) {
253
+ const { vitestCoverageV8, vitestCoverageIstanbul } = await (0, version_utils_1.getVitestDependenciesVersionsToInstall)(tree);
254
+ switch (coverageProvider) {
255
+ case 'v8':
256
+ return {
257
+ '@vitest/coverage-v8': vitestCoverageV8,
258
+ };
259
+ case 'istanbul':
260
+ return {
261
+ '@vitest/coverage-istanbul': vitestCoverageIstanbul,
262
+ };
263
+ default:
264
+ return {
265
+ '@vitest/coverage-v8': vitestCoverageV8,
266
+ };
267
+ }
268
+ }
269
+ function tryFindSetupFile(tree, projectRoot) {
270
+ const setupFile = (0, devkit_1.joinPathFragments)('src', 'test-setup.ts');
271
+ if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, setupFile))) {
272
+ return setupFile;
273
+ }
274
+ }
275
+ function isAngularV20(tree) {
276
+ const angularVersion = (0, devkit_1.getDependencyVersionFromPackageJson)(tree, '@angular/core');
277
+ if (!angularVersion) {
278
+ // assume the latest version will be installed, which will be 20 or later
279
+ return true;
280
+ }
281
+ const cleanedAngularVersion = (0, semver_1.clean)(angularVersion) ?? (0, semver_1.coerce)(angularVersion).version;
282
+ return (0, semver_1.major)(cleanedAngularVersion) >= 20;
283
+ }
284
+ exports.default = configurationGenerator;
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "<%= extendedConfig %>",
3
+ "compilerOptions": {
4
+ "outDir": "<%= outDir %>",
5
+ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"]
6
+ },
7
+ "include": [
8
+ "vite.config.ts",
9
+ "vite.config.mts",
10
+ "vitest.config.ts",
11
+ "vitest.config.mts",
12
+ "src/**/*.test.ts",
13
+ "src/**/*.spec.ts",
14
+ "src/**/*.test.tsx",
15
+ "src/**/*.spec.tsx",
16
+ "src/**/*.test.js",
17
+ "src/**/*.spec.js",
18
+ "src/**/*.test.jsx",
19
+ "src/**/*.spec.jsx",
20
+ "src/**/*.d.ts"
21
+ ]
22
+ }
@@ -0,0 +1,16 @@
1
+ export interface VitestGeneratorSchema {
2
+ project: string;
3
+ uiFramework?: 'angular' | 'react' | 'vue' | 'none';
4
+ coverageProvider: 'v8' | 'istanbul' | 'custom';
5
+ inSourceTests?: boolean;
6
+ skipViteConfig?: boolean;
7
+ testTarget?: string;
8
+ skipFormat?: boolean;
9
+ testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
10
+ addPlugin?: boolean;
11
+ runtimeTsconfigFileName?: string;
12
+ compiler?: 'babel' | 'swc'; // default: babel
13
+ // internal options
14
+ projectType?: 'application' | 'library';
15
+ viteVersion?: 5 | 6 | 7;
16
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "Vitest",
5
+ "title": "Vitest",
6
+ "type": "object",
7
+ "description": "Generate a Vitest setup for a project.",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "description": "The name of the project to test.",
12
+ "$default": {
13
+ "$source": "projectName"
14
+ }
15
+ },
16
+ "uiFramework": {
17
+ "type": "string",
18
+ "enum": ["angular", "react", "vue", "none"],
19
+ "description": "UI framework to use with vitest."
20
+ },
21
+ "inSourceTests": {
22
+ "type": "boolean",
23
+ "default": false,
24
+ "description": "Do not generate separate spec files and set up in-source testing."
25
+ },
26
+ "skipViteConfig": {
27
+ "type": "boolean",
28
+ "default": false,
29
+ "description": "Skip generating a vite config file."
30
+ },
31
+ "coverageProvider": {
32
+ "type": "string",
33
+ "enum": ["v8", "istanbul", "custom"],
34
+ "default": "v8",
35
+ "description": "Coverage provider to use."
36
+ },
37
+ "testTarget": {
38
+ "type": "string",
39
+ "description": "The test target of the project to be transformed to use the @nx/vitest:test executor.",
40
+ "hidden": true
41
+ },
42
+ "skipFormat": {
43
+ "description": "Skip formatting files.",
44
+ "type": "boolean",
45
+ "default": false,
46
+ "x-priority": "internal"
47
+ },
48
+ "testEnvironment": {
49
+ "description": "The vitest environment to use. See https://vitest.dev/config/#environment.",
50
+ "type": "string",
51
+ "enum": ["node", "jsdom", "happy-dom", "edge-runtime"]
52
+ },
53
+ "runtimeTsconfigFileName": {
54
+ "type": "string",
55
+ "description": "The name of the project's tsconfig file that includes the runtime source files. If not provided, it will default to `tsconfig.lib.json` for libraries and `tsconfig.app.json` for applications."
56
+ },
57
+ "compiler": {
58
+ "type": "string",
59
+ "enum": ["babel", "swc"],
60
+ "default": "babel",
61
+ "description": "The compiler to use"
62
+ }
63
+ },
64
+ "required": ["project"]
65
+ }
@@ -0,0 +1,8 @@
1
+ import { type Tree, type GeneratorCallback } from '@nx/devkit';
2
+ import { InitGeneratorSchema } from './schema';
3
+ export declare function updateDependencies(tree: Tree, schema: InitGeneratorSchema): GeneratorCallback;
4
+ export declare function updateNxJsonSettings(tree: Tree): void;
5
+ export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
6
+ export declare function initGeneratorInternal(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
7
+ export default initGenerator;
8
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/init/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EACT,KAAK,iBAAiB,EAOvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAW/C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,qBAmBzE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,QA4B9C;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,8BAEpE;AAED,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,mBAAmB,8BAmC5B;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateDependencies = updateDependencies;
4
+ exports.updateNxJsonSettings = updateNxJsonSettings;
5
+ exports.initGenerator = initGenerator;
6
+ exports.initGeneratorInternal = initGeneratorInternal;
7
+ const devkit_1 = require("@nx/devkit");
8
+ const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
9
+ const versions_1 = require("../../utils/versions");
10
+ const plugin_1 = require("../../plugins/plugin");
11
+ const ignore_vitest_temp_files_1 = require("../../utils/ignore-vitest-temp-files");
12
+ function updateDependencies(tree, schema) {
13
+ const viteVersionToUse = schema.viteVersion
14
+ ? schema.viteVersion === 5
15
+ ? versions_1.viteV5Version
16
+ : schema.viteVersion === 6
17
+ ? versions_1.viteV6Version
18
+ : versions_1.viteVersion
19
+ : versions_1.viteVersion;
20
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
21
+ '@nx/vitest': versions_1.nxVersion,
22
+ vitest: versions_1.vitestVersion,
23
+ vite: viteVersionToUse,
24
+ }, undefined, schema.keepExistingVersions);
25
+ }
26
+ function updateNxJsonSettings(tree) {
27
+ const nxJson = (0, devkit_1.readNxJson)(tree);
28
+ const productionFileSet = nxJson.namedInputs?.production;
29
+ if (productionFileSet) {
30
+ productionFileSet.push('!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json');
31
+ nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
32
+ }
33
+ const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string' ? p === '@nx/vitest' : p.plugin === '@nx/vitest');
34
+ if (!hasPlugin) {
35
+ nxJson.targetDefaults ??= {};
36
+ nxJson.targetDefaults['@nx/vitest:test'] ??= {};
37
+ nxJson.targetDefaults['@nx/vitest:test'].cache ??= true;
38
+ nxJson.targetDefaults['@nx/vitest:test'].inputs ??= [
39
+ 'default',
40
+ productionFileSet ? '^production' : '^default',
41
+ ];
42
+ }
43
+ (0, devkit_1.updateNxJson)(tree, nxJson);
44
+ }
45
+ function initGenerator(tree, schema) {
46
+ return initGeneratorInternal(tree, { addPlugin: false, ...schema });
47
+ }
48
+ async function initGeneratorInternal(tree, schema) {
49
+ const nxJson = (0, devkit_1.readNxJson)(tree);
50
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
51
+ nxJson.useInferencePlugins !== false;
52
+ schema.addPlugin ??= addPluginDefault;
53
+ if (schema.addPlugin) {
54
+ await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/vitest', plugin_1.createNodesV2, {
55
+ testTargetName: ['test', 'vitest:test', 'vitest-test'],
56
+ ciTargetName: ['test-ci', 'vitest:test-ci', 'vitest-test-ci'],
57
+ }, schema.updatePackageScripts);
58
+ }
59
+ updateNxJsonSettings(tree);
60
+ await (0, ignore_vitest_temp_files_1.ignoreVitestTempFiles)(tree, schema.projectRoot);
61
+ const tasks = [];
62
+ if (!schema.skipPackageJson) {
63
+ tasks.push(updateDependencies(tree, schema));
64
+ }
65
+ if (!schema.skipFormat) {
66
+ await (0, devkit_1.formatFiles)(tree);
67
+ }
68
+ return (0, devkit_1.runTasksInSerial)(...tasks);
69
+ }
70
+ exports.default = initGenerator;
@@ -0,0 +1,11 @@
1
+ export interface InitGeneratorSchema {
2
+ addPlugin?: boolean;
3
+ rootProject?: boolean;
4
+ keepExistingVersions?: boolean;
5
+ projectRoot?: string;
6
+ updatePackageScripts?: boolean;
7
+ skipFormat?: boolean;
8
+ skipPackageJson?: boolean;
9
+ // Internal only
10
+ viteVersion?: 5 | 6 | 7;
11
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "Init",
4
+ "title": "Nx Vitest Init Generator",
5
+ "type": "object",
6
+ "description": "Vitest init generator.",
7
+ "properties": {
8
+ "addPlugin": {
9
+ "type": "boolean",
10
+ "x-priority": "internal",
11
+ "description": "Add plugin to nx.json. Defaults to true for new workspaces."
12
+ },
13
+ "rootProject": {
14
+ "type": "boolean",
15
+ "x-priority": "internal"
16
+ },
17
+ "keepExistingVersions": {
18
+ "type": "boolean",
19
+ "x-priority": "internal",
20
+ "description": "Keep existing dependencies versions",
21
+ "default": false
22
+ },
23
+ "updatePackageScripts": {
24
+ "type": "boolean",
25
+ "x-priority": "internal",
26
+ "description": "Update package scripts",
27
+ "default": false
28
+ },
29
+ "skipFormat": {
30
+ "description": "Skip formatting files.",
31
+ "type": "boolean",
32
+ "default": false
33
+ },
34
+ "skipPackageJson": {
35
+ "description": "Do not add dependencies to `package.json`.",
36
+ "type": "boolean",
37
+ "default": false
38
+ }
39
+ },
40
+ "required": []
41
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function addVitestTempFilesToGitIgnore(tree: Tree): void;
3
+ //# sourceMappingURL=add-vitest-temp-files-to-git-ignore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-vitest-temp-files-to-git-ignore.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC,MAAM,CAAC,OAAO,UAAU,6BAA6B,CAAC,IAAI,EAAE,IAAI,QAsB/D"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = addVitestTempFilesToGitIgnore;
4
+ const ignore_vitest_temp_files_1 = require("../../utils/ignore-vitest-temp-files");
5
+ function addVitestTempFilesToGitIgnore(tree) {
6
+ // need to check if .gitignore exists before adding to it
7
+ // then need to check if it contains the following pattern
8
+ // **/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*
9
+ // if it does, remove just this pattern
10
+ if (tree.exists('.gitignore')) {
11
+ const gitIgnoreContents = tree.read('.gitignore', 'utf-8');
12
+ if (gitIgnoreContents.includes('**/vitest.config.{js,ts,mjs,mts,cjs,cts}.timestamp*')) {
13
+ tree.write('.gitignore', gitIgnoreContents.replace('**/vitest.config.{js,ts,mjs,mts,cjs,cts}.timestamp*', ''));
14
+ }
15
+ }
16
+ (0, ignore_vitest_temp_files_1.addVitestTempFilesToGitIgnore)(tree);
17
+ }
@@ -0,0 +1,19 @@
1
+ import { CreateDependencies, CreateNodesV2 } from '@nx/devkit';
2
+ export interface VitestPluginOptions {
3
+ testTargetName?: string;
4
+ /**
5
+ * Atomizer for vitest
6
+ */
7
+ ciTargetName?: string;
8
+ /**
9
+ * The name that should be used to group atomized tasks on CI
10
+ */
11
+ ciGroupName?: string;
12
+ }
13
+ /**
14
+ * @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
15
+ */
16
+ export declare const createDependencies: CreateDependencies;
17
+ export declare const createNodes: CreateNodesV2<VitestPluginOptions>;
18
+ export declare const createNodesV2: CreateNodesV2<VitestPluginOptions>;
19
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/vitest/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAGlB,aAAa,EAQd,MAAM,YAAY,CAAC;AAapB,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAoBD;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAEhC,CAAC;AAIF,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC,mBAAmB,CA+E1D,CAAC;AAEF,eAAO,MAAM,aAAa,oCAAc,CAAC"}