@hublo/sentinel 1.7.0-alpha.29 → 1.7.0-alpha.30
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/README.md +3 -1
- package/dist/bin/sentinel.js +101 -56
- package/dist/{chunk-KGZLTDUT.js → chunk-2PRJJRJI.js} +207 -491
- package/dist/{chunk-AO526UPR.js → chunk-APBEGLRI.js} +7 -10
- package/dist/chunk-APBEGLRI.js.map +1 -0
- package/dist/{chunk-EESVRILJ.js → chunk-DLGBRLUU.js} +16 -3
- package/dist/chunk-DLGBRLUU.js.map +1 -0
- package/dist/chunk-H4HAFJFZ.js +79 -0
- package/dist/chunk-H4HAFJFZ.js.map +1 -0
- package/dist/{chunk-ZZP4DWQK.js → chunk-HYXFUUF5.js} +14697 -8559
- package/dist/{chunk-SWWQ7X7B.js → chunk-LNFGVGLE.js} +23 -11
- package/dist/{chunk-SWWQ7X7B.js.map → chunk-LNFGVGLE.js.map} +1 -1
- package/dist/{chunk-ZDSSUW6A.js → chunk-LVY5NPOC.js} +2 -2
- package/dist/chunk-PXTU5MPW.js +9 -0
- package/dist/chunk-PXTU5MPW.js.map +1 -0
- package/dist/chunk-SHF46ALB.js +190 -0
- package/dist/chunk-SHF46ALB.js.map +1 -0
- package/dist/chunk-TMVKYXZ3.js +18 -0
- package/dist/chunk-TMVKYXZ3.js.map +1 -0
- package/dist/chunk-XYOIXC6A.js +126 -0
- package/dist/chunk-XYOIXC6A.js.map +1 -0
- package/dist/{chunk-VE37F4A5.js → chunk-YUZB4LRJ.js} +10 -5
- package/dist/chunk-YUZB4LRJ.js.map +1 -0
- package/dist/chunk-ZFG6P27V.js +313 -0
- package/dist/chunk-ZZMYV576.js +297 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -9
- package/dist/migrate-X7PB2X7R.js +553 -0
- package/dist/roles/arch/config.d.ts +25 -0
- package/dist/roles/arch/config.js +8 -0
- package/dist/roles/build/nest/toolchain.d.ts +1 -1
- package/dist/roles/build/nest/toolchain.js +9 -5
- package/dist/roles/build/nest/toolchain.js.map +1 -1
- package/dist/roles/code-churn/config.d.ts +92 -0
- package/dist/roles/code-churn/config.js +10 -0
- package/dist/roles/code-churn/config.js.map +1 -0
- package/dist/roles/sql/config.d.ts +68 -0
- package/dist/roles/sql/config.js +8 -0
- package/dist/roles/sql/config.js.map +1 -0
- package/dist/roles/static-analysis/config.js +2 -1
- package/dist/roles/test/nest/toolchain.d.ts +1 -1
- package/dist/roles/test/nest/toolchain.js +3 -2
- package/dist/roles/test/nest/toolchain.js.map +1 -1
- package/dist/roles/test/react/toolchain.js +3 -2
- package/dist/roles/test/react/toolchain.js.map +1 -1
- package/dist/roles/test/setup/file-boundary.js +3 -3
- package/dist/roles/test/setup/jest-parity.js +4 -4
- package/dist/roles/test/setup/workspace-entry.js +2 -2
- package/dist/roles/test/shared-test-config.d.ts +1 -1
- package/dist/roles/test/shared-test-config.js +3 -2
- package/dist/tsconfig/legacy.json +21 -0
- package/dist/tsconfig/nest.json +10 -1
- package/dist/tsconfig/node.json +11 -1
- package/dist/tsconfig/react.json +3 -0
- package/dist/{tsconfig-aliases-Ce6axdJ4.d.ts → tsconfig-aliases-C_PxuZni.d.ts} +17 -2
- package/dist/{validate-D7MW2XE6.js → validate-4GMB32V7.js} +4 -2
- package/docs/arch-adoption.md +201 -0
- package/docs/build-adoption.md +7 -0
- package/docs/code-churn-adoption.md +237 -0
- package/docs/sql-adoption.md +672 -0
- package/docs/static-analysis-study.md +49 -10
- package/docs/test-adoption.md +8 -1
- package/docs/typescript-adoption.md +96 -13
- package/docs/typescript-traces.md +547 -5
- package/docs/using-sentinel.md +4 -2
- package/package.json +20 -9
- package/dist/chunk-AO526UPR.js.map +0 -1
- package/dist/chunk-EESVRILJ.js.map +0 -1
- package/dist/chunk-F5WISUN3.js +0 -17
- package/dist/chunk-F5WISUN3.js.map +0 -1
- package/dist/chunk-FY3P5QPH.js +0 -15
- package/dist/chunk-FY3P5QPH.js.map +0 -1
- package/dist/chunk-NE3IEJBN.js +0 -59
- package/dist/chunk-NE3IEJBN.js.map +0 -1
- package/dist/chunk-VE37F4A5.js.map +0 -1
- package/dist/chunk-VWASE6NN.js +0 -34
- package/dist/chunk-VWASE6NN.js.map +0 -1
- package/dist/roles/runtime-analysis/config.d.ts +0 -92
- package/dist/roles/runtime-analysis/config.js +0 -10
- package/dist/roles/runtime-analysis/gateway.d.ts +0 -2
- package/dist/roles/runtime-analysis/gateway.js +0 -89
- package/dist/roles/runtime-analysis/gateway.js.map +0 -1
- package/dist/roles/runtime-analysis/mock-api.d.ts +0 -2
- package/dist/roles/runtime-analysis/mock-api.js +0 -43
- package/dist/roles/runtime-analysis/mock-api.js.map +0 -1
- package/docs/runtime-analysis-adoption.md +0 -197
- package/runtime-analysis-deps/load.mjs +0 -6
- package/runtime-analysis-deps/package-lock.json +0 -1766
- package/runtime-analysis-deps/package.json +0 -11
- /package/dist/{chunk-ZDSSUW6A.js.map → chunk-LVY5NPOC.js.map} +0 -0
- /package/dist/roles/{runtime-analysis → arch}/config.js.map +0 -0
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
binFromOwnInstall,
|
|
3
|
+
binSearchPath,
|
|
4
|
+
resolveBin,
|
|
5
|
+
writtenFileFormatter
|
|
6
|
+
} from "./chunk-ZFG6P27V.js";
|
|
7
|
+
import {
|
|
8
|
+
matchesTsconfigPattern
|
|
9
|
+
} from "./chunk-O7REVMOC.js";
|
|
10
|
+
import {
|
|
11
|
+
WORKSPACE_TSCONFIG,
|
|
12
|
+
chainPaths,
|
|
13
|
+
effectivePaths
|
|
14
|
+
} from "./chunk-H4HAFJFZ.js";
|
|
15
|
+
import {
|
|
16
|
+
parseJsonc
|
|
17
|
+
} from "./chunk-QXFCZON7.js";
|
|
1
18
|
import {
|
|
2
19
|
DEFAULT_MAX_DIAGNOSTICS,
|
|
3
20
|
WORKSPACE_ROOT_MARKER,
|
|
@@ -6,13 +23,7 @@ import {
|
|
|
6
23
|
readNxProjectName,
|
|
7
24
|
readOwnPackage,
|
|
8
25
|
readProjectPackageJson
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import {
|
|
11
|
-
matchesTsconfigPattern
|
|
12
|
-
} from "./chunk-O7REVMOC.js";
|
|
13
|
-
import {
|
|
14
|
-
parseJsonc
|
|
15
|
-
} from "./chunk-QXFCZON7.js";
|
|
26
|
+
} from "./chunk-YUZB4LRJ.js";
|
|
16
27
|
|
|
17
28
|
// src/core/base-adapter.ts
|
|
18
29
|
var BaseAdapter = class {
|
|
@@ -398,53 +409,9 @@ function moduleEnvironment(cwd) {
|
|
|
398
409
|
// src/roles/test/reference.ts
|
|
399
410
|
import { execFileSync } from "node:child_process";
|
|
400
411
|
import { createHash } from "node:crypto";
|
|
401
|
-
import { existsSync as
|
|
412
|
+
import { existsSync as existsSync5, mkdirSync, mkdtempSync, readFileSync as readFileSync5, rmSync, writeFileSync } from "node:fs";
|
|
402
413
|
import { tmpdir } from "node:os";
|
|
403
|
-
import { join as
|
|
404
|
-
|
|
405
|
-
// src/shared/resolve-bin.ts
|
|
406
|
-
import { existsSync as existsSync5 } from "node:fs";
|
|
407
|
-
import { createRequire } from "node:module";
|
|
408
|
-
import { delimiter, dirname, join as join5 } from "node:path";
|
|
409
|
-
var require2 = createRequire(import.meta.url);
|
|
410
|
-
function resolveBin(fromDir, name) {
|
|
411
|
-
let dir = fromDir;
|
|
412
|
-
for (; ; ) {
|
|
413
|
-
const candidate = join5(dir, "node_modules", ".bin", name);
|
|
414
|
-
if (existsSync5(candidate)) return candidate;
|
|
415
|
-
const parent = dirname(dir);
|
|
416
|
-
if (parent === dir) return void 0;
|
|
417
|
-
dir = parent;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
function binFromOwnInstall(packageName, binName) {
|
|
421
|
-
try {
|
|
422
|
-
const manifest = require2.resolve(`${packageName}/package.json`);
|
|
423
|
-
const bin = require2(manifest).bin;
|
|
424
|
-
const relative8 = typeof bin === "string" ? bin : bin?.[binName];
|
|
425
|
-
if (!relative8) return void 0;
|
|
426
|
-
const executable = join5(dirname(manifest), relative8);
|
|
427
|
-
return existsSync5(executable) ? executable : void 0;
|
|
428
|
-
} catch {
|
|
429
|
-
return void 0;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
function binSearchPath(cwd) {
|
|
433
|
-
return [`${cwd}${delimiter}node_modules/.bin (and parents)`, "sentinel's own install"].join(
|
|
434
|
-
" then "
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
function scriptPath(cwd, path) {
|
|
438
|
-
const bins = [];
|
|
439
|
-
let dir = cwd;
|
|
440
|
-
for (; ; ) {
|
|
441
|
-
bins.push(join5(dir, "node_modules", ".bin"));
|
|
442
|
-
const parent = dirname(dir);
|
|
443
|
-
if (parent === dir) break;
|
|
444
|
-
dir = parent;
|
|
445
|
-
}
|
|
446
|
-
return [...bins, path].filter(Boolean).join(delimiter);
|
|
447
|
-
}
|
|
414
|
+
import { join as join5, resolve as resolve2 } from "node:path";
|
|
448
415
|
|
|
449
416
|
// src/roles/test/baseline.ts
|
|
450
417
|
function readSnapshot(report) {
|
|
@@ -712,7 +679,7 @@ function describeComparison(comparison) {
|
|
|
712
679
|
// src/roles/test/reference.ts
|
|
713
680
|
function referencePath(cwd, suite) {
|
|
714
681
|
const key = createHash("sha256").update(`${resolve2(cwd)}\0${suite}`).digest("hex").slice(0, 16);
|
|
715
|
-
return
|
|
682
|
+
return join5(tmpdir(), "sentinel-test-reference", `${key}.json`);
|
|
716
683
|
}
|
|
717
684
|
function suiteOf(config) {
|
|
718
685
|
const base = config.replace(/^(jest|vitest)\./, "").replace(/\.[cm]?[jt]s$/, "");
|
|
@@ -723,9 +690,9 @@ function runJest(cwd, config) {
|
|
|
723
690
|
const bin = resolveBin(cwd, "jest");
|
|
724
691
|
if (bin === void 0) return void 0;
|
|
725
692
|
const root = findWorkspaceRoot(cwd) ?? cwd;
|
|
726
|
-
const out =
|
|
693
|
+
const out = join5(mkdtempSync(join5(tmpdir(), "sentinel-reference-")), "jest.json");
|
|
727
694
|
try {
|
|
728
|
-
execFileSync(bin, ["-c",
|
|
695
|
+
execFileSync(bin, ["-c", join5(cwd, config), "--json", `--outputFile=${out}`, "--silent"], {
|
|
729
696
|
cwd: root,
|
|
730
697
|
/*
|
|
731
698
|
* ⚠️ The module's environment, not the shell's, and this is what made the reference lie.
|
|
@@ -740,7 +707,7 @@ function runJest(cwd, config) {
|
|
|
740
707
|
});
|
|
741
708
|
} catch {
|
|
742
709
|
}
|
|
743
|
-
if (!
|
|
710
|
+
if (!existsSync5(out)) return void 0;
|
|
744
711
|
try {
|
|
745
712
|
return JSON.parse(readFileSync5(out, "utf8"));
|
|
746
713
|
} catch {
|
|
@@ -773,7 +740,7 @@ function captureReference(cwd, config) {
|
|
|
773
740
|
snapshot
|
|
774
741
|
};
|
|
775
742
|
const path = referencePath(cwd, suiteOf(config));
|
|
776
|
-
mkdirSync(
|
|
743
|
+
mkdirSync(join5(path, ".."), { recursive: true });
|
|
777
744
|
writeFileSync(path, `${JSON.stringify(stored, void 0, 2)}
|
|
778
745
|
`);
|
|
779
746
|
return {
|
|
@@ -782,7 +749,7 @@ function captureReference(cwd, config) {
|
|
|
782
749
|
};
|
|
783
750
|
}
|
|
784
751
|
function hasReference(cwd, suite) {
|
|
785
|
-
return
|
|
752
|
+
return existsSync5(referencePath(cwd, suite));
|
|
786
753
|
}
|
|
787
754
|
function compareAgainstReference(cwd, suite, report) {
|
|
788
755
|
const path = referencePath(cwd, suite);
|
|
@@ -812,9 +779,9 @@ function resolveVitest(cwd) {
|
|
|
812
779
|
|
|
813
780
|
// src/roles/test/adapters/vitest/vitest.adapter.ts
|
|
814
781
|
import { spawnSync } from "node:child_process";
|
|
815
|
-
import { existsSync as
|
|
782
|
+
import { existsSync as existsSync22, mkdtempSync as mkdtempSync3, readFileSync as readFileSync23, writeFileSync as writeFileSync2 } from "node:fs";
|
|
816
783
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
817
|
-
import { isAbsolute as isAbsolute2, join as
|
|
784
|
+
import { isAbsolute as isAbsolute2, join as join28, relative as relative7, resolve as resolve10 } from "node:path";
|
|
818
785
|
|
|
819
786
|
// src/roles/test/ordering-is-a-permutation.ts
|
|
820
787
|
function isAnImport(line) {
|
|
@@ -839,15 +806,15 @@ function lineLostByTheFixer(before, after) {
|
|
|
839
806
|
}
|
|
840
807
|
|
|
841
808
|
// src/core/config/nx-target.ts
|
|
842
|
-
import { existsSync as
|
|
843
|
-
import { join as
|
|
809
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
810
|
+
import { join as join7 } from "node:path";
|
|
844
811
|
|
|
845
812
|
// src/core/config/project-json.ts
|
|
846
|
-
import { existsSync as
|
|
847
|
-
import { join as
|
|
813
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "node:fs";
|
|
814
|
+
import { join as join6 } from "node:path";
|
|
848
815
|
function projectTargets(cwd) {
|
|
849
|
-
const path =
|
|
850
|
-
if (!
|
|
816
|
+
const path = join6(cwd, "project.json");
|
|
817
|
+
if (!existsSync6(path)) return void 0;
|
|
851
818
|
try {
|
|
852
819
|
return JSON.parse(readFileSync6(path, "utf8")).targets;
|
|
853
820
|
} catch {
|
|
@@ -900,7 +867,7 @@ function nxTargetOperations(options) {
|
|
|
900
867
|
if (names.length === 0) return [];
|
|
901
868
|
const targets = withTeamInputs(cwd, options.targets);
|
|
902
869
|
const operations = [];
|
|
903
|
-
if (
|
|
870
|
+
if (existsSync7(join7(cwd, "project.json"))) {
|
|
904
871
|
operations.push({
|
|
905
872
|
kind: "remove-json-keys",
|
|
906
873
|
path: "project.json",
|
|
@@ -1004,24 +971,24 @@ function rewriteToolchainImports(toolchain, source, fileName) {
|
|
|
1004
971
|
}
|
|
1005
972
|
|
|
1006
973
|
// src/roles/test/jest-migration.ts
|
|
1007
|
-
import { existsSync as
|
|
1008
|
-
import { createRequire as
|
|
1009
|
-
import { dirname as
|
|
974
|
+
import { existsSync as existsSync16, readFileSync as readFileSync18, readdirSync as readdirSync6 } from "node:fs";
|
|
975
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
976
|
+
import { dirname as dirname9, join as join21, relative as relative6 } from "node:path";
|
|
1010
977
|
|
|
1011
978
|
// src/roles/test/codemod/migrate-module.ts
|
|
1012
|
-
import { readdirSync as readdirSync4, readFileSync as
|
|
1013
|
-
import { join as
|
|
979
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync15, statSync as statSync5 } from "node:fs";
|
|
980
|
+
import { join as join17 } from "node:path";
|
|
1014
981
|
import { parseSync as parseSync9 } from "oxc-parser";
|
|
1015
982
|
|
|
1016
983
|
// src/roles/test/msw-lifecycle.ts
|
|
1017
|
-
import { existsSync as
|
|
1018
|
-
import { join as
|
|
984
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
|
|
985
|
+
import { join as join8 } from "node:path";
|
|
1019
986
|
var ROOT_SETUP = "jest.setup.after.env.js";
|
|
1020
987
|
function ownsMswLifecycle(cwd, setupFiles) {
|
|
1021
988
|
for (const raw of setupFiles) {
|
|
1022
989
|
if (raw.endsWith(ROOT_SETUP)) continue;
|
|
1023
|
-
const file =
|
|
1024
|
-
if (!
|
|
990
|
+
const file = join8(cwd, raw.replaceAll("<rootDir>/", "").replaceAll("<rootDir>", "."));
|
|
991
|
+
if (!existsSync8(file)) continue;
|
|
1025
992
|
try {
|
|
1026
993
|
if (/\.listen\s*\(/.test(readFileSync7(file, "utf8"))) return true;
|
|
1027
994
|
} catch {
|
|
@@ -1043,7 +1010,7 @@ function vitestSupportName(relative8) {
|
|
|
1043
1010
|
}
|
|
1044
1011
|
|
|
1045
1012
|
// src/roles/test/codemod/inherited-automocks.ts
|
|
1046
|
-
import { existsSync as
|
|
1013
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8 } from "node:fs";
|
|
1047
1014
|
import { resolve as resolve3 } from "node:path";
|
|
1048
1015
|
|
|
1049
1016
|
// src/shared/ast.ts
|
|
@@ -1087,7 +1054,7 @@ function inheritedAutomocks(cwd, setupFiles, parse6) {
|
|
|
1087
1054
|
for (const named of setupFiles) {
|
|
1088
1055
|
const path = resolve3(cwd, named.replace("<rootDir>/", "./"));
|
|
1089
1056
|
if (path.startsWith(`${cwd}/`)) continue;
|
|
1090
|
-
if (!
|
|
1057
|
+
if (!existsSync9(path)) continue;
|
|
1091
1058
|
let source;
|
|
1092
1059
|
try {
|
|
1093
1060
|
source = readFileSync8(path, "utf8");
|
|
@@ -1356,7 +1323,7 @@ ${source}`;
|
|
|
1356
1323
|
}
|
|
1357
1324
|
|
|
1358
1325
|
// src/roles/test/codemod/migrate-file.ts
|
|
1359
|
-
import { dirname as
|
|
1326
|
+
import { dirname as dirname7 } from "node:path";
|
|
1360
1327
|
import { parseSync as parseSync8 } from "oxc-parser";
|
|
1361
1328
|
|
|
1362
1329
|
// src/roles/test/codemod/edits.ts
|
|
@@ -2142,9 +2109,9 @@ function asyncifyEdits(source, fn) {
|
|
|
2142
2109
|
}
|
|
2143
2110
|
|
|
2144
2111
|
// src/roles/test/codemod/named-rules.ts
|
|
2145
|
-
import { existsSync as
|
|
2146
|
-
import { createRequire
|
|
2147
|
-
import { dirname as
|
|
2112
|
+
import { existsSync as existsSync10, readFileSync as readFileSync10 } from "node:fs";
|
|
2113
|
+
import { createRequire } from "node:module";
|
|
2114
|
+
import { dirname as dirname2, join as join10 } from "node:path";
|
|
2148
2115
|
|
|
2149
2116
|
// src/roles/test/codemod/namespace-import.ts
|
|
2150
2117
|
function sameModule(specifier) {
|
|
@@ -2214,7 +2181,7 @@ function namespaceBindings(program) {
|
|
|
2214
2181
|
|
|
2215
2182
|
// src/roles/test/codemod/static-import-for-require.ts
|
|
2216
2183
|
import { readFileSync as readFileSync9, statSync } from "node:fs";
|
|
2217
|
-
import { dirname
|
|
2184
|
+
import { dirname, join as join9, resolve as resolve4 } from "node:path";
|
|
2218
2185
|
import { parseSync as parseSync4 } from "oxc-parser";
|
|
2219
2186
|
|
|
2220
2187
|
// src/shared/module-resolution.ts
|
|
@@ -2231,11 +2198,11 @@ var RESOLVABLE_EXTENSIONS = [
|
|
|
2231
2198
|
|
|
2232
2199
|
// src/roles/test/codemod/static-import-for-require.ts
|
|
2233
2200
|
function resolveRelative(fromFile, specifier) {
|
|
2234
|
-
const base = resolve4(
|
|
2201
|
+
const base = resolve4(dirname(fromFile), specifier);
|
|
2235
2202
|
const candidates = [
|
|
2236
2203
|
base,
|
|
2237
2204
|
...RESOLVABLE_EXTENSIONS.map((extension) => `${base}${extension}`),
|
|
2238
|
-
...RESOLVABLE_EXTENSIONS.map((extension) =>
|
|
2205
|
+
...RESOLVABLE_EXTENSIONS.map((extension) => join9(base, `index${extension}`))
|
|
2239
2206
|
];
|
|
2240
2207
|
for (const candidate of candidates) {
|
|
2241
2208
|
try {
|
|
@@ -2437,24 +2404,24 @@ function isCommonJsPackage(fromFile, specifier) {
|
|
|
2437
2404
|
if (specifier.startsWith(".") || specifier.startsWith("/")) return false;
|
|
2438
2405
|
let resolved;
|
|
2439
2406
|
try {
|
|
2440
|
-
resolved =
|
|
2407
|
+
resolved = createRequire(fromFile).resolve(specifier);
|
|
2441
2408
|
} catch {
|
|
2442
2409
|
return false;
|
|
2443
2410
|
}
|
|
2444
2411
|
if (!resolved.includes(`${"/"}node_modules${"/"}`)) return false;
|
|
2445
2412
|
if (resolved.endsWith(".mjs")) return false;
|
|
2446
2413
|
if (resolved.endsWith(".cjs")) return true;
|
|
2447
|
-
let dir =
|
|
2414
|
+
let dir = dirname2(resolved);
|
|
2448
2415
|
for (let depth = 0; depth < 12; depth += 1) {
|
|
2449
|
-
const manifest =
|
|
2450
|
-
if (
|
|
2416
|
+
const manifest = join10(dir, "package.json");
|
|
2417
|
+
if (existsSync10(manifest)) {
|
|
2451
2418
|
try {
|
|
2452
2419
|
return JSON.parse(readFileSync10(manifest, "utf8")).type !== "module";
|
|
2453
2420
|
} catch {
|
|
2454
2421
|
return false;
|
|
2455
2422
|
}
|
|
2456
2423
|
}
|
|
2457
|
-
const parent =
|
|
2424
|
+
const parent = dirname2(dir);
|
|
2458
2425
|
if (parent === dir) break;
|
|
2459
2426
|
dir = parent;
|
|
2460
2427
|
}
|
|
@@ -3325,8 +3292,8 @@ function propagateAwait(fileName, source, original, elsewhere = /* @__PURE__ */
|
|
|
3325
3292
|
|
|
3326
3293
|
// src/roles/test/codemod/reexport-barrel-mock.ts
|
|
3327
3294
|
import { readFileSync as readFileSync11, readdirSync as readdirSync2, statSync as statSync2 } from "node:fs";
|
|
3328
|
-
import { createRequire as
|
|
3329
|
-
import { dirname as
|
|
3295
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
3296
|
+
import { dirname as dirname3, join as join11 } from "node:path";
|
|
3330
3297
|
var PACKAGE_SUBPATH = /^(@[^/]+\/[^/]+|[^@.][^/]*)\/(.+)$/;
|
|
3331
3298
|
var PURE_REEXPORT = /^module\.exports\s*=\s*require\(\s*(['"])([^'"]+)\1\s*\)\s*;?$/;
|
|
3332
3299
|
function mockCalls(program) {
|
|
@@ -3354,14 +3321,14 @@ function mockCalls(program) {
|
|
|
3354
3321
|
}
|
|
3355
3322
|
function packageRoot(fromFile, name) {
|
|
3356
3323
|
try {
|
|
3357
|
-
return
|
|
3324
|
+
return dirname3(createRequire2(fromFile).resolve(`${name}/package.json`));
|
|
3358
3325
|
} catch {
|
|
3359
3326
|
return void 0;
|
|
3360
3327
|
}
|
|
3361
3328
|
}
|
|
3362
3329
|
function resolveFrom(fromFile, specifier) {
|
|
3363
3330
|
try {
|
|
3364
|
-
return
|
|
3331
|
+
return createRequire2(fromFile).resolve(specifier);
|
|
3365
3332
|
} catch {
|
|
3366
3333
|
return void 0;
|
|
3367
3334
|
}
|
|
@@ -3378,7 +3345,7 @@ function barrelsFor(fromFile, name, target) {
|
|
|
3378
3345
|
const aliases = [];
|
|
3379
3346
|
for (const entry of entries) {
|
|
3380
3347
|
if (!entry.endsWith(".js")) continue;
|
|
3381
|
-
const path =
|
|
3348
|
+
const path = join11(root, entry);
|
|
3382
3349
|
let body;
|
|
3383
3350
|
try {
|
|
3384
3351
|
if (!statSync2(path).isFile()) continue;
|
|
@@ -3481,17 +3448,17 @@ function rewriteRunnerArtefactNames(source, program) {
|
|
|
3481
3448
|
}
|
|
3482
3449
|
|
|
3483
3450
|
// src/roles/test/codemod/setup-static-imports.ts
|
|
3484
|
-
import { dirname as
|
|
3451
|
+
import { dirname as dirname5, resolve as resolve7 } from "node:path";
|
|
3485
3452
|
|
|
3486
3453
|
// src/core/context.ts
|
|
3487
|
-
import { existsSync as
|
|
3488
|
-
import { dirname as
|
|
3454
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
3455
|
+
import { dirname as dirname4, join as join13, resolve as resolve5 } from "node:path";
|
|
3489
3456
|
|
|
3490
3457
|
// src/core/discover-modules.ts
|
|
3491
3458
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
3492
3459
|
import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync12, rmSync as rmSync2 } from "node:fs";
|
|
3493
3460
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
3494
|
-
import { join as
|
|
3461
|
+
import { join as join12 } from "node:path";
|
|
3495
3462
|
function runNx(cwd, args) {
|
|
3496
3463
|
const nx = resolveBin(cwd, "nx") ?? "nx";
|
|
3497
3464
|
try {
|
|
@@ -3509,8 +3476,8 @@ function runNx(cwd, args) {
|
|
|
3509
3476
|
}
|
|
3510
3477
|
}
|
|
3511
3478
|
function readGraph(cwd) {
|
|
3512
|
-
const dir = mkdtempSync2(
|
|
3513
|
-
const file =
|
|
3479
|
+
const dir = mkdtempSync2(join12(tmpdir2(), "sentinel-nx-"));
|
|
3480
|
+
const file = join12(dir, "graph.json");
|
|
3514
3481
|
try {
|
|
3515
3482
|
runNx(cwd, ["graph", "--file", file]);
|
|
3516
3483
|
const parsed = JSON.parse(readFileSync12(file, "utf8"));
|
|
@@ -3522,7 +3489,7 @@ function readGraph(cwd) {
|
|
|
3522
3489
|
}
|
|
3523
3490
|
return Object.entries(nodes).map(([name, node]) => ({
|
|
3524
3491
|
name,
|
|
3525
|
-
root:
|
|
3492
|
+
root: join12(cwd, node.data.root)
|
|
3526
3493
|
}));
|
|
3527
3494
|
} finally {
|
|
3528
3495
|
rmSync2(dir, { recursive: true, force: true });
|
|
@@ -3563,20 +3530,20 @@ ${raw.slice(0, 300)}`
|
|
|
3563
3530
|
// src/core/context.ts
|
|
3564
3531
|
var MODULE_MARKERS = ["package.json", "project.json"];
|
|
3565
3532
|
function isModuleDir(cwd) {
|
|
3566
|
-
return MODULE_MARKERS.some((marker) =>
|
|
3533
|
+
return MODULE_MARKERS.some((marker) => existsSync11(join13(cwd, marker)));
|
|
3567
3534
|
}
|
|
3568
3535
|
function findModuleRoot(startDir, workspaceRoot) {
|
|
3569
3536
|
let dir = resolve5(startDir);
|
|
3570
3537
|
for (; ; ) {
|
|
3571
3538
|
if (workspaceRoot !== void 0 && dir === resolve5(workspaceRoot)) return void 0;
|
|
3572
3539
|
if (isModuleDir(dir)) return dir;
|
|
3573
|
-
const parent =
|
|
3540
|
+
const parent = dirname4(dir);
|
|
3574
3541
|
if (parent === dir) return void 0;
|
|
3575
3542
|
dir = parent;
|
|
3576
3543
|
}
|
|
3577
3544
|
}
|
|
3578
3545
|
function resolveContext(cwd, opts) {
|
|
3579
|
-
const atRoot =
|
|
3546
|
+
const atRoot = existsSync11(join13(cwd, WORKSPACE_ROOT_MARKER));
|
|
3580
3547
|
if (!atRoot && isModuleDir(cwd)) {
|
|
3581
3548
|
if (opts.module) {
|
|
3582
3549
|
throw new Error(
|
|
@@ -3604,37 +3571,40 @@ function resolveContext(cwd, opts) {
|
|
|
3604
3571
|
}
|
|
3605
3572
|
|
|
3606
3573
|
// src/roles/test/codemod/workspace-specifier.ts
|
|
3607
|
-
import { existsSync as
|
|
3608
|
-
import { join as
|
|
3574
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
3575
|
+
import { join as join14, relative as relative2, resolve as resolve6 } from "node:path";
|
|
3609
3576
|
var EXTENSIONS = ["", ".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", "/index.ts", "/index.js"];
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
if (!existsSync13(file)) return [];
|
|
3613
|
-
let paths;
|
|
3577
|
+
var SPEC_TSCONFIGS = ["tsconfig.spec.json", "tsconfig.app.json", "tsconfig.json"];
|
|
3578
|
+
function pathsFor(workspaceRoot, moduleRoot) {
|
|
3614
3579
|
try {
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
)
|
|
3580
|
+
if (moduleRoot !== void 0) return effectivePaths(moduleRoot, workspaceRoot, SPEC_TSCONFIGS);
|
|
3581
|
+
const file = join14(workspaceRoot, WORKSPACE_TSCONFIG);
|
|
3582
|
+
if (!existsSync12(file)) return void 0;
|
|
3583
|
+
const found = chainPaths(file);
|
|
3584
|
+
return found && { ...found, fromWorkspaceFallback: false };
|
|
3619
3585
|
} catch {
|
|
3620
|
-
return
|
|
3586
|
+
return void 0;
|
|
3621
3587
|
}
|
|
3588
|
+
}
|
|
3589
|
+
function pathEntries(workspaceRoot, moduleRoot) {
|
|
3590
|
+
const found = pathsFor(workspaceRoot, moduleRoot);
|
|
3591
|
+
if (found === void 0) return [];
|
|
3622
3592
|
const entries = [];
|
|
3623
|
-
for (const [key, targets] of Object.entries(paths
|
|
3593
|
+
for (const [key, targets] of Object.entries(found.paths)) {
|
|
3624
3594
|
const target = targets[0];
|
|
3625
3595
|
if (target === void 0) continue;
|
|
3626
3596
|
const wildcard = key.endsWith("/*") && target.endsWith("/*");
|
|
3627
3597
|
entries.push({
|
|
3628
3598
|
key: wildcard ? key.slice(0, -2) : key,
|
|
3629
|
-
target: resolve6(
|
|
3599
|
+
target: resolve6(found.baseDirectory, wildcard ? target.slice(0, -2) : target),
|
|
3630
3600
|
wildcard
|
|
3631
3601
|
});
|
|
3632
3602
|
}
|
|
3633
3603
|
return entries.sort((left, right) => right.target.length - left.target.length);
|
|
3634
3604
|
}
|
|
3635
|
-
function workspaceSpecifier(workspaceRoot, file) {
|
|
3605
|
+
function workspaceSpecifier(workspaceRoot, file, moduleRoot) {
|
|
3636
3606
|
const absolute = resolve6(file);
|
|
3637
|
-
for (const entry of pathEntries(workspaceRoot)) {
|
|
3607
|
+
for (const entry of pathEntries(workspaceRoot, moduleRoot)) {
|
|
3638
3608
|
if (!entry.wildcard) {
|
|
3639
3609
|
if (EXTENSIONS.some((extension) => `${entry.target}${extension}` === absolute)) {
|
|
3640
3610
|
return entry.key;
|
|
@@ -3662,12 +3632,12 @@ function requireCall(source, node) {
|
|
|
3662
3632
|
}
|
|
3663
3633
|
function importable(written, fileName, workspaceRoot) {
|
|
3664
3634
|
if (!written.startsWith(".")) return written;
|
|
3665
|
-
const fileDir =
|
|
3635
|
+
const fileDir = dirname5(fileName);
|
|
3666
3636
|
const moduleRoot = findModuleRoot(fileDir, workspaceRoot) ?? fileDir;
|
|
3667
3637
|
const target = resolve7(fileDir, written);
|
|
3668
3638
|
if (target.startsWith(`${moduleRoot}/`)) return written;
|
|
3669
3639
|
if (workspaceRoot === void 0) return void 0;
|
|
3670
|
-
return workspaceSpecifier(workspaceRoot, target);
|
|
3640
|
+
return workspaceSpecifier(workspaceRoot, target, moduleRoot);
|
|
3671
3641
|
}
|
|
3672
3642
|
function statement(fileName, source, node, specifier, written) {
|
|
3673
3643
|
if (node.type === "ExpressionStatement") return `import '${specifier}'`;
|
|
@@ -3778,16 +3748,16 @@ function rewriteMockFactoryGenerics(source, program) {
|
|
|
3778
3748
|
}
|
|
3779
3749
|
|
|
3780
3750
|
// src/roles/test/codemod/spy-on-internal-call.ts
|
|
3781
|
-
import { readFileSync as
|
|
3782
|
-
import { dirname as
|
|
3751
|
+
import { readFileSync as readFileSync13, statSync as statSync3 } from "node:fs";
|
|
3752
|
+
import { dirname as dirname6, join as join15, relative as relative3, resolve as resolve8 } from "node:path";
|
|
3783
3753
|
import { parseSync as parseSync7 } from "oxc-parser";
|
|
3784
3754
|
function resolveRelative2(fromFile, specifier) {
|
|
3785
3755
|
if (!specifier.startsWith(".")) return void 0;
|
|
3786
|
-
const base = resolve8(
|
|
3756
|
+
const base = resolve8(dirname6(fromFile), specifier);
|
|
3787
3757
|
const candidates = [
|
|
3788
3758
|
base,
|
|
3789
3759
|
...RESOLVABLE_EXTENSIONS.map((extension) => `${base}${extension}`),
|
|
3790
|
-
...RESOLVABLE_EXTENSIONS.map((extension) =>
|
|
3760
|
+
...RESOLVABLE_EXTENSIONS.map((extension) => join15(base, `index${extension}`))
|
|
3791
3761
|
];
|
|
3792
3762
|
for (const candidate of candidates) {
|
|
3793
3763
|
try {
|
|
@@ -3799,7 +3769,7 @@ function resolveRelative2(fromFile, specifier) {
|
|
|
3799
3769
|
}
|
|
3800
3770
|
function read(path) {
|
|
3801
3771
|
try {
|
|
3802
|
-
return
|
|
3772
|
+
return readFileSync13(path, "utf8");
|
|
3803
3773
|
} catch {
|
|
3804
3774
|
return void 0;
|
|
3805
3775
|
}
|
|
@@ -3920,7 +3890,7 @@ function importOf(program, local) {
|
|
|
3920
3890
|
return void 0;
|
|
3921
3891
|
}
|
|
3922
3892
|
function respell(fromFile, target) {
|
|
3923
|
-
const path = relative3(
|
|
3893
|
+
const path = relative3(dirname6(fromFile), target).replaceAll("\\", "/").replace(/\.(?:m|c)?[jt]sx?$/, "").replace(/\/index$/, "");
|
|
3924
3894
|
return path.startsWith(".") ? path : `./${path}`;
|
|
3925
3895
|
}
|
|
3926
3896
|
function namesInUse2(program) {
|
|
@@ -4233,7 +4203,7 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
4233
4203
|
fileName,
|
|
4234
4204
|
source,
|
|
4235
4205
|
beforeStatic,
|
|
4236
|
-
findWorkspaceRoot(
|
|
4206
|
+
findWorkspaceRoot(dirname7(fileName))
|
|
4237
4207
|
);
|
|
4238
4208
|
source = statics.source;
|
|
4239
4209
|
const original = statics.rewritten === 0 ? beforeStatic : parse3(fileName, source);
|
|
@@ -4354,7 +4324,7 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
4354
4324
|
*/
|
|
4355
4325
|
...statics.refusals.map((specifier) => ({
|
|
4356
4326
|
binding: specifier,
|
|
4357
|
-
reason: `\`require('${specifier}')\` reaches another project, and \`
|
|
4327
|
+
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.`
|
|
4358
4328
|
})),
|
|
4359
4329
|
...fakeTimers.refusals,
|
|
4360
4330
|
...hoist.refusals,
|
|
@@ -4371,8 +4341,8 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
4371
4341
|
}
|
|
4372
4342
|
|
|
4373
4343
|
// src/roles/test/codemod/test-support-files.ts
|
|
4374
|
-
import { existsSync as
|
|
4375
|
-
import { dirname as
|
|
4344
|
+
import { existsSync as existsSync13, readFileSync as readFileSync14, readdirSync as readdirSync3, statSync as statSync4 } from "node:fs";
|
|
4345
|
+
import { dirname as dirname8, join as join16, relative as relative4, resolve as resolve9 } from "node:path";
|
|
4376
4346
|
var THE_SHIM_CANNOT_ANSWER = [/\brequire\s*\(/, /\bjest\.(?:fn|Mock|SpyInstance)\s*</];
|
|
4377
4347
|
var SKIPPED = /* @__PURE__ */ new Set(["node_modules", "dist", "coverage", ".git", ".vite"]);
|
|
4378
4348
|
var TEST_FILE2 = /[.-](spec|test)\.[cm]?[jt]sx?$/;
|
|
@@ -4392,14 +4362,14 @@ function relativeSpecifiers2(source) {
|
|
|
4392
4362
|
return found;
|
|
4393
4363
|
}
|
|
4394
4364
|
function resolveSpecifier(fromFile, specifier) {
|
|
4395
|
-
const base = resolve9(
|
|
4396
|
-
if (
|
|
4365
|
+
const base = resolve9(dirname8(fromFile), specifier);
|
|
4366
|
+
if (existsSync13(base) && statSync4(base).isFile()) return base;
|
|
4397
4367
|
for (const extension of EXTENSIONS2) {
|
|
4398
|
-
if (
|
|
4368
|
+
if (existsSync13(`${base}${extension}`)) return `${base}${extension}`;
|
|
4399
4369
|
}
|
|
4400
4370
|
for (const extension of EXTENSIONS2) {
|
|
4401
|
-
const index =
|
|
4402
|
-
if (
|
|
4371
|
+
const index = join16(base, `index${extension}`);
|
|
4372
|
+
if (existsSync13(index)) return index;
|
|
4403
4373
|
}
|
|
4404
4374
|
return void 0;
|
|
4405
4375
|
}
|
|
@@ -4416,9 +4386,9 @@ function moduleSources(cwd) {
|
|
|
4416
4386
|
}
|
|
4417
4387
|
for (const entry of entries) {
|
|
4418
4388
|
if (entry.isDirectory()) {
|
|
4419
|
-
if (!SKIPPED.has(entry.name)) stack.push(
|
|
4389
|
+
if (!SKIPPED.has(entry.name)) stack.push(join16(dir, entry.name));
|
|
4420
4390
|
} else if (SOURCE_FILE.test(entry.name)) {
|
|
4421
|
-
found.push(
|
|
4391
|
+
found.push(join16(dir, entry.name));
|
|
4422
4392
|
}
|
|
4423
4393
|
}
|
|
4424
4394
|
}
|
|
@@ -4426,7 +4396,7 @@ function moduleSources(cwd) {
|
|
|
4426
4396
|
}
|
|
4427
4397
|
function read2(path) {
|
|
4428
4398
|
try {
|
|
4429
|
-
return
|
|
4399
|
+
return readFileSync14(path, "utf8");
|
|
4430
4400
|
} catch {
|
|
4431
4401
|
return void 0;
|
|
4432
4402
|
}
|
|
@@ -4438,7 +4408,7 @@ function setupFilesInside(cwd, named) {
|
|
|
4438
4408
|
const full = resolve9(cwd, withoutToken);
|
|
4439
4409
|
const inside = relative4(cwd, full);
|
|
4440
4410
|
if (inside.startsWith("..") || inside === "") continue;
|
|
4441
|
-
if (!
|
|
4411
|
+
if (!existsSync13(full)) continue;
|
|
4442
4412
|
kept.push(inside.replaceAll("\\", "/"));
|
|
4443
4413
|
}
|
|
4444
4414
|
return kept;
|
|
@@ -4484,7 +4454,7 @@ function parse4(fileName, source) {
|
|
|
4484
4454
|
}
|
|
4485
4455
|
function read3(path) {
|
|
4486
4456
|
try {
|
|
4487
|
-
return
|
|
4457
|
+
return readFileSync15(path, "utf8");
|
|
4488
4458
|
} catch {
|
|
4489
4459
|
return void 0;
|
|
4490
4460
|
}
|
|
@@ -4502,7 +4472,7 @@ function defaultImportedSpecifiers(cwd) {
|
|
|
4502
4472
|
}
|
|
4503
4473
|
for (const entry of entries) {
|
|
4504
4474
|
if (SKIPPED2.has(entry)) continue;
|
|
4505
|
-
const path =
|
|
4475
|
+
const path = join17(dir, entry);
|
|
4506
4476
|
let directory;
|
|
4507
4477
|
try {
|
|
4508
4478
|
directory = statSync5(path).isDirectory();
|
|
@@ -4534,13 +4504,13 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4534
4504
|
const defaultImported = defaultImportedSpecifiers(cwd);
|
|
4535
4505
|
const asyncHelpers = /* @__PURE__ */ new Set();
|
|
4536
4506
|
for (const relative8 of listTestSupportFiles(cwd, setupFiles)) {
|
|
4537
|
-
const source = read3(
|
|
4507
|
+
const source = read3(join17(cwd, relative8));
|
|
4538
4508
|
if (source === void 0) {
|
|
4539
4509
|
blockers.push({ file: relative8, reason: "this file could not be read" });
|
|
4540
4510
|
continue;
|
|
4541
4511
|
}
|
|
4542
4512
|
const migrated = migrateTestFile(
|
|
4543
|
-
|
|
4513
|
+
join17(cwd, relative8),
|
|
4544
4514
|
source,
|
|
4545
4515
|
defaultImported,
|
|
4546
4516
|
/* @__PURE__ */ new Set(),
|
|
@@ -4559,8 +4529,8 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4559
4529
|
const renamedTo = vitestSupportName(relative8);
|
|
4560
4530
|
if (!migrated.changed && renamedTo === relative8) continue;
|
|
4561
4531
|
if (renamedTo !== relative8) operations.push({ kind: "delete", path: relative8 });
|
|
4562
|
-
const before = parse4(
|
|
4563
|
-
const after = parse4(
|
|
4532
|
+
const before = parse4(join17(cwd, relative8), source);
|
|
4533
|
+
const after = parse4(join17(cwd, relative8), migrated.source);
|
|
4564
4534
|
if (before !== void 0 && after !== void 0) {
|
|
4565
4535
|
const wasAsync = asyncFunctionNames(before);
|
|
4566
4536
|
for (const name of asyncFunctionNames(after)) {
|
|
@@ -4569,17 +4539,17 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4569
4539
|
}
|
|
4570
4540
|
files++;
|
|
4571
4541
|
renamed += migrated.renamed;
|
|
4572
|
-
const contents = /\bvi\./.test(migrated.source) ? injectViImport(
|
|
4542
|
+
const contents = /\bvi\./.test(migrated.source) ? injectViImport(join17(cwd, renamedTo), migrated.source) : migrated.source;
|
|
4573
4543
|
operations.push({ kind: "write", path: renamedTo, contents });
|
|
4574
4544
|
}
|
|
4575
4545
|
for (const relative8 of listTestFiles(cwd)) {
|
|
4576
|
-
const source = read3(
|
|
4546
|
+
const source = read3(join17(cwd, relative8));
|
|
4577
4547
|
if (source === void 0) {
|
|
4578
4548
|
blockers.push({ file: relative8, reason: "this file could not be read" });
|
|
4579
4549
|
continue;
|
|
4580
4550
|
}
|
|
4581
4551
|
const migrated = migrateTestFile(
|
|
4582
|
-
|
|
4552
|
+
join17(cwd, relative8),
|
|
4583
4553
|
source,
|
|
4584
4554
|
defaultImported,
|
|
4585
4555
|
asyncHelpers,
|
|
@@ -4613,8 +4583,8 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4613
4583
|
}
|
|
4614
4584
|
|
|
4615
4585
|
// src/roles/test/nest/generate-config.ts
|
|
4616
|
-
import { readdirSync as readdirSync5, readFileSync as
|
|
4617
|
-
import { join as
|
|
4586
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync16, statSync as statSync6 } from "node:fs";
|
|
4587
|
+
import { join as join18, relative as relative5 } from "node:path";
|
|
4618
4588
|
import { parseSync as parseSync10 } from "oxc-parser";
|
|
4619
4589
|
var NEST_TEST_PRESET_SPECIFIER = "@hublo/sentinel/test/nest";
|
|
4620
4590
|
var REACT_TEST_PRESET_SPECIFIER = "@hublo/sentinel/test/react";
|
|
@@ -4661,7 +4631,7 @@ function readModuleTraits(cwd) {
|
|
|
4661
4631
|
}
|
|
4662
4632
|
for (const entry of entries) {
|
|
4663
4633
|
if (SKIPPED3.has(entry)) continue;
|
|
4664
|
-
const path =
|
|
4634
|
+
const path = join18(dir, entry);
|
|
4665
4635
|
let directory;
|
|
4666
4636
|
try {
|
|
4667
4637
|
directory = statSync6(path).isDirectory();
|
|
@@ -4675,7 +4645,7 @@ function readModuleTraits(cwd) {
|
|
|
4675
4645
|
if (!/\.tsx?$/.test(entry)) continue;
|
|
4676
4646
|
let source;
|
|
4677
4647
|
try {
|
|
4678
|
-
source =
|
|
4648
|
+
source = readFileSync16(path, "utf8");
|
|
4679
4649
|
} catch {
|
|
4680
4650
|
continue;
|
|
4681
4651
|
}
|
|
@@ -4816,8 +4786,8 @@ ${overrides.join("\n")}
|
|
|
4816
4786
|
}
|
|
4817
4787
|
|
|
4818
4788
|
// src/roles/test/nest/read-jest-config.ts
|
|
4819
|
-
import { existsSync as
|
|
4820
|
-
import { join as
|
|
4789
|
+
import { existsSync as existsSync14, readFileSync as readFileSync17 } from "node:fs";
|
|
4790
|
+
import { join as join19 } from "node:path";
|
|
4821
4791
|
var CARRIED = [
|
|
4822
4792
|
"testEnvironment",
|
|
4823
4793
|
"coverageDirectory",
|
|
@@ -5007,7 +4977,7 @@ function extendedConfig(source, cwd) {
|
|
|
5007
4977
|
(name) => name.replace(/^\.\//, "")
|
|
5008
4978
|
);
|
|
5009
4979
|
const file = candidates.find(
|
|
5010
|
-
(name) => /^jest[\w.-]*\.(ts|js)$/.test(name) &&
|
|
4980
|
+
(name) => /^jest[\w.-]*\.(ts|js)$/.test(name) && existsSync14(join19(cwd, name))
|
|
5011
4981
|
);
|
|
5012
4982
|
if (file === void 0) continue;
|
|
5013
4983
|
if (!new RegExp(String.raw`\{\s*\.\.\.${binding}\b`).test(source)) continue;
|
|
@@ -5034,11 +5004,11 @@ function sideEffects(source, extended) {
|
|
|
5034
5004
|
return found;
|
|
5035
5005
|
}
|
|
5036
5006
|
function readJestConfig(cwd, named) {
|
|
5037
|
-
const file = named ?? JEST_CONFIG_FILES.find((name) =>
|
|
5038
|
-
if (file === void 0 || !
|
|
5007
|
+
const file = named ?? JEST_CONFIG_FILES.find((name) => existsSync14(join19(cwd, name)));
|
|
5008
|
+
if (file === void 0 || !existsSync14(join19(cwd, file))) return void 0;
|
|
5039
5009
|
let source;
|
|
5040
5010
|
try {
|
|
5041
|
-
source =
|
|
5011
|
+
source = readFileSync17(join19(cwd, file), "utf8");
|
|
5042
5012
|
} catch {
|
|
5043
5013
|
return { file, refusals: [`${file} could not be read`], notes: [] };
|
|
5044
5014
|
}
|
|
@@ -5119,8 +5089,8 @@ function readJestConfig(cwd, named) {
|
|
|
5119
5089
|
}
|
|
5120
5090
|
|
|
5121
5091
|
// src/roles/test/nest/run-modes.ts
|
|
5122
|
-
import { existsSync as
|
|
5123
|
-
import { basename as basename2, join as
|
|
5092
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
5093
|
+
import { basename as basename2, join as join20 } from "node:path";
|
|
5124
5094
|
var JEST_EXECUTOR = "@nx/jest:jest";
|
|
5125
5095
|
var PRIMARY_CONFIG_FILE = "vitest.config.mts";
|
|
5126
5096
|
var PRIMARY_TARGET = "test";
|
|
@@ -5141,7 +5111,7 @@ function runModes(cwd, fallback) {
|
|
|
5141
5111
|
const jestConfig = entry.options?.jestConfig;
|
|
5142
5112
|
if (jestConfig === void 0) continue;
|
|
5143
5113
|
const name = configName(jestConfig);
|
|
5144
|
-
if (!
|
|
5114
|
+
if (!existsSync15(join20(cwd, name))) continue;
|
|
5145
5115
|
declared.push({
|
|
5146
5116
|
target,
|
|
5147
5117
|
jestConfig: name,
|
|
@@ -5165,260 +5135,16 @@ function runModes(cwd, fallback) {
|
|
|
5165
5135
|
);
|
|
5166
5136
|
}
|
|
5167
5137
|
|
|
5168
|
-
// src/roles/test/written-file-formatter.ts
|
|
5169
|
-
import { existsSync as existsSync18 } from "node:fs";
|
|
5170
|
-
import { dirname as dirname11, join as join24 } from "node:path";
|
|
5171
|
-
|
|
5172
|
-
// src/roles/format/read-adoption.ts
|
|
5173
|
-
import { existsSync as existsSync17, readFileSync as readFileSync19 } from "node:fs";
|
|
5174
|
-
import { join as join22 } from "node:path";
|
|
5175
|
-
|
|
5176
|
-
// src/roles/format/config-policy.ts
|
|
5177
|
-
var FORMAT_CONFIG_FILE = ".oxfmtrc.json";
|
|
5178
|
-
var FORMAT_SCRIPT_NAME = "format";
|
|
5179
|
-
var PROVENANCE_KEY = "$sentinel";
|
|
5180
|
-
var PERMITTED_LOCAL_KEYS = [
|
|
5181
|
-
"useTabs",
|
|
5182
|
-
"tabWidth",
|
|
5183
|
-
"printWidth",
|
|
5184
|
-
"semi",
|
|
5185
|
-
"singleQuote",
|
|
5186
|
-
"jsxSingleQuote",
|
|
5187
|
-
"trailingComma",
|
|
5188
|
-
"quoteProps",
|
|
5189
|
-
"bracketSpacing",
|
|
5190
|
-
"bracketSameLine",
|
|
5191
|
-
"arrowParens",
|
|
5192
|
-
"endOfLine",
|
|
5193
|
-
"objectWrap",
|
|
5194
|
-
"proseWrap",
|
|
5195
|
-
"experimentalOperatorPosition"
|
|
5196
|
-
];
|
|
5197
|
-
var ALWAYS_LOCAL_KEYS = ["ignorePatterns", "overrides"];
|
|
5198
|
-
var OWNED_WHEN_SET_KEYS = ["sortImports"];
|
|
5199
|
-
var FORMAT_DEFAULT_IGNORES = ["**/*.toml"];
|
|
5200
|
-
var PRETTIER_CONFIG_FILES = [
|
|
5201
|
-
".prettierrc",
|
|
5202
|
-
".prettierrc.json",
|
|
5203
|
-
".prettierrc.json5",
|
|
5204
|
-
".prettierrc.yml",
|
|
5205
|
-
".prettierrc.yaml",
|
|
5206
|
-
".prettierrc.js",
|
|
5207
|
-
".prettierrc.cjs",
|
|
5208
|
-
".prettierrc.mjs",
|
|
5209
|
-
"prettier.config.js",
|
|
5210
|
-
"prettier.config.cjs",
|
|
5211
|
-
"prettier.config.mjs"
|
|
5212
|
-
];
|
|
5213
|
-
function formatTargets() {
|
|
5214
|
-
return {
|
|
5215
|
-
[FORMAT_SCRIPT_NAME]: {
|
|
5216
|
-
cache: true,
|
|
5217
|
-
inputs: ["default", `{projectRoot}/${FORMAT_CONFIG_FILE}`]
|
|
5218
|
-
},
|
|
5219
|
-
[`${FORMAT_SCRIPT_NAME}:fix`]: { cache: false }
|
|
5220
|
-
};
|
|
5221
|
-
}
|
|
5222
|
-
|
|
5223
|
-
// src/roles/format/presets/base.json
|
|
5224
|
-
var base_default = {
|
|
5225
|
-
printWidth: 80,
|
|
5226
|
-
semi: false,
|
|
5227
|
-
singleQuote: true,
|
|
5228
|
-
trailingComma: "all",
|
|
5229
|
-
sortPackageJson: false,
|
|
5230
|
-
sortImports: false
|
|
5231
|
-
};
|
|
5232
|
-
|
|
5233
|
-
// src/roles/format/presets/nest-imports.json
|
|
5234
|
-
var nest_imports_default = {
|
|
5235
|
-
customGroups: [
|
|
5236
|
-
{
|
|
5237
|
-
groupName: "workspace",
|
|
5238
|
-
elementNamePattern: ["@hublo/**", "@shared/**", "@front/**", "@network/**"]
|
|
5239
|
-
}
|
|
5240
|
-
],
|
|
5241
|
-
groups: ["builtin", "external", "workspace", ["parent", "index"], "sibling"],
|
|
5242
|
-
newlinesBetween: true,
|
|
5243
|
-
order: "asc",
|
|
5244
|
-
ignoreCase: false
|
|
5245
|
-
};
|
|
5246
|
-
|
|
5247
|
-
// src/roles/format/preset-data.ts
|
|
5248
|
-
var FORMAT_PRESETS = ["base", "svelte", "nest"];
|
|
5249
|
-
function hasFormatPreset(name) {
|
|
5250
|
-
return FORMAT_PRESETS.includes(name);
|
|
5251
|
-
}
|
|
5252
|
-
function formatPresetName(declared) {
|
|
5253
|
-
if (declared === "svelte") return "svelte";
|
|
5254
|
-
if (declared === "nest") return "nest";
|
|
5255
|
-
return "base";
|
|
5256
|
-
}
|
|
5257
|
-
function formatPresetFor(preset) {
|
|
5258
|
-
const base = base_default;
|
|
5259
|
-
const name = formatPresetName(preset);
|
|
5260
|
-
if (name === "svelte") return { ...base, svelte: true };
|
|
5261
|
-
if (name === "nest") return { ...base, sortImports: nest_imports_default };
|
|
5262
|
-
return base;
|
|
5263
|
-
}
|
|
5264
|
-
|
|
5265
|
-
// src/roles/format/read-adoption.ts
|
|
5266
|
-
var NOT_ADOPTED = (configFile, unreadable = null) => ({
|
|
5267
|
-
configFile,
|
|
5268
|
-
preset: null,
|
|
5269
|
-
adopted: false,
|
|
5270
|
-
conformant: false,
|
|
5271
|
-
drift: [],
|
|
5272
|
-
local: {},
|
|
5273
|
-
presetVersion: null,
|
|
5274
|
-
effective: {},
|
|
5275
|
-
unreadable
|
|
5276
|
-
});
|
|
5277
|
-
function sameValue(a, b) {
|
|
5278
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
5279
|
-
}
|
|
5280
|
-
function readFormatAdoption(cwd) {
|
|
5281
|
-
const path = join22(cwd, FORMAT_CONFIG_FILE);
|
|
5282
|
-
if (!existsSync17(path)) return NOT_ADOPTED(null);
|
|
5283
|
-
let parsed;
|
|
5284
|
-
try {
|
|
5285
|
-
parsed = parseJsonc(readFileSync19(path, "utf8"), FORMAT_CONFIG_FILE);
|
|
5286
|
-
} catch (error) {
|
|
5287
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
5288
|
-
return NOT_ADOPTED(FORMAT_CONFIG_FILE, `${FORMAT_CONFIG_FILE} could not be parsed (${reason})`);
|
|
5289
|
-
}
|
|
5290
|
-
const provenance = parsed[PROVENANCE_KEY];
|
|
5291
|
-
if (!provenance || typeof provenance.preset !== "string") return NOT_ADOPTED(FORMAT_CONFIG_FILE);
|
|
5292
|
-
if (!hasFormatPreset(provenance.preset)) {
|
|
5293
|
-
return NOT_ADOPTED(
|
|
5294
|
-
FORMAT_CONFIG_FILE,
|
|
5295
|
-
`${FORMAT_CONFIG_FILE} declares the format preset "${provenance.preset}", which sentinel does not ship (shipped: ${FORMAT_PRESETS.join(", ")}). Re-run \`sentinel --init --format\`.`
|
|
5296
|
-
);
|
|
5297
|
-
}
|
|
5298
|
-
const declaredLocal = Array.isArray(provenance.local) ? provenance.local : [];
|
|
5299
|
-
const preset = formatPresetFor(provenance.preset);
|
|
5300
|
-
const drift = [];
|
|
5301
|
-
const local = {};
|
|
5302
|
-
for (const [key, expected] of Object.entries(preset)) {
|
|
5303
|
-
if (declaredLocal.includes(key)) {
|
|
5304
|
-
local[key] = parsed[key];
|
|
5305
|
-
continue;
|
|
5306
|
-
}
|
|
5307
|
-
if (!(key in parsed) || !sameValue(parsed[key], expected)) drift.push(key);
|
|
5308
|
-
}
|
|
5309
|
-
for (const key of declaredLocal) {
|
|
5310
|
-
if (!(key in preset)) local[key] = parsed[key];
|
|
5311
|
-
}
|
|
5312
|
-
for (const key of ALWAYS_LOCAL_KEYS) {
|
|
5313
|
-
if (key in parsed) local[key] = parsed[key];
|
|
5314
|
-
}
|
|
5315
|
-
return {
|
|
5316
|
-
configFile: FORMAT_CONFIG_FILE,
|
|
5317
|
-
preset: provenance.preset,
|
|
5318
|
-
adopted: true,
|
|
5319
|
-
conformant: drift.length === 0,
|
|
5320
|
-
drift,
|
|
5321
|
-
local,
|
|
5322
|
-
presetVersion: typeof provenance.version === "string" ? provenance.version : null,
|
|
5323
|
-
effective: parsed,
|
|
5324
|
-
unreadable: null
|
|
5325
|
-
};
|
|
5326
|
-
}
|
|
5327
|
-
|
|
5328
|
-
// src/roles/format/resolve-oxfmt.ts
|
|
5329
|
-
import { readFileSync as readFileSync20 } from "node:fs";
|
|
5330
|
-
import { createRequire as createRequire4 } from "node:module";
|
|
5331
|
-
import { dirname as dirname10, join as join23 } from "node:path";
|
|
5332
|
-
function resolveOxfmt(cwd) {
|
|
5333
|
-
return resolveBin(cwd, "oxfmt") ?? binFromOwnInstall("oxfmt", "oxfmt");
|
|
5334
|
-
}
|
|
5335
|
-
function oxfmtRejects(key, value) {
|
|
5336
|
-
const schema = configSchema();
|
|
5337
|
-
const property = schema?.properties?.[key];
|
|
5338
|
-
if (!property) return false;
|
|
5339
|
-
const definition = resolveRef(schema, property);
|
|
5340
|
-
if (Array.isArray(definition.enum)) return !definition.enum.includes(value);
|
|
5341
|
-
if (definition.type === "boolean") return typeof value !== "boolean";
|
|
5342
|
-
if (definition.type === "integer" || definition.type === "number")
|
|
5343
|
-
return typeof value !== "number";
|
|
5344
|
-
return false;
|
|
5345
|
-
}
|
|
5346
|
-
function resolveRef(schema, node) {
|
|
5347
|
-
const ref = node.$ref ?? node.allOf?.[0]?.$ref;
|
|
5348
|
-
const name = ref?.startsWith("#/definitions/") ? ref.slice("#/definitions/".length) : void 0;
|
|
5349
|
-
return (name ? schema.definitions?.[name] : void 0) ?? node;
|
|
5350
|
-
}
|
|
5351
|
-
var cachedSchema;
|
|
5352
|
-
function configSchema() {
|
|
5353
|
-
if (cachedSchema !== void 0) return cachedSchema ?? void 0;
|
|
5354
|
-
cachedSchema = readConfigSchema() ?? null;
|
|
5355
|
-
return cachedSchema ?? void 0;
|
|
5356
|
-
}
|
|
5357
|
-
function readConfigSchema() {
|
|
5358
|
-
try {
|
|
5359
|
-
const manifest = createRequire4(import.meta.url).resolve("oxfmt/package.json");
|
|
5360
|
-
const schemaPath = join23(dirname10(manifest), "configuration_schema.json");
|
|
5361
|
-
return JSON.parse(readFileSync20(schemaPath, "utf8"));
|
|
5362
|
-
} catch {
|
|
5363
|
-
return void 0;
|
|
5364
|
-
}
|
|
5365
|
-
}
|
|
5366
|
-
|
|
5367
|
-
// src/roles/test/written-file-formatter.ts
|
|
5368
|
-
var PRETTIER_CONFIGS = [
|
|
5369
|
-
".prettierrc",
|
|
5370
|
-
".prettierrc.json",
|
|
5371
|
-
".prettierrc.json5",
|
|
5372
|
-
".prettierrc.yaml",
|
|
5373
|
-
".prettierrc.yml",
|
|
5374
|
-
".prettierrc.js",
|
|
5375
|
-
".prettierrc.cjs",
|
|
5376
|
-
".prettierrc.mjs",
|
|
5377
|
-
".prettierrc.toml",
|
|
5378
|
-
"prettier.config.js",
|
|
5379
|
-
"prettier.config.cjs",
|
|
5380
|
-
"prettier.config.mjs"
|
|
5381
|
-
];
|
|
5382
|
-
function prettierConfigFrom(cwd) {
|
|
5383
|
-
let dir = cwd;
|
|
5384
|
-
for (; ; ) {
|
|
5385
|
-
for (const name of PRETTIER_CONFIGS) {
|
|
5386
|
-
if (existsSync18(join24(dir, name))) return join24(dir, name);
|
|
5387
|
-
}
|
|
5388
|
-
const parent = dirname11(dir);
|
|
5389
|
-
if (parent === dir) return void 0;
|
|
5390
|
-
dir = parent;
|
|
5391
|
-
}
|
|
5392
|
-
}
|
|
5393
|
-
function writtenFileFormatter(cwd) {
|
|
5394
|
-
if (readFormatAdoption(cwd).configFile !== null) {
|
|
5395
|
-
const oxfmt = resolveOxfmt(cwd);
|
|
5396
|
-
if (oxfmt !== void 0) {
|
|
5397
|
-
return { bin: oxfmt, args: ["--write"], origin: "this module's own oxfmt config" };
|
|
5398
|
-
}
|
|
5399
|
-
}
|
|
5400
|
-
const config = prettierConfigFrom(cwd);
|
|
5401
|
-
const prettier = resolveBin(cwd, "prettier");
|
|
5402
|
-
if (config !== void 0 && prettier !== void 0) {
|
|
5403
|
-
return {
|
|
5404
|
-
bin: prettier,
|
|
5405
|
-
args: ["--write", "--log-level", "warn"],
|
|
5406
|
-
origin: `the workspace's Prettier`
|
|
5407
|
-
};
|
|
5408
|
-
}
|
|
5409
|
-
return void 0;
|
|
5410
|
-
}
|
|
5411
|
-
|
|
5412
5138
|
// src/roles/test/jest-migration.ts
|
|
5413
5139
|
var SPEC_TSCONFIG = "tsconfig.spec.json";
|
|
5414
5140
|
var VITEST_GLOBAL_TYPES = "vitest/globals";
|
|
5415
5141
|
function specTypesOperation(cwd) {
|
|
5416
|
-
const path =
|
|
5417
|
-
if (!
|
|
5142
|
+
const path = join21(cwd, SPEC_TSCONFIG);
|
|
5143
|
+
if (!existsSync16(path)) return void 0;
|
|
5418
5144
|
let config;
|
|
5419
5145
|
try {
|
|
5420
5146
|
config = parseJsonc(
|
|
5421
|
-
|
|
5147
|
+
readFileSync18(path, "utf8"),
|
|
5422
5148
|
SPEC_TSCONFIG
|
|
5423
5149
|
);
|
|
5424
5150
|
} catch {
|
|
@@ -5437,12 +5163,12 @@ function specTypesOperation(cwd) {
|
|
|
5437
5163
|
};
|
|
5438
5164
|
}
|
|
5439
5165
|
function specTypesCleanupOperation(cwd) {
|
|
5440
|
-
const path =
|
|
5441
|
-
if (!
|
|
5166
|
+
const path = join21(cwd, SPEC_TSCONFIG);
|
|
5167
|
+
if (!existsSync16(path)) return void 0;
|
|
5442
5168
|
let config;
|
|
5443
5169
|
try {
|
|
5444
5170
|
config = parseJsonc(
|
|
5445
|
-
|
|
5171
|
+
readFileSync18(path, "utf8"),
|
|
5446
5172
|
SPEC_TSCONFIG
|
|
5447
5173
|
);
|
|
5448
5174
|
} catch {
|
|
@@ -5460,9 +5186,9 @@ function specTypesCleanupOperation(cwd) {
|
|
|
5460
5186
|
}
|
|
5461
5187
|
function shippedTypesPath(cwd, declaration) {
|
|
5462
5188
|
try {
|
|
5463
|
-
const manifest =
|
|
5464
|
-
const file =
|
|
5465
|
-
if (
|
|
5189
|
+
const manifest = createRequire3(join21(cwd, "noop.cjs")).resolve("@hublo/sentinel/package.json");
|
|
5190
|
+
const file = join21(dirname9(manifest), declaration);
|
|
5191
|
+
if (existsSync16(file)) {
|
|
5466
5192
|
const path = relative6(cwd, file);
|
|
5467
5193
|
return path.startsWith(".") ? path : `./${path}`;
|
|
5468
5194
|
}
|
|
@@ -5481,7 +5207,7 @@ function helpersStillCallingJest(cwd) {
|
|
|
5481
5207
|
return;
|
|
5482
5208
|
}
|
|
5483
5209
|
for (const entry of entries) {
|
|
5484
|
-
const path =
|
|
5210
|
+
const path = join21(dir, entry.name);
|
|
5485
5211
|
if (entry.isDirectory()) {
|
|
5486
5212
|
if (!skip.has(entry.name)) walk2(path);
|
|
5487
5213
|
continue;
|
|
@@ -5491,7 +5217,7 @@ function helpersStillCallingJest(cwd) {
|
|
|
5491
5217
|
if (/^(jest|vitest)\./.test(entry.name)) continue;
|
|
5492
5218
|
let source;
|
|
5493
5219
|
try {
|
|
5494
|
-
source =
|
|
5220
|
+
source = readFileSync18(path, "utf8");
|
|
5495
5221
|
} catch {
|
|
5496
5222
|
continue;
|
|
5497
5223
|
}
|
|
@@ -5528,7 +5254,7 @@ function tsconfigFileListOperations(cwd) {
|
|
|
5528
5254
|
let config;
|
|
5529
5255
|
try {
|
|
5530
5256
|
config = parseJsonc(
|
|
5531
|
-
|
|
5257
|
+
readFileSync18(join21(cwd, name), "utf8"),
|
|
5532
5258
|
name
|
|
5533
5259
|
);
|
|
5534
5260
|
} catch {
|
|
@@ -5904,9 +5630,10 @@ function plan(context) {
|
|
|
5904
5630
|
const rewritten = rewriteVitestScript(command);
|
|
5905
5631
|
if (rewritten !== command) siblingScripts[name] = rewritten;
|
|
5906
5632
|
}
|
|
5633
|
+
const owned = ownedTestDependencies(context.cwd, adoption.ownDeclarations);
|
|
5907
5634
|
if (Object.keys(siblingScripts).length > 0) {
|
|
5908
5635
|
notes.push(
|
|
5909
|
-
`rewrote ${Object.keys(siblingScripts).join(", ")} to run through sentinel: they called vitest directly
|
|
5636
|
+
`rewrote ${Object.keys(siblingScripts).join(", ")} to run through sentinel: they called vitest directly` + (owned.length > 0 ? `, and the dependency they relied on is removed below` : "") + `. A watch script keeps watching, through \`-- --watch\`.`
|
|
5910
5637
|
);
|
|
5911
5638
|
}
|
|
5912
5639
|
operations.push(
|
|
@@ -5927,7 +5654,6 @@ function plan(context) {
|
|
|
5927
5654
|
})
|
|
5928
5655
|
})
|
|
5929
5656
|
);
|
|
5930
|
-
const owned = ownedTestDependencies(context.cwd, adoption.ownDeclarations);
|
|
5931
5657
|
if (owned.length > 0) {
|
|
5932
5658
|
operations.push({ kind: "remove-json-keys", path: "package.json", keys: owned });
|
|
5933
5659
|
notes.push(
|
|
@@ -5943,12 +5669,12 @@ function plan(context) {
|
|
|
5943
5669
|
}
|
|
5944
5670
|
|
|
5945
5671
|
// src/roles/test/written-file-linter.ts
|
|
5946
|
-
import { existsSync as
|
|
5947
|
-
import { join as
|
|
5672
|
+
import { existsSync as existsSync21 } from "node:fs";
|
|
5673
|
+
import { join as join27 } from "node:path";
|
|
5948
5674
|
|
|
5949
5675
|
// src/roles/lint/module-baseline.ts
|
|
5950
|
-
import { existsSync as
|
|
5951
|
-
import { join as
|
|
5676
|
+
import { existsSync as existsSync17, readFileSync as readFileSync19 } from "node:fs";
|
|
5677
|
+
import { join as join22 } from "node:path";
|
|
5952
5678
|
|
|
5953
5679
|
// src/roles/lint/oxlint-rule-owners.json
|
|
5954
5680
|
var oxlint_rule_owners_default = {
|
|
@@ -6690,10 +6416,10 @@ function describeHolds(holds) {
|
|
|
6690
6416
|
return `held ${holds.length} rule(s) at \`warn\` for this module, covering ${total} violation(s) that were already there: ${listed}${rest}. They are written to ${LINT_BASELINE_FILE}, they still report, and they return to \`error\` once fixed and re-initialized`;
|
|
6691
6417
|
}
|
|
6692
6418
|
function heldRules(cwd) {
|
|
6693
|
-
const path =
|
|
6694
|
-
if (!
|
|
6419
|
+
const path = join22(cwd, LINT_BASELINE_FILE);
|
|
6420
|
+
if (!existsSync17(path)) return [];
|
|
6695
6421
|
try {
|
|
6696
|
-
const parsed = parseJsonc(
|
|
6422
|
+
const parsed = parseJsonc(readFileSync19(path, "utf8"), LINT_BASELINE_FILE);
|
|
6697
6423
|
const scoped = (parsed.overrides ?? []).flatMap((override) => Object.keys(override.rules ?? {}));
|
|
6698
6424
|
return [.../* @__PURE__ */ new Set([...Object.keys(parsed.rules ?? {}), ...scoped])];
|
|
6699
6425
|
} catch {
|
|
@@ -6729,7 +6455,7 @@ var SENTINEL_LINT_PRESET = /@hublo\/sentinel\/(?:lint|oxlint)\/([a-z-]+)\.json$/
|
|
|
6729
6455
|
function presetNameFromPath(preset) {
|
|
6730
6456
|
return preset ? SENTINEL_LINT_PRESET.exec(preset)?.[1] ?? void 0 : void 0;
|
|
6731
6457
|
}
|
|
6732
|
-
var
|
|
6458
|
+
var PERMITTED_LOCAL_KEYS = ["extends", "ignorePatterns"];
|
|
6733
6459
|
var ESLINT_CONFIG_FILES = [
|
|
6734
6460
|
"eslint.config.js",
|
|
6735
6461
|
"eslint.config.mjs",
|
|
@@ -6741,12 +6467,12 @@ function lintTarget() {
|
|
|
6741
6467
|
}
|
|
6742
6468
|
|
|
6743
6469
|
// src/roles/lint/read-adoption.ts
|
|
6744
|
-
import { readFileSync as
|
|
6745
|
-
import { join as
|
|
6470
|
+
import { readFileSync as readFileSync22 } from "node:fs";
|
|
6471
|
+
import { join as join25 } from "node:path";
|
|
6746
6472
|
|
|
6747
6473
|
// src/core/config/read-adoption.ts
|
|
6748
|
-
import { existsSync as
|
|
6749
|
-
import { join as
|
|
6474
|
+
import { existsSync as existsSync19, readFileSync as readFileSync21 } from "node:fs";
|
|
6475
|
+
import { join as join24 } from "node:path";
|
|
6750
6476
|
|
|
6751
6477
|
// src/core/config/owned-keys.ts
|
|
6752
6478
|
function presetOwnedKeys(config, permitted, presetSets) {
|
|
@@ -6761,12 +6487,12 @@ function localOnlyKeys(config, permitted, presetSets) {
|
|
|
6761
6487
|
}
|
|
6762
6488
|
|
|
6763
6489
|
// src/core/config/resolve-config-target.ts
|
|
6764
|
-
import { existsSync as
|
|
6765
|
-
import { join as
|
|
6490
|
+
import { existsSync as existsSync18, readFileSync as readFileSync20 } from "node:fs";
|
|
6491
|
+
import { join as join23 } from "node:path";
|
|
6766
6492
|
function readExtends(absolutePath) {
|
|
6767
6493
|
let parsed;
|
|
6768
6494
|
try {
|
|
6769
|
-
parsed = parseJsonc(
|
|
6495
|
+
parsed = parseJsonc(readFileSync20(absolutePath, "utf8"), absolutePath);
|
|
6770
6496
|
} catch {
|
|
6771
6497
|
return [];
|
|
6772
6498
|
}
|
|
@@ -6780,8 +6506,8 @@ function resolveConfigTarget(moduleDir, { candidates, markers, fallback }) {
|
|
|
6780
6506
|
let existing;
|
|
6781
6507
|
let existingExtendsSomething = false;
|
|
6782
6508
|
for (const candidate of candidates) {
|
|
6783
|
-
const absolutePath =
|
|
6784
|
-
if (!
|
|
6509
|
+
const absolutePath = join23(moduleDir, candidate);
|
|
6510
|
+
if (!existsSync18(absolutePath)) continue;
|
|
6785
6511
|
const chain = readExtends(absolutePath);
|
|
6786
6512
|
if (existing === void 0) {
|
|
6787
6513
|
existing = candidate;
|
|
@@ -6804,7 +6530,7 @@ function normaliseExtends(value) {
|
|
|
6804
6530
|
}
|
|
6805
6531
|
return [];
|
|
6806
6532
|
}
|
|
6807
|
-
var
|
|
6533
|
+
var NOT_ADOPTED = (configFile, unreadable = null) => ({
|
|
6808
6534
|
configFile,
|
|
6809
6535
|
preset: null,
|
|
6810
6536
|
adopted: false,
|
|
@@ -6814,18 +6540,18 @@ var NOT_ADOPTED2 = (configFile, unreadable = null) => ({
|
|
|
6814
6540
|
});
|
|
6815
6541
|
function readAdoption(cwd, options) {
|
|
6816
6542
|
const target = resolveConfigTarget(cwd, options);
|
|
6817
|
-
if (target.reason === "none" || !
|
|
6818
|
-
return
|
|
6543
|
+
if (target.reason === "none" || !existsSync19(join24(cwd, target.path))) {
|
|
6544
|
+
return NOT_ADOPTED(target.reason === "none" ? null : target.path);
|
|
6819
6545
|
}
|
|
6820
6546
|
let parsed;
|
|
6821
6547
|
try {
|
|
6822
|
-
parsed = parseJsonc(
|
|
6548
|
+
parsed = parseJsonc(readFileSync21(join24(cwd, target.path), "utf8"), target.path);
|
|
6823
6549
|
} catch (error) {
|
|
6824
6550
|
const reason = error instanceof Error ? error.message : String(error);
|
|
6825
|
-
return
|
|
6551
|
+
return NOT_ADOPTED(target.path, `${target.path} could not be parsed (${reason})`);
|
|
6826
6552
|
}
|
|
6827
6553
|
const preset = normaliseExtends(parsed.extends).find((entry) => options.presetPattern.test(entry)) ?? null;
|
|
6828
|
-
if (preset === null) return
|
|
6554
|
+
if (preset === null) return NOT_ADOPTED(target.path);
|
|
6829
6555
|
const settings = options.settingsKey === null ? parsed : parsed[options.settingsKey];
|
|
6830
6556
|
const owned = presetOwnedKeys(settings, options.permitted, options.presetOwns?.(preset));
|
|
6831
6557
|
const drift = options.refineDrift !== void 0 && settings !== void 0 ? options.refineDrift(owned, settings, preset) : owned;
|
|
@@ -9447,6 +9173,11 @@ function disabledFor(preset) {
|
|
|
9447
9173
|
function downgradedFor(preset) {
|
|
9448
9174
|
return decisionsAt(preset, "warn");
|
|
9449
9175
|
}
|
|
9176
|
+
function scopedDecisionsAt(preset, severity) {
|
|
9177
|
+
return (presetFile(preset).overrides ?? []).flatMap(
|
|
9178
|
+
({ files, rules }) => Object.entries(rules).filter(([, value]) => isDecision(value) && value.severity === severity).map(([rule, value]) => ({ rule, files, reason: value.reason })).sort((left, right) => left.rule.localeCompare(right.rule))
|
|
9179
|
+
);
|
|
9180
|
+
}
|
|
9450
9181
|
function decisionsAt(preset, severity) {
|
|
9451
9182
|
return Object.entries(layered(preset)).filter(([, value]) => isDecision(value) && value.severity === severity).map(([rule, value]) => ({ rule, reason: value.reason })).sort((left, right) => left.rule.localeCompare(right.rule));
|
|
9452
9183
|
}
|
|
@@ -9485,7 +9216,7 @@ function readLintAdoption(cwd) {
|
|
|
9485
9216
|
// Drift for lint is read from the TOP-LEVEL keys beyond `extends`, so the settings the
|
|
9486
9217
|
// shared reader inspects are the config's own root rather than a nested options object.
|
|
9487
9218
|
settingsKey: null,
|
|
9488
|
-
permitted:
|
|
9219
|
+
permitted: PERMITTED_LOCAL_KEYS,
|
|
9489
9220
|
// `rules` and `overrides` are drift only when they CONFLICT with the preset, by the
|
|
9490
9221
|
// criterion a re-init keeps or drops them by: a rule the preset does not name is the
|
|
9491
9222
|
// module's addition, kept and listed by `--inspect`, not drift. A preset sentinel does not
|
|
@@ -9503,7 +9234,7 @@ function readModuleAdditions(cwd) {
|
|
|
9503
9234
|
if (preset === void 0 || adoption.configFile === null) return NO_ADDITIONS;
|
|
9504
9235
|
try {
|
|
9505
9236
|
const config = parseJsonc(
|
|
9506
|
-
|
|
9237
|
+
readFileSync22(join25(cwd, adoption.configFile), "utf8"),
|
|
9507
9238
|
adoption.configFile
|
|
9508
9239
|
);
|
|
9509
9240
|
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
@@ -9520,15 +9251,15 @@ function readModuleAdditions(cwd) {
|
|
|
9520
9251
|
}
|
|
9521
9252
|
|
|
9522
9253
|
// src/roles/lint/resolve-oxlint.ts
|
|
9523
|
-
import { existsSync as
|
|
9524
|
-
import { createRequire as
|
|
9525
|
-
import { delimiter
|
|
9254
|
+
import { existsSync as existsSync20 } from "node:fs";
|
|
9255
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
9256
|
+
import { delimiter, dirname as dirname10, join as join26 } from "node:path";
|
|
9526
9257
|
import { fileURLToPath } from "node:url";
|
|
9527
9258
|
var PACKAGE_OF = {
|
|
9528
9259
|
oxlint: "oxlint",
|
|
9529
9260
|
tsgolint: "oxlint-tsgolint"
|
|
9530
9261
|
};
|
|
9531
|
-
var
|
|
9262
|
+
var require2 = createRequire4(import.meta.url);
|
|
9532
9263
|
function resolveOxlint(cwd, name = "oxlint") {
|
|
9533
9264
|
return resolveBin(cwd, name) ?? binFromOwnInstall(PACKAGE_OF[name], name);
|
|
9534
9265
|
}
|
|
@@ -9538,7 +9269,7 @@ function canRunTypeAware(cwd) {
|
|
|
9538
9269
|
function oxlintPath(cwd, env) {
|
|
9539
9270
|
const shim = tsgolintShim(cwd);
|
|
9540
9271
|
if (!shim) return env.PATH;
|
|
9541
|
-
return [
|
|
9272
|
+
return [dirname10(shim), env.PATH].filter(Boolean).join(delimiter);
|
|
9542
9273
|
}
|
|
9543
9274
|
function tsgolintShim(cwd) {
|
|
9544
9275
|
const fromModule = resolveBin(cwd, "tsgolint");
|
|
@@ -9546,19 +9277,19 @@ function tsgolintShim(cwd) {
|
|
|
9546
9277
|
const candidates = [];
|
|
9547
9278
|
for (const owner of ["oxlint-tsgolint", "oxlint"]) {
|
|
9548
9279
|
try {
|
|
9549
|
-
const packageDir =
|
|
9550
|
-
candidates.push(
|
|
9551
|
-
candidates.push(
|
|
9280
|
+
const packageDir = dirname10(require2.resolve(`${owner}/package.json`));
|
|
9281
|
+
candidates.push(join26(packageDir, "node_modules", ".bin", "tsgolint"));
|
|
9282
|
+
candidates.push(join26(packageDir, "..", ".bin", "tsgolint"));
|
|
9552
9283
|
} catch {
|
|
9553
9284
|
}
|
|
9554
9285
|
}
|
|
9555
9286
|
try {
|
|
9556
|
-
const ownRoot =
|
|
9557
|
-
candidates.push(
|
|
9287
|
+
const ownRoot = dirname10(require2.resolve("@hublo/sentinel/package.json"));
|
|
9288
|
+
candidates.push(join26(ownRoot, "node_modules", ".bin", "tsgolint"));
|
|
9558
9289
|
} catch {
|
|
9559
|
-
candidates.push(resolveBin(
|
|
9290
|
+
candidates.push(resolveBin(dirname10(fileURLToPath(import.meta.url)), "tsgolint") ?? "");
|
|
9560
9291
|
}
|
|
9561
|
-
return candidates.find((candidate) => candidate !== "" &&
|
|
9292
|
+
return candidates.find((candidate) => candidate !== "" && existsSync20(candidate));
|
|
9562
9293
|
}
|
|
9563
9294
|
function oxlintSearchPath(cwd) {
|
|
9564
9295
|
return binSearchPath(cwd);
|
|
@@ -9572,7 +9303,7 @@ function writtenFileLinter(cwd) {
|
|
|
9572
9303
|
return { bin: oxlint, args: ["--fix"], origin: "this module's own oxlint config" };
|
|
9573
9304
|
}
|
|
9574
9305
|
}
|
|
9575
|
-
const config = ESLINT_CONFIG_FILES.map((name) =>
|
|
9306
|
+
const config = ESLINT_CONFIG_FILES.map((name) => join27(cwd, name)).find((path) => existsSync21(path));
|
|
9576
9307
|
const eslint = resolveBin(cwd, "eslint");
|
|
9577
9308
|
if (config !== void 0 && eslint !== void 0) {
|
|
9578
9309
|
return {
|
|
@@ -9594,7 +9325,7 @@ var FORMATTABLE = /\.(m|c)?(j|t)sx?$|\.json$/;
|
|
|
9594
9325
|
var FORMAT_BATCH = 25;
|
|
9595
9326
|
function readIfPossible(path) {
|
|
9596
9327
|
try {
|
|
9597
|
-
return
|
|
9328
|
+
return readFileSync23(path, "utf8");
|
|
9598
9329
|
} catch {
|
|
9599
9330
|
return void 0;
|
|
9600
9331
|
}
|
|
@@ -9720,12 +9451,12 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9720
9451
|
const linter = writtenFileLinter(ctx.cwd);
|
|
9721
9452
|
if (linter === void 0) return;
|
|
9722
9453
|
const workspaceRoot = findWorkspaceRoot(ctx.cwd) ?? ctx.cwd;
|
|
9723
|
-
const fromRoot = (file) => relative7(workspaceRoot,
|
|
9454
|
+
const fromRoot = (file) => relative7(workspaceRoot, join28(ctx.cwd, file));
|
|
9724
9455
|
let unsettled = 0;
|
|
9725
9456
|
const reverted = [];
|
|
9726
9457
|
for (let at = 0; at < written.length; at += FORMAT_BATCH) {
|
|
9727
9458
|
const batch = written.slice(at, at + FORMAT_BATCH);
|
|
9728
|
-
const before = new Map(batch.map((file) => [file, readIfPossible(
|
|
9459
|
+
const before = new Map(batch.map((file) => [file, readIfPossible(join28(ctx.cwd, file))]));
|
|
9729
9460
|
const pass = spawnSync(linter.bin, [...linter.args, ...batch.map(fromRoot)], {
|
|
9730
9461
|
cwd: workspaceRoot,
|
|
9731
9462
|
encoding: "utf8"
|
|
@@ -9734,11 +9465,11 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9734
9465
|
for (const file of batch) {
|
|
9735
9466
|
const was = before.get(file);
|
|
9736
9467
|
if (was === void 0) continue;
|
|
9737
|
-
const now = readIfPossible(
|
|
9468
|
+
const now = readIfPossible(join28(ctx.cwd, file));
|
|
9738
9469
|
if (now === void 0 || now === was) continue;
|
|
9739
9470
|
const lost = lineLostByTheFixer(was, now);
|
|
9740
9471
|
if (lost === void 0) continue;
|
|
9741
|
-
writeFileSync2(
|
|
9472
|
+
writeFileSync2(join28(ctx.cwd, file), was);
|
|
9742
9473
|
reverted.push(`${file}: \`${lost.slice(0, 80)}\``);
|
|
9743
9474
|
}
|
|
9744
9475
|
}
|
|
@@ -9817,7 +9548,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9817
9548
|
metrics: { ..._VitestAdapter.NOTHING_TO_REPORT, error: "vitest not available" }
|
|
9818
9549
|
};
|
|
9819
9550
|
}
|
|
9820
|
-
const out =
|
|
9551
|
+
const out = join28(mkdtempSync3(join28(tmpdir3(), "sentinel-test-report-")), "vitest.json");
|
|
9821
9552
|
const { cwd: runFrom, options, env } = fromWorkspaceRoot(ctx.cwd, [], []);
|
|
9822
9553
|
const result = spawnSync(bin, ["run", ...options, "--reporter=json", `--outputFile=${out}`], {
|
|
9823
9554
|
cwd: runFrom,
|
|
@@ -9832,7 +9563,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9832
9563
|
metrics: { ..._VitestAdapter.NOTHING_TO_REPORT, error: result.error.message }
|
|
9833
9564
|
};
|
|
9834
9565
|
}
|
|
9835
|
-
if (!
|
|
9566
|
+
if (!existsSync22(out)) {
|
|
9836
9567
|
return {
|
|
9837
9568
|
ok: false,
|
|
9838
9569
|
code: 1,
|
|
@@ -9841,7 +9572,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9841
9572
|
}
|
|
9842
9573
|
let parsed;
|
|
9843
9574
|
try {
|
|
9844
|
-
parsed = JSON.parse(
|
|
9575
|
+
parsed = JSON.parse(readFileSync23(out, "utf8"));
|
|
9845
9576
|
} catch {
|
|
9846
9577
|
return {
|
|
9847
9578
|
ok: false,
|
|
@@ -9956,34 +9687,17 @@ function fromWorkspaceRoot(moduleDir, options, paths) {
|
|
|
9956
9687
|
}
|
|
9957
9688
|
|
|
9958
9689
|
export {
|
|
9690
|
+
BaseAdapter,
|
|
9959
9691
|
moduleScripts,
|
|
9960
9692
|
selfCommand,
|
|
9961
9693
|
adoptedPackageName,
|
|
9962
9694
|
manifestOperation,
|
|
9963
9695
|
projectTargets,
|
|
9964
|
-
|
|
9696
|
+
nxTargetOperations,
|
|
9697
|
+
RESOLVABLE_EXTENSIONS,
|
|
9965
9698
|
splitToolArgs,
|
|
9966
9699
|
separateToolArgs,
|
|
9967
|
-
resolveBin,
|
|
9968
|
-
binFromOwnInstall,
|
|
9969
|
-
binSearchPath,
|
|
9970
|
-
scriptPath,
|
|
9971
|
-
nxTargetOperations,
|
|
9972
|
-
FORMAT_CONFIG_FILE,
|
|
9973
|
-
FORMAT_SCRIPT_NAME,
|
|
9974
|
-
PROVENANCE_KEY,
|
|
9975
|
-
PERMITTED_LOCAL_KEYS,
|
|
9976
|
-
ALWAYS_LOCAL_KEYS,
|
|
9977
|
-
OWNED_WHEN_SET_KEYS,
|
|
9978
|
-
FORMAT_DEFAULT_IGNORES,
|
|
9979
|
-
PRETTIER_CONFIG_FILES,
|
|
9980
|
-
formatTargets,
|
|
9981
|
-
formatPresetName,
|
|
9982
|
-
formatPresetFor,
|
|
9983
|
-
readFormatAdoption,
|
|
9984
9700
|
rewriteToolchainImports,
|
|
9985
|
-
resolveOxfmt,
|
|
9986
|
-
oxfmtRejects,
|
|
9987
9701
|
canonicalRuleName,
|
|
9988
9702
|
describeRuleKey,
|
|
9989
9703
|
LINT_BASELINE_FILE,
|
|
@@ -10009,6 +9723,7 @@ export {
|
|
|
10009
9723
|
uncoveredFor,
|
|
10010
9724
|
disabledFor,
|
|
10011
9725
|
downgradedFor,
|
|
9726
|
+
scopedDecisionsAt,
|
|
10012
9727
|
governedRules,
|
|
10013
9728
|
moduleOwnBlocks,
|
|
10014
9729
|
isOffRuleValue,
|
|
@@ -10023,11 +9738,12 @@ export {
|
|
|
10023
9738
|
canRunTypeAware,
|
|
10024
9739
|
oxlintPath,
|
|
10025
9740
|
oxlintSearchPath,
|
|
9741
|
+
SKIP,
|
|
10026
9742
|
walk,
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
readTestAdoption,
|
|
9743
|
+
MEMBER_TYPES,
|
|
9744
|
+
findModuleRoot,
|
|
10030
9745
|
resolveContext,
|
|
9746
|
+
readTestAdoption,
|
|
10031
9747
|
moduleEnvironment,
|
|
10032
9748
|
suiteOf,
|
|
10033
9749
|
captureReference,
|