@hublo/sentinel 1.7.0-alpha.0 → 1.7.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/sentinel.js +77 -17
- package/dist/chunk-4UUL4SEW.js +50 -0
- package/dist/{chunk-VVEKPCRY.js → chunk-DLGBRLUU.js} +9 -6
- package/dist/chunk-DLGBRLUU.js.map +1 -0
- package/dist/{chunk-WMBXYYLD.js → chunk-EETHWJBF.js} +78 -21
- package/dist/{chunk-ZVHUG6CA.js → chunk-H4HAFJFZ.js} +4 -13
- package/dist/chunk-H4HAFJFZ.js.map +1 -0
- package/dist/{chunk-POZDYETY.js → chunk-LNFGVGLE.js} +5 -3
- package/dist/{chunk-POZDYETY.js.map → chunk-LNFGVGLE.js.map} +1 -1
- package/dist/chunk-QXFCZON7.js +16 -0
- package/dist/chunk-QXFCZON7.js.map +1 -0
- package/dist/{chunk-7E6YTTAK.js → chunk-THTXP2QU.js} +1 -1
- package/dist/chunk-THTXP2QU.js.map +1 -0
- package/dist/{chunk-EVGG55ZO.js → chunk-Z3JI7ZWX.js} +192 -223
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -4
- package/dist/migrate-NI33SXZD.js +517 -0
- package/dist/roles/build/nest/toolchain.js +3 -2
- package/dist/roles/build/nest/toolchain.js.map +1 -1
- package/dist/roles/static-analysis/config.js +1 -1
- package/dist/roles/test/nest/toolchain.js +4 -3
- package/dist/roles/test/nest/toolchain.js.map +1 -1
- package/dist/roles/test/react/toolchain.js +4 -3
- package/dist/roles/test/react/toolchain.js.map +1 -1
- package/dist/roles/test/shared-test-config.js +4 -3
- 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/{validate-VWP6YZP5.js → validate-LRHF63AW.js} +4 -2
- package/docs/typescript-adoption.md +52 -13
- package/docs/typescript-traces.md +1 -1
- package/package.json +4 -1
- package/dist/chunk-7E6YTTAK.js.map +0 -1
- package/dist/chunk-VVEKPCRY.js.map +0 -1
- package/dist/chunk-ZVHUG6CA.js.map +0 -1
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
binFromOwnInstall,
|
|
3
|
+
binSearchPath,
|
|
4
|
+
resolveBin
|
|
5
|
+
} from "./chunk-4UUL4SEW.js";
|
|
1
6
|
import {
|
|
2
7
|
DEFAULT_MAX_DIAGNOSTICS,
|
|
3
8
|
WORKSPACE_ROOT_MARKER,
|
|
@@ -13,9 +18,11 @@ import {
|
|
|
13
18
|
import {
|
|
14
19
|
WORKSPACE_TSCONFIG,
|
|
15
20
|
chainPaths,
|
|
16
|
-
effectivePaths
|
|
21
|
+
effectivePaths
|
|
22
|
+
} from "./chunk-H4HAFJFZ.js";
|
|
23
|
+
import {
|
|
17
24
|
parseJsonc
|
|
18
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-QXFCZON7.js";
|
|
19
26
|
|
|
20
27
|
// src/core/base-adapter.ts
|
|
21
28
|
var BaseAdapter = class {
|
|
@@ -30,12 +37,39 @@ var BaseAdapter = class {
|
|
|
30
37
|
}
|
|
31
38
|
};
|
|
32
39
|
|
|
40
|
+
// src/core/config/tool-args.ts
|
|
41
|
+
import { existsSync } from "node:fs";
|
|
42
|
+
import { isAbsolute, resolve } from "node:path";
|
|
43
|
+
function splitToolArgs(cwd, toolArgs = [], { valueFlags = [] } = {}) {
|
|
44
|
+
const takesValue = new Set(valueFlags);
|
|
45
|
+
const options = [];
|
|
46
|
+
const paths = [];
|
|
47
|
+
let previousTakesValue = false;
|
|
48
|
+
for (const arg of toolArgs) {
|
|
49
|
+
const looksLikeOption = arg.startsWith("-");
|
|
50
|
+
const target = isAbsolute(arg) ? arg : resolve(cwd, arg);
|
|
51
|
+
if (!previousTakesValue && !looksLikeOption && existsSync(target)) paths.push(arg);
|
|
52
|
+
else options.push(arg);
|
|
53
|
+
previousTakesValue = !arg.includes("=") && takesValue.has(arg);
|
|
54
|
+
}
|
|
55
|
+
return { options, paths };
|
|
56
|
+
}
|
|
57
|
+
function separateToolArgs(argv) {
|
|
58
|
+
const separator = argv.indexOf("--");
|
|
59
|
+
if (separator === -1) return { cliArgv: [...argv], toolArgs: [] };
|
|
60
|
+
const rest = argv.slice(separator + 1);
|
|
61
|
+
return {
|
|
62
|
+
cliArgv: argv.slice(0, separator),
|
|
63
|
+
toolArgs: rest[0] === "--" ? rest.slice(1) : rest
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
33
67
|
// src/roles/test/read-adoption.ts
|
|
34
|
-
import { existsSync as
|
|
68
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync } from "node:fs";
|
|
35
69
|
import { join as join3, relative } from "node:path";
|
|
36
70
|
|
|
37
71
|
// src/core/config/manifest.ts
|
|
38
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
72
|
+
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
39
73
|
import { basename, join } from "node:path";
|
|
40
74
|
function moduleScripts(cwd) {
|
|
41
75
|
try {
|
|
@@ -78,7 +112,7 @@ function manifestOperation(cwd, scripts) {
|
|
|
78
112
|
scripts,
|
|
79
113
|
devDependencies: { [own.name]: isSelfAdoption(cwd) ? "link:." : own.version }
|
|
80
114
|
};
|
|
81
|
-
if (
|
|
115
|
+
if (existsSync2(join(cwd, "package.json"))) {
|
|
82
116
|
return { kind: "merge-json", path: "package.json", value };
|
|
83
117
|
}
|
|
84
118
|
return {
|
|
@@ -207,15 +241,15 @@ var JEST_CONFIG_FILES = [
|
|
|
207
241
|
"jest.integration-config.ts"
|
|
208
242
|
];
|
|
209
243
|
function testConfigFile(cwd) {
|
|
210
|
-
return TEST_CONFIG_FILES.find((name) =>
|
|
244
|
+
return TEST_CONFIG_FILES.find((name) => existsSync3(join3(cwd, name)));
|
|
211
245
|
}
|
|
212
246
|
function jestConfigFiles(cwd) {
|
|
213
|
-
return JEST_CONFIG_FILES.filter((name) =>
|
|
247
|
+
return JEST_CONFIG_FILES.filter((name) => existsSync3(join3(cwd, name)));
|
|
214
248
|
}
|
|
215
249
|
function rootJestConfigFiles(cwd) {
|
|
216
250
|
const root = findWorkspaceRoot(cwd);
|
|
217
251
|
if (root === void 0 || root === cwd) return [];
|
|
218
|
-
return JEST_CONFIG_FILES.filter((name) =>
|
|
252
|
+
return JEST_CONFIG_FILES.filter((name) => existsSync3(join3(root, name)));
|
|
219
253
|
}
|
|
220
254
|
var TEST_FILE = /[.-](spec|test)\.[cm]?[jt]sx?$/;
|
|
221
255
|
var NOT_WALKED = /* @__PURE__ */ new Set(["node_modules", "dist", "coverage", ".git", ".nx", ".turbo"]);
|
|
@@ -331,7 +365,7 @@ function hasLostItsSuite(cwd, adoption) {
|
|
|
331
365
|
}
|
|
332
366
|
|
|
333
367
|
// src/roles/test/module-env.ts
|
|
334
|
-
import { existsSync as
|
|
368
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
|
|
335
369
|
import { join as join4 } from "node:path";
|
|
336
370
|
var CASCADE = [".env", ".env.test"];
|
|
337
371
|
var MODULE_CASCADE = [".env", ".env.local", ".env.test"];
|
|
@@ -363,7 +397,7 @@ function moduleEnvironment(cwd) {
|
|
|
363
397
|
...MODULE_CASCADE.map((name) => [join4(cwd, name), `<module>/${name}`])
|
|
364
398
|
];
|
|
365
399
|
for (const [path, label] of files) {
|
|
366
|
-
if (!
|
|
400
|
+
if (!existsSync4(path)) continue;
|
|
367
401
|
loaded.push(label);
|
|
368
402
|
Object.assign(added, parse(path));
|
|
369
403
|
}
|
|
@@ -376,51 +410,7 @@ import { execFileSync } from "node:child_process";
|
|
|
376
410
|
import { createHash } from "node:crypto";
|
|
377
411
|
import { existsSync as existsSync5, mkdirSync, mkdtempSync, readFileSync as readFileSync5, rmSync, writeFileSync } from "node:fs";
|
|
378
412
|
import { tmpdir } from "node:os";
|
|
379
|
-
import { join as
|
|
380
|
-
|
|
381
|
-
// src/shared/resolve-bin.ts
|
|
382
|
-
import { existsSync as existsSync4 } from "node:fs";
|
|
383
|
-
import { createRequire } from "node:module";
|
|
384
|
-
import { delimiter, dirname, join as join5 } from "node:path";
|
|
385
|
-
var require2 = createRequire(import.meta.url);
|
|
386
|
-
function resolveBin(fromDir, name) {
|
|
387
|
-
let dir = fromDir;
|
|
388
|
-
for (; ; ) {
|
|
389
|
-
const candidate = join5(dir, "node_modules", ".bin", name);
|
|
390
|
-
if (existsSync4(candidate)) return candidate;
|
|
391
|
-
const parent = dirname(dir);
|
|
392
|
-
if (parent === dir) return void 0;
|
|
393
|
-
dir = parent;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
function binFromOwnInstall(packageName, binName) {
|
|
397
|
-
try {
|
|
398
|
-
const manifest = require2.resolve(`${packageName}/package.json`);
|
|
399
|
-
const bin = require2(manifest).bin;
|
|
400
|
-
const relative8 = typeof bin === "string" ? bin : bin?.[binName];
|
|
401
|
-
if (!relative8) return void 0;
|
|
402
|
-
const executable = join5(dirname(manifest), relative8);
|
|
403
|
-
return existsSync4(executable) ? executable : void 0;
|
|
404
|
-
} catch {
|
|
405
|
-
return void 0;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
function binSearchPath(cwd) {
|
|
409
|
-
return [`${cwd}${delimiter}node_modules/.bin (and parents)`, "sentinel's own install"].join(
|
|
410
|
-
" then "
|
|
411
|
-
);
|
|
412
|
-
}
|
|
413
|
-
function scriptPath(cwd, path) {
|
|
414
|
-
const bins = [];
|
|
415
|
-
let dir = cwd;
|
|
416
|
-
for (; ; ) {
|
|
417
|
-
bins.push(join5(dir, "node_modules", ".bin"));
|
|
418
|
-
const parent = dirname(dir);
|
|
419
|
-
if (parent === dir) break;
|
|
420
|
-
dir = parent;
|
|
421
|
-
}
|
|
422
|
-
return [...bins, path].filter(Boolean).join(delimiter);
|
|
423
|
-
}
|
|
413
|
+
import { join as join5, resolve as resolve2 } from "node:path";
|
|
424
414
|
|
|
425
415
|
// src/roles/test/baseline.ts
|
|
426
416
|
function readSnapshot(report) {
|
|
@@ -687,8 +677,8 @@ function describeComparison(comparison) {
|
|
|
687
677
|
|
|
688
678
|
// src/roles/test/reference.ts
|
|
689
679
|
function referencePath(cwd, suite) {
|
|
690
|
-
const key = createHash("sha256").update(`${
|
|
691
|
-
return
|
|
680
|
+
const key = createHash("sha256").update(`${resolve2(cwd)}\0${suite}`).digest("hex").slice(0, 16);
|
|
681
|
+
return join5(tmpdir(), "sentinel-test-reference", `${key}.json`);
|
|
692
682
|
}
|
|
693
683
|
function suiteOf(config) {
|
|
694
684
|
const base = config.replace(/^(jest|vitest)\./, "").replace(/\.[cm]?[jt]s$/, "");
|
|
@@ -699,9 +689,9 @@ function runJest(cwd, config) {
|
|
|
699
689
|
const bin = resolveBin(cwd, "jest");
|
|
700
690
|
if (bin === void 0) return void 0;
|
|
701
691
|
const root = findWorkspaceRoot(cwd) ?? cwd;
|
|
702
|
-
const out =
|
|
692
|
+
const out = join5(mkdtempSync(join5(tmpdir(), "sentinel-reference-")), "jest.json");
|
|
703
693
|
try {
|
|
704
|
-
execFileSync(bin, ["-c",
|
|
694
|
+
execFileSync(bin, ["-c", join5(cwd, config), "--json", `--outputFile=${out}`, "--silent"], {
|
|
705
695
|
cwd: root,
|
|
706
696
|
/*
|
|
707
697
|
* ⚠️ The module's environment, not the shell's, and this is what made the reference lie.
|
|
@@ -749,7 +739,7 @@ function captureReference(cwd, config) {
|
|
|
749
739
|
snapshot
|
|
750
740
|
};
|
|
751
741
|
const path = referencePath(cwd, suiteOf(config));
|
|
752
|
-
mkdirSync(
|
|
742
|
+
mkdirSync(join5(path, ".."), { recursive: true });
|
|
753
743
|
writeFileSync(path, `${JSON.stringify(stored, void 0, 2)}
|
|
754
744
|
`);
|
|
755
745
|
return {
|
|
@@ -788,27 +778,9 @@ function resolveVitest(cwd) {
|
|
|
788
778
|
|
|
789
779
|
// src/roles/test/adapters/vitest/vitest.adapter.ts
|
|
790
780
|
import { spawnSync } from "node:child_process";
|
|
791
|
-
import { existsSync as
|
|
781
|
+
import { existsSync as existsSync24, mkdtempSync as mkdtempSync3, readFileSync as readFileSync25, writeFileSync as writeFileSync2 } from "node:fs";
|
|
792
782
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
793
|
-
import { isAbsolute as isAbsolute2, join as
|
|
794
|
-
|
|
795
|
-
// src/core/config/tool-args.ts
|
|
796
|
-
import { existsSync as existsSync6 } from "node:fs";
|
|
797
|
-
import { isAbsolute, resolve as resolve2 } from "node:path";
|
|
798
|
-
function splitToolArgs(cwd, toolArgs = [], { valueFlags = [] } = {}) {
|
|
799
|
-
const takesValue = new Set(valueFlags);
|
|
800
|
-
const options = [];
|
|
801
|
-
const paths = [];
|
|
802
|
-
let previousTakesValue = false;
|
|
803
|
-
for (const arg of toolArgs) {
|
|
804
|
-
const looksLikeOption = arg.startsWith("-");
|
|
805
|
-
const target = isAbsolute(arg) ? arg : resolve2(cwd, arg);
|
|
806
|
-
if (!previousTakesValue && !looksLikeOption && existsSync6(target)) paths.push(arg);
|
|
807
|
-
else options.push(arg);
|
|
808
|
-
previousTakesValue = !arg.includes("=") && takesValue.has(arg);
|
|
809
|
-
}
|
|
810
|
-
return { options, paths };
|
|
811
|
-
}
|
|
783
|
+
import { isAbsolute as isAbsolute2, join as join31, relative as relative7, resolve as resolve10 } from "node:path";
|
|
812
784
|
|
|
813
785
|
// src/roles/test/ordering-is-a-permutation.ts
|
|
814
786
|
function isAnImport(line) {
|
|
@@ -833,15 +805,15 @@ function lineLostByTheFixer(before, after) {
|
|
|
833
805
|
}
|
|
834
806
|
|
|
835
807
|
// src/core/config/nx-target.ts
|
|
836
|
-
import { existsSync as
|
|
837
|
-
import { join as
|
|
808
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
809
|
+
import { join as join7 } from "node:path";
|
|
838
810
|
|
|
839
811
|
// src/core/config/project-json.ts
|
|
840
|
-
import { existsSync as
|
|
841
|
-
import { join as
|
|
812
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "node:fs";
|
|
813
|
+
import { join as join6 } from "node:path";
|
|
842
814
|
function projectTargets(cwd) {
|
|
843
|
-
const path =
|
|
844
|
-
if (!
|
|
815
|
+
const path = join6(cwd, "project.json");
|
|
816
|
+
if (!existsSync6(path)) return void 0;
|
|
845
817
|
try {
|
|
846
818
|
return JSON.parse(readFileSync6(path, "utf8")).targets;
|
|
847
819
|
} catch {
|
|
@@ -894,7 +866,7 @@ function nxTargetOperations(options) {
|
|
|
894
866
|
if (names.length === 0) return [];
|
|
895
867
|
const targets = withTeamInputs(cwd, options.targets);
|
|
896
868
|
const operations = [];
|
|
897
|
-
if (
|
|
869
|
+
if (existsSync7(join7(cwd, "project.json"))) {
|
|
898
870
|
operations.push({
|
|
899
871
|
kind: "remove-json-keys",
|
|
900
872
|
path: "project.json",
|
|
@@ -998,24 +970,24 @@ function rewriteToolchainImports(toolchain, source, fileName) {
|
|
|
998
970
|
}
|
|
999
971
|
|
|
1000
972
|
// src/roles/test/jest-migration.ts
|
|
1001
|
-
import { existsSync as
|
|
1002
|
-
import { createRequire as
|
|
1003
|
-
import { dirname as
|
|
973
|
+
import { existsSync as existsSync18, readFileSync as readFileSync20, readdirSync as readdirSync6 } from "node:fs";
|
|
974
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
975
|
+
import { dirname as dirname11, join as join24, relative as relative6 } from "node:path";
|
|
1004
976
|
|
|
1005
977
|
// src/roles/test/codemod/migrate-module.ts
|
|
1006
978
|
import { readdirSync as readdirSync4, readFileSync as readFileSync15, statSync as statSync5 } from "node:fs";
|
|
1007
|
-
import { join as
|
|
979
|
+
import { join as join17 } from "node:path";
|
|
1008
980
|
import { parseSync as parseSync9 } from "oxc-parser";
|
|
1009
981
|
|
|
1010
982
|
// src/roles/test/msw-lifecycle.ts
|
|
1011
|
-
import { existsSync as
|
|
1012
|
-
import { join as
|
|
983
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
|
|
984
|
+
import { join as join8 } from "node:path";
|
|
1013
985
|
var ROOT_SETUP = "jest.setup.after.env.js";
|
|
1014
986
|
function ownsMswLifecycle(cwd, setupFiles) {
|
|
1015
987
|
for (const raw of setupFiles) {
|
|
1016
988
|
if (raw.endsWith(ROOT_SETUP)) continue;
|
|
1017
|
-
const file =
|
|
1018
|
-
if (!
|
|
989
|
+
const file = join8(cwd, raw.replaceAll("<rootDir>/", "").replaceAll("<rootDir>", "."));
|
|
990
|
+
if (!existsSync8(file)) continue;
|
|
1019
991
|
try {
|
|
1020
992
|
if (/\.listen\s*\(/.test(readFileSync7(file, "utf8"))) return true;
|
|
1021
993
|
} catch {
|
|
@@ -1037,7 +1009,7 @@ function vitestSupportName(relative8) {
|
|
|
1037
1009
|
}
|
|
1038
1010
|
|
|
1039
1011
|
// src/roles/test/codemod/inherited-automocks.ts
|
|
1040
|
-
import { existsSync as
|
|
1012
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8 } from "node:fs";
|
|
1041
1013
|
import { resolve as resolve3 } from "node:path";
|
|
1042
1014
|
|
|
1043
1015
|
// src/shared/ast.ts
|
|
@@ -1081,7 +1053,7 @@ function inheritedAutomocks(cwd, setupFiles, parse6) {
|
|
|
1081
1053
|
for (const named of setupFiles) {
|
|
1082
1054
|
const path = resolve3(cwd, named.replace("<rootDir>/", "./"));
|
|
1083
1055
|
if (path.startsWith(`${cwd}/`)) continue;
|
|
1084
|
-
if (!
|
|
1056
|
+
if (!existsSync9(path)) continue;
|
|
1085
1057
|
let source;
|
|
1086
1058
|
try {
|
|
1087
1059
|
source = readFileSync8(path, "utf8");
|
|
@@ -1350,7 +1322,7 @@ ${source}`;
|
|
|
1350
1322
|
}
|
|
1351
1323
|
|
|
1352
1324
|
// src/roles/test/codemod/migrate-file.ts
|
|
1353
|
-
import { dirname as
|
|
1325
|
+
import { dirname as dirname7 } from "node:path";
|
|
1354
1326
|
import { parseSync as parseSync8 } from "oxc-parser";
|
|
1355
1327
|
|
|
1356
1328
|
// src/roles/test/codemod/edits.ts
|
|
@@ -2136,9 +2108,9 @@ function asyncifyEdits(source, fn) {
|
|
|
2136
2108
|
}
|
|
2137
2109
|
|
|
2138
2110
|
// src/roles/test/codemod/named-rules.ts
|
|
2139
|
-
import { existsSync as
|
|
2140
|
-
import { createRequire
|
|
2141
|
-
import { dirname as
|
|
2111
|
+
import { existsSync as existsSync10, readFileSync as readFileSync10 } from "node:fs";
|
|
2112
|
+
import { createRequire } from "node:module";
|
|
2113
|
+
import { dirname as dirname2, join as join10 } from "node:path";
|
|
2142
2114
|
|
|
2143
2115
|
// src/roles/test/codemod/namespace-import.ts
|
|
2144
2116
|
function sameModule(specifier) {
|
|
@@ -2208,7 +2180,7 @@ function namespaceBindings(program) {
|
|
|
2208
2180
|
|
|
2209
2181
|
// src/roles/test/codemod/static-import-for-require.ts
|
|
2210
2182
|
import { readFileSync as readFileSync9, statSync } from "node:fs";
|
|
2211
|
-
import { dirname
|
|
2183
|
+
import { dirname, join as join9, resolve as resolve4 } from "node:path";
|
|
2212
2184
|
import { parseSync as parseSync4 } from "oxc-parser";
|
|
2213
2185
|
|
|
2214
2186
|
// src/shared/module-resolution.ts
|
|
@@ -2225,11 +2197,11 @@ var RESOLVABLE_EXTENSIONS = [
|
|
|
2225
2197
|
|
|
2226
2198
|
// src/roles/test/codemod/static-import-for-require.ts
|
|
2227
2199
|
function resolveRelative(fromFile, specifier) {
|
|
2228
|
-
const base = resolve4(
|
|
2200
|
+
const base = resolve4(dirname(fromFile), specifier);
|
|
2229
2201
|
const candidates = [
|
|
2230
2202
|
base,
|
|
2231
2203
|
...RESOLVABLE_EXTENSIONS.map((extension) => `${base}${extension}`),
|
|
2232
|
-
...RESOLVABLE_EXTENSIONS.map((extension) =>
|
|
2204
|
+
...RESOLVABLE_EXTENSIONS.map((extension) => join9(base, `index${extension}`))
|
|
2233
2205
|
];
|
|
2234
2206
|
for (const candidate of candidates) {
|
|
2235
2207
|
try {
|
|
@@ -2431,24 +2403,24 @@ function isCommonJsPackage(fromFile, specifier) {
|
|
|
2431
2403
|
if (specifier.startsWith(".") || specifier.startsWith("/")) return false;
|
|
2432
2404
|
let resolved;
|
|
2433
2405
|
try {
|
|
2434
|
-
resolved =
|
|
2406
|
+
resolved = createRequire(fromFile).resolve(specifier);
|
|
2435
2407
|
} catch {
|
|
2436
2408
|
return false;
|
|
2437
2409
|
}
|
|
2438
2410
|
if (!resolved.includes(`${"/"}node_modules${"/"}`)) return false;
|
|
2439
2411
|
if (resolved.endsWith(".mjs")) return false;
|
|
2440
2412
|
if (resolved.endsWith(".cjs")) return true;
|
|
2441
|
-
let dir =
|
|
2413
|
+
let dir = dirname2(resolved);
|
|
2442
2414
|
for (let depth = 0; depth < 12; depth += 1) {
|
|
2443
|
-
const manifest =
|
|
2444
|
-
if (
|
|
2415
|
+
const manifest = join10(dir, "package.json");
|
|
2416
|
+
if (existsSync10(manifest)) {
|
|
2445
2417
|
try {
|
|
2446
2418
|
return JSON.parse(readFileSync10(manifest, "utf8")).type !== "module";
|
|
2447
2419
|
} catch {
|
|
2448
2420
|
return false;
|
|
2449
2421
|
}
|
|
2450
2422
|
}
|
|
2451
|
-
const parent =
|
|
2423
|
+
const parent = dirname2(dir);
|
|
2452
2424
|
if (parent === dir) break;
|
|
2453
2425
|
dir = parent;
|
|
2454
2426
|
}
|
|
@@ -3319,8 +3291,8 @@ function propagateAwait(fileName, source, original, elsewhere = /* @__PURE__ */
|
|
|
3319
3291
|
|
|
3320
3292
|
// src/roles/test/codemod/reexport-barrel-mock.ts
|
|
3321
3293
|
import { readFileSync as readFileSync11, readdirSync as readdirSync2, statSync as statSync2 } from "node:fs";
|
|
3322
|
-
import { createRequire as
|
|
3323
|
-
import { dirname as
|
|
3294
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
3295
|
+
import { dirname as dirname3, join as join11 } from "node:path";
|
|
3324
3296
|
var PACKAGE_SUBPATH = /^(@[^/]+\/[^/]+|[^@.][^/]*)\/(.+)$/;
|
|
3325
3297
|
var PURE_REEXPORT = /^module\.exports\s*=\s*require\(\s*(['"])([^'"]+)\1\s*\)\s*;?$/;
|
|
3326
3298
|
function mockCalls(program) {
|
|
@@ -3348,14 +3320,14 @@ function mockCalls(program) {
|
|
|
3348
3320
|
}
|
|
3349
3321
|
function packageRoot(fromFile, name) {
|
|
3350
3322
|
try {
|
|
3351
|
-
return
|
|
3323
|
+
return dirname3(createRequire2(fromFile).resolve(`${name}/package.json`));
|
|
3352
3324
|
} catch {
|
|
3353
3325
|
return void 0;
|
|
3354
3326
|
}
|
|
3355
3327
|
}
|
|
3356
3328
|
function resolveFrom(fromFile, specifier) {
|
|
3357
3329
|
try {
|
|
3358
|
-
return
|
|
3330
|
+
return createRequire2(fromFile).resolve(specifier);
|
|
3359
3331
|
} catch {
|
|
3360
3332
|
return void 0;
|
|
3361
3333
|
}
|
|
@@ -3372,7 +3344,7 @@ function barrelsFor(fromFile, name, target) {
|
|
|
3372
3344
|
const aliases = [];
|
|
3373
3345
|
for (const entry of entries) {
|
|
3374
3346
|
if (!entry.endsWith(".js")) continue;
|
|
3375
|
-
const path =
|
|
3347
|
+
const path = join11(root, entry);
|
|
3376
3348
|
let body;
|
|
3377
3349
|
try {
|
|
3378
3350
|
if (!statSync2(path).isFile()) continue;
|
|
@@ -3475,17 +3447,17 @@ function rewriteRunnerArtefactNames(source, program) {
|
|
|
3475
3447
|
}
|
|
3476
3448
|
|
|
3477
3449
|
// src/roles/test/codemod/setup-static-imports.ts
|
|
3478
|
-
import { dirname as
|
|
3450
|
+
import { dirname as dirname5, resolve as resolve7 } from "node:path";
|
|
3479
3451
|
|
|
3480
3452
|
// src/core/context.ts
|
|
3481
|
-
import { existsSync as
|
|
3482
|
-
import { dirname as
|
|
3453
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
3454
|
+
import { dirname as dirname4, join as join13, resolve as resolve5 } from "node:path";
|
|
3483
3455
|
|
|
3484
3456
|
// src/core/discover-modules.ts
|
|
3485
3457
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
3486
3458
|
import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync12, rmSync as rmSync2 } from "node:fs";
|
|
3487
3459
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
3488
|
-
import { join as
|
|
3460
|
+
import { join as join12 } from "node:path";
|
|
3489
3461
|
function runNx(cwd, args) {
|
|
3490
3462
|
const nx = resolveBin(cwd, "nx") ?? "nx";
|
|
3491
3463
|
try {
|
|
@@ -3503,8 +3475,8 @@ function runNx(cwd, args) {
|
|
|
3503
3475
|
}
|
|
3504
3476
|
}
|
|
3505
3477
|
function readGraph(cwd) {
|
|
3506
|
-
const dir = mkdtempSync2(
|
|
3507
|
-
const file =
|
|
3478
|
+
const dir = mkdtempSync2(join12(tmpdir2(), "sentinel-nx-"));
|
|
3479
|
+
const file = join12(dir, "graph.json");
|
|
3508
3480
|
try {
|
|
3509
3481
|
runNx(cwd, ["graph", "--file", file]);
|
|
3510
3482
|
const parsed = JSON.parse(readFileSync12(file, "utf8"));
|
|
@@ -3516,7 +3488,7 @@ function readGraph(cwd) {
|
|
|
3516
3488
|
}
|
|
3517
3489
|
return Object.entries(nodes).map(([name, node]) => ({
|
|
3518
3490
|
name,
|
|
3519
|
-
root:
|
|
3491
|
+
root: join12(cwd, node.data.root)
|
|
3520
3492
|
}));
|
|
3521
3493
|
} finally {
|
|
3522
3494
|
rmSync2(dir, { recursive: true, force: true });
|
|
@@ -3557,20 +3529,20 @@ ${raw.slice(0, 300)}`
|
|
|
3557
3529
|
// src/core/context.ts
|
|
3558
3530
|
var MODULE_MARKERS = ["package.json", "project.json"];
|
|
3559
3531
|
function isModuleDir(cwd) {
|
|
3560
|
-
return MODULE_MARKERS.some((marker) =>
|
|
3532
|
+
return MODULE_MARKERS.some((marker) => existsSync11(join13(cwd, marker)));
|
|
3561
3533
|
}
|
|
3562
3534
|
function findModuleRoot(startDir, workspaceRoot) {
|
|
3563
3535
|
let dir = resolve5(startDir);
|
|
3564
3536
|
for (; ; ) {
|
|
3565
3537
|
if (workspaceRoot !== void 0 && dir === resolve5(workspaceRoot)) return void 0;
|
|
3566
3538
|
if (isModuleDir(dir)) return dir;
|
|
3567
|
-
const parent =
|
|
3539
|
+
const parent = dirname4(dir);
|
|
3568
3540
|
if (parent === dir) return void 0;
|
|
3569
3541
|
dir = parent;
|
|
3570
3542
|
}
|
|
3571
3543
|
}
|
|
3572
3544
|
function resolveContext(cwd, opts) {
|
|
3573
|
-
const atRoot =
|
|
3545
|
+
const atRoot = existsSync11(join13(cwd, WORKSPACE_ROOT_MARKER));
|
|
3574
3546
|
if (!atRoot && isModuleDir(cwd)) {
|
|
3575
3547
|
if (opts.module) {
|
|
3576
3548
|
throw new Error(
|
|
@@ -3598,15 +3570,15 @@ function resolveContext(cwd, opts) {
|
|
|
3598
3570
|
}
|
|
3599
3571
|
|
|
3600
3572
|
// src/roles/test/codemod/workspace-specifier.ts
|
|
3601
|
-
import { existsSync as
|
|
3602
|
-
import { join as
|
|
3573
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
3574
|
+
import { join as join14, relative as relative2, resolve as resolve6 } from "node:path";
|
|
3603
3575
|
var EXTENSIONS = ["", ".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", "/index.ts", "/index.js"];
|
|
3604
3576
|
var SPEC_TSCONFIGS = ["tsconfig.spec.json", "tsconfig.app.json", "tsconfig.json"];
|
|
3605
3577
|
function pathsFor(workspaceRoot, moduleRoot) {
|
|
3606
3578
|
try {
|
|
3607
3579
|
if (moduleRoot !== void 0) return effectivePaths(moduleRoot, workspaceRoot, SPEC_TSCONFIGS);
|
|
3608
|
-
const file =
|
|
3609
|
-
if (!
|
|
3580
|
+
const file = join14(workspaceRoot, WORKSPACE_TSCONFIG);
|
|
3581
|
+
if (!existsSync12(file)) return void 0;
|
|
3610
3582
|
const found = chainPaths(file);
|
|
3611
3583
|
return found && { ...found, fromWorkspaceFallback: false };
|
|
3612
3584
|
} catch {
|
|
@@ -3659,7 +3631,7 @@ function requireCall(source, node) {
|
|
|
3659
3631
|
}
|
|
3660
3632
|
function importable(written, fileName, workspaceRoot) {
|
|
3661
3633
|
if (!written.startsWith(".")) return written;
|
|
3662
|
-
const fileDir =
|
|
3634
|
+
const fileDir = dirname5(fileName);
|
|
3663
3635
|
const moduleRoot = findModuleRoot(fileDir, workspaceRoot) ?? fileDir;
|
|
3664
3636
|
const target = resolve7(fileDir, written);
|
|
3665
3637
|
if (target.startsWith(`${moduleRoot}/`)) return written;
|
|
@@ -3776,15 +3748,15 @@ function rewriteMockFactoryGenerics(source, program) {
|
|
|
3776
3748
|
|
|
3777
3749
|
// src/roles/test/codemod/spy-on-internal-call.ts
|
|
3778
3750
|
import { readFileSync as readFileSync13, statSync as statSync3 } from "node:fs";
|
|
3779
|
-
import { dirname as
|
|
3751
|
+
import { dirname as dirname6, join as join15, relative as relative3, resolve as resolve8 } from "node:path";
|
|
3780
3752
|
import { parseSync as parseSync7 } from "oxc-parser";
|
|
3781
3753
|
function resolveRelative2(fromFile, specifier) {
|
|
3782
3754
|
if (!specifier.startsWith(".")) return void 0;
|
|
3783
|
-
const base = resolve8(
|
|
3755
|
+
const base = resolve8(dirname6(fromFile), specifier);
|
|
3784
3756
|
const candidates = [
|
|
3785
3757
|
base,
|
|
3786
3758
|
...RESOLVABLE_EXTENSIONS.map((extension) => `${base}${extension}`),
|
|
3787
|
-
...RESOLVABLE_EXTENSIONS.map((extension) =>
|
|
3759
|
+
...RESOLVABLE_EXTENSIONS.map((extension) => join15(base, `index${extension}`))
|
|
3788
3760
|
];
|
|
3789
3761
|
for (const candidate of candidates) {
|
|
3790
3762
|
try {
|
|
@@ -3917,7 +3889,7 @@ function importOf(program, local) {
|
|
|
3917
3889
|
return void 0;
|
|
3918
3890
|
}
|
|
3919
3891
|
function respell(fromFile, target) {
|
|
3920
|
-
const path = relative3(
|
|
3892
|
+
const path = relative3(dirname6(fromFile), target).replaceAll("\\", "/").replace(/\.(?:m|c)?[jt]sx?$/, "").replace(/\/index$/, "");
|
|
3921
3893
|
return path.startsWith(".") ? path : `./${path}`;
|
|
3922
3894
|
}
|
|
3923
3895
|
function namesInUse2(program) {
|
|
@@ -4230,7 +4202,7 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
4230
4202
|
fileName,
|
|
4231
4203
|
source,
|
|
4232
4204
|
beforeStatic,
|
|
4233
|
-
findWorkspaceRoot(
|
|
4205
|
+
findWorkspaceRoot(dirname7(fileName))
|
|
4234
4206
|
);
|
|
4235
4207
|
source = statics.source;
|
|
4236
4208
|
const original = statics.rewritten === 0 ? beforeStatic : parse3(fileName, source);
|
|
@@ -4368,8 +4340,8 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
4368
4340
|
}
|
|
4369
4341
|
|
|
4370
4342
|
// src/roles/test/codemod/test-support-files.ts
|
|
4371
|
-
import { existsSync as
|
|
4372
|
-
import { dirname as
|
|
4343
|
+
import { existsSync as existsSync13, readFileSync as readFileSync14, readdirSync as readdirSync3, statSync as statSync4 } from "node:fs";
|
|
4344
|
+
import { dirname as dirname8, join as join16, relative as relative4, resolve as resolve9 } from "node:path";
|
|
4373
4345
|
var THE_SHIM_CANNOT_ANSWER = [/\brequire\s*\(/, /\bjest\.(?:fn|Mock|SpyInstance)\s*</];
|
|
4374
4346
|
var SKIPPED = /* @__PURE__ */ new Set(["node_modules", "dist", "coverage", ".git", ".vite"]);
|
|
4375
4347
|
var TEST_FILE2 = /[.-](spec|test)\.[cm]?[jt]sx?$/;
|
|
@@ -4389,14 +4361,14 @@ function relativeSpecifiers2(source) {
|
|
|
4389
4361
|
return found;
|
|
4390
4362
|
}
|
|
4391
4363
|
function resolveSpecifier(fromFile, specifier) {
|
|
4392
|
-
const base = resolve9(
|
|
4393
|
-
if (
|
|
4364
|
+
const base = resolve9(dirname8(fromFile), specifier);
|
|
4365
|
+
if (existsSync13(base) && statSync4(base).isFile()) return base;
|
|
4394
4366
|
for (const extension of EXTENSIONS2) {
|
|
4395
|
-
if (
|
|
4367
|
+
if (existsSync13(`${base}${extension}`)) return `${base}${extension}`;
|
|
4396
4368
|
}
|
|
4397
4369
|
for (const extension of EXTENSIONS2) {
|
|
4398
|
-
const index =
|
|
4399
|
-
if (
|
|
4370
|
+
const index = join16(base, `index${extension}`);
|
|
4371
|
+
if (existsSync13(index)) return index;
|
|
4400
4372
|
}
|
|
4401
4373
|
return void 0;
|
|
4402
4374
|
}
|
|
@@ -4413,9 +4385,9 @@ function moduleSources(cwd) {
|
|
|
4413
4385
|
}
|
|
4414
4386
|
for (const entry of entries) {
|
|
4415
4387
|
if (entry.isDirectory()) {
|
|
4416
|
-
if (!SKIPPED.has(entry.name)) stack.push(
|
|
4388
|
+
if (!SKIPPED.has(entry.name)) stack.push(join16(dir, entry.name));
|
|
4417
4389
|
} else if (SOURCE_FILE.test(entry.name)) {
|
|
4418
|
-
found.push(
|
|
4390
|
+
found.push(join16(dir, entry.name));
|
|
4419
4391
|
}
|
|
4420
4392
|
}
|
|
4421
4393
|
}
|
|
@@ -4435,7 +4407,7 @@ function setupFilesInside(cwd, named) {
|
|
|
4435
4407
|
const full = resolve9(cwd, withoutToken);
|
|
4436
4408
|
const inside = relative4(cwd, full);
|
|
4437
4409
|
if (inside.startsWith("..") || inside === "") continue;
|
|
4438
|
-
if (!
|
|
4410
|
+
if (!existsSync13(full)) continue;
|
|
4439
4411
|
kept.push(inside.replaceAll("\\", "/"));
|
|
4440
4412
|
}
|
|
4441
4413
|
return kept;
|
|
@@ -4499,7 +4471,7 @@ function defaultImportedSpecifiers(cwd) {
|
|
|
4499
4471
|
}
|
|
4500
4472
|
for (const entry of entries) {
|
|
4501
4473
|
if (SKIPPED2.has(entry)) continue;
|
|
4502
|
-
const path =
|
|
4474
|
+
const path = join17(dir, entry);
|
|
4503
4475
|
let directory;
|
|
4504
4476
|
try {
|
|
4505
4477
|
directory = statSync5(path).isDirectory();
|
|
@@ -4531,13 +4503,13 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4531
4503
|
const defaultImported = defaultImportedSpecifiers(cwd);
|
|
4532
4504
|
const asyncHelpers = /* @__PURE__ */ new Set();
|
|
4533
4505
|
for (const relative8 of listTestSupportFiles(cwd, setupFiles)) {
|
|
4534
|
-
const source = read3(
|
|
4506
|
+
const source = read3(join17(cwd, relative8));
|
|
4535
4507
|
if (source === void 0) {
|
|
4536
4508
|
blockers.push({ file: relative8, reason: "this file could not be read" });
|
|
4537
4509
|
continue;
|
|
4538
4510
|
}
|
|
4539
4511
|
const migrated = migrateTestFile(
|
|
4540
|
-
|
|
4512
|
+
join17(cwd, relative8),
|
|
4541
4513
|
source,
|
|
4542
4514
|
defaultImported,
|
|
4543
4515
|
/* @__PURE__ */ new Set(),
|
|
@@ -4556,8 +4528,8 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4556
4528
|
const renamedTo = vitestSupportName(relative8);
|
|
4557
4529
|
if (!migrated.changed && renamedTo === relative8) continue;
|
|
4558
4530
|
if (renamedTo !== relative8) operations.push({ kind: "delete", path: relative8 });
|
|
4559
|
-
const before = parse4(
|
|
4560
|
-
const after = parse4(
|
|
4531
|
+
const before = parse4(join17(cwd, relative8), source);
|
|
4532
|
+
const after = parse4(join17(cwd, relative8), migrated.source);
|
|
4561
4533
|
if (before !== void 0 && after !== void 0) {
|
|
4562
4534
|
const wasAsync = asyncFunctionNames(before);
|
|
4563
4535
|
for (const name of asyncFunctionNames(after)) {
|
|
@@ -4566,17 +4538,17 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4566
4538
|
}
|
|
4567
4539
|
files++;
|
|
4568
4540
|
renamed += migrated.renamed;
|
|
4569
|
-
const contents = /\bvi\./.test(migrated.source) ? injectViImport(
|
|
4541
|
+
const contents = /\bvi\./.test(migrated.source) ? injectViImport(join17(cwd, renamedTo), migrated.source) : migrated.source;
|
|
4570
4542
|
operations.push({ kind: "write", path: renamedTo, contents });
|
|
4571
4543
|
}
|
|
4572
4544
|
for (const relative8 of listTestFiles(cwd)) {
|
|
4573
|
-
const source = read3(
|
|
4545
|
+
const source = read3(join17(cwd, relative8));
|
|
4574
4546
|
if (source === void 0) {
|
|
4575
4547
|
blockers.push({ file: relative8, reason: "this file could not be read" });
|
|
4576
4548
|
continue;
|
|
4577
4549
|
}
|
|
4578
4550
|
const migrated = migrateTestFile(
|
|
4579
|
-
|
|
4551
|
+
join17(cwd, relative8),
|
|
4580
4552
|
source,
|
|
4581
4553
|
defaultImported,
|
|
4582
4554
|
asyncHelpers,
|
|
@@ -4611,7 +4583,7 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
4611
4583
|
|
|
4612
4584
|
// src/roles/test/nest/generate-config.ts
|
|
4613
4585
|
import { readdirSync as readdirSync5, readFileSync as readFileSync16, statSync as statSync6 } from "node:fs";
|
|
4614
|
-
import { join as
|
|
4586
|
+
import { join as join18, relative as relative5 } from "node:path";
|
|
4615
4587
|
import { parseSync as parseSync10 } from "oxc-parser";
|
|
4616
4588
|
var NEST_TEST_PRESET_SPECIFIER = "@hublo/sentinel/test/nest";
|
|
4617
4589
|
var REACT_TEST_PRESET_SPECIFIER = "@hublo/sentinel/test/react";
|
|
@@ -4658,7 +4630,7 @@ function readModuleTraits(cwd) {
|
|
|
4658
4630
|
}
|
|
4659
4631
|
for (const entry of entries) {
|
|
4660
4632
|
if (SKIPPED3.has(entry)) continue;
|
|
4661
|
-
const path =
|
|
4633
|
+
const path = join18(dir, entry);
|
|
4662
4634
|
let directory;
|
|
4663
4635
|
try {
|
|
4664
4636
|
directory = statSync6(path).isDirectory();
|
|
@@ -4813,8 +4785,8 @@ ${overrides.join("\n")}
|
|
|
4813
4785
|
}
|
|
4814
4786
|
|
|
4815
4787
|
// src/roles/test/nest/read-jest-config.ts
|
|
4816
|
-
import { existsSync as
|
|
4817
|
-
import { join as
|
|
4788
|
+
import { existsSync as existsSync14, readFileSync as readFileSync17 } from "node:fs";
|
|
4789
|
+
import { join as join19 } from "node:path";
|
|
4818
4790
|
var CARRIED = [
|
|
4819
4791
|
"testEnvironment",
|
|
4820
4792
|
"coverageDirectory",
|
|
@@ -5004,7 +4976,7 @@ function extendedConfig(source, cwd) {
|
|
|
5004
4976
|
(name) => name.replace(/^\.\//, "")
|
|
5005
4977
|
);
|
|
5006
4978
|
const file = candidates.find(
|
|
5007
|
-
(name) => /^jest[\w.-]*\.(ts|js)$/.test(name) &&
|
|
4979
|
+
(name) => /^jest[\w.-]*\.(ts|js)$/.test(name) && existsSync14(join19(cwd, name))
|
|
5008
4980
|
);
|
|
5009
4981
|
if (file === void 0) continue;
|
|
5010
4982
|
if (!new RegExp(String.raw`\{\s*\.\.\.${binding}\b`).test(source)) continue;
|
|
@@ -5031,11 +5003,11 @@ function sideEffects(source, extended) {
|
|
|
5031
5003
|
return found;
|
|
5032
5004
|
}
|
|
5033
5005
|
function readJestConfig(cwd, named) {
|
|
5034
|
-
const file = named ?? JEST_CONFIG_FILES.find((name) =>
|
|
5035
|
-
if (file === void 0 || !
|
|
5006
|
+
const file = named ?? JEST_CONFIG_FILES.find((name) => existsSync14(join19(cwd, name)));
|
|
5007
|
+
if (file === void 0 || !existsSync14(join19(cwd, file))) return void 0;
|
|
5036
5008
|
let source;
|
|
5037
5009
|
try {
|
|
5038
|
-
source = readFileSync17(
|
|
5010
|
+
source = readFileSync17(join19(cwd, file), "utf8");
|
|
5039
5011
|
} catch {
|
|
5040
5012
|
return { file, refusals: [`${file} could not be read`], notes: [] };
|
|
5041
5013
|
}
|
|
@@ -5116,8 +5088,8 @@ function readJestConfig(cwd, named) {
|
|
|
5116
5088
|
}
|
|
5117
5089
|
|
|
5118
5090
|
// src/roles/test/nest/run-modes.ts
|
|
5119
|
-
import { existsSync as
|
|
5120
|
-
import { basename as basename2, join as
|
|
5091
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
5092
|
+
import { basename as basename2, join as join20 } from "node:path";
|
|
5121
5093
|
var JEST_EXECUTOR = "@nx/jest:jest";
|
|
5122
5094
|
var PRIMARY_CONFIG_FILE = "vitest.config.mts";
|
|
5123
5095
|
var PRIMARY_TARGET = "test";
|
|
@@ -5138,7 +5110,7 @@ function runModes(cwd, fallback) {
|
|
|
5138
5110
|
const jestConfig = entry.options?.jestConfig;
|
|
5139
5111
|
if (jestConfig === void 0) continue;
|
|
5140
5112
|
const name = configName(jestConfig);
|
|
5141
|
-
if (!
|
|
5113
|
+
if (!existsSync15(join20(cwd, name))) continue;
|
|
5142
5114
|
declared.push({
|
|
5143
5115
|
target,
|
|
5144
5116
|
jestConfig: name,
|
|
@@ -5163,12 +5135,12 @@ function runModes(cwd, fallback) {
|
|
|
5163
5135
|
}
|
|
5164
5136
|
|
|
5165
5137
|
// src/roles/test/written-file-formatter.ts
|
|
5166
|
-
import { existsSync as
|
|
5167
|
-
import { dirname as
|
|
5138
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
5139
|
+
import { dirname as dirname10, join as join23 } from "node:path";
|
|
5168
5140
|
|
|
5169
5141
|
// src/roles/format/read-adoption.ts
|
|
5170
|
-
import { existsSync as
|
|
5171
|
-
import { join as
|
|
5142
|
+
import { existsSync as existsSync16, readFileSync as readFileSync18 } from "node:fs";
|
|
5143
|
+
import { join as join21 } from "node:path";
|
|
5172
5144
|
|
|
5173
5145
|
// src/roles/format/config-policy.ts
|
|
5174
5146
|
var FORMAT_CONFIG_FILE = ".oxfmtrc.json";
|
|
@@ -5275,8 +5247,8 @@ function sameValue(a, b) {
|
|
|
5275
5247
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
5276
5248
|
}
|
|
5277
5249
|
function readFormatAdoption(cwd) {
|
|
5278
|
-
const path =
|
|
5279
|
-
if (!
|
|
5250
|
+
const path = join21(cwd, FORMAT_CONFIG_FILE);
|
|
5251
|
+
if (!existsSync16(path)) return NOT_ADOPTED(null);
|
|
5280
5252
|
let parsed;
|
|
5281
5253
|
try {
|
|
5282
5254
|
parsed = parseJsonc(readFileSync18(path, "utf8"), FORMAT_CONFIG_FILE);
|
|
@@ -5324,8 +5296,8 @@ function readFormatAdoption(cwd) {
|
|
|
5324
5296
|
|
|
5325
5297
|
// src/roles/format/resolve-oxfmt.ts
|
|
5326
5298
|
import { readFileSync as readFileSync19 } from "node:fs";
|
|
5327
|
-
import { createRequire as
|
|
5328
|
-
import { dirname as
|
|
5299
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
5300
|
+
import { dirname as dirname9, join as join22 } from "node:path";
|
|
5329
5301
|
function resolveOxfmt(cwd) {
|
|
5330
5302
|
return resolveBin(cwd, "oxfmt") ?? binFromOwnInstall("oxfmt", "oxfmt");
|
|
5331
5303
|
}
|
|
@@ -5353,8 +5325,8 @@ function configSchema() {
|
|
|
5353
5325
|
}
|
|
5354
5326
|
function readConfigSchema() {
|
|
5355
5327
|
try {
|
|
5356
|
-
const manifest =
|
|
5357
|
-
const schemaPath =
|
|
5328
|
+
const manifest = createRequire3(import.meta.url).resolve("oxfmt/package.json");
|
|
5329
|
+
const schemaPath = join22(dirname9(manifest), "configuration_schema.json");
|
|
5358
5330
|
return JSON.parse(readFileSync19(schemaPath, "utf8"));
|
|
5359
5331
|
} catch {
|
|
5360
5332
|
return void 0;
|
|
@@ -5380,9 +5352,9 @@ function prettierConfigFrom(cwd) {
|
|
|
5380
5352
|
let dir = cwd;
|
|
5381
5353
|
for (; ; ) {
|
|
5382
5354
|
for (const name of PRETTIER_CONFIGS) {
|
|
5383
|
-
if (
|
|
5355
|
+
if (existsSync17(join23(dir, name))) return join23(dir, name);
|
|
5384
5356
|
}
|
|
5385
|
-
const parent =
|
|
5357
|
+
const parent = dirname10(dir);
|
|
5386
5358
|
if (parent === dir) return void 0;
|
|
5387
5359
|
dir = parent;
|
|
5388
5360
|
}
|
|
@@ -5410,8 +5382,8 @@ function writtenFileFormatter(cwd) {
|
|
|
5410
5382
|
var SPEC_TSCONFIG = "tsconfig.spec.json";
|
|
5411
5383
|
var VITEST_GLOBAL_TYPES = "vitest/globals";
|
|
5412
5384
|
function specTypesOperation(cwd) {
|
|
5413
|
-
const path =
|
|
5414
|
-
if (!
|
|
5385
|
+
const path = join24(cwd, SPEC_TSCONFIG);
|
|
5386
|
+
if (!existsSync18(path)) return void 0;
|
|
5415
5387
|
let config;
|
|
5416
5388
|
try {
|
|
5417
5389
|
config = parseJsonc(
|
|
@@ -5434,8 +5406,8 @@ function specTypesOperation(cwd) {
|
|
|
5434
5406
|
};
|
|
5435
5407
|
}
|
|
5436
5408
|
function specTypesCleanupOperation(cwd) {
|
|
5437
|
-
const path =
|
|
5438
|
-
if (!
|
|
5409
|
+
const path = join24(cwd, SPEC_TSCONFIG);
|
|
5410
|
+
if (!existsSync18(path)) return void 0;
|
|
5439
5411
|
let config;
|
|
5440
5412
|
try {
|
|
5441
5413
|
config = parseJsonc(
|
|
@@ -5457,9 +5429,9 @@ function specTypesCleanupOperation(cwd) {
|
|
|
5457
5429
|
}
|
|
5458
5430
|
function shippedTypesPath(cwd, declaration) {
|
|
5459
5431
|
try {
|
|
5460
|
-
const manifest =
|
|
5461
|
-
const file =
|
|
5462
|
-
if (
|
|
5432
|
+
const manifest = createRequire4(join24(cwd, "noop.cjs")).resolve("@hublo/sentinel/package.json");
|
|
5433
|
+
const file = join24(dirname11(manifest), declaration);
|
|
5434
|
+
if (existsSync18(file)) {
|
|
5463
5435
|
const path = relative6(cwd, file);
|
|
5464
5436
|
return path.startsWith(".") ? path : `./${path}`;
|
|
5465
5437
|
}
|
|
@@ -5478,7 +5450,7 @@ function helpersStillCallingJest(cwd) {
|
|
|
5478
5450
|
return;
|
|
5479
5451
|
}
|
|
5480
5452
|
for (const entry of entries) {
|
|
5481
|
-
const path =
|
|
5453
|
+
const path = join24(dir, entry.name);
|
|
5482
5454
|
if (entry.isDirectory()) {
|
|
5483
5455
|
if (!skip.has(entry.name)) walk2(path);
|
|
5484
5456
|
continue;
|
|
@@ -5525,7 +5497,7 @@ function tsconfigFileListOperations(cwd) {
|
|
|
5525
5497
|
let config;
|
|
5526
5498
|
try {
|
|
5527
5499
|
config = parseJsonc(
|
|
5528
|
-
readFileSync20(
|
|
5500
|
+
readFileSync20(join24(cwd, name), "utf8"),
|
|
5529
5501
|
name
|
|
5530
5502
|
);
|
|
5531
5503
|
} catch {
|
|
@@ -5940,12 +5912,12 @@ function plan(context) {
|
|
|
5940
5912
|
}
|
|
5941
5913
|
|
|
5942
5914
|
// src/roles/test/written-file-linter.ts
|
|
5943
|
-
import { existsSync as
|
|
5944
|
-
import { join as
|
|
5915
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
5916
|
+
import { join as join30 } from "node:path";
|
|
5945
5917
|
|
|
5946
5918
|
// src/roles/lint/module-baseline.ts
|
|
5947
|
-
import { existsSync as
|
|
5948
|
-
import { join as
|
|
5919
|
+
import { existsSync as existsSync19, readFileSync as readFileSync21 } from "node:fs";
|
|
5920
|
+
import { join as join25 } from "node:path";
|
|
5949
5921
|
|
|
5950
5922
|
// src/roles/lint/oxlint-rule-owners.json
|
|
5951
5923
|
var oxlint_rule_owners_default = {
|
|
@@ -6687,8 +6659,8 @@ function describeHolds(holds) {
|
|
|
6687
6659
|
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`;
|
|
6688
6660
|
}
|
|
6689
6661
|
function heldRules(cwd) {
|
|
6690
|
-
const path =
|
|
6691
|
-
if (!
|
|
6662
|
+
const path = join25(cwd, LINT_BASELINE_FILE);
|
|
6663
|
+
if (!existsSync19(path)) return [];
|
|
6692
6664
|
try {
|
|
6693
6665
|
const parsed = parseJsonc(readFileSync21(path, "utf8"), LINT_BASELINE_FILE);
|
|
6694
6666
|
const scoped = (parsed.overrides ?? []).flatMap((override) => Object.keys(override.rules ?? {}));
|
|
@@ -6739,11 +6711,11 @@ function lintTarget() {
|
|
|
6739
6711
|
|
|
6740
6712
|
// src/roles/lint/read-adoption.ts
|
|
6741
6713
|
import { readFileSync as readFileSync24 } from "node:fs";
|
|
6742
|
-
import { join as
|
|
6714
|
+
import { join as join28 } from "node:path";
|
|
6743
6715
|
|
|
6744
6716
|
// src/core/config/read-adoption.ts
|
|
6745
|
-
import { existsSync as
|
|
6746
|
-
import { join as
|
|
6717
|
+
import { existsSync as existsSync21, readFileSync as readFileSync23 } from "node:fs";
|
|
6718
|
+
import { join as join27 } from "node:path";
|
|
6747
6719
|
|
|
6748
6720
|
// src/core/config/owned-keys.ts
|
|
6749
6721
|
function presetOwnedKeys(config, permitted, presetSets) {
|
|
@@ -6758,8 +6730,8 @@ function localOnlyKeys(config, permitted, presetSets) {
|
|
|
6758
6730
|
}
|
|
6759
6731
|
|
|
6760
6732
|
// src/core/config/resolve-config-target.ts
|
|
6761
|
-
import { existsSync as
|
|
6762
|
-
import { join as
|
|
6733
|
+
import { existsSync as existsSync20, readFileSync as readFileSync22 } from "node:fs";
|
|
6734
|
+
import { join as join26 } from "node:path";
|
|
6763
6735
|
function readExtends(absolutePath) {
|
|
6764
6736
|
let parsed;
|
|
6765
6737
|
try {
|
|
@@ -6777,8 +6749,8 @@ function resolveConfigTarget(moduleDir, { candidates, markers, fallback }) {
|
|
|
6777
6749
|
let existing;
|
|
6778
6750
|
let existingExtendsSomething = false;
|
|
6779
6751
|
for (const candidate of candidates) {
|
|
6780
|
-
const absolutePath =
|
|
6781
|
-
if (!
|
|
6752
|
+
const absolutePath = join26(moduleDir, candidate);
|
|
6753
|
+
if (!existsSync20(absolutePath)) continue;
|
|
6782
6754
|
const chain = readExtends(absolutePath);
|
|
6783
6755
|
if (existing === void 0) {
|
|
6784
6756
|
existing = candidate;
|
|
@@ -6811,12 +6783,12 @@ var NOT_ADOPTED2 = (configFile, unreadable = null) => ({
|
|
|
6811
6783
|
});
|
|
6812
6784
|
function readAdoption(cwd, options) {
|
|
6813
6785
|
const target = resolveConfigTarget(cwd, options);
|
|
6814
|
-
if (target.reason === "none" || !
|
|
6786
|
+
if (target.reason === "none" || !existsSync21(join27(cwd, target.path))) {
|
|
6815
6787
|
return NOT_ADOPTED2(target.reason === "none" ? null : target.path);
|
|
6816
6788
|
}
|
|
6817
6789
|
let parsed;
|
|
6818
6790
|
try {
|
|
6819
|
-
parsed = parseJsonc(readFileSync23(
|
|
6791
|
+
parsed = parseJsonc(readFileSync23(join27(cwd, target.path), "utf8"), target.path);
|
|
6820
6792
|
} catch (error) {
|
|
6821
6793
|
const reason = error instanceof Error ? error.message : String(error);
|
|
6822
6794
|
return NOT_ADOPTED2(target.path, `${target.path} could not be parsed (${reason})`);
|
|
@@ -9500,7 +9472,7 @@ function readModuleAdditions(cwd) {
|
|
|
9500
9472
|
if (preset === void 0 || adoption.configFile === null) return NO_ADDITIONS;
|
|
9501
9473
|
try {
|
|
9502
9474
|
const config = parseJsonc(
|
|
9503
|
-
readFileSync24(
|
|
9475
|
+
readFileSync24(join28(cwd, adoption.configFile), "utf8"),
|
|
9504
9476
|
adoption.configFile
|
|
9505
9477
|
);
|
|
9506
9478
|
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
@@ -9517,15 +9489,15 @@ function readModuleAdditions(cwd) {
|
|
|
9517
9489
|
}
|
|
9518
9490
|
|
|
9519
9491
|
// src/roles/lint/resolve-oxlint.ts
|
|
9520
|
-
import { existsSync as
|
|
9521
|
-
import { createRequire as
|
|
9522
|
-
import { delimiter
|
|
9492
|
+
import { existsSync as existsSync22 } from "node:fs";
|
|
9493
|
+
import { createRequire as createRequire5 } from "node:module";
|
|
9494
|
+
import { delimiter, dirname as dirname12, join as join29 } from "node:path";
|
|
9523
9495
|
import { fileURLToPath } from "node:url";
|
|
9524
9496
|
var PACKAGE_OF = {
|
|
9525
9497
|
oxlint: "oxlint",
|
|
9526
9498
|
tsgolint: "oxlint-tsgolint"
|
|
9527
9499
|
};
|
|
9528
|
-
var
|
|
9500
|
+
var require2 = createRequire5(import.meta.url);
|
|
9529
9501
|
function resolveOxlint(cwd, name = "oxlint") {
|
|
9530
9502
|
return resolveBin(cwd, name) ?? binFromOwnInstall(PACKAGE_OF[name], name);
|
|
9531
9503
|
}
|
|
@@ -9535,7 +9507,7 @@ function canRunTypeAware(cwd) {
|
|
|
9535
9507
|
function oxlintPath(cwd, env) {
|
|
9536
9508
|
const shim = tsgolintShim(cwd);
|
|
9537
9509
|
if (!shim) return env.PATH;
|
|
9538
|
-
return [
|
|
9510
|
+
return [dirname12(shim), env.PATH].filter(Boolean).join(delimiter);
|
|
9539
9511
|
}
|
|
9540
9512
|
function tsgolintShim(cwd) {
|
|
9541
9513
|
const fromModule = resolveBin(cwd, "tsgolint");
|
|
@@ -9543,19 +9515,19 @@ function tsgolintShim(cwd) {
|
|
|
9543
9515
|
const candidates = [];
|
|
9544
9516
|
for (const owner of ["oxlint-tsgolint", "oxlint"]) {
|
|
9545
9517
|
try {
|
|
9546
|
-
const packageDir =
|
|
9547
|
-
candidates.push(
|
|
9548
|
-
candidates.push(
|
|
9518
|
+
const packageDir = dirname12(require2.resolve(`${owner}/package.json`));
|
|
9519
|
+
candidates.push(join29(packageDir, "node_modules", ".bin", "tsgolint"));
|
|
9520
|
+
candidates.push(join29(packageDir, "..", ".bin", "tsgolint"));
|
|
9549
9521
|
} catch {
|
|
9550
9522
|
}
|
|
9551
9523
|
}
|
|
9552
9524
|
try {
|
|
9553
|
-
const ownRoot =
|
|
9554
|
-
candidates.push(
|
|
9525
|
+
const ownRoot = dirname12(require2.resolve("@hublo/sentinel/package.json"));
|
|
9526
|
+
candidates.push(join29(ownRoot, "node_modules", ".bin", "tsgolint"));
|
|
9555
9527
|
} catch {
|
|
9556
|
-
candidates.push(resolveBin(
|
|
9528
|
+
candidates.push(resolveBin(dirname12(fileURLToPath(import.meta.url)), "tsgolint") ?? "");
|
|
9557
9529
|
}
|
|
9558
|
-
return candidates.find((candidate) => candidate !== "" &&
|
|
9530
|
+
return candidates.find((candidate) => candidate !== "" && existsSync22(candidate));
|
|
9559
9531
|
}
|
|
9560
9532
|
function oxlintSearchPath(cwd) {
|
|
9561
9533
|
return binSearchPath(cwd);
|
|
@@ -9569,7 +9541,7 @@ function writtenFileLinter(cwd) {
|
|
|
9569
9541
|
return { bin: oxlint, args: ["--fix"], origin: "this module's own oxlint config" };
|
|
9570
9542
|
}
|
|
9571
9543
|
}
|
|
9572
|
-
const config = ESLINT_CONFIG_FILES.map((name) =>
|
|
9544
|
+
const config = ESLINT_CONFIG_FILES.map((name) => join30(cwd, name)).find((path) => existsSync23(path));
|
|
9573
9545
|
const eslint = resolveBin(cwd, "eslint");
|
|
9574
9546
|
if (config !== void 0 && eslint !== void 0) {
|
|
9575
9547
|
return {
|
|
@@ -9717,12 +9689,12 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9717
9689
|
const linter = writtenFileLinter(ctx.cwd);
|
|
9718
9690
|
if (linter === void 0) return;
|
|
9719
9691
|
const workspaceRoot = findWorkspaceRoot(ctx.cwd) ?? ctx.cwd;
|
|
9720
|
-
const fromRoot = (file) => relative7(workspaceRoot,
|
|
9692
|
+
const fromRoot = (file) => relative7(workspaceRoot, join31(ctx.cwd, file));
|
|
9721
9693
|
let unsettled = 0;
|
|
9722
9694
|
const reverted = [];
|
|
9723
9695
|
for (let at = 0; at < written.length; at += FORMAT_BATCH) {
|
|
9724
9696
|
const batch = written.slice(at, at + FORMAT_BATCH);
|
|
9725
|
-
const before = new Map(batch.map((file) => [file, readIfPossible(
|
|
9697
|
+
const before = new Map(batch.map((file) => [file, readIfPossible(join31(ctx.cwd, file))]));
|
|
9726
9698
|
const pass = spawnSync(linter.bin, [...linter.args, ...batch.map(fromRoot)], {
|
|
9727
9699
|
cwd: workspaceRoot,
|
|
9728
9700
|
encoding: "utf8"
|
|
@@ -9731,11 +9703,11 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9731
9703
|
for (const file of batch) {
|
|
9732
9704
|
const was = before.get(file);
|
|
9733
9705
|
if (was === void 0) continue;
|
|
9734
|
-
const now = readIfPossible(
|
|
9706
|
+
const now = readIfPossible(join31(ctx.cwd, file));
|
|
9735
9707
|
if (now === void 0 || now === was) continue;
|
|
9736
9708
|
const lost = lineLostByTheFixer(was, now);
|
|
9737
9709
|
if (lost === void 0) continue;
|
|
9738
|
-
writeFileSync2(
|
|
9710
|
+
writeFileSync2(join31(ctx.cwd, file), was);
|
|
9739
9711
|
reverted.push(`${file}: \`${lost.slice(0, 80)}\``);
|
|
9740
9712
|
}
|
|
9741
9713
|
}
|
|
@@ -9814,7 +9786,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9814
9786
|
metrics: { ..._VitestAdapter.NOTHING_TO_REPORT, error: "vitest not available" }
|
|
9815
9787
|
};
|
|
9816
9788
|
}
|
|
9817
|
-
const out =
|
|
9789
|
+
const out = join31(mkdtempSync3(join31(tmpdir3(), "sentinel-test-report-")), "vitest.json");
|
|
9818
9790
|
const { cwd: runFrom, options, env } = fromWorkspaceRoot(ctx.cwd, [], []);
|
|
9819
9791
|
const result = spawnSync(bin, ["run", ...options, "--reporter=json", `--outputFile=${out}`], {
|
|
9820
9792
|
cwd: runFrom,
|
|
@@ -9829,7 +9801,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9829
9801
|
metrics: { ..._VitestAdapter.NOTHING_TO_REPORT, error: result.error.message }
|
|
9830
9802
|
};
|
|
9831
9803
|
}
|
|
9832
|
-
if (!
|
|
9804
|
+
if (!existsSync24(out)) {
|
|
9833
9805
|
return {
|
|
9834
9806
|
ok: false,
|
|
9835
9807
|
code: 1,
|
|
@@ -9960,10 +9932,7 @@ export {
|
|
|
9960
9932
|
projectTargets,
|
|
9961
9933
|
BaseAdapter,
|
|
9962
9934
|
splitToolArgs,
|
|
9963
|
-
|
|
9964
|
-
binFromOwnInstall,
|
|
9965
|
-
binSearchPath,
|
|
9966
|
-
scriptPath,
|
|
9935
|
+
separateToolArgs,
|
|
9967
9936
|
nxTargetOperations,
|
|
9968
9937
|
FORMAT_CONFIG_FILE,
|
|
9969
9938
|
FORMAT_SCRIPT_NAME,
|