@nx/vitest 23.0.0-beta.2 → 23.0.0-beta.21
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/{executors.d.ts → dist/executors.d.ts} +0 -1
- package/{generators.d.ts → dist/generators.d.ts} +0 -1
- package/{index.d.ts → dist/index.d.ts} +0 -1
- package/{src → dist/src}/executors/test/compat.d.ts +0 -1
- package/{src → dist/src}/executors/test/lib/nx-reporter.d.ts +0 -1
- package/{src → dist/src}/executors/test/lib/utils.d.ts +0 -1
- package/{src → dist/src}/executors/test/schema.json +1 -0
- package/{src → dist/src}/executors/test/vitest.impl.d.ts +0 -1
- package/{src → dist/src}/executors/test/vitest.impl.js +3 -1
- package/{src → dist/src}/generators/configuration/configuration.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/configuration.js +22 -13
- package/dist/src/generators/convert-to-inferred/convert-to-inferred.d.ts +7 -0
- package/dist/src/generators/convert-to-inferred/convert-to-inferred.js +24 -0
- package/dist/src/generators/convert-to-inferred/lib/test-post-target-transformer.d.ts +5 -0
- package/dist/src/generators/convert-to-inferred/lib/test-post-target-transformer.js +56 -0
- package/dist/src/generators/convert-to-inferred/lib/utils.d.ts +1 -0
- package/dist/src/generators/convert-to-inferred/lib/utils.js +12 -0
- package/dist/src/generators/convert-to-inferred/schema.json +19 -0
- package/{src → dist/src}/generators/init/init.d.ts +0 -1
- package/{src → dist/src}/generators/init/init.js +15 -10
- package/{src → dist/src}/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts +0 -1
- package/dist/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.md +12 -0
- package/{src → dist/src}/migrations/update-22-6-0/prefix-reports-directory-with-project-root.d.ts +0 -1
- package/{src → dist/src}/migrations/update-22-6-0/prefix-reports-directory-with-project-root.js +2 -2
- package/dist/src/migrations/update-22-6-0/prefix-reports-directory-with-project-root.md +35 -0
- package/{src → dist/src}/plugins/plugin.d.ts +0 -1
- package/{src → dist/src}/plugins/plugin.js +19 -55
- package/dist/src/utils/deprecation.d.ts +3 -0
- package/dist/src/utils/deprecation.js +19 -0
- package/{src → dist/src}/utils/detect-ui-framework.d.ts +0 -1
- package/{src → dist/src}/utils/ensure-dependencies.d.ts +0 -1
- package/{src → dist/src}/utils/executor-utils.d.ts +0 -1
- package/{src → dist/src}/utils/generator-utils.d.ts +1 -2
- package/{src → dist/src}/utils/generator-utils.js +8 -6
- package/{src → dist/src}/utils/ignore-vitest-temp-files.d.ts +0 -1
- package/{src → dist/src}/utils/ignore-vitest-temp-files.js +7 -35
- package/{src → dist/src}/utils/options-utils.d.ts +0 -1
- package/{src → dist/src}/utils/version-utils.d.ts +0 -1
- package/{src → dist/src}/utils/versions.d.ts +0 -1
- package/{src → dist/src}/utils/versions.js +2 -1
- package/{src → dist/src}/utils/vite-config-edit-utils.d.ts +0 -1
- package/executors.json +2 -2
- package/generators.json +9 -4
- package/migrations.json +4 -4
- package/package.json +41 -23
- package/executors.d.ts.map +0 -1
- package/generators.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/src/executors/test/compat.d.ts.map +0 -1
- package/src/executors/test/lib/nx-reporter.d.ts.map +0 -1
- package/src/executors/test/lib/utils.d.ts.map +0 -1
- package/src/executors/test/vitest.impl.d.ts.map +0 -1
- package/src/generators/configuration/configuration.d.ts.map +0 -1
- package/src/generators/init/init.d.ts.map +0 -1
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts.map +0 -1
- package/src/migrations/update-22-1-0/create-ai-instructions-for-vitest-4.d.ts +0 -3
- package/src/migrations/update-22-1-0/create-ai-instructions-for-vitest-4.d.ts.map +0 -1
- package/src/migrations/update-22-1-0/create-ai-instructions-for-vitest-4.js +0 -16
- package/src/migrations/update-22-6-0/prefix-reports-directory-with-project-root.d.ts.map +0 -1
- package/src/plugins/plugin.d.ts.map +0 -1
- package/src/utils/detect-ui-framework.d.ts.map +0 -1
- package/src/utils/ensure-dependencies.d.ts.map +0 -1
- package/src/utils/executor-utils.d.ts.map +0 -1
- package/src/utils/generator-utils.d.ts.map +0 -1
- package/src/utils/ignore-vitest-temp-files.d.ts.map +0 -1
- package/src/utils/options-utils.d.ts.map +0 -1
- package/src/utils/version-utils.d.ts.map +0 -1
- package/src/utils/versions.d.ts.map +0 -1
- package/src/utils/vite-config-edit-utils.d.ts.map +0 -1
- /package/{LICENSE → dist/LICENSE} +0 -0
- /package/{PLUGIN.md → dist/PLUGIN.md} +0 -0
- /package/{executors.js → dist/executors.js} +0 -0
- /package/{generators.js → dist/generators.js} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{src → dist/src}/executors/test/compat.js +0 -0
- /package/{src → dist/src}/executors/test/lib/nx-reporter.js +0 -0
- /package/{src → dist/src}/executors/test/lib/utils.js +0 -0
- /package/{src → dist/src}/executors/test/schema.d.ts +0 -0
- /package/{src → dist/src}/generators/configuration/files/tsconfig.spec.json__tmpl__ +0 -0
- /package/{src → dist/src}/generators/configuration/schema.d.ts +0 -0
- /package/{src → dist/src}/generators/configuration/schema.json +0 -0
- /package/{src → dist/src}/generators/init/schema.d.ts +0 -0
- /package/{src → dist/src}/generators/init/schema.json +0 -0
- /package/{src → dist/src}/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.js +0 -0
- /package/{src/migrations/update-22-1-0/files → dist/src/migrations/update-22-1-0}/ai-instructions-for-vitest-4.md +0 -0
- /package/{src → dist/src}/utils/detect-ui-framework.js +0 -0
- /package/{src → dist/src}/utils/ensure-dependencies.js +0 -0
- /package/{src → dist/src}/utils/executor-utils.js +0 -0
- /package/{src → dist/src}/utils/options-utils.js +0 -0
- /package/{src → dist/src}/utils/version-utils.js +0 -0
- /package/{src → dist/src}/utils/vite-config-edit-utils.js +0 -0
|
@@ -9,4 +9,3 @@ export declare function getOptions(options: VitestExecutorOptions, context: Exec
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function resolveReportsDirectory(reportsDirectory: string): string;
|
|
11
11
|
export declare function getOptionsAsArgv(obj: Record<string, any>): string[];
|
|
12
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"title": "Vitest executor",
|
|
6
6
|
"description": "Test using Vitest.",
|
|
7
7
|
"type": "object",
|
|
8
|
+
"x-deprecated": "The `@nx/vitest:test` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vitest:convert-to-inferred` to migrate to the `@nx/vitest/plugin` inferred plugin. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.",
|
|
8
9
|
"properties": {
|
|
9
10
|
"configFile": {
|
|
10
11
|
"type": "string",
|
|
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.vitestExecutor = vitestExecutor;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const internal_1 = require("@nx/js/
|
|
6
|
+
const internal_1 = require("@nx/js/internal");
|
|
7
7
|
const nx_reporter_1 = require("./lib/nx-reporter");
|
|
8
8
|
const utils_1 = require("./lib/utils");
|
|
9
9
|
const executor_utils_1 = require("../../utils/executor-utils");
|
|
10
|
+
const deprecation_1 = require("../../utils/deprecation");
|
|
10
11
|
async function* vitestExecutor(options, context) {
|
|
12
|
+
(0, deprecation_1.warnVitestTestExecutorDeprecation)();
|
|
11
13
|
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
12
14
|
(0, internal_1.registerTsConfigPaths)((0, path_1.resolve)(devkit_1.workspaceRoot, projectRoot, 'tsconfig.json'));
|
|
13
15
|
process.env.VITE_CJS_IGNORE_WARNING = 'true';
|
|
@@ -6,4 +6,3 @@ import { VitestGeneratorSchema } from './schema';
|
|
|
6
6
|
export declare function configurationGenerator(tree: Tree, schema: VitestGeneratorSchema, hasPlugin?: boolean): Promise<GeneratorCallback>;
|
|
7
7
|
export declare function configurationGeneratorInternal(tree: Tree, schema: VitestGeneratorSchema, hasPlugin?: boolean): Promise<GeneratorCallback>;
|
|
8
8
|
export default configurationGenerator;
|
|
9
|
-
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -4,9 +4,9 @@ exports.configurationGenerator = configurationGenerator;
|
|
|
4
4
|
exports.configurationGeneratorInternal = configurationGeneratorInternal;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
7
8
|
const js_1 = require("@nx/js");
|
|
8
|
-
const
|
|
9
|
-
const versions_1 = require("@nx/js/src/utils/versions");
|
|
9
|
+
const internal_2 = require("@nx/js/internal");
|
|
10
10
|
const path_1 = require("path");
|
|
11
11
|
const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
|
|
12
12
|
const generator_utils_1 = require("../../utils/generator-utils");
|
|
@@ -123,10 +123,10 @@ getTestBed().initTestEnvironment(
|
|
|
123
123
|
else if (uiFramework === 'react') {
|
|
124
124
|
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
125
125
|
project: schema.project,
|
|
126
|
-
includeLib: (0,
|
|
126
|
+
includeLib: (0, internal_2.getProjectType)(tree, root, projectType) === 'library',
|
|
127
127
|
includeVitest: true,
|
|
128
128
|
inSourceTests: schema.inSourceTests,
|
|
129
|
-
|
|
129
|
+
rolldownOptionsExternal: [
|
|
130
130
|
"'react'",
|
|
131
131
|
"'react-dom'",
|
|
132
132
|
"'react/jsx-runtime'",
|
|
@@ -146,7 +146,7 @@ getTestBed().initTestEnvironment(
|
|
|
146
146
|
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
147
147
|
...schema,
|
|
148
148
|
includeVitest: true,
|
|
149
|
-
includeLib: (0,
|
|
149
|
+
includeLib: (0, internal_2.getProjectType)(tree, root, projectType) === 'library',
|
|
150
150
|
useEsmExtension: true,
|
|
151
151
|
}, true, {
|
|
152
152
|
vitestFileName: useVitestConfig,
|
|
@@ -154,22 +154,21 @@ getTestBed().initTestEnvironment(
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
const isTsSolutionSetup = (0,
|
|
157
|
+
const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(tree);
|
|
158
158
|
createFiles(tree, schema, root, isTsSolutionSetup);
|
|
159
159
|
updateTsConfig(tree, schema, root, projectType);
|
|
160
160
|
if (isTsSolutionSetup) {
|
|
161
161
|
// in the TS solution setup, the test target depends on the build outputs
|
|
162
162
|
// so we need to setup the task pipeline accordingly
|
|
163
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
163
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
164
164
|
const testTarget = schema.testTarget ?? 'test';
|
|
165
|
-
nxJson.targetDefaults
|
|
166
|
-
|
|
167
|
-
nxJson
|
|
168
|
-
nxJson.targetDefaults[testTarget].dependsOn = Array.from(new Set([...nxJson.targetDefaults[testTarget].dependsOn, '^build']));
|
|
165
|
+
const existing = findTestDefault(nxJson.targetDefaults, testTarget);
|
|
166
|
+
const dependsOn = Array.from(new Set([...(existing?.dependsOn ?? []), '^build']));
|
|
167
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, { target: testTarget, dependsOn });
|
|
169
168
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
170
169
|
}
|
|
171
170
|
const devDependencies = await getCoverageProviderDependency(tree, schema.coverageProvider);
|
|
172
|
-
devDependencies['@types/node'] =
|
|
171
|
+
devDependencies['@types/node'] = internal_2.typesNodeVersion;
|
|
173
172
|
if (!schema.skipPackageJson) {
|
|
174
173
|
const installDependenciesTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, true);
|
|
175
174
|
tasks.push(installDependenciesTask);
|
|
@@ -231,7 +230,7 @@ function updateTsConfig(tree, options, projectRoot, projectType) {
|
|
|
231
230
|
return json;
|
|
232
231
|
});
|
|
233
232
|
}
|
|
234
|
-
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, (0,
|
|
233
|
+
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, (0, internal_2.getProjectType)(tree, projectRoot, projectType) === 'application'
|
|
235
234
|
? 'tsconfig.app.json'
|
|
236
235
|
: 'tsconfig.lib.json');
|
|
237
236
|
if (options.runtimeTsconfigFileName) {
|
|
@@ -354,4 +353,14 @@ function findBuildTarget(project) {
|
|
|
354
353
|
}
|
|
355
354
|
return project.targets?.build ?? null;
|
|
356
355
|
}
|
|
356
|
+
function findTestDefault(td, target) {
|
|
357
|
+
if (!td)
|
|
358
|
+
return undefined;
|
|
359
|
+
if (Array.isArray(td)) {
|
|
360
|
+
return td.find((e) => e.target === target &&
|
|
361
|
+
e.projects === undefined &&
|
|
362
|
+
e.plugin === undefined);
|
|
363
|
+
}
|
|
364
|
+
return td[target];
|
|
365
|
+
}
|
|
357
366
|
exports.default = configurationGenerator;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToInferred = convertToInferred;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
6
|
+
const plugin_1 = require("../../plugins/plugin");
|
|
7
|
+
const test_post_target_transformer_1 = require("./lib/test-post-target-transformer");
|
|
8
|
+
async function convertToInferred(tree, options) {
|
|
9
|
+
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
10
|
+
const migratedProjects = await (0, internal_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/vitest', plugin_1.createNodesV2, { testTargetName: 'test' }, [
|
|
11
|
+
{
|
|
12
|
+
executors: ['@nx/vitest:test'],
|
|
13
|
+
postTargetTransformer: test_post_target_transformer_1.testPostTargetTransformer,
|
|
14
|
+
targetPluginOptionMapper: (target) => ({ testTargetName: target }),
|
|
15
|
+
},
|
|
16
|
+
], options.project);
|
|
17
|
+
if (migratedProjects.size === 0) {
|
|
18
|
+
throw new internal_1.NoTargetsToMigrateError();
|
|
19
|
+
}
|
|
20
|
+
if (!options.skipFormat) {
|
|
21
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = convertToInferred;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TargetConfiguration, type Tree } from '@nx/devkit';
|
|
2
|
+
export declare function testPostTargetTransformer(target: TargetConfiguration, tree: Tree, projectDetails: {
|
|
3
|
+
projectName: string;
|
|
4
|
+
root: string;
|
|
5
|
+
}, inferredTargetConfiguration: TargetConfiguration): TargetConfiguration<any>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testPostTargetTransformer = testPostTargetTransformer;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function testPostTargetTransformer(target, tree, projectDetails, inferredTargetConfiguration) {
|
|
7
|
+
if (target.options) {
|
|
8
|
+
removePropertiesFromTargetOptions(target.options, projectDetails.root);
|
|
9
|
+
}
|
|
10
|
+
if (target.configurations) {
|
|
11
|
+
for (const configurationName in target.configurations) {
|
|
12
|
+
const configuration = target.configurations[configurationName];
|
|
13
|
+
removePropertiesFromTargetOptions(configuration, projectDetails.root);
|
|
14
|
+
}
|
|
15
|
+
if (Object.keys(target.configurations).length === 0) {
|
|
16
|
+
if ('defaultConfiguration' in target) {
|
|
17
|
+
delete target.defaultConfiguration;
|
|
18
|
+
}
|
|
19
|
+
delete target.configurations;
|
|
20
|
+
}
|
|
21
|
+
if ('defaultConfiguration' in target &&
|
|
22
|
+
!target.configurations[target.defaultConfiguration]) {
|
|
23
|
+
delete target.defaultConfiguration;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target.outputs) {
|
|
27
|
+
(0, internal_1.processTargetOutputs)(target, [{ newName: 'coverage.reportsDirectory', oldName: 'reportsDirectory' }], inferredTargetConfiguration, {
|
|
28
|
+
projectName: projectDetails.projectName,
|
|
29
|
+
projectRoot: projectDetails.root,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (target.inputs &&
|
|
33
|
+
target.inputs.every((i) => i === 'default' || i === '^production')) {
|
|
34
|
+
delete target.inputs;
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
}
|
|
38
|
+
function removePropertiesFromTargetOptions(targetOptions, projectRoot) {
|
|
39
|
+
if ('configFile' in targetOptions) {
|
|
40
|
+
targetOptions.config = (0, utils_1.toProjectRelativePath)(targetOptions.configFile, projectRoot);
|
|
41
|
+
delete targetOptions.configFile;
|
|
42
|
+
}
|
|
43
|
+
if ('reportsDirectory' in targetOptions) {
|
|
44
|
+
if (targetOptions.reportsDirectory.startsWith('../')) {
|
|
45
|
+
targetOptions.reportsDirectory = targetOptions.reportsDirectory.replace(/(\.\.\/)+/, '');
|
|
46
|
+
}
|
|
47
|
+
targetOptions['coverage.reportsDirectory'] = (0, utils_1.toProjectRelativePath)(targetOptions.reportsDirectory, projectRoot);
|
|
48
|
+
delete targetOptions.reportsDirectory;
|
|
49
|
+
}
|
|
50
|
+
if ('testFiles' in targetOptions) {
|
|
51
|
+
targetOptions.testNamePattern = `"/(${targetOptions.testFiles
|
|
52
|
+
.map((f) => f.replace('.', '\\.'))
|
|
53
|
+
.join('|')})/"`;
|
|
54
|
+
delete targetOptions.testFiles;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toProjectRelativePath(path: string, projectRoot: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toProjectRelativePath = toProjectRelativePath;
|
|
4
|
+
const posix_1 = require("path/posix");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
function toProjectRelativePath(path, projectRoot) {
|
|
7
|
+
if (projectRoot === '.') {
|
|
8
|
+
return path.startsWith('.') ? path : `./${path}`;
|
|
9
|
+
}
|
|
10
|
+
const relativePath = (0, posix_1.relative)((0, posix_1.resolve)(devkit_1.workspaceRoot, projectRoot), (0, posix_1.resolve)(devkit_1.workspaceRoot, path));
|
|
11
|
+
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxVitestConvertToInferred",
|
|
4
|
+
"description": "Convert existing vitest project(s) using `@nx/vitest:test` executors to use the `@nx/vitest` inferred plugin. Defaults to migrating all projects. Pass '--project' to migrate only one target.",
|
|
5
|
+
"title": "Convert vitest project from executor to inferred plugin",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project to convert from using the `@nx/vitest:test` executor to use the `@nx/vitest` inferred plugin.",
|
|
11
|
+
"x-priority": "important"
|
|
12
|
+
},
|
|
13
|
+
"skipFormat": {
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"description": "Whether to format files at the end of the migration.",
|
|
16
|
+
"default": false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -4,4 +4,3 @@ export declare function updateDependencies(tree: Tree, schema: InitGeneratorSche
|
|
|
4
4
|
export declare function updateNxJsonSettings(tree: Tree): void;
|
|
5
5
|
export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
|
|
6
6
|
export default initGenerator;
|
|
7
|
-
//# sourceMappingURL=init.d.ts.map
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateDependencies = updateDependencies;
|
|
4
4
|
exports.updateNxJsonSettings = updateNxJsonSettings;
|
|
5
5
|
exports.initGenerator = initGenerator;
|
|
6
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
6
7
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
|
|
8
8
|
const versions_1 = require("../../utils/versions");
|
|
9
9
|
const plugin_1 = require("../../plugins/plugin");
|
|
10
10
|
const version_utils_1 = require("../../utils/version-utils");
|
|
@@ -29,7 +29,7 @@ function updateDependencies(tree, schema) {
|
|
|
29
29
|
}, undefined, schema.keepExistingVersions);
|
|
30
30
|
}
|
|
31
31
|
function updateNxJsonSettings(tree) {
|
|
32
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
32
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
33
33
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
34
34
|
if (productionFileSet) {
|
|
35
35
|
productionFileSet.push('!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json');
|
|
@@ -37,13 +37,18 @@ function updateNxJsonSettings(tree) {
|
|
|
37
37
|
}
|
|
38
38
|
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string' ? p === '@nx/vitest' : p.plugin === '@nx/vitest');
|
|
39
39
|
if (!hasPlugin) {
|
|
40
|
-
nxJson.targetDefaults
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
const existing = (0, internal_1.normalizeTargetDefaults)(nxJson.targetDefaults).find((e) => e.executor === '@nx/vitest:test' &&
|
|
41
|
+
e.target === undefined &&
|
|
42
|
+
e.projects === undefined &&
|
|
43
|
+
e.plugin === undefined);
|
|
44
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
45
|
+
executor: '@nx/vitest:test',
|
|
46
|
+
cache: existing?.cache ?? true,
|
|
47
|
+
inputs: existing?.inputs ?? [
|
|
48
|
+
'default',
|
|
49
|
+
productionFileSet ? '^production' : '^default',
|
|
50
|
+
],
|
|
51
|
+
});
|
|
47
52
|
}
|
|
48
53
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
49
54
|
}
|
|
@@ -53,7 +58,7 @@ async function initGenerator(tree, schema) {
|
|
|
53
58
|
nxJson.useInferencePlugins !== false;
|
|
54
59
|
schema.addPlugin ??= addPluginDefault;
|
|
55
60
|
if (schema.addPlugin) {
|
|
56
|
-
await (0,
|
|
61
|
+
await (0, internal_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/vitest', plugin_1.createNodesV2, {
|
|
57
62
|
testTargetName: ['test', 'vitest:test', 'vitest-test'],
|
|
58
63
|
ciTargetName: ['test-ci', 'vitest:test-ci', 'vitest-test-ci'],
|
|
59
64
|
}, schema.updatePackageScripts);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#### Add Vitest Temp Files to Git Ignore
|
|
2
|
+
|
|
3
|
+
Add gitignore entry for temporary vitest config files.
|
|
4
|
+
|
|
5
|
+
#### Sample Code Changes
|
|
6
|
+
|
|
7
|
+
Adds the following entries to the `.gitignore` file.
|
|
8
|
+
|
|
9
|
+
```text title=".gitignore"
|
|
10
|
+
vite.config.*.timestamp*
|
|
11
|
+
vitest.config.*.timestamp*
|
|
12
|
+
```
|
package/{src → dist/src}/migrations/update-22-6-0/prefix-reports-directory-with-project-root.d.ts
RENAMED
|
@@ -7,4 +7,3 @@ import { type Tree } from '@nx/devkit';
|
|
|
7
7
|
* {projectRoot}/ to existing naked paths so the resolved location stays the same.
|
|
8
8
|
*/
|
|
9
9
|
export default function prefixReportsDirectoryWithProjectRoot(tree: Tree): void;
|
|
10
|
-
//# sourceMappingURL=prefix-reports-directory-with-project-root.d.ts.map
|
package/{src → dist/src}/migrations/update-22-6-0/prefix-reports-directory-with-project-root.js
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = prefixReportsDirectoryWithProjectRoot;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
/**
|
|
8
8
|
* Migrates reportsDirectory option for @nx/vitest:test and @nx/vite:test executors.
|
|
@@ -18,7 +18,7 @@ function prefixReportsDirectoryWithProjectRoot(tree) {
|
|
|
18
18
|
function migrateProjectConfigurations(tree) {
|
|
19
19
|
const projectsToUpdate = new Map();
|
|
20
20
|
for (const executorName of ['@nx/vitest:test', '@nx/vite:test']) {
|
|
21
|
-
(0,
|
|
21
|
+
(0, internal_1.forEachExecutorOptions)(tree, executorName, (options, projectName, targetName, configuration) => {
|
|
22
22
|
if (needsMigration(options.reportsDirectory)) {
|
|
23
23
|
if (!projectsToUpdate.has(projectName)) {
|
|
24
24
|
projectsToUpdate.set(projectName, new Map());
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#### Prefix `reportsDirectory` with `{projectRoot}`
|
|
2
|
+
|
|
3
|
+
The `reportsDirectory` option for `@nx/vitest:test` (and `@nx/vite:test`) is now resolved relative to the workspace root instead of the project root. This migration prepends `{projectRoot}/` to existing `reportsDirectory` values so the resolved path remains the same.
|
|
4
|
+
|
|
5
|
+
#### Sample Code Changes
|
|
6
|
+
|
|
7
|
+
##### Before
|
|
8
|
+
|
|
9
|
+
```json title="project.json"
|
|
10
|
+
{
|
|
11
|
+
"targets": {
|
|
12
|
+
"test": {
|
|
13
|
+
"executor": "@nx/vitest:test",
|
|
14
|
+
"options": {
|
|
15
|
+
"reportsDirectory": "coverage/libs/my-lib"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
##### After
|
|
23
|
+
|
|
24
|
+
```json title="project.json" {6}
|
|
25
|
+
{
|
|
26
|
+
"targets": {
|
|
27
|
+
"test": {
|
|
28
|
+
"executor": "@nx/vitest:test",
|
|
29
|
+
"options": {
|
|
30
|
+
"reportsDirectory": "{projectRoot}/coverage/libs/my-lib"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
@@ -22,4 +22,3 @@ export interface VitestPluginOptions {
|
|
|
22
22
|
export declare const createDependencies: CreateDependencies;
|
|
23
23
|
export declare const createNodes: CreateNodesV2<VitestPluginOptions>;
|
|
24
24
|
export declare const createNodesV2: CreateNodesV2<VitestPluginOptions>;
|
|
25
|
-
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1,58 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.createNodesV2 = exports.createNodes = exports.createDependencies = void 0;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
37
5
|
const devkit_1 = require("@nx/devkit");
|
|
38
|
-
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
39
|
-
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
40
6
|
const js_1 = require("@nx/js");
|
|
41
|
-
const
|
|
7
|
+
const internal_2 = require("@nx/js/internal");
|
|
42
8
|
const node_fs_1 = require("node:fs");
|
|
43
9
|
const node_path_1 = require("node:path");
|
|
44
10
|
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
45
11
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
46
12
|
const plugins_1 = require("nx/src/utils/plugins");
|
|
47
13
|
const executor_utils_1 = require("../utils/executor-utils");
|
|
48
|
-
function readTargetsCache(cachePath) {
|
|
49
|
-
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, node_fs_1.existsSync)(cachePath)
|
|
50
|
-
? (0, devkit_1.readJsonFile)(cachePath)
|
|
51
|
-
: {};
|
|
52
|
-
}
|
|
53
|
-
function writeTargetsToCache(cachePath, results) {
|
|
54
|
-
(0, devkit_1.writeJsonFile)(cachePath, results);
|
|
55
|
-
}
|
|
56
14
|
/**
|
|
57
15
|
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
58
16
|
*/
|
|
@@ -68,7 +26,7 @@ exports.createNodes = [
|
|
|
68
26
|
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
|
69
27
|
const normalizedOptions = normalizeOptions(options);
|
|
70
28
|
const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `vitest-${optionsHash}.hash`);
|
|
71
|
-
const targetsCache =
|
|
29
|
+
const targetsCache = new internal_1.PluginCache(cachePath);
|
|
72
30
|
const { roots: projectRoots, configFiles: validConfigFiles } = configFilePaths.reduce((acc, configFile) => {
|
|
73
31
|
const potentialRoot = (0, node_path_1.dirname)(configFile);
|
|
74
32
|
if (checkIfConfigFileShouldBeProject(potentialRoot, context)) {
|
|
@@ -82,7 +40,7 @@ exports.createNodes = [
|
|
|
82
40
|
});
|
|
83
41
|
const lockfile = (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot));
|
|
84
42
|
const tsconfigChainsByProjectRoot = collectTsconfigInputsByProjectRoot(projectRoots, context.workspaceRoot);
|
|
85
|
-
const hashes = await (0,
|
|
43
|
+
const hashes = await (0, internal_1.calculateHashesForCreateNodes)(projectRoots, normalizedOptions, context, projectRoots.map((root) => [
|
|
86
44
|
lockfile,
|
|
87
45
|
...(tsconfigChainsByProjectRoot.get(root) ?? []),
|
|
88
46
|
]));
|
|
@@ -94,8 +52,10 @@ exports.createNodes = [
|
|
|
94
52
|
// Adding the config file path to the hash ensures that the final hash value is different
|
|
95
53
|
// for different config files.
|
|
96
54
|
const hash = hashes[idx] + configFile;
|
|
97
|
-
|
|
98
|
-
await buildVitestTargets(configFile, projectRoot, normalizedOptions, context, pmc, tsconfigChainsByProjectRoot.get(projectRoot) ?? []));
|
|
55
|
+
if (!targetsCache.has(hash)) {
|
|
56
|
+
targetsCache.set(hash, await buildVitestTargets(configFile, projectRoot, normalizedOptions, context, pmc, tsconfigChainsByProjectRoot.get(projectRoot) ?? []));
|
|
57
|
+
}
|
|
58
|
+
const { projectType, metadata, targets } = targetsCache.get(hash);
|
|
99
59
|
const project = {
|
|
100
60
|
root: projectRoot,
|
|
101
61
|
targets,
|
|
@@ -110,7 +70,7 @@ exports.createNodes = [
|
|
|
110
70
|
}, validConfigFiles, options, context);
|
|
111
71
|
}
|
|
112
72
|
finally {
|
|
113
|
-
|
|
73
|
+
targetsCache.writeToDisk();
|
|
114
74
|
}
|
|
115
75
|
},
|
|
116
76
|
];
|
|
@@ -166,7 +126,7 @@ async function buildVitestTargets(configFilePath, projectRoot, options, context,
|
|
|
166
126
|
}
|
|
167
127
|
let metadata = {};
|
|
168
128
|
const { testOutputs, hasTest } = getOutputs(viteBuildConfig, projectRoot, context.workspaceRoot);
|
|
169
|
-
const namedInputs = (0,
|
|
129
|
+
const namedInputs = (0, internal_1.getNamedInputs)(projectRoot, context);
|
|
170
130
|
const targets = {};
|
|
171
131
|
// if file is vitest.config or vite.config has definition for test, create targets for test and/or atomized tests
|
|
172
132
|
if (configFilePath.includes('vitest.config') || hasTest) {
|
|
@@ -370,7 +330,7 @@ function collectTsconfigInputsByProjectRoot(projectRoots, workspaceRoot) {
|
|
|
370
330
|
// 1. Walk the project tsconfig's extends chain
|
|
371
331
|
const projectTsconfig = (0, node_path_1.join)(workspaceRoot, projectRoot, 'tsconfig.json');
|
|
372
332
|
if ((0, node_fs_1.existsSync)(projectTsconfig)) {
|
|
373
|
-
(0,
|
|
333
|
+
(0, internal_2.walkTsconfigExtendsChain)(projectTsconfig, (absPath) => {
|
|
374
334
|
collect(absPath);
|
|
375
335
|
return 'continue';
|
|
376
336
|
}, { jsonCache });
|
|
@@ -381,7 +341,7 @@ function collectTsconfigInputsByProjectRoot(projectRoots, workspaceRoot) {
|
|
|
381
341
|
while (dir && dir !== '.') {
|
|
382
342
|
const ancestorTsconfig = (0, node_path_1.join)(workspaceRoot, dir, 'tsconfig.json');
|
|
383
343
|
if ((0, node_fs_1.existsSync)(ancestorTsconfig)) {
|
|
384
|
-
(0,
|
|
344
|
+
(0, internal_2.walkTsconfigExtendsChain)(ancestorTsconfig, (absPath) => {
|
|
385
345
|
collect(absPath);
|
|
386
346
|
return 'continue';
|
|
387
347
|
}, { jsonCache });
|
|
@@ -394,7 +354,7 @@ function collectTsconfigInputsByProjectRoot(projectRoots, workspaceRoot) {
|
|
|
394
354
|
// 3. Check the workspace root itself (dirname loop above stops at '.')
|
|
395
355
|
const rootTsconfig = (0, node_path_1.join)(workspaceRoot, 'tsconfig.json');
|
|
396
356
|
if ((0, node_fs_1.existsSync)(rootTsconfig)) {
|
|
397
|
-
(0,
|
|
357
|
+
(0, internal_2.walkTsconfigExtendsChain)(rootTsconfig, (absPath) => {
|
|
398
358
|
collect(absPath);
|
|
399
359
|
return 'continue';
|
|
400
360
|
}, { jsonCache });
|
|
@@ -416,7 +376,7 @@ function checkIfConfigFileShouldBeProject(projectRoot, context) {
|
|
|
416
376
|
}
|
|
417
377
|
async function getTestPathsRelativeToProjectRoot(projectRoot, workspaceRoot) {
|
|
418
378
|
const fullProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
|
|
419
|
-
const { createVitest } = await
|
|
379
|
+
const { createVitest } = await import('vitest/node');
|
|
420
380
|
const vitest = await createVitest('test', {
|
|
421
381
|
root: fullProjectRoot,
|
|
422
382
|
dir: fullProjectRoot,
|
|
@@ -424,7 +384,11 @@ async function getTestPathsRelativeToProjectRoot(projectRoot, workspaceRoot) {
|
|
|
424
384
|
watch: false,
|
|
425
385
|
});
|
|
426
386
|
const relevantTestSpecifications = await vitest.getRelevantTestSpecifications();
|
|
387
|
+
// Sort to keep atomized target name insertion order stable.
|
|
388
|
+
// vitest.getRelevantTestSpecifications uses tinyglobby internally,
|
|
389
|
+
// which does not sort its filesystem traversal output.
|
|
427
390
|
return relevantTestSpecifications
|
|
428
391
|
.filter((ts) => fullProjectRoot === '.' ? true : ts.moduleId.startsWith(fullProjectRoot))
|
|
429
|
-
.map((ts) => (0, devkit_1.normalizePath)((0, node_path_1.relative)(projectRoot, ts.moduleId)))
|
|
392
|
+
.map((ts) => (0, devkit_1.normalizePath)((0, node_path_1.relative)(projectRoot, ts.moduleId)))
|
|
393
|
+
.sort();
|
|
430
394
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const VITEST_TEST_EXECUTOR_DEPRECATION_MESSAGE = "The `@nx/vitest:test` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vitest:convert-to-inferred` to migrate to the `@nx/vitest/plugin` inferred targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.";
|
|
2
|
+
export declare function warnVitestTestExecutorDeprecation(): void;
|
|
3
|
+
export declare function warnVitestExecutorGenerating(): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VITEST_TEST_EXECUTOR_DEPRECATION_MESSAGE = void 0;
|
|
4
|
+
exports.warnVitestTestExecutorDeprecation = warnVitestTestExecutorDeprecation;
|
|
5
|
+
exports.warnVitestExecutorGenerating = warnVitestExecutorGenerating;
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
// TODO(v24): Remove the @nx/vitest:test executor. The inferred plugin
|
|
8
|
+
// (@nx/vitest/plugin) and the convert-to-inferred generator stay supported.
|
|
9
|
+
exports.VITEST_TEST_EXECUTOR_DEPRECATION_MESSAGE = 'The `@nx/vitest:test` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/vitest:convert-to-inferred` to migrate to the `@nx/vitest/plugin` inferred targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.';
|
|
10
|
+
function warnVitestTestExecutorDeprecation() {
|
|
11
|
+
devkit_1.logger.warn(exports.VITEST_TEST_EXECUTOR_DEPRECATION_MESSAGE);
|
|
12
|
+
}
|
|
13
|
+
// Fired when the @nx/vitest:configuration generator is about to generate a
|
|
14
|
+
// target that uses the deprecated executor — i.e. when @nx/vitest/plugin
|
|
15
|
+
// isn't registered in nx.json. Surfaces the deprecation at generation time
|
|
16
|
+
// rather than only when the user later runs the generated target.
|
|
17
|
+
function warnVitestExecutorGenerating() {
|
|
18
|
+
devkit_1.logger.warn('Generating a target that uses the deprecated `@nx/vitest:test` executor. This executor will be removed in Nx v24. Run `nx g @nx/vitest:convert-to-inferred` next to migrate this target to the `@nx/vitest/plugin` inferred plugin and prevent future generators from emitting executor targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.');
|
|
19
|
+
}
|
|
@@ -6,4 +6,3 @@ export type EnsureDependenciesOptions = {
|
|
|
6
6
|
testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
|
|
7
7
|
};
|
|
8
8
|
export declare function ensureDependencies(tree: Tree, schema: EnsureDependenciesOptions): Promise<GeneratorCallback>;
|
|
9
|
-
//# sourceMappingURL=ensure-dependencies.d.ts.map
|