@hublo/sentinel 1.6.0-alpha.5 → 1.7.0-alpha.0
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/dist/bin/sentinel.js +4 -4
- package/dist/{chunk-L3TOPT5G.js → chunk-EVGG55ZO.js} +88 -57
- package/dist/{chunk-SWWQ7X7B.js → chunk-POZDYETY.js} +22 -12
- package/dist/{chunk-SWWQ7X7B.js.map → chunk-POZDYETY.js.map} +1 -1
- package/dist/{chunk-EESVRILJ.js → chunk-VVEKPCRY.js} +13 -3
- package/dist/chunk-VVEKPCRY.js.map +1 -0
- package/dist/{chunk-RZJWYVVG.js → chunk-WMBXYYLD.js} +90 -30
- package/dist/chunk-ZVHUG6CA.js +88 -0
- package/dist/chunk-ZVHUG6CA.js.map +1 -0
- package/dist/index.js +3 -3
- package/dist/roles/build/nest/toolchain.d.ts +1 -1
- package/dist/roles/build/nest/toolchain.js +6 -3
- package/dist/roles/build/nest/toolchain.js.map +1 -1
- package/dist/roles/test/nest/toolchain.d.ts +1 -1
- package/dist/roles/test/nest/toolchain.js +3 -3
- package/dist/roles/test/react/toolchain.js +3 -3
- package/dist/roles/test/shared-test-config.d.ts +1 -1
- package/dist/roles/test/shared-test-config.js +3 -3
- package/dist/{tsconfig-aliases-Ce6axdJ4.d.ts → tsconfig-aliases-C_PxuZni.d.ts} +17 -2
- package/dist/{validate-LJHUF3OQ.js → validate-VWP6YZP5.js} +2 -2
- package/docs/build-adoption.md +7 -0
- package/docs/test-adoption.md +8 -1
- package/docs/validating-a-change.md +74 -0
- package/package.json +1 -1
- package/dist/chunk-EESVRILJ.js.map +0 -1
- package/dist/chunk-QXFCZON7.js +0 -16
- package/dist/chunk-QXFCZON7.js.map +0 -1
package/dist/bin/sentinel.js
CHANGED
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
presetNotInstalledYet,
|
|
13
13
|
registerAdapters,
|
|
14
14
|
resolve
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-WMBXYYLD.js";
|
|
16
16
|
import {
|
|
17
17
|
resolveContext
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-EVGG55ZO.js";
|
|
19
19
|
import {
|
|
20
20
|
ensureWorkspacePrep,
|
|
21
21
|
findWorkspaceRoot,
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
} from "../chunk-7E6YTTAK.js";
|
|
37
37
|
import "../chunk-4EIY7TTR.js";
|
|
38
38
|
import "../chunk-O7REVMOC.js";
|
|
39
|
-
import "../chunk-
|
|
39
|
+
import "../chunk-ZVHUG6CA.js";
|
|
40
40
|
|
|
41
41
|
// bin/sentinel.ts
|
|
42
42
|
import { program } from "commander";
|
|
@@ -584,7 +584,7 @@ async function runValidate(ctx) {
|
|
|
584
584
|
);
|
|
585
585
|
}
|
|
586
586
|
if (!ctx.targets.includes("test")) return 1;
|
|
587
|
-
const { validateModuleTests } = await import("../validate-
|
|
587
|
+
const { validateModuleTests } = await import("../validate-VWP6YZP5.js");
|
|
588
588
|
const outcomes = modules.flatMap(
|
|
589
589
|
(module) => validateModuleTests(module.name, module.root)
|
|
590
590
|
);
|
|
@@ -11,8 +11,11 @@ import {
|
|
|
11
11
|
matchesTsconfigPattern
|
|
12
12
|
} from "./chunk-O7REVMOC.js";
|
|
13
13
|
import {
|
|
14
|
+
WORKSPACE_TSCONFIG,
|
|
15
|
+
chainPaths,
|
|
16
|
+
effectivePaths,
|
|
14
17
|
parseJsonc
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-ZVHUG6CA.js";
|
|
16
19
|
|
|
17
20
|
// src/core/base-adapter.ts
|
|
18
21
|
var BaseAdapter = class {
|
|
@@ -785,7 +788,7 @@ function resolveVitest(cwd) {
|
|
|
785
788
|
|
|
786
789
|
// src/roles/test/adapters/vitest/vitest.adapter.ts
|
|
787
790
|
import { spawnSync } from "node:child_process";
|
|
788
|
-
import { existsSync as existsSync25, mkdtempSync as mkdtempSync3, readFileSync as
|
|
791
|
+
import { existsSync as existsSync25, mkdtempSync as mkdtempSync3, readFileSync as readFileSync25, writeFileSync as writeFileSync2 } from "node:fs";
|
|
789
792
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
790
793
|
import { isAbsolute as isAbsolute2, join as join32, relative as relative7, resolve as resolve10 } from "node:path";
|
|
791
794
|
|
|
@@ -995,12 +998,12 @@ function rewriteToolchainImports(toolchain, source, fileName) {
|
|
|
995
998
|
}
|
|
996
999
|
|
|
997
1000
|
// src/roles/test/jest-migration.ts
|
|
998
|
-
import { existsSync as existsSync19, readFileSync as
|
|
1001
|
+
import { existsSync as existsSync19, readFileSync as readFileSync20, readdirSync as readdirSync6 } from "node:fs";
|
|
999
1002
|
import { createRequire as createRequire5 } from "node:module";
|
|
1000
1003
|
import { dirname as dirname12, join as join25, relative as relative6 } from "node:path";
|
|
1001
1004
|
|
|
1002
1005
|
// src/roles/test/codemod/migrate-module.ts
|
|
1003
|
-
import { readdirSync as readdirSync4, readFileSync as
|
|
1006
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync15, statSync as statSync5 } from "node:fs";
|
|
1004
1007
|
import { join as join18 } from "node:path";
|
|
1005
1008
|
import { parseSync as parseSync9 } from "oxc-parser";
|
|
1006
1009
|
|
|
@@ -3595,37 +3598,40 @@ function resolveContext(cwd, opts) {
|
|
|
3595
3598
|
}
|
|
3596
3599
|
|
|
3597
3600
|
// src/roles/test/codemod/workspace-specifier.ts
|
|
3598
|
-
import { existsSync as existsSync13
|
|
3601
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
3599
3602
|
import { join as join15, relative as relative2, resolve as resolve6 } from "node:path";
|
|
3600
3603
|
var EXTENSIONS = ["", ".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", "/index.ts", "/index.js"];
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
if (!existsSync13(file)) return [];
|
|
3604
|
-
let paths;
|
|
3604
|
+
var SPEC_TSCONFIGS = ["tsconfig.spec.json", "tsconfig.app.json", "tsconfig.json"];
|
|
3605
|
+
function pathsFor(workspaceRoot, moduleRoot) {
|
|
3605
3606
|
try {
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
)
|
|
3607
|
+
if (moduleRoot !== void 0) return effectivePaths(moduleRoot, workspaceRoot, SPEC_TSCONFIGS);
|
|
3608
|
+
const file = join15(workspaceRoot, WORKSPACE_TSCONFIG);
|
|
3609
|
+
if (!existsSync13(file)) return void 0;
|
|
3610
|
+
const found = chainPaths(file);
|
|
3611
|
+
return found && { ...found, fromWorkspaceFallback: false };
|
|
3610
3612
|
} catch {
|
|
3611
|
-
return
|
|
3613
|
+
return void 0;
|
|
3612
3614
|
}
|
|
3615
|
+
}
|
|
3616
|
+
function pathEntries(workspaceRoot, moduleRoot) {
|
|
3617
|
+
const found = pathsFor(workspaceRoot, moduleRoot);
|
|
3618
|
+
if (found === void 0) return [];
|
|
3613
3619
|
const entries = [];
|
|
3614
|
-
for (const [key, targets] of Object.entries(paths
|
|
3620
|
+
for (const [key, targets] of Object.entries(found.paths)) {
|
|
3615
3621
|
const target = targets[0];
|
|
3616
3622
|
if (target === void 0) continue;
|
|
3617
3623
|
const wildcard = key.endsWith("/*") && target.endsWith("/*");
|
|
3618
3624
|
entries.push({
|
|
3619
3625
|
key: wildcard ? key.slice(0, -2) : key,
|
|
3620
|
-
target: resolve6(
|
|
3626
|
+
target: resolve6(found.baseDirectory, wildcard ? target.slice(0, -2) : target),
|
|
3621
3627
|
wildcard
|
|
3622
3628
|
});
|
|
3623
3629
|
}
|
|
3624
3630
|
return entries.sort((left, right) => right.target.length - left.target.length);
|
|
3625
3631
|
}
|
|
3626
|
-
function workspaceSpecifier(workspaceRoot, file) {
|
|
3632
|
+
function workspaceSpecifier(workspaceRoot, file, moduleRoot) {
|
|
3627
3633
|
const absolute = resolve6(file);
|
|
3628
|
-
for (const entry of pathEntries(workspaceRoot)) {
|
|
3634
|
+
for (const entry of pathEntries(workspaceRoot, moduleRoot)) {
|
|
3629
3635
|
if (!entry.wildcard) {
|
|
3630
3636
|
if (EXTENSIONS.some((extension) => `${entry.target}${extension}` === absolute)) {
|
|
3631
3637
|
return entry.key;
|
|
@@ -3658,7 +3664,7 @@ function importable(written, fileName, workspaceRoot) {
|
|
|
3658
3664
|
const target = resolve7(fileDir, written);
|
|
3659
3665
|
if (target.startsWith(`${moduleRoot}/`)) return written;
|
|
3660
3666
|
if (workspaceRoot === void 0) return void 0;
|
|
3661
|
-
return workspaceSpecifier(workspaceRoot, target);
|
|
3667
|
+
return workspaceSpecifier(workspaceRoot, target, moduleRoot);
|
|
3662
3668
|
}
|
|
3663
3669
|
function statement(fileName, source, node, specifier, written) {
|
|
3664
3670
|
if (node.type === "ExpressionStatement") return `import '${specifier}'`;
|
|
@@ -3769,7 +3775,7 @@ function rewriteMockFactoryGenerics(source, program) {
|
|
|
3769
3775
|
}
|
|
3770
3776
|
|
|
3771
3777
|
// src/roles/test/codemod/spy-on-internal-call.ts
|
|
3772
|
-
import { readFileSync as
|
|
3778
|
+
import { readFileSync as readFileSync13, statSync as statSync3 } from "node:fs";
|
|
3773
3779
|
import { dirname as dirname7, join as join16, relative as relative3, resolve as resolve8 } from "node:path";
|
|
3774
3780
|
import { parseSync as parseSync7 } from "oxc-parser";
|
|
3775
3781
|
function resolveRelative2(fromFile, specifier) {
|
|
@@ -3790,7 +3796,7 @@ function resolveRelative2(fromFile, specifier) {
|
|
|
3790
3796
|
}
|
|
3791
3797
|
function read(path) {
|
|
3792
3798
|
try {
|
|
3793
|
-
return
|
|
3799
|
+
return readFileSync13(path, "utf8");
|
|
3794
3800
|
} catch {
|
|
3795
3801
|
return void 0;
|
|
3796
3802
|
}
|
|
@@ -4345,7 +4351,7 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
4345
4351
|
*/
|
|
4346
4352
|
...statics.refusals.map((specifier) => ({
|
|
4347
4353
|
binding: specifier,
|
|
4348
|
-
reason: `\`require('${specifier}')\` reaches another project, and \`
|
|
4354
|
+
reason: `\`require('${specifier}')\` reaches another project, and no \`paths\` entry covers it, in this module's tsconfig or in \`tsconfig.base.json\`. A static import of a relative path is refused by nx, and \`await import()\` would make it a dynamic dependency, which forbids every static import of that project across this module. Add a \`paths\` entry for it, or move the file inside this project.`
|
|
4349
4355
|
})),
|
|
4350
4356
|
...fakeTimers.refusals,
|
|
4351
4357
|
...hoist.refusals,
|
|
@@ -4362,7 +4368,7 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
4362
4368
|
}
|
|
4363
4369
|
|
|
4364
4370
|
// src/roles/test/codemod/test-support-files.ts
|
|
4365
|
-
import { existsSync as existsSync14, readFileSync as
|
|
4371
|
+
import { existsSync as existsSync14, readFileSync as readFileSync14, readdirSync as readdirSync3, statSync as statSync4 } from "node:fs";
|
|
4366
4372
|
import { dirname as dirname9, join as join17, relative as relative4, resolve as resolve9 } from "node:path";
|
|
4367
4373
|
var THE_SHIM_CANNOT_ANSWER = [/\brequire\s*\(/, /\bjest\.(?:fn|Mock|SpyInstance)\s*</];
|
|
4368
4374
|
var SKIPPED = /* @__PURE__ */ new Set(["node_modules", "dist", "coverage", ".git", ".vite"]);
|
|
@@ -4417,7 +4423,7 @@ function moduleSources(cwd) {
|
|
|
4417
4423
|
}
|
|
4418
4424
|
function read2(path) {
|
|
4419
4425
|
try {
|
|
4420
|
-
return
|
|
4426
|
+
return readFileSync14(path, "utf8");
|
|
4421
4427
|
} catch {
|
|
4422
4428
|
return void 0;
|
|
4423
4429
|
}
|
|
@@ -4475,7 +4481,7 @@ function parse4(fileName, source) {
|
|
|
4475
4481
|
}
|
|
4476
4482
|
function read3(path) {
|
|
4477
4483
|
try {
|
|
4478
|
-
return
|
|
4484
|
+
return readFileSync15(path, "utf8");
|
|
4479
4485
|
} catch {
|
|
4480
4486
|
return void 0;
|
|
4481
4487
|
}
|
|
@@ -4604,7 +4610,7 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4604
4610
|
}
|
|
4605
4611
|
|
|
4606
4612
|
// src/roles/test/nest/generate-config.ts
|
|
4607
|
-
import { readdirSync as readdirSync5, readFileSync as
|
|
4613
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync16, statSync as statSync6 } from "node:fs";
|
|
4608
4614
|
import { join as join19, relative as relative5 } from "node:path";
|
|
4609
4615
|
import { parseSync as parseSync10 } from "oxc-parser";
|
|
4610
4616
|
var NEST_TEST_PRESET_SPECIFIER = "@hublo/sentinel/test/nest";
|
|
@@ -4666,7 +4672,7 @@ function readModuleTraits(cwd) {
|
|
|
4666
4672
|
if (!/\.tsx?$/.test(entry)) continue;
|
|
4667
4673
|
let source;
|
|
4668
4674
|
try {
|
|
4669
|
-
source =
|
|
4675
|
+
source = readFileSync16(path, "utf8");
|
|
4670
4676
|
} catch {
|
|
4671
4677
|
continue;
|
|
4672
4678
|
}
|
|
@@ -4807,7 +4813,7 @@ ${overrides.join("\n")}
|
|
|
4807
4813
|
}
|
|
4808
4814
|
|
|
4809
4815
|
// src/roles/test/nest/read-jest-config.ts
|
|
4810
|
-
import { existsSync as existsSync15, readFileSync as
|
|
4816
|
+
import { existsSync as existsSync15, readFileSync as readFileSync17 } from "node:fs";
|
|
4811
4817
|
import { join as join20 } from "node:path";
|
|
4812
4818
|
var CARRIED = [
|
|
4813
4819
|
"testEnvironment",
|
|
@@ -5029,7 +5035,7 @@ function readJestConfig(cwd, named) {
|
|
|
5029
5035
|
if (file === void 0 || !existsSync15(join20(cwd, file))) return void 0;
|
|
5030
5036
|
let source;
|
|
5031
5037
|
try {
|
|
5032
|
-
source =
|
|
5038
|
+
source = readFileSync17(join20(cwd, file), "utf8");
|
|
5033
5039
|
} catch {
|
|
5034
5040
|
return { file, refusals: [`${file} could not be read`], notes: [] };
|
|
5035
5041
|
}
|
|
@@ -5161,7 +5167,7 @@ import { existsSync as existsSync18 } from "node:fs";
|
|
|
5161
5167
|
import { dirname as dirname11, join as join24 } from "node:path";
|
|
5162
5168
|
|
|
5163
5169
|
// src/roles/format/read-adoption.ts
|
|
5164
|
-
import { existsSync as existsSync17, readFileSync as
|
|
5170
|
+
import { existsSync as existsSync17, readFileSync as readFileSync18 } from "node:fs";
|
|
5165
5171
|
import { join as join22 } from "node:path";
|
|
5166
5172
|
|
|
5167
5173
|
// src/roles/format/config-policy.ts
|
|
@@ -5273,7 +5279,7 @@ function readFormatAdoption(cwd) {
|
|
|
5273
5279
|
if (!existsSync17(path)) return NOT_ADOPTED(null);
|
|
5274
5280
|
let parsed;
|
|
5275
5281
|
try {
|
|
5276
|
-
parsed = parseJsonc(
|
|
5282
|
+
parsed = parseJsonc(readFileSync18(path, "utf8"), FORMAT_CONFIG_FILE);
|
|
5277
5283
|
} catch (error) {
|
|
5278
5284
|
const reason = error instanceof Error ? error.message : String(error);
|
|
5279
5285
|
return NOT_ADOPTED(FORMAT_CONFIG_FILE, `${FORMAT_CONFIG_FILE} could not be parsed (${reason})`);
|
|
@@ -5317,7 +5323,7 @@ function readFormatAdoption(cwd) {
|
|
|
5317
5323
|
}
|
|
5318
5324
|
|
|
5319
5325
|
// src/roles/format/resolve-oxfmt.ts
|
|
5320
|
-
import { readFileSync as
|
|
5326
|
+
import { readFileSync as readFileSync19 } from "node:fs";
|
|
5321
5327
|
import { createRequire as createRequire4 } from "node:module";
|
|
5322
5328
|
import { dirname as dirname10, join as join23 } from "node:path";
|
|
5323
5329
|
function resolveOxfmt(cwd) {
|
|
@@ -5349,7 +5355,7 @@ function readConfigSchema() {
|
|
|
5349
5355
|
try {
|
|
5350
5356
|
const manifest = createRequire4(import.meta.url).resolve("oxfmt/package.json");
|
|
5351
5357
|
const schemaPath = join23(dirname10(manifest), "configuration_schema.json");
|
|
5352
|
-
return JSON.parse(
|
|
5358
|
+
return JSON.parse(readFileSync19(schemaPath, "utf8"));
|
|
5353
5359
|
} catch {
|
|
5354
5360
|
return void 0;
|
|
5355
5361
|
}
|
|
@@ -5409,7 +5415,7 @@ function specTypesOperation(cwd) {
|
|
|
5409
5415
|
let config;
|
|
5410
5416
|
try {
|
|
5411
5417
|
config = parseJsonc(
|
|
5412
|
-
|
|
5418
|
+
readFileSync20(path, "utf8"),
|
|
5413
5419
|
SPEC_TSCONFIG
|
|
5414
5420
|
);
|
|
5415
5421
|
} catch {
|
|
@@ -5433,7 +5439,7 @@ function specTypesCleanupOperation(cwd) {
|
|
|
5433
5439
|
let config;
|
|
5434
5440
|
try {
|
|
5435
5441
|
config = parseJsonc(
|
|
5436
|
-
|
|
5442
|
+
readFileSync20(path, "utf8"),
|
|
5437
5443
|
SPEC_TSCONFIG
|
|
5438
5444
|
);
|
|
5439
5445
|
} catch {
|
|
@@ -5482,7 +5488,7 @@ function helpersStillCallingJest(cwd) {
|
|
|
5482
5488
|
if (/^(jest|vitest)\./.test(entry.name)) continue;
|
|
5483
5489
|
let source;
|
|
5484
5490
|
try {
|
|
5485
|
-
source =
|
|
5491
|
+
source = readFileSync20(path, "utf8");
|
|
5486
5492
|
} catch {
|
|
5487
5493
|
continue;
|
|
5488
5494
|
}
|
|
@@ -5519,7 +5525,7 @@ function tsconfigFileListOperations(cwd) {
|
|
|
5519
5525
|
let config;
|
|
5520
5526
|
try {
|
|
5521
5527
|
config = parseJsonc(
|
|
5522
|
-
|
|
5528
|
+
readFileSync20(join25(cwd, name), "utf8"),
|
|
5523
5529
|
name
|
|
5524
5530
|
);
|
|
5525
5531
|
} catch {
|
|
@@ -5938,7 +5944,7 @@ import { existsSync as existsSync24 } from "node:fs";
|
|
|
5938
5944
|
import { join as join31 } from "node:path";
|
|
5939
5945
|
|
|
5940
5946
|
// src/roles/lint/module-baseline.ts
|
|
5941
|
-
import { existsSync as existsSync20, readFileSync as
|
|
5947
|
+
import { existsSync as existsSync20, readFileSync as readFileSync21 } from "node:fs";
|
|
5942
5948
|
import { join as join26 } from "node:path";
|
|
5943
5949
|
|
|
5944
5950
|
// src/roles/lint/oxlint-rule-owners.json
|
|
@@ -6617,8 +6623,38 @@ function holdsFrom(errorCounts, presetSpellings = /* @__PURE__ */ new Map()) {
|
|
|
6617
6623
|
}
|
|
6618
6624
|
return [...counts].map(([rule, count]) => ({ rule, count })).sort((left, right) => right.count - left.count || left.rule.localeCompare(right.rule));
|
|
6619
6625
|
}
|
|
6620
|
-
|
|
6621
|
-
|
|
6626
|
+
var isEnforced = (entry) => (Array.isArray(entry) ? entry[0] : entry) === "error";
|
|
6627
|
+
var atWarn = (entry) => Array.isArray(entry) && entry.length > 1 ? ["warn", ...entry.slice(1)] : "warn";
|
|
6628
|
+
function heldIn(rules, holds) {
|
|
6629
|
+
const byRule = new Map(
|
|
6630
|
+
Object.entries(rules).map(([rule, entry]) => [canonicalRuleName(rule), { rule, entry }])
|
|
6631
|
+
);
|
|
6632
|
+
return holds.flatMap((hold) => {
|
|
6633
|
+
const found = byRule.get(canonicalRuleName(hold.rule));
|
|
6634
|
+
return found && isEnforced(found.entry) ? [[found.rule, atWarn(found.entry)]] : [];
|
|
6635
|
+
});
|
|
6636
|
+
}
|
|
6637
|
+
function renderBaseline(holds, version, preset = { rules: {} }) {
|
|
6638
|
+
const scoped = (preset.overrides ?? []).map(({ files, rules: rules2 }) => ({ files, rules: Object.fromEntries(heldIn(rules2, holds)) })).filter(({ rules: rules2 }) => Object.keys(rules2).length > 0);
|
|
6639
|
+
const heldInOverride = new Set(
|
|
6640
|
+
scoped.flatMap(({ rules: rules2 }) => Object.keys(rules2).map((rule) => canonicalRuleName(rule)))
|
|
6641
|
+
);
|
|
6642
|
+
const topLevel = new Map(
|
|
6643
|
+
heldIn(preset.rules, holds).map((held) => [canonicalRuleName(held[0]), held])
|
|
6644
|
+
);
|
|
6645
|
+
const rules = Object.fromEntries(
|
|
6646
|
+
holds.flatMap(({ rule }) => {
|
|
6647
|
+
const canonical = canonicalRuleName(rule);
|
|
6648
|
+
const held = topLevel.get(canonical);
|
|
6649
|
+
if (held) return [held];
|
|
6650
|
+
return heldInOverride.has(canonical) ? [] : [[rule, "warn"]];
|
|
6651
|
+
})
|
|
6652
|
+
);
|
|
6653
|
+
const body = JSON.stringify(
|
|
6654
|
+
{ rules, ...scoped.length > 0 ? { overrides: scoped } : {} },
|
|
6655
|
+
null,
|
|
6656
|
+
2
|
|
6657
|
+
).slice(2);
|
|
6622
6658
|
return [
|
|
6623
6659
|
"{",
|
|
6624
6660
|
` // Written by @hublo/sentinel@${version}. Do not edit by hand: \`sentinel --init --lint\``,
|
|
@@ -6635,10 +6671,7 @@ function renderBaseline(holds, version) {
|
|
|
6635
6671
|
" //",
|
|
6636
6672
|
" // `sentinel --inspect --lint` lists what is held; `sentinel --run --lint --json` counts",
|
|
6637
6673
|
" // what is left, per rule. Fix them and re-run `--init --lint` to get the severity back.",
|
|
6638
|
-
|
|
6639
|
-
entries,
|
|
6640
|
-
" }",
|
|
6641
|
-
"}",
|
|
6674
|
+
body,
|
|
6642
6675
|
""
|
|
6643
6676
|
].join("\n");
|
|
6644
6677
|
}
|
|
@@ -6657,11 +6690,9 @@ function heldRules(cwd) {
|
|
|
6657
6690
|
const path = join26(cwd, LINT_BASELINE_FILE);
|
|
6658
6691
|
if (!existsSync20(path)) return [];
|
|
6659
6692
|
try {
|
|
6660
|
-
const parsed = parseJsonc(
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
);
|
|
6664
|
-
return Object.keys(parsed.rules ?? {});
|
|
6693
|
+
const parsed = parseJsonc(readFileSync21(path, "utf8"), LINT_BASELINE_FILE);
|
|
6694
|
+
const scoped = (parsed.overrides ?? []).flatMap((override) => Object.keys(override.rules ?? {}));
|
|
6695
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(parsed.rules ?? {}), ...scoped])];
|
|
6665
6696
|
} catch {
|
|
6666
6697
|
return [];
|
|
6667
6698
|
}
|
|
@@ -6707,11 +6738,11 @@ function lintTarget() {
|
|
|
6707
6738
|
}
|
|
6708
6739
|
|
|
6709
6740
|
// src/roles/lint/read-adoption.ts
|
|
6710
|
-
import { readFileSync as
|
|
6741
|
+
import { readFileSync as readFileSync24 } from "node:fs";
|
|
6711
6742
|
import { join as join29 } from "node:path";
|
|
6712
6743
|
|
|
6713
6744
|
// src/core/config/read-adoption.ts
|
|
6714
|
-
import { existsSync as existsSync22, readFileSync as
|
|
6745
|
+
import { existsSync as existsSync22, readFileSync as readFileSync23 } from "node:fs";
|
|
6715
6746
|
import { join as join28 } from "node:path";
|
|
6716
6747
|
|
|
6717
6748
|
// src/core/config/owned-keys.ts
|
|
@@ -6727,12 +6758,12 @@ function localOnlyKeys(config, permitted, presetSets) {
|
|
|
6727
6758
|
}
|
|
6728
6759
|
|
|
6729
6760
|
// src/core/config/resolve-config-target.ts
|
|
6730
|
-
import { existsSync as existsSync21, readFileSync as
|
|
6761
|
+
import { existsSync as existsSync21, readFileSync as readFileSync22 } from "node:fs";
|
|
6731
6762
|
import { join as join27 } from "node:path";
|
|
6732
6763
|
function readExtends(absolutePath) {
|
|
6733
6764
|
let parsed;
|
|
6734
6765
|
try {
|
|
6735
|
-
parsed = parseJsonc(
|
|
6766
|
+
parsed = parseJsonc(readFileSync22(absolutePath, "utf8"), absolutePath);
|
|
6736
6767
|
} catch {
|
|
6737
6768
|
return [];
|
|
6738
6769
|
}
|
|
@@ -6785,7 +6816,7 @@ function readAdoption(cwd, options) {
|
|
|
6785
6816
|
}
|
|
6786
6817
|
let parsed;
|
|
6787
6818
|
try {
|
|
6788
|
-
parsed = parseJsonc(
|
|
6819
|
+
parsed = parseJsonc(readFileSync23(join28(cwd, target.path), "utf8"), target.path);
|
|
6789
6820
|
} catch (error) {
|
|
6790
6821
|
const reason = error instanceof Error ? error.message : String(error);
|
|
6791
6822
|
return NOT_ADOPTED2(target.path, `${target.path} could not be parsed (${reason})`);
|
|
@@ -9469,7 +9500,7 @@ function readModuleAdditions(cwd) {
|
|
|
9469
9500
|
if (preset === void 0 || adoption.configFile === null) return NO_ADDITIONS;
|
|
9470
9501
|
try {
|
|
9471
9502
|
const config = parseJsonc(
|
|
9472
|
-
|
|
9503
|
+
readFileSync24(join29(cwd, adoption.configFile), "utf8"),
|
|
9473
9504
|
adoption.configFile
|
|
9474
9505
|
);
|
|
9475
9506
|
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
@@ -9560,7 +9591,7 @@ var FORMATTABLE = /\.(m|c)?(j|t)sx?$|\.json$/;
|
|
|
9560
9591
|
var FORMAT_BATCH = 25;
|
|
9561
9592
|
function readIfPossible(path) {
|
|
9562
9593
|
try {
|
|
9563
|
-
return
|
|
9594
|
+
return readFileSync25(path, "utf8");
|
|
9564
9595
|
} catch {
|
|
9565
9596
|
return void 0;
|
|
9566
9597
|
}
|
|
@@ -9807,7 +9838,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9807
9838
|
}
|
|
9808
9839
|
let parsed;
|
|
9809
9840
|
try {
|
|
9810
|
-
parsed = JSON.parse(
|
|
9841
|
+
parsed = JSON.parse(readFileSync25(out, "utf8"));
|
|
9811
9842
|
} catch {
|
|
9812
9843
|
return {
|
|
9813
9844
|
ok: false,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
WORKSPACE_TSCONFIG,
|
|
3
|
+
effectivePaths,
|
|
2
4
|
parseJsonc
|
|
3
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ZVHUG6CA.js";
|
|
4
6
|
|
|
5
7
|
// src/roles/build/nest/decorator-metadata.ts
|
|
6
8
|
import { existsSync } from "node:fs";
|
|
@@ -158,24 +160,32 @@ var decoratorMetadata = (options) => {
|
|
|
158
160
|
// src/roles/build/nest/tsconfig-aliases.ts
|
|
159
161
|
import { readFileSync } from "node:fs";
|
|
160
162
|
import { join } from "node:path";
|
|
161
|
-
var toAlias = (
|
|
163
|
+
var toAlias = (baseDirectory, pattern, target) => {
|
|
162
164
|
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\*/g, "(.*)");
|
|
163
165
|
return {
|
|
164
166
|
find: new RegExp(`^${escaped}$`),
|
|
165
|
-
replacement: join(
|
|
167
|
+
replacement: join(baseDirectory, target.replace(/\*/g, "$1"))
|
|
166
168
|
};
|
|
167
169
|
};
|
|
168
|
-
var
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
170
|
+
var toAliases = (baseDirectory, paths) => Object.entries(paths).flatMap(([pattern, targets]) => {
|
|
171
|
+
const [target] = targets;
|
|
172
|
+
return target === void 0 ? [] : [toAlias(baseDirectory, pattern, target)];
|
|
173
|
+
}).sort((a, b) => b.find.source.length - a.find.source.length);
|
|
174
|
+
function tsconfigAliases(workspaceRoot, source = WORKSPACE_TSCONFIG) {
|
|
175
|
+
if (typeof source !== "string") {
|
|
176
|
+
const candidates = (source.candidates ?? ["tsconfig.json"]).filter(
|
|
177
|
+
(name) => name !== void 0
|
|
178
|
+
);
|
|
179
|
+
const found = effectivePaths(source.moduleRoot, workspaceRoot, candidates);
|
|
180
|
+
return found === void 0 ? [] : toAliases(found.baseDirectory, found.paths);
|
|
181
|
+
}
|
|
182
|
+
const raw = readFileSync(join(workspaceRoot, source), "utf8");
|
|
183
|
+
const { compilerOptions } = parseJsonc(raw, source);
|
|
184
|
+
return toAliases(workspaceRoot, compilerOptions?.paths ?? {});
|
|
185
|
+
}
|
|
176
186
|
|
|
177
187
|
export {
|
|
178
188
|
decoratorMetadata,
|
|
179
189
|
tsconfigAliases
|
|
180
190
|
};
|
|
181
|
-
//# sourceMappingURL=chunk-
|
|
191
|
+
//# sourceMappingURL=chunk-POZDYETY.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/roles/build/nest/decorator-metadata.ts","../src/roles/build/nest/tsconfig-aliases.ts"],"sourcesContent":["/**\n * Decorator metadata, which esbuild cannot emit and Nest cannot live without, plus the TypeScript\n * transformers a service declared on its webpack target.\n *\n * Vite's default transformer is esbuild, and esbuild does not implement `emitDecoratorMetadata`.\n * Nest resolves a constructor's parameters from exactly that metadata, so without it the DI\n * container comes up empty and the application fails on its first module. Measured in the\n * monorepo this ships to: `emitDecoratorMetadata: true` in `tsconfig.base.json`, and 7365 files\n * carrying `@Injectable`, `@Module` or `@Controller`.\n *\n * ## TWO modes, chosen exactly as nx chooses them\n *\n * This is the one decision in this file that is not ours, and trying to make it ours cost a day.\n *\n * `@nx/webpack` configures ts-loader with one line:\n *\n * transpileOnly: !hasPlugin // hasPlugin = this target declares `transformers`\n *\n * So webpack already had two behaviours. A service with no transformers compiled with\n * `transpileOnly`, which is `ts.transpileModule` semantics: no type checker, one file at a time.\n * A service WITH transformers compiled through a full `ts.Program`, because that is the only way\n * a TypeScript transformer can run at all.\n *\n * The difference is visible, and measured. On a property typed by an imported string enum:\n *\n * Program : __metadata(\"design:type\", String)\n * transpileModule : __metadata(\"design:type\", typeof (_a = ...) === \"function\" ? _a : Object)\n *\n * and on a `@Body()` whose DTO arrives through `import type`, a Program emits `Function` where\n * transpileOnly emits `Object`, which `@nestjs/swagger` turns into four `$ref: Function` request\n * bodies that the published contract does not have.\n *\n * This plugin used only the first mode and this file claimed it was \"the serializer ts-loader was\n * already using\". Half true, and the wrong half: it is what ts-loader uses for the 29 services\n * with no transformers, and those came back byte-identical. Then a Program was used for ALL of\n * them, which fixed the eight and moved the contract of `network`, which had been correct.\n *\n * Both were the same mistake: choosing one mode for everyone, when the tool being replaced chose\n * per service. So the condition is copied rather than invented, and there is no third case to\n * discover: nx has two, and both are reproduced here.\n *\n * The Program costs about six seconds more on the largest service (1419 files: ~1.9s to build it,\n * ~3.3ms per file against ~0.9ms). Only the services that declare a transformer pay it, which is\n * also what webpack did.\n *\n * ## The transformers, which are configuration and are read, never invented\n *\n * Eight services and BFFs declare `@nestjs/swagger/plugin` on their webpack target, with\n * `introspectComments` and `classValidatorShim`. It writes the `@ApiProperty` decorators a\n * developer would otherwise write by hand, turns JSDoc into descriptions, and projects\n * class-validator rules into the schema.\n *\n * Dropping it does not fail a build. Measured on `institution` by regenerating its committed\n * contract after a sentinel build: 385 insertions and 1378 deletions. Response schemas and every\n * `minItems`, `minimum`, `maximum`, `minLength` and `format` disappeared, silently.\n *\n * So `--init` reads the declaration off the webpack target and writes it into the generated Vite\n * config, and this plugin loads it. Nothing here decides which transformers a service runs.\n *\n * ## Why the MODULE's compiler now, and not sentinel's own\n *\n * This plugin used to pin sentinel's TypeScript, on the grounds that `typescript` in the consumer\n * could resolve to the 7.x native port, which exports a version and no compiler API. Measured\n * from a service today it resolves to `@typescript/typescript6` 6.0.2, with the full API.\n *\n * The pin cannot survive the transformers anyway: a plugin loaded from the module's\n * `node_modules` imports the module's TypeScript, and a transformer built against one compiler\n * cannot be handed a Program built by another. One compiler, the module's, is also what ts-loader\n * used, so it is the faithful answer rather than merely the workable one. The API is asserted at\n * `buildStart`, where a failure is reported.\n *\n * ## Why the module's own tsconfig, and not options chosen here\n *\n * Emit follows compiler options, so options invented here would be a second, silent source of\n * divergence from what ts-loader produced. `target` alone decides how classes and fields are\n * downlevelled: this workspace is on `es2021`, where `useDefineForClassFields` defaults to false\n * and a declared-but-unassigned DTO field is therefore NOT emitted. Defaulting to `es2022` here\n * would flip that, `Object.defineProperty` would write `undefined` over every field, and\n * `class-transformer` payloads would arrive empty at runtime with nothing in the build to explain\n * it.\n *\n * So the config is read, `extends` resolved by the compiler itself, and only what this plugin\n * genuinely owns is overridden.\n *\n * ## Still no type CHECKING, which is a different thing from having types\n *\n * The Program gives this plugin a type checker; it does not use it to report errors. Every Nest\n * project already runs `tsc -b` in its own `typecheck` target, and the build never was the thing\n * that type-checked. Emitting with type information and refusing to type-check are independent,\n * and only the first is needed to reproduce what ts-loader wrote.\n */\nimport { existsSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport path from 'node:path'\n\nimport type TS from 'typescript'\nimport type { Plugin } from 'vite'\n\n/** Files this transform owns: TypeScript sources, never a dependency's compiled output. */\nconst TYPESCRIPT_SOURCE = /\\.ts$/\n\n/**\n * Where a Nest service keeps the config it builds with, most specific first.\n *\n * `tsconfig.app.json` is the one Nx generates for the application's own sources and the one\n * ts-loader was pointed at; `tsconfig.json` is the fallback for a service that never split them.\n * Measured on `main`: all 37 services still on webpack name `tsconfig.app.json`.\n */\nconst TSCONFIG_CANDIDATES = ['tsconfig.app.json', 'tsconfig.json']\n\n/** A TypeScript transformer a service runs at build time, as its build target declares it. */\nexport interface TransformerDeclaration {\n /** The package to load it from, e.g. `@nestjs/swagger/plugin`. */\n name: string\n /** Passed to the transformer's own factory, unread here. */\n options?: Record<string, unknown>\n}\n\nexport interface DecoratorMetadataOptions {\n /** The module being built. Its tsconfig is the one whose emit must be preserved. */\n root: string\n /**\n * An explicit tsconfig, when the service does not use either conventional name.\n *\n * Relative paths resolve against `root`.\n */\n tsconfig?: string\n /** The transformers this service declared, translated from its webpack target. */\n transformers?: readonly TransformerDeclaration[]\n}\n\n/**\n * The module's own TypeScript, with its emit API asserted.\n *\n * Resolved from `root` rather than from here, because a transformer loaded from the module binds\n * to the compiler the module resolves, and Programs are not interchangeable between compilers.\n */\nfunction loadCompiler(root: string): typeof TS {\n const require = createRequire(path.join(root, 'noop.js'))\n let compiler: typeof TS\n try {\n compiler = require('typescript') as typeof TS\n } catch {\n throw new Error(\n `sentinel build(nest): no \\`typescript\\` resolvable from ${root}. The build emits decorator ` +\n `metadata with the module's own compiler, so one has to be installed there.`,\n )\n }\n if (typeof compiler.createProgram !== 'function') {\n throw new Error(\n `sentinel build(nest): the typescript resolved from ${root} (${compiler.version ?? 'unknown'}) ` +\n `has no createProgram API. TypeScript 7 is the native port and exposes none; the emit API ` +\n `lives under @typescript/typescript6. Point this module's \\`typescript\\` at a compiler ` +\n `with an emit API, which is the one its \\`typecheck\\` target already uses.`,\n )\n }\n return compiler\n}\n\nfunction resolveTsconfig(options: DecoratorMetadataOptions): string {\n if (options.tsconfig) {\n const explicit = path.resolve(options.root, options.tsconfig)\n if (!existsSync(explicit)) {\n throw new Error(`sentinel build(nest): tsconfig not found at ${explicit}`)\n }\n return explicit\n }\n for (const candidate of TSCONFIG_CANDIDATES) {\n const found = path.join(options.root, candidate)\n if (existsSync(found)) return found\n }\n throw new Error(\n `sentinel build(nest): no ${TSCONFIG_CANDIDATES.join(' or ')} in ${options.root}. ` +\n `Pass \\`tsconfig\\` if this service keeps it elsewhere.`,\n )\n}\n\n/** The module's compiler options, with `extends` already resolved, plus what this plugin owns. */\nfunction readConfig(\n ts: typeof TS,\n options: DecoratorMetadataOptions,\n): { fileNames: string[]; compilerOptions: TS.CompilerOptions } {\n const configPath = resolveTsconfig(options)\n const parsed = ts.getParsedCommandLineOfConfigFile(configPath, {}, {\n ...ts.sys,\n onUnRecoverableConfigFileDiagnostic: (diagnostic) => {\n throw new Error(\n `sentinel build(nest): could not read ${configPath}: ` +\n ts.flattenDiagnosticMessageText(diagnostic.messageText, ' '),\n )\n },\n } as TS.ParseConfigFileHost)\n\n return {\n fileNames: parsed?.fileNames ?? [],\n compilerOptions: {\n ...parsed?.options,\n // ESM out, so Rollup sees imports and exports rather than an opaque `require` it cannot\n // follow. The service still SHIPS as CJS: that conversion is the bundler's, further down.\n module: ts.ModuleKind.ESNext,\n // Vite consumes the map; the tsconfig's own answer is about a different pipeline.\n sourceMap: true,\n inlineSourceMap: false,\n inlineSources: false,\n // Types are another target's job, and emitting them here would write into the source tree.\n declaration: false,\n declarationMap: false,\n emitDeclarationOnly: false,\n noEmit: false,\n // `composite` projects refuse to emit without a `tsBuildInfoFile`, and there is no\n // incremental build here to inform.\n composite: false,\n incremental: false,\n },\n }\n}\n\n/**\n * The declared transformers, loaded from the MODULE so each binds to the compiler it expects.\n *\n * A name that cannot be loaded, or a package that exports no `before`, fails the build here\n * rather than producing a bundle quietly missing what the transformer contributes. That failure\n * mode is the reason this exists: dropping `@nestjs/swagger/plugin` costs a service most of its\n * published contract and nothing in the build says so.\n */\nfunction loadTransformers(\n root: string,\n program: TS.Program,\n declared: readonly TransformerDeclaration[],\n): TS.TransformerFactory<TS.SourceFile>[] {\n const require = createRequire(path.join(root, 'noop.js'))\n return declared.map(({ name, options }) => {\n let loaded: { before?: unknown }\n try {\n loaded = require(name) as { before?: unknown }\n } catch (error) {\n throw new Error(\n `sentinel build(nest): the build target declares the transformer \\`${name}\\`, which ` +\n `cannot be loaded from ${root}: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n )\n }\n if (typeof loaded.before !== 'function') {\n throw new Error(\n `sentinel build(nest): \\`${name}\\` exports no \\`before\\` factory, so it cannot run as a ` +\n `TypeScript transformer. Building without it would drop whatever it contributes.`,\n )\n }\n const factory = loaded.before as (\n options: Record<string, unknown> | undefined,\n program: TS.Program,\n ) => TS.TransformerFactory<TS.SourceFile>\n return factory(options, program)\n })\n}\n\nexport const decoratorMetadata = (options: DecoratorMetadataOptions): Plugin => {\n /*\n * Everything is prepared in `buildStart`, and that placement is the whole point.\n *\n * It used to be resolved lazily inside `transform`, on the reasoning that an error belongs to\n * the build rather than to importing the preset. Half right: it belongs to the build, but\n * Rollup SWALLOWS a throwing `transform` hook. The wrong compiler, an unreadable tsconfig and a\n * missing one all produced the same symptom instead of their own message: \"1 modules\n * transformed\", nothing written, then an unrelated error from whichever later hook tripped over\n * the empty output directory. It cost two diagnoses to recognise.\n *\n * `buildStart` is reported. So the compiler is loaded, the config read, the Program built and\n * the transformers resolved exactly once, before a single file is transformed, where failing\n * says what failed.\n */\n /** `hasPlugin` in nx's own words: this service declares transformers, so it needs a Program. */\n const typeAware = (options.transformers ?? []).length > 0\n\n let ts: typeof TS | undefined\n let program: TS.Program | undefined\n let compilerOptions: TS.CompilerOptions | undefined\n let before: TS.TransformerFactory<TS.SourceFile>[] = []\n /** Files emitted without the Program, which is a fidelity gap and is reported, never silent. */\n const withoutTypes: string[] = []\n\n return {\n name: 'sentinel:decorator-metadata',\n // Before Vite's own transform, so esbuild never sees the decorators it cannot handle, and so\n // the source this plugin reads from the Program is still the source on disk.\n enforce: 'pre',\n buildStart() {\n ts = loadCompiler(options.root)\n const config = readConfig(ts, options)\n compilerOptions = config.compilerOptions\n // Built only in the type-aware mode. It costs ~1.9s on the largest service here and buys\n // nothing a service without transformers can use, which is why nx does not build one either.\n if (!typeAware) return\n program = ts.createProgram(config.fileNames, config.compilerOptions)\n before = loadTransformers(options.root, program, options.transformers ?? [])\n },\n transform(code, id) {\n if (!TYPESCRIPT_SOURCE.test(id) || id.includes('node_modules')) return null\n // Only reachable if `buildStart` did not run, which no Rollup build does. Named rather than\n // defaulted, so it cannot silently emit with TypeScript's defaults instead of the module's.\n if (ts === undefined || compilerOptions === undefined) {\n throw new Error(\n `sentinel build(nest): the compiler was never prepared, so ${id} would be emitted with ` +\n `defaults rather than this module's tsconfig.`,\n )\n }\n\n /*\n * The Program's own SourceFile, which is what carries the type information.\n *\n * Three cases emit without it. The service declares no transformer, which is `transpileOnly`\n * and is what ts-loader did for it. A file the Program never reached, because nothing\n * imports it from the entry. And a file another plugin has already rewritten, where the\n * Program's copy is no longer the truth: emitting that stale copy over someone else's\n * transform would be the worse failure.\n *\n * The last two are counted and reported at the end. The first is not a gap, it is the mode.\n *\n * Measured on the largest service here: neither of the last two fires, on any of its 5594\n * files. That is the point of reporting them rather than tolerating them quietly — a warning\n * from this build means something genuinely new, not a known rough edge.\n */\n const sourceFile = program?.getSourceFile(id)\n if (program === undefined || sourceFile === undefined || sourceFile.text !== code) {\n if (typeAware) withoutTypes.push(id)\n const output = ts.transpileModule(code, { fileName: id, compilerOptions })\n return { code: output.outputText, map: output.sourceMapText ?? null }\n }\n\n let emitted: string | undefined\n let map: string | undefined\n program.emit(\n sourceFile,\n (fileName, text) => {\n if (fileName.endsWith('.map')) map = text\n else emitted = text\n },\n undefined,\n false,\n { before },\n )\n if (emitted === undefined) {\n throw new Error(`sentinel build(nest): TypeScript emitted nothing for ${id}.`)\n }\n return { code: emitted, map: map ?? null }\n },\n closeBundle() {\n if (withoutTypes.length === 0) return\n const shown = withoutTypes.slice(0, 5).map((file) => path.relative(options.root, file))\n this.warn(\n `sentinel build(nest): ${withoutTypes.length} file(s) were emitted without type ` +\n `information, so their decorator metadata may differ from what ts-loader produced ` +\n `(${shown.join(', ')}${withoutTypes.length > shown.length ? ', …' : ''}). They are ` +\n `outside this module's tsconfig, or another plugin rewrote them first.`,\n )\n },\n }\n}\n","/**\n * The workspace's `paths` mappings, as Vite resolve aliases.\n *\n * They matter more than they look. The mappings point at SOURCE files, and that is what makes\n * a workspace library get BUNDLED rather than externalised: Vite treats anything outside\n * `node_modules` as source. Drop them and every `@hublo/nest/*` import becomes an external the\n * runtime cannot resolve, because those packages are never published.\n *\n * This reproduces what webpack did through `tsconfig-paths-webpack-plugin`, alongside\n * `webpack-node-externals` which only ever externalised real packages. Measured on the first\n * migrated service: 45 externals under Vite against 47 under webpack, and nothing externalised\n * by Vite that webpack did not.\n */\nimport { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseJsonc } from '../../../shared/jsonc.js'\n\nexport interface Alias {\n find: RegExp\n replacement: string\n}\n\nconst toAlias = (workspaceRoot: string, pattern: string, target: string): Alias => {\n const escaped = pattern.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\\\\\*/g, '(.*)')\n return {\n find: new RegExp(`^${escaped}$`),\n replacement: join(workspaceRoot, target.replace(/\\*/g, '$1')),\n }\n}\n\n/**\n * Read the mappings from the workspace's base tsconfig.\n *\n * Longest pattern first, because Vite takes the first alias that matches and the mappings\n * overlap by design: `@front/theme/node` must not be swallowed by `@front/theme`.\n */\nexport const tsconfigAliases = (workspaceRoot: string, file = 'tsconfig.base.json'): Alias[] => {\n /*\n * ⚠️ JSONC, through the shared reader. This stripped `//` comments by hand and then called\n * `JSON.parse`, which handled a comment on its OWN line and nothing else: a trailing comment\n * after a value, a block comment, or a trailing comma, all legal in a tsconfig, would throw a\n * raw SyntaxError naming a character offset. Latent on this repo's base config today, and\n * `shared/jsonc.ts` already existed for exactly this.\n */\n const raw = readFileSync(join(workspaceRoot, file), 'utf8')\n const { compilerOptions } = parseJsonc<{\n compilerOptions?: { paths?: Record<string, string[]> }\n }>(raw, file)\n return Object.entries(compilerOptions?.paths ?? {})\n .flatMap(([pattern, targets]) => {\n const [target] = targets\n return target === undefined ? [] : [toAlias(workspaceRoot, pattern, target)]\n })\n .sort((a, b) => b.find.source.length - a.find.source.length)\n}\n"],"mappings":";;;;;AA2FA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAMjB,IAAM,oBAAoB;AAS1B,IAAM,sBAAsB,CAAC,qBAAqB,eAAe;AA6BjE,SAAS,aAAa,MAAyB;AAC7C,QAAMA,WAAU,cAAc,KAAK,KAAK,MAAM,SAAS,CAAC;AACxD,MAAI;AACJ,MAAI;AACF,eAAWA,SAAQ,YAAY;AAAA,EACjC,QAAQ;AACN,UAAM,IAAI;AAAA,MACR,2DAA2D,IAAI;AAAA,IAEjE;AAAA,EACF;AACA,MAAI,OAAO,SAAS,kBAAkB,YAAY;AAChD,UAAM,IAAI;AAAA,MACR,sDAAsD,IAAI,KAAK,SAAS,WAAW,SAAS;AAAA,IAI9F;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,gBAAgB,SAA2C;AAClE,MAAI,QAAQ,UAAU;AACpB,UAAM,WAAW,KAAK,QAAQ,QAAQ,MAAM,QAAQ,QAAQ;AAC5D,QAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,YAAM,IAAI,MAAM,+CAA+C,QAAQ,EAAE;AAAA,IAC3E;AACA,WAAO;AAAA,EACT;AACA,aAAW,aAAa,qBAAqB;AAC3C,UAAM,QAAQ,KAAK,KAAK,QAAQ,MAAM,SAAS;AAC/C,QAAI,WAAW,KAAK,EAAG,QAAO;AAAA,EAChC;AACA,QAAM,IAAI;AAAA,IACR,4BAA4B,oBAAoB,KAAK,MAAM,CAAC,OAAO,QAAQ,IAAI;AAAA,EAEjF;AACF;AAGA,SAAS,WACP,IACA,SAC8D;AAC9D,QAAM,aAAa,gBAAgB,OAAO;AAC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C3C;AAAA,IACA,cAAc;AACZ,UAAI,aAAa,WAAW,EAAG;AAC/B,YAAM,QAAQ,aAAa,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,SAAS,KAAK,SAAS,QAAQ,MAAM,IAAI,CAAC;AACtF,WAAK;AAAA,QACH,yBAAyB,aAAa,MAAM,wHAEtC,MAAM,KAAK,IAAI,CAAC,GAAG,aAAa,SAAS,MAAM,SAAS,aAAQ,EAAE;AAAA,MAE1E;AAAA,IACF;AAAA,EACF;AACF;;;ACxVA,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AASrB,IAAM,UAAU,CAAC,eAAuB,SAAiB,WAA0B;AACjF,QAAM,UAAU,QAAQ,QAAQ,uBAAuB,MAAM,EAAE,QAAQ,SAAS,MAAM;AACtF,SAAO;AAAA,IACL,MAAM,IAAI,OAAO,IAAI,OAAO,GAAG;AAAA,IAC/B,aAAa,KAAK,eAAe,OAAO,QAAQ,OAAO,IAAI,CAAC;AAAA,EAC9D;AACF;AAQO,IAAM,kBAAkB,CAAC,eAAuB,OAAO,yBAAkC;AAQ9F,QAAM,MAAM,aAAa,KAAK,eAAe,IAAI,GAAG,MAAM;AAC1D,QAAM,EAAE,gBAAgB,IAAI,WAEzB,KAAK,IAAI;AACZ,SAAO,OAAO,QAAQ,iBAAiB,SAAS,CAAC,CAAC,EAC/C,QAAQ,CAAC,CAAC,SAAS,OAAO,MAAM;AAC/B,UAAM,CAAC,MAAM,IAAI;AACjB,WAAO,WAAW,SAAY,CAAC,IAAI,CAAC,QAAQ,eAAe,SAAS,MAAM,CAAC;AAAA,EAC7E,CAAC,EACA,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,OAAO,SAAS,EAAE,KAAK,OAAO,MAAM;AAC/D;","names":["require"]}
|
|
1
|
+
{"version":3,"sources":["../src/roles/build/nest/decorator-metadata.ts","../src/roles/build/nest/tsconfig-aliases.ts"],"sourcesContent":["/**\n * Decorator metadata, which esbuild cannot emit and Nest cannot live without, plus the TypeScript\n * transformers a service declared on its webpack target.\n *\n * Vite's default transformer is esbuild, and esbuild does not implement `emitDecoratorMetadata`.\n * Nest resolves a constructor's parameters from exactly that metadata, so without it the DI\n * container comes up empty and the application fails on its first module. Measured in the\n * monorepo this ships to: `emitDecoratorMetadata: true` in `tsconfig.base.json`, and 7365 files\n * carrying `@Injectable`, `@Module` or `@Controller`.\n *\n * ## TWO modes, chosen exactly as nx chooses them\n *\n * This is the one decision in this file that is not ours, and trying to make it ours cost a day.\n *\n * `@nx/webpack` configures ts-loader with one line:\n *\n * transpileOnly: !hasPlugin // hasPlugin = this target declares `transformers`\n *\n * So webpack already had two behaviours. A service with no transformers compiled with\n * `transpileOnly`, which is `ts.transpileModule` semantics: no type checker, one file at a time.\n * A service WITH transformers compiled through a full `ts.Program`, because that is the only way\n * a TypeScript transformer can run at all.\n *\n * The difference is visible, and measured. On a property typed by an imported string enum:\n *\n * Program : __metadata(\"design:type\", String)\n * transpileModule : __metadata(\"design:type\", typeof (_a = ...) === \"function\" ? _a : Object)\n *\n * and on a `@Body()` whose DTO arrives through `import type`, a Program emits `Function` where\n * transpileOnly emits `Object`, which `@nestjs/swagger` turns into four `$ref: Function` request\n * bodies that the published contract does not have.\n *\n * This plugin used only the first mode and this file claimed it was \"the serializer ts-loader was\n * already using\". Half true, and the wrong half: it is what ts-loader uses for the 29 services\n * with no transformers, and those came back byte-identical. Then a Program was used for ALL of\n * them, which fixed the eight and moved the contract of `network`, which had been correct.\n *\n * Both were the same mistake: choosing one mode for everyone, when the tool being replaced chose\n * per service. So the condition is copied rather than invented, and there is no third case to\n * discover: nx has two, and both are reproduced here.\n *\n * The Program costs about six seconds more on the largest service (1419 files: ~1.9s to build it,\n * ~3.3ms per file against ~0.9ms). Only the services that declare a transformer pay it, which is\n * also what webpack did.\n *\n * ## The transformers, which are configuration and are read, never invented\n *\n * Eight services and BFFs declare `@nestjs/swagger/plugin` on their webpack target, with\n * `introspectComments` and `classValidatorShim`. It writes the `@ApiProperty` decorators a\n * developer would otherwise write by hand, turns JSDoc into descriptions, and projects\n * class-validator rules into the schema.\n *\n * Dropping it does not fail a build. Measured on `institution` by regenerating its committed\n * contract after a sentinel build: 385 insertions and 1378 deletions. Response schemas and every\n * `minItems`, `minimum`, `maximum`, `minLength` and `format` disappeared, silently.\n *\n * So `--init` reads the declaration off the webpack target and writes it into the generated Vite\n * config, and this plugin loads it. Nothing here decides which transformers a service runs.\n *\n * ## Why the MODULE's compiler now, and not sentinel's own\n *\n * This plugin used to pin sentinel's TypeScript, on the grounds that `typescript` in the consumer\n * could resolve to the 7.x native port, which exports a version and no compiler API. Measured\n * from a service today it resolves to `@typescript/typescript6` 6.0.2, with the full API.\n *\n * The pin cannot survive the transformers anyway: a plugin loaded from the module's\n * `node_modules` imports the module's TypeScript, and a transformer built against one compiler\n * cannot be handed a Program built by another. One compiler, the module's, is also what ts-loader\n * used, so it is the faithful answer rather than merely the workable one. The API is asserted at\n * `buildStart`, where a failure is reported.\n *\n * ## Why the module's own tsconfig, and not options chosen here\n *\n * Emit follows compiler options, so options invented here would be a second, silent source of\n * divergence from what ts-loader produced. `target` alone decides how classes and fields are\n * downlevelled: this workspace is on `es2021`, where `useDefineForClassFields` defaults to false\n * and a declared-but-unassigned DTO field is therefore NOT emitted. Defaulting to `es2022` here\n * would flip that, `Object.defineProperty` would write `undefined` over every field, and\n * `class-transformer` payloads would arrive empty at runtime with nothing in the build to explain\n * it.\n *\n * So the config is read, `extends` resolved by the compiler itself, and only what this plugin\n * genuinely owns is overridden.\n *\n * ## Still no type CHECKING, which is a different thing from having types\n *\n * The Program gives this plugin a type checker; it does not use it to report errors. Every Nest\n * project already runs `tsc -b` in its own `typecheck` target, and the build never was the thing\n * that type-checked. Emitting with type information and refusing to type-check are independent,\n * and only the first is needed to reproduce what ts-loader wrote.\n */\nimport { existsSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport path from 'node:path'\n\nimport type TS from 'typescript'\nimport type { Plugin } from 'vite'\n\n/** Files this transform owns: TypeScript sources, never a dependency's compiled output. */\nconst TYPESCRIPT_SOURCE = /\\.ts$/\n\n/**\n * Where a Nest service keeps the config it builds with, most specific first.\n *\n * `tsconfig.app.json` is the one Nx generates for the application's own sources and the one\n * ts-loader was pointed at; `tsconfig.json` is the fallback for a service that never split them.\n * Measured on `main`: all 37 services still on webpack name `tsconfig.app.json`.\n */\nconst TSCONFIG_CANDIDATES = ['tsconfig.app.json', 'tsconfig.json']\n\n/** A TypeScript transformer a service runs at build time, as its build target declares it. */\nexport interface TransformerDeclaration {\n /** The package to load it from, e.g. `@nestjs/swagger/plugin`. */\n name: string\n /** Passed to the transformer's own factory, unread here. */\n options?: Record<string, unknown>\n}\n\nexport interface DecoratorMetadataOptions {\n /** The module being built. Its tsconfig is the one whose emit must be preserved. */\n root: string\n /**\n * An explicit tsconfig, when the service does not use either conventional name.\n *\n * Relative paths resolve against `root`.\n */\n tsconfig?: string\n /** The transformers this service declared, translated from its webpack target. */\n transformers?: readonly TransformerDeclaration[]\n}\n\n/**\n * The module's own TypeScript, with its emit API asserted.\n *\n * Resolved from `root` rather than from here, because a transformer loaded from the module binds\n * to the compiler the module resolves, and Programs are not interchangeable between compilers.\n */\nfunction loadCompiler(root: string): typeof TS {\n const require = createRequire(path.join(root, 'noop.js'))\n let compiler: typeof TS\n try {\n compiler = require('typescript') as typeof TS\n } catch {\n throw new Error(\n `sentinel build(nest): no \\`typescript\\` resolvable from ${root}. The build emits decorator ` +\n `metadata with the module's own compiler, so one has to be installed there.`,\n )\n }\n if (typeof compiler.createProgram !== 'function') {\n throw new Error(\n `sentinel build(nest): the typescript resolved from ${root} (${compiler.version ?? 'unknown'}) ` +\n `has no createProgram API. TypeScript 7 is the native port and exposes none; the emit API ` +\n `lives under @typescript/typescript6. Point this module's \\`typescript\\` at a compiler ` +\n `with an emit API, which is the one its \\`typecheck\\` target already uses.`,\n )\n }\n return compiler\n}\n\nfunction resolveTsconfig(options: DecoratorMetadataOptions): string {\n if (options.tsconfig) {\n const explicit = path.resolve(options.root, options.tsconfig)\n if (!existsSync(explicit)) {\n throw new Error(`sentinel build(nest): tsconfig not found at ${explicit}`)\n }\n return explicit\n }\n for (const candidate of TSCONFIG_CANDIDATES) {\n const found = path.join(options.root, candidate)\n if (existsSync(found)) return found\n }\n throw new Error(\n `sentinel build(nest): no ${TSCONFIG_CANDIDATES.join(' or ')} in ${options.root}. ` +\n `Pass \\`tsconfig\\` if this service keeps it elsewhere.`,\n )\n}\n\n/** The module's compiler options, with `extends` already resolved, plus what this plugin owns. */\nfunction readConfig(\n ts: typeof TS,\n options: DecoratorMetadataOptions,\n): { fileNames: string[]; compilerOptions: TS.CompilerOptions } {\n const configPath = resolveTsconfig(options)\n const parsed = ts.getParsedCommandLineOfConfigFile(configPath, {}, {\n ...ts.sys,\n onUnRecoverableConfigFileDiagnostic: (diagnostic) => {\n throw new Error(\n `sentinel build(nest): could not read ${configPath}: ` +\n ts.flattenDiagnosticMessageText(diagnostic.messageText, ' '),\n )\n },\n } as TS.ParseConfigFileHost)\n\n return {\n fileNames: parsed?.fileNames ?? [],\n compilerOptions: {\n ...parsed?.options,\n // ESM out, so Rollup sees imports and exports rather than an opaque `require` it cannot\n // follow. The service still SHIPS as CJS: that conversion is the bundler's, further down.\n module: ts.ModuleKind.ESNext,\n // Vite consumes the map; the tsconfig's own answer is about a different pipeline.\n sourceMap: true,\n inlineSourceMap: false,\n inlineSources: false,\n // Types are another target's job, and emitting them here would write into the source tree.\n declaration: false,\n declarationMap: false,\n emitDeclarationOnly: false,\n noEmit: false,\n // `composite` projects refuse to emit without a `tsBuildInfoFile`, and there is no\n // incremental build here to inform.\n composite: false,\n incremental: false,\n },\n }\n}\n\n/**\n * The declared transformers, loaded from the MODULE so each binds to the compiler it expects.\n *\n * A name that cannot be loaded, or a package that exports no `before`, fails the build here\n * rather than producing a bundle quietly missing what the transformer contributes. That failure\n * mode is the reason this exists: dropping `@nestjs/swagger/plugin` costs a service most of its\n * published contract and nothing in the build says so.\n */\nfunction loadTransformers(\n root: string,\n program: TS.Program,\n declared: readonly TransformerDeclaration[],\n): TS.TransformerFactory<TS.SourceFile>[] {\n const require = createRequire(path.join(root, 'noop.js'))\n return declared.map(({ name, options }) => {\n let loaded: { before?: unknown }\n try {\n loaded = require(name) as { before?: unknown }\n } catch (error) {\n throw new Error(\n `sentinel build(nest): the build target declares the transformer \\`${name}\\`, which ` +\n `cannot be loaded from ${root}: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n )\n }\n if (typeof loaded.before !== 'function') {\n throw new Error(\n `sentinel build(nest): \\`${name}\\` exports no \\`before\\` factory, so it cannot run as a ` +\n `TypeScript transformer. Building without it would drop whatever it contributes.`,\n )\n }\n const factory = loaded.before as (\n options: Record<string, unknown> | undefined,\n program: TS.Program,\n ) => TS.TransformerFactory<TS.SourceFile>\n return factory(options, program)\n })\n}\n\nexport const decoratorMetadata = (options: DecoratorMetadataOptions): Plugin => {\n /*\n * Everything is prepared in `buildStart`, and that placement is the whole point.\n *\n * It used to be resolved lazily inside `transform`, on the reasoning that an error belongs to\n * the build rather than to importing the preset. Half right: it belongs to the build, but\n * Rollup SWALLOWS a throwing `transform` hook. The wrong compiler, an unreadable tsconfig and a\n * missing one all produced the same symptom instead of their own message: \"1 modules\n * transformed\", nothing written, then an unrelated error from whichever later hook tripped over\n * the empty output directory. It cost two diagnoses to recognise.\n *\n * `buildStart` is reported. So the compiler is loaded, the config read, the Program built and\n * the transformers resolved exactly once, before a single file is transformed, where failing\n * says what failed.\n */\n /** `hasPlugin` in nx's own words: this service declares transformers, so it needs a Program. */\n const typeAware = (options.transformers ?? []).length > 0\n\n let ts: typeof TS | undefined\n let program: TS.Program | undefined\n let compilerOptions: TS.CompilerOptions | undefined\n let before: TS.TransformerFactory<TS.SourceFile>[] = []\n /** Files emitted without the Program, which is a fidelity gap and is reported, never silent. */\n const withoutTypes: string[] = []\n\n return {\n name: 'sentinel:decorator-metadata',\n // Before Vite's own transform, so esbuild never sees the decorators it cannot handle, and so\n // the source this plugin reads from the Program is still the source on disk.\n enforce: 'pre',\n buildStart() {\n ts = loadCompiler(options.root)\n const config = readConfig(ts, options)\n compilerOptions = config.compilerOptions\n // Built only in the type-aware mode. It costs ~1.9s on the largest service here and buys\n // nothing a service without transformers can use, which is why nx does not build one either.\n if (!typeAware) return\n program = ts.createProgram(config.fileNames, config.compilerOptions)\n before = loadTransformers(options.root, program, options.transformers ?? [])\n },\n transform(code, id) {\n if (!TYPESCRIPT_SOURCE.test(id) || id.includes('node_modules')) return null\n // Only reachable if `buildStart` did not run, which no Rollup build does. Named rather than\n // defaulted, so it cannot silently emit with TypeScript's defaults instead of the module's.\n if (ts === undefined || compilerOptions === undefined) {\n throw new Error(\n `sentinel build(nest): the compiler was never prepared, so ${id} would be emitted with ` +\n `defaults rather than this module's tsconfig.`,\n )\n }\n\n /*\n * The Program's own SourceFile, which is what carries the type information.\n *\n * Three cases emit without it. The service declares no transformer, which is `transpileOnly`\n * and is what ts-loader did for it. A file the Program never reached, because nothing\n * imports it from the entry. And a file another plugin has already rewritten, where the\n * Program's copy is no longer the truth: emitting that stale copy over someone else's\n * transform would be the worse failure.\n *\n * The last two are counted and reported at the end. The first is not a gap, it is the mode.\n *\n * Measured on the largest service here: neither of the last two fires, on any of its 5594\n * files. That is the point of reporting them rather than tolerating them quietly — a warning\n * from this build means something genuinely new, not a known rough edge.\n */\n const sourceFile = program?.getSourceFile(id)\n if (program === undefined || sourceFile === undefined || sourceFile.text !== code) {\n if (typeAware) withoutTypes.push(id)\n const output = ts.transpileModule(code, { fileName: id, compilerOptions })\n return { code: output.outputText, map: output.sourceMapText ?? null }\n }\n\n let emitted: string | undefined\n let map: string | undefined\n program.emit(\n sourceFile,\n (fileName, text) => {\n if (fileName.endsWith('.map')) map = text\n else emitted = text\n },\n undefined,\n false,\n { before },\n )\n if (emitted === undefined) {\n throw new Error(`sentinel build(nest): TypeScript emitted nothing for ${id}.`)\n }\n return { code: emitted, map: map ?? null }\n },\n closeBundle() {\n if (withoutTypes.length === 0) return\n const shown = withoutTypes.slice(0, 5).map((file) => path.relative(options.root, file))\n this.warn(\n `sentinel build(nest): ${withoutTypes.length} file(s) were emitted without type ` +\n `information, so their decorator metadata may differ from what ts-loader produced ` +\n `(${shown.join(', ')}${withoutTypes.length > shown.length ? ', …' : ''}). They are ` +\n `outside this module's tsconfig, or another plugin rewrote them first.`,\n )\n },\n }\n}\n","/**\n * The workspace's `paths` mappings, as Vite resolve aliases.\n *\n * They matter more than they look. The mappings point at SOURCE files, and that is what makes\n * a workspace library get BUNDLED rather than externalised: Vite treats anything outside\n * `node_modules` as source. Drop them and every `@hublo/nest/*` import becomes an external the\n * runtime cannot resolve, because those packages are never published.\n *\n * This reproduces what webpack did through `tsconfig-paths-webpack-plugin`, alongside\n * `webpack-node-externals` which only ever externalised real packages. Measured on the first\n * migrated service: 45 externals under Vite against 47 under webpack, and nothing externalised\n * by Vite that webpack did not.\n */\nimport { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseJsonc } from '../../../shared/jsonc.js'\nimport { effectivePaths, WORKSPACE_TSCONFIG } from '../../../shared/tsconfig-paths.js'\n\nexport interface Alias {\n find: RegExp\n replacement: string\n}\n\n/** Read the module's own chain rather than one workspace file. */\nexport interface ModuleAliasSource {\n /** The module's directory, where its tsconfig lives. */\n moduleRoot: string\n /** Its tsconfig names to try, most specific first, relative to `moduleRoot`. */\n candidates?: readonly (string | undefined)[]\n}\n\nconst toAlias = (baseDirectory: string, pattern: string, target: string): Alias => {\n const escaped = pattern.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\\\\\*/g, '(.*)')\n return {\n find: new RegExp(`^${escaped}$`),\n replacement: join(baseDirectory, target.replace(/\\*/g, '$1')),\n }\n}\n\n/** Longest pattern first, because Vite takes the first alias that matches. */\nconst toAliases = (baseDirectory: string, paths: Record<string, string[]>): Alias[] =>\n Object.entries(paths)\n .flatMap(([pattern, targets]) => {\n const [target] = targets\n return target === undefined ? [] : [toAlias(baseDirectory, pattern, target)]\n })\n .sort((a, b) => b.find.source.length - a.find.source.length)\n\n/**\n * The aliases a module resolves through.\n *\n * Longest pattern first, because Vite takes the first alias that matches and the mappings\n * overlap by design: `@front/theme/node` must not be swallowed by `@front/theme`.\n *\n * Two ways to call it, and the first is kept for what it always did:\n * - `tsconfigAliases(workspaceRoot)` or with a file name: that one workspace file, read on its\n * own, its targets relative to `workspaceRoot`. Unchanged, because it is exported from the\n * `build/nest` and `test/nest` toolchains and a module's config may call it.\n * - `tsconfigAliases(workspaceRoot, { moduleRoot })`: the module's own chain, the way tsc reads\n * it, falling back to the workspace base when the chain declares no `paths`. See\n * `shared/tsconfig-paths.ts` for the rules and why the fallback is a transition.\n */\nexport function tsconfigAliases(\n workspaceRoot: string,\n source: string | ModuleAliasSource = WORKSPACE_TSCONFIG,\n): Alias[] {\n if (typeof source !== 'string') {\n const candidates = (source.candidates ?? ['tsconfig.json']).filter(\n (name): name is string => name !== undefined,\n )\n const found = effectivePaths(source.moduleRoot, workspaceRoot, candidates)\n return found === undefined ? [] : toAliases(found.baseDirectory, found.paths)\n }\n\n /*\n * ⚠️ JSONC, through the shared reader. This stripped `//` comments by hand and then called\n * `JSON.parse`, which handled a comment on its OWN line and nothing else: a trailing comment\n * after a value, a block comment, or a trailing comma, all legal in a tsconfig, would throw a\n * raw SyntaxError naming a character offset. Latent on this repo's base config today, and\n * `shared/jsonc.ts` already existed for exactly this.\n */\n const raw = readFileSync(join(workspaceRoot, source), 'utf8')\n const { compilerOptions } = parseJsonc<{\n compilerOptions?: { paths?: Record<string, string[]> }\n }>(raw, source)\n return toAliases(workspaceRoot, compilerOptions?.paths ?? {})\n}\n"],"mappings":";;;;;;;AA2FA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAMjB,IAAM,oBAAoB;AAS1B,IAAM,sBAAsB,CAAC,qBAAqB,eAAe;AA6BjE,SAAS,aAAa,MAAyB;AAC7C,QAAMA,WAA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B,SAAiB,WAA0B;AACjF,QAAM,UAAU,QAAQ,QAAQ,uBAAuB,MAAM,EAAE,QAAQ,SAAS,MAAM;AACtF,SAAO;AAAA,IACL,MAAM,IAAI,OAAO,IAAI,OAAO,GAAG;AAAA,IAC/B,aAAa,KAAK,eAAe,OAAO,QAAQ,OAAO,IAAI,CAAC;AAAA,EAC9D;AACF;AAGA,IAAM,YAAY,CAAC,eAAuB,UACxC,OAAO,QAAQ,KAAK,EACjB,QAAQ,CAAC,CAAC,SAAS,OAAO,MAAM;AAC/B,QAAM,CAAC,MAAM,IAAI;AACjB,SAAO,WAAW,SAAY,CAAC,IAAI,CAAC,QAAQ,eAAe,SAAS,MAAM,CAAC;AAC7E,CAAC,EACA,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,OAAO,SAAS,EAAE,KAAK,OAAO,MAAM;AAgBxD,SAAS,gBACd,eACA,SAAqC,oBAC5B;AACT,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,cAAc,OAAO,cAAc,CAAC,eAAe,GAAG;AAAA,MAC1D,CAAC,SAAyB,SAAS;AAAA,IACrC;AACA,UAAM,QAAQ,eAAe,OAAO,YAAY,eAAe,UAAU;AACzE,WAAO,UAAU,SAAY,CAAC,IAAI,UAAU,MAAM,eAAe,MAAM,KAAK;AAAA,EAC9E;AASA,QAAM,MAAM,aAAa,KAAK,eAAe,MAAM,GAAG,MAAM;AAC5D,QAAM,EAAE,gBAAgB,IAAI,WAEzB,KAAK,MAAM;AACd,SAAO,UAAU,eAAe,iBAAiB,SAAS,CAAC,CAAC;AAC9D;","names":["require"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
decoratorMetadata,
|
|
3
3
|
tsconfigAliases
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-POZDYETY.js";
|
|
5
5
|
|
|
6
6
|
// src/roles/test/shared-test-config.ts
|
|
7
7
|
import { existsSync } from "node:fs";
|
|
@@ -311,7 +311,17 @@ function baseConfig(options) {
|
|
|
311
311
|
find: /^jest-mock-extended$/,
|
|
312
312
|
replacement: mockExtendedAdapterPath() ?? vitestMockExtendedPath()
|
|
313
313
|
},
|
|
314
|
-
|
|
314
|
+
/*
|
|
315
|
+
* The chain the module's specs type-check against, and the workspace base only when that
|
|
316
|
+
* chain declares no `paths`. ⚠️ `tsconfig.app.json` sits between the two because the three
|
|
317
|
+
* React apps on this preset have NO `tsconfig.spec.json`, and their `tsconfig.json` holds
|
|
318
|
+
* only `references`: their `paths` reach them through `tsconfig.app.json`. Without it, they
|
|
319
|
+
* would read the base forever, whatever they declare.
|
|
320
|
+
*/
|
|
321
|
+
...tsconfigAliases(workspaceRoot, {
|
|
322
|
+
moduleRoot: root,
|
|
323
|
+
candidates: ["tsconfig.spec.json", "tsconfig.app.json", "tsconfig.json"]
|
|
324
|
+
})
|
|
315
325
|
]
|
|
316
326
|
},
|
|
317
327
|
test: {
|
|
@@ -605,4 +615,4 @@ export {
|
|
|
605
615
|
jestExportConditions,
|
|
606
616
|
sharedTestConfig
|
|
607
617
|
};
|
|
608
|
-
//# sourceMappingURL=chunk-
|
|
618
|
+
//# sourceMappingURL=chunk-VVEKPCRY.js.map
|