@stll/oxlint-config 1.3.0 → 1.4.0
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/README.md +254 -17
- package/dist/cloud-setup-cli.cjs +18 -38
- package/dist/cloud-setup-cli.cjs.map +1 -1
- package/dist/cloud-setup-cli.mjs +21 -41
- package/dist/cloud-setup-cli.mjs.map +1 -1
- package/dist/consumer-compat-cli.cjs +50 -249
- package/dist/consumer-compat-cli.cjs.map +1 -1
- package/dist/consumer-compat-cli.mjs +6 -205
- package/dist/consumer-compat-cli.mjs.map +1 -1
- package/dist/consumer-node-support.cjs +497 -0
- package/dist/consumer-node-support.cjs.map +1 -0
- package/dist/consumer-node-support.mjs +381 -0
- package/dist/consumer-node-support.mjs.map +1 -0
- package/dist/dependabot-cli.cjs +67 -0
- package/dist/dependabot-cli.cjs.map +1 -0
- package/dist/dependabot-cli.d.cts +1 -0
- package/dist/dependabot-cli.d.mts +1 -0
- package/dist/dependabot-cli.mjs +67 -0
- package/dist/dependabot-cli.mjs.map +1 -0
- package/dist/dependabot.cjs +5 -0
- package/dist/dependabot.d.cts +108 -0
- package/dist/dependabot.d.mts +108 -0
- package/dist/dependabot.mjs +3 -0
- package/dist/generated-file.cjs +61 -0
- package/dist/generated-file.cjs.map +1 -0
- package/dist/generated-file.mjs +44 -0
- package/dist/generated-file.mjs.map +1 -0
- package/dist/publish-artifact-syntax.cjs +1309 -0
- package/dist/publish-artifact-syntax.cjs.map +1 -0
- package/dist/publish-artifact-syntax.mjs +1265 -0
- package/dist/publish-artifact-syntax.mjs.map +1 -0
- package/dist/publish-contract-cli.cjs +53 -12
- package/dist/publish-contract-cli.cjs.map +1 -1
- package/dist/publish-contract-cli.mjs +49 -8
- package/dist/publish-contract-cli.mjs.map +1 -1
- package/dist/toolchain-changed.cjs +5 -1
- package/dist/toolchain-changed.cjs.map +1 -1
- package/dist/toolchain-changed.mjs +6 -2
- package/dist/toolchain-changed.mjs.map +1 -1
- package/dist/toolchain-dependabot.cjs +455 -0
- package/dist/toolchain-dependabot.cjs.map +1 -0
- package/dist/toolchain-dependabot.mjs +423 -0
- package/dist/toolchain-dependabot.mjs.map +1 -0
- package/dist/toolchain-guard.cjs +1096 -424
- package/dist/toolchain-guard.cjs.map +1 -1
- package/dist/toolchain-guard.mjs +1085 -413
- package/dist/toolchain-guard.mjs.map +1 -1
- package/dist/toolchain-inputs.cjs +122 -22
- package/dist/toolchain-inputs.cjs.map +1 -1
- package/dist/toolchain-inputs.mjs +117 -23
- package/dist/toolchain-inputs.mjs.map +1 -1
- package/dist/toolchain-schema.cjs +0 -493
- package/dist/toolchain-schema.cjs.map +1 -1
- package/dist/toolchain-schema.mjs +3 -379
- package/dist/toolchain-schema.mjs.map +1 -1
- package/dist/typecheck-parity.cjs +1 -1
- package/dist/typecheck-probe-cli.cjs +1 -1
- package/dist/typecheck-probe-cli.cjs.map +1 -1
- package/dist/typecheck-probe-cli.mjs +1 -1
- package/dist/typecheck-probe-cli.mjs.map +1 -1
- package/package.json +13 -1
- package/dist/publish-contract.cjs +0 -431
- package/dist/publish-contract.cjs.map +0 -1
- package/dist/publish-contract.mjs +0 -396
- package/dist/publish-contract.mjs.map +0 -1
package/dist/toolchain-guard.mjs
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as parseCloudSetup, S as generateCloudSetup, T as nodeSupportRangeMatches, _ as cloudSessionStartFix, a as isMiseConfigPath, d as containerDocumentImages, f as isComposeDefinitionPath, g as cloudClaudeSettingsPath, h as cloudAttributionFix, i as isDockerDefinitionPath, m as workspaceContains, n as githubAutomationFileKind, p as isKubernetesDefinitionPath, s as isShellScript, u as toolchainInputKind, v as hasCloudAttribution, w as nodeSelectorMatches, x as cloudSetupPath, y as hasCloudSessionStartHook } from "./toolchain-inputs.mjs";
|
|
2
2
|
import { t as readGitTrackedOutput } from "./git-tracked-output.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { a as assertConsumerFixtureSelection, g as parseConsumerFixtures, h as discoverConsumerPackages, m as discoverConsumerManifests, r as assertConsumerFixtureKind, t as assertConsumerNodeSupport, u as consumerPackageClosure } from "./consumer-node-support.mjs";
|
|
4
|
+
import { a as rustImageVersion, i as canonicalDockerRuntime, n as dependabotRules, t as checkDependabot } from "./toolchain-dependabot.mjs";
|
|
5
|
+
import "./toolchain-schema.mjs";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
4
7
|
import { closeSync, lstatSync, openSync, readFileSync, readSync, realpathSync } from "node:fs";
|
|
5
|
-
import { execFileSync } from "node:child_process";
|
|
6
|
-
import path from "node:path";
|
|
8
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
9
|
+
import path, { extname } from "node:path";
|
|
7
10
|
import { minVersion, satisfies, valid, validRange } from "semver";
|
|
8
11
|
import { parse as parse$1 } from "smol-toml";
|
|
9
12
|
import { LineCounter, isAlias, isMap, isNode, isScalar, isSeq, parseAllDocuments, parseDocument } from "yaml";
|
|
10
13
|
import picomatch from "picomatch";
|
|
11
14
|
//#endregion
|
|
12
15
|
//#region src/toolchain-consumer-checks.ts
|
|
13
|
-
const consumerRunnerVersion = "1.
|
|
16
|
+
const consumerRunnerVersion = "1.4.0";
|
|
14
17
|
const consumerCheckWorkflow = "stella/.github/.github/workflows/package-consumer-compat.yml";
|
|
15
|
-
const record$
|
|
18
|
+
const record$10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
19
|
const repositoryDirectory = (value) => typeof value === "string" && value !== "" && !value.includes("\\") && !value.includes("${{") && !value.split("").some((character) => {
|
|
17
20
|
const code = character.charCodeAt(0);
|
|
18
21
|
return code < 32 || code === 127;
|
|
@@ -98,12 +101,12 @@ const validConsumerCron = (text) => {
|
|
|
98
101
|
});
|
|
99
102
|
};
|
|
100
103
|
const nightlySchedule = (value) => {
|
|
101
|
-
if (!record$
|
|
104
|
+
if (!record$10(value)) return false;
|
|
102
105
|
const schedule = value["schedule"];
|
|
103
106
|
if (!Array.isArray(schedule) || schedule.length === 0) return false;
|
|
104
107
|
const coveredDays = /* @__PURE__ */ new Set();
|
|
105
108
|
for (const entry of schedule) {
|
|
106
|
-
if (!record$
|
|
109
|
+
if (!record$10(entry) || typeof entry["cron"] !== "string" || !validConsumerCron(entry["cron"])) return false;
|
|
107
110
|
const fields = entry["cron"].trim().split(/\s+/);
|
|
108
111
|
const selections = cronFields.map((field, index) => {
|
|
109
112
|
const text = fields.at(index);
|
|
@@ -119,7 +122,7 @@ const parseConsumerChecks = (input) => {
|
|
|
119
122
|
if (!Array.isArray(input)) throw new Error("consumerChecks must be an array");
|
|
120
123
|
const targets = /* @__PURE__ */ new Set();
|
|
121
124
|
return input.map((entry) => {
|
|
122
|
-
if (!record$
|
|
125
|
+
if (!record$10(entry) || Object.keys(entry).some((key) => ![
|
|
123
126
|
"workflow",
|
|
124
127
|
"job",
|
|
125
128
|
"packages",
|
|
@@ -157,9 +160,9 @@ const checkConsumerChecks = ({ declarations, files, policy }) => {
|
|
|
157
160
|
});
|
|
158
161
|
if (document.errors.length > 0) throw new Error("invalid workflow YAML");
|
|
159
162
|
const source = document.toJS({ maxAliasCount: 100 });
|
|
160
|
-
if (!record$
|
|
163
|
+
if (!record$10(source) || !record$10(source["jobs"])) continue;
|
|
161
164
|
for (const [jobName, job] of Object.entries(source["jobs"])) {
|
|
162
|
-
if (!record$
|
|
165
|
+
if (!record$10(job) || typeof job["uses"] !== "string") continue;
|
|
163
166
|
const [workflowPath, ref] = job["uses"].split("@");
|
|
164
167
|
if (workflowPath?.toLowerCase() !== "stella/.github/.github/workflows/package-consumer-compat.yml") continue;
|
|
165
168
|
const declaration = declarations.find((entry) => entry.workflow === workflow && entry.job === jobName);
|
|
@@ -173,7 +176,7 @@ const checkConsumerChecks = ({ declarations, files, policy }) => {
|
|
|
173
176
|
const approved = Object.entries(policy.actions).find(([name]) => name.toLowerCase() === consumerCheckWorkflow)?.[1];
|
|
174
177
|
if (job["uses"].split("@").length !== 2 || ref === void 0 || !/^[a-f0-9]{40}$/.test(ref) || approved === void 0 || ref !== approved.sha || "steps" in job || "runs-on" in job) throw new Error(`${workflow}:${jobName} must invoke the approved immutable consumer workflow as a reusable job`);
|
|
175
178
|
const inputs = job["with"];
|
|
176
|
-
if (!record$
|
|
179
|
+
if (!record$10(inputs)) throw new Error(`${workflow}:${jobName} requires consumer inputs`);
|
|
177
180
|
const names = /* @__PURE__ */ new Set();
|
|
178
181
|
for (const key of Object.keys(inputs)) {
|
|
179
182
|
const normalized = key.toLowerCase();
|
|
@@ -237,367 +240,13 @@ const checkConsumerChecks = ({ declarations, files, policy }) => {
|
|
|
237
240
|
return diagnostics;
|
|
238
241
|
};
|
|
239
242
|
//#endregion
|
|
240
|
-
//#region src/toolchain-images.ts
|
|
241
|
-
/** Docker Hub spellings accepted by the shared runtime policy. */
|
|
242
|
-
const dockerHubRegistries = [
|
|
243
|
-
"docker.io",
|
|
244
|
-
"index.docker.io",
|
|
245
|
-
"registry-1.docker.io"
|
|
246
|
-
];
|
|
247
|
-
/** Expand the full accepted repository alias class without parsing Dockerfile instructions. */
|
|
248
|
-
const ownedDockerImageAliases = (images) => {
|
|
249
|
-
const aliases = /* @__PURE__ */ new Set();
|
|
250
|
-
for (const image of images) for (const repository of [image, `library/${image}`]) {
|
|
251
|
-
aliases.add(repository);
|
|
252
|
-
for (const registry of dockerHubRegistries) aliases.add(`${registry}/${repository}`);
|
|
253
|
-
}
|
|
254
|
-
return [...aliases].sort();
|
|
255
|
-
};
|
|
256
|
-
/** Preserve tag/digest spelling while normalizing registry and namespace aliases. */
|
|
257
|
-
const canonicalDockerRuntime = (image) => {
|
|
258
|
-
const registry = dockerHubRegistries.find((entry) => image.toLowerCase().startsWith(`${entry}/`));
|
|
259
|
-
return (registry === void 0 ? image : image.slice(registry.length + 1)).replace(/^library\//i, "");
|
|
260
|
-
};
|
|
261
|
-
/** Preserve Rust release identity across official Debian slim and Alpine variants. */
|
|
262
|
-
const rustImageVersion = (tag) => tag.replace(/-(?:alpine(?:\d+(?:\.\d+)*)?|(?:bookworm|bullseye|trixie|buster)(?:-slim)?|slim(?:-(?:bookworm|bullseye|trixie|buster))?)$/, "");
|
|
263
|
-
//#endregion
|
|
264
|
-
//#region src/toolchain-dependabot.ts
|
|
265
|
-
const dependabotRules = ["dependabot-policy"];
|
|
266
|
-
const record$6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
267
|
-
const strings = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
268
|
-
const sameStrings = (value, expected) => {
|
|
269
|
-
if (!strings(value) || value.length !== expected.length) return false;
|
|
270
|
-
const sortedExpected = [...expected].sort();
|
|
271
|
-
return [...value].sort().every((entry, index) => entry === sortedExpected[index]);
|
|
272
|
-
};
|
|
273
|
-
const pinnedVersionUpdateTypes = [
|
|
274
|
-
"version-update:semver-major",
|
|
275
|
-
"version-update:semver-minor",
|
|
276
|
-
"version-update:semver-patch"
|
|
277
|
-
];
|
|
278
|
-
const versionOnlyIgnore = (entry) => record$6(entry) && Object.keys(entry).length === 2 && typeof entry["dependency-name"] === "string" && sameStrings(entry["update-types"], pinnedVersionUpdateTypes);
|
|
279
|
-
const directoryOf = (file) => {
|
|
280
|
-
const directory = path.posix.dirname(file);
|
|
281
|
-
return directory === "." ? "/" : `/${directory}`;
|
|
282
|
-
};
|
|
283
|
-
const workspaceManifests = {
|
|
284
|
-
npm: "package.json",
|
|
285
|
-
cargo: "Cargo.toml",
|
|
286
|
-
uv: "pyproject.toml"
|
|
287
|
-
};
|
|
288
|
-
const workspaceTable = (parsed, ecosystem) => {
|
|
289
|
-
switch (ecosystem) {
|
|
290
|
-
case "npm": return parsed["workspaces"];
|
|
291
|
-
case "cargo": return parsed["workspace"];
|
|
292
|
-
case "uv": {
|
|
293
|
-
const tool = parsed["tool"];
|
|
294
|
-
const uv = record$6(tool) ? tool["uv"] : void 0;
|
|
295
|
-
return record$6(uv) ? uv["workspace"] : void 0;
|
|
296
|
-
}
|
|
297
|
-
default: throw new Error("unknown workspace ecosystem", { cause: ecosystem });
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
/** Installable workspace members share their update root; own-lock projects stay discoverable. */
|
|
301
|
-
const workspaceRoots = (files, ecosystem) => {
|
|
302
|
-
const manifests = Object.keys(files).filter((file) => path.posix.basename(file) === workspaceManifests[ecosystem] || ecosystem === "npm" && path.posix.basename(file) === "pnpm-workspace.yaml");
|
|
303
|
-
const workspaces = /* @__PURE__ */ new Map();
|
|
304
|
-
const npmWorkspaceErrors = /* @__PURE__ */ new Map();
|
|
305
|
-
for (const file of manifests) {
|
|
306
|
-
if (ecosystem === "npm") {
|
|
307
|
-
const directory = path.posix.dirname(file);
|
|
308
|
-
const workspaceFile = path.posix.join(directory, "pnpm-workspace.yaml");
|
|
309
|
-
const text = files[workspaceFile];
|
|
310
|
-
if (text !== void 0) {
|
|
311
|
-
try {
|
|
312
|
-
const document = parseDocument(text);
|
|
313
|
-
if (document.errors.length > 0) throw new Error(`${workspaceFile}:1: invalid pnpm workspace YAML`);
|
|
314
|
-
const parsed = document.toJS({ maxAliasCount: 100 });
|
|
315
|
-
if (!record$6(parsed)) throw new Error(`${workspaceFile}:1: pnpm workspace must contain an object`);
|
|
316
|
-
const patterns = parsed["packages"] ?? [];
|
|
317
|
-
if (!strings(patterns)) throw new Error(`${workspaceFile}:1: pnpm packages must be a string array`);
|
|
318
|
-
workspaces.set(directory, patterns.map((pattern) => pattern.startsWith("!") ? `!${path.posix.normalize(pattern.slice(1))}` : path.posix.normalize(pattern)));
|
|
319
|
-
} catch (error) {
|
|
320
|
-
npmWorkspaceErrors.set(directory, error instanceof Error ? error : new Error(String(error)));
|
|
321
|
-
}
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
try {
|
|
326
|
-
const parsed = ecosystem === "npm" ? JSON.parse(files[file] ?? "") : parse$1(files[file] ?? "");
|
|
327
|
-
if (!record$6(parsed)) continue;
|
|
328
|
-
if (ecosystem === "npm" && typeof parsed["packageManager"] === "string" && parsed["packageManager"].startsWith("pnpm@")) continue;
|
|
329
|
-
const value = workspaceTable(parsed, ecosystem);
|
|
330
|
-
const patterns = record$6(value) ? value[ecosystem === "npm" ? "packages" : "members"] : value;
|
|
331
|
-
const members = ecosystem === "cargo" && record$6(value) && patterns === void 0 ? [] : patterns;
|
|
332
|
-
if (strings(members)) {
|
|
333
|
-
const excluded = ecosystem !== "npm" && record$6(value) && strings(value["exclude"]) ? value["exclude"].map((pattern) => `!${pattern}`) : [];
|
|
334
|
-
workspaces.set(path.posix.dirname(file), [...members, ...excluded]);
|
|
335
|
-
}
|
|
336
|
-
} catch {}
|
|
337
|
-
}
|
|
338
|
-
const implicitCargoMembers = /* @__PURE__ */ new Map();
|
|
339
|
-
const declaredMember = (root, patterns, directory) => {
|
|
340
|
-
const relative = path.posix.relative(root, directory);
|
|
341
|
-
if (relative === "" || relative === ".." || relative.startsWith("../")) return false;
|
|
342
|
-
return workspaceContains({
|
|
343
|
-
directory: root,
|
|
344
|
-
file: path.posix.join(directory, "package.json"),
|
|
345
|
-
patterns,
|
|
346
|
-
rootMembership: "patterns"
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
const installable = /* @__PURE__ */ new Set(["."]);
|
|
350
|
-
if (ecosystem === "npm") {
|
|
351
|
-
for (const file of manifests) {
|
|
352
|
-
const directory = path.posix.dirname(file);
|
|
353
|
-
if (javascriptDependencyLockfiles.some((name) => files[path.posix.join(directory, name)] !== void 0)) installable.add(directory);
|
|
354
|
-
}
|
|
355
|
-
let changed = true;
|
|
356
|
-
while (changed) {
|
|
357
|
-
changed = false;
|
|
358
|
-
for (const [root, patterns] of workspaces) {
|
|
359
|
-
if (!installable.has(root)) continue;
|
|
360
|
-
for (const file of manifests) {
|
|
361
|
-
const directory = path.posix.dirname(file);
|
|
362
|
-
if (installable.has(directory) || !declaredMember(root, patterns, directory)) continue;
|
|
363
|
-
installable.add(directory);
|
|
364
|
-
changed = true;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (ecosystem === "npm") {
|
|
370
|
-
for (const [directory, error] of npmWorkspaceErrors) if (installable.has(directory)) throw error;
|
|
371
|
-
}
|
|
372
|
-
if (ecosystem === "cargo") for (const [root, patterns] of workspaces) {
|
|
373
|
-
const includes = patterns.filter((pattern) => !pattern.startsWith("!"));
|
|
374
|
-
const excludes = patterns.filter((pattern) => pattern.startsWith("!"));
|
|
375
|
-
const memberDirectories = /* @__PURE__ */ new Set([root]);
|
|
376
|
-
for (const file of manifests) {
|
|
377
|
-
const directory = path.posix.dirname(file);
|
|
378
|
-
const relative = path.posix.relative(root, directory);
|
|
379
|
-
if (includes.some((pattern) => picomatch.isMatch(relative, pattern)) && !excludes.some((pattern) => picomatch.isMatch(relative, pattern.slice(1)))) memberDirectories.add(directory);
|
|
380
|
-
}
|
|
381
|
-
for (const directory of memberDirectories) try {
|
|
382
|
-
const parsed = parse$1(files[path.posix.join(directory, "Cargo.toml")] ?? "");
|
|
383
|
-
const workspace = parse$1(files[path.posix.join(root, "Cargo.toml")] ?? "")["workspace"];
|
|
384
|
-
const inherited = record$6(workspace) ? workspace["dependencies"] : void 0;
|
|
385
|
-
const dependencyOwners = [parsed];
|
|
386
|
-
const targets = parsed["target"];
|
|
387
|
-
if (record$6(targets)) {
|
|
388
|
-
for (const target of Object.values(targets)) if (record$6(target)) dependencyOwners.push(target);
|
|
389
|
-
}
|
|
390
|
-
for (const owner of dependencyOwners) for (const key of [
|
|
391
|
-
"dependencies",
|
|
392
|
-
"dev-dependencies",
|
|
393
|
-
"build-dependencies"
|
|
394
|
-
]) {
|
|
395
|
-
const dependencies = owner[key];
|
|
396
|
-
if (!record$6(dependencies)) continue;
|
|
397
|
-
for (const [name, dependency] of Object.entries(dependencies)) {
|
|
398
|
-
if (!record$6(dependency)) continue;
|
|
399
|
-
const isInherited = dependency["workspace"] === true;
|
|
400
|
-
const resolved = isInherited && record$6(inherited) ? inherited[name] : dependency;
|
|
401
|
-
if (!record$6(resolved) || typeof resolved["path"] !== "string") continue;
|
|
402
|
-
if (path.posix.isAbsolute(resolved["path"]) || /\\|\$|^[A-Za-z]:/.test(resolved["path"])) continue;
|
|
403
|
-
const target = path.posix.normalize(path.posix.join(isInherited ? root : directory, resolved["path"]));
|
|
404
|
-
const relative = path.posix.relative(root, target);
|
|
405
|
-
if (relative.startsWith("../") || relative === ".." || files[path.posix.join(target, "Cargo.toml")] === void 0 || excludes.some((pattern) => picomatch.isMatch(relative, pattern.slice(1)))) continue;
|
|
406
|
-
memberDirectories.add(target);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
} catch {}
|
|
410
|
-
implicitCargoMembers.set(root, memberDirectories);
|
|
411
|
-
}
|
|
412
|
-
return manifests.filter((file) => ecosystem !== "npm" || installable.has(path.posix.dirname(file))).filter((file) => {
|
|
413
|
-
const directory = path.posix.dirname(file);
|
|
414
|
-
return ![...workspaces].some(([root, patterns]) => {
|
|
415
|
-
if (ecosystem === "npm" && !installable.has(root)) return false;
|
|
416
|
-
const relative = path.posix.relative(root, directory);
|
|
417
|
-
if (relative === "" || relative.startsWith("../")) return false;
|
|
418
|
-
const includes = patterns.filter((pattern) => !pattern.startsWith("!"));
|
|
419
|
-
const excludes = patterns.filter((pattern) => pattern.startsWith("!"));
|
|
420
|
-
return (implicitCargoMembers.get(root)?.has(directory) === true || (ecosystem === "npm" ? declaredMember(root, patterns, directory) : includes.some((pattern) => picomatch.isMatch(relative, pattern)))) && !excludes.some((pattern) => picomatch.isMatch(relative, pattern.slice(1)));
|
|
421
|
-
});
|
|
422
|
-
}).map(directoryOf).filter((directory, index, values) => values.indexOf(directory) === index);
|
|
423
|
-
};
|
|
424
|
-
const javascriptEcosystem = (directory, files) => {
|
|
425
|
-
const root = directory === "/" ? "." : directory.slice(1);
|
|
426
|
-
if (files[path.posix.join(root, "bun.lock")] !== void 0) return "bun";
|
|
427
|
-
try {
|
|
428
|
-
const manifest = JSON.parse(files[path.posix.join(root, "package.json")] ?? "{}");
|
|
429
|
-
if (record$6(manifest) && typeof manifest["packageManager"] === "string" && manifest["packageManager"].startsWith("bun@")) return "bun";
|
|
430
|
-
} catch {}
|
|
431
|
-
return "npm";
|
|
432
|
-
};
|
|
433
|
-
const pythonEcosystem = (file, files) => {
|
|
434
|
-
const manifestKind = pythonDependencyManifestKind(file);
|
|
435
|
-
if (manifestKind === "pipfile" || manifestKind === "pipfile-lock" || manifestKind === "setup") return "pip";
|
|
436
|
-
const root = path.posix.dirname(file);
|
|
437
|
-
if (files[path.posix.join(root, "uv.lock")] !== void 0 || files[path.posix.join(root, "uv.toml")] !== void 0) return "uv";
|
|
438
|
-
const pyproject = files[path.posix.join(root, "pyproject.toml")];
|
|
439
|
-
if (pyproject !== void 0) try {
|
|
440
|
-
const tool = parse$1(pyproject)["tool"];
|
|
441
|
-
if (record$6(tool) && record$6(tool["uv"])) return "uv";
|
|
442
|
-
} catch {}
|
|
443
|
-
return "pip";
|
|
444
|
-
};
|
|
445
|
-
const ecosystemRoots = (files) => {
|
|
446
|
-
const roots = /* @__PURE__ */ new Map();
|
|
447
|
-
const requireRoot = (ecosystem, directory) => {
|
|
448
|
-
const directories = roots.get(ecosystem) ?? /* @__PURE__ */ new Set();
|
|
449
|
-
directories.add(directory);
|
|
450
|
-
roots.set(ecosystem, directories);
|
|
451
|
-
};
|
|
452
|
-
for (const directory of workspaceRoots(files, "npm")) requireRoot(javascriptEcosystem(directory, files), directory);
|
|
453
|
-
for (const directory of workspaceRoots(files, "cargo")) requireRoot("cargo", directory);
|
|
454
|
-
for (const directory of workspaceRoots(files, "uv")) {
|
|
455
|
-
const root = directory === "/" ? "." : directory.slice(1);
|
|
456
|
-
requireRoot(pythonEcosystem(path.posix.join(root, "pyproject.toml"), files), directory);
|
|
457
|
-
}
|
|
458
|
-
for (const file of Object.keys(files)) {
|
|
459
|
-
if (isDependabotGithubActionsPath(file)) requireRoot("github-actions", "/");
|
|
460
|
-
const name = path.posix.basename(file);
|
|
461
|
-
if (isDockerDefinitionPath(file)) requireRoot("docker", directoryOf(file));
|
|
462
|
-
if (isComposeDefinitionPath(file) || isKubernetesDefinitionPath(file)) for (const document of parseAllDocuments(files[file] ?? "", { merge: true })) {
|
|
463
|
-
if (document.errors.length > 0) continue;
|
|
464
|
-
try {
|
|
465
|
-
const classified = containerDocumentImages(document.toJS({ maxAliasCount: 100 }), file);
|
|
466
|
-
if (classified !== void 0) requireRoot(classified.ecosystem, directoryOf(file));
|
|
467
|
-
} catch {}
|
|
468
|
-
}
|
|
469
|
-
if (name === "uv.lock" || name === "uv.toml" || name !== "pyproject.toml" && isPythonDependencyManifest(file)) requireRoot(pythonEcosystem(file, files), directoryOf(file));
|
|
470
|
-
}
|
|
471
|
-
return roots;
|
|
472
|
-
};
|
|
473
|
-
const ignoredFor = (ecosystem, policy) => {
|
|
474
|
-
if (ecosystem === "npm" || ecosystem === "bun") return policy.ignoredPackages;
|
|
475
|
-
if (ecosystem === "github-actions") return policy.ignoredActions;
|
|
476
|
-
if (ecosystem === "docker" || ecosystem === "docker-compose") return ownedDockerImageAliases(policy.ignoredImages);
|
|
477
|
-
return [];
|
|
478
|
-
};
|
|
479
|
-
/** Validate the shared update policy against a hermetic tracked-file snapshot. */
|
|
480
|
-
const checkDependabot = ({ files, policy }) => {
|
|
481
|
-
const roots = ecosystemRoots(files);
|
|
482
|
-
const paths = [".github/dependabot.yml", ".github/dependabot.yaml"].filter((file) => files[file] !== void 0);
|
|
483
|
-
if (roots.size === 0 && paths.length === 0) return [];
|
|
484
|
-
const file = paths.at(0) ?? ".github/dependabot.yml";
|
|
485
|
-
const diagnostics = [];
|
|
486
|
-
const add = (message, line = 1) => {
|
|
487
|
-
diagnostics.push({
|
|
488
|
-
rule: "dependabot-policy",
|
|
489
|
-
path: file,
|
|
490
|
-
line,
|
|
491
|
-
message
|
|
492
|
-
});
|
|
493
|
-
};
|
|
494
|
-
if (paths.length === 0) {
|
|
495
|
-
add("add a Dependabot configuration for the repository's package ecosystems");
|
|
496
|
-
return diagnostics;
|
|
497
|
-
}
|
|
498
|
-
if (paths.length > 1) add("keep one Dependabot configuration file");
|
|
499
|
-
const lineCounter = new LineCounter();
|
|
500
|
-
const document = parseDocument(files[file] ?? "", { lineCounter });
|
|
501
|
-
if (document.errors.length > 0) {
|
|
502
|
-
for (const error of document.errors) add(`invalid Dependabot YAML: ${error.message}`, lineCounter.linePos(error.pos[0]).line);
|
|
503
|
-
return diagnostics;
|
|
504
|
-
}
|
|
505
|
-
let parsed;
|
|
506
|
-
try {
|
|
507
|
-
parsed = document.toJS({ maxAliasCount: 100 });
|
|
508
|
-
} catch {
|
|
509
|
-
add("cannot resolve Dependabot YAML aliases");
|
|
510
|
-
return diagnostics;
|
|
511
|
-
}
|
|
512
|
-
if (!record$6(parsed) || parsed["version"] !== 2 || !Array.isArray(parsed["updates"])) {
|
|
513
|
-
add("Dependabot must declare version: 2 and an updates array");
|
|
514
|
-
return diagnostics;
|
|
515
|
-
}
|
|
516
|
-
const covered = /* @__PURE__ */ new Map();
|
|
517
|
-
let legacy;
|
|
518
|
-
try {
|
|
519
|
-
const legacyDocument = parseDocument(files[file] ?? "", {
|
|
520
|
-
version: "1.1",
|
|
521
|
-
schema: "yaml-1.1"
|
|
522
|
-
});
|
|
523
|
-
if (legacyDocument.errors.length === 0) legacy = legacyDocument.toJS({ maxAliasCount: 100 });
|
|
524
|
-
} catch {}
|
|
525
|
-
const legacyUpdates = record$6(legacy) && Array.isArray(legacy["updates"]) ? legacy["updates"] : [];
|
|
526
|
-
const rootClaims = /* @__PURE__ */ new Map();
|
|
527
|
-
const directoryClaims = /* @__PURE__ */ new Map();
|
|
528
|
-
for (const [index, update] of parsed["updates"].entries()) {
|
|
529
|
-
const lineOf = (key) => {
|
|
530
|
-
const node = document.getIn([
|
|
531
|
-
"updates",
|
|
532
|
-
index,
|
|
533
|
-
key
|
|
534
|
-
], true);
|
|
535
|
-
const offset = isNode(node) ? node.range?.[0] : void 0;
|
|
536
|
-
return offset === void 0 ? 1 : lineCounter.linePos(offset).line;
|
|
537
|
-
};
|
|
538
|
-
const report = (key, message) => add(message, lineOf(key));
|
|
539
|
-
if (!record$6(update) || typeof update["package-ecosystem"] !== "string") {
|
|
540
|
-
report("package-ecosystem", "each Dependabot update must declare a package ecosystem");
|
|
541
|
-
continue;
|
|
542
|
-
}
|
|
543
|
-
const ecosystem = update["package-ecosystem"];
|
|
544
|
-
if (update["target-branch"] !== void 0) report("target-branch", `${ecosystem}: shared updates must target the default branch`);
|
|
545
|
-
if (update["open-pull-requests-limit"] === 0) report("open-pull-requests-limit", `${ecosystem}: version updates must remain enabled`);
|
|
546
|
-
const single = update["directory"];
|
|
547
|
-
const multiple = update["directories"];
|
|
548
|
-
let directories = [];
|
|
549
|
-
if (typeof single === "string" && multiple === void 0) directories = [single];
|
|
550
|
-
else if (single === void 0 && strings(multiple)) directories = multiple;
|
|
551
|
-
const validDirectories = directories.filter((directory) => directory.startsWith("/") && !directory.split("/").includes(".."));
|
|
552
|
-
if (directories.length === 0 || validDirectories.length !== directories.length) report("directory", `${ecosystem}: declare directory or nonempty directories with absolute repository paths`);
|
|
553
|
-
const normalizedDirectories = Array.from(new Set(validDirectories.map((value) => path.posix.normalize(value).replace(/\/+$/, "") || "/")));
|
|
554
|
-
const matches = covered.get(ecosystem) ?? /* @__PURE__ */ new Set();
|
|
555
|
-
const claimedDirectories = directoryClaims.get(ecosystem) ?? /* @__PURE__ */ new Map();
|
|
556
|
-
for (const directory of normalizedDirectories) {
|
|
557
|
-
const previous = claimedDirectories.get(directory);
|
|
558
|
-
if (previous !== void 0) report(multiple === void 0 ? "directory" : "directories", `${ecosystem}: directory ${directory} overlaps update entry ${previous + 1}`);
|
|
559
|
-
else claimedDirectories.set(directory, index);
|
|
560
|
-
}
|
|
561
|
-
directoryClaims.set(ecosystem, claimedDirectories);
|
|
562
|
-
const claimedRoots = rootClaims.get(ecosystem) ?? /* @__PURE__ */ new Map();
|
|
563
|
-
for (const root of roots.get(ecosystem) ?? []) if (normalizedDirectories.some((directory) => directory === root || multiple !== void 0 && picomatch.isMatch(root, directory))) {
|
|
564
|
-
const previous = claimedRoots.get(root);
|
|
565
|
-
if (previous !== void 0) report(multiple === void 0 ? "directory" : "directories", `${ecosystem}: update root ${root} overlaps update entry ${previous + 1}`);
|
|
566
|
-
else claimedRoots.set(root, index);
|
|
567
|
-
matches.add(root);
|
|
568
|
-
}
|
|
569
|
-
rootClaims.set(ecosystem, claimedRoots);
|
|
570
|
-
covered.set(ecosystem, matches);
|
|
571
|
-
const schedule = update["schedule"];
|
|
572
|
-
const legacyUpdate = legacyUpdates.at(index);
|
|
573
|
-
const legacySchedule = record$6(legacyUpdate) ? legacyUpdate["schedule"] : void 0;
|
|
574
|
-
if (record$6(schedule) && schedule["time"] === policy.schedule.time && (!record$6(legacySchedule) || legacySchedule["time"] !== policy.schedule.time)) report("schedule", `${ecosystem}: quote schedule time to preserve its string value in YAML 1.1`);
|
|
575
|
-
if (!record$6(schedule) || Object.keys(schedule).length !== Object.keys(policy.schedule).length || Object.entries(policy.schedule).some(([key, value]) => schedule[key] !== value)) report("schedule", `${ecosystem}: schedule must match the shared policy`);
|
|
576
|
-
const cooldown = update["cooldown"];
|
|
577
|
-
if (!record$6(cooldown) || Object.keys(cooldown).length !== 1 || cooldown["default-days"] !== policy.cooldown.defaultDays) report("cooldown", `${ecosystem}: cooldown must contain only default-days: ${policy.cooldown.defaultDays}`);
|
|
578
|
-
const groups = update["groups"];
|
|
579
|
-
if (!record$6(groups) || Object.keys(groups).length !== Object.keys(policy.groups).length || Object.entries(policy.groups).some(([name, expected]) => {
|
|
580
|
-
const group = groups[name];
|
|
581
|
-
return !record$6(group) || Object.keys(group).length !== 2 || !sameStrings(group["patterns"], expected.patterns) || !sameStrings(group["update-types"], expected.updateTypes);
|
|
582
|
-
})) report("groups", `${ecosystem}: groups must match the shared policy`);
|
|
583
|
-
const ignored = ignoredFor(ecosystem, policy);
|
|
584
|
-
const ignore = update["ignore"];
|
|
585
|
-
if (ignore !== void 0 && (!Array.isArray(ignore) || ignore.length === 0)) report("ignore", `${ecosystem}: omit ignore or provide a nonempty array`);
|
|
586
|
-
if (Array.isArray(ignore) && ignore.some((entry) => !record$6(entry) || typeof entry["dependency-name"] !== "string" || !ignored.includes(entry["dependency-name"]))) report("ignore", `${ecosystem}: ignore only packages owned by the shared policy`);
|
|
587
|
-
if (Array.isArray(ignore) && ignore.some((entry) => !versionOnlyIgnore(entry))) report("ignore", `${ecosystem}: each shared-pin ignore must contain only dependency-name and update-types for semver-major, semver-minor, and semver-patch version updates; security updates must remain enabled`);
|
|
588
|
-
for (const name of ignored) if (!Array.isArray(ignore) || !ignore.some((entry) => record$6(entry) && entry["dependency-name"] === name && versionOnlyIgnore(entry))) report("ignore", `${ecosystem}: ignore all version updates for shared pin ${name}`);
|
|
589
|
-
}
|
|
590
|
-
for (const [ecosystem, directories] of roots) for (const directory of directories) if (!covered.get(ecosystem)?.has(directory)) add(`add a ${ecosystem} update entry covering ${directory}`);
|
|
591
|
-
return diagnostics;
|
|
592
|
-
};
|
|
593
|
-
//#endregion
|
|
594
243
|
//#region src/toolchain-dynamic-selectors.ts
|
|
595
244
|
const locatorValidators = {
|
|
596
245
|
image: /^(?:jobs\.[\w-]+\.(?:container|services\.[\w-]+)|services\.[\w.-]+\.image)$/,
|
|
597
246
|
"bun-source": /^(?:jobs\.[\w-]+|runs)\.steps\.[\w-]+$/
|
|
598
247
|
};
|
|
599
248
|
const knownKind = (value) => typeof value === "string" && Object.hasOwn(locatorValidators, value);
|
|
600
|
-
const record$
|
|
249
|
+
const record$9 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
601
250
|
/** One reviewed declaration identifies one unresolved selector, never a rule. */
|
|
602
251
|
const parseDynamicSelectors = (input) => {
|
|
603
252
|
if (input === void 0) return [];
|
|
@@ -605,7 +254,7 @@ const parseDynamicSelectors = (input) => {
|
|
|
605
254
|
const result = [];
|
|
606
255
|
const keys = /* @__PURE__ */ new Set();
|
|
607
256
|
for (const entry of input) {
|
|
608
|
-
if (!record$
|
|
257
|
+
if (!record$9(entry) || Object.keys(entry).some((key) => ![
|
|
609
258
|
"path",
|
|
610
259
|
"kind",
|
|
611
260
|
"reason",
|
|
@@ -641,7 +290,7 @@ const parseDynamicSelectors = (input) => {
|
|
|
641
290
|
};
|
|
642
291
|
//#endregion
|
|
643
292
|
//#region src/toolchain-engine-floors.ts
|
|
644
|
-
const record$
|
|
293
|
+
const record$8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
645
294
|
const repositoryPath = (value) => typeof value === "string" && value !== "" && !/^[A-Za-z]:/.test(value) && !/[\\\s]/.test(value) && !Array.from(value).some((character) => character.charCodeAt(0) < 32) && value.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
646
295
|
const parseEngineFloors = (input) => {
|
|
647
296
|
if (input === void 0) return [];
|
|
@@ -649,7 +298,7 @@ const parseEngineFloors = (input) => {
|
|
|
649
298
|
const result = [];
|
|
650
299
|
const jobs = /* @__PURE__ */ new Set();
|
|
651
300
|
for (const entry of input) {
|
|
652
|
-
if (!record$
|
|
301
|
+
if (!record$8(entry) || Object.keys(entry).some((key) => ![
|
|
653
302
|
"package",
|
|
654
303
|
"workflow",
|
|
655
304
|
"job"
|
|
@@ -670,16 +319,16 @@ const resolveEngineFloor = (entry, files) => {
|
|
|
670
319
|
const workflowText = files[entry.workflow];
|
|
671
320
|
if (manifestText === void 0 || workflowText === void 0) throw new Error("engine floor package and workflow must be tracked");
|
|
672
321
|
const manifest = JSON.parse(manifestText);
|
|
673
|
-
if (!record$
|
|
322
|
+
if (!record$8(manifest) || manifest["private"] === true || typeof manifest["name"] !== "string" || manifest["name"].trim() === "" || !record$8(manifest["engines"]) || typeof manifest["engines"]["node"] !== "string") throw new Error("engine floor package must be published and declare engines.node");
|
|
674
323
|
const range = manifest["engines"]["node"];
|
|
675
324
|
const minimum = validRange(range) === null ? null : minVersion(range);
|
|
676
325
|
if (minimum === null || minimum.prerelease.length !== 0) throw new Error("engine floor engines.node must declare a stable minimum");
|
|
677
326
|
const document = parseDocument(workflowText, { merge: true });
|
|
678
327
|
if (document.errors.length !== 0) throw new Error("engine floor workflow must be valid YAML");
|
|
679
328
|
const workflow = document.toJS({ maxAliasCount: 100 });
|
|
680
|
-
if (!record$
|
|
329
|
+
if (!record$8(workflow) || !record$8(workflow["jobs"])) throw new Error("engine floor job must exist in its tracked workflow");
|
|
681
330
|
const job = workflow["jobs"][entry.job];
|
|
682
|
-
if (!record$
|
|
331
|
+
if (!record$8(job)) throw new Error("engine floor job must exist in its tracked workflow");
|
|
683
332
|
if (!Array.isArray(job["steps"]) || Object.hasOwn(job, "uses")) throw new Error("engine floor job must declare steps and cannot reuse a workflow");
|
|
684
333
|
return {
|
|
685
334
|
...entry,
|
|
@@ -699,7 +348,7 @@ const packageRules = [
|
|
|
699
348
|
"typescript-layout",
|
|
700
349
|
"node-engine"
|
|
701
350
|
];
|
|
702
|
-
const record$
|
|
351
|
+
const record$7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
703
352
|
const shellSubstitutions = (command) => {
|
|
704
353
|
const frames = [{
|
|
705
354
|
kind: "root",
|
|
@@ -1259,10 +908,10 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1259
908
|
const document = pnpm ? parseDocument(text, { lineCounter }) : void 0;
|
|
1260
909
|
if (document !== void 0 && document.errors.length > 0) throw new Error("invalid YAML");
|
|
1261
910
|
const json = document === void 0 ? JSON.parse(text) : document.toJS();
|
|
1262
|
-
if (!record$
|
|
911
|
+
if (!record$7(json)) throw new Error("manifest must be an object");
|
|
1263
912
|
if (pnpm) {
|
|
1264
|
-
if (json["catalog"] !== void 0 && !record$
|
|
1265
|
-
if (json["catalogs"] !== void 0 && (!record$
|
|
913
|
+
if (json["catalog"] !== void 0 && !record$7(json["catalog"])) throw new Error("catalog must be a mapping");
|
|
914
|
+
if (json["catalogs"] !== void 0 && (!record$7(json["catalogs"]) || Object.values(json["catalogs"]).some((catalog) => !record$7(catalog)))) throw new Error("named catalogs must be mappings");
|
|
1266
915
|
if (json["packages"] !== void 0 && (!Array.isArray(json["packages"]) || !json["packages"].every((pattern) => typeof pattern === "string"))) throw new Error("workspace packages must be patterns");
|
|
1267
916
|
}
|
|
1268
917
|
manifests.set(file, json);
|
|
@@ -1276,13 +925,13 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1276
925
|
catalog: json["overrides"],
|
|
1277
926
|
prefix: ["overrides"]
|
|
1278
927
|
},
|
|
1279
|
-
...record$
|
|
928
|
+
...record$7(json["catalogs"]) ? Object.entries(json["catalogs"]).map(([name, catalog]) => ({
|
|
1280
929
|
catalog,
|
|
1281
930
|
prefix: ["catalogs", name]
|
|
1282
931
|
})) : []
|
|
1283
932
|
];
|
|
1284
933
|
for (const { catalog, prefix } of catalogEntries) {
|
|
1285
|
-
if (!record$
|
|
934
|
+
if (!record$7(catalog)) continue;
|
|
1286
935
|
for (const [name, value] of Object.entries(catalog)) {
|
|
1287
936
|
const node = document.getIn([...prefix, name], true);
|
|
1288
937
|
if (!isNode(node) || node.range === void 0 || node.range === null) continue;
|
|
@@ -1301,7 +950,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1301
950
|
});
|
|
1302
951
|
}
|
|
1303
952
|
}
|
|
1304
|
-
const catalogSources = (json) => [json, ...record$
|
|
953
|
+
const catalogSources = (json) => [json, ...record$7(json["workspaces"]) ? [json["workspaces"]] : []];
|
|
1305
954
|
const pnpmWorkspaceFor = (file) => {
|
|
1306
955
|
let directory = path.posix.dirname(file);
|
|
1307
956
|
while (true) {
|
|
@@ -1324,8 +973,8 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1324
973
|
patterns: workspace["packages"],
|
|
1325
974
|
rootMembership: "implicit"
|
|
1326
975
|
})) return void 0;
|
|
1327
|
-
if (name === "" || name === "default") return workspace["catalog"] ?? (record$
|
|
1328
|
-
return record$
|
|
976
|
+
if (name === "" || name === "default") return workspace["catalog"] ?? (record$7(workspace["catalogs"]) ? workspace["catalogs"]["default"] : void 0);
|
|
977
|
+
return record$7(workspace["catalogs"]) ? workspace["catalogs"][name] : void 0;
|
|
1329
978
|
}
|
|
1330
979
|
let directory = path.posix.dirname(file);
|
|
1331
980
|
while (true) {
|
|
@@ -1333,7 +982,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1333
982
|
if (manifest !== void 0) {
|
|
1334
983
|
for (const source of catalogSources(manifest)) {
|
|
1335
984
|
if (name === "" && source["catalog"] !== void 0) return source["catalog"];
|
|
1336
|
-
if (record$
|
|
985
|
+
if (record$7(source["catalogs"]) && source["catalogs"][name] !== void 0) return source["catalogs"][name];
|
|
1337
986
|
}
|
|
1338
987
|
if (manifest["workspaces"] !== void 0) return void 0;
|
|
1339
988
|
}
|
|
@@ -1347,7 +996,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1347
996
|
if (visited.has(value)) return void 0;
|
|
1348
997
|
visited.add(value);
|
|
1349
998
|
const catalog = catalogFor(file, value.slice(8));
|
|
1350
|
-
value = record$
|
|
999
|
+
value = record$7(catalog) ? catalog[name] : void 0;
|
|
1351
1000
|
}
|
|
1352
1001
|
return value;
|
|
1353
1002
|
};
|
|
@@ -1363,7 +1012,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1363
1012
|
const workspaces = manifests.get(path.posix.join(directory, "package.json"))?.["workspaces"];
|
|
1364
1013
|
if (workspaces !== void 0) return {
|
|
1365
1014
|
directory,
|
|
1366
|
-
patterns: record$
|
|
1015
|
+
patterns: record$7(workspaces) ? workspaces["packages"] : workspaces,
|
|
1367
1016
|
source: "json"
|
|
1368
1017
|
};
|
|
1369
1018
|
if (directory === ".") return void 0;
|
|
@@ -1419,7 +1068,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1419
1068
|
"peerDependencies"
|
|
1420
1069
|
]) {
|
|
1421
1070
|
const dependencies = json[section];
|
|
1422
|
-
if (!record$
|
|
1071
|
+
if (!record$7(dependencies)) continue;
|
|
1423
1072
|
for (const [name, value] of Object.entries(dependencies)) {
|
|
1424
1073
|
if (!tsSpecifiers.has(name)) continue;
|
|
1425
1074
|
const resolved = resolve(file, name, value);
|
|
@@ -1481,7 +1130,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1481
1130
|
message: `packageManager Bun version must be ${policy.bun}, found ${JSON.stringify(manager)}`
|
|
1482
1131
|
});
|
|
1483
1132
|
const checkEntries = (entries, location) => {
|
|
1484
|
-
if (!record$
|
|
1133
|
+
if (!record$7(entries)) return;
|
|
1485
1134
|
for (const [name, raw] of Object.entries(entries)) {
|
|
1486
1135
|
const value = resolve(file, name, raw);
|
|
1487
1136
|
const tsAllowed = tsSpecifiers.get(name);
|
|
@@ -1518,12 +1167,12 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1518
1167
|
"devDependencies",
|
|
1519
1168
|
"optionalDependencies"
|
|
1520
1169
|
]) checkEntries(json[key]);
|
|
1521
|
-
if (record$
|
|
1170
|
+
if (record$7(json["peerDependencies"])) {
|
|
1522
1171
|
for (const [name, value] of Object.entries(json["peerDependencies"])) if (tsSpecifiers.has(name) && !peerRange(resolve(file, name, value))) checkEntries({ [name]: value });
|
|
1523
1172
|
}
|
|
1524
1173
|
for (const source of catalogSources(json)) {
|
|
1525
1174
|
checkEntries(source["catalog"]);
|
|
1526
|
-
if (!record$
|
|
1175
|
+
if (!record$7(source["catalogs"])) continue;
|
|
1527
1176
|
for (const catalog of Object.values(source["catalogs"])) checkEntries(catalog);
|
|
1528
1177
|
}
|
|
1529
1178
|
const ownedNames = /* @__PURE__ */ new Set([...pins.keys(), ...tsSpecifiers.keys()]);
|
|
@@ -1535,7 +1184,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1535
1184
|
"optionalDependencies"
|
|
1536
1185
|
]) {
|
|
1537
1186
|
const entries = resolutionRoot[section];
|
|
1538
|
-
if (!record$
|
|
1187
|
+
if (!record$7(entries)) continue;
|
|
1539
1188
|
for (const [name, value] of Object.entries(entries)) resolutionDependencies[name] = resolve(file, name, value);
|
|
1540
1189
|
}
|
|
1541
1190
|
const affectedSpecifiers = /* @__PURE__ */ new Map();
|
|
@@ -1555,7 +1204,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1555
1204
|
"optionalDependencies"
|
|
1556
1205
|
]) {
|
|
1557
1206
|
const entries = member[section];
|
|
1558
|
-
if (!record$
|
|
1207
|
+
if (!record$7(entries)) continue;
|
|
1559
1208
|
for (const [name, value] of Object.entries(entries)) {
|
|
1560
1209
|
if (!tsSpecifiers.has(name)) continue;
|
|
1561
1210
|
const values = affectedSpecifiers.get(name) ?? /* @__PURE__ */ new Set();
|
|
@@ -1565,7 +1214,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1565
1214
|
}
|
|
1566
1215
|
}
|
|
1567
1216
|
const checkResolutionMap = (entries, parent) => {
|
|
1568
|
-
if (!record$
|
|
1217
|
+
if (!record$7(entries)) return;
|
|
1569
1218
|
for (const [selector, replacement] of Object.entries(entries)) {
|
|
1570
1219
|
const target = selector === "." ? parent : selector;
|
|
1571
1220
|
if (target === void 0) continue;
|
|
@@ -1588,7 +1237,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1588
1237
|
});
|
|
1589
1238
|
continue;
|
|
1590
1239
|
}
|
|
1591
|
-
if (record$
|
|
1240
|
+
if (record$7(replacement)) {
|
|
1592
1241
|
checkResolutionMap(replacement, target);
|
|
1593
1242
|
continue;
|
|
1594
1243
|
}
|
|
@@ -1623,7 +1272,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1623
1272
|
};
|
|
1624
1273
|
checkResolutionMap(json["overrides"]);
|
|
1625
1274
|
checkResolutionMap(json["resolutions"]);
|
|
1626
|
-
if (record$
|
|
1275
|
+
if (record$7(json["pnpm"])) checkResolutionMap(json["pnpm"]["overrides"]);
|
|
1627
1276
|
const localEntries = toolchainEntries(file, json);
|
|
1628
1277
|
const usesCompiler = policy.typescriptInstallLayouts.some((layout) => localEntries.some(({ name }) => name === layout.compilerPackage));
|
|
1629
1278
|
let selectedLayout = layoutFor(specifierMap(localEntries));
|
|
@@ -1647,7 +1296,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1647
1296
|
key: "dependencies",
|
|
1648
1297
|
message: "TypeScript compiler and compatibility packages must match one complete declared install layout"
|
|
1649
1298
|
});
|
|
1650
|
-
const command = record$
|
|
1299
|
+
const command = record$7(json["scripts"]) ? json["scripts"]["typecheck"] : void 0;
|
|
1651
1300
|
if (selectedLayout !== void 0 && typeof command === "string") {
|
|
1652
1301
|
const normalizedExpected = selectedLayout.typecheckCommand.replace(/\s+/g, " ").trim();
|
|
1653
1302
|
for (const words of compilerCommandSegments(command)) {
|
|
@@ -1665,7 +1314,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1665
1314
|
}
|
|
1666
1315
|
}
|
|
1667
1316
|
}
|
|
1668
|
-
if (record$
|
|
1317
|
+
if (record$7(json["peerDependencies"])) {
|
|
1669
1318
|
const peerLayout = selectedLayout ?? workspaceLayoutFor(file)?.layout;
|
|
1670
1319
|
for (const [name, raw] of Object.entries(json["peerDependencies"])) {
|
|
1671
1320
|
if (!tsSpecifiers.has(name)) continue;
|
|
@@ -1689,7 +1338,7 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1689
1338
|
});
|
|
1690
1339
|
}
|
|
1691
1340
|
}
|
|
1692
|
-
if (record$
|
|
1341
|
+
if (record$7(json["engines"]) && json["engines"]["node"] !== void 0 && (typeof json["engines"]["node"] !== "string" || !nodeSupportRangeMatches(policy.node, json["engines"]["node"]))) add({
|
|
1693
1342
|
file,
|
|
1694
1343
|
rule: "node-engine",
|
|
1695
1344
|
key: "node",
|
|
@@ -1699,16 +1348,633 @@ const checkPackageFiles = ({ files, policy }) => {
|
|
|
1699
1348
|
}
|
|
1700
1349
|
return diagnostics;
|
|
1701
1350
|
};
|
|
1351
|
+
const extensionKinds = new Map(Object.entries({
|
|
1352
|
+
".js": "javascript",
|
|
1353
|
+
".jsx": "javascript",
|
|
1354
|
+
".mjs": "javascript",
|
|
1355
|
+
".cjs": "javascript",
|
|
1356
|
+
".ts": "typescript",
|
|
1357
|
+
".tsx": "typescript",
|
|
1358
|
+
".mts": "typescript",
|
|
1359
|
+
".cts": "typescript"
|
|
1360
|
+
}));
|
|
1361
|
+
/** Share source classification between lint ownership and script command discovery. */
|
|
1362
|
+
const scriptSourceKind = (file) => extensionKinds.get(extname(file));
|
|
1363
|
+
//#endregion
|
|
1364
|
+
//#region src/toolchain-script-lifecycle.ts
|
|
1365
|
+
const record$6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1366
|
+
const declaredManager = (value) => typeof value === "string" ? /^(bun|npm|pnpm|yarn)@(\d+\.\d+\.\d+)(?:\+\S+)?$/u.exec(value) : null;
|
|
1367
|
+
const rootScriptManager = (manifest, context) => declaredManager(context.packageManager ?? (record$6(manifest) ? manifest["packageManager"] : void 0))?.at(1);
|
|
1368
|
+
const npmHooksEnabled = (file) => {
|
|
1369
|
+
if (file?.type === "unknown") throw new Error("npm lifecycle configuration must be a tracked regular file");
|
|
1370
|
+
if (file?.type !== "tracked") return true;
|
|
1371
|
+
let enabled = true;
|
|
1372
|
+
let section = false;
|
|
1373
|
+
for (const raw of file.source.split(/\r?\n/u)) {
|
|
1374
|
+
const line = raw.trim();
|
|
1375
|
+
if (line.startsWith("[")) {
|
|
1376
|
+
section = true;
|
|
1377
|
+
continue;
|
|
1378
|
+
}
|
|
1379
|
+
if (section || !/^ignore-scripts(?:\s*=|\s*$)/iu.test(line)) continue;
|
|
1380
|
+
if (!/^ignore-scripts(?:\s*=|\s*$)/u.test(line)) throw new Error("npm ignore-scripts must use its canonical lowercase key");
|
|
1381
|
+
const value = line.slice(line.indexOf("=") + 1).trim();
|
|
1382
|
+
if (value !== "true" && value !== "false") throw new Error("npm ignore-scripts must be a literal boolean for lifecycle discovery");
|
|
1383
|
+
enabled = value === "false";
|
|
1384
|
+
}
|
|
1385
|
+
return enabled;
|
|
1386
|
+
};
|
|
1387
|
+
const yamlSettings = (file, manager) => {
|
|
1388
|
+
if (file?.type === "unknown") throw new Error(`${manager} lifecycle configuration requires tracked regular root files without nested workspace overrides`);
|
|
1389
|
+
if (file?.type !== "tracked") return {};
|
|
1390
|
+
const document = parseDocument(file.source);
|
|
1391
|
+
if (document.errors.length > 0) throw new Error(`Cannot parse ${manager} lifecycle configuration`);
|
|
1392
|
+
let settings;
|
|
1393
|
+
try {
|
|
1394
|
+
settings = document.toJS();
|
|
1395
|
+
} catch {
|
|
1396
|
+
throw new Error(`Cannot parse ${manager} lifecycle configuration`);
|
|
1397
|
+
}
|
|
1398
|
+
if (!record$6(settings)) throw new Error(`${manager} lifecycle configuration must be a mapping`);
|
|
1399
|
+
return settings;
|
|
1400
|
+
};
|
|
1401
|
+
const pnpmHooksEnabled = (manifest, context) => {
|
|
1402
|
+
const declared = declaredManager(context.packageManager ?? manifest["packageManager"]);
|
|
1403
|
+
const dependency = [manifest["dependencies"], manifest["devDependencies"]].flatMap((field) => record$6(field) ? [field["pnpm"]] : []).find((value) => typeof value === "string");
|
|
1404
|
+
if ((declared?.at(1) === "pnpm" ? declared.at(2) : dependency) !== "12.9.1") throw new Error("pnpm lifecycle discovery requires declared pnpm@12.9.1");
|
|
1405
|
+
const enabled = yamlSettings(context.pnpmWorkspace, "pnpm")["enablePrePostScripts"];
|
|
1406
|
+
if (enabled === void 0) return true;
|
|
1407
|
+
if (typeof enabled !== "boolean") throw new Error("pnpm enablePrePostScripts must be a literal boolean");
|
|
1408
|
+
return enabled;
|
|
1409
|
+
};
|
|
1410
|
+
/** Automatic pre/post stages run their bodies directly, without pre-pre recursion. */
|
|
1411
|
+
const scriptLifecycleStages = ({ name, manager, manifest, scripts, context }) => {
|
|
1412
|
+
const present = [`pre${name}`, `post${name}`].filter((hook) => scripts[hook] !== void 0 && scripts[hook] !== "");
|
|
1413
|
+
if (present.length === 0) return [name];
|
|
1414
|
+
if (present.some((hook) => typeof scripts[hook] !== "string")) throw new Error(`Lifecycle hooks for ${name} must be literal package scripts`);
|
|
1415
|
+
let enabled;
|
|
1416
|
+
switch (manager) {
|
|
1417
|
+
case "npm":
|
|
1418
|
+
enabled = npmHooksEnabled(context.npmrc);
|
|
1419
|
+
break;
|
|
1420
|
+
case "bun":
|
|
1421
|
+
enabled = true;
|
|
1422
|
+
break;
|
|
1423
|
+
case "pnpm":
|
|
1424
|
+
enabled = pnpmHooksEnabled(manifest, context);
|
|
1425
|
+
break;
|
|
1426
|
+
case "yarn": {
|
|
1427
|
+
const declaration = declaredManager(context.packageManager ?? manifest["packageManager"]);
|
|
1428
|
+
if (declaration?.at(1) !== "yarn" || !/^[234]\./u.test(declaration.at(2) ?? "")) throw new Error("Yarn lifecycle discovery requires a declared Berry version (2, 3 or 4)");
|
|
1429
|
+
const settings = yamlSettings(context.yarnrc, "Yarn");
|
|
1430
|
+
if (settings["yarnPath"] !== void 0 && settings["yarnPath"] !== null || settings["plugins"] !== void 0 && (!Array.isArray(settings["plugins"]) || settings["plugins"].length > 0)) throw new Error("Custom Yarn executables or plugins require explicit lifecycle discovery support");
|
|
1431
|
+
enabled = false;
|
|
1432
|
+
break;
|
|
1433
|
+
}
|
|
1434
|
+
default: throw new Error(`Cannot determine the package manager for lifecycle hooks of ${name}`);
|
|
1435
|
+
}
|
|
1436
|
+
if (!enabled) return [name];
|
|
1437
|
+
const source = scripts[name];
|
|
1438
|
+
const include = (hook) => present.includes(hook) && !(manager === "pnpm" && typeof source === "string" && source.includes(hook));
|
|
1439
|
+
return [
|
|
1440
|
+
...include(`pre${name}`) ? [`pre${name}`] : [],
|
|
1441
|
+
name,
|
|
1442
|
+
...include(`post${name}`) ? [`post${name}`] : []
|
|
1443
|
+
];
|
|
1444
|
+
};
|
|
1445
|
+
//#endregion
|
|
1446
|
+
//#region src/toolchain-lint-command.ts
|
|
1447
|
+
const record$5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1448
|
+
const scriptManagers = /* @__PURE__ */ new Set([
|
|
1449
|
+
"bun",
|
|
1450
|
+
"npm",
|
|
1451
|
+
"pnpm",
|
|
1452
|
+
"yarn"
|
|
1453
|
+
]);
|
|
1454
|
+
const valueFlags = /* @__PURE__ */ new Set([
|
|
1455
|
+
"-c",
|
|
1456
|
+
"--config",
|
|
1457
|
+
"--tsconfig",
|
|
1458
|
+
"--ignore-path",
|
|
1459
|
+
"--ignore-pattern",
|
|
1460
|
+
"-A",
|
|
1461
|
+
"--allow",
|
|
1462
|
+
"-W",
|
|
1463
|
+
"--warn",
|
|
1464
|
+
"-D",
|
|
1465
|
+
"--deny",
|
|
1466
|
+
"-f",
|
|
1467
|
+
"--format",
|
|
1468
|
+
"--max-warnings",
|
|
1469
|
+
"--threads",
|
|
1470
|
+
"--report-unused-disable-directives-severity"
|
|
1471
|
+
]);
|
|
1472
|
+
const booleanFlags = /* @__PURE__ */ new Set([
|
|
1473
|
+
"--no-ignore",
|
|
1474
|
+
"--quiet",
|
|
1475
|
+
"--deny-warnings",
|
|
1476
|
+
"--silent",
|
|
1477
|
+
"--no-error-on-unmatched-pattern",
|
|
1478
|
+
"--disable-nested-config",
|
|
1479
|
+
"--report-unused-disable-directives",
|
|
1480
|
+
"--disable-unicorn-plugin",
|
|
1481
|
+
"--disable-oxc-plugin",
|
|
1482
|
+
"--disable-typescript-plugin",
|
|
1483
|
+
"--import-plugin",
|
|
1484
|
+
"--react-plugin",
|
|
1485
|
+
"--jsdoc-plugin",
|
|
1486
|
+
"--jest-plugin",
|
|
1487
|
+
"--vitest-plugin",
|
|
1488
|
+
"--jsx-a11y-plugin",
|
|
1489
|
+
"--nextjs-plugin",
|
|
1490
|
+
"--react-perf-plugin",
|
|
1491
|
+
"--promise-plugin",
|
|
1492
|
+
"--node-plugin",
|
|
1493
|
+
"--vue-plugin"
|
|
1494
|
+
]);
|
|
1495
|
+
const literalWord = (raw) => {
|
|
1496
|
+
let quote;
|
|
1497
|
+
for (let index = 0; index < raw.length; index++) {
|
|
1498
|
+
const character = raw.at(index);
|
|
1499
|
+
if (character === "\\" && quote !== "'") {
|
|
1500
|
+
index++;
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
if (character === quote) {
|
|
1504
|
+
quote = void 0;
|
|
1505
|
+
continue;
|
|
1506
|
+
}
|
|
1507
|
+
if (quote === void 0 && (character === "'" || character === "\"")) {
|
|
1508
|
+
quote = character;
|
|
1509
|
+
continue;
|
|
1510
|
+
}
|
|
1511
|
+
if (quote !== "'" && (character === "$" || character === "`")) return false;
|
|
1512
|
+
if (quote === void 0 && character !== void 0 && /[*?[\]{}~]/.test(character)) return false;
|
|
1513
|
+
}
|
|
1514
|
+
return quote === void 0;
|
|
1515
|
+
};
|
|
1516
|
+
const inventoryArguments = (raw) => {
|
|
1517
|
+
const args = [];
|
|
1518
|
+
let threadsSeen = false;
|
|
1519
|
+
for (let index = 0; index < raw.length; index++) {
|
|
1520
|
+
const word = raw.at(index);
|
|
1521
|
+
if (word === void 0) break;
|
|
1522
|
+
if (!literalWord(word)) return { error: "oxlint arguments must be literal shell words" };
|
|
1523
|
+
const value = decodeShellWord(word);
|
|
1524
|
+
if (!value.startsWith("-")) {
|
|
1525
|
+
args.push(value);
|
|
1526
|
+
continue;
|
|
1527
|
+
}
|
|
1528
|
+
if (value === "--") return { error: "oxlint argument terminators are unsupported for inventory" };
|
|
1529
|
+
if (value === "--type-aware" || value === "--type-check") continue;
|
|
1530
|
+
const equals = value.indexOf("=");
|
|
1531
|
+
const flag = equals < 0 ? value : value.slice(0, equals);
|
|
1532
|
+
if (booleanFlags.has(flag)) {
|
|
1533
|
+
if (equals >= 0) return { error: `unexpected value for oxlint flag ${flag}` };
|
|
1534
|
+
args.push(value);
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
if (!valueFlags.has(flag)) return { error: `unsupported oxlint flag ${flag}` };
|
|
1538
|
+
let argument;
|
|
1539
|
+
if (equals >= 0) {
|
|
1540
|
+
argument = value.slice(equals + 1);
|
|
1541
|
+
if (argument === "") return { error: `missing value for oxlint flag ${flag}` };
|
|
1542
|
+
} else {
|
|
1543
|
+
const next = raw.at(++index);
|
|
1544
|
+
if (next === void 0 || !literalWord(next) || decodeShellWord(next).startsWith("-")) return { error: `missing or nonliteral value for oxlint flag ${flag}` };
|
|
1545
|
+
argument = decodeShellWord(next);
|
|
1546
|
+
}
|
|
1547
|
+
if (flag === "--threads") {
|
|
1548
|
+
if (threadsSeen) return { error: "duplicate oxlint flag --threads" };
|
|
1549
|
+
if (!/^\+?[0-9]+$/u.test(argument) || BigInt(argument) > 18446744073709551615n) return { error: "invalid integer value for oxlint flag --threads" };
|
|
1550
|
+
threadsSeen = true;
|
|
1551
|
+
continue;
|
|
1552
|
+
}
|
|
1553
|
+
if (equals >= 0) args.push(value);
|
|
1554
|
+
else args.push(value, argument);
|
|
1555
|
+
}
|
|
1556
|
+
return { args };
|
|
1557
|
+
};
|
|
1558
|
+
/** Extract runtime and arguments for the pinned inventory binary; never execute package-script shell text. */
|
|
1559
|
+
const lintInventoryCommands = (manifest, forceEnabled = false, context = {}) => {
|
|
1560
|
+
const commands = [];
|
|
1561
|
+
const errors = [];
|
|
1562
|
+
const workspaceTasks = /* @__PURE__ */ new Set();
|
|
1563
|
+
const filteredBuilds = /* @__PURE__ */ new Set();
|
|
1564
|
+
const declaresEngine = record$5(manifest) && [manifest["dependencies"], manifest["devDependencies"]].some((dependencies) => record$5(dependencies) && "oxlint-tsgolint" in dependencies);
|
|
1565
|
+
const enabled = forceEnabled || declaresEngine;
|
|
1566
|
+
if (!enabled) return {
|
|
1567
|
+
commands,
|
|
1568
|
+
errors,
|
|
1569
|
+
enabled,
|
|
1570
|
+
workspaceTask: false
|
|
1571
|
+
};
|
|
1572
|
+
if (!record$5(manifest)) return {
|
|
1573
|
+
commands,
|
|
1574
|
+
errors: ["lint inventory requires an object package manifest"],
|
|
1575
|
+
enabled,
|
|
1576
|
+
workspaceTask: false
|
|
1577
|
+
};
|
|
1578
|
+
const scripts = manifest["scripts"];
|
|
1579
|
+
if (!record$5(scripts)) return {
|
|
1580
|
+
commands,
|
|
1581
|
+
errors: ["type-aware linting requires a root lint script"],
|
|
1582
|
+
enabled,
|
|
1583
|
+
workspaceTask: false
|
|
1584
|
+
};
|
|
1585
|
+
const active = /* @__PURE__ */ new Set();
|
|
1586
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1587
|
+
const visit = (name) => {
|
|
1588
|
+
if (active.has(name)) {
|
|
1589
|
+
errors.push(`cyclic lint script alias: ${name}`);
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
if (visited.has(name)) return;
|
|
1593
|
+
const source = scripts[name];
|
|
1594
|
+
if (typeof source !== "string") {
|
|
1595
|
+
errors.push(`missing literal package script: ${name}`);
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
active.add(name);
|
|
1599
|
+
for (const raw of shellCommandSegments(source)) {
|
|
1600
|
+
if (raw.length === 0) continue;
|
|
1601
|
+
const words = raw.map(decodeShellWord);
|
|
1602
|
+
const first = words.at(0);
|
|
1603
|
+
if (first === "cd" || first === "pushd" || first === "popd") {
|
|
1604
|
+
errors.push(`${name}: changing directories is unsupported for lint inventory`);
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1607
|
+
if (first === "echo" || first === "printf") continue;
|
|
1608
|
+
if (first === "turbo") {
|
|
1609
|
+
if (words.length === 3 && words.at(1) === "run" && words.at(2) === "lint" && raw.every(literalWord)) workspaceTasks.add(name);
|
|
1610
|
+
else if (words.includes("lint") || !raw.every(literalWord)) errors.push(`${name}: workspace lint delegation requires literal turbo run lint without options`);
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
if (first === "bun" && words.length === 4 && words.at(1) === "--filter" && words.at(2) !== "" && !words.at(2)?.startsWith("-") && words.at(3) === "build" && raw.every(literalWord)) {
|
|
1614
|
+
const selector = words.at(2);
|
|
1615
|
+
try {
|
|
1616
|
+
if (selector === void 0 || context.assertFilteredBunBuild === void 0) throw new Error("Filtered Bun builds require verified workspace lifecycle context");
|
|
1617
|
+
context.assertFilteredBunBuild(selector);
|
|
1618
|
+
filteredBuilds.add(selector);
|
|
1619
|
+
} catch (error) {
|
|
1620
|
+
errors.push(error instanceof Error ? error.message : "Cannot determine filtered build lifecycle stages");
|
|
1621
|
+
}
|
|
1622
|
+
continue;
|
|
1623
|
+
}
|
|
1624
|
+
if (first !== void 0 && scriptManagers.has(first) && words.at(1) === "run") {
|
|
1625
|
+
const target = words.at(2);
|
|
1626
|
+
if (target !== void 0 && first === "bun" && scriptSourceKind(target) !== void 0 && typeof scripts[target] !== "string") {
|
|
1627
|
+
if (!raw.every(literalWord)) errors.push(`${name}: validation file commands require literal arguments`);
|
|
1628
|
+
continue;
|
|
1629
|
+
}
|
|
1630
|
+
if (raw.length !== 3 || !raw.every(literalWord)) {
|
|
1631
|
+
errors.push(`${name}: package script aliases must have one literal name`);
|
|
1632
|
+
continue;
|
|
1633
|
+
}
|
|
1634
|
+
const alias = words.at(2);
|
|
1635
|
+
if (alias !== void 0) invoke({
|
|
1636
|
+
name: alias,
|
|
1637
|
+
manager: first
|
|
1638
|
+
});
|
|
1639
|
+
continue;
|
|
1640
|
+
}
|
|
1641
|
+
let offset;
|
|
1642
|
+
if (first === "oxlint" || first === "./node_modules/.bin/oxlint" || first === "node_modules/.bin/oxlint") offset = 1;
|
|
1643
|
+
else if (first === "bun" && words.at(1) === "--bun" && words.at(2) === "oxlint") offset = 3;
|
|
1644
|
+
else if (first === "bunx" && words.at(1) === "oxlint") offset = 2;
|
|
1645
|
+
else if (first === "bunx" && words.at(1) === "--no-install" && words.at(2) === "oxlint") offset = 3;
|
|
1646
|
+
if (offset === void 0) {
|
|
1647
|
+
if (words.some((word) => /(?:^|\/)oxlint(?:@[^/]+)?$/.test(word)) || words.some((word, index) => scriptManagers.has(word) && words.slice(index + 1).includes("run")) || words.includes("turbo") && words.includes("lint") || first === "bun" && words.includes("--filter") || first !== void 0 && scriptManagers.has(first) && !(first === "bun" && [
|
|
1648
|
+
"test",
|
|
1649
|
+
"build",
|
|
1650
|
+
"check",
|
|
1651
|
+
"install",
|
|
1652
|
+
"x"
|
|
1653
|
+
].includes(words.at(1) ?? "")) && (words.slice(1).some((word) => typeof scripts[word] === "string") || !raw.every(literalWord)) || raw.at(0) !== void 0 && !literalWord(raw.at(0) ?? "")) errors.push(`${name}: unsupported or dynamic oxlint launcher`);
|
|
1654
|
+
continue;
|
|
1655
|
+
}
|
|
1656
|
+
if (!raw.slice(0, offset).every(literalWord)) {
|
|
1657
|
+
errors.push(`${name}: oxlint launcher must be literal`);
|
|
1658
|
+
continue;
|
|
1659
|
+
}
|
|
1660
|
+
const inventory = inventoryArguments(raw.slice(offset));
|
|
1661
|
+
if (inventory.error !== void 0) errors.push(`${name}: ${inventory.error}`);
|
|
1662
|
+
else commands.push({
|
|
1663
|
+
runtime: first === "bun" ? "bun" : "node",
|
|
1664
|
+
args: inventory.args
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
active.delete(name);
|
|
1668
|
+
visited.add(name);
|
|
1669
|
+
};
|
|
1670
|
+
const activeInvocations = /* @__PURE__ */ new Set();
|
|
1671
|
+
const invoke = ({ name, manager }) => {
|
|
1672
|
+
const key = `${manager ?? "unknown"}:${name}`;
|
|
1673
|
+
if (activeInvocations.has(key)) {
|
|
1674
|
+
errors.push(`cyclic lint script alias: ${name}`);
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
activeInvocations.add(key);
|
|
1678
|
+
try {
|
|
1679
|
+
const stages = scriptLifecycleStages({
|
|
1680
|
+
name,
|
|
1681
|
+
manager,
|
|
1682
|
+
manifest,
|
|
1683
|
+
scripts,
|
|
1684
|
+
context
|
|
1685
|
+
});
|
|
1686
|
+
for (const stage of stages) visit(stage);
|
|
1687
|
+
} catch (error) {
|
|
1688
|
+
errors.push(error instanceof Error ? error.message : "Cannot determine script lifecycle stages");
|
|
1689
|
+
} finally {
|
|
1690
|
+
activeInvocations.delete(key);
|
|
1691
|
+
}
|
|
1692
|
+
};
|
|
1693
|
+
invoke({
|
|
1694
|
+
name: context.entryScript ?? "lint",
|
|
1695
|
+
manager: rootScriptManager(manifest, context)
|
|
1696
|
+
});
|
|
1697
|
+
const workspaceTask = workspaceTasks.size > 0;
|
|
1698
|
+
if (!declaresEngine && commands.length === 0 && !workspaceTask && filteredBuilds.size === 0 && errors.length === 0) return {
|
|
1699
|
+
commands,
|
|
1700
|
+
errors,
|
|
1701
|
+
enabled: false,
|
|
1702
|
+
workspaceTask
|
|
1703
|
+
};
|
|
1704
|
+
if (commands.length === 0 && !workspaceTask && filteredBuilds.size === 0 && context.entryScript === void 0) errors.push("root lint scripts contain no supported oxlint invocation");
|
|
1705
|
+
return {
|
|
1706
|
+
commands: errors.length === 0 ? commands : [],
|
|
1707
|
+
errors,
|
|
1708
|
+
enabled,
|
|
1709
|
+
workspaceTask: errors.length === 0 && workspaceTask
|
|
1710
|
+
};
|
|
1711
|
+
};
|
|
1712
|
+
//#endregion
|
|
1713
|
+
//#region src/toolchain-node-projects.ts
|
|
1714
|
+
const nodeProjectRule = "type-aware-projects";
|
|
1715
|
+
const checkProjectOwnership = ({ trackedFiles, lintedFiles, projectFiles }) => [...new Set(lintedFiles)].filter((file) => scriptSourceKind(file) !== void 0 && trackedFiles.has(file) && !projectFiles.has(file)).sort((left, right) => left.localeCompare(right)).map((file) => ({
|
|
1716
|
+
rule: nodeProjectRule,
|
|
1717
|
+
path: file,
|
|
1718
|
+
line: 1,
|
|
1719
|
+
message: "type-aware lint would use an inferred project; include this file in a declared tsconfig project (for Node scripts, add scripts/tsconfig.json extending @stll/typescript-config/node.json; see the Node scripts recipe in stella/tooling README)"
|
|
1720
|
+
}));
|
|
1721
|
+
const record$4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1722
|
+
const stringList = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
1723
|
+
const readCommand = ({ root, executable, args, runtime }) => {
|
|
1724
|
+
const result = spawnSync(runtime, [
|
|
1725
|
+
...runtime === "bun" ? ["--bun"] : [],
|
|
1726
|
+
executable,
|
|
1727
|
+
...args
|
|
1728
|
+
], {
|
|
1729
|
+
cwd: root,
|
|
1730
|
+
encoding: "utf8",
|
|
1731
|
+
timeout: 3e4,
|
|
1732
|
+
maxBuffer: 33554432
|
|
1733
|
+
});
|
|
1734
|
+
if (result.error !== void 0) throw result.error;
|
|
1735
|
+
if (result.status !== 0) throw new Error(`configuration discovery failed: ${(result.stderr + result.stdout).trim()}`);
|
|
1736
|
+
return result.stdout;
|
|
1737
|
+
};
|
|
1738
|
+
const relativePath = (root, file) => path.relative(root, path.resolve(root, file)).split(path.sep).join("/");
|
|
1739
|
+
const lifecycleFile = (root, file, tracked) => {
|
|
1740
|
+
try {
|
|
1741
|
+
const location = path.join(root, file);
|
|
1742
|
+
const metadata = lstatSync(location);
|
|
1743
|
+
if (!tracked.has(file) || !metadata.isFile()) return { type: "unknown" };
|
|
1744
|
+
return {
|
|
1745
|
+
type: "tracked",
|
|
1746
|
+
source: readFileSync(location, "utf8")
|
|
1747
|
+
};
|
|
1748
|
+
} catch (error) {
|
|
1749
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return { type: "absent" };
|
|
1750
|
+
return { type: "unknown" };
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
/** Inventory and config expansion only: neither subprocess lints or typechecks. */
|
|
1754
|
+
const checkNodeProjects = ({ root, manifest, trackedFiles }) => {
|
|
1755
|
+
const packageManager = record$4(manifest) ? manifest["packageManager"] : void 0;
|
|
1756
|
+
const managerUsesPnpmWorkspace = packageManager === void 0 || typeof packageManager === "string" && packageManager.startsWith("pnpm@");
|
|
1757
|
+
const discovered = /* @__PURE__ */ new Map();
|
|
1758
|
+
const workspaceMembers = (pnpmMembership) => {
|
|
1759
|
+
const cached = discovered.get(pnpmMembership);
|
|
1760
|
+
if (cached !== void 0) return cached;
|
|
1761
|
+
const files = { "package.json": JSON.stringify(manifest) };
|
|
1762
|
+
for (const file of trackedFiles) {
|
|
1763
|
+
const name = path.posix.basename(file);
|
|
1764
|
+
if (file !== "package.json" && (name === "package.json" || pnpmMembership && name === "pnpm-workspace.yaml") && !file.split("/").includes("node_modules")) files[file] = readFileSync(path.join(root, file), "utf8");
|
|
1765
|
+
}
|
|
1766
|
+
const result = discoverConsumerManifests(files);
|
|
1767
|
+
discovered.set(pnpmMembership, result);
|
|
1768
|
+
return result;
|
|
1769
|
+
};
|
|
1770
|
+
const filteredCommands = [];
|
|
1771
|
+
const activeBuilds = /* @__PURE__ */ new Set();
|
|
1772
|
+
const workspaceLifecycle = (directory) => {
|
|
1773
|
+
const nestedLifecycle = { ...lifecycle };
|
|
1774
|
+
for (const [key, name] of [
|
|
1775
|
+
["npmrc", ".npmrc"],
|
|
1776
|
+
["pnpmWorkspace", "pnpm-workspace.yaml"],
|
|
1777
|
+
["yarnrc", ".yarnrc.yml"]
|
|
1778
|
+
]) {
|
|
1779
|
+
let ancestor = directory;
|
|
1780
|
+
while (ancestor !== ".") {
|
|
1781
|
+
if (lifecycleFile(root, path.posix.join(ancestor, name), trackedFiles).type !== "absent") {
|
|
1782
|
+
nestedLifecycle[key] = { type: "unknown" };
|
|
1783
|
+
break;
|
|
1784
|
+
}
|
|
1785
|
+
ancestor = path.posix.dirname(ancestor);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return nestedLifecycle;
|
|
1789
|
+
};
|
|
1790
|
+
const lifecycle = {
|
|
1791
|
+
packageManager: record$4(manifest) ? manifest["packageManager"] : void 0,
|
|
1792
|
+
npmrc: lifecycleFile(root, ".npmrc", trackedFiles),
|
|
1793
|
+
pnpmWorkspace: lifecycleFile(root, "pnpm-workspace.yaml", trackedFiles),
|
|
1794
|
+
yarnrc: lifecycleFile(root, ".yarnrc.yml", trackedFiles),
|
|
1795
|
+
assertFilteredBunBuild: (selector) => {
|
|
1796
|
+
const selected = [...workspaceMembers(false).entries()].filter(([, pkg]) => pkg["name"] === selector);
|
|
1797
|
+
if (selected.length !== 1) throw new Error("Filtered Bun build requires one declared workspace package");
|
|
1798
|
+
const member = selected.at(0);
|
|
1799
|
+
if (member === void 0) throw new Error("Missing selected workspace");
|
|
1800
|
+
const [directory, pkg] = member;
|
|
1801
|
+
const scripts = pkg["scripts"];
|
|
1802
|
+
if (!record$4(scripts) || typeof scripts["build"] !== "string") throw new Error("Filtered Bun build requires a literal build script");
|
|
1803
|
+
if (["prebuild", "postbuild"].some((name) => scripts[name] !== void 0 && scripts[name] !== "")) throw new Error("Filtered Bun build lifecycle hooks are unsupported for lint inventory; invoke lint scopes explicitly");
|
|
1804
|
+
if (activeBuilds.has(directory)) throw new Error("Cyclic filtered Bun build delegation");
|
|
1805
|
+
activeBuilds.add(directory);
|
|
1806
|
+
try {
|
|
1807
|
+
const nested = lintInventoryCommands(pkg, true, {
|
|
1808
|
+
...workspaceLifecycle(directory),
|
|
1809
|
+
entryScript: "build"
|
|
1810
|
+
});
|
|
1811
|
+
if (nested.workspaceTask) throw new Error("Nested workspace lint delegation is unsupported in filtered builds");
|
|
1812
|
+
if (nested.errors.length > 0) throw new Error(`${directory}/package.json: ${nested.errors.join("; ")}`);
|
|
1813
|
+
for (const command of nested.commands) filteredCommands.push({
|
|
1814
|
+
cwd: path.join(root, directory),
|
|
1815
|
+
...command
|
|
1816
|
+
});
|
|
1817
|
+
} finally {
|
|
1818
|
+
activeBuilds.delete(directory);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
const inventory = lintInventoryCommands(manifest, false, lifecycle);
|
|
1823
|
+
if (!inventory.enabled) return [];
|
|
1824
|
+
const diagnostics = [];
|
|
1825
|
+
const addConfiguration = (file, message) => diagnostics.push({
|
|
1826
|
+
rule: nodeProjectRule,
|
|
1827
|
+
path: file,
|
|
1828
|
+
line: 1,
|
|
1829
|
+
message
|
|
1830
|
+
});
|
|
1831
|
+
for (const error of inventory.errors) addConfiguration("package.json", error);
|
|
1832
|
+
if (inventory.errors.length !== 0) return diagnostics;
|
|
1833
|
+
try {
|
|
1834
|
+
const require = createRequire(path.join(root, "package.json"));
|
|
1835
|
+
const oxlint = path.join(path.dirname(require.resolve("oxlint/package.json")), "bin/oxlint");
|
|
1836
|
+
const compiler = path.join(path.dirname(require.resolve("typescript/package.json")), "bin/tsc");
|
|
1837
|
+
const commands = inventory.commands.map((command) => ({
|
|
1838
|
+
cwd: root,
|
|
1839
|
+
...command
|
|
1840
|
+
}));
|
|
1841
|
+
if (inventory.workspaceTask) {
|
|
1842
|
+
for (const [directory, workspace] of workspaceMembers(managerUsesPnpmWorkspace)) {
|
|
1843
|
+
if (directory === ".") continue;
|
|
1844
|
+
const file = `${directory}/package.json`;
|
|
1845
|
+
if (!record$4(workspace["scripts"]) || workspace["scripts"]["lint"] === void 0) continue;
|
|
1846
|
+
const nestedLifecycle = workspaceLifecycle(directory);
|
|
1847
|
+
const nested = lintInventoryCommands(workspace, true, nestedLifecycle);
|
|
1848
|
+
if (nested.workspaceTask) throw new Error(`nested workspace lint delegation is unsupported: ${file}`);
|
|
1849
|
+
if (nested.errors.length > 0) throw new Error(`${file}: ${nested.errors.join("; ")}`);
|
|
1850
|
+
for (const command of nested.commands) commands.push({
|
|
1851
|
+
cwd: path.join(root, directory),
|
|
1852
|
+
...command
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
if (commands.length === 0 && filteredCommands.length === 0) throw new Error("workspace lint task has no declared oxlint commands");
|
|
1856
|
+
}
|
|
1857
|
+
commands.push(...filteredCommands);
|
|
1858
|
+
if (commands.length === 0) throw new Error("root lint scripts contain no supported oxlint invocation");
|
|
1859
|
+
const lintedFiles = commands.flatMap(({ cwd, args, runtime }) => readCommand({
|
|
1860
|
+
root: cwd,
|
|
1861
|
+
executable: oxlint,
|
|
1862
|
+
args: [
|
|
1863
|
+
...args,
|
|
1864
|
+
"--debug",
|
|
1865
|
+
"files",
|
|
1866
|
+
"--threads",
|
|
1867
|
+
"1"
|
|
1868
|
+
],
|
|
1869
|
+
runtime
|
|
1870
|
+
}).split(/\r?\n/).filter((file) => file !== "").map((file) => relativePath(root, path.resolve(cwd, file))));
|
|
1871
|
+
const nearestProject = (start) => {
|
|
1872
|
+
let directory = start;
|
|
1873
|
+
while (true) {
|
|
1874
|
+
const config = path.posix.join(directory, "tsconfig.json");
|
|
1875
|
+
if (trackedFiles.has(config)) return config;
|
|
1876
|
+
if (directory === ".") return void 0;
|
|
1877
|
+
directory = path.posix.dirname(directory);
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1881
|
+
for (const file of new Set(lintedFiles)) {
|
|
1882
|
+
if (!trackedFiles.has(file) || scriptSourceKind(file) === void 0) continue;
|
|
1883
|
+
const config = nearestProject(path.posix.dirname(file));
|
|
1884
|
+
if (config === void 0) continue;
|
|
1885
|
+
const group = groups.get(config);
|
|
1886
|
+
if (group === void 0) groups.set(config, [file]);
|
|
1887
|
+
else group.push(file);
|
|
1888
|
+
}
|
|
1889
|
+
const projects = /* @__PURE__ */ new Map();
|
|
1890
|
+
const readProject = (config) => {
|
|
1891
|
+
const cached = projects.get(config);
|
|
1892
|
+
if (cached !== void 0) return cached;
|
|
1893
|
+
const result = {
|
|
1894
|
+
files: /* @__PURE__ */ new Set(),
|
|
1895
|
+
references: []
|
|
1896
|
+
};
|
|
1897
|
+
try {
|
|
1898
|
+
const project = JSON.parse(readCommand({
|
|
1899
|
+
root,
|
|
1900
|
+
executable: compiler,
|
|
1901
|
+
args: [
|
|
1902
|
+
"--showConfig",
|
|
1903
|
+
"--project",
|
|
1904
|
+
config
|
|
1905
|
+
],
|
|
1906
|
+
runtime: "node"
|
|
1907
|
+
}));
|
|
1908
|
+
if (!record$4(project)) throw new Error("compiler configuration must be an object");
|
|
1909
|
+
const references = project["references"] ?? [];
|
|
1910
|
+
if (!Array.isArray(references)) throw new Error("compiler configuration references must be an array");
|
|
1911
|
+
for (const reference of references) {
|
|
1912
|
+
if (!record$4(reference) || typeof reference["path"] !== "string") throw new Error("compiler project reference requires a path");
|
|
1913
|
+
const target = relativePath(root, path.resolve(root, path.dirname(config), reference["path"]));
|
|
1914
|
+
const referencedConfig = target.endsWith(".json") ? target : path.posix.join(target, "tsconfig.json");
|
|
1915
|
+
if (!trackedFiles.has(referencedConfig)) throw new Error(`project reference is not tracked: ${referencedConfig}`);
|
|
1916
|
+
result.references.push(referencedConfig);
|
|
1917
|
+
}
|
|
1918
|
+
const sources = project["files"] ?? [];
|
|
1919
|
+
if (!stringList(sources)) throw new Error("compiler configuration did not return a files array");
|
|
1920
|
+
const options = project["compilerOptions"];
|
|
1921
|
+
for (const file of sources) {
|
|
1922
|
+
if (scriptSourceKind(file) === "javascript" && (!record$4(options) || options["allowJs"] !== true && options["checkJs"] !== true)) continue;
|
|
1923
|
+
result.files.add(relativePath(root, path.resolve(root, path.dirname(config), file)));
|
|
1924
|
+
}
|
|
1925
|
+
} catch (error) {
|
|
1926
|
+
result.files.clear();
|
|
1927
|
+
result.references.length = 0;
|
|
1928
|
+
addConfiguration(config, error instanceof Error ? error.message : String(error));
|
|
1929
|
+
}
|
|
1930
|
+
projects.set(config, result);
|
|
1931
|
+
return result;
|
|
1932
|
+
};
|
|
1933
|
+
const projectFiles = /* @__PURE__ */ new Set();
|
|
1934
|
+
for (const [nearest, sources] of groups) {
|
|
1935
|
+
const remaining = new Set(sources);
|
|
1936
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1937
|
+
let ancestor = nearest;
|
|
1938
|
+
while (ancestor !== void 0 && remaining.size > 0) {
|
|
1939
|
+
const pending = [ancestor];
|
|
1940
|
+
let config = pending.pop();
|
|
1941
|
+
while (config !== void 0 && remaining.size > 0) {
|
|
1942
|
+
if (!visited.has(config)) {
|
|
1943
|
+
visited.add(config);
|
|
1944
|
+
const project = readProject(config);
|
|
1945
|
+
for (const source of remaining) {
|
|
1946
|
+
if (!project.files.has(source)) continue;
|
|
1947
|
+
projectFiles.add(source);
|
|
1948
|
+
remaining.delete(source);
|
|
1949
|
+
}
|
|
1950
|
+
pending.push(...project.references);
|
|
1951
|
+
}
|
|
1952
|
+
config = pending.pop();
|
|
1953
|
+
}
|
|
1954
|
+
const directory = path.posix.dirname(ancestor);
|
|
1955
|
+
ancestor = directory === "." ? void 0 : nearestProject(path.posix.dirname(directory));
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
diagnostics.push(...checkProjectOwnership({
|
|
1959
|
+
trackedFiles,
|
|
1960
|
+
lintedFiles,
|
|
1961
|
+
projectFiles
|
|
1962
|
+
}));
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
addConfiguration("package.json", error instanceof Error ? error.message : String(error));
|
|
1965
|
+
}
|
|
1966
|
+
return diagnostics;
|
|
1967
|
+
};
|
|
1702
1968
|
//#endregion
|
|
1703
1969
|
//#region src/toolchain-rust.ts
|
|
1704
|
-
const record$
|
|
1970
|
+
const record$3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1705
1971
|
/** Exceptions authorize one immutable release, never a channel or an entire rule. */
|
|
1706
1972
|
const parseRustExceptions = (input, today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)) => {
|
|
1707
1973
|
if (input === void 0) return [];
|
|
1708
1974
|
if (!Array.isArray(input)) throw new Error("rustExceptions must be an array");
|
|
1709
1975
|
const pins = /* @__PURE__ */ new Set();
|
|
1710
1976
|
return input.map((entry) => {
|
|
1711
|
-
if (!record$
|
|
1977
|
+
if (!record$3(entry) || Object.keys(entry).length !== 4 || Object.keys(entry).some((key) => ![
|
|
1712
1978
|
"pin",
|
|
1713
1979
|
"reason",
|
|
1714
1980
|
"tracking",
|
|
@@ -1862,7 +2128,7 @@ const checkRustReferences = (options) => {
|
|
|
1862
2128
|
if (isShellScript(file, text)) shell(text);
|
|
1863
2129
|
if (/(?:^|\/)package\.json$/.test(file)) try {
|
|
1864
2130
|
const object = JSON.parse(text);
|
|
1865
|
-
if (record$
|
|
2131
|
+
if (record$3(object) && record$3(object["scripts"])) {
|
|
1866
2132
|
for (const [name, script] of Object.entries(object["scripts"])) if (typeof script === "string") shell(script, lineOf(`"${name}"`));
|
|
1867
2133
|
}
|
|
1868
2134
|
} catch {}
|
|
@@ -1873,7 +2139,7 @@ const checkRustReferences = (options) => {
|
|
|
1873
2139
|
const version = tag === void 0 ? void 0 : rustImageVersion(tag);
|
|
1874
2140
|
select(version, "Rust service image", lineOf(value));
|
|
1875
2141
|
} else if (Array.isArray(value)) value.forEach(images);
|
|
1876
|
-
else if (record$
|
|
2142
|
+
else if (record$3(value)) {
|
|
1877
2143
|
for (const [key, entry] of Object.entries(value)) if (key !== "name") images(entry);
|
|
1878
2144
|
}
|
|
1879
2145
|
};
|
|
@@ -1897,13 +2163,13 @@ const checkRustReferences = (options) => {
|
|
|
1897
2163
|
value.forEach(visit);
|
|
1898
2164
|
return;
|
|
1899
2165
|
}
|
|
1900
|
-
if (!record$
|
|
1901
|
-
if (record$
|
|
2166
|
+
if (!record$3(value)) return;
|
|
2167
|
+
if (record$3(value["env"]) && value["env"]["RUSTUP_TOOLCHAIN"] !== void 0) select(value["env"]["RUSTUP_TOOLCHAIN"], "RUSTUP_TOOLCHAIN", lineOf("RUSTUP_TOOLCHAIN"));
|
|
1902
2168
|
if (typeof value["run"] === "string") shell(value["run"], lineOf("run:"));
|
|
1903
2169
|
const uses = value["uses"];
|
|
1904
2170
|
if (typeof uses === "string") {
|
|
1905
2171
|
const action = uses.split("@").at(0)?.toLowerCase();
|
|
1906
|
-
const inputs = record$
|
|
2172
|
+
const inputs = record$3(value["with"]) ? value["with"] : {};
|
|
1907
2173
|
if (action === "dtolnay/rust-toolchain" || action === "actions-rust-lang/setup-rust-toolchain") {
|
|
1908
2174
|
const entries = Object.entries(inputs).filter(([key]) => key.toLowerCase() === "toolchain");
|
|
1909
2175
|
if (entries.length !== 1) select(void 0, `${action} requires an explicit exact toolchain input`, lineOf(uses));
|
|
@@ -1917,8 +2183,8 @@ const checkRustReferences = (options) => {
|
|
|
1917
2183
|
}
|
|
1918
2184
|
}
|
|
1919
2185
|
for (const [key, child] of Object.entries(value)) {
|
|
1920
|
-
if (key === "workflow_call" && record$
|
|
1921
|
-
for (const [input, declaration] of Object.entries(child["inputs"])) if (["toolchain", "rust-toolchain"].includes(input) && record$
|
|
2186
|
+
if (key === "workflow_call" && record$3(child) && record$3(child["inputs"])) {
|
|
2187
|
+
for (const [input, declaration] of Object.entries(child["inputs"])) if (["toolchain", "rust-toolchain"].includes(input) && record$3(declaration) && declaration["default"] !== void 0) select(declaration["default"], `reusable workflow default ${input}`, lineOf("default:"));
|
|
1922
2188
|
}
|
|
1923
2189
|
visit(child);
|
|
1924
2190
|
}
|
|
@@ -1928,6 +2194,374 @@ const checkRustReferences = (options) => {
|
|
|
1928
2194
|
return diagnostics;
|
|
1929
2195
|
};
|
|
1930
2196
|
//#endregion
|
|
2197
|
+
//#region src/toolchain-workflow-trust.ts
|
|
2198
|
+
const record$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2199
|
+
const booleanParts = (source, operator) => {
|
|
2200
|
+
const parts = [];
|
|
2201
|
+
let depth = 0;
|
|
2202
|
+
let quoted = false;
|
|
2203
|
+
let start = 0;
|
|
2204
|
+
for (let index = 0; index < source.length; index++) {
|
|
2205
|
+
const character = source[index];
|
|
2206
|
+
if (character === "'") {
|
|
2207
|
+
if (quoted && source[index + 1] === "'") index++;
|
|
2208
|
+
else quoted = !quoted;
|
|
2209
|
+
}
|
|
2210
|
+
if (quoted) continue;
|
|
2211
|
+
if (character === "(") depth++;
|
|
2212
|
+
if (character === ")") depth--;
|
|
2213
|
+
if (depth === 0 && source.slice(index, index + 2) === operator) {
|
|
2214
|
+
parts.push(source.slice(start, index));
|
|
2215
|
+
start = index + 2;
|
|
2216
|
+
index++;
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
parts.push(source.slice(start));
|
|
2220
|
+
return parts;
|
|
2221
|
+
};
|
|
2222
|
+
const withoutOuterParentheses = (source) => {
|
|
2223
|
+
if (!source.startsWith("(") || !source.endsWith(")")) return source;
|
|
2224
|
+
let depth = 0;
|
|
2225
|
+
let quoted = false;
|
|
2226
|
+
for (let index = 0; index < source.length; index++) {
|
|
2227
|
+
const character = source[index];
|
|
2228
|
+
if (character === "'") {
|
|
2229
|
+
if (quoted && source[index + 1] === "'") index++;
|
|
2230
|
+
else quoted = !quoted;
|
|
2231
|
+
}
|
|
2232
|
+
if (quoted) continue;
|
|
2233
|
+
if (character === "(") depth++;
|
|
2234
|
+
if (character === ")") depth--;
|
|
2235
|
+
if (depth === 0 && index !== source.length - 1) return source;
|
|
2236
|
+
}
|
|
2237
|
+
return withoutOuterParentheses(source.slice(1, -1).trim());
|
|
2238
|
+
};
|
|
2239
|
+
const excludesUntrusted = ({ condition, event, allowTrust = true }) => {
|
|
2240
|
+
if (condition === false) return true;
|
|
2241
|
+
if (typeof condition !== "string") return false;
|
|
2242
|
+
const source = withoutOuterParentheses(condition.trim().replace(/^\$\{\{([\s\S]*)\}\}$/u, "$1").trim());
|
|
2243
|
+
const alternatives = booleanParts(source, "||");
|
|
2244
|
+
if (alternatives.length > 1) return alternatives.every((part) => excludesUntrusted({
|
|
2245
|
+
condition: part,
|
|
2246
|
+
event,
|
|
2247
|
+
allowTrust
|
|
2248
|
+
}));
|
|
2249
|
+
const conjuncts = booleanParts(source, "&&");
|
|
2250
|
+
if (conjuncts.length > 1) return conjuncts.some((part) => excludesUntrusted({
|
|
2251
|
+
condition: part,
|
|
2252
|
+
event,
|
|
2253
|
+
allowTrust
|
|
2254
|
+
}));
|
|
2255
|
+
const trustComparison = /^needs\.trust-check\.outputs\.trusted\s*==\s*'([^']*)'$/u.exec(source);
|
|
2256
|
+
if (allowTrust && trustComparison?.at(1)?.toLowerCase() === "true") return true;
|
|
2257
|
+
if (source === "false") return true;
|
|
2258
|
+
const comparison = /^github\.event_name\s*(==|!=)\s*'([^']+)'$/u.exec(source);
|
|
2259
|
+
if (comparison === null) return false;
|
|
2260
|
+
const equal = comparison.at(2)?.toLowerCase() === event.toLowerCase();
|
|
2261
|
+
return comparison.at(1) === "==" ? !equal : equal;
|
|
2262
|
+
};
|
|
2263
|
+
const staticData = (word) => !/[`$\\]/u.test(word) && !/[<>]/u.test(word);
|
|
2264
|
+
const metadataScript = (command) => {
|
|
2265
|
+
const interpolation = /\$\{\{([\s\S]*?)\}\}/gu;
|
|
2266
|
+
for (const match of command.matchAll(interpolation)) {
|
|
2267
|
+
const expression = match.at(1);
|
|
2268
|
+
if (expression === void 0 || ![
|
|
2269
|
+
"github.sha",
|
|
2270
|
+
"github.run_id",
|
|
2271
|
+
"github.run_attempt",
|
|
2272
|
+
"github.repository"
|
|
2273
|
+
].includes(expression.trim())) return void 0;
|
|
2274
|
+
}
|
|
2275
|
+
const source = command.replace(interpolation, "stll-metadata");
|
|
2276
|
+
return source.includes("${{") ? void 0 : source;
|
|
2277
|
+
};
|
|
2278
|
+
const metadataWord = (raw) => {
|
|
2279
|
+
if (/^'[^']*'$/u.test(raw)) return true;
|
|
2280
|
+
if ([
|
|
2281
|
+
"[",
|
|
2282
|
+
"]",
|
|
2283
|
+
"[[",
|
|
2284
|
+
"]]"
|
|
2285
|
+
].includes(raw)) return true;
|
|
2286
|
+
let quote;
|
|
2287
|
+
for (const character of raw) {
|
|
2288
|
+
if (quote === void 0 && "*?~[{$".includes(character)) return false;
|
|
2289
|
+
if (character === quote) quote = void 0;
|
|
2290
|
+
else if (quote === void 0 && (character === "'" || character === "\"")) quote = character;
|
|
2291
|
+
}
|
|
2292
|
+
if (quote !== void 0) return false;
|
|
2293
|
+
const withoutKnownExpressions = raw.replace(/\$\{[A-Za-z_][A-Za-z_0-9]*\}|\$[A-Za-z_][A-Za-z_0-9]*/gu, "value");
|
|
2294
|
+
return !/[`$\\]/u.test(withoutKnownExpressions);
|
|
2295
|
+
};
|
|
2296
|
+
const safeComparison = (words) => {
|
|
2297
|
+
const first = words.at(0);
|
|
2298
|
+
if (![
|
|
2299
|
+
"test",
|
|
2300
|
+
"[",
|
|
2301
|
+
"[["
|
|
2302
|
+
].includes(first ?? "")) return false;
|
|
2303
|
+
let end;
|
|
2304
|
+
if (first === "[[") end = "]]";
|
|
2305
|
+
else if (first === "[") end = "]";
|
|
2306
|
+
if (end !== void 0 && words.at(-1) !== end) return false;
|
|
2307
|
+
const operands = words.slice(1, end === void 0 ? void 0 : -1);
|
|
2308
|
+
if (operands.length === 1) return true;
|
|
2309
|
+
if (operands.length === 2) return ["-n", "-z"].includes(operands.at(0) ?? "");
|
|
2310
|
+
return operands.length === 3 && [
|
|
2311
|
+
"=",
|
|
2312
|
+
"==",
|
|
2313
|
+
"!="
|
|
2314
|
+
].includes(operands.at(1) ?? "");
|
|
2315
|
+
};
|
|
2316
|
+
const objectReference = (value) => /^(?:HEAD|[a-f0-9]{7,64}|(?:refs\/(?:heads|tags|remotes)\/|origin\/)[A-Za-z0-9][A-Za-z0-9._/-]*)(?:[~^][0-9]*)*$/u.test(value) && !value.includes("..") && !value.includes("//") && !value.endsWith("/");
|
|
2317
|
+
const workflowTrustBootstrapCatalog = {
|
|
2318
|
+
commands: {
|
|
2319
|
+
test: "comparison",
|
|
2320
|
+
"[": "comparison",
|
|
2321
|
+
"[[": "comparison",
|
|
2322
|
+
true: "status",
|
|
2323
|
+
false: "status",
|
|
2324
|
+
exit: "exit",
|
|
2325
|
+
echo: "output",
|
|
2326
|
+
printf: "format",
|
|
2327
|
+
git: "git",
|
|
2328
|
+
gh: "github"
|
|
2329
|
+
},
|
|
2330
|
+
git: {
|
|
2331
|
+
"rev-parse": {
|
|
2332
|
+
flags: ["--short", "--verify"],
|
|
2333
|
+
references: 1
|
|
2334
|
+
},
|
|
2335
|
+
"merge-base": {
|
|
2336
|
+
flags: ["--all", "--is-ancestor"],
|
|
2337
|
+
references: 2
|
|
2338
|
+
}
|
|
2339
|
+
},
|
|
2340
|
+
github: ["api"],
|
|
2341
|
+
actions: {
|
|
2342
|
+
"actions/checkout": [
|
|
2343
|
+
"fetch-depth",
|
|
2344
|
+
"persist-credentials",
|
|
2345
|
+
"ref",
|
|
2346
|
+
"repository",
|
|
2347
|
+
"submodules"
|
|
2348
|
+
],
|
|
2349
|
+
"oven-sh/setup-bun": ["bun-version", "no-cache"]
|
|
2350
|
+
}
|
|
2351
|
+
};
|
|
2352
|
+
const safeGit = (words) => {
|
|
2353
|
+
const selected = Object.entries(workflowTrustBootstrapCatalog.git).find(([name]) => name === words.at(1));
|
|
2354
|
+
if (selected === void 0) return false;
|
|
2355
|
+
const [, policy] = selected;
|
|
2356
|
+
const references = [];
|
|
2357
|
+
for (const argument of words.slice(2)) {
|
|
2358
|
+
if (!staticData(argument)) return false;
|
|
2359
|
+
if (!argument.startsWith("-")) {
|
|
2360
|
+
references.push(argument);
|
|
2361
|
+
continue;
|
|
2362
|
+
}
|
|
2363
|
+
if (!policy.flags.some((flag) => flag === argument)) return false;
|
|
2364
|
+
}
|
|
2365
|
+
return references.length === policy.references && references.every(objectReference);
|
|
2366
|
+
};
|
|
2367
|
+
const safeGh = (words) => {
|
|
2368
|
+
if (!words.every(staticData)) return false;
|
|
2369
|
+
if (workflowTrustBootstrapCatalog.github.some((name) => name === words.at(1))) {
|
|
2370
|
+
const arguments_ = words.slice(2);
|
|
2371
|
+
if (["--method", "-X"].includes(arguments_.at(0) ?? "") && arguments_.at(1) === "GET") arguments_.splice(0, 2);
|
|
2372
|
+
if (!arguments_.at(0) || arguments_.at(0)?.startsWith("-")) return false;
|
|
2373
|
+
for (let index = 1; index < arguments_.length; index++) {
|
|
2374
|
+
const argument = arguments_.at(index);
|
|
2375
|
+
if ((argument === "--method" || argument === "-X") && arguments_.at(index + 1) === "GET") index++;
|
|
2376
|
+
else if (["--jq", "-q"].includes(argument ?? "") && /^\.[A-Za-z0-9_.[\]" -]*$/u.test(arguments_.at(index + 1) ?? "")) index++;
|
|
2377
|
+
else return false;
|
|
2378
|
+
}
|
|
2379
|
+
return /^\/?repos\/[A-Za-z0-9_./-]+$/u.test(arguments_.at(0) ?? "");
|
|
2380
|
+
}
|
|
2381
|
+
return false;
|
|
2382
|
+
};
|
|
2383
|
+
const safeCommand = (raw) => {
|
|
2384
|
+
if (raw.length === 0) return true;
|
|
2385
|
+
if (!raw.every(metadataWord)) return false;
|
|
2386
|
+
const words = raw.map(decodeShellWord);
|
|
2387
|
+
const name = words.at(0);
|
|
2388
|
+
if (raw.at(0) !== name) return false;
|
|
2389
|
+
if (name === "if" || name === "elif") return safeComparison(words.slice(1));
|
|
2390
|
+
if (["then", "else"].includes(name ?? "")) return safeCommand(raw.slice(1));
|
|
2391
|
+
if (name === "fi") return words.length === 1;
|
|
2392
|
+
const kind = Object.entries(workflowTrustBootstrapCatalog.commands).find(([command]) => command === name)?.[1];
|
|
2393
|
+
if (kind === "comparison") return safeComparison(words);
|
|
2394
|
+
if (kind === "status") return words.length === 1;
|
|
2395
|
+
if (kind === "exit") return words.length === 1 || words.length === 2 && /^[0-9]+$/u.test(words.at(1) ?? "");
|
|
2396
|
+
if (kind === "output") return true;
|
|
2397
|
+
if (kind === "format") {
|
|
2398
|
+
const format = words.at(1);
|
|
2399
|
+
return format !== void 0 && !format.startsWith("-") && /^(?:[^%$`]|%%|%s)*$/u.test(format);
|
|
2400
|
+
}
|
|
2401
|
+
if (kind === "git") return safeGit(words);
|
|
2402
|
+
if (kind === "github") return safeGh(words);
|
|
2403
|
+
return false;
|
|
2404
|
+
};
|
|
2405
|
+
const invokesRepositoryCode = (command) => {
|
|
2406
|
+
const source = metadataScript(command);
|
|
2407
|
+
if (source === void 0) return true;
|
|
2408
|
+
const tokens = shellTokens(source);
|
|
2409
|
+
for (const [index, token] of tokens.entries()) {
|
|
2410
|
+
if (token.kind !== "redirect") continue;
|
|
2411
|
+
const target = tokens.at(index + 1);
|
|
2412
|
+
if (![">", ">>"].includes(token.value) || target?.kind !== "word" || ![
|
|
2413
|
+
"\"$GITHUB_OUTPUT\"",
|
|
2414
|
+
"\"${GITHUB_OUTPUT}\"",
|
|
2415
|
+
"/dev/null"
|
|
2416
|
+
].includes(target.value)) return true;
|
|
2417
|
+
}
|
|
2418
|
+
const branches = [];
|
|
2419
|
+
for (let words of shellCommandSegments(source, "tokens")) {
|
|
2420
|
+
if (!safeCommand(words)) return true;
|
|
2421
|
+
while (["then", "else"].includes(words.at(0) ?? "")) {
|
|
2422
|
+
const keyword = words.at(0);
|
|
2423
|
+
const previous = branches.pop();
|
|
2424
|
+
if (keyword === "then" && previous === "condition") branches.push("then");
|
|
2425
|
+
else if (keyword === "else" && previous === "then") branches.push("else");
|
|
2426
|
+
else return true;
|
|
2427
|
+
words = words.slice(1);
|
|
2428
|
+
}
|
|
2429
|
+
const keyword = words.at(0);
|
|
2430
|
+
if (keyword === "if") branches.push("condition");
|
|
2431
|
+
if (keyword === "elif") {
|
|
2432
|
+
if (branches.pop() !== "then") return true;
|
|
2433
|
+
branches.push("condition");
|
|
2434
|
+
}
|
|
2435
|
+
if (keyword === "fi") {
|
|
2436
|
+
const previous = branches.pop();
|
|
2437
|
+
if (previous !== "then" && previous !== "else") return true;
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
return branches.length !== 0;
|
|
2441
|
+
};
|
|
2442
|
+
const safeAction = (uses, inputs) => {
|
|
2443
|
+
if (typeof uses !== "string" || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_./-]+@[a-f0-9]{40}$/u.test(uses)) return false;
|
|
2444
|
+
const repository = uses.split("@").at(0);
|
|
2445
|
+
const approved = Object.entries(workflowTrustBootstrapCatalog.actions).find(([name]) => name === repository);
|
|
2446
|
+
if (approved === void 0) return false;
|
|
2447
|
+
if (inputs === void 0) return repository === "actions/checkout";
|
|
2448
|
+
if (!record$2(inputs)) return false;
|
|
2449
|
+
if (repository !== "actions/checkout") {
|
|
2450
|
+
const version = inputs["bun-version"];
|
|
2451
|
+
if (typeof version !== "string" || !/^v?[0-9]+(?:\.(?:[0-9]+|x)){0,2}$/u.test(version)) return false;
|
|
2452
|
+
}
|
|
2453
|
+
const [, allowedInputs] = approved;
|
|
2454
|
+
return Object.entries(inputs).every(([name, value]) => allowedInputs.some((allowed) => allowed === name) && [
|
|
2455
|
+
"string",
|
|
2456
|
+
"boolean",
|
|
2457
|
+
"number"
|
|
2458
|
+
].includes(typeof value) && (name !== "submodules" || value === false || value === "false"));
|
|
2459
|
+
};
|
|
2460
|
+
const safeShell = (shell) => shell === void 0 || shell === "bash" || shell === "sh";
|
|
2461
|
+
const safeEnvironment = (value) => value === void 0 || record$2(value) && Object.keys(value).every((name) => [
|
|
2462
|
+
"HEAD_REPO",
|
|
2463
|
+
"BASE_REPO",
|
|
2464
|
+
"HAS_RUN_CI_LABEL",
|
|
2465
|
+
"PR_TITLE",
|
|
2466
|
+
"HEAD_REF",
|
|
2467
|
+
"ISSUE_BODY",
|
|
2468
|
+
"COMMENT_BODY",
|
|
2469
|
+
"GH_TOKEN",
|
|
2470
|
+
"GITHUB_TOKEN",
|
|
2471
|
+
"HAWK_RUST_TOOLCHAIN",
|
|
2472
|
+
"HAWK_VERSION",
|
|
2473
|
+
"HAWK_X86_64_UNKNOWN_LINUX_GNU_SHA256"
|
|
2474
|
+
].includes(name));
|
|
2475
|
+
const configuredShell = (value) => record$2(value) && record$2(value["run"]) ? value["run"]["shell"] : void 0;
|
|
2476
|
+
const workflowTrustRules = ["workflow-trust"];
|
|
2477
|
+
const workflowEvents = (triggers) => {
|
|
2478
|
+
if (typeof triggers === "string") return [triggers];
|
|
2479
|
+
if (Array.isArray(triggers)) return triggers;
|
|
2480
|
+
if (record$2(triggers)) return Object.keys(triggers);
|
|
2481
|
+
return [];
|
|
2482
|
+
};
|
|
2483
|
+
/** Enforce a workflow's declared trust boundary before repository dependency execution. */
|
|
2484
|
+
const checkWorkflowTrust = (workflow) => {
|
|
2485
|
+
const findings = [];
|
|
2486
|
+
if (!record$2(workflow) || !record$2(workflow["jobs"])) return findings;
|
|
2487
|
+
const jobs = workflow["jobs"];
|
|
2488
|
+
if (!record$2(jobs["trust-check"])) return findings;
|
|
2489
|
+
const triggers = workflow["on"];
|
|
2490
|
+
const pullRequests = workflowEvents(triggers).filter((event) => event === "pull_request" || event === "pull_request_target");
|
|
2491
|
+
if (pullRequests.length === 0) return findings;
|
|
2492
|
+
for (const [name, job] of Object.entries(jobs)) {
|
|
2493
|
+
if (!record$2(job)) continue;
|
|
2494
|
+
const needs = job["needs"];
|
|
2495
|
+
const ordered = name !== "trust-check" && (needs === "trust-check" || Array.isArray(needs) && needs.includes("trust-check"));
|
|
2496
|
+
const permitsExecution = (stepCondition) => {
|
|
2497
|
+
const guarded = pullRequests.every((event) => excludesUntrusted({
|
|
2498
|
+
condition: job["if"],
|
|
2499
|
+
event
|
|
2500
|
+
}) || excludesUntrusted({
|
|
2501
|
+
condition: stepCondition,
|
|
2502
|
+
event
|
|
2503
|
+
}));
|
|
2504
|
+
if (ordered && guarded) return true;
|
|
2505
|
+
return pullRequests.every((event) => excludesUntrusted({
|
|
2506
|
+
condition: job["if"],
|
|
2507
|
+
event,
|
|
2508
|
+
allowTrust: false
|
|
2509
|
+
}) || excludesUntrusted({
|
|
2510
|
+
condition: stepCondition,
|
|
2511
|
+
event,
|
|
2512
|
+
allowTrust: false
|
|
2513
|
+
}));
|
|
2514
|
+
};
|
|
2515
|
+
const message = `jobs.${name} repository commands require needs: trust-check and a condition requiring its trusted output on pull requests`;
|
|
2516
|
+
if (job["uses"] !== void 0 && !permitsExecution(void 0)) findings.push({
|
|
2517
|
+
type: "job",
|
|
2518
|
+
property: "uses",
|
|
2519
|
+
job: name,
|
|
2520
|
+
message
|
|
2521
|
+
});
|
|
2522
|
+
if (!permitsExecution(void 0)) {
|
|
2523
|
+
if (job["container"] !== void 0) findings.push({
|
|
2524
|
+
type: "job",
|
|
2525
|
+
property: "container",
|
|
2526
|
+
job: name,
|
|
2527
|
+
message
|
|
2528
|
+
});
|
|
2529
|
+
const services = job["services"];
|
|
2530
|
+
if (services !== void 0 && (!record$2(services) || Object.keys(services).length > 0)) findings.push({
|
|
2531
|
+
type: "job",
|
|
2532
|
+
property: "services",
|
|
2533
|
+
job: name,
|
|
2534
|
+
message
|
|
2535
|
+
});
|
|
2536
|
+
}
|
|
2537
|
+
if (!Array.isArray(job["steps"])) continue;
|
|
2538
|
+
for (const [index, step] of job["steps"].entries()) {
|
|
2539
|
+
if (!record$2(step)) continue;
|
|
2540
|
+
const run = step["run"];
|
|
2541
|
+
const uses = step["uses"];
|
|
2542
|
+
const unsafeRun = typeof run === "string" && (invokesRepositoryCode(run) || !safeShell(step["shell"] ?? configuredShell(job["defaults"]) ?? configuredShell(workflow["defaults"])) || ![
|
|
2543
|
+
workflow["env"],
|
|
2544
|
+
job["env"],
|
|
2545
|
+
step["env"]
|
|
2546
|
+
].every(safeEnvironment));
|
|
2547
|
+
const unsafeAction = uses !== void 0 && (!safeAction(uses, step["with"]) || ![
|
|
2548
|
+
workflow["env"],
|
|
2549
|
+
job["env"],
|
|
2550
|
+
step["env"]
|
|
2551
|
+
].every(safeEnvironment));
|
|
2552
|
+
if (!unsafeRun && !unsafeAction) continue;
|
|
2553
|
+
if (permitsExecution(unsafeAction ? void 0 : step["if"])) continue;
|
|
2554
|
+
findings.push({
|
|
2555
|
+
type: "step",
|
|
2556
|
+
job: name,
|
|
2557
|
+
step: index,
|
|
2558
|
+
message
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
return findings;
|
|
2563
|
+
};
|
|
2564
|
+
//#endregion
|
|
1931
2565
|
//#region src/toolchain-runtime.ts
|
|
1932
2566
|
const runtimeRules = [
|
|
1933
2567
|
"bun-pins",
|
|
@@ -1937,7 +2571,8 @@ const runtimeRules = [
|
|
|
1937
2571
|
"runtime-manager",
|
|
1938
2572
|
"runtime-docker",
|
|
1939
2573
|
"runtime-workflow",
|
|
1940
|
-
"action-pins"
|
|
2574
|
+
"action-pins",
|
|
2575
|
+
...workflowTrustRules
|
|
1941
2576
|
];
|
|
1942
2577
|
const record$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1943
2578
|
const dockerEnvironmentAssignments = ({ source, escape }) => {
|
|
@@ -3171,8 +3806,29 @@ const checkRuntimeFile = ({ file, text, policy, trackedFiles, readFile, reposito
|
|
|
3171
3806
|
}
|
|
3172
3807
|
};
|
|
3173
3808
|
try {
|
|
3174
|
-
document.toJS({ maxAliasCount: 100 });
|
|
3809
|
+
const workflow = document.toJS({ maxAliasCount: 100 });
|
|
3175
3810
|
if (automationKind === "workflow") {
|
|
3811
|
+
for (const finding of checkWorkflowTrust(workflow)) {
|
|
3812
|
+
const jobNode = getNode(getNode(document.contents, "jobs"), finding.job);
|
|
3813
|
+
let source;
|
|
3814
|
+
switch (finding.type) {
|
|
3815
|
+
case "job":
|
|
3816
|
+
source = getNode(jobNode, finding.property);
|
|
3817
|
+
break;
|
|
3818
|
+
case "step": {
|
|
3819
|
+
const steps = resolveNode(getNode(jobNode, "steps"));
|
|
3820
|
+
const step = isSeq(steps) ? steps.items.at(finding.step) : void 0;
|
|
3821
|
+
source = getNode(step, "run") ?? getNode(step, "uses");
|
|
3822
|
+
break;
|
|
3823
|
+
}
|
|
3824
|
+
default: throw new Error("unknown workflow finding", { cause: finding });
|
|
3825
|
+
}
|
|
3826
|
+
add({
|
|
3827
|
+
rule: "workflow-trust",
|
|
3828
|
+
line: nodeLine(source ?? jobNode),
|
|
3829
|
+
message: finding.message
|
|
3830
|
+
});
|
|
3831
|
+
}
|
|
3176
3832
|
const jobs = getNode(document.contents, "jobs");
|
|
3177
3833
|
if (isMap(jobs)) for (const key of keysOf(jobs)) {
|
|
3178
3834
|
checkoutBindings = [];
|
|
@@ -3226,6 +3882,7 @@ const toolchainRules = [.../* @__PURE__ */ new Set([
|
|
|
3226
3882
|
...packageRules,
|
|
3227
3883
|
...runtimeRules,
|
|
3228
3884
|
...dependabotRules,
|
|
3885
|
+
nodeProjectRule,
|
|
3229
3886
|
"cloud-setup-drift"
|
|
3230
3887
|
])];
|
|
3231
3888
|
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -3240,7 +3897,9 @@ const parseToolchainConfiguration = (input) => {
|
|
|
3240
3897
|
if (!record(entry) || Object.keys(entry).some((key) => key !== "rule" && key !== "reason") || typeof entry["rule"] !== "string" || !toolchainRules.some((rule) => rule === entry["rule"]) || typeof entry["reason"] !== "string" || entry["reason"].trim() === "" || disabled.has(entry["rule"])) throw new Error("each opt-out requires a unique known rule and a nonempty reason");
|
|
3241
3898
|
if (entry["rule"] === "rust-version") throw new Error("rust-version requires expiring exact-pin rustExceptions, not an opt-out");
|
|
3242
3899
|
if (entry["rule"] === "node-engine") throw new Error("node-engine cannot be opted out; engines.node must support the shared Node series");
|
|
3900
|
+
if (entry["rule"] === "workflow-trust") throw new Error("workflow-trust cannot be opted out; repository commands must follow the declared trust decision");
|
|
3243
3901
|
if (entry["rule"] === "cloud-setup-drift") throw new Error("cloud-setup-drift cannot be opted out; generated setup must match shared policy");
|
|
3902
|
+
if (entry["rule"] === "type-aware-projects") throw new Error("type-aware-projects cannot be opted out; linted files require declared TypeScript projects");
|
|
3244
3903
|
disabled.add(entry["rule"]);
|
|
3245
3904
|
}
|
|
3246
3905
|
return {
|
|
@@ -3263,12 +3922,13 @@ const readToolchainInputs = (root) => {
|
|
|
3263
3922
|
const kind = toolchainInputKind(file);
|
|
3264
3923
|
const shebangCandidate = kind === void 0 && path.posix.extname(file) === "" && !file.split("/").some((part) => part === "vendor" || part === "node_modules");
|
|
3265
3924
|
if (kind === void 0 && !shebangCandidate) continue;
|
|
3266
|
-
if (kind === "presence") {
|
|
3267
|
-
files[file] = "";
|
|
3268
|
-
continue;
|
|
3269
|
-
}
|
|
3270
3925
|
try {
|
|
3271
3926
|
const inputPath = path.join(resolvedRoot, file);
|
|
3927
|
+
if (kind === "presence") {
|
|
3928
|
+
lstatSync(inputPath);
|
|
3929
|
+
files[file] = "";
|
|
3930
|
+
continue;
|
|
3931
|
+
}
|
|
3272
3932
|
if (shebangCandidate) {
|
|
3273
3933
|
const input = lstatSync(inputPath);
|
|
3274
3934
|
if (!input.isFile() && !input.isSymbolicLink()) continue;
|
|
@@ -3289,7 +3949,8 @@ const readToolchainInputs = (root) => {
|
|
|
3289
3949
|
if (toolchainInputKind(file, prefix.toString("utf8", 0, count)) === void 0) continue;
|
|
3290
3950
|
}
|
|
3291
3951
|
files[file] = readFileSync(resolvedFile, "utf8");
|
|
3292
|
-
} catch {
|
|
3952
|
+
} catch (error) {
|
|
3953
|
+
if (kind === "presence" && error instanceof Error && "code" in error && error.code === "ENOENT") continue;
|
|
3293
3954
|
if (shebangCandidate) continue;
|
|
3294
3955
|
diagnostics.push({
|
|
3295
3956
|
rule: "configuration",
|
|
@@ -3396,6 +4057,17 @@ const checkToolchain = ({ root, policy, onDelegated }) => {
|
|
|
3396
4057
|
files,
|
|
3397
4058
|
policy
|
|
3398
4059
|
}));
|
|
4060
|
+
if (files["package.json"] !== void 0) {
|
|
4061
|
+
let manifest;
|
|
4062
|
+
try {
|
|
4063
|
+
manifest = JSON.parse(files["package.json"]);
|
|
4064
|
+
} catch {}
|
|
4065
|
+
diagnostics.push(...checkNodeProjects({
|
|
4066
|
+
root,
|
|
4067
|
+
manifest,
|
|
4068
|
+
trackedFiles
|
|
4069
|
+
}));
|
|
4070
|
+
}
|
|
3399
4071
|
for (const [file, text] of Object.entries(files)) diagnostics.push(...checkRuntimeFile({
|
|
3400
4072
|
file,
|
|
3401
4073
|
text,
|