@trackunit/repo-checks 0.0.19-alpha-07efa4379b2.0 → 0.0.22

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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 0.0.22 (2026-10-26)
2
+
3
+ This was a version bump only for repo-checks to align it with other projects, there were no code changes.
4
+
5
+ ## 0.0.21 (2026-10-26)
6
+
7
+ This was a version bump only for repo-checks to align it with other projects, there were no code changes.
8
+
9
+ ## 0.0.20 (2026-10-26)
10
+
11
+ This was a version bump only for repo-checks to align it with other projects, there were no code changes.
12
+
13
+ ## 0.0.19 (2026-10-25)
14
+
15
+ This was a version bump only for repo-checks to align it with other projects, there were no code changes.
16
+
1
17
  ## 0.0.18 (2026-10-23)
2
18
 
3
19
  This was a version bump only for repo-checks to align it with other projects, there were no code changes.
package/README.md CHANGED
@@ -9,6 +9,7 @@ This package is for Trackunit internal usage.
9
9
  - [What is never checked](#what-is-never-checked)
10
10
  - [Anchors](#anchors)
11
11
  - [Exists on disk](#exists-on-disk)
12
+ - [Storybook links](#storybook-links)
12
13
  - [Running it](#running-it)
13
14
  - [CLI](#cli)
14
15
  - [Exit codes](#exit-codes)
@@ -23,6 +24,7 @@ This package is for Trackunit internal usage.
23
24
  - [`constructs`](#constructs)
24
25
  - [`directories`](#directories)
25
26
  - [`bareFilenames`](#barefilenames)
27
+ - [`storybookLinks`](#storybooklinks)
26
28
  - [Ignore comments](#ignore-comments)
27
29
  - [Running unit tests](#running-unit-tests)
28
30
 
@@ -71,7 +73,7 @@ These are categorically not repository paths, so they are skipped whatever the c
71
73
  - globs: anything containing `*` (`libs/**/README.md`);
72
74
  - shell variables: anything containing `$` (`$HOME/bin`, `${DIR}/x.md`);
73
75
  - multi-word spans: anything containing whitespace, such as an inline-code command;
74
- - Storybook links with a `?path=` query;
76
+ - Storybook links with a `?path=` query (see [Storybook links](#storybook-links));
75
77
  - code blocks, fenced or indented, and frontmatter, which are never read for references; in `.mdx`, ESM (`import`/`export`), `{expressions}`, and JSX attributes aren't read either, though markdown in JSX children is;
76
78
  - references whose shape isn't a path under the current options (see [`directories`](#directories) and [`bareFilenames`](#barefilenames)).
77
79
 
@@ -98,6 +100,61 @@ Targets are checked against the working tree, not the git index. A gitignored or
98
100
 
99
101
  Documents are found with `git ls-files`: tracked and untracked files, minus gitignored ones, that exist on disk. Outside a git work tree the checker walks the file system instead, skipping `.git`, `node_modules`, `dist`, `build`, and `coverage`.
100
102
 
103
+ ### Storybook links
104
+
105
+ `storybook-links` finds `.md` and `.mdx` documents as `doc-references` does and reports Storybook links whose ID is in none of the Storybook indexes you pass with `--index`, or is there only as the other entry type. A Storybook link is a link, an image, or a link reference definition whose target is a `?path=/docs/<id>` or `?path=/story/<id>` query, possibly beside other query parameters, either:
106
+
107
+ - relative: the query alone or after `/`, `./`, or `../` (`../?path=/story/<id>`);
108
+ - absolute on a checked host, by default only `design.iris.trackunit.com` (see [`hosts`](#storybooklinks)): `https://design.iris.trackunit.com/?path=/docs/<id>`, also with a base path such as a feature-branch deployment (`https://design.iris.trackunit.com/<branch>/?path=/docs/<id>`) and with `http://`. The host matches case-insensitively, and only on the scheme's default port.
109
+
110
+ For a document `docs/index.md` and an index with a `components-button--docs` docs entry and a `components-button--default` story, but no `components-button--primary`:
111
+
112
+ ```markdown
113
+ # Index
114
+
115
+ [button](?path=/story/components-button--primary)
116
+ [button docs](?path=/docs/components-button--docs)
117
+ [default button](?path=/docs/components-button--default)
118
+ [deployed](https://design.iris.trackunit.com/?path=/story/components-button--primary)
119
+ ```
120
+
121
+ ```text
122
+ docs/index.md:3:1 ?path=/story/components-button--primary unknownStoryId
123
+ docs/index.md:5:1 ?path=/docs/components-button--default wrongStoryType did you mean ?path=/story/components-button--default
124
+ docs/index.md:6:1 https://design.iris.trackunit.com/?path=/story/components-button--primary unknownStoryId
125
+ ```
126
+
127
+ | Reason | Meaning |
128
+ | ---------------- | ------------------------------------------------------------------------------ |
129
+ | `unknownStoryId` | The `<id>` in `?path=/<type>/<id>` is an entry in none of the `--index` files. |
130
+ | `wrongStoryType` | The `<id>` is an entry only of the other type: a `/docs/` link to a story, or a `/story/` link to a docs page. `did you mean` gives the link with `/docs/` and `/story/` swapped, keeping any host, base path, and other query parameters; it's omitted when the `path=/docs/` or `path=/story/` prefix is percent-encoded. |
131
+
132
+ An ID found in any of the indexes passes, since no single Storybook covers every ID; it passes as either type it has in any of them.
133
+
134
+ Not checked:
135
+
136
+ - links with a `#fragment`, relative or absolute;
137
+ - absolute URLs on a host that isn't checked (a third-party Storybook can't be checked against our indexes), with a non-default port or credentials, or with a scheme other than `http:` and `https:`, and protocol-relative URLs (`//design.iris.trackunit.com/?path=...`);
138
+ - absolute URLs whose path names a file other than `index.html`, such as `iframe.html?id=<id>`;
139
+ - code blocks, inline code, frontmatter, and in `.mdx` ESM, `{expressions}`, and JSX attributes, as for `doc-references`;
140
+ - `.ts` and `.tsx` files, such as the `parameters.docs` of a story;
141
+ - HTML `<a href>` and other raw HTML;
142
+ - query paths in other shapes, such as `docs/?path=` or a `/Docs/` type.
143
+
144
+ The [`storybookLinks`](#storybooklinks) config section sets the checked hosts, documents to skip, and IDs never reported. To skip the links on one line, put a [`storybook-links-ignore-next-line` comment](#ignore-comments) above it; `doc-references-ignore-next-line` doesn't affect `storybook-links`.
145
+
146
+ AI agents should use the machine-readable index at [`/llms.txt`](https://design.iris.trackunit.com/llms.txt) instead of the Storybook HTML; it links to per-component docs at `/ai?storyId=<id>`.
147
+
148
+ #### Producing an index
149
+
150
+ `storybook index` writes the index without building Storybook:
151
+
152
+ ```sh
153
+ npx storybook index -c <configDir> -o <file>
154
+ ```
155
+
156
+ `<configDir>` is the Storybook's config directory (the one with `main.ts`). Pass one `--index` per Storybook your documents link to.
157
+
101
158
  ## Running it
102
159
 
103
160
  ### CLI
@@ -112,6 +169,16 @@ npx @trackunit/repo-checks doc-references [--root <dir>] [--format text|json]
112
169
  | `--format <fmt>` | `text` | `text`: one `file:line:col target reason[ did you mean <path>]` line per finding, nothing when clean. `json`: an array of findings with `file`, `line`, `column`, `target`, `kind` (`link`, `image`, `definition`, `inlineCode`), `reason`, and `suggestion` when known; `[]` when clean. |
113
170
  | `--help`, `-h` | | Print usage. |
114
171
 
172
+ ```sh
173
+ npx @trackunit/repo-checks storybook-links --index <file> [--index <file>...] [--root <dir>] [--format text|json]
174
+ ```
175
+
176
+ `storybook-links` takes `--root` and `--format` as above, plus:
177
+
178
+ | Flag | Default | Meaning |
179
+ | ---------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
180
+ | `--index <file>` | | Required, repeatable: a [`storybook index`](#producing-an-index) output file. The IDs of every given index are combined. A relative path resolves against the current directory, not `--root`. |
181
+
115
182
  Findings are sorted by file, line, and column, so the output is the same on every host.
116
183
 
117
184
  ### Exit codes
@@ -120,7 +187,7 @@ Findings are sorted by file, line, and column, so the output is the same on ever
120
187
  | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
121
188
  | `0` | No findings. |
122
189
  | `1` | One or more findings. |
123
- | `2` | The check couldn't run: a usage error, an invalid config, a document that can't be parsed (an `.mdx` that isn't valid MDX), or an unreadable path. |
190
+ | `2` | The check couldn't run: a usage error, an invalid config, a document that can't be parsed (an `.mdx` that isn't valid MDX), or an unreadable path. For `storybook-links`, also no `--index`, or an index that is missing, unreadable, not valid JSON, or not shaped like a `storybook index` output. |
124
191
 
125
192
  ### In manager
126
193
 
@@ -140,9 +207,29 @@ const findings = checkDocReferences({ rootDir, config: config.docReferences });
140
207
  console.log(findings.map(formatFinding).join("\n"));
141
208
  ```
142
209
 
210
+ ```ts
211
+ import { checkStorybookLinks, formatFinding, loadConfig, StorybookIndexError } from "@trackunit/repo-checks";
212
+
213
+ const { config } = loadConfig(rootDir);
214
+ try {
215
+ const findings = checkStorybookLinks({
216
+ rootDir,
217
+ indexFiles: ["storybook-index.json"],
218
+ config: config.storybookLinks,
219
+ });
220
+ console.log(findings.map(formatFinding).join("\n"));
221
+ } catch (error) {
222
+ if (!(error instanceof StorybookIndexError)) throw error;
223
+ console.error(error.message);
224
+ process.exitCode = 2;
225
+ }
226
+ ```
227
+
228
+ The optional `config` is the [`storybookLinks`](#storybooklinks) section as written in the file; omitted, every default applies. `checkStorybookLinks` validates it first, throwing `ConfigError` when it is invalid, then loads every index before reading any document, so a bad index throws instead of giving a clean result: `StorybookIndexError` for an index that isn't valid JSON or an index, or for an empty `indexFiles`, and `ReadError` for one that can't be read. Relative `indexFiles` resolve against `process.cwd()`.
229
+
143
230
  ## Configuration
144
231
 
145
- Options live under `docReferences` in `repo-checks.config.json` at the repository root (the nearest `.git` at or above `--root`). The file is optional: no file, or `{}`, means every default. An unknown key, a wrong type, or a bad value fails the run with exit code `2` and a message naming the key:
232
+ Options live in `repo-checks.config.json` at the repository root (the nearest `.git` at or above `--root`): under `docReferences` for `doc-references`, described in the table below, and under [`storybookLinks`](#storybooklinks) for `storybook-links`. The file is optional: no file, or `{}`, means every default. The file is validated as a whole, so an invalid section fails either command. An unknown key, a wrong type, or a bad value fails the run with exit code `2` and a message naming the key:
146
233
 
147
234
  ```text
148
235
  Error: Invalid config /repo/repo-checks.config.json: docReferences.ignore: expected { extend: [...] } to add to the defaults or { replace: [...] } to swap them out (a bare array is ambiguous)
@@ -277,6 +364,46 @@ Also check inline code without a `/`, such as `` `README.md` ``. Most such spans
277
364
  { "docReferences": { "bareFilenames": true } }
278
365
  ```
279
366
 
367
+ ### `storybookLinks`
368
+
369
+ Options for [`storybook-links`](#storybook-links), in the same file and validated the same way. None of the `docReferences` options apply to it.
370
+
371
+ | Option | Type | Default |
372
+ | --------- | ------------------------------------------------------------ | ------------------------------- |
373
+ | `exclude` | array of globs | `[]` |
374
+ | `ignore` | array of Storybook ID globs | `[]` |
375
+ | `hosts` | `{ "extend": [...] }` or `{ "replace": [...] }` of hostnames | `["design.iris.trackunit.com"]` |
376
+
377
+ `exclude` is a plain array of [picomatch](https://github.com/micromatch/picomatch) globs of **documents** that are never read, matched against the path relative to the repository root, with the same rules as the `docReferences` [`exclude`](#exclude):
378
+
379
+ ```json
380
+ { "storybookLinks": { "exclude": ["legacy/**"] } }
381
+ ```
382
+
383
+ `ignore` is a plain array of picomatch globs matched against the Storybook ID alone, not the `/docs/` or `/story/` type or the rest of the link. A link whose ID matches is never reported, relative or absolute, whatever the indexes hold. A negated glob (`!foo--wip`) is rejected, since it would ignore every other ID. This skips both `?path=/docs/foo--wip` and `?path=/story/bar--wip`:
384
+
385
+ ```json
386
+ { "storybookLinks": { "ignore": ["*--wip"] } }
387
+ ```
388
+
389
+ IDs contain no `/`, so a glob with one, or an empty glob, is rejected.
390
+
391
+ `hosts` are the hosts whose absolute links are checked; relative links always are. Each entry is a bare hostname, without a scheme, port, path, or credentials, written as a URL writes it (an internationalised domain in its `xn--` form), and is matched case-insensitively. It has a default, so it takes `{ "extend": [...] }` or `{ "replace": [...] }`, as in [List options](#list-options-extend-replace-empty), and a bare array is rejected:
392
+
393
+ ```text
394
+ Error: Invalid config /repo/repo-checks.config.json: storybookLinks.hosts: expected { extend: [...] } to add to the defaults or { replace: [...] } to swap them out (a bare array is ambiguous)
395
+ ```
396
+
397
+ ```json
398
+ { "storybookLinks": { "hosts": { "extend": ["storybook.example.com"] } } }
399
+ ```
400
+
401
+ ```json
402
+ { "storybookLinks": { "hosts": { "replace": [] } } }
403
+ ```
404
+
405
+ The first also checks links to `storybook.example.com`; the second checks relative links only.
406
+
280
407
  ## Ignore comments
281
408
 
282
409
  When a reference is intentionally broken, first prefer a fenced code block, which is never checked. Otherwise put an ignore comment on the line directly above the reference; it suppresses every reference on the next line. The `: reason` is optional, but say why, so the next reader knows whether it can go.
@@ -304,7 +431,19 @@ See [the old guide][old].
304
431
  [old]: ./old-guide.md
305
432
  ```
306
433
 
307
- To skip a whole document, use [`exclude`](#exclude); to skip a whole target location, use [`ignore`](#ignore).
434
+ `storybook-links` has its own marker, `storybook-links-ignore-next-line`, written the same way and with the same rules. Each check honours only its own marker, so a `doc-references-ignore-next-line` comment doesn't suppress Storybook links, and a `storybook-links-ignore-next-line` comment doesn't suppress `doc-references` findings.
435
+
436
+ ```markdown
437
+ <!-- storybook-links-ignore-next-line: renamed upstream -->
438
+ See [the button docs](?path=/docs/components-button--docs).
439
+ ```
440
+
441
+ ```mdx
442
+ {/* storybook-links-ignore-next-line: renamed upstream */}
443
+ See [the button docs](?path=/docs/components-button--docs).
444
+ ```
445
+
446
+ To skip a whole document, use [`exclude`](#exclude), or the `storybookLinks` [`exclude`](#storybooklinks); to skip a whole target location, use [`ignore`](#ignore), or the `storybookLinks` [`ignore`](#storybooklinks) for Storybook IDs.
308
447
 
309
448
  ## Running unit tests
310
449
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/repo-checks",
3
- "version": "0.0.19-alpha-07efa4379b2.0",
3
+ "version": "0.0.22",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "engines": {
6
6
  "node": ">=24.x"
package/src/cli.d.ts CHANGED
@@ -7,7 +7,7 @@ export type CliStreams = {
7
7
  readonly stderr: WritableStream;
8
8
  };
9
9
  export type CliOptions = {
10
- /** The directory a relative `--root`, and the default root, resolve from. Defaults to `process.cwd()`. */
10
+ /** The directory a relative `--root` or `--index`, and the default root, resolve from. Defaults to `process.cwd()`. */
11
11
  readonly cwd?: string;
12
12
  };
13
13
  export type CliCommand = {
@@ -19,6 +19,11 @@ export type CliCommand = {
19
19
  readonly kind: "doc-references";
20
20
  readonly root: string | undefined;
21
21
  readonly format: OutputFormat;
22
+ } | {
23
+ readonly kind: "storybook-links";
24
+ readonly root: string | undefined;
25
+ readonly format: OutputFormat;
26
+ readonly indexFiles: ReadonlyArray<string>;
22
27
  };
23
28
  /** Parse the command line into the command to run, without touching the file system. */
24
29
  export declare const parseCliArgs: (argv: ReadonlyArray<string>) => CliCommand;
package/src/cli.js CHANGED
@@ -10,11 +10,16 @@ const check_doc_references_1 = require("./lib/doc-references/check-doc-reference
10
10
  const fs_errors_1 = require("./lib/doc-references/fs-errors");
11
11
  const repo_root_1 = require("./lib/doc-references/repo-root");
12
12
  const format_1 = require("./lib/format");
13
+ const check_storybook_links_1 = require("./lib/storybook-links/check-storybook-links");
13
14
  /** Exit codes: findings (1) are kept apart from a tool, usage, config, or parse failure (2), so CI can tell them apart. */
14
15
  const EXIT_CLEAN = 0;
15
16
  const EXIT_FINDINGS = 1;
16
17
  const EXIT_ERROR = 2;
18
+ const SUBCOMMANDS = ["doc-references", "storybook-links"];
19
+ /** Options that may be given more than once. */
20
+ const REPEATABLE_OPTIONS = ["index"];
17
21
  const USAGE = `Usage: repo-checks doc-references [--root <dir>] [--format text|json]
22
+ repo-checks storybook-links --index <file> [--index <file>...] [--root <dir>] [--format text|json]
18
23
 
19
24
  Repository-wide checks for Trackunit repositories.
20
25
 
@@ -22,10 +27,22 @@ Commands:
22
27
  doc-references
23
28
  Report file references in .md and .mdx documents whose target or #anchor doesn't exist.
24
29
  Exits 0 when clean, 1 with findings, 2 on a usage, config, document parse, or other tool error.
30
+ storybook-links
31
+ Report Storybook links (?path=/docs/<id>, /?path=/story/<id>, and absolute links on
32
+ design.iris.trackunit.com or the configured hosts) in .md and .mdx documents whose ID is in
33
+ none of the --index files, or is an entry only of the other type. Links with a #fragment aren't
34
+ checked.
35
+ Exits 0 when clean, 1 with findings, 2 on a usage, config, index, document parse, or other tool
36
+ error.
37
+
38
+ Both commands read their settings from repo-checks.config.json at the repository root, if present.
25
39
 
26
40
  Options:
27
41
  --root <dir> Directory to check. Defaults to the repository root of the current directory
28
42
  (or the current directory outside a repository).
43
+ --index <file> storybook-links only, required, repeatable: a \`storybook index\` output file.
44
+ The IDs of every given index are combined. Relative paths resolve against the
45
+ current directory, not --root.
29
46
  --format <format> text (default): one "file:line:col target reason[ did you mean <path>]"
30
47
  line per finding. json: an array of findings.
31
48
  --help, -h Show this help message.
@@ -39,6 +56,7 @@ const parseCliOptions = (argv) => (0, util_1.parseArgs)({
39
56
  options: {
40
57
  root: { type: "string" },
41
58
  format: { type: "string" },
59
+ index: { type: "string", multiple: true },
42
60
  help: { type: "boolean", short: "h" },
43
61
  },
44
62
  });
@@ -54,26 +72,49 @@ const parseCliArgs = (argv) => {
54
72
  const { values, positionals, tokens } = parsed;
55
73
  if (values.help)
56
74
  return { kind: "help" };
57
- const optionNames = tokens.flatMap(token => (token.kind === "option" ? [token.name] : []));
75
+ const optionNames = tokens.flatMap(token => token.kind === "option" && !REPEATABLE_OPTIONS.includes(token.name) ? [token.name] : []);
58
76
  const repeated = optionNames.find((name, index) => optionNames.indexOf(name) !== index);
59
77
  if (repeated !== undefined)
60
78
  return { kind: "usageError", message: `--${repeated} given more than once` };
61
79
  if (values.root === "")
62
80
  return { kind: "usageError", message: "--root requires a directory" };
63
- const [subcommand, ...extra] = positionals;
64
- if (subcommand === undefined)
81
+ if (values.index?.includes(""))
82
+ return { kind: "usageError", message: "--index requires a file" };
83
+ const [subcommandArg, ...extra] = positionals;
84
+ if (subcommandArg === undefined)
65
85
  return { kind: "usageError", message: "Missing command" };
66
- if (subcommand !== "doc-references")
67
- return { kind: "usageError", message: `Unknown command "${subcommand}"` };
86
+ const subcommand = SUBCOMMANDS.find(name => name === subcommandArg);
87
+ if (subcommand === undefined)
88
+ return { kind: "usageError", message: `Unknown command "${subcommandArg}"` };
68
89
  if (extra.length > 0)
69
90
  return { kind: "usageError", message: `Unexpected argument "${extra.join(" ")}"` };
70
91
  const format = values.format ?? "text";
71
92
  if (!isOutputFormat(format)) {
72
93
  return { kind: "usageError", message: `Unknown --format "${format}". Expected ${format_1.OUTPUT_FORMATS.join(" or ")}` };
73
94
  }
74
- return { kind: "doc-references", root: values.root, format };
95
+ if (subcommand === "doc-references") {
96
+ if (values.index !== undefined) {
97
+ return { kind: "usageError", message: "--index is only valid for storybook-links" };
98
+ }
99
+ return { kind: "doc-references", root: values.root, format };
100
+ }
101
+ if (values.index === undefined) {
102
+ return { kind: "usageError", message: "storybook-links requires at least one --index <file>" };
103
+ }
104
+ return { kind: "storybook-links", root: values.root, format, indexFiles: values.index };
75
105
  };
76
106
  exports.parseCliArgs = parseCliArgs;
107
+ const runCheck = (command, rootDir, workingDir) => {
108
+ const { config } = (0, config_1.loadConfig)(rootDir);
109
+ if (command.kind === "storybook-links") {
110
+ return (0, check_storybook_links_1.checkStorybookLinks)({
111
+ rootDir,
112
+ indexFiles: command.indexFiles.map(indexFile => path.resolve(workingDir, indexFile)),
113
+ config: config.storybookLinks,
114
+ });
115
+ }
116
+ return (0, check_doc_references_1.checkDocReferences)({ rootDir, config: config.docReferences });
117
+ };
77
118
  /** Run the CLI and return its exit code; output goes to `streams`, never to `process` directly. */
78
119
  const runCli = (argv, streams, { cwd } = {}) => {
79
120
  const command = (0, exports.parseCliArgs)(argv);
@@ -95,8 +136,7 @@ const runCli = (argv, streams, { cwd } = {}) => {
95
136
  streams.stderr.write(`Error: --root ${rootDir} ${rootStat ? "is not a directory" : "does not exist"}\n`);
96
137
  return EXIT_ERROR;
97
138
  }
98
- const { config } = (0, config_1.loadConfig)(rootDir);
99
- const findings = (0, check_doc_references_1.checkDocReferences)({ rootDir, config: config.docReferences });
139
+ const findings = runCheck(command, rootDir, workingDir);
100
140
  streams.stdout.write((0, format_1.formatFindings)(findings, command.format));
101
141
  return findings.length === 0 ? EXIT_CLEAN : EXIT_FINDINGS;
102
142
  }
package/src/index.d.ts CHANGED
@@ -6,3 +6,7 @@ export { ReadError } from "./lib/doc-references/fs-errors";
6
6
  export { DocumentParseError } from "./lib/doc-references/parse";
7
7
  export { DEFAULT_DOCS_SETTINGS, parseDocsSettings, type DocReferencesConfig, type DocsSettings, } from "./lib/doc-references/settings";
8
8
  export { OUTPUT_FORMATS, formatFinding, formatFindings, type OutputFormat } from "./lib/format";
9
+ export { checkStorybookLinks, type CheckStorybookLinksOptions } from "./lib/storybook-links/check-storybook-links";
10
+ export { DEFAULT_STORYBOOK_LINKS_SETTINGS, parseStorybookLinksSettings, type StorybookLinksConfig, type StorybookLinksSettings, } from "./lib/storybook-links/settings";
11
+ export { StorybookIndexError } from "./lib/storybook-links/storybook-index";
12
+ export { DEFAULT_STORYBOOK_HOSTS } from "./lib/storybook-links/storybook-path";
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatFindings = exports.formatFinding = exports.OUTPUT_FORMATS = exports.parseDocsSettings = exports.DEFAULT_DOCS_SETTINGS = exports.DocumentParseError = exports.ReadError = exports.checkDocReferences = exports.loadConfig = exports.ConfigError = exports.CONFIG_FILE_NAME = void 0;
3
+ exports.DEFAULT_STORYBOOK_HOSTS = exports.StorybookIndexError = exports.parseStorybookLinksSettings = exports.DEFAULT_STORYBOOK_LINKS_SETTINGS = exports.checkStorybookLinks = exports.formatFindings = exports.formatFinding = exports.OUTPUT_FORMATS = exports.parseDocsSettings = exports.DEFAULT_DOCS_SETTINGS = exports.DocumentParseError = exports.ReadError = exports.checkDocReferences = exports.loadConfig = exports.ConfigError = exports.CONFIG_FILE_NAME = void 0;
4
4
  var config_1 = require("./lib/config");
5
5
  Object.defineProperty(exports, "CONFIG_FILE_NAME", { enumerable: true, get: function () { return config_1.CONFIG_FILE_NAME; } });
6
6
  Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return config_1.ConfigError; } });
@@ -18,4 +18,13 @@ var format_1 = require("./lib/format");
18
18
  Object.defineProperty(exports, "OUTPUT_FORMATS", { enumerable: true, get: function () { return format_1.OUTPUT_FORMATS; } });
19
19
  Object.defineProperty(exports, "formatFinding", { enumerable: true, get: function () { return format_1.formatFinding; } });
20
20
  Object.defineProperty(exports, "formatFindings", { enumerable: true, get: function () { return format_1.formatFindings; } });
21
+ var check_storybook_links_1 = require("./lib/storybook-links/check-storybook-links");
22
+ Object.defineProperty(exports, "checkStorybookLinks", { enumerable: true, get: function () { return check_storybook_links_1.checkStorybookLinks; } });
23
+ var settings_2 = require("./lib/storybook-links/settings");
24
+ Object.defineProperty(exports, "DEFAULT_STORYBOOK_LINKS_SETTINGS", { enumerable: true, get: function () { return settings_2.DEFAULT_STORYBOOK_LINKS_SETTINGS; } });
25
+ Object.defineProperty(exports, "parseStorybookLinksSettings", { enumerable: true, get: function () { return settings_2.parseStorybookLinksSettings; } });
26
+ var storybook_index_1 = require("./lib/storybook-links/storybook-index");
27
+ Object.defineProperty(exports, "StorybookIndexError", { enumerable: true, get: function () { return storybook_index_1.StorybookIndexError; } });
28
+ var storybook_path_1 = require("./lib/storybook-links/storybook-path");
29
+ Object.defineProperty(exports, "DEFAULT_STORYBOOK_HOSTS", { enumerable: true, get: function () { return storybook_path_1.DEFAULT_STORYBOOK_HOSTS; } });
21
30
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,12 @@
1
1
  import { type DocReferencesConfig } from "./doc-references/settings";
2
+ import { type StorybookLinksConfig } from "./storybook-links/settings";
2
3
  export { ConfigError } from "./config-error";
3
4
  /** The config file, read from the repository root. */
4
5
  export declare const CONFIG_FILE_NAME = "repo-checks.config.json";
5
6
  /** A validated `repo-checks.config.json`; each section is passed as-is to its check, which resolves it onto the defaults. */
6
7
  export interface RepoChecksConfig {
7
8
  readonly docReferences?: DocReferencesConfig;
9
+ readonly storybookLinks?: StorybookLinksConfig;
8
10
  }
9
11
  export interface LoadedConfig {
10
12
  /** The absolute path of the file read, or `undefined` when there is none. */
package/src/lib/config.js CHANGED
@@ -8,11 +8,12 @@ const config_error_1 = require("./config-error");
8
8
  const fs_errors_1 = require("./doc-references/fs-errors");
9
9
  const repo_root_1 = require("./doc-references/repo-root");
10
10
  const settings_1 = require("./doc-references/settings");
11
+ const settings_2 = require("./storybook-links/settings");
11
12
  var config_error_2 = require("./config-error");
12
13
  Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return config_error_2.ConfigError; } });
13
14
  /** The config file, read from the repository root. */
14
15
  exports.CONFIG_FILE_NAME = "repo-checks.config.json";
15
- const repoChecksConfigSchema = (0, settings_1.strictObjectNamingKeys)({ docReferences: settings_1.docReferencesConfigSchema.optional() }, { noun: "key", expected: "a JSON object" });
16
+ const repoChecksConfigSchema = (0, settings_1.strictObjectNamingKeys)({ docReferences: settings_1.docReferencesConfigSchema.optional(), storybookLinks: settings_2.storybookLinksConfigSchema.optional() }, { noun: "key", expected: "a JSON object" });
16
17
  const readConfigFile = (file) => {
17
18
  try {
18
19
  return fs.readFileSync(file, "utf8");
@@ -2,29 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkDocReferences = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("fs"));
6
5
  const path = tslib_1.__importStar(require("path"));
7
6
  const case_fix_1 = require("./case-fix");
8
7
  const classify_1 = require("./classify");
9
- const discover_1 = require("./discover");
8
+ const documents_1 = require("./documents");
10
9
  const extract_1 = require("./extract");
11
10
  const finding_1 = require("./finding");
12
- const fs_errors_1 = require("./fs-errors");
13
11
  const headings_1 = require("./headings");
14
12
  const parse_1 = require("./parse");
15
13
  const placeholders_1 = require("./placeholders");
16
- const repo_root_1 = require("./repo-root");
17
14
  const resolver_1 = require("./resolver");
18
15
  const settings_1 = require("./settings");
19
- const toPosix = (relativePath) => relativePath.split(path.sep).join("/");
20
- const readDocument = (absolutePath, file) => {
21
- try {
22
- return fs.readFileSync(absolutePath, "utf8");
23
- }
24
- catch (error) {
25
- throw new fs_errors_1.ReadError(`Cannot read ${file}: ${error instanceof Error ? error.message : String(error)}`);
26
- }
27
- };
16
+ const suppressions_1 = require("./suppressions");
28
17
  /**
29
18
  * The reference rewritten to the on-disk casing, or `undefined` when there's no single safe rewrite:
30
19
  * several siblings match case-insensitively, the reference has placeholders (so `actualPath` is one
@@ -68,12 +57,15 @@ const isMissingAnchor = (reference, resolution, placeholders) => {
68
57
  const anchors = (0, headings_1.readDocumentAnchors)(resolution.path);
69
58
  return anchors !== undefined && !(0, headings_1.hasAnchor)(anchors, fragment);
70
59
  };
71
- const checkDocument = (absolutePath, repoRoot, settings) => {
72
- const file = toPosix(path.relative(repoRoot, absolutePath));
73
- const tree = (0, parse_1.parseMarkdown)(readDocument(absolutePath, file), file);
60
+ const checkDocument = (document, repoRoot, settings) => {
61
+ const { absolutePath, file } = document;
62
+ const tree = (0, parse_1.parseMarkdown)((0, documents_1.readDocument)(document), file);
74
63
  const documentDir = path.dirname(absolutePath);
75
64
  let own;
76
- return (0, extract_1.extractReferences)(tree, settings).flatMap(({ kind, target, line, column }) => {
65
+ return (0, extract_1.extractReferences)(tree, {
66
+ constructs: settings.constructs,
67
+ ignoreMarker: suppressions_1.DOC_REFERENCES_IGNORE_MARKER,
68
+ }).flatMap(({ kind, target, line, column }) => {
77
69
  const referenceKind = (0, extract_1.referenceKindOf)(kind);
78
70
  // A fragment-only URL points into this document; inline code like `#channel` isn't a link.
79
71
  if (referenceKind === "url" && target.startsWith("#")) {
@@ -135,13 +127,12 @@ const checkDocument = (absolutePath, repoRoot, settings) => {
135
127
  */
136
128
  const checkDocReferences = ({ rootDir, config }) => {
137
129
  const settings = (0, settings_1.parseDocsSettings)(config);
138
- const checkedDir = (0, resolver_1.canonicalCase)(path.resolve(rootDir));
139
- const repoRoot = (0, resolver_1.canonicalCase)((0, repo_root_1.findRepoRootFromDir)(checkedDir, { rootDir: settings.rootDir, cwd: checkedDir }) ?? checkedDir);
140
- return (0, discover_1.discoverDocuments)(checkedDir)
141
- .map(resolver_1.canonicalCase)
142
- .filter(document => !(0, resolver_1.isIgnoredPath)(path.relative(repoRoot, document), settings.exclude))
143
- .flatMap(document => checkDocument(document, repoRoot, settings))
144
- .sort(finding_1.compareFindings);
130
+ const { repoRoot, documents } = (0, documents_1.discoverDocumentsToCheck)({
131
+ rootDir,
132
+ repoRootDir: settings.rootDir,
133
+ exclude: settings.exclude,
134
+ });
135
+ return documents.flatMap(document => checkDocument(document, repoRoot, settings)).sort(finding_1.compareFindings);
145
136
  };
146
137
  exports.checkDocReferences = checkDocReferences;
147
138
  //# sourceMappingURL=check-doc-references.js.map
@@ -0,0 +1,32 @@
1
+ export interface DocumentToCheck {
2
+ /** The document's absolute path, in on-disk letter case. */
3
+ readonly absolutePath: string;
4
+ /** The document's path relative to the repository root, with `/` separators. */
5
+ readonly file: string;
6
+ }
7
+ export interface DocumentsToCheck {
8
+ /** The repository root: the given `repoRootDir`, else the nearest `.git` at or above `rootDir`, else `rootDir`. */
9
+ readonly repoRoot: string;
10
+ readonly documents: ReadonlyArray<DocumentToCheck>;
11
+ }
12
+ export interface DiscoverDocumentsToCheckOptions {
13
+ /** The directory whose documents are checked: a repository, a git worktree, or a subdirectory of one. */
14
+ readonly rootDir: string;
15
+ /** An explicit repository root, resolved against `rootDir`; found from `.git` when omitted. */
16
+ readonly repoRootDir?: string;
17
+ /** Repo-relative globs of documents to leave out. */
18
+ readonly exclude?: ReadonlyArray<string>;
19
+ }
20
+ /**
21
+ * The `.md` and `.mdx` documents under `rootDir` that a check reads, minus the excluded ones, with the
22
+ * repository root their `file` paths are relative to.
23
+ *
24
+ * @throws {ReadError} when a directory can't be read
25
+ */
26
+ export declare const discoverDocumentsToCheck: ({ rootDir, repoRootDir, exclude, }: DiscoverDocumentsToCheckOptions) => DocumentsToCheck;
27
+ /**
28
+ * A document's text.
29
+ *
30
+ * @throws {ReadError} when the document can't be read
31
+ */
32
+ export declare const readDocument: ({ absolutePath, file }: DocumentToCheck) => string;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readDocument = exports.discoverDocumentsToCheck = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const discover_1 = require("./discover");
8
+ const fs_errors_1 = require("./fs-errors");
9
+ const repo_root_1 = require("./repo-root");
10
+ const resolver_1 = require("./resolver");
11
+ const toPosix = (relativePath) => relativePath.split(path.sep).join("/");
12
+ /**
13
+ * The `.md` and `.mdx` documents under `rootDir` that a check reads, minus the excluded ones, with the
14
+ * repository root their `file` paths are relative to.
15
+ *
16
+ * @throws {ReadError} when a directory can't be read
17
+ */
18
+ const discoverDocumentsToCheck = ({ rootDir, repoRootDir, exclude = [], }) => {
19
+ const checkedDir = (0, resolver_1.canonicalCase)(path.resolve(rootDir));
20
+ const repoRoot = (0, resolver_1.canonicalCase)((0, repo_root_1.findRepoRootFromDir)(checkedDir, { rootDir: repoRootDir, cwd: checkedDir }) ?? checkedDir);
21
+ const documents = (0, discover_1.discoverDocuments)(checkedDir)
22
+ .map(resolver_1.canonicalCase)
23
+ .filter(absolutePath => !(0, resolver_1.isIgnoredPath)(path.relative(repoRoot, absolutePath), exclude))
24
+ .map(absolutePath => ({ absolutePath, file: toPosix(path.relative(repoRoot, absolutePath)) }));
25
+ return { repoRoot, documents };
26
+ };
27
+ exports.discoverDocumentsToCheck = discoverDocumentsToCheck;
28
+ /**
29
+ * A document's text.
30
+ *
31
+ * @throws {ReadError} when the document can't be read
32
+ */
33
+ const readDocument = ({ absolutePath, file }) => {
34
+ try {
35
+ return fs.readFileSync(absolutePath, "utf8");
36
+ }
37
+ catch (error) {
38
+ throw new fs_errors_1.ReadError(`Cannot read ${file}: ${(0, fs_errors_1.errorMessage)(error)}`);
39
+ }
40
+ };
41
+ exports.readDocument = readDocument;
42
+ //# sourceMappingURL=documents.js.map
@@ -13,17 +13,24 @@ export interface ExtractedReference {
13
13
  /** 1-based column of the construct's start. */
14
14
  readonly column: number;
15
15
  }
16
+ export interface ExtractOptions extends Pick<DocsSettings, "constructs"> {
17
+ /**
18
+ * The marker of the ignore-next-line comment that suppresses the next line's references, such as
19
+ * `DOC_REFERENCES_IGNORE_MARKER`. Each check has its own, so one check's comment doesn't silence another.
20
+ */
21
+ readonly ignoreMarker: string;
22
+ }
16
23
  /** The resolver's reading of a construct: inline code is resolved as a bare path, everything else as a URL. */
17
24
  export declare const referenceKindOf: (construct: ReferenceConstruct) => ReferenceKind;
18
25
  /**
19
- * Every reference in `tree` whose construct `settings.constructs` enables, in document order.
26
+ * Every reference in `tree` whose construct `options.constructs` enables, in document order.
20
27
  * Code blocks (fenced or indented) and frontmatter are leaves, so nothing inside them is extracted;
21
28
  * so are MDX ESM and `{expressions}`, and a JSX element's attributes aren't children, so only the
22
29
  * markdown in its children is.
23
30
  * A link reference (`[x][r]`) is reported through its definition only, so each target is reported
24
31
  * once. Autolinks and GFM literal URLs are links like any other; deciding which targets to check is
25
32
  * the caller's job (see `classify.ts`).
26
- * References starting on the line after an ignore-next-line comment are dropped (see
27
- * `suppressions.ts`); a link reference's is decided on its definition's line.
33
+ * References starting on the line after an ignore-next-line comment for `options.ignoreMarker` are
34
+ * dropped (see `suppressions.ts`); a link reference's is decided on its definition's line.
28
35
  */
29
- export declare const extractReferences: (tree: MarkdownNode, settings: Pick<DocsSettings, "constructs">) => Array<ExtractedReference>;
36
+ export declare const extractReferences: (tree: MarkdownNode, options: ExtractOptions) => Array<ExtractedReference>;