@nx/vite 22.7.0-beta.12 → 22.7.0-beta.13
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "22.7.0-beta.
|
|
3
|
+
"version": "22.7.0-beta.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"migrations": "./migrations.json"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nx/devkit": "22.7.0-beta.
|
|
34
|
+
"@nx/devkit": "22.7.0-beta.13",
|
|
35
35
|
"@phenomnomnominal/tsquery": "~6.1.4",
|
|
36
36
|
"enquirer": "~2.3.6",
|
|
37
|
-
"@nx/js": "22.7.0-beta.
|
|
38
|
-
"@nx/vitest": "22.7.0-beta.
|
|
37
|
+
"@nx/js": "22.7.0-beta.13",
|
|
38
|
+
"@nx/vitest": "22.7.0-beta.13",
|
|
39
39
|
"picomatch": "4.0.4",
|
|
40
40
|
"tsconfig-paths": "^4.1.2",
|
|
41
41
|
"semver": "^7.6.3",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"ajv": "^8.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"nx": "22.7.0-beta.
|
|
46
|
+
"nx": "22.7.0-beta.13"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.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":"
|
|
1
|
+
{"version":3,"file":"nx-tsconfig-paths.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"names":[],"mappings":"AAmBA,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,GA4KzD,MAAM,CA0EZ"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.nxViteTsPaths = nxViteTsPaths;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
|
|
6
|
+
const ts_config_1 = require("@nx/js/src/utils/typescript/ts-config");
|
|
6
7
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
7
8
|
const node_fs_1 = require("node:fs");
|
|
8
9
|
const node_path_1 = require("node:path");
|
|
@@ -84,13 +85,13 @@ function nxViteTsPaths(options = {}) {
|
|
|
84
85
|
throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);
|
|
85
86
|
}
|
|
86
87
|
tsConfigPathsEsm = parsed;
|
|
87
|
-
matchTsPathEsm = (0, tsconfig_paths_1.createMatchPath)(
|
|
88
|
+
matchTsPathEsm = (0, tsconfig_paths_1.createMatchPath)((0, ts_config_1.resolvePathsBaseUrl)(foundTsConfigPath), parsed.paths, options.mainFields);
|
|
88
89
|
const rootLevelTsConfig = getTsConfig((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.base.json'));
|
|
89
90
|
const rootLevelParsed = (0, tsconfig_paths_1.loadConfig)(rootLevelTsConfig);
|
|
90
91
|
logIt('fallback parsed tsconfig: ', rootLevelParsed);
|
|
91
92
|
if (rootLevelParsed.resultType === 'success') {
|
|
92
93
|
tsConfigPathsFallback = rootLevelParsed;
|
|
93
|
-
matchTsPathFallback = (0, tsconfig_paths_1.createMatchPath)(
|
|
94
|
+
matchTsPathFallback = (0, tsconfig_paths_1.createMatchPath)((0, ts_config_1.resolvePathsBaseUrl)(rootLevelTsConfig), rootLevelParsed.paths, ['main', 'module']);
|
|
94
95
|
}
|
|
95
96
|
},
|
|
96
97
|
resolveId(importPath) {
|
|
@@ -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,EASd,MAAM,YAAY,CAAC;
|
|
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;AAmBpB,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,CAgHxD,CAAC;AAEF,eAAO,MAAM,aAAa,kCAAc,CAAC"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -38,6 +38,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
38
38
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
39
39
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
40
40
|
const js_1 = require("@nx/js");
|
|
41
|
+
const internal_1 = require("@nx/js/src/internal");
|
|
41
42
|
const util_1 = require("@nx/js/src/plugins/typescript/util");
|
|
42
43
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
43
44
|
const node_fs_1 = require("node:fs");
|
|
@@ -85,7 +86,11 @@ exports.createNodes = [
|
|
|
85
86
|
const detectedPackageManager = (0, devkit_1.detectPackageManager)(context.workspaceRoot);
|
|
86
87
|
const pmc = (0, devkit_1.getPackageManagerCommand)(detectedPackageManager);
|
|
87
88
|
const lockfile = (0, js_1.getLockFileName)(detectedPackageManager);
|
|
88
|
-
const
|
|
89
|
+
const tsconfigChainsByProjectRoot = collectTsconfigInputsByProjectRoot(projectRoots, context.workspaceRoot);
|
|
90
|
+
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots, { ...normalizedOptions, isUsingTsSolutionSetup }, context, projectRoots.map((root) => [
|
|
91
|
+
lockfile,
|
|
92
|
+
...(tsconfigChainsByProjectRoot.get(root) ?? []),
|
|
93
|
+
]));
|
|
89
94
|
try {
|
|
90
95
|
return await (0, devkit_1.createNodesFromFiles)(async (configFile, _, context, idx) => {
|
|
91
96
|
const projectRoot = (0, node_path_1.dirname)(configFile);
|
|
@@ -104,7 +109,7 @@ exports.createNodes = [
|
|
|
104
109
|
// for different config files.
|
|
105
110
|
const hash = hashes[idx] + configFile;
|
|
106
111
|
const { projectType, metadata, targets } = (targetsCache[hash] ??=
|
|
107
|
-
await buildViteTargets(configFile, projectRoot, normalizedOptions, tsConfigFiles, hasReactRouterConfig, isUsingTsSolutionSetup, context, pmc));
|
|
112
|
+
await buildViteTargets(configFile, projectRoot, normalizedOptions, tsConfigFiles, hasReactRouterConfig, isUsingTsSolutionSetup, context, pmc, tsconfigChainsByProjectRoot.get(projectRoot) ?? []));
|
|
108
113
|
const project = {
|
|
109
114
|
root: projectRoot,
|
|
110
115
|
targets,
|
|
@@ -128,7 +133,7 @@ exports.createNodes = [
|
|
|
128
133
|
},
|
|
129
134
|
];
|
|
130
135
|
exports.createNodesV2 = exports.createNodes;
|
|
131
|
-
async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFiles, hasReactRouterConfig, isUsingTsSolutionSetup, context, pmc) {
|
|
136
|
+
async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFiles, hasReactRouterConfig, isUsingTsSolutionSetup, context, pmc, tsconfigInputs) {
|
|
132
137
|
const absoluteConfigFilePath = (0, devkit_1.joinPathFragments)(context.workspaceRoot, configFilePath);
|
|
133
138
|
// Workaround for the `build$3 is not a function` error that we sometimes see in agents.
|
|
134
139
|
// This should be removed later once we address the issue properly
|
|
@@ -175,7 +180,9 @@ async function buildViteTargets(configFilePath, projectRoot, options, tsConfigFi
|
|
|
175
180
|
const targets = {};
|
|
176
181
|
// if file is vitest.config or vite.config has definition for test, create targets for test and/or atomized tests
|
|
177
182
|
if (configFilePath.includes('vitest.config') || hasTest) {
|
|
178
|
-
|
|
183
|
+
const isTypecheckEnabled = !!viteBuildConfig?.test?.typecheck
|
|
184
|
+
?.enabled;
|
|
185
|
+
targets[options.testTargetName] = await testTarget(namedInputs, testOutputs, projectRoot, pmc, isTypecheckEnabled, tsconfigInputs);
|
|
179
186
|
if (options.ciTargetName) {
|
|
180
187
|
const groupName = options.ciGroupName ?? (0, plugins_1.deriveGroupNameFromTarget)(options.ciTargetName);
|
|
181
188
|
const targetGroup = [];
|
|
@@ -406,7 +413,8 @@ function previewTarget(projectRoot, buildTargetName, pmc) {
|
|
|
406
413
|
};
|
|
407
414
|
return targetConfig;
|
|
408
415
|
}
|
|
409
|
-
async function testTarget(namedInputs, outputs, projectRoot, pmc) {
|
|
416
|
+
async function testTarget(namedInputs, outputs, projectRoot, pmc, isTypecheckEnabled, tsconfigInputs) {
|
|
417
|
+
const depOutputsGlob = isTypecheckEnabled ? '**/*.{js,d.ts}' : '**/*.js';
|
|
410
418
|
return {
|
|
411
419
|
command: `vitest`,
|
|
412
420
|
options: { cwd: (0, devkit_1.joinPathFragments)(projectRoot) },
|
|
@@ -415,10 +423,15 @@ async function testTarget(namedInputs, outputs, projectRoot, pmc) {
|
|
|
415
423
|
...('production' in namedInputs
|
|
416
424
|
? ['default', '^production']
|
|
417
425
|
: ['default', '^default']),
|
|
426
|
+
...tsconfigInputs.map((f) => ({
|
|
427
|
+
json: `{workspaceRoot}/${f}`,
|
|
428
|
+
fields: ['compilerOptions'],
|
|
429
|
+
})),
|
|
418
430
|
{
|
|
419
431
|
externalDependencies: ['vitest'],
|
|
420
432
|
},
|
|
421
433
|
{ env: 'CI' },
|
|
434
|
+
{ dependentTasksOutputFiles: depOutputsGlob, transitive: true },
|
|
422
435
|
],
|
|
423
436
|
outputs,
|
|
424
437
|
metadata: {
|
|
@@ -506,6 +519,83 @@ function normalizeOptions(options) {
|
|
|
506
519
|
options.typecheckTargetName ??= 'typecheck';
|
|
507
520
|
return options;
|
|
508
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* Collects tsconfig files that Vite's esbuild-based config bundler reads
|
|
524
|
+
* but are outside the project root (and thus not covered by `default`).
|
|
525
|
+
*
|
|
526
|
+
* Vite < 8 uses esbuild's Build API to bundle config files. esbuild walks
|
|
527
|
+
* UP from the entry point, reading and parsing every `tsconfig.json` in
|
|
528
|
+
* every ancestor directory plus their `extends` chains. Vite >= 8 uses
|
|
529
|
+
* rolldown with `tsconfig: false`, but pnpm can resolve different Vite
|
|
530
|
+
* versions per project, so we always collect — the walk is cheap (cached
|
|
531
|
+
* JSON reads) and over-declaring inputs for Vite 8 projects is harmless.
|
|
532
|
+
*/
|
|
533
|
+
function collectTsconfigInputsByProjectRoot(projectRoots, workspaceRoot) {
|
|
534
|
+
const jsonCache = new Map();
|
|
535
|
+
const result = new Map();
|
|
536
|
+
const rootTsConfigName = (0, js_1.getRootTsConfigFileName)();
|
|
537
|
+
for (const projectRoot of projectRoots) {
|
|
538
|
+
if (projectRoot === '.')
|
|
539
|
+
continue;
|
|
540
|
+
const outside = [];
|
|
541
|
+
const seen = new Set();
|
|
542
|
+
const projectPrefix = `${projectRoot}/`;
|
|
543
|
+
const collect = (absolutePath) => {
|
|
544
|
+
const wsRelative = (0, node_path_1.relative)(workspaceRoot, absolutePath)
|
|
545
|
+
.split(node_path_1.sep)
|
|
546
|
+
.join('/');
|
|
547
|
+
if (seen.has(wsRelative))
|
|
548
|
+
return;
|
|
549
|
+
seen.add(wsRelative);
|
|
550
|
+
if (wsRelative.startsWith('../') || wsRelative === '..')
|
|
551
|
+
return;
|
|
552
|
+
if (wsRelative.startsWith('node_modules/') ||
|
|
553
|
+
wsRelative.includes('/node_modules/'))
|
|
554
|
+
return;
|
|
555
|
+
if (wsRelative === projectRoot || wsRelative.startsWith(projectPrefix))
|
|
556
|
+
return;
|
|
557
|
+
if (wsRelative === rootTsConfigName)
|
|
558
|
+
return;
|
|
559
|
+
outside.push(wsRelative);
|
|
560
|
+
};
|
|
561
|
+
// Walk the project tsconfig's extends chain
|
|
562
|
+
const projectTsconfig = (0, node_path_1.join)(workspaceRoot, projectRoot, 'tsconfig.json');
|
|
563
|
+
if ((0, node_fs_1.existsSync)(projectTsconfig)) {
|
|
564
|
+
(0, internal_1.walkTsconfigExtendsChain)(projectTsconfig, (absPath) => {
|
|
565
|
+
collect(absPath);
|
|
566
|
+
return 'continue';
|
|
567
|
+
}, { jsonCache });
|
|
568
|
+
}
|
|
569
|
+
// Walk UP ancestor directories — esbuild reads every tsconfig.json
|
|
570
|
+
// between the entry point and the filesystem root.
|
|
571
|
+
let dir = (0, node_path_1.dirname)(projectRoot);
|
|
572
|
+
while (dir && dir !== '.') {
|
|
573
|
+
const ancestorTsconfig = (0, node_path_1.join)(workspaceRoot, dir, 'tsconfig.json');
|
|
574
|
+
if ((0, node_fs_1.existsSync)(ancestorTsconfig)) {
|
|
575
|
+
(0, internal_1.walkTsconfigExtendsChain)(ancestorTsconfig, (absPath) => {
|
|
576
|
+
collect(absPath);
|
|
577
|
+
return 'continue';
|
|
578
|
+
}, { jsonCache });
|
|
579
|
+
}
|
|
580
|
+
const parent = (0, node_path_1.dirname)(dir);
|
|
581
|
+
if (parent === dir)
|
|
582
|
+
break;
|
|
583
|
+
dir = parent;
|
|
584
|
+
}
|
|
585
|
+
// Check the workspace root itself (dirname loop above stops at '.')
|
|
586
|
+
const rootTsconfig = (0, node_path_1.join)(workspaceRoot, 'tsconfig.json');
|
|
587
|
+
if ((0, node_fs_1.existsSync)(rootTsconfig)) {
|
|
588
|
+
(0, internal_1.walkTsconfigExtendsChain)(rootTsconfig, (absPath) => {
|
|
589
|
+
collect(absPath);
|
|
590
|
+
return 'continue';
|
|
591
|
+
}, { jsonCache });
|
|
592
|
+
}
|
|
593
|
+
if (outside.length > 0) {
|
|
594
|
+
result.set(projectRoot, outside);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return result;
|
|
598
|
+
}
|
|
509
599
|
function checkIfConfigFileShouldBeProject(projectRoot, context) {
|
|
510
600
|
// Do not create a project if package.json and project.json isn't there.
|
|
511
601
|
const siblingFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot));
|