@heroiclands/package-build 22.4.2 → 22.4.3

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.
@@ -1,11 +1,89 @@
1
+ /**
2
+ * Where a character offset in `text` falls, as a 1-based line and column.
3
+ *
4
+ * @param {string} text - The text the offset indexes into.
5
+ * @param {number} index - 0-based character offset.
6
+ * @returns {{line: number, column: number}}
7
+ */
8
+ export function lineColOf(text: string, index: number): {
9
+ line: number;
10
+ column: number;
11
+ };
12
+ /**
13
+ * Every code region in `text`, as a set of 1-based line numbers it spans.
14
+ *
15
+ * Block-level only (`spans: false`): an inline code span does not remove a
16
+ * whole line from consideration, only the characters it covers, which the
17
+ * text-scanning rules mask separately.
18
+ *
19
+ * @param {string} text - The section text.
20
+ * @returns {Set<number>} Lines that fall inside a fenced or indented block.
21
+ */
22
+ export function codeLineSet(text: string): Set<number>;
23
+ /**
24
+ * Every top-level bullet, as its own contiguous run of lines.
25
+ *
26
+ * A bullet's continuation — a wrapped line, a second paragraph, a nested
27
+ * elaboration — is indented under it and belongs to it; a line back at
28
+ * column 0 that is not itself a bullet (a bold subsection label, ordinary
29
+ * prose) closes it.
30
+ *
31
+ * @param {string} text - Section text.
32
+ * @param {Set<number>} codeLines - Lines inside a code region, from
33
+ * {@link codeLineSet}.
34
+ * @returns {Array<{startLine: number, text: string}>}
35
+ */
36
+ export function topLevelBullets(text: string, codeLines: Set<number>): Array<{
37
+ startLine: number;
38
+ text: string;
39
+ }>;
40
+ /**
41
+ * Every top-level block of release prose — one rendered changeset entry, or
42
+ * one unlabelled paragraph standing in for one.
43
+ *
44
+ * `@heroiclands/package-build/changelog` (`changelog.cjs`) writes a
45
+ * changeset's whole summary as one block, verbatim, so a block here holds
46
+ * together the same way that summary is authored: a bold label opening a
47
+ * line at column 0 (`**Compendiums**`) starts a new block, and — unlike
48
+ * {@link topLevelBullets}, where a bullet marker *is* the top-level
49
+ * construct — a `-` bullet at column 0 belongs to whatever block is
50
+ * already open, since a label's bullets sit unindented directly under it.
51
+ * Any other column-0 line (plain prose with no label, a bullet with no
52
+ * block open yet) starts the one "lead" block (`label: null`) a changeset
53
+ * with no category writes — the case `changelog group` sorts first and
54
+ * `check` never flags. Nested detail — a wrapped line, a bullet's own
55
+ * continuation — stays indented and belongs to whatever it follows.
56
+ * `changelog group` folds same-label blocks together; `check` warns when a
57
+ * block's label is not in the declared vocabulary.
58
+ *
59
+ * @param {string} text - Section text.
60
+ * @param {Set<number>} codeLines - Lines inside a code region, from
61
+ * {@link codeLineSet}.
62
+ * @param {Set<number>} [scaffoldLines] - Generated heading lines that close
63
+ * whatever block is open without starting one, from
64
+ * {@link scaffoldLineSet} — empty for a caller that already isolated one
65
+ * `### <Bump> Changes` body, since no heading falls inside it.
66
+ * @returns {Array<{startLine: number, label: string|null, text: string}>}
67
+ */
68
+ export function topLevelBlocks(text: string, codeLines: Set<number>, scaffoldLines?: Set<number>): Array<{
69
+ startLine: number;
70
+ label: string | null;
71
+ text: string;
72
+ }>;
1
73
  /**
2
74
  * Lint one pending changeset (`.changeset/*.md`).
3
75
  *
4
76
  * @param {string} text - The file's full contents, frontmatter included.
77
+ * @param {object} [opts]
78
+ * @param {readonly string[]|null} [opts.labels] - `changelog.labels`, in
79
+ * display order, or `null`/absent when the repository declares none —
80
+ * {@link checkUnknownLabels} checks nothing in that case.
5
81
  * @returns {{findings: Array<{line: number, column?: number,
6
82
  * severity: "error"|"warning", message: string}>}}
7
83
  */
8
- export function lintChangesetText(text: string): {
84
+ export function lintChangesetText(text: string, { labels }?: {
85
+ labels?: readonly string[] | null | undefined;
86
+ }): {
9
87
  findings: Array<{
10
88
  line: number;
11
89
  column?: number;
@@ -17,10 +95,16 @@ export function lintChangesetText(text: string): {
17
95
  * Lint the first `## <version>` release section of a `CHANGELOG.md`.
18
96
  *
19
97
  * @param {string} text - The changelog's full contents.
98
+ * @param {object} [opts]
99
+ * @param {readonly string[]|null} [opts.labels] - `changelog.labels`, in
100
+ * display order, or `null`/absent when the repository declares none —
101
+ * {@link checkUnknownLabels} checks nothing in that case.
20
102
  * @returns {{findings: Array<{line?: number, column?: number,
21
103
  * severity: "error"|"warning", message: string}>}}
22
104
  */
23
- export function lintReleaseText(text: string): {
105
+ export function lintReleaseText(text: string, { labels }?: {
106
+ labels?: readonly string[] | null | undefined;
107
+ }): {
24
108
  findings: Array<{
25
109
  line?: number;
26
110
  column?: number;
@@ -28,6 +112,27 @@ export function lintReleaseText(text: string): {
28
112
  message: string;
29
113
  }>;
30
114
  };
115
+ /**
116
+ * The first `## <version>` release section of a changelog, as raw character
117
+ * offsets rather than {@link extractReleaseSection}'s line-joined copy.
118
+ *
119
+ * `extractReleaseSection` rebuilds its `body` by joining a slice of
120
+ * `text.split("\n")`, which is fine for reporting a line number but drops
121
+ * the exact byte the next `## ` heading sits after — a caller rewriting the
122
+ * file in place, such as `changelog group`, needs `text.slice(start, end)`
123
+ * to be the section verbatim, so it can splice a replacement back in without
124
+ * guessing at the whitespace on either side.
125
+ *
126
+ * @param {string} text - The changelog's full contents.
127
+ * @returns {{start: number, end: number}|null} `null` when no `## ` heading
128
+ * is present. `text.slice(start, end)` is the section, byte-exact,
129
+ * including whatever separates it from the next `## ` heading or the end
130
+ * of the file.
131
+ */
132
+ export function releaseSectionRange(text: string): {
133
+ start: number;
134
+ end: number;
135
+ } | null;
31
136
  /**
32
137
  * The finding one rule reports, before its line is mapped into the caller's
33
138
  * file.