@nx/vite 22.1.0-beta.0 → 22.1.0-beta.2
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/plugins/nx-tsconfig-paths.plugin.d.ts.map +1 -1
- package/plugins/nx-tsconfig-paths.plugin.js +6 -3
- package/src/executors/build/schema.json +2 -2
- package/src/generators/configuration/schema.json +2 -2
- package/src/plugins/plugin.d.ts +8 -0
- package/src/plugins/plugin.d.ts.map +1 -1
- package/src/plugins/plugin.js +103 -20
- package/src/utils/generator-utils.d.ts.map +1 -1
- package/src/utils/generator-utils.js +11 -6
- package/src/utils/test-files/test-vite-configs.d.ts +2 -2
- package/src/utils/test-files/test-vite-configs.d.ts.map +1 -1
- package/src/utils/test-files/test-vite-configs.js +2 -2
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.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"migrations": "./migrations.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@nx/devkit": "22.1.0-beta.
|
|
33
|
+
"@nx/devkit": "22.1.0-beta.2",
|
|
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.2",
|
|
37
37
|
"picomatch": "4.0.2",
|
|
38
38
|
"tsconfig-paths": "^4.1.2",
|
|
39
39
|
"semver": "^7.6.3",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"ajv": "^8.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"nx": "22.1.0-beta.
|
|
44
|
+
"nx": "22.1.0-beta.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-tsconfig-paths.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAK9B,MAAM,WAAW,oBAAoB;IACnC;;;;QAII;IACJ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;QAKI;IACJ,UAAU,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;IACnC;;;QAGI;IACJ,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,
|
|
1
|
+
{"version":3,"file":"nx-tsconfig-paths.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAK9B,MAAM,WAAW,oBAAoB;IACnC;;;;QAII;IACJ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;QAKI;IACJ,UAAU,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;IACnC;;;QAGI;IACJ,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAsKzD,MAAM,CA0EZ"}
|
|
@@ -33,6 +33,7 @@ function nxViteTsPaths(options = {}) {
|
|
|
33
33
|
options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];
|
|
34
34
|
options.buildLibsFromSource ??= true;
|
|
35
35
|
let projectRoot = '';
|
|
36
|
+
let projectRootFromWorkspaceRoot;
|
|
36
37
|
return {
|
|
37
38
|
name: 'nx-vite-ts-paths',
|
|
38
39
|
// Ensure the resolveId aspect of the plugin is called before vite's internal resolver
|
|
@@ -40,7 +41,7 @@ function nxViteTsPaths(options = {}) {
|
|
|
40
41
|
enforce: 'pre',
|
|
41
42
|
async configResolved(config) {
|
|
42
43
|
projectRoot = config.root;
|
|
43
|
-
|
|
44
|
+
projectRootFromWorkspaceRoot = (0, node_path_1.relative)(devkit_1.workspaceRoot, projectRoot);
|
|
44
45
|
foundTsConfigPath = getTsConfig(process.env.NX_TSCONFIG_PATH ??
|
|
45
46
|
(0, node_path_1.join)(devkit_1.workspaceRoot, 'tmp', projectRootFromWorkspaceRoot, process.env.NX_TASK_TARGET_TARGET ?? 'build', 'tsconfig.generated.json'));
|
|
46
47
|
if (!foundTsConfigPath)
|
|
@@ -137,10 +138,12 @@ function nxViteTsPaths(options = {}) {
|
|
|
137
138
|
},
|
|
138
139
|
};
|
|
139
140
|
function getTsConfig(preferredTsConfigPath) {
|
|
140
|
-
const projectTsConfigPath = (0, options_utils_1.getProjectTsConfigPath)(
|
|
141
|
+
const projectTsConfigPath = (0, options_utils_1.getProjectTsConfigPath)(projectRootFromWorkspaceRoot);
|
|
141
142
|
return [
|
|
142
143
|
(0, node_path_1.resolve)(preferredTsConfigPath),
|
|
143
|
-
projectTsConfigPath
|
|
144
|
+
projectTsConfigPath
|
|
145
|
+
? (0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, projectTsConfigPath))
|
|
146
|
+
: null,
|
|
144
147
|
(0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.base.json')),
|
|
145
148
|
(0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.json')),
|
|
146
149
|
(0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'jsconfig.json')),
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"outputCapture": "direct-nodejs",
|
|
4
4
|
"title": "Vite Prod Builder",
|
|
5
5
|
"cli": "nx",
|
|
6
|
-
"description": "Builds a Vite
|
|
6
|
+
"description": "Builds a Vite application for production.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"presets": [
|
|
9
9
|
{
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"configFile": {
|
|
38
38
|
"type": "string",
|
|
39
|
-
"description": "The name of the Vite
|
|
39
|
+
"description": "The name of the Vite configuration file.",
|
|
40
40
|
"x-completion-type": "file",
|
|
41
41
|
"x-completion-glob": "vite.config.@(js|ts)"
|
|
42
42
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"cli": "nx",
|
|
3
|
-
"title": "Configure a project to use Vite.
|
|
4
|
-
"description": "Configure a project to use Vite.
|
|
3
|
+
"title": "Configure a project to use Vite.",
|
|
4
|
+
"description": "Configure a project to use Vite.",
|
|
5
5
|
"$id": "configure-vite-project",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -12,6 +12,14 @@ export interface VitePluginOptions {
|
|
|
12
12
|
typecheckTargetName?: string;
|
|
13
13
|
watchDepsTargetName?: string;
|
|
14
14
|
buildDepsTargetName?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Atomizer for vitest
|
|
17
|
+
*/
|
|
18
|
+
ciTargetName?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The name that should be used to group atomized tasks on CI
|
|
21
|
+
*/
|
|
22
|
+
ciGroupName?: string;
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
17
25
|
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/vite/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAGlB,aAAa,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/vite/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAGlB,aAAa,EASd,MAAM,YAAY,CAAC;AAgBpB,MAAM,WAAW,iBAAiB;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAiBD;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAEhC,CAAC;AAIF,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC,iBAAiB,CAuGxD,CAAC;AAEF,eAAO,MAAM,aAAa,kCAAc,CAAC"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNodesV2 = exports.createNodes = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
5
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
9
|
-
const
|
|
6
|
+
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
10
7
|
const js_1 = require("@nx/js");
|
|
11
|
-
const
|
|
8
|
+
const util_1 = require("@nx/js/src/plugins/typescript/util");
|
|
9
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
10
|
+
const node_fs_1 = require("node:fs");
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
12
|
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
13
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
14
|
+
const plugins_1 = require("nx/src/utils/plugins");
|
|
15
|
+
const executor_utils_1 = require("../utils/executor-utils");
|
|
13
16
|
const picomatch = require("picomatch");
|
|
14
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
15
|
-
const util_1 = require("@nx/js/src/plugins/typescript/util");
|
|
16
17
|
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
17
18
|
function readTargetsCache(cachePath) {
|
|
18
|
-
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0,
|
|
19
|
+
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, node_fs_1.existsSync)(cachePath)
|
|
19
20
|
? (0, devkit_1.readJsonFile)(cachePath)
|
|
20
21
|
: {};
|
|
21
22
|
}
|
|
@@ -35,11 +36,11 @@ exports.createNodes = [
|
|
|
35
36
|
async (configFilePaths, options, context) => {
|
|
36
37
|
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
|
37
38
|
const normalizedOptions = normalizeOptions(options);
|
|
38
|
-
const cachePath = (0,
|
|
39
|
+
const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `vite-${optionsHash}.hash`);
|
|
39
40
|
const targetsCache = readTargetsCache(cachePath);
|
|
40
41
|
const isUsingTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
|
|
41
42
|
const { roots: projectRoots, configFiles: validConfigFiles } = configFilePaths.reduce((acc, configFile) => {
|
|
42
|
-
const potentialRoot = (0,
|
|
43
|
+
const potentialRoot = (0, node_path_1.dirname)(configFile);
|
|
43
44
|
if (checkIfConfigFileShouldBeProject(potentialRoot, context)) {
|
|
44
45
|
acc.roots.push(potentialRoot);
|
|
45
46
|
acc.configFiles.push(configFile);
|
|
@@ -53,9 +54,9 @@ exports.createNodes = [
|
|
|
53
54
|
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots, { ...normalizedOptions, isUsingTsSolutionSetup }, context, projectRoots.map((r) => [lockfile]));
|
|
54
55
|
try {
|
|
55
56
|
return await (0, devkit_1.createNodesFromFiles)(async (configFile, _, context, idx) => {
|
|
56
|
-
const projectRoot = (0,
|
|
57
|
+
const projectRoot = (0, node_path_1.dirname)(configFile);
|
|
57
58
|
// Do not create a project if package.json and project.json isn't there.
|
|
58
|
-
const siblingFiles = (0,
|
|
59
|
+
const siblingFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot));
|
|
59
60
|
const tsConfigFiles = siblingFiles.filter((p) => picomatch('tsconfig*{.json,.*.json}')(p)) ?? [];
|
|
60
61
|
const hasReactRouterConfig = siblingFiles.some((configFile) => {
|
|
61
62
|
const parts = configFile.split('.');
|
|
@@ -109,12 +110,84 @@ async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFi
|
|
|
109
110
|
configFile: absoluteConfigFilePath,
|
|
110
111
|
mode: 'development',
|
|
111
112
|
}, 'build');
|
|
113
|
+
let metadata = {};
|
|
112
114
|
const { buildOutputs, testOutputs, hasTest, isBuildable, hasServeConfig } = getOutputs(viteBuildConfig, projectRoot, context.workspaceRoot);
|
|
113
115
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
114
116
|
const targets = {};
|
|
115
|
-
// if file is vitest.config or vite.config has definition for test, create
|
|
117
|
+
// if file is vitest.config or vite.config has definition for test, create targets for test and/or atomized tests
|
|
116
118
|
if (configFilePath.includes('vitest.config') || hasTest) {
|
|
117
119
|
targets[options.testTargetName] = await testTarget(namedInputs, testOutputs, projectRoot);
|
|
120
|
+
if (options.ciTargetName) {
|
|
121
|
+
const groupName = options.ciGroupName ?? (0, plugins_1.deriveGroupNameFromTarget)(options.ciTargetName);
|
|
122
|
+
const targetGroup = [];
|
|
123
|
+
const dependsOn = [];
|
|
124
|
+
metadata = {
|
|
125
|
+
targetGroups: {
|
|
126
|
+
[groupName]: targetGroup,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const projectRootRelativeTestPaths = await getTestPathsRelativeToProjectRoot(projectRoot);
|
|
130
|
+
for (const relativePath of projectRootRelativeTestPaths) {
|
|
131
|
+
if (relativePath.includes('../')) {
|
|
132
|
+
throw new Error('@nx/vite/plugin attempted to run tests outside of the project root. This is not supported and should not happen. Please open an issue at https://github.com/nrwl/nx/issues/new/choose with the following information:\n\n' +
|
|
133
|
+
`\n\n${JSON.stringify({
|
|
134
|
+
projectRoot,
|
|
135
|
+
relativePath,
|
|
136
|
+
projectRootRelativeTestPaths,
|
|
137
|
+
context,
|
|
138
|
+
}, null, 2)}`);
|
|
139
|
+
}
|
|
140
|
+
const targetName = `${options.ciTargetName}--${relativePath}`;
|
|
141
|
+
dependsOn.push(targetName);
|
|
142
|
+
targets[targetName] = {
|
|
143
|
+
// It does not make sense to run atomized tests in watch mode as they are intended to be run in CI
|
|
144
|
+
command: `vitest run ${relativePath}`,
|
|
145
|
+
cache: targets[options.testTargetName].cache,
|
|
146
|
+
inputs: targets[options.testTargetName].inputs,
|
|
147
|
+
outputs: targets[options.testTargetName].outputs,
|
|
148
|
+
options: {
|
|
149
|
+
cwd: projectRoot,
|
|
150
|
+
env: targets[options.testTargetName].options.env,
|
|
151
|
+
},
|
|
152
|
+
metadata: {
|
|
153
|
+
technologies: ['vitest'],
|
|
154
|
+
description: `Run Vitest Tests in ${relativePath}`,
|
|
155
|
+
help: {
|
|
156
|
+
command: `${pmc.exec} vitest --help`,
|
|
157
|
+
example: {
|
|
158
|
+
options: {
|
|
159
|
+
coverage: true,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
targetGroup.push(targetName);
|
|
166
|
+
}
|
|
167
|
+
if (targetGroup.length > 0) {
|
|
168
|
+
targets[options.ciTargetName] = {
|
|
169
|
+
executor: 'nx:noop',
|
|
170
|
+
cache: true,
|
|
171
|
+
inputs: targets[options.testTargetName].inputs,
|
|
172
|
+
outputs: targets[options.testTargetName].outputs,
|
|
173
|
+
dependsOn,
|
|
174
|
+
metadata: {
|
|
175
|
+
technologies: ['vitest'],
|
|
176
|
+
description: 'Run Vitest Tests in CI',
|
|
177
|
+
nonAtomizedTarget: options.testTargetName,
|
|
178
|
+
help: {
|
|
179
|
+
command: `${pmc.exec} vitest --help`,
|
|
180
|
+
example: {
|
|
181
|
+
options: {
|
|
182
|
+
coverage: true,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
targetGroup.unshift(options.ciTargetName);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
118
191
|
}
|
|
119
192
|
if (hasReactRouterConfig) {
|
|
120
193
|
// If we have a react-router config, we can skip the rest of the targets
|
|
@@ -186,7 +259,6 @@ async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFi
|
|
|
186
259
|
}
|
|
187
260
|
}
|
|
188
261
|
(0, util_1.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmc);
|
|
189
|
-
const metadata = {};
|
|
190
262
|
return {
|
|
191
263
|
targets,
|
|
192
264
|
metadata,
|
|
@@ -324,7 +396,7 @@ function getOutputs(viteBuildConfig, projectRoot, workspaceRoot) {
|
|
|
324
396
|
const buildOutputPath = normalizeOutputPath(build?.outDir, projectRoot, workspaceRoot, 'dist');
|
|
325
397
|
const isBuildable = build?.lib ||
|
|
326
398
|
build?.rollupOptions?.input ||
|
|
327
|
-
(0,
|
|
399
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(workspaceRoot, projectRoot, 'index.html'));
|
|
328
400
|
const hasServeConfig = Boolean(server?.host || server?.port);
|
|
329
401
|
const reportsDirectoryPath = normalizeOutputPath(test?.coverage?.reportsDirectory, projectRoot, workspaceRoot, 'coverage');
|
|
330
402
|
return {
|
|
@@ -345,15 +417,15 @@ function normalizeOutputPath(outputPath, projectRoot, workspaceRoot, path) {
|
|
|
345
417
|
}
|
|
346
418
|
}
|
|
347
419
|
else {
|
|
348
|
-
if ((0,
|
|
349
|
-
return `{workspaceRoot}/${(0,
|
|
420
|
+
if ((0, node_path_1.isAbsolute)(outputPath)) {
|
|
421
|
+
return `{workspaceRoot}/${(0, node_path_1.relative)(workspaceRoot, outputPath)}`;
|
|
350
422
|
}
|
|
351
423
|
else {
|
|
352
424
|
if (outputPath.startsWith('..')) {
|
|
353
|
-
return (0,
|
|
425
|
+
return (0, node_path_1.join)('{workspaceRoot}', (0, node_path_1.join)(projectRoot, outputPath));
|
|
354
426
|
}
|
|
355
427
|
else {
|
|
356
|
-
return (0,
|
|
428
|
+
return (0, node_path_1.join)('{projectRoot}', outputPath);
|
|
357
429
|
}
|
|
358
430
|
}
|
|
359
431
|
}
|
|
@@ -371,10 +443,21 @@ function normalizeOptions(options) {
|
|
|
371
443
|
}
|
|
372
444
|
function checkIfConfigFileShouldBeProject(projectRoot, context) {
|
|
373
445
|
// Do not create a project if package.json and project.json isn't there.
|
|
374
|
-
const siblingFiles = (0,
|
|
446
|
+
const siblingFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot));
|
|
375
447
|
if (!siblingFiles.includes('package.json') &&
|
|
376
448
|
!siblingFiles.includes('project.json')) {
|
|
377
449
|
return false;
|
|
378
450
|
}
|
|
379
451
|
return true;
|
|
380
452
|
}
|
|
453
|
+
async function getTestPathsRelativeToProjectRoot(projectRoot) {
|
|
454
|
+
const fullProjectRoot = (0, node_path_1.join)(devkit_1.workspaceRoot, projectRoot);
|
|
455
|
+
const { createVitest } = await Promise.resolve().then(() => require('vitest/node'));
|
|
456
|
+
const vitest = await createVitest('test', {
|
|
457
|
+
dir: fullProjectRoot,
|
|
458
|
+
filesOnly: true,
|
|
459
|
+
watch: false,
|
|
460
|
+
});
|
|
461
|
+
const relevantTestSpecifications = await vitest.getRelevantTestSpecifications();
|
|
462
|
+
return relevantTestSpecifications.map((ts) => (0, node_path_1.relative)(projectRoot, ts.moduleId));
|
|
463
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/vite/src/utils/generator-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,mBAAmB,EACnB,IAAI,EAGL,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAEtF,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,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;AAC3D,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACrE,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnE,wBAAgB,kCAAkC,CAAC,OAAO,EAAE;IAC1D,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,CAAC;CAC3C,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,CAAC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AO,EACnB,4BAA4B,CAAC,EAAE,WAAW,EAC1C,cAAc,CAAC,EAAE,OAAO,QA4LzB;AAMD,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAQR;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,UAgBhB;AAED,wBAAsB,oCAAoC,CACxD,+BAA+B,EAAE,WAAW,EAC5C,sBAAsB,EAAE,sBAAsB,EAC9C,oBAAoB,EAAE,oBAAoB,iBA4B3C;AAoCD,wBAAsB,0BAA0B,CAAC,WAAW,EAAE,MAAM,iBA4BnE"}
|
|
@@ -282,7 +282,7 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
282
282
|
? ''
|
|
283
283
|
: options.includeLib
|
|
284
284
|
? ` // Configuration for building your library.
|
|
285
|
-
// See: https://
|
|
285
|
+
// See: https://vite.dev/guide/build.html#library-mode
|
|
286
286
|
build: {
|
|
287
287
|
outDir: '${buildOutDir}',
|
|
288
288
|
emptyOutDir: true,
|
|
@@ -370,7 +370,12 @@ ${options.inSourceTests
|
|
|
370
370
|
port: ${options.previewPort ?? 4300},
|
|
371
371
|
host: 'localhost',
|
|
372
372
|
},`;
|
|
373
|
-
const workerOption =
|
|
373
|
+
const workerOption = isTsSolutionSetup
|
|
374
|
+
? ` // Uncomment this if you are using workers.
|
|
375
|
+
// worker: {
|
|
376
|
+
// plugins: [],
|
|
377
|
+
// },`
|
|
378
|
+
: ` // Uncomment this if you are using workers.
|
|
374
379
|
// worker: {
|
|
375
380
|
// plugins: [ nxViteTsPaths() ],
|
|
376
381
|
// },`;
|
|
@@ -430,8 +435,8 @@ async function handleUnsupportedUserProvidedTargetsErrors(userProvidedTargetName
|
|
|
430
435
|
devkit_1.logger.warn(`The custom ${target} target you provided (${userProvidedTargetName}) cannot be converted to use the @nx/vite:${executor} executor.
|
|
431
436
|
However, we found the following ${target} target in your project that can be converted: ${validFoundTargetName}
|
|
432
437
|
|
|
433
|
-
Please note that converting a potentially non-compatible project to use Vite
|
|
434
|
-
your changes before converting a project to use Vite
|
|
438
|
+
Please note that converting a potentially non-compatible project to use Vite may result in unexpected behavior. Always commit
|
|
439
|
+
your changes before converting a project to use Vite, and test the converted project thoroughly before deploying it.
|
|
435
440
|
`);
|
|
436
441
|
const { Confirm } = require('enquirer');
|
|
437
442
|
const prompt = new Confirm({
|
|
@@ -445,8 +450,8 @@ async function handleUnsupportedUserProvidedTargetsErrors(userProvidedTargetName
|
|
|
445
450
|
Please try again, either by providing a different ${target} target or by not providing a target at all (Nx will
|
|
446
451
|
convert the first one it finds, most probably this one: ${validFoundTargetName})
|
|
447
452
|
|
|
448
|
-
Please note that converting a potentially non-compatible project to use Vite
|
|
449
|
-
your changes before converting a project to use Vite
|
|
453
|
+
Please note that converting a potentially non-compatible project to use Vite may result in unexpected behavior. Always commit
|
|
454
|
+
your changes before converting a project to use Vite, and test the converted project thoroughly before deploying it.
|
|
450
455
|
`);
|
|
451
456
|
}
|
|
452
457
|
}
|
|
@@ -5,8 +5,8 @@ export declare const conditionalConfig = "\n /// <reference types=\"vitest\"
|
|
|
5
5
|
export declare const configNoDefineConfig = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\n export default {\n plugins: [\n react(),\n nxViteTsPaths(),\n ],\n };\n ";
|
|
6
6
|
export declare const noBuildOptionsHasTestOption = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\n export default defineConfig({\n \n cacheDir: '../../node_modules/.vitest',\n plugins: [\n react(),\n nxViteTsPaths(),\n ],\n\n test: {\n globals: true,\n environment: 'jsdom',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n },\n\n });\n ";
|
|
7
7
|
export declare const someBuildOptionsSomeTestOption = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\n export default defineConfig({\n plugins: [\n react(),\n nxViteTsPaths(),\n ],\n\n test: {\n my: 'option',\n },\n\n build: {\n my: 'option',\n }\n\n });\n ";
|
|
8
|
-
export declare const hasEverything = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n import dts from 'vite-plugin-dts';\n import { joinPathFragments } from '@nx/devkit';\n\n export default defineConfig({\n cacheDir: '../../node_modules/.vitest',\n plugins: [\n dts({ entryRoot: 'src', tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true }),\n react(),\n nxViteTsPaths(),\n ],\n \n // Configuration for building your library.\n // See: https://
|
|
9
|
-
export declare const buildOption = "\n // Configuration for building your library.\n // See: https://
|
|
8
|
+
export declare const hasEverything = "\n /// <reference types=\"vitest\" />\n import { defineConfig } from 'vite';\n import react from '@vitejs/plugin-react';\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n import dts from 'vite-plugin-dts';\n import { joinPathFragments } from '@nx/devkit';\n\n export default defineConfig({\n cacheDir: '../../node_modules/.vitest',\n plugins: [\n dts({ entryRoot: 'src', tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true }),\n react(),\n nxViteTsPaths(),\n ],\n \n // Configuration for building your library.\n // See: https://vite.dev/guide/build.html#library-mode\n build: {\n lib: {\n // Could also be a dictionary or array of multiple entry points.\n entry: 'src/index.ts',\n name: 'pure-libs-react-vite',\n fileName: 'index',\n // Change this to the formats you want to support.\n // Don't forget to update your package.json as well.\n formats: ['es'],\n },\n rollupOptions: {\n // External packages that should not be bundled into your library.\n external: ['react', 'react-dom', 'react/jsx-runtime'],\n },\n },\n \n test: {\n globals: true,\n environment: 'jsdom',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n },\n });\n ";
|
|
9
|
+
export declare const buildOption = "\n // Configuration for building your library.\n // See: https://vite.dev/guide/build.html#library-mode\n build: {\n lib: {\n // Could also be a dictionary or array of multiple entry points.\n entry: 'src/index.ts',\n name: 'my-app',\n fileName: 'index',\n // Change this to the formats you want to support.\n // Don't forget to update your package.json as well.\n formats: ['es']\n },\n rollupOptions: {\n // External packages that should not be bundled into your library.\n external: ['react', 'react-dom', 'react/jsx-runtime']\n }\n },";
|
|
10
10
|
export declare const buildOptionObject: {
|
|
11
11
|
lib: {
|
|
12
12
|
entry: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-vite-configs.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/utils/test-files/test-vite-configs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,iiBAoBtB,CAAC;AAEN,eAAO,MAAM,gBAAgB,mlBAwBxB,CAAC;AAEN,eAAO,MAAM,qBAAqB,oQAO7B,CAAC;AAEN,eAAO,MAAM,iBAAiB,4YAgBzB,CAAC;AAEN,eAAO,MAAM,oBAAoB,oUAY5B,CAAC;AAEN,eAAO,MAAM,2BAA2B,uiBAqBnC,CAAC;AAEN,eAAO,MAAM,8BAA8B,wbAqBtC,CAAC;AAEN,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"test-vite-configs.d.ts","sourceRoot":"","sources":["../../../../../../packages/vite/src/utils/test-files/test-vite-configs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,iiBAoBtB,CAAC;AAEN,eAAO,MAAM,gBAAgB,mlBAwBxB,CAAC;AAEN,eAAO,MAAM,qBAAqB,oQAO7B,CAAC;AAEN,eAAO,MAAM,iBAAiB,4YAgBzB,CAAC;AAEN,eAAO,MAAM,oBAAoB,oUAY5B,CAAC;AAEN,eAAO,MAAM,2BAA2B,uiBAqBnC,CAAC;AAEN,eAAO,MAAM,8BAA8B,wbAqBtC,CAAC;AAEN,eAAO,MAAM,aAAa,k7CAwCrB,CAAC;AAEN,eAAO,MAAM,WAAW,8nBAiBjB,CAAC;AACR,eAAO,MAAM,iBAAiB;;;;;;;;;;CAU7B,CAAC;AAEF,eAAO,MAAM,UAAU,uJAIhB,CAAC;AAER,eAAO,MAAM,gBAAgB;;;;CAI5B,CAAC;AAEF,eAAO,MAAM,OAAO,UAGnB,CAAC;AAEF,eAAO,MAAM,OAAO,UAAiC,CAAC"}
|
|
@@ -146,7 +146,7 @@ exports.hasEverything = `
|
|
|
146
146
|
],
|
|
147
147
|
|
|
148
148
|
// Configuration for building your library.
|
|
149
|
-
// See: https://
|
|
149
|
+
// See: https://vite.dev/guide/build.html#library-mode
|
|
150
150
|
build: {
|
|
151
151
|
lib: {
|
|
152
152
|
// Could also be a dictionary or array of multiple entry points.
|
|
@@ -172,7 +172,7 @@ exports.hasEverything = `
|
|
|
172
172
|
`;
|
|
173
173
|
exports.buildOption = `
|
|
174
174
|
// Configuration for building your library.
|
|
175
|
-
// See: https://
|
|
175
|
+
// See: https://vite.dev/guide/build.html#library-mode
|
|
176
176
|
build: {
|
|
177
177
|
lib: {
|
|
178
178
|
// Could also be a dictionary or array of multiple entry points.
|