@hublo/sentinel 1.7.0-alpha.2 → 1.7.0-alpha.4
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 +15 -6
- package/dist/{chunk-EETHWJBF.js → chunk-CTSBAGVM.js} +85 -179
- package/dist/chunk-ETVNZUU4.js +288 -0
- package/dist/{chunk-Z3JI7ZWX.js → chunk-P6KTBQ2Q.js} +66 -324
- package/dist/chunk-ZFG6P27V.js +313 -0
- package/dist/index.js +4 -3
- package/dist/{migrate-NI33SXZD.js → migrate-W5VLHDT5.js} +39 -88
- package/dist/{validate-LRHF63AW.js → validate-4V3EGTXN.js} +2 -2
- package/docs/typescript-adoption.md +21 -1
- package/package.json +1 -1
- package/dist/chunk-4UUL4SEW.js +0 -50
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
binFromOwnInstall,
|
|
3
3
|
binSearchPath,
|
|
4
|
-
resolveBin
|
|
5
|
-
|
|
4
|
+
resolveBin,
|
|
5
|
+
writtenFileFormatter
|
|
6
|
+
} from "./chunk-ZFG6P27V.js";
|
|
6
7
|
import {
|
|
7
8
|
DEFAULT_MAX_DIAGNOSTICS,
|
|
8
9
|
WORKSPACE_ROOT_MARKER,
|
|
@@ -778,9 +779,9 @@ function resolveVitest(cwd) {
|
|
|
778
779
|
|
|
779
780
|
// src/roles/test/adapters/vitest/vitest.adapter.ts
|
|
780
781
|
import { spawnSync } from "node:child_process";
|
|
781
|
-
import { existsSync as
|
|
782
|
+
import { existsSync as existsSync22, mkdtempSync as mkdtempSync3, readFileSync as readFileSync23, writeFileSync as writeFileSync2 } from "node:fs";
|
|
782
783
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
783
|
-
import { isAbsolute as isAbsolute2, join as
|
|
784
|
+
import { isAbsolute as isAbsolute2, join as join28, relative as relative7, resolve as resolve10 } from "node:path";
|
|
784
785
|
|
|
785
786
|
// src/roles/test/ordering-is-a-permutation.ts
|
|
786
787
|
function isAnImport(line) {
|
|
@@ -970,9 +971,9 @@ function rewriteToolchainImports(toolchain, source, fileName) {
|
|
|
970
971
|
}
|
|
971
972
|
|
|
972
973
|
// src/roles/test/jest-migration.ts
|
|
973
|
-
import { existsSync as
|
|
974
|
-
import { createRequire as
|
|
975
|
-
import { dirname as
|
|
974
|
+
import { existsSync as existsSync16, readFileSync as readFileSync18, readdirSync as readdirSync6 } from "node:fs";
|
|
975
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
976
|
+
import { dirname as dirname9, join as join21, relative as relative6 } from "node:path";
|
|
976
977
|
|
|
977
978
|
// src/roles/test/codemod/migrate-module.ts
|
|
978
979
|
import { readdirSync as readdirSync4, readFileSync as readFileSync15, statSync as statSync5 } from "node:fs";
|
|
@@ -5134,260 +5135,16 @@ function runModes(cwd, fallback) {
|
|
|
5134
5135
|
);
|
|
5135
5136
|
}
|
|
5136
5137
|
|
|
5137
|
-
// src/roles/test/written-file-formatter.ts
|
|
5138
|
-
import { existsSync as existsSync17 } from "node:fs";
|
|
5139
|
-
import { dirname as dirname10, join as join23 } from "node:path";
|
|
5140
|
-
|
|
5141
|
-
// src/roles/format/read-adoption.ts
|
|
5142
|
-
import { existsSync as existsSync16, readFileSync as readFileSync18 } from "node:fs";
|
|
5143
|
-
import { join as join21 } from "node:path";
|
|
5144
|
-
|
|
5145
|
-
// src/roles/format/config-policy.ts
|
|
5146
|
-
var FORMAT_CONFIG_FILE = ".oxfmtrc.json";
|
|
5147
|
-
var FORMAT_SCRIPT_NAME = "format";
|
|
5148
|
-
var PROVENANCE_KEY = "$sentinel";
|
|
5149
|
-
var PERMITTED_LOCAL_KEYS = [
|
|
5150
|
-
"useTabs",
|
|
5151
|
-
"tabWidth",
|
|
5152
|
-
"printWidth",
|
|
5153
|
-
"semi",
|
|
5154
|
-
"singleQuote",
|
|
5155
|
-
"jsxSingleQuote",
|
|
5156
|
-
"trailingComma",
|
|
5157
|
-
"quoteProps",
|
|
5158
|
-
"bracketSpacing",
|
|
5159
|
-
"bracketSameLine",
|
|
5160
|
-
"arrowParens",
|
|
5161
|
-
"endOfLine",
|
|
5162
|
-
"objectWrap",
|
|
5163
|
-
"proseWrap",
|
|
5164
|
-
"experimentalOperatorPosition"
|
|
5165
|
-
];
|
|
5166
|
-
var ALWAYS_LOCAL_KEYS = ["ignorePatterns", "overrides"];
|
|
5167
|
-
var OWNED_WHEN_SET_KEYS = ["sortImports"];
|
|
5168
|
-
var FORMAT_DEFAULT_IGNORES = ["**/*.toml"];
|
|
5169
|
-
var PRETTIER_CONFIG_FILES = [
|
|
5170
|
-
".prettierrc",
|
|
5171
|
-
".prettierrc.json",
|
|
5172
|
-
".prettierrc.json5",
|
|
5173
|
-
".prettierrc.yml",
|
|
5174
|
-
".prettierrc.yaml",
|
|
5175
|
-
".prettierrc.js",
|
|
5176
|
-
".prettierrc.cjs",
|
|
5177
|
-
".prettierrc.mjs",
|
|
5178
|
-
"prettier.config.js",
|
|
5179
|
-
"prettier.config.cjs",
|
|
5180
|
-
"prettier.config.mjs"
|
|
5181
|
-
];
|
|
5182
|
-
function formatTargets() {
|
|
5183
|
-
return {
|
|
5184
|
-
[FORMAT_SCRIPT_NAME]: {
|
|
5185
|
-
cache: true,
|
|
5186
|
-
inputs: ["default", `{projectRoot}/${FORMAT_CONFIG_FILE}`]
|
|
5187
|
-
},
|
|
5188
|
-
[`${FORMAT_SCRIPT_NAME}:fix`]: { cache: false }
|
|
5189
|
-
};
|
|
5190
|
-
}
|
|
5191
|
-
|
|
5192
|
-
// src/roles/format/presets/base.json
|
|
5193
|
-
var base_default = {
|
|
5194
|
-
printWidth: 80,
|
|
5195
|
-
semi: false,
|
|
5196
|
-
singleQuote: true,
|
|
5197
|
-
trailingComma: "all",
|
|
5198
|
-
sortPackageJson: false,
|
|
5199
|
-
sortImports: false
|
|
5200
|
-
};
|
|
5201
|
-
|
|
5202
|
-
// src/roles/format/presets/nest-imports.json
|
|
5203
|
-
var nest_imports_default = {
|
|
5204
|
-
customGroups: [
|
|
5205
|
-
{
|
|
5206
|
-
groupName: "workspace",
|
|
5207
|
-
elementNamePattern: ["@hublo/**", "@shared/**", "@front/**", "@network/**"]
|
|
5208
|
-
}
|
|
5209
|
-
],
|
|
5210
|
-
groups: ["builtin", "external", "workspace", ["parent", "index"], "sibling"],
|
|
5211
|
-
newlinesBetween: true,
|
|
5212
|
-
order: "asc",
|
|
5213
|
-
ignoreCase: false
|
|
5214
|
-
};
|
|
5215
|
-
|
|
5216
|
-
// src/roles/format/preset-data.ts
|
|
5217
|
-
var FORMAT_PRESETS = ["base", "svelte", "nest"];
|
|
5218
|
-
function hasFormatPreset(name) {
|
|
5219
|
-
return FORMAT_PRESETS.includes(name);
|
|
5220
|
-
}
|
|
5221
|
-
function formatPresetName(declared) {
|
|
5222
|
-
if (declared === "svelte") return "svelte";
|
|
5223
|
-
if (declared === "nest") return "nest";
|
|
5224
|
-
return "base";
|
|
5225
|
-
}
|
|
5226
|
-
function formatPresetFor(preset) {
|
|
5227
|
-
const base = base_default;
|
|
5228
|
-
const name = formatPresetName(preset);
|
|
5229
|
-
if (name === "svelte") return { ...base, svelte: true };
|
|
5230
|
-
if (name === "nest") return { ...base, sortImports: nest_imports_default };
|
|
5231
|
-
return base;
|
|
5232
|
-
}
|
|
5233
|
-
|
|
5234
|
-
// src/roles/format/read-adoption.ts
|
|
5235
|
-
var NOT_ADOPTED = (configFile, unreadable = null) => ({
|
|
5236
|
-
configFile,
|
|
5237
|
-
preset: null,
|
|
5238
|
-
adopted: false,
|
|
5239
|
-
conformant: false,
|
|
5240
|
-
drift: [],
|
|
5241
|
-
local: {},
|
|
5242
|
-
presetVersion: null,
|
|
5243
|
-
effective: {},
|
|
5244
|
-
unreadable
|
|
5245
|
-
});
|
|
5246
|
-
function sameValue(a, b) {
|
|
5247
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
5248
|
-
}
|
|
5249
|
-
function readFormatAdoption(cwd) {
|
|
5250
|
-
const path = join21(cwd, FORMAT_CONFIG_FILE);
|
|
5251
|
-
if (!existsSync16(path)) return NOT_ADOPTED(null);
|
|
5252
|
-
let parsed;
|
|
5253
|
-
try {
|
|
5254
|
-
parsed = parseJsonc(readFileSync18(path, "utf8"), FORMAT_CONFIG_FILE);
|
|
5255
|
-
} catch (error) {
|
|
5256
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
5257
|
-
return NOT_ADOPTED(FORMAT_CONFIG_FILE, `${FORMAT_CONFIG_FILE} could not be parsed (${reason})`);
|
|
5258
|
-
}
|
|
5259
|
-
const provenance = parsed[PROVENANCE_KEY];
|
|
5260
|
-
if (!provenance || typeof provenance.preset !== "string") return NOT_ADOPTED(FORMAT_CONFIG_FILE);
|
|
5261
|
-
if (!hasFormatPreset(provenance.preset)) {
|
|
5262
|
-
return NOT_ADOPTED(
|
|
5263
|
-
FORMAT_CONFIG_FILE,
|
|
5264
|
-
`${FORMAT_CONFIG_FILE} declares the format preset "${provenance.preset}", which sentinel does not ship (shipped: ${FORMAT_PRESETS.join(", ")}). Re-run \`sentinel --init --format\`.`
|
|
5265
|
-
);
|
|
5266
|
-
}
|
|
5267
|
-
const declaredLocal = Array.isArray(provenance.local) ? provenance.local : [];
|
|
5268
|
-
const preset = formatPresetFor(provenance.preset);
|
|
5269
|
-
const drift = [];
|
|
5270
|
-
const local = {};
|
|
5271
|
-
for (const [key, expected] of Object.entries(preset)) {
|
|
5272
|
-
if (declaredLocal.includes(key)) {
|
|
5273
|
-
local[key] = parsed[key];
|
|
5274
|
-
continue;
|
|
5275
|
-
}
|
|
5276
|
-
if (!(key in parsed) || !sameValue(parsed[key], expected)) drift.push(key);
|
|
5277
|
-
}
|
|
5278
|
-
for (const key of declaredLocal) {
|
|
5279
|
-
if (!(key in preset)) local[key] = parsed[key];
|
|
5280
|
-
}
|
|
5281
|
-
for (const key of ALWAYS_LOCAL_KEYS) {
|
|
5282
|
-
if (key in parsed) local[key] = parsed[key];
|
|
5283
|
-
}
|
|
5284
|
-
return {
|
|
5285
|
-
configFile: FORMAT_CONFIG_FILE,
|
|
5286
|
-
preset: provenance.preset,
|
|
5287
|
-
adopted: true,
|
|
5288
|
-
conformant: drift.length === 0,
|
|
5289
|
-
drift,
|
|
5290
|
-
local,
|
|
5291
|
-
presetVersion: typeof provenance.version === "string" ? provenance.version : null,
|
|
5292
|
-
effective: parsed,
|
|
5293
|
-
unreadable: null
|
|
5294
|
-
};
|
|
5295
|
-
}
|
|
5296
|
-
|
|
5297
|
-
// src/roles/format/resolve-oxfmt.ts
|
|
5298
|
-
import { readFileSync as readFileSync19 } from "node:fs";
|
|
5299
|
-
import { createRequire as createRequire3 } from "node:module";
|
|
5300
|
-
import { dirname as dirname9, join as join22 } from "node:path";
|
|
5301
|
-
function resolveOxfmt(cwd) {
|
|
5302
|
-
return resolveBin(cwd, "oxfmt") ?? binFromOwnInstall("oxfmt", "oxfmt");
|
|
5303
|
-
}
|
|
5304
|
-
function oxfmtRejects(key, value) {
|
|
5305
|
-
const schema = configSchema();
|
|
5306
|
-
const property = schema?.properties?.[key];
|
|
5307
|
-
if (!property) return false;
|
|
5308
|
-
const definition = resolveRef(schema, property);
|
|
5309
|
-
if (Array.isArray(definition.enum)) return !definition.enum.includes(value);
|
|
5310
|
-
if (definition.type === "boolean") return typeof value !== "boolean";
|
|
5311
|
-
if (definition.type === "integer" || definition.type === "number")
|
|
5312
|
-
return typeof value !== "number";
|
|
5313
|
-
return false;
|
|
5314
|
-
}
|
|
5315
|
-
function resolveRef(schema, node) {
|
|
5316
|
-
const ref = node.$ref ?? node.allOf?.[0]?.$ref;
|
|
5317
|
-
const name = ref?.startsWith("#/definitions/") ? ref.slice("#/definitions/".length) : void 0;
|
|
5318
|
-
return (name ? schema.definitions?.[name] : void 0) ?? node;
|
|
5319
|
-
}
|
|
5320
|
-
var cachedSchema;
|
|
5321
|
-
function configSchema() {
|
|
5322
|
-
if (cachedSchema !== void 0) return cachedSchema ?? void 0;
|
|
5323
|
-
cachedSchema = readConfigSchema() ?? null;
|
|
5324
|
-
return cachedSchema ?? void 0;
|
|
5325
|
-
}
|
|
5326
|
-
function readConfigSchema() {
|
|
5327
|
-
try {
|
|
5328
|
-
const manifest = createRequire3(import.meta.url).resolve("oxfmt/package.json");
|
|
5329
|
-
const schemaPath = join22(dirname9(manifest), "configuration_schema.json");
|
|
5330
|
-
return JSON.parse(readFileSync19(schemaPath, "utf8"));
|
|
5331
|
-
} catch {
|
|
5332
|
-
return void 0;
|
|
5333
|
-
}
|
|
5334
|
-
}
|
|
5335
|
-
|
|
5336
|
-
// src/roles/test/written-file-formatter.ts
|
|
5337
|
-
var PRETTIER_CONFIGS = [
|
|
5338
|
-
".prettierrc",
|
|
5339
|
-
".prettierrc.json",
|
|
5340
|
-
".prettierrc.json5",
|
|
5341
|
-
".prettierrc.yaml",
|
|
5342
|
-
".prettierrc.yml",
|
|
5343
|
-
".prettierrc.js",
|
|
5344
|
-
".prettierrc.cjs",
|
|
5345
|
-
".prettierrc.mjs",
|
|
5346
|
-
".prettierrc.toml",
|
|
5347
|
-
"prettier.config.js",
|
|
5348
|
-
"prettier.config.cjs",
|
|
5349
|
-
"prettier.config.mjs"
|
|
5350
|
-
];
|
|
5351
|
-
function prettierConfigFrom(cwd) {
|
|
5352
|
-
let dir = cwd;
|
|
5353
|
-
for (; ; ) {
|
|
5354
|
-
for (const name of PRETTIER_CONFIGS) {
|
|
5355
|
-
if (existsSync17(join23(dir, name))) return join23(dir, name);
|
|
5356
|
-
}
|
|
5357
|
-
const parent = dirname10(dir);
|
|
5358
|
-
if (parent === dir) return void 0;
|
|
5359
|
-
dir = parent;
|
|
5360
|
-
}
|
|
5361
|
-
}
|
|
5362
|
-
function writtenFileFormatter(cwd) {
|
|
5363
|
-
if (readFormatAdoption(cwd).configFile !== null) {
|
|
5364
|
-
const oxfmt = resolveOxfmt(cwd);
|
|
5365
|
-
if (oxfmt !== void 0) {
|
|
5366
|
-
return { bin: oxfmt, args: ["--write"], origin: "this module's own oxfmt config" };
|
|
5367
|
-
}
|
|
5368
|
-
}
|
|
5369
|
-
const config = prettierConfigFrom(cwd);
|
|
5370
|
-
const prettier = resolveBin(cwd, "prettier");
|
|
5371
|
-
if (config !== void 0 && prettier !== void 0) {
|
|
5372
|
-
return {
|
|
5373
|
-
bin: prettier,
|
|
5374
|
-
args: ["--write", "--log-level", "warn"],
|
|
5375
|
-
origin: `the workspace's Prettier`
|
|
5376
|
-
};
|
|
5377
|
-
}
|
|
5378
|
-
return void 0;
|
|
5379
|
-
}
|
|
5380
|
-
|
|
5381
5138
|
// src/roles/test/jest-migration.ts
|
|
5382
5139
|
var SPEC_TSCONFIG = "tsconfig.spec.json";
|
|
5383
5140
|
var VITEST_GLOBAL_TYPES = "vitest/globals";
|
|
5384
5141
|
function specTypesOperation(cwd) {
|
|
5385
|
-
const path =
|
|
5386
|
-
if (!
|
|
5142
|
+
const path = join21(cwd, SPEC_TSCONFIG);
|
|
5143
|
+
if (!existsSync16(path)) return void 0;
|
|
5387
5144
|
let config;
|
|
5388
5145
|
try {
|
|
5389
5146
|
config = parseJsonc(
|
|
5390
|
-
|
|
5147
|
+
readFileSync18(path, "utf8"),
|
|
5391
5148
|
SPEC_TSCONFIG
|
|
5392
5149
|
);
|
|
5393
5150
|
} catch {
|
|
@@ -5406,12 +5163,12 @@ function specTypesOperation(cwd) {
|
|
|
5406
5163
|
};
|
|
5407
5164
|
}
|
|
5408
5165
|
function specTypesCleanupOperation(cwd) {
|
|
5409
|
-
const path =
|
|
5410
|
-
if (!
|
|
5166
|
+
const path = join21(cwd, SPEC_TSCONFIG);
|
|
5167
|
+
if (!existsSync16(path)) return void 0;
|
|
5411
5168
|
let config;
|
|
5412
5169
|
try {
|
|
5413
5170
|
config = parseJsonc(
|
|
5414
|
-
|
|
5171
|
+
readFileSync18(path, "utf8"),
|
|
5415
5172
|
SPEC_TSCONFIG
|
|
5416
5173
|
);
|
|
5417
5174
|
} catch {
|
|
@@ -5429,9 +5186,9 @@ function specTypesCleanupOperation(cwd) {
|
|
|
5429
5186
|
}
|
|
5430
5187
|
function shippedTypesPath(cwd, declaration) {
|
|
5431
5188
|
try {
|
|
5432
|
-
const manifest =
|
|
5433
|
-
const file =
|
|
5434
|
-
if (
|
|
5189
|
+
const manifest = createRequire3(join21(cwd, "noop.cjs")).resolve("@hublo/sentinel/package.json");
|
|
5190
|
+
const file = join21(dirname9(manifest), declaration);
|
|
5191
|
+
if (existsSync16(file)) {
|
|
5435
5192
|
const path = relative6(cwd, file);
|
|
5436
5193
|
return path.startsWith(".") ? path : `./${path}`;
|
|
5437
5194
|
}
|
|
@@ -5450,7 +5207,7 @@ function helpersStillCallingJest(cwd) {
|
|
|
5450
5207
|
return;
|
|
5451
5208
|
}
|
|
5452
5209
|
for (const entry of entries) {
|
|
5453
|
-
const path =
|
|
5210
|
+
const path = join21(dir, entry.name);
|
|
5454
5211
|
if (entry.isDirectory()) {
|
|
5455
5212
|
if (!skip.has(entry.name)) walk2(path);
|
|
5456
5213
|
continue;
|
|
@@ -5460,7 +5217,7 @@ function helpersStillCallingJest(cwd) {
|
|
|
5460
5217
|
if (/^(jest|vitest)\./.test(entry.name)) continue;
|
|
5461
5218
|
let source;
|
|
5462
5219
|
try {
|
|
5463
|
-
source =
|
|
5220
|
+
source = readFileSync18(path, "utf8");
|
|
5464
5221
|
} catch {
|
|
5465
5222
|
continue;
|
|
5466
5223
|
}
|
|
@@ -5497,7 +5254,7 @@ function tsconfigFileListOperations(cwd) {
|
|
|
5497
5254
|
let config;
|
|
5498
5255
|
try {
|
|
5499
5256
|
config = parseJsonc(
|
|
5500
|
-
|
|
5257
|
+
readFileSync18(join21(cwd, name), "utf8"),
|
|
5501
5258
|
name
|
|
5502
5259
|
);
|
|
5503
5260
|
} catch {
|
|
@@ -5912,12 +5669,12 @@ function plan(context) {
|
|
|
5912
5669
|
}
|
|
5913
5670
|
|
|
5914
5671
|
// src/roles/test/written-file-linter.ts
|
|
5915
|
-
import { existsSync as
|
|
5916
|
-
import { join as
|
|
5672
|
+
import { existsSync as existsSync21 } from "node:fs";
|
|
5673
|
+
import { join as join27 } from "node:path";
|
|
5917
5674
|
|
|
5918
5675
|
// src/roles/lint/module-baseline.ts
|
|
5919
|
-
import { existsSync as
|
|
5920
|
-
import { join as
|
|
5676
|
+
import { existsSync as existsSync17, readFileSync as readFileSync19 } from "node:fs";
|
|
5677
|
+
import { join as join22 } from "node:path";
|
|
5921
5678
|
|
|
5922
5679
|
// src/roles/lint/oxlint-rule-owners.json
|
|
5923
5680
|
var oxlint_rule_owners_default = {
|
|
@@ -6659,10 +6416,10 @@ function describeHolds(holds) {
|
|
|
6659
6416
|
return `held ${holds.length} rule(s) at \`warn\` for this module, covering ${total} violation(s) that were already there: ${listed}${rest}. They are written to ${LINT_BASELINE_FILE}, they still report, and they return to \`error\` once fixed and re-initialized`;
|
|
6660
6417
|
}
|
|
6661
6418
|
function heldRules(cwd) {
|
|
6662
|
-
const path =
|
|
6663
|
-
if (!
|
|
6419
|
+
const path = join22(cwd, LINT_BASELINE_FILE);
|
|
6420
|
+
if (!existsSync17(path)) return [];
|
|
6664
6421
|
try {
|
|
6665
|
-
const parsed = parseJsonc(
|
|
6422
|
+
const parsed = parseJsonc(readFileSync19(path, "utf8"), LINT_BASELINE_FILE);
|
|
6666
6423
|
const scoped = (parsed.overrides ?? []).flatMap((override) => Object.keys(override.rules ?? {}));
|
|
6667
6424
|
return [.../* @__PURE__ */ new Set([...Object.keys(parsed.rules ?? {}), ...scoped])];
|
|
6668
6425
|
} catch {
|
|
@@ -6698,7 +6455,7 @@ var SENTINEL_LINT_PRESET = /@hublo\/sentinel\/(?:lint|oxlint)\/([a-z-]+)\.json$/
|
|
|
6698
6455
|
function presetNameFromPath(preset) {
|
|
6699
6456
|
return preset ? SENTINEL_LINT_PRESET.exec(preset)?.[1] ?? void 0 : void 0;
|
|
6700
6457
|
}
|
|
6701
|
-
var
|
|
6458
|
+
var PERMITTED_LOCAL_KEYS = ["extends", "ignorePatterns"];
|
|
6702
6459
|
var ESLINT_CONFIG_FILES = [
|
|
6703
6460
|
"eslint.config.js",
|
|
6704
6461
|
"eslint.config.mjs",
|
|
@@ -6710,12 +6467,12 @@ function lintTarget() {
|
|
|
6710
6467
|
}
|
|
6711
6468
|
|
|
6712
6469
|
// src/roles/lint/read-adoption.ts
|
|
6713
|
-
import { readFileSync as
|
|
6714
|
-
import { join as
|
|
6470
|
+
import { readFileSync as readFileSync22 } from "node:fs";
|
|
6471
|
+
import { join as join25 } from "node:path";
|
|
6715
6472
|
|
|
6716
6473
|
// src/core/config/read-adoption.ts
|
|
6717
|
-
import { existsSync as
|
|
6718
|
-
import { join as
|
|
6474
|
+
import { existsSync as existsSync19, readFileSync as readFileSync21 } from "node:fs";
|
|
6475
|
+
import { join as join24 } from "node:path";
|
|
6719
6476
|
|
|
6720
6477
|
// src/core/config/owned-keys.ts
|
|
6721
6478
|
function presetOwnedKeys(config, permitted, presetSets) {
|
|
@@ -6730,12 +6487,12 @@ function localOnlyKeys(config, permitted, presetSets) {
|
|
|
6730
6487
|
}
|
|
6731
6488
|
|
|
6732
6489
|
// src/core/config/resolve-config-target.ts
|
|
6733
|
-
import { existsSync as
|
|
6734
|
-
import { join as
|
|
6490
|
+
import { existsSync as existsSync18, readFileSync as readFileSync20 } from "node:fs";
|
|
6491
|
+
import { join as join23 } from "node:path";
|
|
6735
6492
|
function readExtends(absolutePath) {
|
|
6736
6493
|
let parsed;
|
|
6737
6494
|
try {
|
|
6738
|
-
parsed = parseJsonc(
|
|
6495
|
+
parsed = parseJsonc(readFileSync20(absolutePath, "utf8"), absolutePath);
|
|
6739
6496
|
} catch {
|
|
6740
6497
|
return [];
|
|
6741
6498
|
}
|
|
@@ -6749,8 +6506,8 @@ function resolveConfigTarget(moduleDir, { candidates, markers, fallback }) {
|
|
|
6749
6506
|
let existing;
|
|
6750
6507
|
let existingExtendsSomething = false;
|
|
6751
6508
|
for (const candidate of candidates) {
|
|
6752
|
-
const absolutePath =
|
|
6753
|
-
if (!
|
|
6509
|
+
const absolutePath = join23(moduleDir, candidate);
|
|
6510
|
+
if (!existsSync18(absolutePath)) continue;
|
|
6754
6511
|
const chain = readExtends(absolutePath);
|
|
6755
6512
|
if (existing === void 0) {
|
|
6756
6513
|
existing = candidate;
|
|
@@ -6773,7 +6530,7 @@ function normaliseExtends(value) {
|
|
|
6773
6530
|
}
|
|
6774
6531
|
return [];
|
|
6775
6532
|
}
|
|
6776
|
-
var
|
|
6533
|
+
var NOT_ADOPTED = (configFile, unreadable = null) => ({
|
|
6777
6534
|
configFile,
|
|
6778
6535
|
preset: null,
|
|
6779
6536
|
adopted: false,
|
|
@@ -6783,18 +6540,18 @@ var NOT_ADOPTED2 = (configFile, unreadable = null) => ({
|
|
|
6783
6540
|
});
|
|
6784
6541
|
function readAdoption(cwd, options) {
|
|
6785
6542
|
const target = resolveConfigTarget(cwd, options);
|
|
6786
|
-
if (target.reason === "none" || !
|
|
6787
|
-
return
|
|
6543
|
+
if (target.reason === "none" || !existsSync19(join24(cwd, target.path))) {
|
|
6544
|
+
return NOT_ADOPTED(target.reason === "none" ? null : target.path);
|
|
6788
6545
|
}
|
|
6789
6546
|
let parsed;
|
|
6790
6547
|
try {
|
|
6791
|
-
parsed = parseJsonc(
|
|
6548
|
+
parsed = parseJsonc(readFileSync21(join24(cwd, target.path), "utf8"), target.path);
|
|
6792
6549
|
} catch (error) {
|
|
6793
6550
|
const reason = error instanceof Error ? error.message : String(error);
|
|
6794
|
-
return
|
|
6551
|
+
return NOT_ADOPTED(target.path, `${target.path} could not be parsed (${reason})`);
|
|
6795
6552
|
}
|
|
6796
6553
|
const preset = normaliseExtends(parsed.extends).find((entry) => options.presetPattern.test(entry)) ?? null;
|
|
6797
|
-
if (preset === null) return
|
|
6554
|
+
if (preset === null) return NOT_ADOPTED(target.path);
|
|
6798
6555
|
const settings = options.settingsKey === null ? parsed : parsed[options.settingsKey];
|
|
6799
6556
|
const owned = presetOwnedKeys(settings, options.permitted, options.presetOwns?.(preset));
|
|
6800
6557
|
const drift = options.refineDrift !== void 0 && settings !== void 0 ? options.refineDrift(owned, settings, preset) : owned;
|
|
@@ -9454,7 +9211,7 @@ function readLintAdoption(cwd) {
|
|
|
9454
9211
|
// Drift for lint is read from the TOP-LEVEL keys beyond `extends`, so the settings the
|
|
9455
9212
|
// shared reader inspects are the config's own root rather than a nested options object.
|
|
9456
9213
|
settingsKey: null,
|
|
9457
|
-
permitted:
|
|
9214
|
+
permitted: PERMITTED_LOCAL_KEYS,
|
|
9458
9215
|
// `rules` and `overrides` are drift only when they CONFLICT with the preset, by the
|
|
9459
9216
|
// criterion a re-init keeps or drops them by: a rule the preset does not name is the
|
|
9460
9217
|
// module's addition, kept and listed by `--inspect`, not drift. A preset sentinel does not
|
|
@@ -9472,7 +9229,7 @@ function readModuleAdditions(cwd) {
|
|
|
9472
9229
|
if (preset === void 0 || adoption.configFile === null) return NO_ADDITIONS;
|
|
9473
9230
|
try {
|
|
9474
9231
|
const config = parseJsonc(
|
|
9475
|
-
|
|
9232
|
+
readFileSync22(join25(cwd, adoption.configFile), "utf8"),
|
|
9476
9233
|
adoption.configFile
|
|
9477
9234
|
);
|
|
9478
9235
|
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
@@ -9489,15 +9246,15 @@ function readModuleAdditions(cwd) {
|
|
|
9489
9246
|
}
|
|
9490
9247
|
|
|
9491
9248
|
// src/roles/lint/resolve-oxlint.ts
|
|
9492
|
-
import { existsSync as
|
|
9493
|
-
import { createRequire as
|
|
9494
|
-
import { delimiter, dirname as
|
|
9249
|
+
import { existsSync as existsSync20 } from "node:fs";
|
|
9250
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
9251
|
+
import { delimiter, dirname as dirname10, join as join26 } from "node:path";
|
|
9495
9252
|
import { fileURLToPath } from "node:url";
|
|
9496
9253
|
var PACKAGE_OF = {
|
|
9497
9254
|
oxlint: "oxlint",
|
|
9498
9255
|
tsgolint: "oxlint-tsgolint"
|
|
9499
9256
|
};
|
|
9500
|
-
var require2 =
|
|
9257
|
+
var require2 = createRequire4(import.meta.url);
|
|
9501
9258
|
function resolveOxlint(cwd, name = "oxlint") {
|
|
9502
9259
|
return resolveBin(cwd, name) ?? binFromOwnInstall(PACKAGE_OF[name], name);
|
|
9503
9260
|
}
|
|
@@ -9507,7 +9264,7 @@ function canRunTypeAware(cwd) {
|
|
|
9507
9264
|
function oxlintPath(cwd, env) {
|
|
9508
9265
|
const shim = tsgolintShim(cwd);
|
|
9509
9266
|
if (!shim) return env.PATH;
|
|
9510
|
-
return [
|
|
9267
|
+
return [dirname10(shim), env.PATH].filter(Boolean).join(delimiter);
|
|
9511
9268
|
}
|
|
9512
9269
|
function tsgolintShim(cwd) {
|
|
9513
9270
|
const fromModule = resolveBin(cwd, "tsgolint");
|
|
@@ -9515,19 +9272,19 @@ function tsgolintShim(cwd) {
|
|
|
9515
9272
|
const candidates = [];
|
|
9516
9273
|
for (const owner of ["oxlint-tsgolint", "oxlint"]) {
|
|
9517
9274
|
try {
|
|
9518
|
-
const packageDir =
|
|
9519
|
-
candidates.push(
|
|
9520
|
-
candidates.push(
|
|
9275
|
+
const packageDir = dirname10(require2.resolve(`${owner}/package.json`));
|
|
9276
|
+
candidates.push(join26(packageDir, "node_modules", ".bin", "tsgolint"));
|
|
9277
|
+
candidates.push(join26(packageDir, "..", ".bin", "tsgolint"));
|
|
9521
9278
|
} catch {
|
|
9522
9279
|
}
|
|
9523
9280
|
}
|
|
9524
9281
|
try {
|
|
9525
|
-
const ownRoot =
|
|
9526
|
-
candidates.push(
|
|
9282
|
+
const ownRoot = dirname10(require2.resolve("@hublo/sentinel/package.json"));
|
|
9283
|
+
candidates.push(join26(ownRoot, "node_modules", ".bin", "tsgolint"));
|
|
9527
9284
|
} catch {
|
|
9528
|
-
candidates.push(resolveBin(
|
|
9285
|
+
candidates.push(resolveBin(dirname10(fileURLToPath(import.meta.url)), "tsgolint") ?? "");
|
|
9529
9286
|
}
|
|
9530
|
-
return candidates.find((candidate) => candidate !== "" &&
|
|
9287
|
+
return candidates.find((candidate) => candidate !== "" && existsSync20(candidate));
|
|
9531
9288
|
}
|
|
9532
9289
|
function oxlintSearchPath(cwd) {
|
|
9533
9290
|
return binSearchPath(cwd);
|
|
@@ -9541,7 +9298,7 @@ function writtenFileLinter(cwd) {
|
|
|
9541
9298
|
return { bin: oxlint, args: ["--fix"], origin: "this module's own oxlint config" };
|
|
9542
9299
|
}
|
|
9543
9300
|
}
|
|
9544
|
-
const config = ESLINT_CONFIG_FILES.map((name) =>
|
|
9301
|
+
const config = ESLINT_CONFIG_FILES.map((name) => join27(cwd, name)).find((path) => existsSync21(path));
|
|
9545
9302
|
const eslint = resolveBin(cwd, "eslint");
|
|
9546
9303
|
if (config !== void 0 && eslint !== void 0) {
|
|
9547
9304
|
return {
|
|
@@ -9563,7 +9320,7 @@ var FORMATTABLE = /\.(m|c)?(j|t)sx?$|\.json$/;
|
|
|
9563
9320
|
var FORMAT_BATCH = 25;
|
|
9564
9321
|
function readIfPossible(path) {
|
|
9565
9322
|
try {
|
|
9566
|
-
return
|
|
9323
|
+
return readFileSync23(path, "utf8");
|
|
9567
9324
|
} catch {
|
|
9568
9325
|
return void 0;
|
|
9569
9326
|
}
|
|
@@ -9689,12 +9446,12 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9689
9446
|
const linter = writtenFileLinter(ctx.cwd);
|
|
9690
9447
|
if (linter === void 0) return;
|
|
9691
9448
|
const workspaceRoot = findWorkspaceRoot(ctx.cwd) ?? ctx.cwd;
|
|
9692
|
-
const fromRoot = (file) => relative7(workspaceRoot,
|
|
9449
|
+
const fromRoot = (file) => relative7(workspaceRoot, join28(ctx.cwd, file));
|
|
9693
9450
|
let unsettled = 0;
|
|
9694
9451
|
const reverted = [];
|
|
9695
9452
|
for (let at = 0; at < written.length; at += FORMAT_BATCH) {
|
|
9696
9453
|
const batch = written.slice(at, at + FORMAT_BATCH);
|
|
9697
|
-
const before = new Map(batch.map((file) => [file, readIfPossible(
|
|
9454
|
+
const before = new Map(batch.map((file) => [file, readIfPossible(join28(ctx.cwd, file))]));
|
|
9698
9455
|
const pass = spawnSync(linter.bin, [...linter.args, ...batch.map(fromRoot)], {
|
|
9699
9456
|
cwd: workspaceRoot,
|
|
9700
9457
|
encoding: "utf8"
|
|
@@ -9703,11 +9460,11 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9703
9460
|
for (const file of batch) {
|
|
9704
9461
|
const was = before.get(file);
|
|
9705
9462
|
if (was === void 0) continue;
|
|
9706
|
-
const now = readIfPossible(
|
|
9463
|
+
const now = readIfPossible(join28(ctx.cwd, file));
|
|
9707
9464
|
if (now === void 0 || now === was) continue;
|
|
9708
9465
|
const lost = lineLostByTheFixer(was, now);
|
|
9709
9466
|
if (lost === void 0) continue;
|
|
9710
|
-
writeFileSync2(
|
|
9467
|
+
writeFileSync2(join28(ctx.cwd, file), was);
|
|
9711
9468
|
reverted.push(`${file}: \`${lost.slice(0, 80)}\``);
|
|
9712
9469
|
}
|
|
9713
9470
|
}
|
|
@@ -9786,7 +9543,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9786
9543
|
metrics: { ..._VitestAdapter.NOTHING_TO_REPORT, error: "vitest not available" }
|
|
9787
9544
|
};
|
|
9788
9545
|
}
|
|
9789
|
-
const out =
|
|
9546
|
+
const out = join28(mkdtempSync3(join28(tmpdir3(), "sentinel-test-report-")), "vitest.json");
|
|
9790
9547
|
const { cwd: runFrom, options, env } = fromWorkspaceRoot(ctx.cwd, [], []);
|
|
9791
9548
|
const result = spawnSync(bin, ["run", ...options, "--reporter=json", `--outputFile=${out}`], {
|
|
9792
9549
|
cwd: runFrom,
|
|
@@ -9801,7 +9558,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9801
9558
|
metrics: { ..._VitestAdapter.NOTHING_TO_REPORT, error: result.error.message }
|
|
9802
9559
|
};
|
|
9803
9560
|
}
|
|
9804
|
-
if (!
|
|
9561
|
+
if (!existsSync22(out)) {
|
|
9805
9562
|
return {
|
|
9806
9563
|
ok: false,
|
|
9807
9564
|
code: 1,
|
|
@@ -9810,7 +9567,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
|
|
|
9810
9567
|
}
|
|
9811
9568
|
let parsed;
|
|
9812
9569
|
try {
|
|
9813
|
-
parsed = JSON.parse(
|
|
9570
|
+
parsed = JSON.parse(readFileSync23(out, "utf8"));
|
|
9814
9571
|
} catch {
|
|
9815
9572
|
return {
|
|
9816
9573
|
ok: false,
|
|
@@ -9934,21 +9691,7 @@ export {
|
|
|
9934
9691
|
splitToolArgs,
|
|
9935
9692
|
separateToolArgs,
|
|
9936
9693
|
nxTargetOperations,
|
|
9937
|
-
FORMAT_CONFIG_FILE,
|
|
9938
|
-
FORMAT_SCRIPT_NAME,
|
|
9939
|
-
PROVENANCE_KEY,
|
|
9940
|
-
PERMITTED_LOCAL_KEYS,
|
|
9941
|
-
ALWAYS_LOCAL_KEYS,
|
|
9942
|
-
OWNED_WHEN_SET_KEYS,
|
|
9943
|
-
FORMAT_DEFAULT_IGNORES,
|
|
9944
|
-
PRETTIER_CONFIG_FILES,
|
|
9945
|
-
formatTargets,
|
|
9946
|
-
formatPresetName,
|
|
9947
|
-
formatPresetFor,
|
|
9948
|
-
readFormatAdoption,
|
|
9949
9694
|
rewriteToolchainImports,
|
|
9950
|
-
resolveOxfmt,
|
|
9951
|
-
oxfmtRejects,
|
|
9952
9695
|
canonicalRuleName,
|
|
9953
9696
|
describeRuleKey,
|
|
9954
9697
|
LINT_BASELINE_FILE,
|
|
@@ -9989,7 +9732,6 @@ export {
|
|
|
9989
9732
|
oxlintPath,
|
|
9990
9733
|
oxlintSearchPath,
|
|
9991
9734
|
walk,
|
|
9992
|
-
writtenFileFormatter,
|
|
9993
9735
|
RESOLVABLE_EXTENSIONS,
|
|
9994
9736
|
readTestAdoption,
|
|
9995
9737
|
resolveContext,
|