@nx/vitest 22.3.0-canary.20251211-205daee → 22.3.0-canary.20251216-71bfc21
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/package.json +4 -4
- package/src/generators/configuration/configuration.d.ts.map +1 -1
- package/src/generators/configuration/configuration.js +15 -6
- package/src/generators/configuration/schema.d.ts +1 -0
- package/src/generators/configuration/schema.json +6 -0
- package/src/utils/generator-utils.d.ts +5 -1
- package/src/utils/generator-utils.d.ts.map +1 -1
- package/src/utils/generator-utils.js +7 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vitest",
|
|
3
3
|
"description": "The Nx Plugin for Vitest to enable fast unit testing with Vitest.",
|
|
4
|
-
"version": "22.3.0-canary.
|
|
4
|
+
"version": "22.3.0-canary.20251216-71bfc21",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"executors": "./executors.json",
|
|
53
53
|
"generators": "./generators.json",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@nx/devkit": "22.3.0-canary.
|
|
56
|
-
"@nx/js": "22.3.0-canary.
|
|
55
|
+
"@nx/devkit": "22.3.0-canary.20251216-71bfc21",
|
|
56
|
+
"@nx/js": "22.3.0-canary.20251216-71bfc21",
|
|
57
57
|
"tslib": "^2.3.0",
|
|
58
58
|
"semver": "^7.6.3",
|
|
59
59
|
"@phenomnomnominal/tsquery": "~5.0.1"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"nx": "22.3.0-canary.
|
|
74
|
+
"nx": "22.3.0-canary.20251216-71bfc21"
|
|
75
75
|
},
|
|
76
76
|
"types": "./src/index.d.ts"
|
|
77
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EASjB,IAAI,EAGL,MAAM,YAAY,CAAC;AAcpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAmCjD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAOlB;AAED,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EASjB,IAAI,EAGL,MAAM,YAAY,CAAC;AAcpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAmCjD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAOlB;AAED,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAqMlB;AAgMD,eAAe,sBAAsB,CAAC"}
|
|
@@ -55,9 +55,13 @@ async function configurationGeneratorInternal(tree, schema, hasPlugin = false) {
|
|
|
55
55
|
addPlugin: schema.addPlugin,
|
|
56
56
|
projectRoot: root,
|
|
57
57
|
viteVersion: schema.viteVersion,
|
|
58
|
+
skipPackageJson: schema.skipPackageJson,
|
|
59
|
+
keepExistingVersions: true,
|
|
58
60
|
});
|
|
59
61
|
tasks.push(initTask);
|
|
60
|
-
|
|
62
|
+
if (!schema.skipPackageJson) {
|
|
63
|
+
tasks.push(await (0, ensure_dependencies_1.ensureDependencies)(tree, { ...schema, uiFramework }));
|
|
64
|
+
}
|
|
61
65
|
(0, generator_utils_1.addOrChangeTestTarget)(tree, schema, hasPlugin);
|
|
62
66
|
if (!schema.skipViteConfig) {
|
|
63
67
|
if (uiFramework === 'angular') {
|
|
@@ -105,7 +109,7 @@ getTestBed().initTestEnvironment(
|
|
|
105
109
|
plugins: ['angular()'],
|
|
106
110
|
setupFile: relativeTestSetupPath,
|
|
107
111
|
useEsmExtension: true,
|
|
108
|
-
}, true);
|
|
112
|
+
}, true, { skipPackageJson: schema.skipPackageJson });
|
|
109
113
|
}
|
|
110
114
|
else if (uiFramework === 'react') {
|
|
111
115
|
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
@@ -126,7 +130,7 @@ getTestBed().initTestEnvironment(
|
|
|
126
130
|
plugins: ['react()'],
|
|
127
131
|
coverageProvider: schema.coverageProvider,
|
|
128
132
|
useEsmExtension: true,
|
|
129
|
-
}, true);
|
|
133
|
+
}, true, { skipPackageJson: schema.skipPackageJson });
|
|
130
134
|
}
|
|
131
135
|
else {
|
|
132
136
|
const useVitestConfig = shouldUseVitestConfig(tree, root, uiFramework);
|
|
@@ -135,7 +139,10 @@ getTestBed().initTestEnvironment(
|
|
|
135
139
|
includeVitest: true,
|
|
136
140
|
includeLib: (0, ts_solution_setup_1.getProjectType)(tree, root, projectType) === 'library',
|
|
137
141
|
useEsmExtension: true,
|
|
138
|
-
}, true,
|
|
142
|
+
}, true, {
|
|
143
|
+
vitestFileName: useVitestConfig,
|
|
144
|
+
skipPackageJson: schema.skipPackageJson,
|
|
145
|
+
});
|
|
139
146
|
}
|
|
140
147
|
}
|
|
141
148
|
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
@@ -154,8 +161,10 @@ getTestBed().initTestEnvironment(
|
|
|
154
161
|
}
|
|
155
162
|
const devDependencies = await getCoverageProviderDependency(tree, schema.coverageProvider);
|
|
156
163
|
devDependencies['@types/node'] = versions_1.typesNodeVersion;
|
|
157
|
-
|
|
158
|
-
|
|
164
|
+
if (!schema.skipPackageJson) {
|
|
165
|
+
const installDependenciesTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
|
|
166
|
+
tasks.push(installDependenciesTask);
|
|
167
|
+
}
|
|
159
168
|
// Setup workspace config file (https://vitest.dev/guide/workspace.html)
|
|
160
169
|
if (!isRootProject &&
|
|
161
170
|
!tree.exists(`vitest.workspace.ts`) &&
|
|
@@ -6,6 +6,7 @@ export interface VitestGeneratorSchema {
|
|
|
6
6
|
skipViteConfig?: boolean;
|
|
7
7
|
testTarget?: string;
|
|
8
8
|
skipFormat?: boolean;
|
|
9
|
+
skipPackageJson?: boolean;
|
|
9
10
|
testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
|
|
10
11
|
addPlugin?: boolean;
|
|
11
12
|
runtimeTsconfigFileName?: string;
|
|
@@ -59,6 +59,12 @@
|
|
|
59
59
|
"enum": ["babel", "swc"],
|
|
60
60
|
"default": "babel",
|
|
61
61
|
"description": "The compiler to use"
|
|
62
|
+
},
|
|
63
|
+
"skipPackageJson": {
|
|
64
|
+
"type": "boolean",
|
|
65
|
+
"default": false,
|
|
66
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
67
|
+
"x-priority": "internal"
|
|
62
68
|
}
|
|
63
69
|
},
|
|
64
70
|
"required": ["project"]
|
|
@@ -31,5 +31,9 @@ export interface ViteConfigFileOptions {
|
|
|
31
31
|
port?: number;
|
|
32
32
|
previewPort?: number;
|
|
33
33
|
}
|
|
34
|
-
export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigFileOptions, onlyVitest: boolean,
|
|
34
|
+
export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigFileOptions, onlyVitest: boolean, extraOptions?: {
|
|
35
|
+
projectAlreadyHasViteTargets?: TargetFlags;
|
|
36
|
+
skipPackageJson?: boolean;
|
|
37
|
+
vitestFileName?: boolean;
|
|
38
|
+
}): void;
|
|
35
39
|
//# sourceMappingURL=generator-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/vitest/src/utils/generator-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,IAAI,EAGL,MAAM,YAAY,CAAC;AAMpB,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAC5D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE3D,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;IACnD,gBAAgB,EAAE,IAAI,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC/C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,cAAc,GAAG,MAAM,CAAC;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC3B,WAAW,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CACzC;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,qBAAqB,EAC9B,SAAS,EAAE,OAAO,QAuCnB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe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
33
33
|
}
|
|
34
34
|
(0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
|
|
35
35
|
}
|
|
36
|
-
function createOrEditViteConfig(tree, options, onlyVitest,
|
|
36
|
+
function createOrEditViteConfig(tree, options, onlyVitest, extraOptions = {}) {
|
|
37
37
|
const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
38
38
|
const extension = options.useEsmExtension ? 'mts' : 'ts';
|
|
39
|
-
const viteConfigPath = vitestFileName
|
|
39
|
+
const viteConfigPath = extraOptions.vitestFileName
|
|
40
40
|
? `${projectRoot}/vitest.config.${extension}`
|
|
41
41
|
: `${projectRoot}/vite.config.${extension}`;
|
|
42
42
|
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
@@ -87,7 +87,9 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
87
87
|
if (!isTsSolutionSetup) {
|
|
88
88
|
imports.push(`import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'`, `import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'`);
|
|
89
89
|
plugins.push(`nxViteTsPaths()`, `nxCopyAssetsPlugin(['*.md'])`);
|
|
90
|
-
(
|
|
90
|
+
if (!extraOptions.skipPackageJson) {
|
|
91
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/vite': versions_1.nxVersion });
|
|
92
|
+
}
|
|
91
93
|
}
|
|
92
94
|
if (!onlyVitest && options.includeLib) {
|
|
93
95
|
plugins.push(`dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json')${!isTsSolutionSetup ? ', pathsToAliases: false' : ''} })`);
|
|
@@ -149,11 +151,11 @@ ${options.inSourceTests
|
|
|
149
151
|
// },`;
|
|
150
152
|
const cacheDir = `cacheDir: '${normalizedJoinPaths((0, devkit_1.offsetFromRoot)(projectRoot), 'node_modules', '.vite', projectRoot === '.' ? options.project : projectRoot)}',`;
|
|
151
153
|
if (tree.exists(viteConfigPath)) {
|
|
152
|
-
handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, (0, devkit_1.offsetFromRoot)(projectRoot), projectAlreadyHasViteTargets);
|
|
154
|
+
handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, (0, devkit_1.offsetFromRoot)(projectRoot), extraOptions.projectAlreadyHasViteTargets);
|
|
153
155
|
return;
|
|
154
156
|
}
|
|
155
157
|
// When using vitest.config, use vitest/config import and skip vite-specific options
|
|
156
|
-
const viteConfigContent = vitestFileName
|
|
158
|
+
const viteConfigContent = extraOptions.vitestFileName
|
|
157
159
|
? `import { defineConfig } from 'vitest/config';
|
|
158
160
|
${imports.join(';\n')}${imports.length ? ';' : ''}
|
|
159
161
|
|