@hublo/sentinel 1.4.0-alpha.20 → 1.4.0-alpha.21
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-7LE72AFG.js} +122 -103
- 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
|
}
|
|
@@ -7917,8 +7936,8 @@ ${overrides.join("\n")}
|
|
|
7917
7936
|
}
|
|
7918
7937
|
|
|
7919
7938
|
// src/roles/test/nest/read-jest-config.ts
|
|
7920
|
-
import { existsSync as existsSync27, readFileSync as
|
|
7921
|
-
import { join as
|
|
7939
|
+
import { existsSync as existsSync27, readFileSync as readFileSync28 } from "node:fs";
|
|
7940
|
+
import { join as join34 } from "node:path";
|
|
7922
7941
|
var CARRIED = [
|
|
7923
7942
|
"testEnvironment",
|
|
7924
7943
|
"coverageDirectory",
|
|
@@ -8108,7 +8127,7 @@ function extendedConfig(source, cwd) {
|
|
|
8108
8127
|
(name) => name.replace(/^\.\//, "")
|
|
8109
8128
|
);
|
|
8110
8129
|
const file = candidates.find(
|
|
8111
|
-
(name) => /^jest[\w.-]*\.(ts|js)$/.test(name) && existsSync27(
|
|
8130
|
+
(name) => /^jest[\w.-]*\.(ts|js)$/.test(name) && existsSync27(join34(cwd, name))
|
|
8112
8131
|
);
|
|
8113
8132
|
if (file === void 0) continue;
|
|
8114
8133
|
if (!new RegExp(String.raw`\{\s*\.\.\.${binding}\b`).test(source)) continue;
|
|
@@ -8135,11 +8154,11 @@ function sideEffects(source, extended) {
|
|
|
8135
8154
|
return found;
|
|
8136
8155
|
}
|
|
8137
8156
|
function readJestConfig(cwd, named) {
|
|
8138
|
-
const file = named ?? JEST_CONFIG_FILES.find((name) => existsSync27(
|
|
8139
|
-
if (file === void 0 || !existsSync27(
|
|
8157
|
+
const file = named ?? JEST_CONFIG_FILES.find((name) => existsSync27(join34(cwd, name)));
|
|
8158
|
+
if (file === void 0 || !existsSync27(join34(cwd, file))) return void 0;
|
|
8140
8159
|
let source;
|
|
8141
8160
|
try {
|
|
8142
|
-
source =
|
|
8161
|
+
source = readFileSync28(join34(cwd, file), "utf8");
|
|
8143
8162
|
} catch {
|
|
8144
8163
|
return { file, refusals: [`${file} could not be read`], notes: [] };
|
|
8145
8164
|
}
|
|
@@ -8221,7 +8240,7 @@ function readJestConfig(cwd, named) {
|
|
|
8221
8240
|
|
|
8222
8241
|
// src/roles/test/nest/run-modes.ts
|
|
8223
8242
|
import { existsSync as existsSync28 } from "node:fs";
|
|
8224
|
-
import { basename as basename2, join as
|
|
8243
|
+
import { basename as basename2, join as join35 } from "node:path";
|
|
8225
8244
|
var JEST_EXECUTOR = "@nx/jest:jest";
|
|
8226
8245
|
var PRIMARY_CONFIG_FILE = "vitest.config.mts";
|
|
8227
8246
|
var PRIMARY_TARGET = "test";
|
|
@@ -8242,7 +8261,7 @@ function runModes(cwd, fallback) {
|
|
|
8242
8261
|
const jestConfig = entry.options?.jestConfig;
|
|
8243
8262
|
if (jestConfig === void 0) continue;
|
|
8244
8263
|
const name = configName(jestConfig);
|
|
8245
|
-
if (!existsSync28(
|
|
8264
|
+
if (!existsSync28(join35(cwd, name))) continue;
|
|
8246
8265
|
declared.push({
|
|
8247
8266
|
target,
|
|
8248
8267
|
jestConfig: name,
|
|
@@ -8268,7 +8287,7 @@ function runModes(cwd, fallback) {
|
|
|
8268
8287
|
|
|
8269
8288
|
// src/roles/test/written-file-formatter.ts
|
|
8270
8289
|
import { existsSync as existsSync29 } from "node:fs";
|
|
8271
|
-
import { dirname as dirname7, join as
|
|
8290
|
+
import { dirname as dirname7, join as join36 } from "node:path";
|
|
8272
8291
|
var PRETTIER_CONFIGS = [
|
|
8273
8292
|
".prettierrc",
|
|
8274
8293
|
".prettierrc.json",
|
|
@@ -8287,7 +8306,7 @@ function prettierConfigFrom(cwd) {
|
|
|
8287
8306
|
let dir = cwd;
|
|
8288
8307
|
for (; ; ) {
|
|
8289
8308
|
for (const name of PRETTIER_CONFIGS) {
|
|
8290
|
-
if (existsSync29(
|
|
8309
|
+
if (existsSync29(join36(dir, name))) return join36(dir, name);
|
|
8291
8310
|
}
|
|
8292
8311
|
const parent = dirname7(dir);
|
|
8293
8312
|
if (parent === dir) return void 0;
|
|
@@ -8317,12 +8336,12 @@ function writtenFileFormatter(cwd) {
|
|
|
8317
8336
|
var SPEC_TSCONFIG = "tsconfig.spec.json";
|
|
8318
8337
|
var VITEST_GLOBAL_TYPES = "vitest/globals";
|
|
8319
8338
|
function specTypesOperation(cwd) {
|
|
8320
|
-
const path =
|
|
8339
|
+
const path = join37(cwd, SPEC_TSCONFIG);
|
|
8321
8340
|
if (!existsSync30(path)) return void 0;
|
|
8322
8341
|
let config;
|
|
8323
8342
|
try {
|
|
8324
8343
|
config = parseJsonc(
|
|
8325
|
-
|
|
8344
|
+
readFileSync29(path, "utf8"),
|
|
8326
8345
|
SPEC_TSCONFIG
|
|
8327
8346
|
);
|
|
8328
8347
|
} catch {
|
|
@@ -8342,8 +8361,8 @@ function specTypesOperation(cwd) {
|
|
|
8342
8361
|
}
|
|
8343
8362
|
function shippedTypesPath(cwd, declaration) {
|
|
8344
8363
|
try {
|
|
8345
|
-
const manifest = createRequire6(
|
|
8346
|
-
const file =
|
|
8364
|
+
const manifest = createRequire6(join37(cwd, "noop.cjs")).resolve("@hublo/sentinel/package.json");
|
|
8365
|
+
const file = join37(dirname8(manifest), declaration);
|
|
8347
8366
|
if (existsSync30(file)) {
|
|
8348
8367
|
const path = relative7(cwd, file);
|
|
8349
8368
|
return path.startsWith(".") ? path : `./${path}`;
|
|
@@ -8364,7 +8383,7 @@ function tsconfigFileListOperations(cwd) {
|
|
|
8364
8383
|
let config;
|
|
8365
8384
|
try {
|
|
8366
8385
|
config = parseJsonc(
|
|
8367
|
-
|
|
8386
|
+
readFileSync29(join37(cwd, name), "utf8"),
|
|
8368
8387
|
name
|
|
8369
8388
|
);
|
|
8370
8389
|
} catch {
|
|
@@ -8653,9 +8672,9 @@ function plan3(context) {
|
|
|
8653
8672
|
// src/roles/test/reference.ts
|
|
8654
8673
|
import { execFileSync } from "node:child_process";
|
|
8655
8674
|
import { createHash } from "node:crypto";
|
|
8656
|
-
import { existsSync as existsSync31, mkdirSync, mkdtempSync, readFileSync as
|
|
8675
|
+
import { existsSync as existsSync31, mkdirSync, mkdtempSync, readFileSync as readFileSync30, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8657
8676
|
import { tmpdir } from "node:os";
|
|
8658
|
-
import { join as
|
|
8677
|
+
import { join as join38, resolve as resolve5 } from "node:path";
|
|
8659
8678
|
|
|
8660
8679
|
// src/roles/test/baseline.ts
|
|
8661
8680
|
function readSnapshot(report) {
|
|
@@ -8899,15 +8918,15 @@ function describeComparison(comparison) {
|
|
|
8899
8918
|
// src/roles/test/reference.ts
|
|
8900
8919
|
function referencePath(cwd) {
|
|
8901
8920
|
const key = createHash("sha256").update(resolve5(cwd)).digest("hex").slice(0, 16);
|
|
8902
|
-
return
|
|
8921
|
+
return join38(tmpdir(), "sentinel-test-reference", `${key}.json`);
|
|
8903
8922
|
}
|
|
8904
8923
|
function runJest(cwd, config) {
|
|
8905
8924
|
const bin = resolveBin(cwd, "jest");
|
|
8906
8925
|
if (bin === void 0) return void 0;
|
|
8907
8926
|
const root = findWorkspaceRoot(cwd) ?? cwd;
|
|
8908
|
-
const out =
|
|
8927
|
+
const out = join38(mkdtempSync(join38(tmpdir(), "sentinel-reference-")), "jest.json");
|
|
8909
8928
|
try {
|
|
8910
|
-
execFileSync(bin, ["-c",
|
|
8929
|
+
execFileSync(bin, ["-c", join38(cwd, config), "--json", `--outputFile=${out}`, "--silent"], {
|
|
8911
8930
|
cwd: root,
|
|
8912
8931
|
stdio: ["ignore", "ignore", "ignore"],
|
|
8913
8932
|
maxBuffer: 1 << 28
|
|
@@ -8916,7 +8935,7 @@ function runJest(cwd, config) {
|
|
|
8916
8935
|
}
|
|
8917
8936
|
if (!existsSync31(out)) return void 0;
|
|
8918
8937
|
try {
|
|
8919
|
-
return JSON.parse(
|
|
8938
|
+
return JSON.parse(readFileSync30(out, "utf8"));
|
|
8920
8939
|
} catch {
|
|
8921
8940
|
return void 0;
|
|
8922
8941
|
}
|
|
@@ -8944,7 +8963,7 @@ function captureReference(cwd, config) {
|
|
|
8944
8963
|
snapshot
|
|
8945
8964
|
};
|
|
8946
8965
|
const path = referencePath(cwd);
|
|
8947
|
-
mkdirSync(
|
|
8966
|
+
mkdirSync(join38(path, ".."), { recursive: true });
|
|
8948
8967
|
writeFileSync3(path, `${JSON.stringify(stored, void 0, 2)}
|
|
8949
8968
|
`);
|
|
8950
8969
|
return {
|
|
@@ -8959,7 +8978,7 @@ function compareAgainstReference(cwd, report) {
|
|
|
8959
8978
|
const path = referencePath(cwd);
|
|
8960
8979
|
let stored;
|
|
8961
8980
|
try {
|
|
8962
|
-
stored = JSON.parse(
|
|
8981
|
+
stored = JSON.parse(readFileSync30(path, "utf8"));
|
|
8963
8982
|
} catch {
|
|
8964
8983
|
rmSync3(path, { force: true });
|
|
8965
8984
|
return { ok: true, message: `the recorded reference could not be read, so nothing was proved.` };
|
|
@@ -9126,7 +9145,7 @@ var VitestAdapter = class extends BaseAdapter {
|
|
|
9126
9145
|
const { cwd: runFrom, options, paths } = fromWorkspaceRoot(ctx.cwd, typedOptions, typedPaths);
|
|
9127
9146
|
const watching = options.includes("--watch") || options.includes("-w");
|
|
9128
9147
|
const proving = !watching && hasReference(ctx.cwd);
|
|
9129
|
-
const reportFile = proving ?
|
|
9148
|
+
const reportFile = proving ? join39(mkdtempSync2(join39(tmpdir2(), "sentinel-run-")), "vitest.json") : void 0;
|
|
9130
9149
|
const reporters = reportFile === void 0 ? [] : ["--reporter=default", "--reporter=json", `--outputFile=${reportFile}`];
|
|
9131
9150
|
const argv = watching ? [...options, ...paths] : ["run", ...reporters, ...options, ...paths];
|
|
9132
9151
|
const result = spawnSync5(bin, argv, { cwd: runFrom, stdio: "inherit" });
|
|
@@ -9138,7 +9157,7 @@ var VitestAdapter = class extends BaseAdapter {
|
|
|
9138
9157
|
if (reportFile !== void 0) {
|
|
9139
9158
|
let report;
|
|
9140
9159
|
try {
|
|
9141
|
-
report = JSON.parse(
|
|
9160
|
+
report = JSON.parse(readFileSync31(reportFile, "utf8"));
|
|
9142
9161
|
} catch {
|
|
9143
9162
|
report = void 0;
|
|
9144
9163
|
}
|
|
@@ -9191,9 +9210,9 @@ function registerTest() {
|
|
|
9191
9210
|
|
|
9192
9211
|
// src/roles/typescript/adapters/tsc/tsc.adapter.ts
|
|
9193
9212
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
9194
|
-
import { existsSync as existsSync32, readFileSync as
|
|
9213
|
+
import { existsSync as existsSync32, readFileSync as readFileSync33 } from "node:fs";
|
|
9195
9214
|
import { createRequire as createRequire7 } from "node:module";
|
|
9196
|
-
import { join as
|
|
9215
|
+
import { join as join41 } from "node:path";
|
|
9197
9216
|
|
|
9198
9217
|
// src/roles/typescript/presets/nest.json
|
|
9199
9218
|
var nest_default2 = {
|
|
@@ -9374,8 +9393,8 @@ function readTsconfigAdoption(cwd) {
|
|
|
9374
9393
|
}
|
|
9375
9394
|
|
|
9376
9395
|
// src/roles/typescript/adapters/tsc/plan.ts
|
|
9377
|
-
import { readFileSync as
|
|
9378
|
-
import { join as
|
|
9396
|
+
import { readFileSync as readFileSync32 } from "node:fs";
|
|
9397
|
+
import { join as join40 } from "node:path";
|
|
9379
9398
|
|
|
9380
9399
|
// src/roles/typescript/typecheck-script.ts
|
|
9381
9400
|
var SENTINEL_TYPECHECK_COMMAND = "sentinel --run --typescript";
|
|
@@ -9468,7 +9487,7 @@ function planAdoption(context) {
|
|
|
9468
9487
|
};
|
|
9469
9488
|
}
|
|
9470
9489
|
const existing = parseJsonc(
|
|
9471
|
-
|
|
9490
|
+
readFileSync32(join40(context.cwd, target.path), "utf8"),
|
|
9472
9491
|
target.path
|
|
9473
9492
|
);
|
|
9474
9493
|
const extendsChain = composeExtends(existing.extends, preset);
|
|
@@ -9606,7 +9625,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
9606
9625
|
let chain;
|
|
9607
9626
|
try {
|
|
9608
9627
|
const parsed = parseJsonc(
|
|
9609
|
-
|
|
9628
|
+
readFileSync33(join41(cwd, target.path), "utf8"),
|
|
9610
9629
|
target.path
|
|
9611
9630
|
);
|
|
9612
9631
|
chain = parsed.extends;
|
|
@@ -9619,7 +9638,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
9619
9638
|
);
|
|
9620
9639
|
if (preset === void 0) return void 0;
|
|
9621
9640
|
try {
|
|
9622
|
-
createRequire7(
|
|
9641
|
+
createRequire7(join41(cwd, "noop.js")).resolve(preset);
|
|
9623
9642
|
return void 0;
|
|
9624
9643
|
} catch {
|
|
9625
9644
|
return preset;
|
|
@@ -9715,7 +9734,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
9715
9734
|
referencedProjects(cwd, config) {
|
|
9716
9735
|
try {
|
|
9717
9736
|
const parsed = parseJsonc(
|
|
9718
|
-
|
|
9737
|
+
readFileSync33(join41(cwd, config), "utf8"),
|
|
9719
9738
|
config
|
|
9720
9739
|
);
|
|
9721
9740
|
const referenced = (parsed.references ?? []).map((reference) => reference.path).filter((path) => typeof path === "string" && path.length > 0);
|
|
@@ -9731,7 +9750,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
9731
9750
|
* check.
|
|
9732
9751
|
*/
|
|
9733
9752
|
typecheckTarget(cwd) {
|
|
9734
|
-
if (existsSync32(
|
|
9753
|
+
if (existsSync32(join41(cwd, "tsconfig.json"))) return "tsconfig.json";
|
|
9735
9754
|
const target = resolveTsconfigTarget(cwd);
|
|
9736
9755
|
return target.reason === "none" ? null : target.path;
|
|
9737
9756
|
}
|
|
@@ -9936,7 +9955,7 @@ function replaceLines(current, replacements) {
|
|
|
9936
9955
|
}
|
|
9937
9956
|
|
|
9938
9957
|
// src/core/apply-plan.ts
|
|
9939
|
-
import { existsSync as existsSync33, readFileSync as
|
|
9958
|
+
import { existsSync as existsSync33, readFileSync as readFileSync34, renameSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
9940
9959
|
import { resolve as resolve7, sep } from "node:path";
|
|
9941
9960
|
import { applyEdits as applyEdits3, findNodeAtLocation, modify, parseTree } from "jsonc-parser";
|
|
9942
9961
|
|
|
@@ -9955,7 +9974,7 @@ function resolveWithinRoot(cwd, relativePath) {
|
|
|
9955
9974
|
return absolutePath;
|
|
9956
9975
|
}
|
|
9957
9976
|
function readIfExists(absolutePath) {
|
|
9958
|
-
return existsSync33(absolutePath) ?
|
|
9977
|
+
return existsSync33(absolutePath) ? readFileSync34(absolutePath, "utf8") : void 0;
|
|
9959
9978
|
}
|
|
9960
9979
|
function* leaves(value, prefix = []) {
|
|
9961
9980
|
for (const [key, keyValue] of Object.entries(value)) {
|
|
@@ -10073,8 +10092,8 @@ function applyPlan(cwd, plan4) {
|
|
|
10073
10092
|
}
|
|
10074
10093
|
|
|
10075
10094
|
// src/core/config/preset-evidence.ts
|
|
10076
|
-
import { existsSync as existsSync34, readdirSync as readdirSync9, readFileSync as
|
|
10077
|
-
import { join as
|
|
10095
|
+
import { existsSync as existsSync34, readdirSync as readdirSync9, readFileSync as readFileSync35 } from "node:fs";
|
|
10096
|
+
import { join as join42 } from "node:path";
|
|
10078
10097
|
var PATH_SIGNALS = [
|
|
10079
10098
|
{
|
|
10080
10099
|
preset: "nest",
|
|
@@ -10108,12 +10127,12 @@ function sourceImports(cwd, pattern) {
|
|
|
10108
10127
|
}
|
|
10109
10128
|
for (const entry of entries) {
|
|
10110
10129
|
if (entry.isDirectory()) {
|
|
10111
|
-
if (!NOT_SCANNED.has(entry.name)) stack.push(
|
|
10130
|
+
if (!NOT_SCANNED.has(entry.name)) stack.push(join42(dir, entry.name));
|
|
10112
10131
|
continue;
|
|
10113
10132
|
}
|
|
10114
10133
|
if (!SOURCE_FILE2.test(entry.name)) continue;
|
|
10115
10134
|
try {
|
|
10116
|
-
if (pattern.test(
|
|
10135
|
+
if (pattern.test(readFileSync35(join42(dir, entry.name), "utf8"))) return true;
|
|
10117
10136
|
} catch {
|
|
10118
10137
|
continue;
|
|
10119
10138
|
}
|
|
@@ -10122,11 +10141,11 @@ function sourceImports(cwd, pattern) {
|
|
|
10122
10141
|
return false;
|
|
10123
10142
|
}
|
|
10124
10143
|
function dependencyNames(cwd) {
|
|
10125
|
-
const path =
|
|
10144
|
+
const path = join42(cwd, "package.json");
|
|
10126
10145
|
if (!existsSync34(path)) return [];
|
|
10127
10146
|
try {
|
|
10128
10147
|
const manifest = parseJsonc(
|
|
10129
|
-
|
|
10148
|
+
readFileSync35(path, "utf8"),
|
|
10130
10149
|
path
|
|
10131
10150
|
);
|
|
10132
10151
|
return [
|
|
@@ -10149,7 +10168,7 @@ function declaresJsx(cwd) {
|
|
|
10149
10168
|
for (const name of entries) {
|
|
10150
10169
|
try {
|
|
10151
10170
|
const config = parseJsonc(
|
|
10152
|
-
|
|
10171
|
+
readFileSync35(join42(cwd, name), "utf8"),
|
|
10153
10172
|
name
|
|
10154
10173
|
);
|
|
10155
10174
|
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.21",
|
|
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",
|