@nx/vitest 23.0.0-pr.35413.460eeef → 23.0.0-rc.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.
- package/{executors.d.ts → dist/executors.d.ts} +0 -1
- package/{generators.d.ts → dist/generators.d.ts} +0 -1
- package/dist/index.d.ts +1 -0
- package/{index.js → dist/index.js} +2 -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 +30 -18
- 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 +26 -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 +18 -11
- package/{src → dist/src}/generators/init/schema.json +1 -1
- 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/dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.d.ts +9 -0
- package/dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.js +223 -0
- package/dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.md +25 -0
- package/{src → dist/src}/plugins/plugin.d.ts +3 -4
- package/{src → dist/src}/plugins/plugin.js +38 -56
- package/dist/src/utils/assert-supported-vitest-version.d.ts +2 -0
- package/dist/src/utils/assert-supported-vitest-version.js +8 -0
- 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/ensure-dependencies.js +6 -7
- 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/dist/src/utils/version-utils.d.ts +3 -0
- package/dist/src/utils/version-utils.js +27 -0
- package/{src → dist/src}/utils/versions.d.ts +14 -13
- package/dist/src/utils/versions.js +66 -0
- 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 +15 -9
- package/package.json +43 -25
- package/executors.d.ts.map +0 -1
- package/generators.d.ts.map +0 -1
- package/index.d.ts +0 -2
- 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 +0 -3
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts.map +0 -1
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.js +0 -17
- 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 +0 -16
- package/src/utils/version-utils.d.ts.map +0 -1
- package/src/utils/version-utils.js +0 -90
- package/src/utils/versions.d.ts.map +0 -1
- package/src/utils/versions.js +0 -31
- 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/{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/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/executor-utils.js +0 -0
- /package/{src → dist/src}/utils/options-utils.js +0 -0
- /package/{src → dist/src}/utils/vite-config-edit-utils.js +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createNodes, createNodesV2, VitestPluginOptions, } from './src/plugins/plugin';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodesV2 = void 0;
|
|
3
|
+
exports.createNodesV2 = exports.createNodes = void 0;
|
|
4
4
|
var plugin_1 = require("./src/plugins/plugin");
|
|
5
|
+
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
|
5
6
|
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
|
|
@@ -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,15 +4,17 @@ 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");
|
|
13
13
|
const init_1 = tslib_1.__importDefault(require("../init/init"));
|
|
14
14
|
const detect_ui_framework_1 = require("../../utils/detect-ui-framework");
|
|
15
15
|
const version_utils_1 = require("../../utils/version-utils");
|
|
16
|
+
const versions_1 = require("../../utils/versions");
|
|
17
|
+
const assert_supported_vitest_version_1 = require("../../utils/assert-supported-vitest-version");
|
|
16
18
|
const semver_1 = require("semver");
|
|
17
19
|
/**
|
|
18
20
|
* Determines whether to use vitest.config.mts instead of vite.config.mts.
|
|
@@ -39,6 +41,7 @@ function configurationGenerator(tree, schema, hasPlugin = false) {
|
|
|
39
41
|
return configurationGeneratorInternal(tree, { addPlugin: false, ...schema }, hasPlugin);
|
|
40
42
|
}
|
|
41
43
|
async function configurationGeneratorInternal(tree, schema, hasPlugin = false) {
|
|
44
|
+
(0, assert_supported_vitest_version_1.assertSupportedVitestVersion)(tree);
|
|
42
45
|
// Setting default to jsdom since it is the most common use case (React, Web).
|
|
43
46
|
// The @nx/js:lib generator specifically sets this to node to be more generic.
|
|
44
47
|
schema.testEnvironment ??= 'jsdom';
|
|
@@ -123,10 +126,10 @@ getTestBed().initTestEnvironment(
|
|
|
123
126
|
else if (uiFramework === 'react') {
|
|
124
127
|
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
125
128
|
project: schema.project,
|
|
126
|
-
includeLib: (0,
|
|
129
|
+
includeLib: (0, internal_2.getProjectType)(tree, root, projectType) === 'library',
|
|
127
130
|
includeVitest: true,
|
|
128
131
|
inSourceTests: schema.inSourceTests,
|
|
129
|
-
|
|
132
|
+
rolldownOptionsExternal: [
|
|
130
133
|
"'react'",
|
|
131
134
|
"'react-dom'",
|
|
132
135
|
"'react/jsx-runtime'",
|
|
@@ -146,7 +149,7 @@ getTestBed().initTestEnvironment(
|
|
|
146
149
|
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
147
150
|
...schema,
|
|
148
151
|
includeVitest: true,
|
|
149
|
-
includeLib: (0,
|
|
152
|
+
includeLib: (0, internal_2.getProjectType)(tree, root, projectType) === 'library',
|
|
150
153
|
useEsmExtension: true,
|
|
151
154
|
}, true, {
|
|
152
155
|
vitestFileName: useVitestConfig,
|
|
@@ -154,22 +157,21 @@ getTestBed().initTestEnvironment(
|
|
|
154
157
|
});
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
|
-
const isTsSolutionSetup = (0,
|
|
160
|
+
const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(tree);
|
|
158
161
|
createFiles(tree, schema, root, isTsSolutionSetup);
|
|
159
162
|
updateTsConfig(tree, schema, root, projectType);
|
|
160
163
|
if (isTsSolutionSetup) {
|
|
161
164
|
// in the TS solution setup, the test target depends on the build outputs
|
|
162
165
|
// so we need to setup the task pipeline accordingly
|
|
163
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
166
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
164
167
|
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']));
|
|
168
|
+
const existing = findTestDefault(nxJson.targetDefaults, testTarget);
|
|
169
|
+
const dependsOn = Array.from(new Set([...(existing?.dependsOn ?? []), '^build']));
|
|
170
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, { target: testTarget, dependsOn });
|
|
169
171
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
170
172
|
}
|
|
171
173
|
const devDependencies = await getCoverageProviderDependency(tree, schema.coverageProvider);
|
|
172
|
-
devDependencies['@types/node'] =
|
|
174
|
+
devDependencies['@types/node'] = internal_2.typesNodeVersion;
|
|
173
175
|
if (!schema.skipPackageJson) {
|
|
174
176
|
const installDependenciesTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, true);
|
|
175
177
|
tasks.push(installDependenciesTask);
|
|
@@ -231,7 +233,7 @@ function updateTsConfig(tree, options, projectRoot, projectType) {
|
|
|
231
233
|
return json;
|
|
232
234
|
});
|
|
233
235
|
}
|
|
234
|
-
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, (0,
|
|
236
|
+
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, (0, internal_2.getProjectType)(tree, projectRoot, projectType) === 'application'
|
|
235
237
|
? 'tsconfig.app.json'
|
|
236
238
|
: 'tsconfig.lib.json');
|
|
237
239
|
if (options.runtimeTsconfigFileName) {
|
|
@@ -288,20 +290,20 @@ function createFiles(tree, options, projectRoot, isTsSolutionSetup) {
|
|
|
288
290
|
: `${rootOffset}dist/out-tsc`,
|
|
289
291
|
});
|
|
290
292
|
}
|
|
291
|
-
|
|
292
|
-
const {
|
|
293
|
+
function getCoverageProviderDependency(tree, coverageProvider) {
|
|
294
|
+
const { vitestCoverageV8Version, vitestCoverageIstanbulVersion } = (0, versions_1.versions)(tree);
|
|
293
295
|
switch (coverageProvider) {
|
|
294
296
|
case 'v8':
|
|
295
297
|
return {
|
|
296
|
-
'@vitest/coverage-v8':
|
|
298
|
+
'@vitest/coverage-v8': vitestCoverageV8Version,
|
|
297
299
|
};
|
|
298
300
|
case 'istanbul':
|
|
299
301
|
return {
|
|
300
|
-
'@vitest/coverage-istanbul':
|
|
302
|
+
'@vitest/coverage-istanbul': vitestCoverageIstanbulVersion,
|
|
301
303
|
};
|
|
302
304
|
default:
|
|
303
305
|
return {
|
|
304
|
-
'@vitest/coverage-v8':
|
|
306
|
+
'@vitest/coverage-v8': vitestCoverageV8Version,
|
|
305
307
|
};
|
|
306
308
|
}
|
|
307
309
|
}
|
|
@@ -354,4 +356,14 @@ function findBuildTarget(project) {
|
|
|
354
356
|
}
|
|
355
357
|
return project.targets?.build ?? null;
|
|
356
358
|
}
|
|
359
|
+
function findTestDefault(td, target) {
|
|
360
|
+
if (!td)
|
|
361
|
+
return undefined;
|
|
362
|
+
if (Array.isArray(td)) {
|
|
363
|
+
return td.find((e) => e.target === target &&
|
|
364
|
+
e.projects === undefined &&
|
|
365
|
+
e.plugin === undefined);
|
|
366
|
+
}
|
|
367
|
+
return td[target];
|
|
368
|
+
}
|
|
357
369
|
exports.default = configurationGenerator;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
const assert_supported_vitest_version_1 = require("../../utils/assert-supported-vitest-version");
|
|
9
|
+
async function convertToInferred(tree, options) {
|
|
10
|
+
(0, assert_supported_vitest_version_1.assertSupportedVitestVersion)(tree);
|
|
11
|
+
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
12
|
+
const migratedProjects = await (0, internal_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/vitest', plugin_1.createNodesV2, { testTargetName: 'test' }, [
|
|
13
|
+
{
|
|
14
|
+
executors: ['@nx/vitest:test'],
|
|
15
|
+
postTargetTransformer: test_post_target_transformer_1.testPostTargetTransformer,
|
|
16
|
+
targetPluginOptionMapper: (target) => ({ testTargetName: target }),
|
|
17
|
+
},
|
|
18
|
+
], options.project);
|
|
19
|
+
if (migratedProjects.size === 0) {
|
|
20
|
+
throw new internal_1.NoTargetsToMigrateError();
|
|
21
|
+
}
|
|
22
|
+
if (!options.skipFormat) {
|
|
23
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
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,12 +3,13 @@ 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");
|
|
11
11
|
const ignore_vitest_temp_files_1 = require("../../utils/ignore-vitest-temp-files");
|
|
12
|
+
const assert_supported_vitest_version_1 = require("../../utils/assert-supported-vitest-version");
|
|
12
13
|
function updateDependencies(tree, schema) {
|
|
13
14
|
// Determine which vite version to install:
|
|
14
15
|
// 1. Explicit viteVersion flag takes priority
|
|
@@ -26,10 +27,10 @@ function updateDependencies(tree, schema) {
|
|
|
26
27
|
'@nx/vitest': versions_1.nxVersion,
|
|
27
28
|
vitest: versions_1.vitestVersion,
|
|
28
29
|
vite: viteVersionToUse,
|
|
29
|
-
}, undefined, schema.keepExistingVersions);
|
|
30
|
+
}, undefined, schema.keepExistingVersions ?? true);
|
|
30
31
|
}
|
|
31
32
|
function updateNxJsonSettings(tree) {
|
|
32
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
33
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
33
34
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
34
35
|
if (productionFileSet) {
|
|
35
36
|
productionFileSet.push('!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json');
|
|
@@ -37,23 +38,29 @@ function updateNxJsonSettings(tree) {
|
|
|
37
38
|
}
|
|
38
39
|
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string' ? p === '@nx/vitest' : p.plugin === '@nx/vitest');
|
|
39
40
|
if (!hasPlugin) {
|
|
40
|
-
nxJson.targetDefaults
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
const existing = (0, internal_1.normalizeTargetDefaults)(nxJson.targetDefaults).find((e) => e.executor === '@nx/vitest:test' &&
|
|
42
|
+
e.target === undefined &&
|
|
43
|
+
e.projects === undefined &&
|
|
44
|
+
e.plugin === undefined);
|
|
45
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
46
|
+
executor: '@nx/vitest:test',
|
|
47
|
+
cache: existing?.cache ?? true,
|
|
48
|
+
inputs: existing?.inputs ?? [
|
|
49
|
+
'default',
|
|
50
|
+
productionFileSet ? '^production' : '^default',
|
|
51
|
+
],
|
|
52
|
+
});
|
|
47
53
|
}
|
|
48
54
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
49
55
|
}
|
|
50
56
|
async function initGenerator(tree, schema) {
|
|
57
|
+
(0, assert_supported_vitest_version_1.assertSupportedVitestVersion)(tree);
|
|
51
58
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
52
59
|
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
53
60
|
nxJson.useInferencePlugins !== false;
|
|
54
61
|
schema.addPlugin ??= addPluginDefault;
|
|
55
62
|
if (schema.addPlugin) {
|
|
56
|
-
await (0,
|
|
63
|
+
await (0, internal_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/vitest', plugin_1.createNodesV2, {
|
|
57
64
|
testTargetName: ['test', 'vitest:test', 'vitest-test'],
|
|
58
65
|
ciTargetName: ['test-ci', 'vitest:test-ci', 'vitest-test-ci'],
|
|
59
66
|
}, schema.updatePackageScripts);
|
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
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
export default function migrateCreateNodesV2ToCreateNodes(tree: Tree): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* Rewrites named imports and re-exports of `createNodesV2` to `createNodes`
|
|
5
|
+
* when they come from one of the given module specifiers. Only the named
|
|
6
|
+
* bindings are touched — the module specifier, the `import`/`export` keyword,
|
|
7
|
+
* any `type` modifier, and any default import are left untouched.
|
|
8
|
+
*/
|
|
9
|
+
export declare function rewriteCreateNodesV2Imports(source: string, specifiers: ReadonlySet<string>): string;
|