@vwala/tooling-config 1.1.0 → 1.3.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.
@@ -5,6 +5,10 @@
5
5
  // shape and is not matched, and template-literal titles are skipped because the
6
6
  // interpolated text is not visible to the regex.
7
7
  //
8
+ // `$...` after the title absorbs the callback and any trailing timeout, so
9
+ // `test(title, fn)` and `test(title, fn, timeout)` are both visible. Matching
10
+ // exactly two arguments left the three-argument form unchecked.
11
+ //
8
12
  // This matches `test(...)` only, not `it(...)` — which is why the
9
13
  // `useConsistentTestIt` rule in biome.json has to stay on. Turn that off and a
10
14
  // title reverted to `it()` becomes invisible here.
@@ -13,7 +17,7 @@
13
17
  // makes Biome reformat the line to single quotes, which fails `biome ci`.
14
18
  //
15
19
  // See: .agents/skills/vwala-conventions/references/test-style.md
16
- `test($title, $body)` as $node where {
20
+ `test($title, $...)` as $node where {
17
21
  $title <: r"(?s)\"[^\"]*\"",
18
22
  $title <: not r"(?s).*GIVEN.*WHEN.*THEN.*",
19
23
  register_diagnostic(span=$title, message="Name the test GIVEN … WHEN … THEN … so the failure describes the scenario.", severity="error")
@@ -0,0 +1,60 @@
1
+ // Every package-manager invocation in a package.json script goes through pnpm:
2
+ // `pnpm install`, `pnpm add`, `pnpm run`, `pnpm dlx`. npm and yarn in a pnpm
3
+ // repository write a second lockfile and resolve a different dependency tree
4
+ // from the one CI installs, so the script that passes locally is not the script
5
+ // that runs in CI.
6
+ //
7
+ // `language json` is what makes this possible at all — GritQL only learned to
8
+ // parse JSON in Biome 2.4, which is why the four sibling plugins are all
9
+ // JavaScript. Those four declare no language and so default to JavaScript,
10
+ // which is also why none of them fire on the fixtures here.
11
+ //
12
+ // `within` walks the ancestors, so the enclosing `"scripts"` key scopes the
13
+ // rule: a `"description"` mentioning npm, an `npm-run-all` devDependency, and
14
+ // an `npm:` alias in `dependencies` are all invisible to it. The query root is
15
+ // re-executed per node with a fresh scope, so N offending scripts produce N
16
+ // diagnostics without `bubble`.
17
+ //
18
+ // The regex full-matches the node text INCLUDING its surrounding quotes — the
19
+ // same semantics use-given-when-then-test-names.grit relies on — which is what
20
+ // makes the leading `\"` usable as "start of the command". The other command
21
+ // position is after a shell separator, hence `.*[;&|(]`. Every group has to be
22
+ // non-capturing: Biome binds regex captures as pattern variables, so a plain
23
+ // `(` fails the plugin with `regex pattern matched N variables, but expected
24
+ // 0`. There is no `(?s)` either, unlike the JavaScript plugins, because a JSON
25
+ // string never holds a raw newline.
26
+ //
27
+ // npm is gated on its install and run verbs rather than on the bare word, so
28
+ // the registry operations npm genuinely owns still pass — `npm publish`,
29
+ // `npm view`, `npm pkg set`, `npm --version`. That is not a courtesy: OIDC
30
+ // trusted publishing needs the npm CLI, and this package's own release workflow
31
+ // runs all four. yarn is flagged unconditionally, matched as `yarn[ \t\";&|]`
32
+ // so the `yarn-deduplicate` binary is left alone. `npx` is flagged unless it is
33
+ // `npx --no`, which resolves the LOCAL binary and refuses to fetch — the same
34
+ // property that satisfies zizmor's adhoc-packages rule in
35
+ // src/commitlint/action.yml. Rust's regex has no lookaround, so that one
36
+ // exception is spelled out by expanding the alternatives that may follow
37
+ // `npx `.
38
+ //
39
+ // biome.json scopes this to `["**/package.json"]`, which matches the root file
40
+ // and every nested one. The glob is not redundant with `language json`: without
41
+ // it the plugin would also lint tsconfig.json, app.json, and the fixture
42
+ // workspace's own biome.json.
43
+ //
44
+ // Known gaps: commands the `scripts` object cannot see — a `lint-staged` array
45
+ // elsewhere in package.json, turbo.json, CI workflows, git hooks, Dockerfiles —
46
+ // plus the lockfile and `packageManager` halves of the convention. Those live
47
+ // in `_scripts/check-pnpm.mjs`. A plugin also cannot see the convention's own
48
+ // escape hatch, so a repository that deliberately uses another package manager
49
+ // has to drop this entry from its own `plugins` array.
50
+ //
51
+ // See: .agents/skills/vwala-conventions/references/prefer-pnpm.md
52
+ language json
53
+
54
+ JsonMember(value=$command) as $node where {
55
+ $node <: within JsonMember(name=$section) where {
56
+ $section <: r"\"scripts\""
57
+ } ,
58
+ $command <: r"(?:\"|.*[;&|(])[ \t]*(?:npm[ \t]+(?:install|i|ci|add|run|run-script|exec|x|test|start|update|uninstall|remove|rm|link|rebuild|prune|dedupe|init|create)\b|yarn[ \t\";&|]|npx[ \t]+(?:--no[a-zA-Z0-9]|--n[^o]|--[^n]|-[^-]|[^-\t ])).*",
59
+ register_diagnostic(span=$command, message="Run this through pnpm — `pnpm install`, `pnpm add`, `pnpm run`, `pnpm dlx`. npm and yarn in a pnpm repo write a second lockfile and resolve a different tree than CI installs. `npx --no -- <bin>` is the one exception: it runs the locally installed binary and refuses to fetch.", severity="error")
60
+ }
@@ -4,4 +4,4 @@ if [ -n "${2:-}" ]; then
4
4
  exit 0
5
5
  fi
6
6
 
7
- exec < /dev/tty && npx cz --hook || true
7
+ exec < /dev/tty && npx --no -- cz --hook || true
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Every package under `packages/modules/` owns a bounded area of the business,
4
+ * so every one of them declares its domain language in `CONTEXT.md`.
5
+ *
6
+ * Without it each module invents its own words for the same thing — one calls
7
+ * it an order, the next a purchase, the third a transaction — and the cost only
8
+ * shows up later, when the three have to talk to each other and nobody can say
9
+ * whether they mean the same thing. `packages/platform/` and `packages/tooling/`
10
+ * are excluded on purpose: they hold code with no domain knowledge, so they
11
+ * have no domain language to declare.
12
+ *
13
+ * Existence and non-emptiness are all that is checked. The convention asks for
14
+ * a glossary written as terms crystallise, and a checker that demanded headings
15
+ * and a minimum term count would only teach people to satisfy it with a heading
16
+ * and a fake term.
17
+ *
18
+ * Biome cannot express this. A missing file has no syntax to parse.
19
+ *
20
+ * See: .agents/skills/vwala-conventions/references/domain-language-in-context-md.md
21
+ * See: .agents/skills/vwala-conventions/references/monorepo-structure.md
22
+ */
23
+ import {
24
+ readBlob,
25
+ readIndexEntries,
26
+ SYMLINK_MODE,
27
+ } from "../../_scripts/git-index.mjs";
28
+
29
+ const MODULES_ROOT = "packages/modules/";
30
+ const MANIFEST = "package.json";
31
+ const CONTEXT_FILE = "CONTEXT.md";
32
+
33
+ /**
34
+ * Folders a workspace package never has as an ancestor. A `package.json` below
35
+ * one of these belongs to a fixture, a build output, or a vendored dependency
36
+ * rather than to a module.
37
+ */
38
+ const NOT_A_PACKAGE_ROOT = new Set([
39
+ "node_modules",
40
+ "src",
41
+ "dist",
42
+ "build",
43
+ "__tests__",
44
+ "test-support",
45
+ "fixtures",
46
+ ]);
47
+
48
+ const entries = readIndexEntries();
49
+ const byPath = new Map(entries.map((entry) => [entry.path, entry]));
50
+
51
+ /**
52
+ * A module is a package, so its `package.json` is what marks it — a directory
53
+ * with no tracked files does not exist to git, and one without a manifest is a
54
+ * folder rather than a workspace package.
55
+ *
56
+ * Depth is not fixed. Modules nest (`packages/modules/act/enrich/`) and may be
57
+ * scoped (`packages/modules/@acme/invoicing/`), so every manifest under
58
+ * `packages/modules/` counts — including one at a grouping level that also has
59
+ * modules beneath it, because a directory carrying a manifest is a package and
60
+ * a package here is a module. Excluding by ancestor folder rather than by depth
61
+ * is what keeps a fixture's manifest from registering as a module of its own.
62
+ */
63
+ const modules = entries
64
+ .filter(
65
+ (entry) =>
66
+ entry.path.startsWith(MODULES_ROOT) &&
67
+ entry.path.endsWith(`/${MANIFEST}`) &&
68
+ !entry.path
69
+ .slice(MODULES_ROOT.length, -`/${MANIFEST}`.length)
70
+ .split("/")
71
+ .some((segment) => NOT_A_PACKAGE_ROOT.has(segment)),
72
+ )
73
+ .map((entry) => entry.path.slice(0, -MANIFEST.length))
74
+ .sort();
75
+
76
+ const violations = [];
77
+
78
+ for (const module of modules) {
79
+ const contextPath = `${module}${CONTEXT_FILE}`;
80
+ const context = byPath.get(contextPath);
81
+
82
+ if (context === undefined) {
83
+ // macOS filesystems are case-insensitive, so a `Context.md` looks present
84
+ // in an editor while git tracks the name that was actually committed.
85
+ // Saying which is which beats "missing" on a file the author can see.
86
+ const miscased = entries.find(
87
+ (entry) =>
88
+ entry.path.toLowerCase() === contextPath.toLowerCase() &&
89
+ entry.path !== contextPath,
90
+ );
91
+
92
+ violations.push(
93
+ miscased === undefined
94
+ ? `${contextPath}\n Missing. Every module under ${MODULES_ROOT} declares its domain language in ${CONTEXT_FILE}.`
95
+ : `${miscased.path}\n Wrong case. Rename it to ${CONTEXT_FILE}.`,
96
+ );
97
+ continue;
98
+ }
99
+
100
+ if (context.mode === SYMLINK_MODE) {
101
+ violations.push(
102
+ `${contextPath}\n Symlink. A module's domain language is its own; it cannot be borrowed from another module.`,
103
+ );
104
+ continue;
105
+ }
106
+
107
+ if (readBlob({ sha: context.sha }).trim() === "") {
108
+ violations.push(
109
+ `${contextPath}\n Empty. Write the module's terms, or the file is a placeholder that says nothing.`,
110
+ );
111
+ }
112
+ }
113
+
114
+ if (violations.length > 0) {
115
+ console.error(`\n ✖ ${violations.length} module-context violation(s):\n`);
116
+ for (const violation of violations) {
117
+ console.error(` ${violation}\n`);
118
+ }
119
+ process.exit(1);
120
+ }
121
+
122
+ console.log(" ✔ module context clean");
@@ -0,0 +1,369 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The package-manifest half of the packaging convention: a shared package
4
+ * declares its entry points in `exports`, one explicit subpath each, and
5
+ * nothing else claims to be an entry point. Biome reasons about syntax and
6
+ * never opens a `package.json`, so this cannot be a lint rule.
7
+ *
8
+ * Scope is two rules, not one, because "must have an exports map" and "the
9
+ * exports map must be well formed" are different questions:
10
+ *
11
+ * - Only `packages/**` has to *have* an `exports` map and a scoped name. An
12
+ * app under `apps/` is bundled by Next or Expo and imported by nobody, so an
13
+ * entry-point map would be ceremony; the workspace root is not a package.
14
+ * - *Any* manifest that declares `exports` has its shape checked, wherever it
15
+ * lives. If you wrote an entry-point map, it has to be one — which is also
16
+ * what lets this package check its own root manifest.
17
+ *
18
+ * Detection is by path rather than by `private`, because `private` does not
19
+ * separate the two: an app and an internal package are both routinely private.
20
+ * `packages/` is a mandated layout, so the prefix enforces a documented rule
21
+ * instead of guessing. It is a prefix rather than `packages/*\/`, because the
22
+ * layout nests a category: `packages/<tooling|modules|platform>/<name>/`.
23
+ *
24
+ * Severity follows age, like check-naming, because an exports map is a
25
+ * published contract: migrating one means updating every importer and cannot be
26
+ * a drive-by. The difference from check-naming is `--diff-filter=AM` rather
27
+ * than `A` — a filename can only be wrong the day it is created, while a
28
+ * manifest field can be wrong at any edit, and the commonest real breakage is a
29
+ * typo in a subpath added to a manifest that already existed.
30
+ *
31
+ * A target counts as resolved when it is a file on disk, and is skipped when
32
+ * git ignores it. That is how `"./dist/button.js"` passes in a compiled package
33
+ * before `turbo build` has ever run. The trade is that build output nobody
34
+ * added to .gitignore reads as a broken path, which is the safer mistake.
35
+ * Resolution is a stat rather than a lookup in the tracked file list, so a new
36
+ * package whose sources are written but not yet `git add`ed does not report
37
+ * every one of its own targets as dangling.
38
+ *
39
+ * Deliberately not checked: whether `"."` exists — a feature's `index.ts` is
40
+ * its documented public boundary, so a package exporting only `"."` is obeying
41
+ * a convention rather than breaking one, and whether a package should have one
42
+ * entry point or five is a review judgement rather than a pattern; whether a
43
+ * target is a barrel, for the same reason; the `@vwala/<category>-<name>`
44
+ * prefix, which belongs to the monorepo-structure convention and would break a
45
+ * consumer with a different org; and `"./test-support"` exports, which
46
+ * check-test-layout explicitly sanctions.
47
+ *
48
+ * Wire this into a repository's own check script and run it from the repository
49
+ * root. Set EXPORTS_BASE_REF when the default branch is not `origin/main`; when
50
+ * it cannot be resolved, nothing counts as changed and the script degrades to
51
+ * warnings only.
52
+ *
53
+ * See: .agents/skills/vwala-conventions/references/monorepo-structure.md
54
+ * .agents/skills/turborepo/references/best-practices/packages.md
55
+ */
56
+ import { execFileSync } from "node:child_process";
57
+ import { readFileSync, statSync } from "node:fs";
58
+ import path from "node:path";
59
+
60
+ const BASE_REF = process.env.EXPORTS_BASE_REF ?? "origin/main";
61
+
62
+ const MANIFEST = /(^|\/)package\.json$/;
63
+ const LIBRARY_MANIFEST = /^packages\//;
64
+ // A manifest under one of these is test data — a consumer testing a package
65
+ // generator commits fixture manifests — not a workspace package.
66
+ const FIXTURE_MANIFEST =
67
+ /\/(__tests__|__fixtures__|test-support|node_modules)\//;
68
+ const IGNORED_PREFIXES = [".agents/", ".claude/"];
69
+
70
+ // npm names are lowercase; the scope is what stops `ui` colliding with an
71
+ // unrelated package on the public registry.
72
+ const SCOPED_NAME = /^@[a-z0-9][a-z0-9-._]*\/[a-z0-9][a-z0-9-._]*$/;
73
+ // "." or "./anything" — an exports key. Rejects the condition names that belong
74
+ // one level down ("types", "default", "import") and any "../" escape.
75
+ const SUBPATH = /^\.(\/.+)?$/;
76
+ const LEGACY_FIELDS = ["main", "module", "types", "typings"];
77
+
78
+ const trackedFiles = git(["ls-files"]);
79
+ const untrackedFiles = git(["ls-files", "--others", "--exclude-standard"]);
80
+ const changedFiles = new Set([...untrackedFiles, ...changedSinceBaseRef()]);
81
+
82
+ const errors = [];
83
+ const warnings = [];
84
+
85
+ const manifests = [];
86
+ for (const file of [...trackedFiles, ...untrackedFiles]) {
87
+ if (
88
+ !MANIFEST.test(file) ||
89
+ FIXTURE_MANIFEST.test(file) ||
90
+ IGNORED_PREFIXES.some((prefix) => file.startsWith(prefix))
91
+ ) {
92
+ continue;
93
+ }
94
+ const isChanged = changedFiles.has(file);
95
+ let manifest;
96
+ try {
97
+ manifest = JSON.parse(readFileSync(file, "utf8"));
98
+ } catch {
99
+ // Reported rather than thrown, so one unparseable manifest does not hide
100
+ // every other violation in the repository.
101
+ report({
102
+ isChanged,
103
+ violation: `${file}\n Not valid JSON, so the exports map cannot be checked.`,
104
+ });
105
+ continue;
106
+ }
107
+ manifests.push({
108
+ file,
109
+ directory: path.posix.dirname(file),
110
+ isChanged,
111
+ manifest,
112
+ });
113
+ }
114
+
115
+ const ignoredTargets = resolveIgnored(manifests);
116
+
117
+ for (const { file, directory, isChanged, manifest } of manifests) {
118
+ const isLibrary = LIBRARY_MANIFEST.test(file);
119
+ const exportsField = manifest.exports;
120
+
121
+ if (isLibrary) {
122
+ if (exportsField === undefined) {
123
+ report({
124
+ isChanged,
125
+ violation: `${file}\n No "exports" field. A shared package names its entry points explicitly: "exports": { "./button": "./src/button.tsx" }.`,
126
+ });
127
+ }
128
+ if (typeof manifest.name !== "string") {
129
+ report({
130
+ isChanged,
131
+ violation: `${file}\n Package name is missing. Use a lowercase "@<org>/<name>" — a bare name collides with the public npm registry.`,
132
+ });
133
+ } else if (!SCOPED_NAME.test(manifest.name)) {
134
+ report({
135
+ isChanged,
136
+ violation: `${file}\n Package name "${manifest.name}" is not scoped. Use a lowercase "@<org>/<name>" — a bare name collides with the public npm registry.`,
137
+ });
138
+ }
139
+ }
140
+
141
+ if (exportsField === undefined) {
142
+ continue;
143
+ }
144
+
145
+ for (const field of LEGACY_FIELDS) {
146
+ if (manifest[field] === undefined) {
147
+ continue;
148
+ }
149
+ // `types` gets its own sentence, because the fix is to move it rather than
150
+ // to delete it.
151
+ report({
152
+ isChanged,
153
+ violation:
154
+ field === "types" || field === "typings"
155
+ ? `${file}\n "${field}" alongside "exports". Modern TypeScript resolution reads types out of "exports" and ignores the top-level field, so it only ever goes stale — put "types" inside each subpath's condition object instead.`
156
+ : `${file}\n "${field}" alongside "exports". Node and TypeScript resolve through "exports" and ignore "${field}", so it only ever goes stale — delete it.`,
157
+ });
158
+ }
159
+
160
+ if (!isSubpathMap(exportsField)) {
161
+ report({
162
+ isChanged,
163
+ violation: `${file}\n "exports" is a single target, not a subpath map. Name each entry point — "exports": { "./button": "./src/button.tsx" } — so an importer reaches one file rather than a barrel.`,
164
+ });
165
+ continue;
166
+ }
167
+
168
+ const conditionKeys = Object.keys(exportsField).filter(
169
+ (key) => !SUBPATH.test(key),
170
+ );
171
+ if (conditionKeys.length > 0) {
172
+ report({
173
+ isChanged,
174
+ violation: `${file}\n "exports" keys ${quoteList(conditionKeys)} are conditions, not subpaths. Conditions nest one level down, under a "." or "./<name>" key.`,
175
+ });
176
+ }
177
+
178
+ for (const subpath of Object.keys(exportsField)) {
179
+ if (subpath.includes("*")) {
180
+ report({
181
+ isChanged,
182
+ violation: `${file}\n Wildcard subpath "${subpath}". Enumerate the entry points — a pattern re-opens the whole package and leaves nothing to check against the files on disk.`,
183
+ });
184
+ }
185
+ }
186
+
187
+ for (const { subpath, value, resolved } of exportTargets({
188
+ directory,
189
+ manifest,
190
+ })) {
191
+ if (resolved === undefined) {
192
+ report({
193
+ isChanged,
194
+ violation: `${file}\n "${subpath}" points at "${value}". An "exports" target is a path inside the package and starts with "./".`,
195
+ });
196
+ continue;
197
+ }
198
+ if (isFile(resolved) || ignoredTargets.has(resolved)) {
199
+ continue;
200
+ }
201
+ report({
202
+ isChanged,
203
+ violation: `${file}\n "${subpath}" points at "${value}", which does not resolve to a file and is not git-ignored. Fix the path — or, if it is build output, let .gitignore cover it so the check knows to skip it.`,
204
+ });
205
+ }
206
+ }
207
+
208
+ if (warnings.length > 0) {
209
+ console.warn(
210
+ `\n ! ${warnings.length} exports violation(s) in unchanged manifests — fix when you next touch them:\n`,
211
+ );
212
+ for (const warning of warnings) {
213
+ console.warn(` ${warning}\n`);
214
+ }
215
+ }
216
+
217
+ if (errors.length > 0) {
218
+ console.error(
219
+ `\n ✖ ${errors.length} exports violation(s) in changed manifests:\n`,
220
+ );
221
+ for (const error of errors) {
222
+ console.error(` ${error}\n`);
223
+ }
224
+ process.exit(1);
225
+ }
226
+
227
+ console.log(" ✔ no exports violations in changed manifests");
228
+
229
+ function report({ isChanged, violation }) {
230
+ if (isChanged) {
231
+ errors.push(violation);
232
+ } else {
233
+ warnings.push(violation);
234
+ }
235
+ }
236
+
237
+ function isSubpathMap(exportsField) {
238
+ return (
239
+ typeof exportsField === "object" &&
240
+ exportsField !== null &&
241
+ !Array.isArray(exportsField)
242
+ );
243
+ }
244
+
245
+ /**
246
+ * Every target a manifest's `exports` map points at, paired with the repository
247
+ * path it resolves to. A wildcard subpath is skipped: its target cannot be
248
+ * resolved, and the wildcard itself is already reported.
249
+ */
250
+ function exportTargets({ directory, manifest }) {
251
+ const exportsField = manifest.exports;
252
+ if (!isSubpathMap(exportsField)) {
253
+ return [];
254
+ }
255
+ const targets = [];
256
+ for (const [subpath, target] of Object.entries(exportsField)) {
257
+ if (!SUBPATH.test(subpath) || subpath.includes("*")) {
258
+ continue;
259
+ }
260
+ for (const value of flattenTargets(target)) {
261
+ targets.push({
262
+ subpath,
263
+ value,
264
+ resolved: value.startsWith("./")
265
+ ? path.posix.join(directory, value)
266
+ : undefined,
267
+ });
268
+ }
269
+ }
270
+ return targets;
271
+ }
272
+
273
+ /**
274
+ * The three legal target shapes — a string, a fallback array, and a condition
275
+ * object — flattened to the paths they can resolve to. `null` yields nothing,
276
+ * because it deliberately blocks a subpath rather than naming a file.
277
+ */
278
+ function flattenTargets(target) {
279
+ if (typeof target === "string") {
280
+ return [target];
281
+ }
282
+ if (Array.isArray(target)) {
283
+ return target.flatMap(flattenTargets);
284
+ }
285
+ if (target !== null && typeof target === "object") {
286
+ return Object.values(target).flatMap(flattenTargets);
287
+ }
288
+ return [];
289
+ }
290
+
291
+ /**
292
+ * Which unresolved targets git ignores, in one call rather than one process per
293
+ * target. `git check-ignore` exits 1 when nothing matches, which is the clean
294
+ * case here, so the status is read off the thrown error the way check-test-layout
295
+ * reads `git grep`'s.
296
+ */
297
+ function resolveIgnored(manifestList) {
298
+ const candidates = [
299
+ ...new Set(
300
+ manifestList
301
+ .flatMap(exportTargets)
302
+ .filter(({ resolved }) => resolved !== undefined && !isFile(resolved))
303
+ .map(({ resolved }) => resolved),
304
+ ),
305
+ ];
306
+ if (candidates.length === 0) {
307
+ return new Set();
308
+ }
309
+ try {
310
+ return toSet(
311
+ execFileSync("git", ["check-ignore", "--stdin"], {
312
+ encoding: "utf8",
313
+ input: `${candidates.join("\n")}\n`,
314
+ maxBuffer: 1024 * 1024 * 64,
315
+ }),
316
+ );
317
+ } catch (error) {
318
+ if (error.status !== 1) {
319
+ throw error;
320
+ }
321
+ return toSet(error.stdout ?? "");
322
+ }
323
+ }
324
+
325
+ function toSet(output) {
326
+ return new Set(output.split("\n").filter(Boolean));
327
+ }
328
+
329
+ function isFile(file) {
330
+ try {
331
+ return statSync(file).isFile();
332
+ } catch {
333
+ return false;
334
+ }
335
+ }
336
+
337
+ function quoteList(values) {
338
+ return values.map((value) => `"${value}"`).join(", ");
339
+ }
340
+
341
+ /**
342
+ * Diffs the merge base against the working tree rather than against HEAD, so
343
+ * manifests edited but not yet committed are held to the same standard as the
344
+ * ones already on the branch.
345
+ */
346
+ function changedSinceBaseRef() {
347
+ let mergeBase;
348
+ try {
349
+ mergeBase = execFileSync("git", ["merge-base", BASE_REF, "HEAD"], {
350
+ encoding: "utf8",
351
+ stdio: ["ignore", "pipe", "ignore"],
352
+ }).trim();
353
+ } catch {
354
+ console.warn(
355
+ ` ! Cannot resolve ${BASE_REF} — reporting every violation as a warning.`,
356
+ );
357
+ return [];
358
+ }
359
+ return git(["diff", "--diff-filter=AM", "--name-only", mergeBase]);
360
+ }
361
+
362
+ function git(args) {
363
+ return execFileSync("git", args, {
364
+ encoding: "utf8",
365
+ maxBuffer: 1024 * 1024 * 64,
366
+ })
367
+ .split("\n")
368
+ .filter(Boolean);
369
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "// rule": "Every external dependency must be declared in the pnpm-workspace.yaml catalog and referenced as `catalog:`. Two declarations of the same package re-resolve independently, which is how a second copy lands in the tree even when the ranges look identical today.",
3
+ "// source": "No `source` key on purpose. Syncpack discovers packages from pnpm-workspace.yaml `packages:` and then appends the root package.json. Setting `source` (default sourceMode `replace`) replaces discovery and silently drops the root manifest, whose dependencies install a real copy too. Override with `sourceMode: extend` if you must.",
4
+ "// peers": "peerDependencies are out of scope. A peer range is a deliberately wide compatibility statement; collapsing it to `catalog:` would pin a published package to one version of its own peer. The devDependency that actually installs the copy is in scope.",
5
+ "// customTypes": "optionalDependencies is not one of syncpack's built-in dependency types (dev, local, overrides, peer, pnpmOverrides, prod, resolutions). Without the custom type below, the string \"optional\" passes schema validation and silently matches nothing. Never add a `//` comment key inside `customTypes` itself — it is parsed as a custom type, fails to deserialise, and syncpack falls back to its default version group without reporting an error.",
6
+ "customTypes": {
7
+ "optional": {
8
+ "strategy": "versionsByName",
9
+ "path": "optionalDependencies"
10
+ }
11
+ },
12
+ "versionGroups": [
13
+ {
14
+ "// order": "Must stay first. Version groups are first-match-wins, and `policy: catalog` does not exempt these itself — syncpack only refuses to catalog a package's own `version` field. Without this group, `syncpack fix` rewrites workspace:, link: and file: specifiers to `catalog:`, which breaks them: all three resolve relative to the declaring package.",
15
+ "// types": "`link` is a real specifier type at runtime but is missing from the JSON schema's enum, so editors will not suggest it. Verified against syncpack 15.3.2.",
16
+ "label": "Locally-resolved specifiers cannot be centralised in a catalog",
17
+ "dependencyTypes": ["prod", "dev", "optional"],
18
+ "specifierTypes": ["workspace-protocol", "file", "link"],
19
+ "isIgnored": true
20
+ },
21
+ {
22
+ "// scope": "Registry ranges, tags, npm: aliases, git refs and tarball URLs all stay in scope — each is a globally resolvable identifier a catalog can legitimately centralise.",
23
+ "label": "Every external dependency comes from the pnpm catalog",
24
+ "dependencyTypes": ["prod", "dev", "optional"],
25
+ "policy": "catalog"
26
+ },
27
+ {
28
+ "// order": "Must stay last, and must exist. Anything no explicit group claims falls into syncpack's built-in \"Default Version Group\", which enforces highest-semver agreement across packages — a second, unrelated rule this config does not intend to impose. Without this group, peerDependencies, overrides and resolutions are all quietly linted for version agreement.",
29
+ "label": "Everything else is outside the scope of this config",
30
+ "isIgnored": true
31
+ }
32
+ ]
33
+ }