@stll/oxlint-config 1.6.2 → 1.7.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 +1 -1
- package/dist/cloud-setup-cli.mjs +1 -1
- package/dist/consumer-compat-cli.cjs.map +1 -1
- package/dist/consumer-compat-cli.mjs.map +1 -1
- package/dist/consumer-node-support.mjs +1 -1
- package/dist/dependabot.d.cts +10 -0
- package/dist/dependabot.d.mts +10 -0
- package/dist/engine-support-cli.cjs.map +1 -1
- package/dist/engine-support-cli.mjs.map +1 -1
- package/dist/git-tracked-output.cjs.map +1 -1
- package/dist/git-tracked-output.mjs.map +1 -1
- package/dist/publish-artifact-syntax.cjs.map +1 -1
- package/dist/publish-artifact-syntax.mjs.map +1 -1
- package/dist/publish-build-target-vite-dts-helper2.cjs.map +1 -1
- package/dist/publish-build-target-vite-dts-helper2.mjs.map +1 -1
- package/dist/publish-contract-cli.cjs.map +1 -1
- package/dist/publish-contract-cli.mjs.map +1 -1
- package/dist/quarantine-policy2.cjs.map +1 -1
- package/dist/quarantine-policy2.mjs.map +1 -1
- package/dist/toolchain-changed.cjs +1 -3
- package/dist/toolchain-changed.cjs.map +1 -1
- package/dist/toolchain-changed.mjs +2 -4
- package/dist/toolchain-changed.mjs.map +1 -1
- package/dist/toolchain-dependabot.cjs.map +1 -1
- package/dist/toolchain-dependabot.mjs +1 -1
- package/dist/toolchain-dependabot.mjs.map +1 -1
- package/dist/toolchain-guard.cjs +11 -4
- package/dist/toolchain-guard.cjs.map +1 -1
- package/dist/toolchain-guard.mjs +12 -5
- package/dist/toolchain-guard.mjs.map +1 -1
- package/dist/toolchain-inputs.cjs +99 -9
- package/dist/toolchain-inputs.cjs.map +1 -1
- package/dist/toolchain-inputs.mjs +88 -10
- package/dist/toolchain-inputs.mjs.map +1 -1
- package/dist/toolchain-schema.cjs +179 -1
- package/dist/toolchain-schema.cjs.map +1 -1
- package/dist/toolchain-schema.mjs +167 -3
- package/dist/toolchain-schema.mjs.map +1 -1
- package/dist/typecheck-parity.cjs.map +1 -1
- package/dist/typecheck-parity.mjs.map +1 -1
- package/dist/wasi-loader-normalizer-cli.cjs.map +1 -1
- package/dist/wasi-loader-normalizer-cli.mjs.map +1 -1
- package/package.json +2 -4
- package/toolchain.json +54 -12
|
@@ -1,12 +1,177 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime.cjs");
|
|
1
2
|
const require_toolchain_inputs = require("./toolchain-inputs.cjs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
5
|
+
let smol_toml = require("smol-toml");
|
|
2
6
|
let semver = require("semver");
|
|
7
|
+
let yaml = require("yaml");
|
|
8
|
+
//#region src/toolchain-formatter.ts
|
|
9
|
+
const formatterRule = "formatter-policy";
|
|
10
|
+
/** Repository-owned [fmt] keys: what to skip, and the Tailwind entry point. */
|
|
11
|
+
const repositoryFormatKeys = ["ignorePatterns", "sortTailwindcss"];
|
|
12
|
+
const record$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
/** One style for every repository; only repository-owned keys may differ. */
|
|
14
|
+
const parseFormatterPolicy = (input) => {
|
|
15
|
+
if (!record$1(input) || Object.keys(input).some((key) => key !== "command" && key !== "style" && key !== "ignorePatterns")) throw new Error("toolchain.json formatter accepts only command, style and ignorePatterns");
|
|
16
|
+
if (input["command"] !== "bun fmt") throw new Error("toolchain.json formatter command must be bun fmt");
|
|
17
|
+
const style = input["style"];
|
|
18
|
+
if (!record$1(style) || Object.keys(style).length === 0) throw new Error("toolchain.json formatter style must be a nonempty table");
|
|
19
|
+
for (const key of Object.keys(style)) if (repositoryFormatKeys.some((owned) => owned === key)) throw new Error(`toolchain.json formatter style cannot own the repository key ${key}`);
|
|
20
|
+
const ignorePatterns = input["ignorePatterns"];
|
|
21
|
+
if (!Array.isArray(ignorePatterns) || !ignorePatterns.every((pattern) => typeof pattern === "string" && pattern !== "")) throw new Error("toolchain.json formatter ignorePatterns must be nonempty strings");
|
|
22
|
+
return {
|
|
23
|
+
command: "bun fmt",
|
|
24
|
+
style,
|
|
25
|
+
ignorePatterns
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const tomlValue = (value) => {
|
|
29
|
+
if (Array.isArray(value)) return `[${value.map(tomlValue).join(", ")}]`;
|
|
30
|
+
if (record$1(value)) return `{ ${Object.entries(value).map(([key, entry]) => `${key} = ${tomlValue(entry)}`).join(", ")} }`;
|
|
31
|
+
return JSON.stringify(value);
|
|
32
|
+
};
|
|
33
|
+
const tomlLines = (entries) => entries.map(([key, value]) => `${key} = ${tomlValue(value)}\n`).join("");
|
|
34
|
+
/** Render the shared bunfig.toml [fmt] tables. */
|
|
35
|
+
const sharedFormatTables = (policy) => {
|
|
36
|
+
const entries = Object.entries(policy.style);
|
|
37
|
+
let output = `[fmt]\n${tomlLines(entries.filter(([, value]) => !record$1(value)))}ignorePatterns = ${tomlValue(policy.ignorePatterns)}\n`;
|
|
38
|
+
for (const [name, table] of entries) if (record$1(table)) output += `\n[fmt.${name}]\n${tomlLines(Object.entries(table))}`;
|
|
39
|
+
return output;
|
|
40
|
+
};
|
|
41
|
+
const stableJson = (value) => JSON.stringify(value, (_key, entry) => record$1(entry) ? Object.fromEntries(Object.entries(entry).toSorted(([left], [right]) => left.localeCompare(right))) : entry);
|
|
42
|
+
const formatterPackage = (name) => name === "oxfmt" || name === "prettier" || name === "dprint" || name === "@biomejs/biome" || name.startsWith("@dprint/") || /^(?:@[^/]+\/)?prettier-plugin-/.test(name);
|
|
43
|
+
const dependencyFields = [
|
|
44
|
+
"dependencies",
|
|
45
|
+
"devDependencies",
|
|
46
|
+
"optionalDependencies",
|
|
47
|
+
"peerDependencies",
|
|
48
|
+
"overrides",
|
|
49
|
+
"resolutions",
|
|
50
|
+
"catalog"
|
|
51
|
+
];
|
|
52
|
+
const declaredPackages = (manifest) => {
|
|
53
|
+
const tables = dependencyFields.map((field) => manifest[field]);
|
|
54
|
+
const workspaces = manifest["workspaces"];
|
|
55
|
+
for (const owner of [manifest, record$1(workspaces) ? workspaces : {}]) {
|
|
56
|
+
if (owner !== manifest) tables.push(owner["catalog"]);
|
|
57
|
+
const catalogs = owner["catalogs"];
|
|
58
|
+
if (record$1(catalogs)) tables.push(...Object.values(catalogs));
|
|
59
|
+
}
|
|
60
|
+
return tables.flatMap((table) => record$1(table) ? Object.keys(table) : []);
|
|
61
|
+
};
|
|
62
|
+
const shellWords = (command) => command.split(/[\s;&|()<>`]+/u).map((word) => word.replace(/^["']+|["']+$/gu, "")).filter((word) => word !== "");
|
|
63
|
+
/** Over-approximate: any formatter executable named as a word is an invocation. */
|
|
64
|
+
const invokesFormatter = (command) => {
|
|
65
|
+
const words = shellWords(command);
|
|
66
|
+
return words.some((word, index) => {
|
|
67
|
+
const name = node_path.default.posix.basename(word);
|
|
68
|
+
if (name === "oxfmt" || name === "prettier" || name === "dprint") return true;
|
|
69
|
+
return name === "biome" && [
|
|
70
|
+
"format",
|
|
71
|
+
"check",
|
|
72
|
+
"ci"
|
|
73
|
+
].includes(words.at(index + 1) ?? "");
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const lineOf = (text, needle) => Math.max(1, text.split(/\r?\n/u).findIndex((line) => line.includes(needle)) + 1);
|
|
77
|
+
/** Collect every `run` string of a workflow, composite action or hook config. */
|
|
78
|
+
const runValues = (value) => {
|
|
79
|
+
if (Array.isArray(value)) return value.flatMap(runValues);
|
|
80
|
+
if (!record$1(value)) return [];
|
|
81
|
+
return Object.entries(value).flatMap(([key, entry]) => key === "run" && typeof entry === "string" ? [entry] : runValues(entry));
|
|
82
|
+
};
|
|
83
|
+
const commandLines = (commands) => commands.flatMap((command) => command.replace(/\\\r?\n/gu, " ").split(/\r?\n|&&|;/u).map((line) => line.trim()));
|
|
84
|
+
const isBunFormat = (line, flag) => {
|
|
85
|
+
const words = shellWords(line);
|
|
86
|
+
return words[0] === "bun" && words[1] === "fmt" && words.slice(2).includes(flag) && words.slice(2).every((word) => word.startsWith("-"));
|
|
87
|
+
};
|
|
88
|
+
const checkFormatConfig = (bunfig, policy) => {
|
|
89
|
+
let parsed;
|
|
90
|
+
try {
|
|
91
|
+
parsed = (0, smol_toml.parse)(bunfig);
|
|
92
|
+
} catch {
|
|
93
|
+
return ["bunfig.toml must be valid TOML"];
|
|
94
|
+
}
|
|
95
|
+
const fmt = parsed["fmt"];
|
|
96
|
+
if (!record$1(fmt)) return [`bunfig.toml requires a [fmt] table: bun fmt reads its configuration only from there; start from:\n${sharedFormatTables(policy)}`];
|
|
97
|
+
const errors = [];
|
|
98
|
+
for (const key of Object.keys(fmt)) if (!Object.hasOwn(policy.style, key) && !repositoryFormatKeys.some((owned) => owned === key)) errors.push(`bunfig.toml [fmt] ${key} is not part of the shared style; every repository formats alike`);
|
|
99
|
+
const ignored = Array.isArray(fmt["ignorePatterns"]) ? fmt["ignorePatterns"] : [];
|
|
100
|
+
const missing = policy.ignorePatterns.filter((pattern) => !ignored.includes(pattern));
|
|
101
|
+
if (missing.length > 0) errors.push(`bunfig.toml [fmt] ignorePatterns must include the shared generated files: ${missing.join(", ")}`);
|
|
102
|
+
for (const [key, value] of Object.entries(policy.style)) if (stableJson(fmt[key]) !== stableJson(value)) errors.push(`bunfig.toml [fmt] ${key} must equal the shared style:\n${sharedFormatTables(policy)}`);
|
|
103
|
+
return errors;
|
|
104
|
+
};
|
|
105
|
+
/** bun fmt is the only formatter: one config table, staged hooks and a full CI check. */
|
|
106
|
+
const checkFormatter = ({ files, policy, usesBun }) => {
|
|
107
|
+
const diagnostics = [];
|
|
108
|
+
const add = (file, line, message) => diagnostics.push({
|
|
109
|
+
rule: formatterRule,
|
|
110
|
+
path: file,
|
|
111
|
+
line,
|
|
112
|
+
message
|
|
113
|
+
});
|
|
114
|
+
const workflowCommands = [];
|
|
115
|
+
for (const [file, text] of Object.entries(files)) {
|
|
116
|
+
const name = node_path.default.posix.basename(file);
|
|
117
|
+
if (require_toolchain_inputs.isFormatterConfigPath(file)) add(file, 1, "formatter configuration belongs in bunfig.toml [fmt]; remove this file");
|
|
118
|
+
if (name === "package.json") {
|
|
119
|
+
let manifest;
|
|
120
|
+
try {
|
|
121
|
+
manifest = JSON.parse(text);
|
|
122
|
+
} catch {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!record$1(manifest)) continue;
|
|
126
|
+
for (const dependency of declaredPackages(manifest)) if (formatterPackage(dependency)) add(file, lineOf(text, JSON.stringify(dependency)), `${dependency} is not allowed: bun fmt is the only formatter`);
|
|
127
|
+
if (manifest["prettier"] !== void 0) add(file, lineOf(text, "\"prettier\""), "package.json prettier configuration belongs in bunfig.toml [fmt]");
|
|
128
|
+
const scripts = manifest["scripts"];
|
|
129
|
+
if (record$1(scripts)) for (const [script, command] of Object.entries(scripts)) {
|
|
130
|
+
if (script === "fmt") add(file, lineOf(text, "\"fmt\""), "a package script named fmt shadows bun fmt; remove it");
|
|
131
|
+
if (typeof command === "string" && invokesFormatter(command)) add(file, lineOf(text, JSON.stringify(script)), `script ${script} runs another formatter; use bun fmt`);
|
|
132
|
+
}
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (file === ".changeset/config.json") {
|
|
136
|
+
try {
|
|
137
|
+
const config = JSON.parse(text);
|
|
138
|
+
if (record$1(config) && config["format"] !== false) add(file, lineOf(text, "\"format\""), "changesets must not run a formatter (format: false); format releases with bun fmt");
|
|
139
|
+
} catch {
|
|
140
|
+
add(file, 1, "changeset configuration must be valid JSON");
|
|
141
|
+
}
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const automation = require_toolchain_inputs.githubAutomationFileKind(file);
|
|
145
|
+
if (automation !== void 0 || require_toolchain_inputs.isLefthookConfigPath(file)) {
|
|
146
|
+
const document = (0, yaml.parseDocument)(text);
|
|
147
|
+
if (document.errors.length > 0) continue;
|
|
148
|
+
const parsed = document.toJS();
|
|
149
|
+
const commands = runValues(parsed);
|
|
150
|
+
for (const command of commands) if (invokesFormatter(command)) add(file, lineOf(text, command.split(/\r?\n/u)[0] ?? command), "command runs another formatter; use bun fmt");
|
|
151
|
+
if (automation === "workflow") workflowCommands.push(...commands);
|
|
152
|
+
if (require_toolchain_inputs.isLefthookConfigPath(file) && usesBun) {
|
|
153
|
+
const preCommit = record$1(parsed) ? parsed["pre-commit"] : void 0;
|
|
154
|
+
if (!commandLines(runValues(preCommit)).some((line) => isBunFormat(line, "--staged"))) add(file, lineOf(text, "pre-commit"), "lefthook pre-commit must run bun fmt --staged");
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (text !== "" && (require_toolchain_inputs.isDockerDefinitionPath(file) || require_toolchain_inputs.isShellScript(file, text))) {
|
|
159
|
+
for (const [index, line] of text.split(/\r?\n/u).entries()) if (!line.trimStart().startsWith("#") && invokesFormatter(line)) add(file, index + 1, "command runs another formatter; use bun fmt");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (!usesBun) return diagnostics;
|
|
163
|
+
const bunfig = files["bunfig.toml"];
|
|
164
|
+
if (bunfig !== void 0) for (const message of checkFormatConfig(bunfig, policy)) add("bunfig.toml", lineOf(bunfig, "[fmt"), message);
|
|
165
|
+
if (Object.keys(files).some((file) => require_toolchain_inputs.githubAutomationFileKind(file) === "workflow") && !commandLines(workflowCommands).some((line) => isBunFormat(line, "--check"))) add(".github/workflows", 1, "a workflow must run bun fmt --check over the whole repository");
|
|
166
|
+
return diagnostics;
|
|
167
|
+
};
|
|
168
|
+
//#endregion
|
|
3
169
|
//#region src/toolchain-schema.ts
|
|
4
170
|
const packagePinKeys = [
|
|
5
171
|
"oxlint",
|
|
6
172
|
"oxlint-tsgolint",
|
|
7
173
|
"@oxlint/plugins",
|
|
8
174
|
"@stll/oxlint-plugin",
|
|
9
|
-
"oxfmt",
|
|
10
175
|
"lefthook"
|
|
11
176
|
];
|
|
12
177
|
const valkeyArchitectures = ["amd64", "arm64"];
|
|
@@ -158,6 +323,7 @@ const parseToolchainPolicy = (input) => {
|
|
|
158
323
|
}
|
|
159
324
|
return {
|
|
160
325
|
bun,
|
|
326
|
+
formatter: parseFormatterPolicy(input["formatter"]),
|
|
161
327
|
typescript,
|
|
162
328
|
node,
|
|
163
329
|
postgres,
|
|
@@ -196,6 +362,18 @@ const parseToolchainPolicy = (input) => {
|
|
|
196
362
|
};
|
|
197
363
|
};
|
|
198
364
|
//#endregion
|
|
365
|
+
Object.defineProperty(exports, "checkFormatter", {
|
|
366
|
+
enumerable: true,
|
|
367
|
+
get: function() {
|
|
368
|
+
return checkFormatter;
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
Object.defineProperty(exports, "formatterRule", {
|
|
372
|
+
enumerable: true,
|
|
373
|
+
get: function() {
|
|
374
|
+
return formatterRule;
|
|
375
|
+
}
|
|
376
|
+
});
|
|
199
377
|
Object.defineProperty(exports, "parseToolchainPolicy", {
|
|
200
378
|
enumerable: true,
|
|
201
379
|
get: function() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolchain-schema.cjs","names":["valid","nodePolicyValid"],"sources":["../src/toolchain-schema.ts"],"sourcesContent":["import { valid } from \"semver\";\n\nimport { nodePolicyValid } from \"./toolchain-node\";\n\nexport const packagePinKeys = [\n \"oxlint\",\n \"oxlint-tsgolint\",\n \"@oxlint/plugins\",\n \"@stll/oxlint-plugin\",\n \"oxfmt\",\n \"lefthook\",\n] as const;\n\nexport const valkeyArchitectures = [\"amd64\", \"arm64\"] as const;\nexport const valkeyArtifactPackages = {\n server: \"valkey-server\",\n tools: \"valkey-tools\",\n} as const;\n\nconst record = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst artifactRecord = (value: unknown, keys: readonly string[]) => {\n if (\n !record(value) ||\n Object.keys(value).some((key) => !keys.includes(key)) ||\n keys.some((key) => !Object.hasOwn(value, key))\n )\n throw new Error(\n \"valkeyArtifacts requires complete, closed artifact objects\",\n );\n return value;\n};\n\nconst parseValkeyArtifacts = (input: unknown, version: string) => {\n const architectures = artifactRecord(input, valkeyArchitectures);\n const line = version.split(\".\").slice(0, 2).join(\".\");\n const parseArchitecture = (\n architecture: (typeof valkeyArchitectures)[number],\n ) => {\n const packages = artifactRecord(\n architectures[architecture],\n Object.keys(valkeyArtifactPackages),\n );\n const parseArtifact = (kind: keyof typeof valkeyArtifactPackages) => {\n const artifact = artifactRecord(packages[kind], [\"url\", \"sha256\"]);\n const url = artifact[\"url\"];\n const sha256 = artifact[\"sha256\"];\n const expected = `https://download.valkey.io/packaging/valkey-${line}/deb/ubuntu2404/${architecture}/${valkeyArtifactPackages[kind]}_${version}-1.noble_${architecture}.deb`;\n if (typeof url !== \"string\" || url !== expected)\n throw new Error(\n \"valkeyArtifacts URL must select the exact official versioned Ubuntu artifact\",\n );\n if (typeof sha256 !== \"string\" || !/^[a-f0-9]{64}$/.test(sha256))\n throw new Error(\"valkeyArtifacts requires a lowercase SHA256 pin\");\n return { url, sha256 };\n };\n return {\n server: parseArtifact(\"server\"),\n tools: parseArtifact(\"tools\"),\n } satisfies Record<\n keyof typeof valkeyArtifactPackages,\n ReturnType<typeof parseArtifact>\n >;\n };\n return {\n amd64: parseArchitecture(\"amd64\"),\n arm64: parseArchitecture(\"arm64\"),\n } satisfies Record<\n (typeof valkeyArchitectures)[number],\n ReturnType<typeof parseArchitecture>\n >;\n};\n\n/** Reject unsupported or incomplete installed policies before inspecting a consumer. */\nexport const parseToolchainPolicy = (input: unknown) => {\n if (!record(input) || input[\"schemaVersion\"] !== 1)\n throw new Error(\"toolchain.json must use schemaVersion 1\");\n const string = (object: Record<string, unknown>, key: string) => {\n const value = object[key];\n if (typeof value !== \"string\" || value.trim() === \"\")\n throw new Error(`toolchain.json requires a nonempty ${key}`);\n return value;\n };\n const packages: Record<string, string> = {};\n for (const key of packagePinKeys) packages[key] = string(input, key);\n const bun = string(input, \"bun\");\n const typescript = string(input, \"typescript\");\n const node = string(input, \"node\");\n const consumerNode = string(input, \"consumerNode\");\n const consumerNpm = string(input, \"consumerNpm\");\n const consumerPnpm = string(input, \"consumerPnpm\");\n const consumerTypescript = string(input, \"consumerTypescript\");\n const python = string(input, \"python\");\n const postgres = string(input, \"postgres\");\n const valkey = string(input, \"valkey\");\n const rust = string(input, \"rust\");\n for (const [name, value] of Object.entries({\n ...packages,\n bun,\n typescript,\n consumerNpm,\n consumerPnpm,\n consumerTypescript,\n }))\n if (valid(value) !== value)\n throw new Error(`toolchain.json ${name} must be an exact release`);\n if (!/^[1-9]\\d*$/.test(postgres) || !Number.isSafeInteger(Number(postgres)))\n throw new Error(\"PostgreSQL must be a canonical positive major\");\n if (valid(valkey) !== valkey || !/^\\d+\\.\\d+\\.\\d+$/.test(valkey))\n throw new Error(\"Valkey must be an exact stable release\");\n const valkeyArtifacts = parseValkeyArtifacts(\n input[\"valkeyArtifacts\"],\n valkey,\n );\n if (!nodePolicyValid(node))\n throw new Error(\"Node must be a canonical major N.x series\");\n if (\n valid(consumerNode) !== consumerNode ||\n !consumerNode.startsWith(\"22.\") ||\n consumerNode.includes(\"-\") ||\n consumerNode.includes(\"+\")\n )\n throw new Error(\"consumerNode must be an exact stable Node 22 release\");\n if (!/^\\d+\\.\\d+(?:\\.\\d+)?$/.test(python))\n throw new Error(\"Python must be an exact minor or patch release\");\n if (!/^\\d+\\.\\d+\\.\\d+$/.test(rust))\n throw new Error(\"Rust must be an exact stable release\");\n if (\n !consumerTypescript.startsWith(\"6.\") ||\n consumerTypescript.includes(\"-\") ||\n consumerTypescript.includes(\"+\")\n )\n throw new Error(\n \"consumerTypescript must be an exact stable TypeScript 6 release\",\n );\n const compatibility = input[\"typescript6Compatibility\"];\n if (!record(compatibility))\n throw new Error(\"missing TypeScript compatibility policy\");\n const version = string(compatibility, \"version\");\n const packageAlias = string(compatibility, \"packageAlias\");\n if (valid(version) !== version)\n throw new Error(\"TypeScript compatibility must be an exact release\");\n const layouts = input[\"typescriptInstallLayouts\"];\n if (!Array.isArray(layouts) || layouts.length === 0)\n throw new Error(\"missing TypeScript install layouts\");\n const typescriptInstallLayouts = layouts.map((layout: unknown) => {\n if (!record(layout)) throw new Error(\"invalid TypeScript install layout\");\n const compilerPackage = string(layout, \"compilerPackage\");\n const compilerSpecifier = string(layout, \"compilerSpecifier\");\n const typecheckCommand = string(layout, \"typecheckCommand\");\n switch (layout[\"type\"]) {\n case \"direct\":\n if (\n compilerSpecifier !== typescript ||\n compilerPackage !== \"typescript\"\n )\n throw new Error(\n \"direct TypeScript layout differs from shared version\",\n );\n return {\n type: \"direct\",\n compilerPackage,\n compilerSpecifier,\n typecheckCommand,\n } as const;\n case \"split-compatibility\": {\n const compatibilityPackage = string(layout, \"compatibilityPackage\");\n const compatibilitySpecifier = string(layout, \"compatibilitySpecifier\");\n if (\n compilerSpecifier !== `npm:typescript@${typescript}` ||\n compatibilitySpecifier !== version\n )\n throw new Error(\n \"split TypeScript layout differs from shared versions\",\n );\n return {\n type: \"split-compatibility\",\n compilerPackage,\n compilerSpecifier,\n compatibilityPackage,\n compatibilitySpecifier,\n typecheckCommand,\n } as const;\n }\n default:\n throw new Error(\"unsupported TypeScript install layout\");\n }\n });\n const actionsInput = input[\"actions\"];\n if (!record(actionsInput) || Object.keys(actionsInput).length === 0)\n throw new Error(\"missing approved actions\");\n const actions: Record<string, { sha: string; version: string }> = {};\n for (const [name, action] of Object.entries(actionsInput)) {\n if (!record(action)) throw new Error(`invalid action policy: ${name}`);\n const sha = string(action, \"sha\");\n const actionVersion = string(action, \"version\");\n if (!/^[a-f0-9]{40}$/.test(sha) || !/^v\\d+(?:\\.\\d+)*$/.test(actionVersion))\n throw new Error(`invalid action SHA/version: ${name}`);\n actions[name] = { sha, version: actionVersion };\n }\n const dependabotInput = input[\"dependabot\"];\n if (\n !record(dependabotInput) ||\n !record(dependabotInput[\"schedule\"]) ||\n !record(dependabotInput[\"cooldown\"]) ||\n !record(dependabotInput[\"groups\"])\n )\n throw new Error(\"missing Dependabot policy\");\n const scheduleInput = dependabotInput[\"schedule\"];\n const schedule = {\n interval: string(scheduleInput, \"interval\"),\n day: string(scheduleInput, \"day\"),\n time: string(scheduleInput, \"time\"),\n timezone: string(scheduleInput, \"timezone\"),\n };\n const defaultDays = dependabotInput[\"cooldown\"][\"defaultDays\"];\n if (\n typeof defaultDays !== \"number\" ||\n !Number.isInteger(defaultDays) ||\n defaultDays < 5\n )\n throw new Error(\"Dependabot cooldown must be at least five days\");\n const strings = (value: unknown): string[] => {\n if (\n !Array.isArray(value) ||\n !value.every((entry: unknown) => typeof entry === \"string\")\n )\n throw new Error(\"Dependabot group values must be string arrays\");\n return value;\n };\n const groups: Record<string, { patterns: string[]; updateTypes: string[] }> =\n {};\n for (const [name, group] of Object.entries(dependabotInput[\"groups\"])) {\n if (!record(group)) throw new Error(`invalid Dependabot group: ${name}`);\n groups[name] = {\n patterns: strings(group[\"patterns\"]),\n updateTypes: strings(group[\"updateTypes\"]),\n };\n }\n return {\n bun,\n typescript,\n node,\n postgres,\n valkey,\n valkeyArtifacts,\n consumerNode,\n consumerNpm,\n consumerPnpm,\n consumerTypescript,\n python,\n rust,\n packages,\n actions,\n typescriptInstallLayouts,\n typescript6Compatibility: { version, packageAlias },\n dependabot: {\n schedule,\n cooldown: { defaultDays },\n groups,\n ignoredPackages: [\n ...new Set([\n ...Object.keys(packages),\n ...typescriptInstallLayouts.flatMap((layout) =>\n layout.type === \"direct\"\n ? [layout.compilerPackage]\n : [layout.compilerPackage, layout.compatibilityPackage],\n ),\n packageAlias,\n \"bun-types\",\n ]),\n ],\n ignoredActions: Object.keys(actions),\n ignoredImages: [\"node\", \"python\", \"oven/bun\"],\n },\n };\n};\n"],"mappings":";;;AAIA,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,sBAAsB,CAAC,SAAS,OAAO;AACpD,MAAa,yBAAyB;CACpC,QAAQ;CACR,OAAO;AACT;AAEA,MAAM,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D;CAClE,MAAM,WAAW,UAA6B;EAC5C,IACE,CAAC,MAAM,QAAQ,KAAK,KACpB,CAAC,MAAM,OAAO,UAAmB,OAAO,UAAU,QAAQ,GAE1D,MAAM,IAAI,MAAM,+CAA+C;EACjE,OAAO;CACT;CACA,MAAM,SACJ,CAAC;CACH,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,gBAAgB,SAAS,GAAG;EACrE,IAAI,CAAC,OAAO,KAAK,GAAG,MAAM,IAAI,MAAM,6BAA6B,MAAM;EACvE,OAAO,QAAQ;GACb,UAAU,QAAQ,MAAM,WAAW;GACnC,aAAa,QAAQ,MAAM,cAAc;EAC3C;CACF;CACA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,0BAA0B;GAAE;GAAS;EAAa;EAClD,YAAY;GACV;GACA,UAAU,EAAE,YAAY;GACxB;GACA,iBAAiB,CACf,mBAAG,IAAI,IAAI;IACT,GAAG,OAAO,KAAK,QAAQ;IACvB,GAAG,yBAAyB,SAAS,WACnC,OAAO,SAAS,WACZ,CAAC,OAAO,eAAe,IACvB,CAAC,OAAO,iBAAiB,OAAO,oBAAoB,CAC1D;IACA;IACA;GACF,CAAC,CACH;GACA,gBAAgB,OAAO,KAAK,OAAO;GACnC,eAAe;IAAC;IAAQ;IAAU;GAAU;EAC9C;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"toolchain-schema.cjs","names":["record","path","parseToml","isFormatterConfigPath","githubAutomationFileKind","isLefthookConfigPath","parseDocument","isDockerDefinitionPath","isShellScript","valid","nodePolicyValid"],"sources":["../src/toolchain-formatter.ts","../src/toolchain-schema.ts"],"sourcesContent":["import path from \"node:path\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { parseDocument } from \"yaml\";\n\nimport {\n githubAutomationFileKind,\n isDockerDefinitionPath,\n isFormatterConfigPath,\n isLefthookConfigPath,\n isShellScript,\n} from \"./toolchain-inputs\";\n\nexport const formatterRule = \"formatter-policy\" as const;\n\ntype Diagnostic = {\n rule: typeof formatterRule;\n path: string;\n line: number;\n message: string;\n};\n\nexport type FormatterStyle = Readonly<Record<string, unknown>>;\n\nexport type FormatterPolicy = {\n command: \"bun fmt\";\n style: FormatterStyle;\n /** Generated files every repository leaves to their generators. */\n ignorePatterns: readonly string[];\n};\n\n/** Repository-owned [fmt] keys: what to skip, and the Tailwind entry point. */\nexport const repositoryFormatKeys = [\n \"ignorePatterns\",\n \"sortTailwindcss\",\n] as const;\n\nconst record = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/** One style for every repository; only repository-owned keys may differ. */\nexport const parseFormatterPolicy = (input: unknown): FormatterPolicy => {\n if (\n !record(input) ||\n Object.keys(input).some(\n (key) => key !== \"command\" && key !== \"style\" && key !== \"ignorePatterns\",\n )\n )\n throw new Error(\n \"toolchain.json formatter accepts only command, style and ignorePatterns\",\n );\n if (input[\"command\"] !== \"bun fmt\")\n throw new Error(\"toolchain.json formatter command must be bun fmt\");\n const style = input[\"style\"];\n if (!record(style) || Object.keys(style).length === 0)\n throw new Error(\"toolchain.json formatter style must be a nonempty table\");\n for (const key of Object.keys(style))\n if (repositoryFormatKeys.some((owned) => owned === key))\n throw new Error(\n `toolchain.json formatter style cannot own the repository key ${key}`,\n );\n const ignorePatterns = input[\"ignorePatterns\"];\n if (\n !Array.isArray(ignorePatterns) ||\n !ignorePatterns.every(\n (pattern): pattern is string =>\n typeof pattern === \"string\" && pattern !== \"\",\n )\n )\n throw new Error(\n \"toolchain.json formatter ignorePatterns must be nonempty strings\",\n );\n return { command: \"bun fmt\", style, ignorePatterns };\n};\n\nconst tomlValue = (value: unknown): string => {\n if (Array.isArray(value)) return `[${value.map(tomlValue).join(\", \")}]`;\n if (record(value))\n return `{ ${Object.entries(value)\n .map(([key, entry]) => `${key} = ${tomlValue(entry)}`)\n .join(\", \")} }`;\n return JSON.stringify(value);\n};\n\nconst tomlLines = (entries: readonly (readonly [string, unknown])[]) =>\n entries.map(([key, value]) => `${key} = ${tomlValue(value)}\\n`).join(\"\");\n\n/** Render the shared bunfig.toml [fmt] tables. */\nexport const sharedFormatTables = (policy: FormatterPolicy) => {\n const entries = Object.entries(policy.style);\n let output = `[fmt]\\n${tomlLines(\n entries.filter(([, value]) => !record(value)),\n )}ignorePatterns = ${tomlValue(policy.ignorePatterns)}\\n`;\n for (const [name, table] of entries)\n if (record(table))\n output += `\\n[fmt.${name}]\\n${tomlLines(Object.entries(table))}`;\n return output;\n};\n\nconst stableJson = (value: unknown): string =>\n JSON.stringify(value, (_key, entry: unknown) =>\n record(entry)\n ? Object.fromEntries(\n Object.entries(entry).toSorted(([left], [right]) =>\n left.localeCompare(right),\n ),\n )\n : entry,\n );\n\n// Every alternative formatter is rejected, not only the one being replaced.\nconst formatterPackage = (name: string) =>\n name === \"oxfmt\" ||\n name === \"prettier\" ||\n name === \"dprint\" ||\n name === \"@biomejs/biome\" ||\n name.startsWith(\"@dprint/\") ||\n /^(?:@[^/]+\\/)?prettier-plugin-/.test(name);\n\nconst dependencyFields = [\n \"dependencies\",\n \"devDependencies\",\n \"optionalDependencies\",\n \"peerDependencies\",\n \"overrides\",\n \"resolutions\",\n \"catalog\",\n] as const;\n\nconst declaredPackages = (manifest: Record<string, unknown>) => {\n const tables: unknown[] = dependencyFields.map((field) => manifest[field]);\n const workspaces = manifest[\"workspaces\"];\n for (const owner of [manifest, record(workspaces) ? workspaces : {}]) {\n if (owner !== manifest) tables.push(owner[\"catalog\"]);\n const catalogs = owner[\"catalogs\"];\n if (record(catalogs)) tables.push(...Object.values(catalogs));\n }\n return tables.flatMap((table) => (record(table) ? Object.keys(table) : []));\n};\n\nconst shellWords = (command: string) =>\n command\n .split(/[\\s;&|()<>`]+/u)\n .map((word) => word.replace(/^[\"']+|[\"']+$/gu, \"\"))\n .filter((word) => word !== \"\");\n\n/** Over-approximate: any formatter executable named as a word is an invocation. */\nconst invokesFormatter = (command: string) => {\n const words = shellWords(command);\n return words.some((word, index) => {\n const name = path.posix.basename(word);\n if (name === \"oxfmt\" || name === \"prettier\" || name === \"dprint\")\n return true;\n return (\n name === \"biome\" &&\n [\"format\", \"check\", \"ci\"].includes(words.at(index + 1) ?? \"\")\n );\n });\n};\n\nconst lineOf = (text: string, needle: string) =>\n Math.max(\n 1,\n text.split(/\\r?\\n/u).findIndex((line) => line.includes(needle)) + 1,\n );\n\n/** Collect every `run` string of a workflow, composite action or hook config. */\nconst runValues = (value: unknown): string[] => {\n if (Array.isArray(value)) return value.flatMap(runValues);\n if (!record(value)) return [];\n return Object.entries(value).flatMap(([key, entry]) =>\n key === \"run\" && typeof entry === \"string\" ? [entry] : runValues(entry),\n );\n};\n\nconst commandLines = (commands: readonly string[]) =>\n commands.flatMap((command) =>\n command\n .replace(/\\\\\\r?\\n/gu, \" \")\n .split(/\\r?\\n|&&|;/u)\n .map((line) => line.trim()),\n );\n\nconst isBunFormat = (line: string, flag: \"--check\" | \"--staged\") => {\n const words = shellWords(line);\n // Only flags may follow: a path operand narrows the check below the repository.\n return (\n words[0] === \"bun\" &&\n words[1] === \"fmt\" &&\n words.slice(2).includes(flag) &&\n words.slice(2).every((word) => word.startsWith(\"-\"))\n );\n};\n\nconst checkFormatConfig = (\n bunfig: string,\n policy: FormatterPolicy,\n): string[] => {\n let parsed: Record<string, unknown>;\n try {\n parsed = parseToml(bunfig);\n } catch {\n return [\"bunfig.toml must be valid TOML\"];\n }\n const fmt = parsed[\"fmt\"];\n if (!record(fmt))\n return [\n `bunfig.toml requires a [fmt] table: bun fmt reads its configuration only from there; start from:\\n${sharedFormatTables(policy)}`,\n ];\n const errors: string[] = [];\n for (const key of Object.keys(fmt))\n if (\n !Object.hasOwn(policy.style, key) &&\n !repositoryFormatKeys.some((owned) => owned === key)\n )\n errors.push(\n `bunfig.toml [fmt] ${key} is not part of the shared style; every repository formats alike`,\n );\n const ignored = Array.isArray(fmt[\"ignorePatterns\"])\n ? fmt[\"ignorePatterns\"]\n : [];\n const missing = policy.ignorePatterns.filter(\n (pattern) => !ignored.includes(pattern),\n );\n if (missing.length > 0)\n errors.push(\n `bunfig.toml [fmt] ignorePatterns must include the shared generated files: ${missing.join(\", \")}`,\n );\n for (const [key, value] of Object.entries(policy.style))\n if (stableJson(fmt[key]) !== stableJson(value))\n errors.push(\n `bunfig.toml [fmt] ${key} must equal the shared style:\\n${sharedFormatTables(policy)}`,\n );\n return errors;\n};\n\ntype CheckFormatterOptions = {\n files: Record<string, string>;\n policy: FormatterPolicy;\n usesBun: boolean;\n};\n\n/** bun fmt is the only formatter: one config table, staged hooks and a full CI check. */\nexport const checkFormatter = ({\n files,\n policy,\n usesBun,\n}: CheckFormatterOptions): Diagnostic[] => {\n const diagnostics: Diagnostic[] = [];\n const add = (file: string, line: number, message: string) =>\n diagnostics.push({ rule: formatterRule, path: file, line, message });\n const workflowCommands: string[] = [];\n for (const [file, text] of Object.entries(files)) {\n const name = path.posix.basename(file);\n if (isFormatterConfigPath(file))\n add(\n file,\n 1,\n \"formatter configuration belongs in bunfig.toml [fmt]; remove this file\",\n );\n if (name === \"package.json\") {\n let manifest: unknown;\n try {\n manifest = JSON.parse(text);\n } catch {\n // Package diagnostics already reject malformed manifests.\n continue;\n }\n if (!record(manifest)) continue;\n for (const dependency of declaredPackages(manifest))\n if (formatterPackage(dependency))\n add(\n file,\n lineOf(text, JSON.stringify(dependency)),\n `${dependency} is not allowed: bun fmt is the only formatter`,\n );\n if (manifest[\"prettier\"] !== undefined)\n add(\n file,\n lineOf(text, '\"prettier\"'),\n \"package.json prettier configuration belongs in bunfig.toml [fmt]\",\n );\n const scripts = manifest[\"scripts\"];\n if (record(scripts))\n for (const [script, command] of Object.entries(scripts)) {\n if (script === \"fmt\")\n add(\n file,\n lineOf(text, '\"fmt\"'),\n \"a package script named fmt shadows bun fmt; remove it\",\n );\n if (typeof command === \"string\" && invokesFormatter(command))\n add(\n file,\n lineOf(text, JSON.stringify(script)),\n `script ${script} runs another formatter; use bun fmt`,\n );\n }\n continue;\n }\n if (file === \".changeset/config.json\") {\n try {\n const config: unknown = JSON.parse(text);\n if (record(config) && config[\"format\"] !== false)\n add(\n file,\n lineOf(text, '\"format\"'),\n \"changesets must not run a formatter (format: false); format releases with bun fmt\",\n );\n } catch {\n add(file, 1, \"changeset configuration must be valid JSON\");\n }\n continue;\n }\n const automation = githubAutomationFileKind(file);\n if (automation !== undefined || isLefthookConfigPath(file)) {\n const document = parseDocument(text);\n if (document.errors.length > 0) continue;\n const parsed: unknown = document.toJS();\n const commands = runValues(parsed);\n for (const command of commands)\n if (invokesFormatter(command))\n add(\n file,\n lineOf(text, command.split(/\\r?\\n/u)[0] ?? command),\n \"command runs another formatter; use bun fmt\",\n );\n if (automation === \"workflow\") workflowCommands.push(...commands);\n if (isLefthookConfigPath(file) && usesBun) {\n const preCommit = record(parsed) ? parsed[\"pre-commit\"] : undefined;\n if (\n !commandLines(runValues(preCommit)).some((line) =>\n isBunFormat(line, \"--staged\"),\n )\n )\n add(\n file,\n lineOf(text, \"pre-commit\"),\n \"lefthook pre-commit must run bun fmt --staged\",\n );\n }\n continue;\n }\n if (\n text !== \"\" &&\n (isDockerDefinitionPath(file) || isShellScript(file, text))\n )\n for (const [index, line] of text.split(/\\r?\\n/u).entries())\n if (!line.trimStart().startsWith(\"#\") && invokesFormatter(line))\n add(file, index + 1, \"command runs another formatter; use bun fmt\");\n }\n if (!usesBun) return diagnostics;\n const bunfig = files[\"bunfig.toml\"];\n if (bunfig !== undefined)\n for (const message of checkFormatConfig(bunfig, policy))\n add(\"bunfig.toml\", lineOf(bunfig, \"[fmt\"), message);\n const hasWorkflows = Object.keys(files).some(\n (file) => githubAutomationFileKind(file) === \"workflow\",\n );\n if (\n hasWorkflows &&\n !commandLines(workflowCommands).some((line) => isBunFormat(line, \"--check\"))\n )\n add(\n \".github/workflows\",\n 1,\n \"a workflow must run bun fmt --check over the whole repository\",\n );\n return diagnostics;\n};\n","import { valid } from \"semver\";\n\nimport { parseFormatterPolicy } from \"./toolchain-formatter\";\nimport { nodePolicyValid } from \"./toolchain-node\";\n\nexport const packagePinKeys = [\n \"oxlint\",\n \"oxlint-tsgolint\",\n \"@oxlint/plugins\",\n \"@stll/oxlint-plugin\",\n \"lefthook\",\n] as const;\n\nexport const valkeyArchitectures = [\"amd64\", \"arm64\"] as const;\nexport const valkeyArtifactPackages = {\n server: \"valkey-server\",\n tools: \"valkey-tools\",\n} as const;\n\nconst record = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst artifactRecord = (value: unknown, keys: readonly string[]) => {\n if (\n !record(value) ||\n Object.keys(value).some((key) => !keys.includes(key)) ||\n keys.some((key) => !Object.hasOwn(value, key))\n )\n throw new Error(\n \"valkeyArtifacts requires complete, closed artifact objects\",\n );\n return value;\n};\n\nconst parseValkeyArtifacts = (input: unknown, version: string) => {\n const architectures = artifactRecord(input, valkeyArchitectures);\n const line = version.split(\".\").slice(0, 2).join(\".\");\n const parseArchitecture = (\n architecture: (typeof valkeyArchitectures)[number],\n ) => {\n const packages = artifactRecord(\n architectures[architecture],\n Object.keys(valkeyArtifactPackages),\n );\n const parseArtifact = (kind: keyof typeof valkeyArtifactPackages) => {\n const artifact = artifactRecord(packages[kind], [\"url\", \"sha256\"]);\n const url = artifact[\"url\"];\n const sha256 = artifact[\"sha256\"];\n const expected = `https://download.valkey.io/packaging/valkey-${line}/deb/ubuntu2404/${architecture}/${valkeyArtifactPackages[kind]}_${version}-1.noble_${architecture}.deb`;\n if (typeof url !== \"string\" || url !== expected)\n throw new Error(\n \"valkeyArtifacts URL must select the exact official versioned Ubuntu artifact\",\n );\n if (typeof sha256 !== \"string\" || !/^[a-f0-9]{64}$/.test(sha256))\n throw new Error(\"valkeyArtifacts requires a lowercase SHA256 pin\");\n return { url, sha256 };\n };\n return {\n server: parseArtifact(\"server\"),\n tools: parseArtifact(\"tools\"),\n } satisfies Record<\n keyof typeof valkeyArtifactPackages,\n ReturnType<typeof parseArtifact>\n >;\n };\n return {\n amd64: parseArchitecture(\"amd64\"),\n arm64: parseArchitecture(\"arm64\"),\n } satisfies Record<\n (typeof valkeyArchitectures)[number],\n ReturnType<typeof parseArchitecture>\n >;\n};\n\n/** Reject unsupported or incomplete installed policies before inspecting a consumer. */\nexport const parseToolchainPolicy = (input: unknown) => {\n if (!record(input) || input[\"schemaVersion\"] !== 1)\n throw new Error(\"toolchain.json must use schemaVersion 1\");\n const string = (object: Record<string, unknown>, key: string) => {\n const value = object[key];\n if (typeof value !== \"string\" || value.trim() === \"\")\n throw new Error(`toolchain.json requires a nonempty ${key}`);\n return value;\n };\n const packages: Record<string, string> = {};\n for (const key of packagePinKeys) packages[key] = string(input, key);\n const bun = string(input, \"bun\");\n const typescript = string(input, \"typescript\");\n const node = string(input, \"node\");\n const consumerNode = string(input, \"consumerNode\");\n const consumerNpm = string(input, \"consumerNpm\");\n const consumerPnpm = string(input, \"consumerPnpm\");\n const consumerTypescript = string(input, \"consumerTypescript\");\n const python = string(input, \"python\");\n const postgres = string(input, \"postgres\");\n const valkey = string(input, \"valkey\");\n const rust = string(input, \"rust\");\n for (const [name, value] of Object.entries({\n ...packages,\n bun,\n typescript,\n consumerNpm,\n consumerPnpm,\n consumerTypescript,\n }))\n if (valid(value) !== value)\n throw new Error(`toolchain.json ${name} must be an exact release`);\n if (!/^[1-9]\\d*$/.test(postgres) || !Number.isSafeInteger(Number(postgres)))\n throw new Error(\"PostgreSQL must be a canonical positive major\");\n if (valid(valkey) !== valkey || !/^\\d+\\.\\d+\\.\\d+$/.test(valkey))\n throw new Error(\"Valkey must be an exact stable release\");\n const valkeyArtifacts = parseValkeyArtifacts(\n input[\"valkeyArtifacts\"],\n valkey,\n );\n if (!nodePolicyValid(node))\n throw new Error(\"Node must be a canonical major N.x series\");\n if (\n valid(consumerNode) !== consumerNode ||\n !consumerNode.startsWith(\"22.\") ||\n consumerNode.includes(\"-\") ||\n consumerNode.includes(\"+\")\n )\n throw new Error(\"consumerNode must be an exact stable Node 22 release\");\n if (!/^\\d+\\.\\d+(?:\\.\\d+)?$/.test(python))\n throw new Error(\"Python must be an exact minor or patch release\");\n if (!/^\\d+\\.\\d+\\.\\d+$/.test(rust))\n throw new Error(\"Rust must be an exact stable release\");\n if (\n !consumerTypescript.startsWith(\"6.\") ||\n consumerTypescript.includes(\"-\") ||\n consumerTypescript.includes(\"+\")\n )\n throw new Error(\n \"consumerTypescript must be an exact stable TypeScript 6 release\",\n );\n const compatibility = input[\"typescript6Compatibility\"];\n if (!record(compatibility))\n throw new Error(\"missing TypeScript compatibility policy\");\n const version = string(compatibility, \"version\");\n const packageAlias = string(compatibility, \"packageAlias\");\n if (valid(version) !== version)\n throw new Error(\"TypeScript compatibility must be an exact release\");\n const layouts = input[\"typescriptInstallLayouts\"];\n if (!Array.isArray(layouts) || layouts.length === 0)\n throw new Error(\"missing TypeScript install layouts\");\n const typescriptInstallLayouts = layouts.map((layout: unknown) => {\n if (!record(layout)) throw new Error(\"invalid TypeScript install layout\");\n const compilerPackage = string(layout, \"compilerPackage\");\n const compilerSpecifier = string(layout, \"compilerSpecifier\");\n const typecheckCommand = string(layout, \"typecheckCommand\");\n switch (layout[\"type\"]) {\n case \"direct\":\n if (\n compilerSpecifier !== typescript ||\n compilerPackage !== \"typescript\"\n )\n throw new Error(\n \"direct TypeScript layout differs from shared version\",\n );\n return {\n type: \"direct\",\n compilerPackage,\n compilerSpecifier,\n typecheckCommand,\n } as const;\n case \"split-compatibility\": {\n const compatibilityPackage = string(layout, \"compatibilityPackage\");\n const compatibilitySpecifier = string(layout, \"compatibilitySpecifier\");\n if (\n compilerSpecifier !== `npm:typescript@${typescript}` ||\n compatibilitySpecifier !== version\n )\n throw new Error(\n \"split TypeScript layout differs from shared versions\",\n );\n return {\n type: \"split-compatibility\",\n compilerPackage,\n compilerSpecifier,\n compatibilityPackage,\n compatibilitySpecifier,\n typecheckCommand,\n } as const;\n }\n default:\n throw new Error(\"unsupported TypeScript install layout\");\n }\n });\n const actionsInput = input[\"actions\"];\n if (!record(actionsInput) || Object.keys(actionsInput).length === 0)\n throw new Error(\"missing approved actions\");\n const actions: Record<string, { sha: string; version: string }> = {};\n for (const [name, action] of Object.entries(actionsInput)) {\n if (!record(action)) throw new Error(`invalid action policy: ${name}`);\n const sha = string(action, \"sha\");\n const actionVersion = string(action, \"version\");\n if (!/^[a-f0-9]{40}$/.test(sha) || !/^v\\d+(?:\\.\\d+)*$/.test(actionVersion))\n throw new Error(`invalid action SHA/version: ${name}`);\n actions[name] = { sha, version: actionVersion };\n }\n const dependabotInput = input[\"dependabot\"];\n if (\n !record(dependabotInput) ||\n !record(dependabotInput[\"schedule\"]) ||\n !record(dependabotInput[\"cooldown\"]) ||\n !record(dependabotInput[\"groups\"])\n )\n throw new Error(\"missing Dependabot policy\");\n const scheduleInput = dependabotInput[\"schedule\"];\n const schedule = {\n interval: string(scheduleInput, \"interval\"),\n day: string(scheduleInput, \"day\"),\n time: string(scheduleInput, \"time\"),\n timezone: string(scheduleInput, \"timezone\"),\n };\n const defaultDays = dependabotInput[\"cooldown\"][\"defaultDays\"];\n if (\n typeof defaultDays !== \"number\" ||\n !Number.isInteger(defaultDays) ||\n defaultDays < 5\n )\n throw new Error(\"Dependabot cooldown must be at least five days\");\n const strings = (value: unknown): string[] => {\n if (\n !Array.isArray(value) ||\n !value.every((entry: unknown) => typeof entry === \"string\")\n )\n throw new Error(\"Dependabot group values must be string arrays\");\n return value;\n };\n const groups: Record<string, { patterns: string[]; updateTypes: string[] }> =\n {};\n for (const [name, group] of Object.entries(dependabotInput[\"groups\"])) {\n if (!record(group)) throw new Error(`invalid Dependabot group: ${name}`);\n groups[name] = {\n patterns: strings(group[\"patterns\"]),\n updateTypes: strings(group[\"updateTypes\"]),\n };\n }\n return {\n bun,\n formatter: parseFormatterPolicy(input[\"formatter\"]),\n typescript,\n node,\n postgres,\n valkey,\n valkeyArtifacts,\n consumerNode,\n consumerNpm,\n consumerPnpm,\n consumerTypescript,\n python,\n rust,\n packages,\n actions,\n typescriptInstallLayouts,\n typescript6Compatibility: { version, packageAlias },\n dependabot: {\n schedule,\n cooldown: { defaultDays },\n groups,\n ignoredPackages: [\n ...new Set([\n ...Object.keys(packages),\n ...typescriptInstallLayouts.flatMap((layout) =>\n layout.type === \"direct\"\n ? [layout.compilerPackage]\n : [layout.compilerPackage, layout.compatibilityPackage],\n ),\n packageAlias,\n \"bun-types\",\n ]),\n ],\n ignoredActions: Object.keys(actions),\n ignoredImages: [\"node\", \"python\", \"oven/bun\"],\n },\n };\n};\n"],"mappings":";;;;;;;;AAYA,MAAa,gBAAgB;;AAmB7B,MAAa,uBAAuB,CAClC,kBACA,iBACF;AAEA,MAAMA,YAAU,UACd,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,MAAa,wBAAwB,UAAoC;CACvE,IACE,CAACA,SAAO,KAAK,KACb,OAAO,KAAK,KAAK,CAAC,CAAC,MAChB,QAAQ,QAAQ,aAAa,QAAQ,WAAW,QAAQ,gBAC3D,GAEA,MAAM,IAAI,MACR,yEACF;CACF,IAAI,MAAM,eAAe,WACvB,MAAM,IAAI,MAAM,kDAAkD;CACpE,MAAM,QAAQ,MAAM;CACpB,IAAI,CAACA,SAAO,KAAK,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,GAClD,MAAM,IAAI,MAAM,yDAAyD;CAC3E,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GACjC,IAAI,qBAAqB,MAAM,UAAU,UAAU,GAAG,GACpD,MAAM,IAAI,MACR,gEAAgE,KAClE;CACJ,MAAM,iBAAiB,MAAM;CAC7B,IACE,CAAC,MAAM,QAAQ,cAAc,KAC7B,CAAC,eAAe,OACb,YACC,OAAO,YAAY,YAAY,YAAY,EAC/C,GAEA,MAAM,IAAI,MACR,kEACF;CACF,OAAO;EAAE,SAAS;EAAW;EAAO;CAAe;AACrD;AAEA,MAAM,aAAa,UAA2B;CAC5C,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icyValid, a as isFormatterConfigPath, i as isDockerDefinitionPath, l as isShellScript, n as githubAutomationFileKind, o as isLefthookConfigPath } from "./toolchain-inputs.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parse } from "smol-toml";
|
|
2
4
|
import { valid } from "semver";
|
|
5
|
+
import { parseDocument } from "yaml";
|
|
6
|
+
//#region src/toolchain-formatter.ts
|
|
7
|
+
const formatterRule = "formatter-policy";
|
|
8
|
+
/** Repository-owned [fmt] keys: what to skip, and the Tailwind entry point. */
|
|
9
|
+
const repositoryFormatKeys = ["ignorePatterns", "sortTailwindcss"];
|
|
10
|
+
const record$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
/** One style for every repository; only repository-owned keys may differ. */
|
|
12
|
+
const parseFormatterPolicy = (input) => {
|
|
13
|
+
if (!record$1(input) || Object.keys(input).some((key) => key !== "command" && key !== "style" && key !== "ignorePatterns")) throw new Error("toolchain.json formatter accepts only command, style and ignorePatterns");
|
|
14
|
+
if (input["command"] !== "bun fmt") throw new Error("toolchain.json formatter command must be bun fmt");
|
|
15
|
+
const style = input["style"];
|
|
16
|
+
if (!record$1(style) || Object.keys(style).length === 0) throw new Error("toolchain.json formatter style must be a nonempty table");
|
|
17
|
+
for (const key of Object.keys(style)) if (repositoryFormatKeys.some((owned) => owned === key)) throw new Error(`toolchain.json formatter style cannot own the repository key ${key}`);
|
|
18
|
+
const ignorePatterns = input["ignorePatterns"];
|
|
19
|
+
if (!Array.isArray(ignorePatterns) || !ignorePatterns.every((pattern) => typeof pattern === "string" && pattern !== "")) throw new Error("toolchain.json formatter ignorePatterns must be nonempty strings");
|
|
20
|
+
return {
|
|
21
|
+
command: "bun fmt",
|
|
22
|
+
style,
|
|
23
|
+
ignorePatterns
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const tomlValue = (value) => {
|
|
27
|
+
if (Array.isArray(value)) return `[${value.map(tomlValue).join(", ")}]`;
|
|
28
|
+
if (record$1(value)) return `{ ${Object.entries(value).map(([key, entry]) => `${key} = ${tomlValue(entry)}`).join(", ")} }`;
|
|
29
|
+
return JSON.stringify(value);
|
|
30
|
+
};
|
|
31
|
+
const tomlLines = (entries) => entries.map(([key, value]) => `${key} = ${tomlValue(value)}\n`).join("");
|
|
32
|
+
/** Render the shared bunfig.toml [fmt] tables. */
|
|
33
|
+
const sharedFormatTables = (policy) => {
|
|
34
|
+
const entries = Object.entries(policy.style);
|
|
35
|
+
let output = `[fmt]\n${tomlLines(entries.filter(([, value]) => !record$1(value)))}ignorePatterns = ${tomlValue(policy.ignorePatterns)}\n`;
|
|
36
|
+
for (const [name, table] of entries) if (record$1(table)) output += `\n[fmt.${name}]\n${tomlLines(Object.entries(table))}`;
|
|
37
|
+
return output;
|
|
38
|
+
};
|
|
39
|
+
const stableJson = (value) => JSON.stringify(value, (_key, entry) => record$1(entry) ? Object.fromEntries(Object.entries(entry).toSorted(([left], [right]) => left.localeCompare(right))) : entry);
|
|
40
|
+
const formatterPackage = (name) => name === "oxfmt" || name === "prettier" || name === "dprint" || name === "@biomejs/biome" || name.startsWith("@dprint/") || /^(?:@[^/]+\/)?prettier-plugin-/.test(name);
|
|
41
|
+
const dependencyFields = [
|
|
42
|
+
"dependencies",
|
|
43
|
+
"devDependencies",
|
|
44
|
+
"optionalDependencies",
|
|
45
|
+
"peerDependencies",
|
|
46
|
+
"overrides",
|
|
47
|
+
"resolutions",
|
|
48
|
+
"catalog"
|
|
49
|
+
];
|
|
50
|
+
const declaredPackages = (manifest) => {
|
|
51
|
+
const tables = dependencyFields.map((field) => manifest[field]);
|
|
52
|
+
const workspaces = manifest["workspaces"];
|
|
53
|
+
for (const owner of [manifest, record$1(workspaces) ? workspaces : {}]) {
|
|
54
|
+
if (owner !== manifest) tables.push(owner["catalog"]);
|
|
55
|
+
const catalogs = owner["catalogs"];
|
|
56
|
+
if (record$1(catalogs)) tables.push(...Object.values(catalogs));
|
|
57
|
+
}
|
|
58
|
+
return tables.flatMap((table) => record$1(table) ? Object.keys(table) : []);
|
|
59
|
+
};
|
|
60
|
+
const shellWords = (command) => command.split(/[\s;&|()<>`]+/u).map((word) => word.replace(/^["']+|["']+$/gu, "")).filter((word) => word !== "");
|
|
61
|
+
/** Over-approximate: any formatter executable named as a word is an invocation. */
|
|
62
|
+
const invokesFormatter = (command) => {
|
|
63
|
+
const words = shellWords(command);
|
|
64
|
+
return words.some((word, index) => {
|
|
65
|
+
const name = path.posix.basename(word);
|
|
66
|
+
if (name === "oxfmt" || name === "prettier" || name === "dprint") return true;
|
|
67
|
+
return name === "biome" && [
|
|
68
|
+
"format",
|
|
69
|
+
"check",
|
|
70
|
+
"ci"
|
|
71
|
+
].includes(words.at(index + 1) ?? "");
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const lineOf = (text, needle) => Math.max(1, text.split(/\r?\n/u).findIndex((line) => line.includes(needle)) + 1);
|
|
75
|
+
/** Collect every `run` string of a workflow, composite action or hook config. */
|
|
76
|
+
const runValues = (value) => {
|
|
77
|
+
if (Array.isArray(value)) return value.flatMap(runValues);
|
|
78
|
+
if (!record$1(value)) return [];
|
|
79
|
+
return Object.entries(value).flatMap(([key, entry]) => key === "run" && typeof entry === "string" ? [entry] : runValues(entry));
|
|
80
|
+
};
|
|
81
|
+
const commandLines = (commands) => commands.flatMap((command) => command.replace(/\\\r?\n/gu, " ").split(/\r?\n|&&|;/u).map((line) => line.trim()));
|
|
82
|
+
const isBunFormat = (line, flag) => {
|
|
83
|
+
const words = shellWords(line);
|
|
84
|
+
return words[0] === "bun" && words[1] === "fmt" && words.slice(2).includes(flag) && words.slice(2).every((word) => word.startsWith("-"));
|
|
85
|
+
};
|
|
86
|
+
const checkFormatConfig = (bunfig, policy) => {
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
parsed = parse(bunfig);
|
|
90
|
+
} catch {
|
|
91
|
+
return ["bunfig.toml must be valid TOML"];
|
|
92
|
+
}
|
|
93
|
+
const fmt = parsed["fmt"];
|
|
94
|
+
if (!record$1(fmt)) return [`bunfig.toml requires a [fmt] table: bun fmt reads its configuration only from there; start from:\n${sharedFormatTables(policy)}`];
|
|
95
|
+
const errors = [];
|
|
96
|
+
for (const key of Object.keys(fmt)) if (!Object.hasOwn(policy.style, key) && !repositoryFormatKeys.some((owned) => owned === key)) errors.push(`bunfig.toml [fmt] ${key} is not part of the shared style; every repository formats alike`);
|
|
97
|
+
const ignored = Array.isArray(fmt["ignorePatterns"]) ? fmt["ignorePatterns"] : [];
|
|
98
|
+
const missing = policy.ignorePatterns.filter((pattern) => !ignored.includes(pattern));
|
|
99
|
+
if (missing.length > 0) errors.push(`bunfig.toml [fmt] ignorePatterns must include the shared generated files: ${missing.join(", ")}`);
|
|
100
|
+
for (const [key, value] of Object.entries(policy.style)) if (stableJson(fmt[key]) !== stableJson(value)) errors.push(`bunfig.toml [fmt] ${key} must equal the shared style:\n${sharedFormatTables(policy)}`);
|
|
101
|
+
return errors;
|
|
102
|
+
};
|
|
103
|
+
/** bun fmt is the only formatter: one config table, staged hooks and a full CI check. */
|
|
104
|
+
const checkFormatter = ({ files, policy, usesBun }) => {
|
|
105
|
+
const diagnostics = [];
|
|
106
|
+
const add = (file, line, message) => diagnostics.push({
|
|
107
|
+
rule: formatterRule,
|
|
108
|
+
path: file,
|
|
109
|
+
line,
|
|
110
|
+
message
|
|
111
|
+
});
|
|
112
|
+
const workflowCommands = [];
|
|
113
|
+
for (const [file, text] of Object.entries(files)) {
|
|
114
|
+
const name = path.posix.basename(file);
|
|
115
|
+
if (isFormatterConfigPath(file)) add(file, 1, "formatter configuration belongs in bunfig.toml [fmt]; remove this file");
|
|
116
|
+
if (name === "package.json") {
|
|
117
|
+
let manifest;
|
|
118
|
+
try {
|
|
119
|
+
manifest = JSON.parse(text);
|
|
120
|
+
} catch {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (!record$1(manifest)) continue;
|
|
124
|
+
for (const dependency of declaredPackages(manifest)) if (formatterPackage(dependency)) add(file, lineOf(text, JSON.stringify(dependency)), `${dependency} is not allowed: bun fmt is the only formatter`);
|
|
125
|
+
if (manifest["prettier"] !== void 0) add(file, lineOf(text, "\"prettier\""), "package.json prettier configuration belongs in bunfig.toml [fmt]");
|
|
126
|
+
const scripts = manifest["scripts"];
|
|
127
|
+
if (record$1(scripts)) for (const [script, command] of Object.entries(scripts)) {
|
|
128
|
+
if (script === "fmt") add(file, lineOf(text, "\"fmt\""), "a package script named fmt shadows bun fmt; remove it");
|
|
129
|
+
if (typeof command === "string" && invokesFormatter(command)) add(file, lineOf(text, JSON.stringify(script)), `script ${script} runs another formatter; use bun fmt`);
|
|
130
|
+
}
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (file === ".changeset/config.json") {
|
|
134
|
+
try {
|
|
135
|
+
const config = JSON.parse(text);
|
|
136
|
+
if (record$1(config) && config["format"] !== false) add(file, lineOf(text, "\"format\""), "changesets must not run a formatter (format: false); format releases with bun fmt");
|
|
137
|
+
} catch {
|
|
138
|
+
add(file, 1, "changeset configuration must be valid JSON");
|
|
139
|
+
}
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const automation = githubAutomationFileKind(file);
|
|
143
|
+
if (automation !== void 0 || isLefthookConfigPath(file)) {
|
|
144
|
+
const document = parseDocument(text);
|
|
145
|
+
if (document.errors.length > 0) continue;
|
|
146
|
+
const parsed = document.toJS();
|
|
147
|
+
const commands = runValues(parsed);
|
|
148
|
+
for (const command of commands) if (invokesFormatter(command)) add(file, lineOf(text, command.split(/\r?\n/u)[0] ?? command), "command runs another formatter; use bun fmt");
|
|
149
|
+
if (automation === "workflow") workflowCommands.push(...commands);
|
|
150
|
+
if (isLefthookConfigPath(file) && usesBun) {
|
|
151
|
+
const preCommit = record$1(parsed) ? parsed["pre-commit"] : void 0;
|
|
152
|
+
if (!commandLines(runValues(preCommit)).some((line) => isBunFormat(line, "--staged"))) add(file, lineOf(text, "pre-commit"), "lefthook pre-commit must run bun fmt --staged");
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (text !== "" && (isDockerDefinitionPath(file) || isShellScript(file, text))) {
|
|
157
|
+
for (const [index, line] of text.split(/\r?\n/u).entries()) if (!line.trimStart().startsWith("#") && invokesFormatter(line)) add(file, index + 1, "command runs another formatter; use bun fmt");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!usesBun) return diagnostics;
|
|
161
|
+
const bunfig = files["bunfig.toml"];
|
|
162
|
+
if (bunfig !== void 0) for (const message of checkFormatConfig(bunfig, policy)) add("bunfig.toml", lineOf(bunfig, "[fmt"), message);
|
|
163
|
+
if (Object.keys(files).some((file) => githubAutomationFileKind(file) === "workflow") && !commandLines(workflowCommands).some((line) => isBunFormat(line, "--check"))) add(".github/workflows", 1, "a workflow must run bun fmt --check over the whole repository");
|
|
164
|
+
return diagnostics;
|
|
165
|
+
};
|
|
166
|
+
//#endregion
|
|
3
167
|
//#region src/toolchain-schema.ts
|
|
4
168
|
const packagePinKeys = [
|
|
5
169
|
"oxlint",
|
|
6
170
|
"oxlint-tsgolint",
|
|
7
171
|
"@oxlint/plugins",
|
|
8
172
|
"@stll/oxlint-plugin",
|
|
9
|
-
"oxfmt",
|
|
10
173
|
"lefthook"
|
|
11
174
|
];
|
|
12
175
|
const valkeyArchitectures = ["amd64", "arm64"];
|
|
@@ -158,6 +321,7 @@ const parseToolchainPolicy = (input) => {
|
|
|
158
321
|
}
|
|
159
322
|
return {
|
|
160
323
|
bun,
|
|
324
|
+
formatter: parseFormatterPolicy(input["formatter"]),
|
|
161
325
|
typescript,
|
|
162
326
|
node,
|
|
163
327
|
postgres,
|
|
@@ -196,6 +360,6 @@ const parseToolchainPolicy = (input) => {
|
|
|
196
360
|
};
|
|
197
361
|
};
|
|
198
362
|
//#endregion
|
|
199
|
-
export { parseToolchainPolicy as t };
|
|
363
|
+
export { checkFormatter as n, formatterRule as r, parseToolchainPolicy as t };
|
|
200
364
|
|
|
201
365
|
//# sourceMappingURL=toolchain-schema.mjs.map
|