@nx/vite 22.1.0-beta.6 → 22.1.0-beta.7
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/generators.json +1 -1
- package/migrations.json +0 -5
- package/package.json +5 -4
- package/src/executors/test/vitest.impl.d.ts +4 -3
- package/src/executors/test/vitest.impl.d.ts.map +1 -1
- package/src/executors/test/vitest.impl.js +8 -52
- package/src/generators/init/init.d.ts.map +1 -1
- package/src/generators/init/init.js +0 -12
- package/src/generators/init/lib/utils.d.ts +0 -1
- package/src/generators/init/lib/utils.d.ts.map +1 -1
- package/src/generators/init/lib/utils.js +0 -10
- package/src/generators/vitest/schema.d.ts +1 -1
- package/src/generators/vitest/schema.json +1 -1
- package/src/generators/vitest/vitest-generator.d.ts +3 -4
- package/src/generators/vitest/vitest-generator.d.ts.map +1 -1
- package/src/generators/vitest/vitest-generator.js +7 -277
- package/src/utils/ignore-vite-temp-files.d.ts.map +1 -1
- package/src/utils/ignore-vite-temp-files.js +1 -8
- 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/generators.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"description": "Convert existing Vite project(s) using `@nx/vite:*` executors to use `@nx/vite/plugin`. Defaults to migrating all projects. Pass '--project' to migrate only one target."
|
|
28
28
|
},
|
|
29
29
|
"vitest": {
|
|
30
|
-
"factory": "./src/generators/vitest/vitest-generator
|
|
30
|
+
"factory": "./src/generators/vitest/vitest-generator",
|
|
31
31
|
"schema": "./src/generators/vitest/schema.json",
|
|
32
32
|
"description": "Generate a vitest configuration."
|
|
33
33
|
}
|
package/migrations.json
CHANGED
|
@@ -10,11 +10,6 @@
|
|
|
10
10
|
"description": "Add gitignore entry for temporary vite config files and remove previous incorrect glob.",
|
|
11
11
|
"implementation": "./src/migrations/update-20-0-4/add-vite-temp-files-to-git-ignore"
|
|
12
12
|
},
|
|
13
|
-
"update-20-3-0": {
|
|
14
|
-
"version": "20.3.0-beta.2",
|
|
15
|
-
"description": "Add gitignore entry for temporary vitest config files.",
|
|
16
|
-
"implementation": "./src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore"
|
|
17
|
-
},
|
|
18
13
|
"update-20-5-0-install-jiti": {
|
|
19
14
|
"version": "20.5.0-beta.2",
|
|
20
15
|
"description": "Install jiti as a devDependency to allow vite to parse TS postcss files.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "22.1.0-beta.
|
|
3
|
+
"version": "22.1.0-beta.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
"migrations": "./migrations.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@nx/devkit": "22.1.0-beta.
|
|
33
|
+
"@nx/devkit": "22.1.0-beta.7",
|
|
34
34
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
35
35
|
"enquirer": "~2.3.6",
|
|
36
|
-
"@nx/js": "22.1.0-beta.
|
|
36
|
+
"@nx/js": "22.1.0-beta.7",
|
|
37
|
+
"@nx/vitest": "22.1.0-beta.7",
|
|
37
38
|
"picomatch": "4.0.2",
|
|
38
39
|
"tsconfig-paths": "^4.1.2",
|
|
39
40
|
"semver": "^7.6.3",
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
"ajv": "^8.0.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"nx": "22.1.0-beta.
|
|
45
|
+
"nx": "22.1.0-beta.7"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { VitestExecutorOptions } from './schema';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use `@nx/vitest:test` instead. This executor will be removed in Nx 23.
|
|
5
|
+
*/
|
|
6
|
+
export declare function vitestExecutor(options: VitestExecutorOptions, context: ExecutorContext): AsyncGenerator<never, void, unknown>;
|
|
6
7
|
export default vitestExecutor;
|
|
7
8
|
//# sourceMappingURL=vitest.impl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/executors/test/vitest.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"vitest.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/executors/test/vitest.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAU,MAAM,YAAY,CAAC;AAGrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,wBAAuB,cAAc,CACnC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,eAAe,wCAWzB;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -2,58 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.vitestExecutor = vitestExecutor;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const devkit_2 = require("@nx/devkit");
|
|
6
|
+
const versions_1 = require("../../utils/versions");
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `@nx/vitest:test` instead. This executor will be removed in Nx 23.
|
|
9
|
+
*/
|
|
10
10
|
async function* vitestExecutor(options, context) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
15
|
-
const { startVitest } = await (0, executor_utils_1.loadVitestDynamicImport)();
|
|
16
|
-
const resolvedOptions = (await (0, utils_1.getOptions)(options, context, projectRoot)) ?? {};
|
|
17
|
-
const watch = resolvedOptions['watch'] === true;
|
|
18
|
-
const nxReporter = new nx_reporter_1.NxReporter(watch);
|
|
19
|
-
if (resolvedOptions['reporters'] === undefined) {
|
|
20
|
-
resolvedOptions['reporters'] = [];
|
|
21
|
-
}
|
|
22
|
-
else if (typeof resolvedOptions['reporters'] === 'string') {
|
|
23
|
-
resolvedOptions['reporters'] = [resolvedOptions['reporters']];
|
|
24
|
-
}
|
|
25
|
-
resolvedOptions['reporters'].push(nxReporter);
|
|
26
|
-
const cliFilters = options.testFiles ?? [];
|
|
27
|
-
const ctx = await startVitest(resolvedOptions['mode'] ?? 'test', cliFilters, resolvedOptions);
|
|
28
|
-
let hasErrors = false;
|
|
29
|
-
const processExit = () => {
|
|
30
|
-
ctx.exit();
|
|
31
|
-
if (hasErrors) {
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
process.exit(0);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
if (watch) {
|
|
39
|
-
process.on('SIGINT', processExit);
|
|
40
|
-
process.on('SIGTERM', processExit);
|
|
41
|
-
process.on('exit', processExit);
|
|
42
|
-
}
|
|
43
|
-
// vitest sets the exitCode in case of exception without notifying reporters
|
|
44
|
-
if (process.exitCode === undefined ||
|
|
45
|
-
(watch && ctx.state.getFiles().length > 0)) {
|
|
46
|
-
for await (const report of nxReporter) {
|
|
47
|
-
// vitest sets the exitCode = 1 when code coverage isn't met
|
|
48
|
-
hasErrors =
|
|
49
|
-
report.hasErrors || (process.exitCode && process.exitCode !== 0);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
hasErrors = process.exitCode !== 0;
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
success: !hasErrors,
|
|
57
|
-
};
|
|
11
|
+
devkit_1.logger.warn(`The '@nx/vite:test' executor is deprecated. Please use '@nx/vitest:test' instead. This executor will be removed in Nx 23.`);
|
|
12
|
+
const { vitestExecutor: actualVitestExecutor } = (0, devkit_2.ensurePackage)('@nx/vitest', versions_1.nxVersion);
|
|
13
|
+
yield* actualVitestExecutor(options, context);
|
|
58
14
|
}
|
|
59
15
|
exports.default = vitestExecutor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAGjB,IAAI,EAEL,MAAM,YAAY,CAAC;AAKpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAI/C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAGjB,IAAI,EAEL,MAAM,YAAY,CAAC;AAKpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAI/C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,QAe9C;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,8BAEpE;AAED,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,mBAAmB,8BA2D5B;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -16,18 +16,6 @@ function updateNxJsonSettings(tree) {
|
|
|
16
16
|
productionFileSet.push('!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json', '!{projectRoot}/src/test-setup.[jt]s');
|
|
17
17
|
nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
|
|
18
18
|
}
|
|
19
|
-
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
|
|
20
|
-
? p === '@nx/vite/plugin'
|
|
21
|
-
: p.plugin === '@nx/vite/plugin');
|
|
22
|
-
if (!hasPlugin) {
|
|
23
|
-
nxJson.targetDefaults ??= {};
|
|
24
|
-
nxJson.targetDefaults['@nx/vite:test'] ??= {};
|
|
25
|
-
nxJson.targetDefaults['@nx/vite:test'].cache ??= true;
|
|
26
|
-
nxJson.targetDefaults['@nx/vite:test'].inputs ??= [
|
|
27
|
-
'default',
|
|
28
|
-
productionFileSet ? '^production' : '^default',
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
19
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
32
20
|
}
|
|
33
21
|
function initGenerator(tree, schema) {
|
|
@@ -2,5 +2,4 @@ import { Tree } from '@nx/devkit';
|
|
|
2
2
|
import { InitGeneratorSchema } from '../schema';
|
|
3
3
|
export declare function checkDependenciesInstalled(host: Tree, schema: InitGeneratorSchema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
4
4
|
export declare function moveToDevDependencies(tree: Tree): () => void;
|
|
5
|
-
export declare function createVitestConfig(tree: Tree): void;
|
|
6
5
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/vite/src/generators/init/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EAGL,MAAM,YAAY,CAAC;AAQpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGhD,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,mBAAmB,mDAqB5B;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,cAgB/C
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/vite/src/generators/init/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EAGL,MAAM,YAAY,CAAC;AAQpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGhD,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,mBAAmB,mDAqB5B;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,cAgB/C"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkDependenciesInstalled = checkDependenciesInstalled;
|
|
4
4
|
exports.moveToDevDependencies = moveToDevDependencies;
|
|
5
|
-
exports.createVitestConfig = createVitestConfig;
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const versions_1 = require("../../../utils/versions");
|
|
8
7
|
const version_utils_1 = require("../../../utils/version-utils");
|
|
@@ -36,12 +35,3 @@ function moveToDevDependencies(tree) {
|
|
|
36
35
|
});
|
|
37
36
|
return wasUpdated ? () => (0, devkit_1.installPackagesTask)(tree) : () => { };
|
|
38
37
|
}
|
|
39
|
-
function createVitestConfig(tree) {
|
|
40
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
41
|
-
const productionFileSet = nxJson.namedInputs?.production;
|
|
42
|
-
if (productionFileSet) {
|
|
43
|
-
productionFileSet.push('!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json');
|
|
44
|
-
nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
|
|
45
|
-
}
|
|
46
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
47
|
-
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { VitestGeneratorSchema } from './schema';
|
|
3
3
|
/**
|
|
4
|
-
* @
|
|
4
|
+
* @deprecated Use `@nx/vitest:configuration` instead. This generator will be removed in Nx 23.
|
|
5
5
|
*/
|
|
6
|
-
export declare function vitestGenerator(tree: Tree, schema: VitestGeneratorSchema, hasPlugin?: boolean): Promise<GeneratorCallback>;
|
|
7
|
-
export declare function vitestGeneratorInternal(tree: Tree, schema: VitestGeneratorSchema, hasPlugin?: boolean): Promise<GeneratorCallback>;
|
|
6
|
+
export declare function vitestGenerator(tree: Tree, schema: VitestGeneratorSchema, hasPlugin?: boolean): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
8
7
|
export default vitestGenerator;
|
|
9
8
|
//# sourceMappingURL=vitest-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest-generator.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/generators/vitest/vitest-generator.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"vitest-generator.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/generators/vitest/vitest-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAU,MAAM,YAAY,CAAC;AAG1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,mDAYlB;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -1,285 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.vitestGenerator = vitestGenerator;
|
|
4
|
-
exports.vitestGeneratorInternal = vitestGeneratorInternal;
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
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");
|
|
5
|
+
const devkit_2 = require("@nx/devkit");
|
|
6
|
+
const versions_1 = require("../../utils/versions");
|
|
16
7
|
/**
|
|
17
|
-
* @
|
|
8
|
+
* @deprecated Use `@nx/vitest:configuration` instead. This generator will be removed in Nx 23.
|
|
18
9
|
*/
|
|
19
|
-
function vitestGenerator(tree, schema, hasPlugin = false) {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
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
|
-
const tasks = [];
|
|
27
|
-
const { root, projectType: _projectType } = (0, devkit_1.readProjectConfiguration)(tree, schema.project);
|
|
28
|
-
const projectType = schema.projectType ?? _projectType;
|
|
29
|
-
const uiFramework = schema.uiFramework ?? (await (0, detect_ui_framework_1.detectUiFramework)(schema.project));
|
|
30
|
-
const isRootProject = root === '.';
|
|
31
|
-
tasks.push(await (0, js_1.initGenerator)(tree, { ...schema, skipFormat: true }));
|
|
32
|
-
const viteVersion = (0, devkit_1.getDependencyVersionFromPackageJson)(tree, 'vite') ?? '7.0.0';
|
|
33
|
-
const useViteV5 = (0, semver_1.major)((0, semver_1.coerce)(viteVersion)) === 5;
|
|
34
|
-
const useViteV6 = (0, semver_1.major)((0, semver_1.coerce)(viteVersion)) === 6;
|
|
35
|
-
const initTask = await (0, init_1.default)(tree, {
|
|
36
|
-
projectRoot: root,
|
|
37
|
-
skipFormat: true,
|
|
38
|
-
addPlugin: schema.addPlugin,
|
|
39
|
-
useViteV5,
|
|
40
|
-
useViteV6,
|
|
41
|
-
});
|
|
42
|
-
tasks.push(initTask);
|
|
43
|
-
tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, { ...schema, uiFramework }));
|
|
44
|
-
(0, generator_utils_1.addOrChangeTestTarget)(tree, schema, hasPlugin);
|
|
45
|
-
if (!schema.skipViteConfig) {
|
|
46
|
-
if (uiFramework === 'angular') {
|
|
47
|
-
const relativeTestSetupPath = (0, devkit_1.joinPathFragments)('src', 'test-setup.ts');
|
|
48
|
-
const setupFile = (0, devkit_1.joinPathFragments)(root, relativeTestSetupPath);
|
|
49
|
-
if (!tree.exists(setupFile)) {
|
|
50
|
-
if (isAngularV20(tree)) {
|
|
51
|
-
tree.write(setupFile, `import '@angular/compiler';
|
|
52
|
-
import '@analogjs/vitest-angular/setup-zone';
|
|
53
|
-
|
|
54
|
-
import {
|
|
55
|
-
BrowserTestingModule,
|
|
56
|
-
platformBrowserTesting,
|
|
57
|
-
} from '@angular/platform-browser/testing';
|
|
58
|
-
import { getTestBed } from '@angular/core/testing';
|
|
59
|
-
|
|
60
|
-
getTestBed().initTestEnvironment(
|
|
61
|
-
BrowserTestingModule,
|
|
62
|
-
platformBrowserTesting()
|
|
63
|
-
);
|
|
64
|
-
`);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
tree.write(setupFile, `import '@analogjs/vitest-angular/setup-zone';
|
|
68
|
-
|
|
69
|
-
import {
|
|
70
|
-
BrowserDynamicTestingModule,
|
|
71
|
-
platformBrowserDynamicTesting,
|
|
72
|
-
} from '@angular/platform-browser-dynamic/testing';
|
|
73
|
-
import { getTestBed } from '@angular/core/testing';
|
|
74
|
-
|
|
75
|
-
getTestBed().initTestEnvironment(
|
|
76
|
-
BrowserDynamicTestingModule,
|
|
77
|
-
platformBrowserDynamicTesting()
|
|
78
|
-
);
|
|
79
|
-
`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
83
|
-
project: schema.project,
|
|
84
|
-
includeLib: false,
|
|
85
|
-
includeVitest: true,
|
|
86
|
-
inSourceTests: false,
|
|
87
|
-
imports: [`import angular from '@analogjs/vite-plugin-angular'`],
|
|
88
|
-
plugins: ['angular()'],
|
|
89
|
-
setupFile: relativeTestSetupPath,
|
|
90
|
-
useEsmExtension: true,
|
|
91
|
-
}, true);
|
|
92
|
-
}
|
|
93
|
-
else if (uiFramework === 'react') {
|
|
94
|
-
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
95
|
-
project: schema.project,
|
|
96
|
-
includeLib: (0, ts_solution_setup_1.getProjectType)(tree, root, projectType) === 'library',
|
|
97
|
-
includeVitest: true,
|
|
98
|
-
inSourceTests: schema.inSourceTests,
|
|
99
|
-
rollupOptionsExternal: [
|
|
100
|
-
"'react'",
|
|
101
|
-
"'react-dom'",
|
|
102
|
-
"'react/jsx-runtime'",
|
|
103
|
-
],
|
|
104
|
-
imports: [
|
|
105
|
-
schema.compiler === 'swc'
|
|
106
|
-
? `import react from '@vitejs/plugin-react-swc'`
|
|
107
|
-
: `import react from '@vitejs/plugin-react'`,
|
|
108
|
-
],
|
|
109
|
-
plugins: ['react()'],
|
|
110
|
-
coverageProvider: schema.coverageProvider,
|
|
111
|
-
}, true);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
115
|
-
...schema,
|
|
116
|
-
includeVitest: true,
|
|
117
|
-
includeLib: (0, ts_solution_setup_1.getProjectType)(tree, root, projectType) === 'library',
|
|
118
|
-
}, true);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
122
|
-
createFiles(tree, schema, root, isTsSolutionSetup);
|
|
123
|
-
updateTsConfig(tree, schema, root, projectType);
|
|
124
|
-
if (isTsSolutionSetup) {
|
|
125
|
-
// in the TS solution setup, the test target depends on the build outputs
|
|
126
|
-
// so we need to setup the task pipeline accordingly
|
|
127
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
128
|
-
const testTarget = schema.testTarget ?? 'test';
|
|
129
|
-
nxJson.targetDefaults ??= {};
|
|
130
|
-
nxJson.targetDefaults[testTarget] ??= {};
|
|
131
|
-
nxJson.targetDefaults[testTarget].dependsOn ??= [];
|
|
132
|
-
nxJson.targetDefaults[testTarget].dependsOn = Array.from(new Set([...nxJson.targetDefaults[testTarget].dependsOn, '^build']));
|
|
133
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
134
|
-
}
|
|
135
|
-
const devDependencies = await getCoverageProviderDependency(tree, schema.coverageProvider);
|
|
136
|
-
devDependencies['@types/node'] = versions_1.typesNodeVersion;
|
|
137
|
-
const installDependenciesTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
|
|
138
|
-
tasks.push(installDependenciesTask);
|
|
139
|
-
// Setup workspace config file (https://vitest.dev/guide/workspace.html)
|
|
140
|
-
if (!isRootProject &&
|
|
141
|
-
!tree.exists(`vitest.workspace.ts`) &&
|
|
142
|
-
!tree.exists(`vitest.workspace.js`) &&
|
|
143
|
-
!tree.exists(`vitest.workspace.json`) &&
|
|
144
|
-
!tree.exists(`vitest.projects.ts`) &&
|
|
145
|
-
!tree.exists(`vitest.projects.js`) &&
|
|
146
|
-
!tree.exists(`vitest.projects.json`)) {
|
|
147
|
-
tree.write('vitest.workspace.ts', `export default ['**/vite.config.{mjs,js,ts,mts}', '**/vitest.config.{mjs,js,ts,mts}'];`);
|
|
148
|
-
}
|
|
149
|
-
if (!schema.skipFormat) {
|
|
150
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
151
|
-
}
|
|
152
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
153
|
-
}
|
|
154
|
-
function updateTsConfig(tree, options, projectRoot, projectType) {
|
|
155
|
-
const setupFile = tryFindSetupFile(tree, projectRoot);
|
|
156
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.spec.json'))) {
|
|
157
|
-
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.spec.json'), (json) => {
|
|
158
|
-
if (!json.compilerOptions?.types?.includes('vitest')) {
|
|
159
|
-
if (json.compilerOptions?.types) {
|
|
160
|
-
json.compilerOptions.types.push('vitest');
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
json.compilerOptions ??= {};
|
|
164
|
-
json.compilerOptions.types = ['vitest'];
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (setupFile) {
|
|
168
|
-
json.files = [...(json.files ?? []), setupFile];
|
|
169
|
-
}
|
|
170
|
-
return json;
|
|
171
|
-
});
|
|
172
|
-
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json'), (json) => {
|
|
173
|
-
if (json.references &&
|
|
174
|
-
!json.references.some((r) => r.path === './tsconfig.spec.json')) {
|
|
175
|
-
json.references.push({
|
|
176
|
-
path: './tsconfig.spec.json',
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return json;
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json'), (json) => {
|
|
184
|
-
if (!json.compilerOptions?.types?.includes('vitest')) {
|
|
185
|
-
if (json.compilerOptions?.types) {
|
|
186
|
-
json.compilerOptions.types.push('vitest');
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
json.compilerOptions ??= {};
|
|
190
|
-
json.compilerOptions.types = ['vitest'];
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return json;
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, (0, ts_solution_setup_1.getProjectType)(tree, projectRoot, projectType) === 'application'
|
|
197
|
-
? 'tsconfig.app.json'
|
|
198
|
-
: 'tsconfig.lib.json');
|
|
199
|
-
if (options.runtimeTsconfigFileName) {
|
|
200
|
-
runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, options.runtimeTsconfigFileName);
|
|
201
|
-
if (!tree.exists(runtimeTsconfigPath)) {
|
|
202
|
-
throw new Error(`Cannot find the specified runtimeTsConfigFileName ("${options.runtimeTsconfigFileName}") at the project root "${projectRoot}".`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (tree.exists(runtimeTsconfigPath)) {
|
|
206
|
-
(0, devkit_1.updateJson)(tree, runtimeTsconfigPath, (json) => {
|
|
207
|
-
if (options.inSourceTests) {
|
|
208
|
-
(json.compilerOptions.types ??= []).push('vitest/importMeta');
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
const uniqueExclude = new Set([
|
|
212
|
-
...(json.exclude || []),
|
|
213
|
-
'vite.config.ts',
|
|
214
|
-
'vite.config.mts',
|
|
215
|
-
'vitest.config.ts',
|
|
216
|
-
'vitest.config.mts',
|
|
217
|
-
'src/**/*.test.ts',
|
|
218
|
-
'src/**/*.spec.ts',
|
|
219
|
-
'src/**/*.test.tsx',
|
|
220
|
-
'src/**/*.spec.tsx',
|
|
221
|
-
'src/**/*.test.js',
|
|
222
|
-
'src/**/*.spec.js',
|
|
223
|
-
'src/**/*.test.jsx',
|
|
224
|
-
'src/**/*.spec.jsx',
|
|
225
|
-
]);
|
|
226
|
-
json.exclude = [...uniqueExclude];
|
|
227
|
-
}
|
|
228
|
-
if (setupFile) {
|
|
229
|
-
json.exclude = [...(json.exclude ?? []), setupFile];
|
|
230
|
-
}
|
|
231
|
-
return json;
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
devkit_1.logger.warn(`Couldn't find a runtime tsconfig file at ${runtimeTsconfigPath} to exclude the test files from. ` +
|
|
236
|
-
`If you're using a different filename for your runtime tsconfig, please provide it with the '--runtimeTsconfigFileName' flag.`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
function createFiles(tree, options, projectRoot, isTsSolutionSetup) {
|
|
240
|
-
const rootOffset = (0, devkit_1.offsetFromRoot)(projectRoot);
|
|
241
|
-
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectRoot, {
|
|
242
|
-
tmpl: '',
|
|
243
|
-
...options,
|
|
244
|
-
projectRoot,
|
|
245
|
-
extendedConfig: isTsSolutionSetup
|
|
246
|
-
? `${rootOffset}tsconfig.base.json`
|
|
247
|
-
: './tsconfig.json',
|
|
248
|
-
outDir: isTsSolutionSetup
|
|
249
|
-
? `./out-tsc/vitest`
|
|
250
|
-
: `${rootOffset}dist/out-tsc`,
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
async function getCoverageProviderDependency(tree, coverageProvider) {
|
|
254
|
-
const { vitestCoverageV8, vitestCoverageIstanbul } = await (0, version_utils_1.getVitestDependenciesVersionsToInstall)(tree);
|
|
255
|
-
switch (coverageProvider) {
|
|
256
|
-
case 'v8':
|
|
257
|
-
return {
|
|
258
|
-
'@vitest/coverage-v8': vitestCoverageV8,
|
|
259
|
-
};
|
|
260
|
-
case 'istanbul':
|
|
261
|
-
return {
|
|
262
|
-
'@vitest/coverage-istanbul': vitestCoverageIstanbul,
|
|
263
|
-
};
|
|
264
|
-
default:
|
|
265
|
-
return {
|
|
266
|
-
'@vitest/coverage-v8': vitestCoverageV8,
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
function tryFindSetupFile(tree, projectRoot) {
|
|
271
|
-
const setupFile = (0, devkit_1.joinPathFragments)('src', 'test-setup.ts');
|
|
272
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, setupFile))) {
|
|
273
|
-
return setupFile;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function isAngularV20(tree) {
|
|
277
|
-
const angularVersion = (0, devkit_1.getDependencyVersionFromPackageJson)(tree, '@angular/core');
|
|
278
|
-
if (!angularVersion) {
|
|
279
|
-
// assume the latest version will be installed, which will be 20 or later
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
const cleanedAngularVersion = (0, semver_1.clean)(angularVersion) ?? (0, semver_1.coerce)(angularVersion).version;
|
|
283
|
-
return (0, semver_1.major)(cleanedAngularVersion) >= 20;
|
|
10
|
+
async function vitestGenerator(tree, schema, hasPlugin = false) {
|
|
11
|
+
devkit_1.logger.warn(`The '@nx/vite:vitest' generator is deprecated. Please use '@nx/vitest:configuration' instead. This generator will be removed in Nx 23.`);
|
|
12
|
+
const { configurationGenerator } = (0, devkit_2.ensurePackage)('@nx/vitest', versions_1.nxVersion);
|
|
13
|
+
return await configurationGenerator(tree, schema, hasPlugin);
|
|
284
14
|
}
|
|
285
15
|
exports.default = vitestGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ignore-vite-temp-files.d.ts","sourceRoot":"","sources":["../../../../../packages/vite/src/utils/ignore-vite-temp-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAG9E,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,IAAI,EACV,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,GAC/B,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"ignore-vite-temp-files.d.ts","sourceRoot":"","sources":["../../../../../packages/vite/src/utils/ignore-vite-temp-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAG9E,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,IAAI,EACV,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,GAC/B,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAW5D;AAiCD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAYrD"}
|
|
@@ -17,10 +17,6 @@ function addViteTempFilesToGitIgnore(tree) {
|
|
|
17
17
|
gitIgnoreContents = (0, devkit_1.stripIndents) `${gitIgnoreContents}
|
|
18
18
|
vite.config.*.timestamp*`;
|
|
19
19
|
}
|
|
20
|
-
if (!/^vitest\.config\.\*\.timestamp\*$/m.test(gitIgnoreContents)) {
|
|
21
|
-
gitIgnoreContents = (0, devkit_1.stripIndents) `${gitIgnoreContents}
|
|
22
|
-
vitest.config.*.timestamp*`;
|
|
23
|
-
}
|
|
24
20
|
tree.write('.gitignore', gitIgnoreContents);
|
|
25
21
|
}
|
|
26
22
|
async function ignoreViteTempFilesInEslintConfig(tree, projectRoot) {
|
|
@@ -42,10 +38,7 @@ async function ignoreViteTempFilesInEslintConfig(tree, projectRoot) {
|
|
|
42
38
|
}
|
|
43
39
|
// for flat config, we update the root config file
|
|
44
40
|
const directory = isUsingFlatConfig ? '' : projectRoot ?? '';
|
|
45
|
-
addIgnoresToLintConfig(tree, directory, [
|
|
46
|
-
'**/vite.config.*.timestamp*',
|
|
47
|
-
'**/vitest.config.*.timestamp*',
|
|
48
|
-
]);
|
|
41
|
+
addIgnoresToLintConfig(tree, directory, ['**/vite.config.*.timestamp*']);
|
|
49
42
|
}
|
|
50
43
|
function isEslintInstalled(tree) {
|
|
51
44
|
try {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add-vitest-temp-files-to-git-ignore.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/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,2BAA2B,CAAC,IAAI,EAAE,IAAI,QAsB7D"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = addViteTempFilesToGitIgnore;
|
|
4
|
-
const ignore_vite_temp_files_1 = require("../../utils/ignore-vite-temp-files");
|
|
5
|
-
function addViteTempFilesToGitIgnore(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_vite_temp_files_1.addViteTempFilesToGitIgnore)(tree);
|
|
17
|
-
}
|