@hublo/sentinel 1.4.0-alpha.20 → 1.4.0-alpha.22
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 +1 -1
- package/dist/{chunk-BPLSUYU7.js → chunk-SIGFE5KL.js} +129 -108
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/bin/sentinel.js
CHANGED
|
@@ -5406,9 +5406,9 @@ function registerLint() {
|
|
|
5406
5406
|
|
|
5407
5407
|
// src/roles/test/adapters/vitest/vitest.adapter.ts
|
|
5408
5408
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
5409
|
-
import { mkdtempSync as mkdtempSync2, readFileSync as
|
|
5409
|
+
import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync31 } from "node:fs";
|
|
5410
5410
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
5411
|
-
import { isAbsolute as isAbsolute3, join as
|
|
5411
|
+
import { isAbsolute as isAbsolute3, join as join39, resolve as resolve6 } from "node:path";
|
|
5412
5412
|
|
|
5413
5413
|
// src/roles/test/presets/toolchain.json
|
|
5414
5414
|
var toolchain_default2 = {
|
|
@@ -5485,18 +5485,36 @@ function testTarget(options) {
|
|
|
5485
5485
|
}
|
|
5486
5486
|
|
|
5487
5487
|
// src/roles/test/jest-migration.ts
|
|
5488
|
-
import { existsSync as existsSync30, readFileSync as
|
|
5488
|
+
import { existsSync as existsSync30, readFileSync as readFileSync29, readdirSync as readdirSync8 } from "node:fs";
|
|
5489
5489
|
import { createRequire as createRequire6 } from "node:module";
|
|
5490
|
-
import { dirname as dirname8, join as
|
|
5490
|
+
import { dirname as dirname8, join as join37, relative as relative7 } from "node:path";
|
|
5491
5491
|
|
|
5492
5492
|
// src/roles/test/codemod/migrate-module.ts
|
|
5493
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
5494
|
-
import { join as
|
|
5493
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync26, statSync as statSync6 } from "node:fs";
|
|
5494
|
+
import { join as join32 } from "node:path";
|
|
5495
5495
|
import { parseSync as parseSync8 } from "oxc-parser";
|
|
5496
5496
|
|
|
5497
|
+
// src/roles/test/msw-lifecycle.ts
|
|
5498
|
+
import { existsSync as existsSync23, readFileSync as readFileSync21 } from "node:fs";
|
|
5499
|
+
import { join as join27 } from "node:path";
|
|
5500
|
+
var ROOT_SETUP = "jest.setup.after.env.js";
|
|
5501
|
+
function ownsMswLifecycle(cwd, setupFiles) {
|
|
5502
|
+
for (const raw of setupFiles) {
|
|
5503
|
+
if (raw.endsWith(ROOT_SETUP)) continue;
|
|
5504
|
+
const file = join27(cwd, raw.replaceAll("<rootDir>/", "").replaceAll("<rootDir>", "."));
|
|
5505
|
+
if (!existsSync23(file)) continue;
|
|
5506
|
+
try {
|
|
5507
|
+
if (/\.listen\s*\(/.test(readFileSync21(file, "utf8"))) return true;
|
|
5508
|
+
} catch {
|
|
5509
|
+
continue;
|
|
5510
|
+
}
|
|
5511
|
+
}
|
|
5512
|
+
return false;
|
|
5513
|
+
}
|
|
5514
|
+
|
|
5497
5515
|
// src/roles/test/read-adoption.ts
|
|
5498
|
-
import { existsSync as
|
|
5499
|
-
import { join as
|
|
5516
|
+
import { existsSync as existsSync24, readFileSync as readFileSync22, readdirSync as readdirSync3 } from "node:fs";
|
|
5517
|
+
import { join as join28, relative as relative4 } from "node:path";
|
|
5500
5518
|
var JEST_CONFIG_FILES = [
|
|
5501
5519
|
"jest.config.ts",
|
|
5502
5520
|
"jest.config.js",
|
|
@@ -5505,15 +5523,15 @@ var JEST_CONFIG_FILES = [
|
|
|
5505
5523
|
"jest.integration-config.ts"
|
|
5506
5524
|
];
|
|
5507
5525
|
function testConfigFile(cwd) {
|
|
5508
|
-
return TEST_CONFIG_FILES.find((name) =>
|
|
5526
|
+
return TEST_CONFIG_FILES.find((name) => existsSync24(join28(cwd, name)));
|
|
5509
5527
|
}
|
|
5510
5528
|
function jestConfigFiles(cwd) {
|
|
5511
|
-
return JEST_CONFIG_FILES.filter((name) =>
|
|
5529
|
+
return JEST_CONFIG_FILES.filter((name) => existsSync24(join28(cwd, name)));
|
|
5512
5530
|
}
|
|
5513
5531
|
function rootJestConfigFiles(cwd) {
|
|
5514
5532
|
const root = findWorkspaceRoot(cwd);
|
|
5515
5533
|
if (root === void 0 || root === cwd) return [];
|
|
5516
|
-
return JEST_CONFIG_FILES.filter((name) =>
|
|
5534
|
+
return JEST_CONFIG_FILES.filter((name) => existsSync24(join28(root, name)));
|
|
5517
5535
|
}
|
|
5518
5536
|
var TEST_FILE = /[.-](spec|test)\.[cm]?[jt]sx?$/;
|
|
5519
5537
|
var NOT_WALKED = /* @__PURE__ */ new Set(["node_modules", "dist", "coverage", ".git", ".nx", ".turbo"]);
|
|
@@ -5536,9 +5554,9 @@ function walkTestFiles(cwd, stopAtFirst) {
|
|
|
5536
5554
|
}
|
|
5537
5555
|
for (const entry of entries) {
|
|
5538
5556
|
if (entry.isDirectory()) {
|
|
5539
|
-
if (!NOT_WALKED.has(entry.name)) stack.push(
|
|
5557
|
+
if (!NOT_WALKED.has(entry.name)) stack.push(join28(dir, entry.name));
|
|
5540
5558
|
} else if (TEST_FILE.test(entry.name)) {
|
|
5541
|
-
found.push(relative4(cwd,
|
|
5559
|
+
found.push(relative4(cwd, join28(dir, entry.name)).replaceAll("\\", "/"));
|
|
5542
5560
|
if (stopAtFirst) return found;
|
|
5543
5561
|
}
|
|
5544
5562
|
}
|
|
@@ -5547,7 +5565,7 @@ function walkTestFiles(cwd, stopAtFirst) {
|
|
|
5547
5565
|
}
|
|
5548
5566
|
function readTestConfigSource(cwd, fileName) {
|
|
5549
5567
|
try {
|
|
5550
|
-
return
|
|
5568
|
+
return readFileSync22(join28(cwd, fileName), "utf8");
|
|
5551
5569
|
} catch {
|
|
5552
5570
|
return "";
|
|
5553
5571
|
}
|
|
@@ -6477,9 +6495,9 @@ ${source}`;
|
|
|
6477
6495
|
}
|
|
6478
6496
|
|
|
6479
6497
|
// src/roles/test/codemod/named-rules.ts
|
|
6480
|
-
import { existsSync as
|
|
6498
|
+
import { existsSync as existsSync25, readFileSync as readFileSync23 } from "node:fs";
|
|
6481
6499
|
import { createRequire as createRequire4 } from "node:module";
|
|
6482
|
-
import { dirname as dirname4, join as
|
|
6500
|
+
import { dirname as dirname4, join as join29 } from "node:path";
|
|
6483
6501
|
function isCommonJsPackage(fromFile, specifier) {
|
|
6484
6502
|
if (specifier.startsWith(".") || specifier.startsWith("/")) return false;
|
|
6485
6503
|
let resolved;
|
|
@@ -6493,10 +6511,10 @@ function isCommonJsPackage(fromFile, specifier) {
|
|
|
6493
6511
|
if (resolved.endsWith(".cjs")) return true;
|
|
6494
6512
|
let dir = dirname4(resolved);
|
|
6495
6513
|
for (let depth = 0; depth < 12; depth += 1) {
|
|
6496
|
-
const manifest =
|
|
6497
|
-
if (
|
|
6514
|
+
const manifest = join29(dir, "package.json");
|
|
6515
|
+
if (existsSync25(manifest)) {
|
|
6498
6516
|
try {
|
|
6499
|
-
return JSON.parse(
|
|
6517
|
+
return JSON.parse(readFileSync23(manifest, "utf8")).type !== "module";
|
|
6500
6518
|
} catch {
|
|
6501
6519
|
return false;
|
|
6502
6520
|
}
|
|
@@ -7193,9 +7211,9 @@ function propagateAwait(fileName, source, original, elsewhere = /* @__PURE__ */
|
|
|
7193
7211
|
}
|
|
7194
7212
|
|
|
7195
7213
|
// src/roles/test/codemod/reexport-barrel-mock.ts
|
|
7196
|
-
import { readFileSync as
|
|
7214
|
+
import { readFileSync as readFileSync24, readdirSync as readdirSync4, statSync as statSync4 } from "node:fs";
|
|
7197
7215
|
import { createRequire as createRequire5 } from "node:module";
|
|
7198
|
-
import { dirname as dirname5, join as
|
|
7216
|
+
import { dirname as dirname5, join as join30 } from "node:path";
|
|
7199
7217
|
var MEMBER_TYPES13 = /* @__PURE__ */ new Set(["MemberExpression", "StaticMemberExpression"]);
|
|
7200
7218
|
var PACKAGE_SUBPATH = /^(@[^/]+\/[^/]+|[^@.][^/]*)\/(.+)$/;
|
|
7201
7219
|
var PURE_REEXPORT = /^module\.exports\s*=\s*require\(\s*(['"])([^'"]+)\1\s*\)\s*;?$/;
|
|
@@ -7248,11 +7266,11 @@ function barrelsFor(fromFile, name, target) {
|
|
|
7248
7266
|
const aliases = [];
|
|
7249
7267
|
for (const entry of entries) {
|
|
7250
7268
|
if (!entry.endsWith(".js")) continue;
|
|
7251
|
-
const path =
|
|
7269
|
+
const path = join30(root, entry);
|
|
7252
7270
|
let body;
|
|
7253
7271
|
try {
|
|
7254
7272
|
if (!statSync4(path).isFile()) continue;
|
|
7255
|
-
body =
|
|
7273
|
+
body = readFileSync24(path, "utf8");
|
|
7256
7274
|
} catch {
|
|
7257
7275
|
continue;
|
|
7258
7276
|
}
|
|
@@ -7394,7 +7412,7 @@ function parse2(fileName, source) {
|
|
|
7394
7412
|
const { program, errors } = parseSync7(fileName, source, { sourceType: "module" });
|
|
7395
7413
|
return errors.length > 0 ? void 0 : program;
|
|
7396
7414
|
}
|
|
7397
|
-
function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new Set(), asyncHelpers = /* @__PURE__ */ new Set()) {
|
|
7415
|
+
function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new Set(), asyncHelpers = /* @__PURE__ */ new Set(), modulesOwnMsw = false) {
|
|
7398
7416
|
const untouched = {
|
|
7399
7417
|
source,
|
|
7400
7418
|
changed: false,
|
|
@@ -7475,7 +7493,7 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
7475
7493
|
...spyTypes.typeImports
|
|
7476
7494
|
]);
|
|
7477
7495
|
const deep = normaliseDeepImports(withImport);
|
|
7478
|
-
const repointed = repointMswServer(fileName, deep.source);
|
|
7496
|
+
const repointed = modulesOwnMsw ? { source: deep.source, repointed: false } : repointMswServer(fileName, deep.source);
|
|
7479
7497
|
const finalProgram = parse2(fileName, repointed.source);
|
|
7480
7498
|
if (finalProgram === void 0) return unparsable("msw server import");
|
|
7481
7499
|
const barrels = rewriteReexportBarrelMocks(fileName, repointed.source, finalProgram);
|
|
@@ -7511,8 +7529,8 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
7511
7529
|
}
|
|
7512
7530
|
|
|
7513
7531
|
// src/roles/test/codemod/test-support-files.ts
|
|
7514
|
-
import { existsSync as
|
|
7515
|
-
import { dirname as dirname6, join as
|
|
7532
|
+
import { existsSync as existsSync26, readFileSync as readFileSync25, readdirSync as readdirSync5, statSync as statSync5 } from "node:fs";
|
|
7533
|
+
import { dirname as dirname6, join as join31, relative as relative5, resolve as resolve4 } from "node:path";
|
|
7516
7534
|
var SKIPPED = /* @__PURE__ */ new Set(["node_modules", "dist", "coverage", ".git", ".vite"]);
|
|
7517
7535
|
var TEST_FILE2 = /\.(spec|test)\.[cm]?[jt]sx?$/;
|
|
7518
7536
|
var SOURCE_FILE = /\.[cm]?[jt]sx?$/;
|
|
@@ -7532,13 +7550,13 @@ function relativeSpecifiers(source) {
|
|
|
7532
7550
|
}
|
|
7533
7551
|
function resolveSpecifier(fromFile, specifier) {
|
|
7534
7552
|
const base = resolve4(dirname6(fromFile), specifier);
|
|
7535
|
-
if (
|
|
7553
|
+
if (existsSync26(base) && statSync5(base).isFile()) return base;
|
|
7536
7554
|
for (const extension of EXTENSIONS) {
|
|
7537
|
-
if (
|
|
7555
|
+
if (existsSync26(`${base}${extension}`)) return `${base}${extension}`;
|
|
7538
7556
|
}
|
|
7539
7557
|
for (const extension of EXTENSIONS) {
|
|
7540
|
-
const index =
|
|
7541
|
-
if (
|
|
7558
|
+
const index = join31(base, `index${extension}`);
|
|
7559
|
+
if (existsSync26(index)) return index;
|
|
7542
7560
|
}
|
|
7543
7561
|
return void 0;
|
|
7544
7562
|
}
|
|
@@ -7555,9 +7573,9 @@ function moduleSources(cwd) {
|
|
|
7555
7573
|
}
|
|
7556
7574
|
for (const entry of entries) {
|
|
7557
7575
|
if (entry.isDirectory()) {
|
|
7558
|
-
if (!SKIPPED.has(entry.name)) stack.push(
|
|
7576
|
+
if (!SKIPPED.has(entry.name)) stack.push(join31(dir, entry.name));
|
|
7559
7577
|
} else if (SOURCE_FILE.test(entry.name)) {
|
|
7560
|
-
found.push(
|
|
7578
|
+
found.push(join31(dir, entry.name));
|
|
7561
7579
|
}
|
|
7562
7580
|
}
|
|
7563
7581
|
}
|
|
@@ -7565,7 +7583,7 @@ function moduleSources(cwd) {
|
|
|
7565
7583
|
}
|
|
7566
7584
|
function read(path) {
|
|
7567
7585
|
try {
|
|
7568
|
-
return
|
|
7586
|
+
return readFileSync25(path, "utf8");
|
|
7569
7587
|
} catch {
|
|
7570
7588
|
return void 0;
|
|
7571
7589
|
}
|
|
@@ -7577,7 +7595,7 @@ function setupFilesInside(cwd, named) {
|
|
|
7577
7595
|
const full = resolve4(cwd, withoutToken);
|
|
7578
7596
|
const inside = relative5(cwd, full);
|
|
7579
7597
|
if (inside.startsWith("..") || inside === "") continue;
|
|
7580
|
-
if (!
|
|
7598
|
+
if (!existsSync26(full)) continue;
|
|
7581
7599
|
kept.push(inside.replaceAll("\\", "/"));
|
|
7582
7600
|
}
|
|
7583
7601
|
return kept;
|
|
@@ -7623,7 +7641,7 @@ function parse3(source) {
|
|
|
7623
7641
|
}
|
|
7624
7642
|
function read2(path) {
|
|
7625
7643
|
try {
|
|
7626
|
-
return
|
|
7644
|
+
return readFileSync26(path, "utf8");
|
|
7627
7645
|
} catch {
|
|
7628
7646
|
return void 0;
|
|
7629
7647
|
}
|
|
@@ -7641,7 +7659,7 @@ function defaultImportedSpecifiers(cwd) {
|
|
|
7641
7659
|
}
|
|
7642
7660
|
for (const entry of entries) {
|
|
7643
7661
|
if (SKIPPED2.has(entry)) continue;
|
|
7644
|
-
const path =
|
|
7662
|
+
const path = join32(dir, entry);
|
|
7645
7663
|
let directory;
|
|
7646
7664
|
try {
|
|
7647
7665
|
directory = statSync6(path).isDirectory();
|
|
@@ -7662,6 +7680,7 @@ function defaultImportedSpecifiers(cwd) {
|
|
|
7662
7680
|
return found;
|
|
7663
7681
|
}
|
|
7664
7682
|
function migrateModuleTests(cwd, setupFiles = []) {
|
|
7683
|
+
const modulesOwnMsw = ownsMswLifecycle(cwd, setupFiles);
|
|
7665
7684
|
const operations = [];
|
|
7666
7685
|
const blockers = [];
|
|
7667
7686
|
let files = 0;
|
|
@@ -7670,12 +7689,18 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
7670
7689
|
const defaultImported = defaultImportedSpecifiers(cwd);
|
|
7671
7690
|
const asyncHelpers = /* @__PURE__ */ new Set();
|
|
7672
7691
|
for (const relative8 of listTestSupportFiles(cwd, setupFiles)) {
|
|
7673
|
-
const source = read2(
|
|
7692
|
+
const source = read2(join32(cwd, relative8));
|
|
7674
7693
|
if (source === void 0) {
|
|
7675
7694
|
blockers.push({ file: relative8, reason: "this file could not be read" });
|
|
7676
7695
|
continue;
|
|
7677
7696
|
}
|
|
7678
|
-
const migrated = migrateTestFile(
|
|
7697
|
+
const migrated = migrateTestFile(
|
|
7698
|
+
join32(cwd, relative8),
|
|
7699
|
+
source,
|
|
7700
|
+
defaultImported,
|
|
7701
|
+
/* @__PURE__ */ new Set(),
|
|
7702
|
+
modulesOwnMsw
|
|
7703
|
+
);
|
|
7679
7704
|
const renamedTo = vitestSupportName(relative8);
|
|
7680
7705
|
if (!migrated.changed && renamedTo === relative8) continue;
|
|
7681
7706
|
if (renamedTo !== relative8) operations.push({ kind: "delete", path: relative8 });
|
|
@@ -7692,12 +7717,18 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
7692
7717
|
operations.push({ kind: "write", path: renamedTo, contents: migrated.source });
|
|
7693
7718
|
}
|
|
7694
7719
|
for (const relative8 of listTestFiles(cwd)) {
|
|
7695
|
-
const source = read2(
|
|
7720
|
+
const source = read2(join32(cwd, relative8));
|
|
7696
7721
|
if (source === void 0) {
|
|
7697
7722
|
blockers.push({ file: relative8, reason: "this file could not be read" });
|
|
7698
7723
|
continue;
|
|
7699
7724
|
}
|
|
7700
|
-
const migrated = migrateTestFile(
|
|
7725
|
+
const migrated = migrateTestFile(
|
|
7726
|
+
join32(cwd, relative8),
|
|
7727
|
+
source,
|
|
7728
|
+
defaultImported,
|
|
7729
|
+
asyncHelpers,
|
|
7730
|
+
modulesOwnMsw
|
|
7731
|
+
);
|
|
7701
7732
|
for (const member of migrated.unhandled) {
|
|
7702
7733
|
blockers.push({
|
|
7703
7734
|
file: `${relative8}:${member.line}`,
|
|
@@ -7717,8 +7748,8 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
7717
7748
|
}
|
|
7718
7749
|
|
|
7719
7750
|
// src/roles/test/nest/generate-config.ts
|
|
7720
|
-
import {
|
|
7721
|
-
import { join as
|
|
7751
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync27, statSync as statSync7 } from "node:fs";
|
|
7752
|
+
import { join as join33, relative as relative6 } from "node:path";
|
|
7722
7753
|
var NEST_TEST_PRESET_SPECIFIER = "@hublo/sentinel/test/nest";
|
|
7723
7754
|
var REACT_TEST_PRESET_SPECIFIER = "@hublo/sentinel/test/react";
|
|
7724
7755
|
function flavourOf(reading) {
|
|
@@ -7762,7 +7793,7 @@ function readModuleTraits(cwd) {
|
|
|
7762
7793
|
}
|
|
7763
7794
|
for (const entry of entries) {
|
|
7764
7795
|
if (SKIPPED3.has(entry)) continue;
|
|
7765
|
-
const path =
|
|
7796
|
+
const path = join33(dir, entry);
|
|
7766
7797
|
let directory;
|
|
7767
7798
|
try {
|
|
7768
7799
|
directory = statSync7(path).isDirectory();
|
|
@@ -7776,7 +7807,7 @@ function readModuleTraits(cwd) {
|
|
|
7776
7807
|
if (!/\.tsx?$/.test(entry)) continue;
|
|
7777
7808
|
let source;
|
|
7778
7809
|
try {
|
|
7779
|
-
source =
|
|
7810
|
+
source = readFileSync27(path, "utf8");
|
|
7780
7811
|
} catch {
|
|
7781
7812
|
continue;
|
|
7782
7813
|
}
|
|
@@ -7793,20 +7824,8 @@ function readModuleTraits(cwd) {
|
|
|
7793
7824
|
return traits;
|
|
7794
7825
|
}
|
|
7795
7826
|
var withoutRootDir = (value) => value.replaceAll("<rootDir>/", "./").replaceAll("<rootDir>", ".");
|
|
7796
|
-
function
|
|
7797
|
-
|
|
7798
|
-
(file) => !file.endsWith("jest.setup.after.env.js")
|
|
7799
|
-
);
|
|
7800
|
-
for (const raw of declared) {
|
|
7801
|
-
const file = join32(cwd, raw.replaceAll("<rootDir>/", "").replaceAll("<rootDir>", "."));
|
|
7802
|
-
if (!existsSync26(file)) continue;
|
|
7803
|
-
try {
|
|
7804
|
-
if (/\.listen\s*\(/.test(readFileSync26(file, "utf8"))) return true;
|
|
7805
|
-
} catch {
|
|
7806
|
-
continue;
|
|
7807
|
-
}
|
|
7808
|
-
}
|
|
7809
|
-
return false;
|
|
7827
|
+
function ownsMswLifecycle2(cwd, reading) {
|
|
7828
|
+
return ownsMswLifecycle(cwd, [...reading.setupFiles ?? [], ...reading.setupFilesAfterEnv ?? []]);
|
|
7810
7829
|
}
|
|
7811
7830
|
function setupBlock(cwd, reading, msw) {
|
|
7812
7831
|
const declared = [...reading.setupFiles ?? [], ...reading.setupFilesAfterEnv ?? []];
|
|
@@ -7815,7 +7834,7 @@ function setupBlock(cwd, reading, msw) {
|
|
|
7815
7834
|
const sentinel = [
|
|
7816
7835
|
`'${SENTINEL_TEST_SETUP}'`,
|
|
7817
7836
|
...namedTheRootSetup ? [`'${SENTINEL_WORKSPACE_SETUP}'`] : [],
|
|
7818
|
-
...msw && namedTheRootSetup && !
|
|
7837
|
+
...msw && namedTheRootSetup && !ownsMswLifecycle2(cwd, reading) ? [`'${SENTINEL_MSW_SETUP}'`] : []
|
|
7819
7838
|
];
|
|
7820
7839
|
return ` setupFiles: [${[...sentinel, ...own].join(", ")}],`;
|
|
7821
7840
|
}
|
|
@@ -7829,11 +7848,13 @@ function concurrencyBlock(cwd, reading, target) {
|
|
|
7829
7848
|
if (declared !== void 0) {
|
|
7830
7849
|
return declared === "1" ? ` fileParallelism: false,` : ` maxWorkers: ${declared},`;
|
|
7831
7850
|
}
|
|
7832
|
-
const
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7851
|
+
const nxTarget = projectTargets(cwd)?.[target];
|
|
7852
|
+
for (const level of [nxTarget?.options, nxTarget?.configurations?.ci]) {
|
|
7853
|
+
if (level === void 0) continue;
|
|
7854
|
+
if (level.runInBand === true) return ` fileParallelism: false,`;
|
|
7855
|
+
if (typeof level.maxWorkers === "number") {
|
|
7856
|
+
return level.maxWorkers === 1 ? ` fileParallelism: false,` : ` maxWorkers: ${level.maxWorkers},`;
|
|
7857
|
+
}
|
|
7837
7858
|
}
|
|
7838
7859
|
return "";
|
|
7839
7860
|
}
|
|
@@ -7917,8 +7938,8 @@ ${overrides.join("\n")}
|
|
|
7917
7938
|
}
|
|
7918
7939
|
|
|
7919
7940
|
// src/roles/test/nest/read-jest-config.ts
|
|
7920
|
-
import { existsSync as existsSync27, readFileSync as
|
|
7921
|
-
import { join as
|
|
7941
|
+
import { existsSync as existsSync27, readFileSync as readFileSync28 } from "node:fs";
|
|
7942
|
+
import { join as join34 } from "node:path";
|
|
7922
7943
|
var CARRIED = [
|
|
7923
7944
|
"testEnvironment",
|
|
7924
7945
|
"coverageDirectory",
|
|
@@ -8108,7 +8129,7 @@ function extendedConfig(source, cwd) {
|
|
|
8108
8129
|
(name) => name.replace(/^\.\//, "")
|
|
8109
8130
|
);
|
|
8110
8131
|
const file = candidates.find(
|
|
8111
|
-
(name) => /^jest[\w.-]*\.(ts|js)$/.test(name) && existsSync27(
|
|
8132
|
+
(name) => /^jest[\w.-]*\.(ts|js)$/.test(name) && existsSync27(join34(cwd, name))
|
|
8112
8133
|
);
|
|
8113
8134
|
if (file === void 0) continue;
|
|
8114
8135
|
if (!new RegExp(String.raw`\{\s*\.\.\.${binding}\b`).test(source)) continue;
|
|
@@ -8135,11 +8156,11 @@ function sideEffects(source, extended) {
|
|
|
8135
8156
|
return found;
|
|
8136
8157
|
}
|
|
8137
8158
|
function readJestConfig(cwd, named) {
|
|
8138
|
-
const file = named ?? JEST_CONFIG_FILES.find((name) => existsSync27(
|
|
8139
|
-
if (file === void 0 || !existsSync27(
|
|
8159
|
+
const file = named ?? JEST_CONFIG_FILES.find((name) => existsSync27(join34(cwd, name)));
|
|
8160
|
+
if (file === void 0 || !existsSync27(join34(cwd, file))) return void 0;
|
|
8140
8161
|
let source;
|
|
8141
8162
|
try {
|
|
8142
|
-
source =
|
|
8163
|
+
source = readFileSync28(join34(cwd, file), "utf8");
|
|
8143
8164
|
} catch {
|
|
8144
8165
|
return { file, refusals: [`${file} could not be read`], notes: [] };
|
|
8145
8166
|
}
|
|
@@ -8221,7 +8242,7 @@ function readJestConfig(cwd, named) {
|
|
|
8221
8242
|
|
|
8222
8243
|
// src/roles/test/nest/run-modes.ts
|
|
8223
8244
|
import { existsSync as existsSync28 } from "node:fs";
|
|
8224
|
-
import { basename as basename2, join as
|
|
8245
|
+
import { basename as basename2, join as join35 } from "node:path";
|
|
8225
8246
|
var JEST_EXECUTOR = "@nx/jest:jest";
|
|
8226
8247
|
var PRIMARY_CONFIG_FILE = "vitest.config.mts";
|
|
8227
8248
|
var PRIMARY_TARGET = "test";
|
|
@@ -8242,7 +8263,7 @@ function runModes(cwd, fallback) {
|
|
|
8242
8263
|
const jestConfig = entry.options?.jestConfig;
|
|
8243
8264
|
if (jestConfig === void 0) continue;
|
|
8244
8265
|
const name = configName(jestConfig);
|
|
8245
|
-
if (!existsSync28(
|
|
8266
|
+
if (!existsSync28(join35(cwd, name))) continue;
|
|
8246
8267
|
declared.push({
|
|
8247
8268
|
target,
|
|
8248
8269
|
jestConfig: name,
|
|
@@ -8268,7 +8289,7 @@ function runModes(cwd, fallback) {
|
|
|
8268
8289
|
|
|
8269
8290
|
// src/roles/test/written-file-formatter.ts
|
|
8270
8291
|
import { existsSync as existsSync29 } from "node:fs";
|
|
8271
|
-
import { dirname as dirname7, join as
|
|
8292
|
+
import { dirname as dirname7, join as join36 } from "node:path";
|
|
8272
8293
|
var PRETTIER_CONFIGS = [
|
|
8273
8294
|
".prettierrc",
|
|
8274
8295
|
".prettierrc.json",
|
|
@@ -8287,7 +8308,7 @@ function prettierConfigFrom(cwd) {
|
|
|
8287
8308
|
let dir = cwd;
|
|
8288
8309
|
for (; ; ) {
|
|
8289
8310
|
for (const name of PRETTIER_CONFIGS) {
|
|
8290
|
-
if (existsSync29(
|
|
8311
|
+
if (existsSync29(join36(dir, name))) return join36(dir, name);
|
|
8291
8312
|
}
|
|
8292
8313
|
const parent = dirname7(dir);
|
|
8293
8314
|
if (parent === dir) return void 0;
|
|
@@ -8317,12 +8338,12 @@ function writtenFileFormatter(cwd) {
|
|
|
8317
8338
|
var SPEC_TSCONFIG = "tsconfig.spec.json";
|
|
8318
8339
|
var VITEST_GLOBAL_TYPES = "vitest/globals";
|
|
8319
8340
|
function specTypesOperation(cwd) {
|
|
8320
|
-
const path =
|
|
8341
|
+
const path = join37(cwd, SPEC_TSCONFIG);
|
|
8321
8342
|
if (!existsSync30(path)) return void 0;
|
|
8322
8343
|
let config;
|
|
8323
8344
|
try {
|
|
8324
8345
|
config = parseJsonc(
|
|
8325
|
-
|
|
8346
|
+
readFileSync29(path, "utf8"),
|
|
8326
8347
|
SPEC_TSCONFIG
|
|
8327
8348
|
);
|
|
8328
8349
|
} catch {
|
|
@@ -8342,8 +8363,8 @@ function specTypesOperation(cwd) {
|
|
|
8342
8363
|
}
|
|
8343
8364
|
function shippedTypesPath(cwd, declaration) {
|
|
8344
8365
|
try {
|
|
8345
|
-
const manifest = createRequire6(
|
|
8346
|
-
const file =
|
|
8366
|
+
const manifest = createRequire6(join37(cwd, "noop.cjs")).resolve("@hublo/sentinel/package.json");
|
|
8367
|
+
const file = join37(dirname8(manifest), declaration);
|
|
8347
8368
|
if (existsSync30(file)) {
|
|
8348
8369
|
const path = relative7(cwd, file);
|
|
8349
8370
|
return path.startsWith(".") ? path : `./${path}`;
|
|
@@ -8364,7 +8385,7 @@ function tsconfigFileListOperations(cwd) {
|
|
|
8364
8385
|
let config;
|
|
8365
8386
|
try {
|
|
8366
8387
|
config = parseJsonc(
|
|
8367
|
-
|
|
8388
|
+
readFileSync29(join37(cwd, name), "utf8"),
|
|
8368
8389
|
name
|
|
8369
8390
|
);
|
|
8370
8391
|
} catch {
|
|
@@ -8653,9 +8674,9 @@ function plan3(context) {
|
|
|
8653
8674
|
// src/roles/test/reference.ts
|
|
8654
8675
|
import { execFileSync } from "node:child_process";
|
|
8655
8676
|
import { createHash } from "node:crypto";
|
|
8656
|
-
import { existsSync as existsSync31, mkdirSync, mkdtempSync, readFileSync as
|
|
8677
|
+
import { existsSync as existsSync31, mkdirSync, mkdtempSync, readFileSync as readFileSync30, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8657
8678
|
import { tmpdir } from "node:os";
|
|
8658
|
-
import { join as
|
|
8679
|
+
import { join as join38, resolve as resolve5 } from "node:path";
|
|
8659
8680
|
|
|
8660
8681
|
// src/roles/test/baseline.ts
|
|
8661
8682
|
function readSnapshot(report) {
|
|
@@ -8899,15 +8920,15 @@ function describeComparison(comparison) {
|
|
|
8899
8920
|
// src/roles/test/reference.ts
|
|
8900
8921
|
function referencePath(cwd) {
|
|
8901
8922
|
const key = createHash("sha256").update(resolve5(cwd)).digest("hex").slice(0, 16);
|
|
8902
|
-
return
|
|
8923
|
+
return join38(tmpdir(), "sentinel-test-reference", `${key}.json`);
|
|
8903
8924
|
}
|
|
8904
8925
|
function runJest(cwd, config) {
|
|
8905
8926
|
const bin = resolveBin(cwd, "jest");
|
|
8906
8927
|
if (bin === void 0) return void 0;
|
|
8907
8928
|
const root = findWorkspaceRoot(cwd) ?? cwd;
|
|
8908
|
-
const out =
|
|
8929
|
+
const out = join38(mkdtempSync(join38(tmpdir(), "sentinel-reference-")), "jest.json");
|
|
8909
8930
|
try {
|
|
8910
|
-
execFileSync(bin, ["-c",
|
|
8931
|
+
execFileSync(bin, ["-c", join38(cwd, config), "--json", `--outputFile=${out}`, "--silent"], {
|
|
8911
8932
|
cwd: root,
|
|
8912
8933
|
stdio: ["ignore", "ignore", "ignore"],
|
|
8913
8934
|
maxBuffer: 1 << 28
|
|
@@ -8916,7 +8937,7 @@ function runJest(cwd, config) {
|
|
|
8916
8937
|
}
|
|
8917
8938
|
if (!existsSync31(out)) return void 0;
|
|
8918
8939
|
try {
|
|
8919
|
-
return JSON.parse(
|
|
8940
|
+
return JSON.parse(readFileSync30(out, "utf8"));
|
|
8920
8941
|
} catch {
|
|
8921
8942
|
return void 0;
|
|
8922
8943
|
}
|
|
@@ -8944,7 +8965,7 @@ function captureReference(cwd, config) {
|
|
|
8944
8965
|
snapshot
|
|
8945
8966
|
};
|
|
8946
8967
|
const path = referencePath(cwd);
|
|
8947
|
-
mkdirSync(
|
|
8968
|
+
mkdirSync(join38(path, ".."), { recursive: true });
|
|
8948
8969
|
writeFileSync3(path, `${JSON.stringify(stored, void 0, 2)}
|
|
8949
8970
|
`);
|
|
8950
8971
|
return {
|
|
@@ -8959,7 +8980,7 @@ function compareAgainstReference(cwd, report) {
|
|
|
8959
8980
|
const path = referencePath(cwd);
|
|
8960
8981
|
let stored;
|
|
8961
8982
|
try {
|
|
8962
|
-
stored = JSON.parse(
|
|
8983
|
+
stored = JSON.parse(readFileSync30(path, "utf8"));
|
|
8963
8984
|
} catch {
|
|
8964
8985
|
rmSync3(path, { force: true });
|
|
8965
8986
|
return { ok: true, message: `the recorded reference could not be read, so nothing was proved.` };
|
|
@@ -9126,7 +9147,7 @@ var VitestAdapter = class extends BaseAdapter {
|
|
|
9126
9147
|
const { cwd: runFrom, options, paths } = fromWorkspaceRoot(ctx.cwd, typedOptions, typedPaths);
|
|
9127
9148
|
const watching = options.includes("--watch") || options.includes("-w");
|
|
9128
9149
|
const proving = !watching && hasReference(ctx.cwd);
|
|
9129
|
-
const reportFile = proving ?
|
|
9150
|
+
const reportFile = proving ? join39(mkdtempSync2(join39(tmpdir2(), "sentinel-run-")), "vitest.json") : void 0;
|
|
9130
9151
|
const reporters = reportFile === void 0 ? [] : ["--reporter=default", "--reporter=json", `--outputFile=${reportFile}`];
|
|
9131
9152
|
const argv = watching ? [...options, ...paths] : ["run", ...reporters, ...options, ...paths];
|
|
9132
9153
|
const result = spawnSync5(bin, argv, { cwd: runFrom, stdio: "inherit" });
|
|
@@ -9138,7 +9159,7 @@ var VitestAdapter = class extends BaseAdapter {
|
|
|
9138
9159
|
if (reportFile !== void 0) {
|
|
9139
9160
|
let report;
|
|
9140
9161
|
try {
|
|
9141
|
-
report = JSON.parse(
|
|
9162
|
+
report = JSON.parse(readFileSync31(reportFile, "utf8"));
|
|
9142
9163
|
} catch {
|
|
9143
9164
|
report = void 0;
|
|
9144
9165
|
}
|
|
@@ -9191,9 +9212,9 @@ function registerTest() {
|
|
|
9191
9212
|
|
|
9192
9213
|
// src/roles/typescript/adapters/tsc/tsc.adapter.ts
|
|
9193
9214
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
9194
|
-
import { existsSync as existsSync32, readFileSync as
|
|
9215
|
+
import { existsSync as existsSync32, readFileSync as readFileSync33 } from "node:fs";
|
|
9195
9216
|
import { createRequire as createRequire7 } from "node:module";
|
|
9196
|
-
import { join as
|
|
9217
|
+
import { join as join41 } from "node:path";
|
|
9197
9218
|
|
|
9198
9219
|
// src/roles/typescript/presets/nest.json
|
|
9199
9220
|
var nest_default2 = {
|
|
@@ -9374,8 +9395,8 @@ function readTsconfigAdoption(cwd) {
|
|
|
9374
9395
|
}
|
|
9375
9396
|
|
|
9376
9397
|
// src/roles/typescript/adapters/tsc/plan.ts
|
|
9377
|
-
import { readFileSync as
|
|
9378
|
-
import { join as
|
|
9398
|
+
import { readFileSync as readFileSync32 } from "node:fs";
|
|
9399
|
+
import { join as join40 } from "node:path";
|
|
9379
9400
|
|
|
9380
9401
|
// src/roles/typescript/typecheck-script.ts
|
|
9381
9402
|
var SENTINEL_TYPECHECK_COMMAND = "sentinel --run --typescript";
|
|
@@ -9468,7 +9489,7 @@ function planAdoption(context) {
|
|
|
9468
9489
|
};
|
|
9469
9490
|
}
|
|
9470
9491
|
const existing = parseJsonc(
|
|
9471
|
-
|
|
9492
|
+
readFileSync32(join40(context.cwd, target.path), "utf8"),
|
|
9472
9493
|
target.path
|
|
9473
9494
|
);
|
|
9474
9495
|
const extendsChain = composeExtends(existing.extends, preset);
|
|
@@ -9606,7 +9627,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
9606
9627
|
let chain;
|
|
9607
9628
|
try {
|
|
9608
9629
|
const parsed = parseJsonc(
|
|
9609
|
-
|
|
9630
|
+
readFileSync33(join41(cwd, target.path), "utf8"),
|
|
9610
9631
|
target.path
|
|
9611
9632
|
);
|
|
9612
9633
|
chain = parsed.extends;
|
|
@@ -9619,7 +9640,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
9619
9640
|
);
|
|
9620
9641
|
if (preset === void 0) return void 0;
|
|
9621
9642
|
try {
|
|
9622
|
-
createRequire7(
|
|
9643
|
+
createRequire7(join41(cwd, "noop.js")).resolve(preset);
|
|
9623
9644
|
return void 0;
|
|
9624
9645
|
} catch {
|
|
9625
9646
|
return preset;
|
|
@@ -9715,7 +9736,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
9715
9736
|
referencedProjects(cwd, config) {
|
|
9716
9737
|
try {
|
|
9717
9738
|
const parsed = parseJsonc(
|
|
9718
|
-
|
|
9739
|
+
readFileSync33(join41(cwd, config), "utf8"),
|
|
9719
9740
|
config
|
|
9720
9741
|
);
|
|
9721
9742
|
const referenced = (parsed.references ?? []).map((reference) => reference.path).filter((path) => typeof path === "string" && path.length > 0);
|
|
@@ -9731,7 +9752,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
9731
9752
|
* check.
|
|
9732
9753
|
*/
|
|
9733
9754
|
typecheckTarget(cwd) {
|
|
9734
|
-
if (existsSync32(
|
|
9755
|
+
if (existsSync32(join41(cwd, "tsconfig.json"))) return "tsconfig.json";
|
|
9735
9756
|
const target = resolveTsconfigTarget(cwd);
|
|
9736
9757
|
return target.reason === "none" ? null : target.path;
|
|
9737
9758
|
}
|
|
@@ -9936,7 +9957,7 @@ function replaceLines(current, replacements) {
|
|
|
9936
9957
|
}
|
|
9937
9958
|
|
|
9938
9959
|
// src/core/apply-plan.ts
|
|
9939
|
-
import { existsSync as existsSync33, readFileSync as
|
|
9960
|
+
import { existsSync as existsSync33, readFileSync as readFileSync34, renameSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
9940
9961
|
import { resolve as resolve7, sep } from "node:path";
|
|
9941
9962
|
import { applyEdits as applyEdits3, findNodeAtLocation, modify, parseTree } from "jsonc-parser";
|
|
9942
9963
|
|
|
@@ -9955,7 +9976,7 @@ function resolveWithinRoot(cwd, relativePath) {
|
|
|
9955
9976
|
return absolutePath;
|
|
9956
9977
|
}
|
|
9957
9978
|
function readIfExists(absolutePath) {
|
|
9958
|
-
return existsSync33(absolutePath) ?
|
|
9979
|
+
return existsSync33(absolutePath) ? readFileSync34(absolutePath, "utf8") : void 0;
|
|
9959
9980
|
}
|
|
9960
9981
|
function* leaves(value, prefix = []) {
|
|
9961
9982
|
for (const [key, keyValue] of Object.entries(value)) {
|
|
@@ -10073,8 +10094,8 @@ function applyPlan(cwd, plan4) {
|
|
|
10073
10094
|
}
|
|
10074
10095
|
|
|
10075
10096
|
// src/core/config/preset-evidence.ts
|
|
10076
|
-
import { existsSync as existsSync34, readdirSync as readdirSync9, readFileSync as
|
|
10077
|
-
import { join as
|
|
10097
|
+
import { existsSync as existsSync34, readdirSync as readdirSync9, readFileSync as readFileSync35 } from "node:fs";
|
|
10098
|
+
import { join as join42 } from "node:path";
|
|
10078
10099
|
var PATH_SIGNALS = [
|
|
10079
10100
|
{
|
|
10080
10101
|
preset: "nest",
|
|
@@ -10108,12 +10129,12 @@ function sourceImports(cwd, pattern) {
|
|
|
10108
10129
|
}
|
|
10109
10130
|
for (const entry of entries) {
|
|
10110
10131
|
if (entry.isDirectory()) {
|
|
10111
|
-
if (!NOT_SCANNED.has(entry.name)) stack.push(
|
|
10132
|
+
if (!NOT_SCANNED.has(entry.name)) stack.push(join42(dir, entry.name));
|
|
10112
10133
|
continue;
|
|
10113
10134
|
}
|
|
10114
10135
|
if (!SOURCE_FILE2.test(entry.name)) continue;
|
|
10115
10136
|
try {
|
|
10116
|
-
if (pattern.test(
|
|
10137
|
+
if (pattern.test(readFileSync35(join42(dir, entry.name), "utf8"))) return true;
|
|
10117
10138
|
} catch {
|
|
10118
10139
|
continue;
|
|
10119
10140
|
}
|
|
@@ -10122,11 +10143,11 @@ function sourceImports(cwd, pattern) {
|
|
|
10122
10143
|
return false;
|
|
10123
10144
|
}
|
|
10124
10145
|
function dependencyNames(cwd) {
|
|
10125
|
-
const path =
|
|
10146
|
+
const path = join42(cwd, "package.json");
|
|
10126
10147
|
if (!existsSync34(path)) return [];
|
|
10127
10148
|
try {
|
|
10128
10149
|
const manifest = parseJsonc(
|
|
10129
|
-
|
|
10150
|
+
readFileSync35(path, "utf8"),
|
|
10130
10151
|
path
|
|
10131
10152
|
);
|
|
10132
10153
|
return [
|
|
@@ -10149,7 +10170,7 @@ function declaresJsx(cwd) {
|
|
|
10149
10170
|
for (const name of entries) {
|
|
10150
10171
|
try {
|
|
10151
10172
|
const config = parseJsonc(
|
|
10152
|
-
|
|
10173
|
+
readFileSync35(join42(cwd, name), "utf8"),
|
|
10153
10174
|
name
|
|
10154
10175
|
);
|
|
10155
10176
|
if (config.compilerOptions?.jsx !== void 0) return true;
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hublo/sentinel",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.22",
|
|
4
4
|
"description": "One CLI that guards code health across Hublo repos: shared lint/typescript/build/test presets, static & dynamic analysis, and architecture checks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|