@nx/vite 17.0.4 → 17.0.6
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/LICENSE +1 -1
- package/README.md +4 -9
- package/generators.json +3 -3
- package/migrations.json +0 -90
- package/package.json +7 -9
- package/plugins/nx-tsconfig-paths.plugin.js +5 -9
- package/plugins/nx-tsconfig-paths.plugin.js.map +1 -1
- package/plugins/rollup-replace-files.plugin.d.ts +3 -3
- package/plugins/rollup-replace-files.plugin.js +2 -2
- package/plugins/rollup-replace-files.plugin.js.map +1 -1
- package/src/executors/build/build.impl.d.ts +1 -5
- package/src/executors/build/build.impl.js +21 -90
- package/src/executors/build/build.impl.js.map +1 -1
- package/src/executors/build/schema.d.ts +18 -5
- package/src/executors/build/schema.json +106 -4
- package/src/executors/dev-server/dev-server.impl.js +9 -74
- package/src/executors/dev-server/dev-server.impl.js.map +1 -1
- package/src/executors/dev-server/schema.d.ts +10 -0
- package/src/executors/dev-server/schema.json +63 -0
- package/src/executors/preview-server/preview-server.impl.d.ts +1 -1
- package/src/executors/preview-server/preview-server.impl.js +15 -79
- package/src/executors/preview-server/preview-server.impl.js.map +1 -1
- package/src/executors/preview-server/schema.d.ts +7 -0
- package/src/executors/preview-server/schema.json +51 -1
- package/src/executors/test/schema.d.ts +8 -3
- package/src/executors/test/schema.json +43 -11
- package/src/executors/test/vitest.impl.js +112 -20
- package/src/executors/test/vitest.impl.js.map +1 -1
- package/src/generators/configuration/configuration.d.ts +1 -2
- package/src/generators/configuration/configuration.js +87 -49
- package/src/generators/configuration/configuration.js.map +1 -1
- package/src/generators/configuration/schema.d.ts +3 -1
- package/src/generators/configuration/schema.json +12 -0
- package/src/generators/init/init.d.ts +3 -4
- package/src/generators/init/init.js +67 -50
- package/src/generators/init/init.js.map +1 -1
- package/src/generators/init/schema.d.ts +5 -5
- package/src/generators/init/schema.json +20 -17
- package/src/generators/vitest/files/tsconfig.spec.json__tmpl__ +1 -2
- package/src/generators/vitest/schema.d.ts +1 -2
- package/src/generators/vitest/schema.json +2 -2
- package/src/generators/vitest/vitest-generator.d.ts +1 -2
- package/src/generators/vitest/vitest-generator.js +10 -34
- package/src/generators/vitest/vitest-generator.js.map +1 -1
- package/src/migrations/update-15-3-1/update-vite-tsconfig-paths.js.map +1 -1
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js +17 -3
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js.map +1 -1
- package/src/utils/executor-utils.d.ts +0 -2
- package/src/utils/executor-utils.js +7 -22
- package/src/utils/executor-utils.js.map +1 -1
- package/src/utils/generator-utils.d.ts +12 -10
- package/src/utils/generator-utils.js +213 -134
- package/src/utils/generator-utils.js.map +1 -1
- package/src/utils/options-utils.d.ts +19 -3
- package/src/utils/options-utils.js +68 -25
- package/src/utils/options-utils.js.map +1 -1
- package/src/utils/test-files/react-lib-non-buildable-jest.json +4 -1
- package/src/utils/test-files/react-lib-non-buildable-vitest.json +4 -1
- package/src/utils/test-files/react-mixed-project.config.json +6 -1
- package/src/utils/test-files/react-project.config.json +85 -0
- package/src/utils/test-files/react-vite-project.config.json +4 -1
- package/src/utils/test-files/unknown-project.config.json +4 -1
- package/src/utils/test-files/web-project.config.json +72 -0
- package/src/utils/test-utils.d.ts +1 -1
- package/src/utils/test-utils.js +18 -10
- package/src/utils/test-utils.js.map +1 -1
- package/src/utils/versions.d.ts +9 -7
- package/src/utils/versions.js +15 -7
- package/src/utils/versions.js.map +1 -1
- package/src/utils/vite-config-edit-utils.js +1 -1
- package/src/utils/vite-config-edit-utils.js.map +1 -1
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -21
- package/plugin.js.map +0 -1
- package/src/executors/test/lib/nx-reporter.d.ts +0 -14
- package/src/executors/test/lib/nx-reporter.js +0 -40
- package/src/executors/test/lib/nx-reporter.js.map +0 -1
- package/src/executors/test/lib/utils.d.ts +0 -4
- package/src/executors/test/lib/utils.js +0 -77
- package/src/executors/test/lib/utils.js.map +0 -1
- package/src/generators/configuration/lib/convert-non-vite.d.ts +0 -5
- package/src/generators/configuration/lib/convert-non-vite.js +0 -62
- package/src/generators/configuration/lib/convert-non-vite.js.map +0 -1
- package/src/generators/init/lib/utils.d.ts +0 -6
- package/src/generators/init/lib/utils.js +0 -80
- package/src/generators/init/lib/utils.js.map +0 -1
- package/src/migrations/update-17-1-0/move-target-defaults.d.ts +0 -2
- package/src/migrations/update-17-1-0/move-target-defaults.js +0 -77
- package/src/migrations/update-17-1-0/move-target-defaults.js.map +0 -1
- package/src/migrations/update-17-2-0/lib/add-file-replacements.d.ts +0 -2
- package/src/migrations/update-17-2-0/lib/add-file-replacements.js +0 -67
- package/src/migrations/update-17-2-0/lib/add-file-replacements.js.map +0 -1
- package/src/migrations/update-17-2-0/lib/edit-build-config.d.ts +0 -2
- package/src/migrations/update-17-2-0/lib/edit-build-config.js +0 -121
- package/src/migrations/update-17-2-0/lib/edit-build-config.js.map +0 -1
- package/src/migrations/update-17-2-0/lib/edit-test-config.d.ts +0 -2
- package/src/migrations/update-17-2-0/lib/edit-test-config.js +0 -83
- package/src/migrations/update-17-2-0/lib/edit-test-config.js.map +0 -1
- package/src/migrations/update-17-2-0/update-vite-config.d.ts +0 -5
- package/src/migrations/update-17-2-0/update-vite-config.js +0 -68
- package/src/migrations/update-17-2-0/update-vite-config.js.map +0 -1
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.d.ts +0 -3
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.js +0 -117
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.js.map +0 -1
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.d.ts +0 -2
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.js +0 -45
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.js.map +0 -1
- package/src/plugins/plugin.d.ts +0 -10
- package/src/plugins/plugin.js +0 -226
- package/src/plugins/plugin.js.map +0 -1
- package/src/utils/ensure-dependencies.d.ts +0 -8
- package/src/utils/ensure-dependencies.js +0 -34
- package/src/utils/ensure-dependencies.js.map +0 -1
- package/src/utils/find-vite-config.d.ts +0 -3
- package/src/utils/find-vite-config.js +0 -46
- package/src/utils/find-vite-config.js.map +0 -1
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export interface VitestExecutorOptions {
|
|
2
|
-
|
|
2
|
+
config?: string;
|
|
3
|
+
passWithNoTests?: boolean;
|
|
4
|
+
testNamePattern?: string;
|
|
5
|
+
mode?: 'test' | 'benchmark' | 'typecheck';
|
|
6
|
+
reporters?: string[];
|
|
7
|
+
watch?: boolean;
|
|
8
|
+
update?: boolean;
|
|
3
9
|
reportsDirectory?: string;
|
|
10
|
+
coverage?: boolean;
|
|
4
11
|
testFiles?: string[];
|
|
5
|
-
watch?: boolean;
|
|
6
|
-
mode?: string;
|
|
7
12
|
}
|
|
@@ -1,34 +1,66 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
3
|
"version": 2,
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"title": "Vitest executor",
|
|
6
6
|
"description": "Test using Vitest.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"properties": {
|
|
9
|
-
"
|
|
9
|
+
"config": {
|
|
10
10
|
"type": "string",
|
|
11
11
|
"description": "The path to the local vitest config",
|
|
12
12
|
"x-completion-type": "file",
|
|
13
|
-
"x-completion-glob": "@(vitest|vite).config@(.js|.ts)"
|
|
14
|
-
"aliases": ["config"]
|
|
13
|
+
"x-completion-glob": "@(vitest|vite).config@(.js|.ts)"
|
|
15
14
|
},
|
|
16
|
-
"
|
|
15
|
+
"passWithNoTests": {
|
|
16
|
+
"type": "boolean",
|
|
17
|
+
"default": true,
|
|
18
|
+
"description": "Pass the test even if no tests are found"
|
|
19
|
+
},
|
|
20
|
+
"testNamePattern": {
|
|
17
21
|
"type": "string",
|
|
18
|
-
"description": "
|
|
22
|
+
"description": "Run tests with full names matching the pattern"
|
|
19
23
|
},
|
|
20
24
|
"mode": {
|
|
21
25
|
"type": "string",
|
|
22
|
-
"
|
|
26
|
+
"enum": ["test", "benchmark", "typecheck"],
|
|
27
|
+
"default": "test",
|
|
28
|
+
"description": "The mode that vitest will run on",
|
|
29
|
+
"x-priority": "important"
|
|
30
|
+
},
|
|
31
|
+
"watch": {
|
|
32
|
+
"type": "boolean",
|
|
33
|
+
"default": false,
|
|
34
|
+
"description": "Enable watch mode"
|
|
35
|
+
},
|
|
36
|
+
"reporters": {
|
|
37
|
+
"type": "array",
|
|
38
|
+
"items": {
|
|
39
|
+
"type": "string"
|
|
40
|
+
},
|
|
41
|
+
"description": "An array of reporters to pass to vitest"
|
|
42
|
+
},
|
|
43
|
+
"update": {
|
|
44
|
+
"type": "boolean",
|
|
45
|
+
"default": false,
|
|
46
|
+
"alias": "u",
|
|
47
|
+
"description": "Update snapshots",
|
|
48
|
+
"x-priority": "important"
|
|
49
|
+
},
|
|
50
|
+
"coverage": {
|
|
51
|
+
"type": "boolean",
|
|
52
|
+
"default": false,
|
|
53
|
+
"description": "Enable coverage report",
|
|
54
|
+
"x-priority": "important"
|
|
55
|
+
},
|
|
56
|
+
"reportsDirectory": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"description": "Directory to write coverage report to."
|
|
23
59
|
},
|
|
24
60
|
"testFiles": {
|
|
25
61
|
"aliases": ["testFile"],
|
|
26
62
|
"type": "array",
|
|
27
63
|
"items": { "type": "string" }
|
|
28
|
-
},
|
|
29
|
-
"watch": {
|
|
30
|
-
"description": "Watch files for changes and rerun tests related to changed files.",
|
|
31
|
-
"type": "boolean"
|
|
32
64
|
}
|
|
33
65
|
},
|
|
34
66
|
"required": [],
|
|
@@ -13,33 +13,52 @@ _export(exports, {
|
|
|
13
13
|
return _default;
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
+
const _extends = require("@swc/helpers/_/_extends");
|
|
16
17
|
const _devkit = require("@nx/devkit");
|
|
17
18
|
const _path = require("path");
|
|
19
|
+
const _fs = require("fs");
|
|
18
20
|
const _internal = require("@nx/js/src/internal");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
let NxReporter = class NxReporter {
|
|
22
|
+
async *[Symbol.asyncIterator]() {
|
|
23
|
+
do {
|
|
24
|
+
const hasErrors = await this.deferred.promise;
|
|
25
|
+
yield {
|
|
26
|
+
hasErrors
|
|
27
|
+
};
|
|
28
|
+
this.setupDeferred();
|
|
29
|
+
}while (this.watch)
|
|
30
|
+
}
|
|
31
|
+
setupDeferred() {
|
|
32
|
+
let resolve;
|
|
33
|
+
this.deferred = {
|
|
34
|
+
promise: new Promise((res)=>{
|
|
35
|
+
resolve = res;
|
|
36
|
+
}),
|
|
37
|
+
resolve
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
onFinished(files, errors) {
|
|
41
|
+
const hasErrors = files.some((f)=>{
|
|
42
|
+
var _f_result;
|
|
43
|
+
return ((_f_result = f.result) == null ? void 0 : _f_result.state) === 'fail';
|
|
44
|
+
}) || (errors == null ? void 0 : errors.length) > 0;
|
|
45
|
+
this.deferred.resolve(hasErrors);
|
|
46
|
+
}
|
|
47
|
+
constructor(watch){
|
|
48
|
+
this.watch = watch;
|
|
49
|
+
this.setupDeferred();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
22
52
|
async function* vitestExecutor(options, context) {
|
|
23
53
|
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
24
54
|
(0, _internal.registerTsConfigPaths)((0, _path.resolve)(_devkit.workspaceRoot, projectRoot, 'tsconfig.json'));
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const resolvedOptions = (_ref = await (0, _utils.getOptions)(options, context, projectRoot)) != null ? _ref : {};
|
|
30
|
-
const nxReporter = new _nxreporter.NxReporter(resolvedOptions['watch']);
|
|
31
|
-
if (resolvedOptions['reporters'] === undefined) {
|
|
32
|
-
resolvedOptions['reporters'] = [];
|
|
33
|
-
} else if (typeof resolvedOptions['reporters'] === 'string') {
|
|
34
|
-
resolvedOptions['reporters'] = [
|
|
35
|
-
resolvedOptions['reporters']
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
resolvedOptions['reporters'].push(nxReporter);
|
|
55
|
+
const { startVitest } = await Function('return import("vitest/node")')();
|
|
56
|
+
const nxReporter = new NxReporter(options.watch);
|
|
57
|
+
const settings = await getSettings(options, context, projectRoot);
|
|
58
|
+
settings.reporters.push(nxReporter);
|
|
39
59
|
var _options_testFiles;
|
|
40
60
|
const cliFilters = (_options_testFiles = options.testFiles) != null ? _options_testFiles : [];
|
|
41
|
-
|
|
42
|
-
const ctx = await startVitest((_resolvedOptions_mode = resolvedOptions['mode']) != null ? _resolvedOptions_mode : 'test', cliFilters, resolvedOptions);
|
|
61
|
+
const ctx = await startVitest(options.mode, cliFilters, settings);
|
|
43
62
|
let hasErrors = false;
|
|
44
63
|
const processExit = ()=>{
|
|
45
64
|
ctx.exit();
|
|
@@ -49,7 +68,7 @@ async function* vitestExecutor(options, context) {
|
|
|
49
68
|
process.exit(0);
|
|
50
69
|
}
|
|
51
70
|
};
|
|
52
|
-
if (
|
|
71
|
+
if (options.watch) {
|
|
53
72
|
process.on('SIGINT', processExit);
|
|
54
73
|
process.on('SIGTERM', processExit);
|
|
55
74
|
process.on('exit', processExit);
|
|
@@ -62,6 +81,79 @@ async function* vitestExecutor(options, context) {
|
|
|
62
81
|
success: !hasErrors
|
|
63
82
|
};
|
|
64
83
|
}
|
|
84
|
+
async function getSettings(options, context, projectRoot) {
|
|
85
|
+
var _packageJson_dependencies, _packageJson_devDependencies, _resolved_config, _resolved_config_test, _resolved_config1, _resolved_config_test1, _resolved_config2;
|
|
86
|
+
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
87
|
+
const { loadConfigFromFile } = await Function('return import("vite")')();
|
|
88
|
+
const packageJsonPath = (0, _path.join)(_devkit.workspaceRoot, 'package.json');
|
|
89
|
+
const packageJson = (0, _fs.existsSync)(packageJsonPath) ? (0, _devkit.readJsonFile)(packageJsonPath) : undefined;
|
|
90
|
+
let provider = 'v8';
|
|
91
|
+
if ((packageJson == null ? void 0 : (_packageJson_dependencies = packageJson.dependencies) == null ? void 0 : _packageJson_dependencies['@vitest/coverage-c8']) || (packageJson == null ? void 0 : (_packageJson_devDependencies = packageJson.devDependencies) == null ? void 0 : _packageJson_devDependencies['@vitest/coverage-c8'])) {
|
|
92
|
+
provider = 'c8';
|
|
93
|
+
}
|
|
94
|
+
const offset = (0, _path.relative)(_devkit.workspaceRoot, context.cwd);
|
|
95
|
+
// if reportsDirectory is not provided vitest will remove all files in the project root
|
|
96
|
+
// when coverage is enabled in the vite.config.ts
|
|
97
|
+
const coverage = options.reportsDirectory ? {
|
|
98
|
+
enabled: options.coverage,
|
|
99
|
+
reportsDirectory: options.reportsDirectory,
|
|
100
|
+
provider
|
|
101
|
+
} : {};
|
|
102
|
+
const viteConfigPath = options.config ? options.config // config is expected to be from the workspace root
|
|
103
|
+
: findViteConfig((0, _devkit.joinPathFragments)(context.root, projectRoot));
|
|
104
|
+
if (!viteConfigPath) {
|
|
105
|
+
throw new Error((0, _devkit.stripIndents)`
|
|
106
|
+
Unable to load test config from config file ${viteConfigPath}.
|
|
107
|
+
|
|
108
|
+
Please make sure that vitest is configured correctly,
|
|
109
|
+
or use the @nx/vite:vitest generator to configure it for you.
|
|
110
|
+
You can read more here: https://nx.dev/nx-api/vite/generators/vitest
|
|
111
|
+
`);
|
|
112
|
+
}
|
|
113
|
+
const resolvedProjectRoot = (0, _path.resolve)(_devkit.workspaceRoot, projectRoot);
|
|
114
|
+
const resolvedViteConfigPath = (0, _path.resolve)(_devkit.workspaceRoot, projectRoot, (0, _path.relative)(resolvedProjectRoot, viteConfigPath));
|
|
115
|
+
const resolved = await loadConfigFromFile({
|
|
116
|
+
mode: options.mode,
|
|
117
|
+
command: 'serve'
|
|
118
|
+
}, resolvedViteConfigPath, resolvedProjectRoot);
|
|
119
|
+
if (!viteConfigPath || !(resolved == null ? void 0 : (_resolved_config = resolved.config) == null ? void 0 : _resolved_config['test'])) {
|
|
120
|
+
var _resolved_path;
|
|
121
|
+
_devkit.logger.warn((0, _devkit.stripIndents)`Unable to load test config from config file ${(_resolved_path = resolved == null ? void 0 : resolved.path) != null ? _resolved_path : viteConfigPath}
|
|
122
|
+
Some settings may not be applied as expected.
|
|
123
|
+
You can manually set the config in the project, ${context.projectName}, configuration.
|
|
124
|
+
`);
|
|
125
|
+
}
|
|
126
|
+
var _options_reporters, _ref;
|
|
127
|
+
const settings = _extends._({}, options, {
|
|
128
|
+
// when running nx from the project root, the root will get appended to the cwd.
|
|
129
|
+
// creating an invalid path and no tests will be found.
|
|
130
|
+
// instead if we are not at the root, let the cwd be root.
|
|
131
|
+
root: offset === '' ? resolvedProjectRoot : _devkit.workspaceRoot,
|
|
132
|
+
config: resolvedViteConfigPath,
|
|
133
|
+
reporters: [
|
|
134
|
+
...(_options_reporters = options.reporters) != null ? _options_reporters : [],
|
|
135
|
+
...(_ref = resolved == null ? void 0 : (_resolved_config1 = resolved.config) == null ? void 0 : (_resolved_config_test = _resolved_config1['test']) == null ? void 0 : _resolved_config_test.reporters) != null ? _ref : [],
|
|
136
|
+
'default'
|
|
137
|
+
],
|
|
138
|
+
coverage: _extends._({}, coverage, resolved == null ? void 0 : (_resolved_config2 = resolved.config) == null ? void 0 : (_resolved_config_test1 = _resolved_config2['test']) == null ? void 0 : _resolved_config_test1.coverage)
|
|
139
|
+
});
|
|
140
|
+
return settings;
|
|
141
|
+
}
|
|
142
|
+
function findViteConfig(projectRootFullPath) {
|
|
143
|
+
const allowsExt = [
|
|
144
|
+
'js',
|
|
145
|
+
'mjs',
|
|
146
|
+
'ts',
|
|
147
|
+
'cjs',
|
|
148
|
+
'mts',
|
|
149
|
+
'cts'
|
|
150
|
+
];
|
|
151
|
+
for (const ext of allowsExt){
|
|
152
|
+
if ((0, _fs.existsSync)((0, _devkit.joinPathFragments)(projectRootFullPath, `vite.config.${ext}`))) {
|
|
153
|
+
return (0, _devkit.joinPathFragments)(projectRootFullPath, `vite.config.${ext}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
65
157
|
const _default = vitestExecutor;
|
|
66
158
|
|
|
67
159
|
//# sourceMappingURL=vitest.impl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/executors/test/vitest.impl.ts"],"sourcesContent":["import { ExecutorContext, workspaceRoot } from '@nx/devkit';\nimport { VitestExecutorOptions } from './schema';\nimport { resolve } from 'path';\nimport { registerTsConfigPaths } from '@nx/js/src/internal';\nimport { NxReporter } from './lib/nx-reporter';\nimport { getOptions } from './lib/utils';\nimport { loadVitestDynamicImport } from '../../utils/executor-utils';\n\nexport async function* vitestExecutor(\n options: VitestExecutorOptions,\n context: ExecutorContext\n) {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n registerTsConfigPaths(resolve(workspaceRoot, projectRoot, 'tsconfig.json'));\n\n process.env.VITE_CJS_IGNORE_WARNING = 'true';\n // Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.\n const { startVitest } = await loadVitestDynamicImport();\n\n const resolvedOptions =\n (await getOptions(options, context, projectRoot)) ?? {};\n\n const nxReporter = new NxReporter(resolvedOptions['watch']);\n if (resolvedOptions['reporters'] === undefined) {\n resolvedOptions['reporters'] = [];\n } else if (typeof resolvedOptions['reporters'] === 'string') {\n resolvedOptions['reporters'] = [resolvedOptions['reporters']];\n }\n resolvedOptions['reporters'].push(nxReporter);\n\n const cliFilters = options.testFiles ?? [];\n\n const ctx = await startVitest(\n resolvedOptions['mode'] ?? 'test',\n cliFilters,\n resolvedOptions\n );\n\n let hasErrors = false;\n\n const processExit = () => {\n ctx.exit();\n if (hasErrors) {\n process.exit(1);\n } else {\n process.exit(0);\n }\n };\n\n if (resolvedOptions['watch'] === true) {\n process.on('SIGINT', processExit);\n process.on('SIGTERM', processExit);\n process.on('exit', processExit);\n }\n\n for await (const report of nxReporter) {\n // vitest sets the exitCode = 1 when code coverage isn't met\n hasErrors =\n report.hasErrors || (process.exitCode && process.exitCode !== 0);\n }\n\n return {\n success: !hasErrors,\n };\n}\n\nexport default vitestExecutor;\n"],"names":["vitestExecutor","options","context","projectRoot","projectsConfigurations","projects","projectName","root","registerTsConfigPaths","resolve","workspaceRoot","process","env","VITE_CJS_IGNORE_WARNING","startVitest","loadVitestDynamicImport","resolvedOptions","getOptions","nxReporter","NxReporter","undefined","push","cliFilters","testFiles","ctx","hasErrors","processExit","exit","on","report","exitCode","success"],"mappings":";;;;;;;;IAQuBA,cAAc;eAAdA;;IA4DvB,OAA8B;eAA9B;;;wBApE+C;sBAEvB;0BACc;4BACX;uBACA;+BACa;AAEjC,gBAAgBA,eACrBC,OAA8B,EAC9BC,OAAwB;IAExB,MAAMC,cACJD,QAAQE,sBAAsB,CAACC,QAAQ,CAACH,QAAQI,WAAW,CAAC,CAACC,IAAI;IAEnEC,IAAAA,+BAAqB,EAACC,IAAAA,aAAO,EAACC,qBAAa,EAAEP,aAAa;IAE1DQ,QAAQC,GAAG,CAACC,uBAAuB,GAAG;IACtC,yFAAyF;IACzF,MAAM,EAAEC,WAAW,EAAE,GAAG,MAAMC,IAAAA,sCAAuB;QAGlD;IADH,MAAMC,kBACJ,CAAC,OAAA,MAAMC,IAAAA,iBAAU,EAAChB,SAASC,SAASC,wBAAnC,OAAoD,CAAC;IAExD,MAAMe,aAAa,IAAIC,sBAAU,CAACH,eAAe,CAAC,QAAQ;IAC1D,IAAIA,eAAe,CAAC,YAAY,KAAKI,WAAW;QAC9CJ,eAAe,CAAC,YAAY,GAAG,EAAE;IACnC,OAAO,IAAI,OAAOA,eAAe,CAAC,YAAY,KAAK,UAAU;QAC3DA,eAAe,CAAC,YAAY,GAAG;YAACA,eAAe,CAAC,YAAY;SAAC;IAC/D;IACAA,eAAe,CAAC,YAAY,CAACK,IAAI,CAACH;QAEfjB;IAAnB,MAAMqB,aAAarB,CAAAA,qBAAAA,QAAQsB,SAAS,YAAjBtB,qBAAqB,EAAE;QAGxCe;IADF,MAAMQ,MAAM,MAAMV,YAChBE,CAAAA,wBAAAA,eAAe,CAAC,OAAO,YAAvBA,wBAA2B,QAC3BM,YACAN;IAGF,IAAIS,YAAY;IAEhB,MAAMC,cAAc;QAClBF,IAAIG,IAAI;QACR,IAAIF,WAAW;YACbd,QAAQgB,IAAI,CAAC;QACf,OAAO;YACLhB,QAAQgB,IAAI,CAAC;QACf;IACF;IAEA,IAAIX,eAAe,CAAC,QAAQ,KAAK,MAAM;QACrCL,QAAQiB,EAAE,CAAC,UAAUF;QACrBf,QAAQiB,EAAE,CAAC,WAAWF;QACtBf,QAAQiB,EAAE,CAAC,QAAQF;IACrB;IAEA,WAAW,MAAMG,UAAUX,WAAY;QACrC,4DAA4D;QAC5DO,YACEI,OAAOJ,SAAS,IAAKd,QAAQmB,QAAQ,IAAInB,QAAQmB,QAAQ,KAAK;IAClE;IAEA,OAAO;QACLC,SAAS,CAACN;IACZ;AACF;MAEA,WAAezB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/executors/test/vitest.impl.ts"],"sourcesContent":["import {\n ExecutorContext,\n joinPathFragments,\n logger,\n readJsonFile,\n stripIndents,\n workspaceRoot,\n} from '@nx/devkit';\nimport type { CoverageOptions, File, Reporter } from 'vitest';\nimport { VitestExecutorOptions } from './schema';\nimport { join, relative, resolve } from 'path';\nimport { existsSync } from 'fs';\nimport { registerTsConfigPaths } from '@nx/js/src/internal';\n\nclass NxReporter implements Reporter {\n deferred: {\n promise: Promise<boolean>;\n resolve: (val: boolean) => void;\n };\n\n constructor(private watch: boolean) {\n this.setupDeferred();\n }\n\n async *[Symbol.asyncIterator]() {\n do {\n const hasErrors = await this.deferred.promise;\n yield { hasErrors };\n this.setupDeferred();\n } while (this.watch);\n }\n\n private setupDeferred() {\n let resolve: (val: boolean) => void;\n this.deferred = {\n promise: new Promise((res) => {\n resolve = res;\n }),\n resolve,\n };\n }\n\n onFinished(files: File[], errors?: unknown[]) {\n const hasErrors =\n files.some((f) => f.result?.state === 'fail') || errors?.length > 0;\n this.deferred.resolve(hasErrors);\n }\n}\n\nexport async function* vitestExecutor(\n options: VitestExecutorOptions,\n context: ExecutorContext\n) {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n registerTsConfigPaths(resolve(workspaceRoot, projectRoot, 'tsconfig.json'));\n\n const { startVitest } = await (Function(\n 'return import(\"vitest/node\")'\n )() as Promise<typeof import('vitest/node')>);\n\n const nxReporter = new NxReporter(options.watch);\n const settings = await getSettings(options, context, projectRoot);\n settings.reporters.push(nxReporter);\n const cliFilters = options.testFiles ?? [];\n\n const ctx = await startVitest(options.mode, cliFilters, settings);\n\n let hasErrors = false;\n\n const processExit = () => {\n ctx.exit();\n if (hasErrors) {\n process.exit(1);\n } else {\n process.exit(0);\n }\n };\n\n if (options.watch) {\n process.on('SIGINT', processExit);\n process.on('SIGTERM', processExit);\n process.on('exit', processExit);\n }\n\n for await (const report of nxReporter) {\n // vitest sets the exitCode = 1 when code coverage isn't met\n hasErrors =\n report.hasErrors || (process.exitCode && process.exitCode !== 0);\n }\n\n return {\n success: !hasErrors,\n };\n}\n\nasync function getSettings(\n options: VitestExecutorOptions,\n context: ExecutorContext,\n projectRoot: string\n) {\n // Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.\n const { loadConfigFromFile } = await (Function(\n 'return import(\"vite\")'\n )() as Promise<typeof import('vite')>);\n\n const packageJsonPath = join(workspaceRoot, 'package.json');\n const packageJson = existsSync(packageJsonPath)\n ? readJsonFile(packageJsonPath)\n : undefined;\n let provider: 'v8' | 'c8' = 'v8';\n if (\n packageJson?.dependencies?.['@vitest/coverage-c8'] ||\n packageJson?.devDependencies?.['@vitest/coverage-c8']\n ) {\n provider = 'c8';\n }\n const offset = relative(workspaceRoot, context.cwd);\n // if reportsDirectory is not provided vitest will remove all files in the project root\n // when coverage is enabled in the vite.config.ts\n const coverage: CoverageOptions = options.reportsDirectory\n ? {\n enabled: options.coverage,\n reportsDirectory: options.reportsDirectory,\n provider,\n }\n : ({} as CoverageOptions);\n\n const viteConfigPath = options.config\n ? options.config // config is expected to be from the workspace root\n : findViteConfig(joinPathFragments(context.root, projectRoot));\n\n if (!viteConfigPath) {\n throw new Error(\n stripIndents`\n Unable to load test config from config file ${viteConfigPath}.\n \n Please make sure that vitest is configured correctly, \n or use the @nx/vite:vitest generator to configure it for you.\n You can read more here: https://nx.dev/nx-api/vite/generators/vitest\n `\n );\n }\n\n const resolvedProjectRoot = resolve(workspaceRoot, projectRoot);\n const resolvedViteConfigPath = resolve(\n workspaceRoot,\n projectRoot,\n relative(resolvedProjectRoot, viteConfigPath)\n );\n\n const resolved = await loadConfigFromFile(\n {\n mode: options.mode,\n command: 'serve',\n },\n resolvedViteConfigPath,\n resolvedProjectRoot\n );\n\n if (!viteConfigPath || !resolved?.config?.['test']) {\n logger.warn(stripIndents`Unable to load test config from config file ${\n resolved?.path ?? viteConfigPath\n }\nSome settings may not be applied as expected.\nYou can manually set the config in the project, ${\n context.projectName\n }, configuration.\n `);\n }\n\n const settings = {\n ...options,\n // when running nx from the project root, the root will get appended to the cwd.\n // creating an invalid path and no tests will be found.\n // instead if we are not at the root, let the cwd be root.\n root: offset === '' ? resolvedProjectRoot : workspaceRoot,\n config: resolvedViteConfigPath,\n reporters: [\n ...(options.reporters ?? []),\n ...((resolved?.config?.['test']?.reporters as string[]) ?? []),\n 'default',\n ] as (string | Reporter)[],\n coverage: { ...coverage, ...resolved?.config?.['test']?.coverage },\n };\n\n return settings;\n}\n\nfunction findViteConfig(projectRootFullPath: string): string {\n const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];\n\n for (const ext of allowsExt) {\n if (\n existsSync(joinPathFragments(projectRootFullPath, `vite.config.${ext}`))\n ) {\n return joinPathFragments(projectRootFullPath, `vite.config.${ext}`);\n }\n }\n}\n\nexport default vitestExecutor;\n"],"names":["vitestExecutor","NxReporter","Symbol","asyncIterator","hasErrors","deferred","promise","setupDeferred","watch","resolve","Promise","res","onFinished","files","errors","some","f","result","state","length","constructor","options","context","projectRoot","projectsConfigurations","projects","projectName","root","registerTsConfigPaths","workspaceRoot","startVitest","Function","nxReporter","settings","getSettings","reporters","push","cliFilters","testFiles","ctx","mode","processExit","exit","process","on","report","exitCode","success","packageJson","resolved","loadConfigFromFile","packageJsonPath","join","existsSync","readJsonFile","undefined","provider","dependencies","devDependencies","offset","relative","cwd","coverage","reportsDirectory","enabled","viteConfigPath","config","findViteConfig","joinPathFragments","Error","stripIndents","resolvedProjectRoot","resolvedViteConfigPath","command","logger","warn","path","projectRootFullPath","allowsExt","ext"],"mappings":";;;;;;;;IAiDuBA,cAAc;eAAdA;;IAwJvB,OAA8B;eAA9B;;;;wBAlMO;sBAGiC;oBACb;0BACW;AAEtC,IAAA,AAAMC,aAAN,MAAMA;IAUJ,OAAO,CAACC,OAAOC,aAAa,CAAC,GAAG;QAC9B,GAAG;YACD,MAAMC,YAAY,MAAM,IAAI,CAACC,QAAQ,CAACC,OAAO;YAC7C,MAAM;gBAAEF;YAAU;YAClB,IAAI,CAACG,aAAa;QACpB,QAAS,IAAI,CAACC,KAAK,CAAE;IACvB;IAEQD,gBAAgB;QACtB,IAAIE;QACJ,IAAI,CAACJ,QAAQ,GAAG;YACdC,SAAS,IAAII,QAAQ,CAACC;gBACpBF,UAAUE;YACZ;YACAF;QACF;IACF;IAEAG,WAAWC,KAAa,EAAEC,MAAkB,EAAE;QAC5C,MAAMV,YACJS,MAAME,IAAI,CAAC,CAACC;gBAAMA;mBAAAA,EAAAA,YAAAA,EAAEC,MAAM,qBAARD,UAAUE,KAAK,MAAK;cAAWJ,CAAAA,0BAAAA,OAAQK,MAAM,IAAG;QACpE,IAAI,CAACd,QAAQ,CAACI,OAAO,CAACL;IACxB;IA1BAgB,YAAoBZ,MAAgB;qB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C,IAAI,CAACL,IAAAA,oBAAY,CAAA,CAAC,4CAA4C,EACnErB,CAAAA,iBAAAA,4BAAAA,SAAU2B,IAAI,YAAd3B,iBAAkBgB,eACnB;;gDAE2C,EAC1C3C,QAAQI,WAAW,CACpB;MACC,CAAC;IACL;QAUQL,oBACA;IATR,MAAMY,WAAW,eACZZ;QACH,gFAAgF;QAChF,uDAAuD;QACvD,0DAA0D;QAC1DM,MAAMgC,WAAW,KAAKY,sBAAsB1C,qBAAa;QACzDqC,QAAQM;QACRrC,WAAW;eACLd,CAAAA,qBAAAA,QAAQc,SAAS,YAAjBd,qBAAqB,EAAE;eACvB,CAAA,OAAC4B,4BAAD,CAACA,oBAAAA,SAAUiB,MAAM,AAAiC,sBAAjDjB,wBAAAA,iBAAkB,CAAC,OAAO,qBAA1BA,sBAA4Bd,SAAS,YAAtC,OAAuD,EAAE;YAC7D;SACD;QACD2B,UAAU,eAAKA,UAAab,6BAAAA,oBAAAA,SAAUiB,MAAM,sBAAhBjB,yBAAAA,iBAAkB,CAAC,OAAO,qBAA1BA,uBAA4Ba,QAAQ;;IAGlE,OAAO7B;AACT;AAEA,SAASkC,eAAeU,mBAA2B;IACjD,MAAMC,YAAY;QAAC;QAAM;QAAO;QAAM;QAAO;QAAO;KAAM;IAE1D,KAAK,MAAMC,OAAOD,UAAW;QAC3B,IACEzB,IAAAA,cAAU,EAACe,IAAAA,yBAAiB,EAACS,qBAAqB,CAAC,YAAY,EAAEE,IAAI,CAAC,IACtE;YACA,OAAOX,IAAAA,yBAAiB,EAACS,qBAAqB,CAAC,YAAY,EAAEE,IAAI,CAAC;QACpE;IACF;AACF;MAEA,WAAe/E"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
2
|
import { ViteConfigurationGeneratorSchema } from './schema';
|
|
3
|
-
export declare function viteConfigurationGenerator(
|
|
4
|
-
export declare function viteConfigurationGeneratorInternal(tree: Tree, schema: ViteConfigurationGeneratorSchema): Promise<GeneratorCallback>;
|
|
3
|
+
export declare function viteConfigurationGenerator(tree: Tree, schema: ViteConfigurationGeneratorSchema): Promise<GeneratorCallback>;
|
|
5
4
|
export default viteConfigurationGenerator;
|
|
@@ -9,36 +9,24 @@ _export(exports, {
|
|
|
9
9
|
viteConfigurationGenerator: function() {
|
|
10
10
|
return viteConfigurationGenerator;
|
|
11
11
|
},
|
|
12
|
-
viteConfigurationGeneratorInternal: function() {
|
|
13
|
-
return viteConfigurationGeneratorInternal;
|
|
14
|
-
},
|
|
15
12
|
default: function() {
|
|
16
13
|
return _default;
|
|
17
14
|
}
|
|
18
15
|
});
|
|
19
16
|
const _extends = require("@swc/helpers/_/_extends");
|
|
20
17
|
const _devkit = require("@nx/devkit");
|
|
21
|
-
const _js = require("@nx/js");
|
|
22
18
|
const _generatorutils = require("../../utils/generator-utils");
|
|
23
19
|
const _init = require("../init/init");
|
|
24
20
|
const _vitestgenerator = require("../vitest/vitest-generator");
|
|
25
|
-
|
|
26
|
-
const _convertnonvite = require("./lib/convert-non-vite");
|
|
27
|
-
function viteConfigurationGenerator(host, schema) {
|
|
28
|
-
return viteConfigurationGeneratorInternal(host, _extends._({
|
|
29
|
-
addPlugin: false
|
|
30
|
-
}, schema));
|
|
31
|
-
}
|
|
32
|
-
async function viteConfigurationGeneratorInternal(tree, schema) {
|
|
33
|
-
var _nxJson_plugins;
|
|
21
|
+
async function viteConfigurationGenerator(tree, schema) {
|
|
34
22
|
var _schema, // Setting default to jsdom since it is the most common use case (React, Web).
|
|
35
23
|
// The @nx/js:lib generator specifically sets this to node to be more generic.
|
|
36
|
-
_schema1
|
|
24
|
+
_schema1;
|
|
37
25
|
const tasks = [];
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
const { targets, projectType, root } = (0, _devkit.readProjectConfiguration)(tree, schema.project);
|
|
27
|
+
let buildTargetName = 'build';
|
|
28
|
+
let serveTargetName = 'serve';
|
|
29
|
+
let testTargetName = 'test';
|
|
42
30
|
var _includeLib;
|
|
43
31
|
(_includeLib = (_schema = schema).includeLib) != null ? _includeLib : _schema.includeLib = projectType === 'library';
|
|
44
32
|
var _testEnvironment;
|
|
@@ -48,39 +36,90 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
|
|
|
48
36
|
* to use the vite executors.
|
|
49
37
|
*/ let projectAlreadyHasViteTargets = {};
|
|
50
38
|
if (!schema.newProject) {
|
|
51
|
-
|
|
39
|
+
var _targets_buildTargetName_options, _targets_buildTargetName;
|
|
40
|
+
const userProvidedTargetName = {
|
|
41
|
+
build: schema.buildTarget,
|
|
42
|
+
serve: schema.serveTarget,
|
|
43
|
+
test: schema.testTarget
|
|
44
|
+
};
|
|
45
|
+
const { validFoundTargetName, projectContainsUnsupportedExecutor, userProvidedTargetIsUnsupported, alreadyHasNxViteTargets } = (0, _generatorutils.findExistingTargetsInProject)(targets, userProvidedTargetName);
|
|
46
|
+
projectAlreadyHasViteTargets = alreadyHasNxViteTargets;
|
|
47
|
+
/**
|
|
48
|
+
* This means that we only found unsupported build targets in that project.
|
|
49
|
+
* The only way that buildTarget is defined, means that it is supported.
|
|
50
|
+
*
|
|
51
|
+
* If the `unsupported` flag was false, it would mean that we did not find
|
|
52
|
+
* a build target at all, so we can create a new one.
|
|
53
|
+
*
|
|
54
|
+
* So we only throw if we found a target, but it is unsupported.
|
|
55
|
+
*/ if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {
|
|
56
|
+
throw new Error(`The project ${schema.project} cannot be converted to use the @nx/vite executors.`);
|
|
57
|
+
}
|
|
58
|
+
if (alreadyHasNxViteTargets.build && (alreadyHasNxViteTargets.serve || projectType === 'library') && alreadyHasNxViteTargets.test) {
|
|
59
|
+
throw new Error(`The project ${schema.project} is already configured to use the @nx/vite executors.
|
|
60
|
+
Please try a different project, or remove the existing targets
|
|
61
|
+
and re-run this generator to reset the existing Vite Configuration.
|
|
62
|
+
`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* This means that we did not find any supported executors
|
|
66
|
+
* so we don't have any valid target names.
|
|
67
|
+
*
|
|
68
|
+
* However, the executors that we may have found are not in the
|
|
69
|
+
* list of the specifically unsupported executors either.
|
|
70
|
+
*
|
|
71
|
+
* So, we should warn the user about it.
|
|
72
|
+
*/ if (!projectContainsUnsupportedExecutor && !validFoundTargetName.build && !validFoundTargetName.serve && !validFoundTargetName.test) {
|
|
73
|
+
await (0, _generatorutils.handleUnknownExecutors)(schema.project);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* There is a possibility at this stage that the user has provided
|
|
77
|
+
* targets with unsupported executors.
|
|
78
|
+
* We keep track here of which of the targets that the user provided
|
|
79
|
+
* are unsupported.
|
|
80
|
+
* We do this with the `userProvidedTargetIsUnsupported` object,
|
|
81
|
+
* which contains flags for each target (whether it is supported or not).
|
|
82
|
+
*
|
|
83
|
+
* We also keep track of the targets that we found in the project,
|
|
84
|
+
* through the findExistingTargetsInProject function, which returns
|
|
85
|
+
* targets for build/serve/test that use supported executors, and
|
|
86
|
+
* can be converted to use the vite executors. These are the
|
|
87
|
+
* kept in the validFoundTargetName object.
|
|
88
|
+
*/ await (0, _generatorutils.handleUnsupportedUserProvidedTargets)(userProvidedTargetIsUnsupported, userProvidedTargetName, validFoundTargetName);
|
|
89
|
+
var _validFoundTargetName_build;
|
|
90
|
+
/**
|
|
91
|
+
* Once the user is at this stage, then they can go ahead and convert.
|
|
92
|
+
*/ buildTargetName = (_validFoundTargetName_build = validFoundTargetName.build) != null ? _validFoundTargetName_build : buildTargetName;
|
|
93
|
+
var _validFoundTargetName_serve;
|
|
94
|
+
serveTargetName = (_validFoundTargetName_serve = validFoundTargetName.serve) != null ? _validFoundTargetName_serve : serveTargetName;
|
|
95
|
+
if (projectType === 'application') {
|
|
96
|
+
(0, _generatorutils.moveAndEditIndexHtml)(tree, schema, buildTargetName);
|
|
97
|
+
}
|
|
98
|
+
(0, _generatorutils.deleteWebpackConfig)(tree, root, targets == null ? void 0 : (_targets_buildTargetName = targets[buildTargetName]) == null ? void 0 : (_targets_buildTargetName_options = _targets_buildTargetName.options) == null ? void 0 : _targets_buildTargetName_options.webpackConfig);
|
|
99
|
+
(0, _generatorutils.editTsConfig)(tree, schema);
|
|
52
100
|
}
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}));
|
|
101
|
+
const initTask = await (0, _init.default)(tree, {
|
|
102
|
+
uiFramework: schema.uiFramework,
|
|
103
|
+
includeLib: schema.includeLib,
|
|
104
|
+
compiler: schema.compiler,
|
|
105
|
+
testEnvironment: schema.testEnvironment,
|
|
106
|
+
rootProject: root === '.'
|
|
107
|
+
});
|
|
61
108
|
tasks.push(initTask);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!hasPlugin) {
|
|
69
|
-
if (!projectAlreadyHasViteTargets.build) {
|
|
70
|
-
(0, _generatorutils.addBuildTarget)(tree, schema, 'build');
|
|
109
|
+
if (!projectAlreadyHasViteTargets.build) {
|
|
110
|
+
(0, _generatorutils.addOrChangeBuildTarget)(tree, schema, buildTargetName);
|
|
111
|
+
}
|
|
112
|
+
if (!schema.includeLib) {
|
|
113
|
+
if (!projectAlreadyHasViteTargets.serve) {
|
|
114
|
+
(0, _generatorutils.addOrChangeServeTarget)(tree, schema, serveTargetName);
|
|
71
115
|
}
|
|
72
|
-
if (!
|
|
73
|
-
|
|
74
|
-
(0, _generatorutils.addServeTarget)(tree, schema, 'serve');
|
|
75
|
-
}
|
|
76
|
-
if (!projectAlreadyHasViteTargets.preview) {
|
|
77
|
-
(0, _generatorutils.addPreviewTarget)(tree, schema, 'preview');
|
|
78
|
-
}
|
|
116
|
+
if (!projectAlreadyHasViteTargets.preview) {
|
|
117
|
+
(0, _generatorutils.addPreviewTarget)(tree, schema, serveTargetName);
|
|
79
118
|
}
|
|
80
119
|
}
|
|
81
120
|
if (projectType === 'library') {
|
|
82
121
|
// update tsconfig.lib.json to include vite/client
|
|
83
|
-
(0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(
|
|
122
|
+
(0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(root, 'tsconfig.lib.json'), (json)=>{
|
|
84
123
|
if (!json.compilerOptions) {
|
|
85
124
|
json.compilerOptions = {};
|
|
86
125
|
}
|
|
@@ -119,7 +158,7 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
|
|
|
119
158
|
plugins: [
|
|
120
159
|
'react()'
|
|
121
160
|
]
|
|
122
|
-
}, false
|
|
161
|
+
}, false);
|
|
123
162
|
} else {
|
|
124
163
|
(0, _generatorutils.createOrEditViteConfig)(tree, schema, false, projectAlreadyHasViteTargets);
|
|
125
164
|
}
|
|
@@ -129,11 +168,10 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
|
|
|
129
168
|
project: schema.project,
|
|
130
169
|
uiFramework: schema.uiFramework,
|
|
131
170
|
inSourceTests: schema.inSourceTests,
|
|
132
|
-
coverageProvider: '
|
|
171
|
+
coverageProvider: 'c8',
|
|
133
172
|
skipViteConfig: true,
|
|
134
|
-
testTarget:
|
|
135
|
-
skipFormat: true
|
|
136
|
-
addPlugin: schema.addPlugin
|
|
173
|
+
testTarget: testTargetName,
|
|
174
|
+
skipFormat: true
|
|
137
175
|
});
|
|
138
176
|
tasks.push(vitestTask);
|
|
139
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readNxJson,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport { initGenerator as jsInitGenerator } from '@nx/js';\n\nimport {\n addBuildTarget,\n addServeTarget,\n addPreviewTarget,\n createOrEditViteConfig,\n TargetFlags,\n} from '../../utils/generator-utils';\n\nimport initGenerator from '../init/init';\nimport vitestGenerator from '../vitest/vitest-generator';\nimport { ViteConfigurationGeneratorSchema } from './schema';\nimport { ensureDependencies } from '../../utils/ensure-dependencies';\nimport { convertNonVite } from './lib/convert-non-vite';\n\nexport function viteConfigurationGenerator(\n host: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n return viteConfigurationGeneratorInternal(host, {\n addPlugin: false,\n ...schema,\n });\n}\n\nexport async function viteConfigurationGeneratorInternal(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const projectConfig = readProjectConfiguration(tree, schema.project);\n const { targets, root: projectRoot } = projectConfig;\n\n const projectType = projectConfig.projectType ?? 'library';\n\n schema.includeLib ??= projectType === 'library';\n\n // Setting default to jsdom since it is the most common use case (React, Web).\n // The @nx/js:lib generator specifically sets this to node to be more generic.\n schema.testEnvironment ??= 'jsdom';\n\n /**\n * This is for when we are converting an existing project\n * to use the vite executors.\n */\n let projectAlreadyHasViteTargets: TargetFlags = {};\n\n if (!schema.newProject) {\n await convertNonVite(tree, schema, projectRoot, projectType, targets);\n }\n\n const jsInitTask = await jsInitGenerator(tree, {\n ...schema,\n skipFormat: true,\n tsConfigName: projectRoot === '.' ? 'tsconfig.json' : 'tsconfig.base.json',\n });\n tasks.push(jsInitTask);\n const initTask = await initGenerator(tree, { ...schema, skipFormat: true });\n tasks.push(initTask);\n tasks.push(ensureDependencies(tree, schema));\n\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\n\n const hasPlugin = nxJson.plugins?.some((p) =>\n typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin'\n );\n\n if (!hasPlugin) {\n if (!projectAlreadyHasViteTargets.build) {\n addBuildTarget(tree, schema, 'build');\n }\n\n if (!schema.includeLib) {\n if (!projectAlreadyHasViteTargets.serve) {\n addServeTarget(tree, schema, 'serve');\n }\n if (!projectAlreadyHasViteTargets.preview) {\n addPreviewTarget(tree, schema, 'preview');\n }\n }\n }\n if (projectType === 'library') {\n // update tsconfig.lib.json to include vite/client\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.lib.json'),\n (json) => {\n if (!json.compilerOptions) {\n json.compilerOptions = {};\n }\n if (!json.compilerOptions.types) {\n json.compilerOptions.types = [];\n }\n if (!json.compilerOptions.types.includes('vite/client')) {\n return {\n ...json,\n compilerOptions: {\n ...json.compilerOptions,\n types: [...json.compilerOptions.types, 'vite/client'],\n },\n };\n }\n return json;\n }\n );\n }\n\n if (!schema.newProject) {\n // We are converting existing project to use Vite\n if (schema.uiFramework === 'react') {\n createOrEditViteConfig(\n tree,\n {\n project: schema.project,\n includeLib: schema.includeLib,\n includeVitest: schema.includeVitest,\n inSourceTests: schema.inSourceTests,\n rollupOptionsExternal: [\n \"'react'\",\n \"'react-dom'\",\n \"'react/jsx-runtime'\",\n ],\n imports: [\n schema.compiler === 'swc'\n ? `import react from '@vitejs/plugin-react-swc'`\n : `import react from '@vitejs/plugin-react'`,\n ],\n plugins: ['react()'],\n },\n false,\n undefined\n );\n } else {\n createOrEditViteConfig(tree, schema, false, projectAlreadyHasViteTargets);\n }\n }\n\n if (schema.includeVitest) {\n const vitestTask = await vitestGenerator(tree, {\n project: schema.project,\n uiFramework: schema.uiFramework,\n inSourceTests: schema.inSourceTests,\n coverageProvider: 'v8',\n skipViteConfig: true,\n testTarget: 'test',\n skipFormat: true,\n addPlugin: schema.addPlugin,\n });\n tasks.push(vitestTask);\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default viteConfigurationGenerator;\n"],"names":["viteConfigurationGenerator","viteConfigurationGeneratorInternal","host","schema","addPlugin","tree","nxJson","tasks","projectConfig","readProjectConfiguration","project","targets","root","projectRoot","projectType","includeLib","testEnvironment","projectAlreadyHasViteTargets","newProject","convertNonVite","jsInitTask","jsInitGenerator","skipFormat","tsConfigName","push","initTask","initGenerator","ensureDependencies","readNxJson","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","hasPlugin","plugins","some","p","plugin","build","addBuildTarget","serve","addServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","uiFramework","createOrEditViteConfig","includeVitest","inSourceTests","rollupOptionsExternal","imports","compiler","undefined","vitestTask","vitestGenerator","coverageProvider","skipViteConfig","testTarget","formatFiles","runTasksInSerial"],"mappings":";;;;;;;;IA0BgBA,0BAA0B;eAA1BA;;IAUMC,kCAAkC;eAAlCA;;IA4ItB,OAA0C;eAA1C;;;;wBAvKO;oBAC0C;gCAQ1C;sBAEmB;iCACE;oCAEO;gCACJ;AAExB,SAASD,2BACdE,IAAU,EACVC,MAAwC;IAExC,OAAOF,mCAAmCC,MAAM;QAC9CE,WAAW;OACRD;AAEP;AAEO,eAAeF,mCACpBI,IAAU,EACVF,MAAwC;QAyCtBG;QAhClBH,SAEA,8EAA8E;IAC9E,8EAA8E;IAC9EA,UA0BAA;IArCA,MAAMI,QAA6B,EAAE;IAErC,MAAMC,gBAAgBC,IAAAA,gCAAwB,EAACJ,MAAMF,OAAOO,OAAO;IACnE,MAAM,EAAEC,OAAO,EAAEC,MAAMC,WAAW,EAAE,GAAGL;QAEnBA;IAApB,MAAMM,cAAcN,CAAAA,6BAAAA,cAAcM,WAAW,YAAzBN,6BAA6B;;IAEjDL,gBAAAA,UAAAA,QAAOY,oCAAPZ,QAAOY,aAAeD,gBAAgB;;IAItCX,qBAAAA,WAAAA,QAAOa,8CAAPb,SAAOa,kBAAoB;IAE3B;;;GAGC,GACD,IAAIC,+BAA4C,CAAC;IAEjD,IAAI,CAACd,OAAOe,UAAU,EAAE;QACtB,MAAMC,IAAAA,8BAAc,EAACd,MAAMF,QAAQU,aAAaC,aAAaH;IAC/D;IAEA,MAAMS,aAAa,MA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":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\n\nimport {\n addOrChangeBuildTarget,\n addOrChangeServeTarget,\n addPreviewTarget,\n createOrEditViteConfig,\n deleteWebpackConfig,\n editTsConfig,\n findExistingTargetsInProject,\n handleUnknownExecutors,\n handleUnsupportedUserProvidedTargets,\n moveAndEditIndexHtml,\n TargetFlags,\n UserProvidedTargetName,\n} from '../../utils/generator-utils';\n\nimport initGenerator from '../init/init';\nimport vitestGenerator from '../vitest/vitest-generator';\nimport { ViteConfigurationGeneratorSchema } from './schema';\n\nexport async function viteConfigurationGenerator(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const { targets, projectType, root } = readProjectConfiguration(\n tree,\n schema.project\n );\n let buildTargetName = 'build';\n let serveTargetName = 'serve';\n let testTargetName = 'test';\n\n schema.includeLib ??= projectType === 'library';\n\n // Setting default to jsdom since it is the most common use case (React, Web).\n // The @nx/js:lib generator specifically sets this to node to be more generic.\n schema.testEnvironment ??= 'jsdom';\n\n /**\n * This is for when we are converting an existing project\n * to use the vite executors.\n */\n let projectAlreadyHasViteTargets: TargetFlags = {};\n\n if (!schema.newProject) {\n const userProvidedTargetName: UserProvidedTargetName = {\n build: schema.buildTarget,\n serve: schema.serveTarget,\n test: schema.testTarget,\n };\n\n const {\n validFoundTargetName,\n projectContainsUnsupportedExecutor,\n userProvidedTargetIsUnsupported,\n alreadyHasNxViteTargets,\n } = findExistingTargetsInProject(targets, userProvidedTargetName);\n projectAlreadyHasViteTargets = alreadyHasNxViteTargets;\n /**\n * This means that we only found unsupported build targets in that project.\n * The only way that buildTarget is defined, means that it is supported.\n *\n * If the `unsupported` flag was false, it would mean that we did not find\n * a build target at all, so we can create a new one.\n *\n * So we only throw if we found a target, but it is unsupported.\n */\n if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {\n throw new Error(\n `The project ${schema.project} cannot be converted to use the @nx/vite executors.`\n );\n }\n\n if (\n alreadyHasNxViteTargets.build &&\n (alreadyHasNxViteTargets.serve || projectType === 'library') &&\n alreadyHasNxViteTargets.test\n ) {\n throw new Error(\n `The project ${schema.project} is already configured to use the @nx/vite executors.\n Please try a different project, or remove the existing targets \n and re-run this generator to reset the existing Vite Configuration.\n `\n );\n }\n\n /**\n * This means that we did not find any supported executors\n * so we don't have any valid target names.\n *\n * However, the executors that we may have found are not in the\n * list of the specifically unsupported executors either.\n *\n * So, we should warn the user about it.\n */\n\n if (\n !projectContainsUnsupportedExecutor &&\n !validFoundTargetName.build &&\n !validFoundTargetName.serve &&\n !validFoundTargetName.test\n ) {\n await handleUnknownExecutors(schema.project);\n }\n\n /**\n * There is a possibility at this stage that the user has provided\n * targets with unsupported executors.\n * We keep track here of which of the targets that the user provided\n * are unsupported.\n * We do this with the `userProvidedTargetIsUnsupported` object,\n * which contains flags for each target (whether it is supported or not).\n *\n * We also keep track of the targets that we found in the project,\n * through the findExistingTargetsInProject function, which returns\n * targets for build/serve/test that use supported executors, and\n * can be converted to use the vite executors. These are the\n * kept in the validFoundTargetName object.\n */\n await handleUnsupportedUserProvidedTargets(\n userProvidedTargetIsUnsupported,\n userProvidedTargetName,\n validFoundTargetName\n );\n\n /**\n * Once the user is at this stage, then they can go ahead and convert.\n */\n\n buildTargetName = validFoundTargetName.build ?? buildTargetName;\n serveTargetName = validFoundTargetName.serve ?? serveTargetName;\n\n if (projectType === 'application') {\n moveAndEditIndexHtml(tree, schema, buildTargetName);\n }\n\n deleteWebpackConfig(\n tree,\n root,\n targets?.[buildTargetName]?.options?.webpackConfig\n );\n\n editTsConfig(tree, schema);\n }\n\n const initTask = await initGenerator(tree, {\n uiFramework: schema.uiFramework,\n includeLib: schema.includeLib,\n compiler: schema.compiler,\n testEnvironment: schema.testEnvironment,\n rootProject: root === '.',\n });\n tasks.push(initTask);\n\n if (!projectAlreadyHasViteTargets.build) {\n addOrChangeBuildTarget(tree, schema, buildTargetName);\n }\n\n if (!schema.includeLib) {\n if (!projectAlreadyHasViteTargets.serve) {\n addOrChangeServeTarget(tree, schema, serveTargetName);\n }\n if (!projectAlreadyHasViteTargets.preview) {\n addPreviewTarget(tree, schema, serveTargetName);\n }\n }\n\n if (projectType === 'library') {\n // update tsconfig.lib.json to include vite/client\n updateJson(tree, joinPathFragments(root, 'tsconfig.lib.json'), (json) => {\n if (!json.compilerOptions) {\n json.compilerOptions = {};\n }\n if (!json.compilerOptions.types) {\n json.compilerOptions.types = [];\n }\n if (!json.compilerOptions.types.includes('vite/client')) {\n return {\n ...json,\n compilerOptions: {\n ...json.compilerOptions,\n types: [...json.compilerOptions.types, 'vite/client'],\n },\n };\n }\n return json;\n });\n }\n\n if (!schema.newProject) {\n // We are converting existing project to use Vite\n if (schema.uiFramework === 'react') {\n createOrEditViteConfig(\n tree,\n {\n project: schema.project,\n includeLib: schema.includeLib,\n includeVitest: schema.includeVitest,\n inSourceTests: schema.inSourceTests,\n rollupOptionsExternal: [\n \"'react'\",\n \"'react-dom'\",\n \"'react/jsx-runtime'\",\n ],\n imports: [\n schema.compiler === 'swc'\n ? `import react from '@vitejs/plugin-react-swc'`\n : `import react from '@vitejs/plugin-react'`,\n ],\n plugins: ['react()'],\n },\n false\n );\n } else {\n createOrEditViteConfig(tree, schema, false, projectAlreadyHasViteTargets);\n }\n }\n\n if (schema.includeVitest) {\n const vitestTask = await vitestGenerator(tree, {\n project: schema.project,\n uiFramework: schema.uiFramework,\n inSourceTests: schema.inSourceTests,\n coverageProvider: 'c8',\n skipViteConfig: true,\n testTarget: testTargetName,\n skipFormat: true,\n });\n tasks.push(vitestTask);\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default viteConfigurationGenerator;\n"],"names":["viteConfigurationGenerator","tree","schema","tasks","targets","projectType","root","readProjectConfiguration","project","buildTargetName","serveTargetName","testTargetName","includeLib","testEnvironment","projectAlreadyHasViteTargets","newProject","userProvidedTargetName","build","buildTarget","serve","serveTarget","test","testTarget","validFoundTargetName","projectContainsUnsupportedExecutor","userProvidedTargetIsUnsupported","alreadyHasNxViteTargets","findExistingTargetsInProject","Error","handleUnknownExecutors","handleUnsupportedUserProvidedTargets","moveAndEditIndexHtml","deleteWebpackConfig","options","webpackConfig","editTsConfig","initTask","initGenerator","uiFramework","compiler","rootProject","push","addOrChangeBuildTarget","addOrChangeServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","createOrEditViteConfig","includeVitest","inSourceTests","rollupOptionsExternal","imports","plugins","vitestTask","vitestGenerator","coverageProvider","skipViteConfig","skipFormat","formatFiles","runTasksInSerial"],"mappings":";;;;;;;;IA6BsBA,0BAA0B;eAA1BA;;IA4NtB,OAA0C;eAA1C;;;;wBAjPO;gCAeA;sBAEmB;iCACE;AAGrB,eAAeA,2BACpBC,IAAU,EACVC,MAAwC;QAYxCA,SAEA,8EAA8E;IAC9E,8EAA8E;IAC9EA;IAdA,MAAMC,QAA6B,EAAE;IAErC,MAAM,EAAEC,OAAO,EAAEC,WAAW,EAAEC,IAAI,EAAE,GAAGC,IAAAA,gCAAwB,EAC7DN,MACAC,OAAOM,OAAO;IAEhB,IAAIC,kBAAkB;IACtB,IAAIC,kBAAkB;IACtB,IAAIC,iBAAiB;;IAErBT,gBAAAA,UAAAA,QAAOU,oCAAPV,QAAOU,aAAeP,gBAAgB;;IAItCH,qBAAAA,WAAAA,QAAOW,8CAAPX,SAAOW,kBAAoB;IAE3B;;;GAGC,GACD,IAAIC,+BAA4C,CAAC;IAEjD,IAAI,CAACZ,OAAOa,UAAU,EAAE;YA+FpBX,kCAAAA;QA9FF,MAAMY,yBAAiD;YACrDC,OAAOf,OAAOgB,WAAW;YACzBC,OAAOjB,OAAOkB,WAAW;YACzBC,MAAMnB,OAAOoB,UAAU;QACzB;QAEA,MAAM,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,OAAOmD,aAAa;gBACnCC,eAAepD,OAAOoD,aAAa;gBACnCC,uBAAuB;oBACrB;oBACA;oBACA;iBACD;gBACDC,SAAS;oBACPtD,OAAOqC,QAAQ,KAAK,QAChB,CAAC,4CAA4C,CAAC,GAC9C,CAAC,wCAAwC,CAAC;iBAC/C;gBACDkB,SAAS;oBAAC;iBAAU;YACtB,GACA;QAEJ,OAAO;YACLL,IAAAA,sCAAsB,EAACnD,MAAMC,QAAQ,OAAOY;QAC9C;IACF;IAEA,IAAIZ,OAAOmD,aAAa,EAAE;QACxB,MAAMK,aAAa,MAAMC,IAAAA,wBAAe,EAAC1D,MAAM;YAC7CO,SAASN,OAAOM,OAAO;YACvB8B,aAAapC,OAAOoC,WAAW;YAC/BgB,eAAepD,OAAOoD,aAAa;YACnCM,kBAAkB;YAClBC,gBAAgB;YAChBvC,YAAYX;YACZmD,YAAY;QACd;QACA3D,MAAMsC,IAAI,CAACiB;IACb;IAEA,IAAI,CAACxD,OAAO4D,UAAU,EAAE;QACtB,MAAMC,IAAAA,mBAAW,EAAC9D;IACpB;IAEA,OAAO+D,IAAAA,wBAAgB,KAAI7D;AAC7B;MAEA,WAAeH"}
|
|
@@ -6,7 +6,9 @@ export interface ViteConfigurationGeneratorSchema {
|
|
|
6
6
|
includeVitest?: boolean;
|
|
7
7
|
inSourceTests?: boolean;
|
|
8
8
|
includeLib?: boolean;
|
|
9
|
+
buildTarget?: string;
|
|
10
|
+
serveTarget?: string;
|
|
11
|
+
testTarget?: string;
|
|
9
12
|
skipFormat?: boolean;
|
|
10
13
|
testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
|
|
11
|
-
addPlugin?: boolean;
|
|
12
14
|
}
|
|
@@ -44,6 +44,18 @@
|
|
|
44
44
|
"default": false,
|
|
45
45
|
"hidden": true
|
|
46
46
|
},
|
|
47
|
+
"buildTarget": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "The build target of the project to be transformed to use the @nx/vite:build executor."
|
|
50
|
+
},
|
|
51
|
+
"serveTarget": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"description": "The serve target of the project to be transformed to use the @nx/vite:dev-server and @nx/vite:preview-server executors."
|
|
54
|
+
},
|
|
55
|
+
"testTarget": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"description": "The test target of the project to be transformed to use the @nx/vite:test executor."
|
|
58
|
+
},
|
|
47
59
|
"skipFormat": {
|
|
48
60
|
"description": "Skip formatting files.",
|
|
49
61
|
"type": "boolean",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { InitGeneratorSchema } from './schema';
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
|
|
5
|
-
export declare function initGeneratorInternal(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
|
|
3
|
+
export declare function createVitestConfig(tree: Tree): void;
|
|
4
|
+
export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
6
5
|
export default initGenerator;
|