@hublo/sentinel 1.4.0-alpha.5 → 1.4.0-alpha.7
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
CHANGED
|
@@ -5404,7 +5404,7 @@ function registerLint() {
|
|
|
5404
5404
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
5405
5405
|
import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync30 } from "fs";
|
|
5406
5406
|
import { tmpdir as tmpdir2 } from "os";
|
|
5407
|
-
import { join as join37 } from "path";
|
|
5407
|
+
import { isAbsolute as isAbsolute3, join as join37, resolve as resolve6 } from "path";
|
|
5408
5408
|
|
|
5409
5409
|
// src/roles/test/presets/toolchain.json
|
|
5410
5410
|
var toolchain_default2 = {
|
|
@@ -5611,6 +5611,17 @@ function readTestAdoption(cwd) {
|
|
|
5611
5611
|
};
|
|
5612
5612
|
}
|
|
5613
5613
|
|
|
5614
|
+
// src/roles/test/support-file-name.ts
|
|
5615
|
+
var JEST_PREFIX = "jest.";
|
|
5616
|
+
var VITEST_PREFIX = "vitest.";
|
|
5617
|
+
function vitestSupportName(relative7) {
|
|
5618
|
+
const cut = relative7.lastIndexOf("/");
|
|
5619
|
+
const directory = cut === -1 ? "" : relative7.slice(0, cut + 1);
|
|
5620
|
+
const base = relative7.slice(cut + 1);
|
|
5621
|
+
if (!base.startsWith(JEST_PREFIX)) return relative7;
|
|
5622
|
+
return `${directory}${VITEST_PREFIX}${base.slice(JEST_PREFIX.length)}`;
|
|
5623
|
+
}
|
|
5624
|
+
|
|
5614
5625
|
// src/roles/test/codemod/migrate-file.ts
|
|
5615
5626
|
import { parseSync as parseSync7 } from "oxc-parser";
|
|
5616
5627
|
|
|
@@ -7571,7 +7582,9 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
7571
7582
|
continue;
|
|
7572
7583
|
}
|
|
7573
7584
|
const migrated = migrateTestFile(join31(cwd, relative7), source, defaultImported);
|
|
7574
|
-
|
|
7585
|
+
const renamedTo = vitestSupportName(relative7);
|
|
7586
|
+
if (!migrated.changed && renamedTo === relative7) continue;
|
|
7587
|
+
if (renamedTo !== relative7) operations.push({ kind: "delete", path: relative7 });
|
|
7575
7588
|
const before = parse3(source);
|
|
7576
7589
|
const after = parse3(migrated.source);
|
|
7577
7590
|
if (before !== void 0 && after !== void 0) {
|
|
@@ -7582,7 +7595,7 @@ function migrateModuleTests(cwd, setupFiles = []) {
|
|
|
7582
7595
|
}
|
|
7583
7596
|
files++;
|
|
7584
7597
|
renamed += migrated.renamed;
|
|
7585
|
-
operations.push({ kind: "write", path:
|
|
7598
|
+
operations.push({ kind: "write", path: renamedTo, contents: migrated.source });
|
|
7586
7599
|
}
|
|
7587
7600
|
for (const relative7 of listTestFiles(cwd)) {
|
|
7588
7601
|
const source = read2(join31(cwd, relative7));
|
|
@@ -7704,11 +7717,11 @@ function ownsMswLifecycle(cwd, reading) {
|
|
|
7704
7717
|
function setupBlock(cwd, reading, msw) {
|
|
7705
7718
|
const declared = [...reading.setupFiles ?? [], ...reading.setupFilesAfterEnv ?? []];
|
|
7706
7719
|
const namedTheRootSetup = declared.some((file) => file.endsWith("jest.setup.after.env.js"));
|
|
7707
|
-
const own = declared.filter((file) => !file.endsWith("jest.setup.after.env.js")).map((file) => `'${withoutRootDir(file)}'`);
|
|
7720
|
+
const own = declared.filter((file) => !file.endsWith("jest.setup.after.env.js")).map((file) => `'${vitestSupportName(withoutRootDir(file))}'`);
|
|
7708
7721
|
const sentinel = [
|
|
7709
7722
|
`'${SENTINEL_TEST_SETUP}'`,
|
|
7710
7723
|
...namedTheRootSetup ? [`'${SENTINEL_WORKSPACE_SETUP}'`] : [],
|
|
7711
|
-
...msw && !ownsMswLifecycle(cwd, reading) ? [`'${SENTINEL_MSW_SETUP}'`] : []
|
|
7724
|
+
...msw && namedTheRootSetup && !ownsMswLifecycle(cwd, reading) ? [`'${SENTINEL_MSW_SETUP}'`] : []
|
|
7712
7725
|
];
|
|
7713
7726
|
return ` setupFiles: [${[...sentinel, ...own].join(", ")}],`;
|
|
7714
7727
|
}
|
|
@@ -7735,7 +7748,7 @@ function timeoutBlock(reading) {
|
|
|
7735
7748
|
}
|
|
7736
7749
|
function globalSetupBlock(reading) {
|
|
7737
7750
|
if (reading.globalSetup === void 0) return "";
|
|
7738
|
-
const files = reading.globalSetup.map((file) => `'${withoutRootDir(file)}'`).join(", ");
|
|
7751
|
+
const files = reading.globalSetup.map((file) => `'${vitestSupportName(withoutRootDir(file))}'`).join(", ");
|
|
7739
7752
|
return ` globalSetup: [${files}],`;
|
|
7740
7753
|
}
|
|
7741
7754
|
function includeBlock(reading) {
|
|
@@ -8175,17 +8188,31 @@ function specTypesOperation(cwd) {
|
|
|
8175
8188
|
return void 0;
|
|
8176
8189
|
}
|
|
8177
8190
|
const types = config?.compilerOptions?.types;
|
|
8178
|
-
|
|
8191
|
+
const include = config?.include;
|
|
8192
|
+
const rewrittenInclude = Array.isArray(include) ? rewriteSpecInclude(include) : void 0;
|
|
8193
|
+
const typesChanged = Array.isArray(types) && types.includes("jest");
|
|
8194
|
+
if (!typesChanged && rewrittenInclude === void 0) return void 0;
|
|
8179
8195
|
return {
|
|
8180
8196
|
kind: "merge-json",
|
|
8181
8197
|
path: SPEC_TSCONFIG,
|
|
8182
8198
|
value: {
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8199
|
+
...typesChanged ? {
|
|
8200
|
+
compilerOptions: {
|
|
8201
|
+
types: types.map(
|
|
8202
|
+
(entry) => entry === "jest" ? VITEST_GLOBAL_TYPES : entry
|
|
8203
|
+
)
|
|
8204
|
+
}
|
|
8205
|
+
} : {},
|
|
8206
|
+
...rewrittenInclude === void 0 ? {} : { include: rewrittenInclude }
|
|
8186
8207
|
}
|
|
8187
8208
|
};
|
|
8188
8209
|
}
|
|
8210
|
+
function rewriteSpecInclude(include) {
|
|
8211
|
+
const rewritten = include.filter((entry) => typeof entry !== "string" || !JEST_CONFIG_ENTRY.test(entry)).map((entry) => typeof entry === "string" ? vitestSupportName(entry) : entry);
|
|
8212
|
+
const unchanged = rewritten.length === include.length && rewritten.every((entry, index) => entry === include[index]);
|
|
8213
|
+
return unchanged ? void 0 : rewritten;
|
|
8214
|
+
}
|
|
8215
|
+
var JEST_CONFIG_ENTRY = /(^|\/)jest\.[\w.-]*config\.[cm]?[jt]s$/;
|
|
8189
8216
|
function siblingScriptRewrites(cwd) {
|
|
8190
8217
|
const rewrites = {};
|
|
8191
8218
|
for (const [name, command] of Object.entries(moduleScripts(cwd))) {
|
|
@@ -8820,13 +8847,16 @@ var VitestAdapter = class extends BaseAdapter {
|
|
|
8820
8847
|
`using the MODULE's vitest, not sentinel's. An adopted config gets its plugins from sentinel, and two copies fail in ways that never mention a version. Remove vitest from this module's package.json.`
|
|
8821
8848
|
);
|
|
8822
8849
|
}
|
|
8823
|
-
const { options, paths } = splitToolArgs(ctx.cwd, ctx.toolArgs, {
|
|
8850
|
+
const { options: typedOptions, paths: typedPaths } = splitToolArgs(ctx.cwd, ctx.toolArgs, {
|
|
8851
|
+
valueFlags: ["--config", "-c"]
|
|
8852
|
+
});
|
|
8853
|
+
const { cwd: runFrom, options, paths } = fromWorkspaceRoot(ctx.cwd, typedOptions, typedPaths);
|
|
8824
8854
|
const watching = options.includes("--watch") || options.includes("-w");
|
|
8825
8855
|
const proving = !watching && hasReference(ctx.cwd);
|
|
8826
8856
|
const reportFile = proving ? join37(mkdtempSync2(join37(tmpdir2(), "sentinel-run-")), "vitest.json") : void 0;
|
|
8827
8857
|
const reporters = reportFile === void 0 ? [] : ["--reporter=default", "--reporter=json", `--outputFile=${reportFile}`];
|
|
8828
8858
|
const argv = watching ? [...options, ...paths] : ["run", ...reporters, ...options, ...paths];
|
|
8829
|
-
const result = spawnSync5(bin, argv, { cwd:
|
|
8859
|
+
const result = spawnSync5(bin, argv, { cwd: runFrom, stdio: "inherit" });
|
|
8830
8860
|
if (result.error) {
|
|
8831
8861
|
this.say(`could not run vitest (${result.error.message})`);
|
|
8832
8862
|
return Promise.resolve({ ok: false, code: 1 });
|
|
@@ -8854,6 +8884,31 @@ var VitestAdapter = class extends BaseAdapter {
|
|
|
8854
8884
|
`);
|
|
8855
8885
|
}
|
|
8856
8886
|
};
|
|
8887
|
+
function fromWorkspaceRoot(moduleDir, options, paths) {
|
|
8888
|
+
const root = findWorkspaceRoot(moduleDir);
|
|
8889
|
+
if (root === void 0 || root === moduleDir) {
|
|
8890
|
+
return { cwd: moduleDir, options: [...options], paths: [...paths] };
|
|
8891
|
+
}
|
|
8892
|
+
const absolute = (value) => isAbsolute3(value) ? value : resolve6(moduleDir, value);
|
|
8893
|
+
const moved = [];
|
|
8894
|
+
let previousWasConfig = false;
|
|
8895
|
+
for (const option of options) {
|
|
8896
|
+
if (previousWasConfig) {
|
|
8897
|
+
moved.push(absolute(option));
|
|
8898
|
+
previousWasConfig = false;
|
|
8899
|
+
continue;
|
|
8900
|
+
}
|
|
8901
|
+
if (option.startsWith("--config=")) moved.push(`--config=${absolute(option.slice(9))}`);
|
|
8902
|
+
else moved.push(option);
|
|
8903
|
+
previousWasConfig = option === "--config" || option === "-c";
|
|
8904
|
+
}
|
|
8905
|
+
return {
|
|
8906
|
+
cwd: root,
|
|
8907
|
+
// `--root` LAST, so a caller cannot be silently overridden by our own flag.
|
|
8908
|
+
options: [...moved, "--root", moduleDir],
|
|
8909
|
+
paths: paths.map((path) => absolute(path))
|
|
8910
|
+
};
|
|
8911
|
+
}
|
|
8857
8912
|
|
|
8858
8913
|
// src/roles/test/register.ts
|
|
8859
8914
|
function registerTest() {
|
|
@@ -9609,7 +9664,7 @@ function replaceLines(current, replacements) {
|
|
|
9609
9664
|
|
|
9610
9665
|
// src/core/apply-plan.ts
|
|
9611
9666
|
import { existsSync as existsSync32, readFileSync as readFileSync33, renameSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
9612
|
-
import { resolve as
|
|
9667
|
+
import { resolve as resolve7, sep } from "path";
|
|
9613
9668
|
import { applyEdits as applyEdits3, findNodeAtLocation, modify, parseTree } from "jsonc-parser";
|
|
9614
9669
|
|
|
9615
9670
|
// src/shared/deep-merge.ts
|
|
@@ -9619,8 +9674,8 @@ function isPlainObject(value) {
|
|
|
9619
9674
|
|
|
9620
9675
|
// src/core/apply-plan.ts
|
|
9621
9676
|
function resolveWithinRoot(cwd, relativePath) {
|
|
9622
|
-
const root =
|
|
9623
|
-
const absolutePath =
|
|
9677
|
+
const root = resolve7(cwd);
|
|
9678
|
+
const absolutePath = resolve7(root, relativePath);
|
|
9624
9679
|
if (absolutePath !== root && !absolutePath.startsWith(root + sep)) {
|
|
9625
9680
|
throw new Error(`Refusing to write outside the module root: "${relativePath}".`);
|
|
9626
9681
|
}
|
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.7",
|
|
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",
|