slicekit 0.3.0 → 0.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicekit",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Spec-driven agentic workflow kit",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,4 +1,4 @@
1
- // sync-release (05 REQ-5.5, D-43, D-89, D-90): under --ci on a sync pull request (a `sync/<short sha>`
1
+ // sync-release (05 REQ-5.5, D-43, D-89, D-90, D-92): under --ci on a sync pull request (a `sync/<short sha>`
2
2
  // branch), the files the release step writes (package.json, CHANGELOG.md and the rendered files) must
3
3
  // equal what CI computes for the merge the branch names: a fresh checkout of that merge in a temporary
4
4
  // worktree, synced from the git host and given the version, section and render the sync step would
@@ -78,12 +78,13 @@ function blob(root, rev, file) {
78
78
  }
79
79
 
80
80
  // Runs the sync step in the merge's worktree and returns the release paths it changed, with their
81
- // new content (null for a removed file).
81
+ // new content (null for a removed file). The version comes from the function the sync job runs
82
+ // (applyRelease): the merged slices no changelog section at the merge names (D-92).
82
83
  function expectedFiles(root, ctx, wt, owns) {
83
84
  const cfg = loadConfig(wt);
84
85
  const host = getHost(cfg, ctx.env ?? process.env, root);
85
- const { changes } = syncFromHost(wt, cfg, host);
86
- applyRelease(wt, cfg, changes, { merge: 'HEAD', isKit: isKitRoot(root) });
86
+ syncFromHost(wt, cfg, host);
87
+ applyRelease(wt, cfg, { merge: 'HEAD', isKit: isKitRoot(root) });
87
88
  const tracked = nul(git(wt, ['diff', '--name-only', '--no-renames', '-z', 'HEAD']));
88
89
  const untracked = nul(git(wt, ['ls-files', '--others', '--exclude-standard', '-z']));
89
90
  const out = new Map();
package/src/cli/status.js CHANGED
@@ -7,7 +7,7 @@ import { programStage } from '../stage.js';
7
7
  import { renderBuild } from '../state/build.js';
8
8
  import { LockError, readSlice } from '../state/index.js';
9
9
  import { syncFromHost } from '../state/sync.js';
10
- import { ReleaseError, applyRelease } from '../release-version.js';
10
+ import { ReleaseError, applyRelease, onDefaultTip } from '../release-version.js';
11
11
  import { getHost } from '../adapters/githost/index.js';
12
12
  import { GitHostError } from '../adapters/githost/errors.js';
13
13
 
@@ -71,9 +71,12 @@ async function run(args, io) {
71
71
  throw e;
72
72
  }
73
73
  record(result);
74
- // With --write and release.auto, the sync also sets the next version (D-90).
75
- if (values.write) {
76
- const release = applyRelease(root, cfg, result.changes);
74
+ // With --write and release.auto, the sync also sets the next version (D-90, D-92), and only
75
+ // when HEAD is the tip of the default branch (issue #142): a version counts from that branch.
76
+ if (values.write && cfg.release?.auto === true && !onDefaultTip(root, cfg)) {
77
+ io.stderr(`slicekit: version not set: HEAD is not the tip of ${cfg.defaultBranch}\n`);
78
+ } else if (values.write) {
79
+ const release = applyRelease(root, cfg);
77
80
  if (release) {
78
81
  version = release.version;
79
82
  if (!values.json) io.stdout(`version ${version}: package.json and CHANGELOG.md\n`);
@@ -1,19 +1,45 @@
1
- // The version a sync pull request sets (05 REQ-5.5, D-90, P5/S-48). With `release.auto` true in
2
- // config, the sync step after a merge sets package.json's version and adds CHANGELOG.md's newest
3
- // section for it: the patch number up by one for the slice merges the sync records, or the minor
4
- // number up by one (patch 0) when a merge it records leaves every slice of that slice's phase
5
- // `merged` or `released`. One version per sync, however many merges it records; its section names
6
- // every one of them. A merge that changes package.json's version itself, with that version's
7
- // CHANGELOG.md section (the release slice's own, or a sync pull request's), a merge that records no
8
- // slice merge (a [plan], [sync] or [release] merge), and a config without `release.auto` set none. The version counts from package.json at the merge commit, never from one
9
- // an open sync pull request proposes. The rendered files follow the version (`update --yes`), as
10
- // `build render` would commit them.
1
+ // The version a sync pull request sets (05 REQ-5.5, D-90, D-92, P5/S-48, P5/S-49). With
2
+ // `release.auto` true in config, the sync step after a merge sets package.json's version and adds
3
+ // CHANGELOG.md's newest section for it: the patch number up by one, or the minor number up by one
4
+ // (patch 0) when a slice it names leaves every slice of that slice's phase `merged` or `released`.
5
+ // One version per sync; its section names every slice it versions.
6
+ //
7
+ // The changelog is the record (D-92). The slices a sync versions are the merged slices that no
8
+ // CHANGELOG.md section at the merge names, less those that began at or before the floor: the
9
+ // newest commit that set the version by hand, or the commit that turned `release.auto` on when
10
+ // there is none. So the result does not depend on which merge the sync runs on, nor on which
11
+ // slices this run of the sync moved to `merged`. A sync with no such slice, and a config without
12
+ // `release.auto`, set none. The version counts from package.json at the merge commit, never from
13
+ // one an open sync pull request proposes. The rendered files follow the version (`update --yes`),
14
+ // as `build render` would commit them.
15
+ //
16
+ // Where a slice begins: the oldest commit of the default branch's first-parent history that brings
17
+ // its state file. For a merge commit or a squash merge that is the merge itself; for a rebase merge
18
+ // it is the slice's first commit. A slice that begins at or before the floor either merged before
19
+ // the version set by hand or set that version itself: the commits of a rebase-merged slice are
20
+ // contiguous on that history, so a floor among them is that slice's own commit. Neither how the
21
+ // pull request was merged, nor a commit's subject, nor a move of a slice's recorded state plays a
22
+ // part.
23
+ //
24
+ // A version is set at the first commit of the first-parent history where package.json holds it and
25
+ // CHANGELOG.md holds its section, whichever of the two arrived first: a commit that changes the
26
+ // version followed by a commit that adds the section sets it at the second, and so does a section
27
+ // followed by the version. A version that never gets a section is not set. A heading
28
+ // `## [<version>] - <date>` is that version's section as `## <version>` is. What tells a sync's
29
+ // version from one set by hand is that section's content, read at that commit. The section is a sync's only when it holds a slice line
30
+ // and every non-empty line under its heading is a line `changelogSection` writes: a slice line,
31
+ // `- <slice ID> <name> (#<pull request>)`, or, for a minor version, a phase line. A section with
32
+ // any other line was written by hand, and its commit is a floor. A section written by hand that
33
+ // holds only lines of those shapes is taken for a sync's. That is accepted: the slices it names are
34
+ // excluded by name, and only the slices merged before it that no section names are then counted.
11
35
  import fs from 'node:fs';
12
36
  import path from 'node:path';
13
37
  import { fileURLToPath } from 'node:url';
14
- import { ConfigError, releaseAutoError } from './config.js';
38
+ import { CONFIG_PATH, ConfigError, releaseAutoError } from './config.js';
15
39
  import { GitError, git } from './git.js';
16
40
  import { readText, writeText } from './fs.js';
41
+ import { ID, stateFileName } from './ids.js';
42
+ import { kitPaths } from './paths.js';
17
43
  import { RENDERED, SETTINGS, kitVersion } from './render/index.js';
18
44
  import { entriesForShape } from './render/manifest.js';
19
45
  import { applyUpdate, planUpdate } from './render/update.js';
@@ -53,7 +79,24 @@ export function nextVersion({ current, merges, phaseComplete }) {
53
79
  return phaseComplete ? `${maj}.${min + 1}.0` : `${maj}.${min}.${pat + 1}`;
54
80
  }
55
81
 
56
- const sliceLine = (s) => `- ${s.id} ${s.name}${Number.isInteger(s.pr) ? ` (#${s.pr})` : ''}`;
82
+ // The two lines `changelogSection` writes under a heading, each from its parts. `lineShape` builds
83
+ // the test for a line of either kind from the same two functions, so the test follows the format.
84
+ const sliceText = (id, name, pr) => `- ${id} ${name}${pr === null ? '' : ` (#${pr})`}`;
85
+ const phaseText = (number, name) => `Phase ${number}${name ? `: ${name}` : ''}.`;
86
+ const sliceLine = (s) => sliceText(s.id, s.name, Number.isInteger(s.pr) ? s.pr : null);
87
+ const phaseLine = (p) => phaseText(p.id.replace(/^P/, ''), p.name);
88
+
89
+ // A part left open in a line, and the text that may stand in its place.
90
+ const OPEN = { id: '\u0001', name: '\u0002', number: '\u0003' };
91
+ const FILLS = { [OPEN.id]: ID.sliceAddr, [OPEN.name]: '\\S.*', [OPEN.number]: '\\d+' };
92
+ function lineShape(text) {
93
+ const literal = text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
94
+ return new RegExp(`^${literal.replace(/[\u0001-\u0003]/g, (open) => FILLS[open])}$`);
95
+ }
96
+ const SLICE_SHAPES = [sliceText(OPEN.id, OPEN.name, null), sliceText(OPEN.id, OPEN.name, OPEN.number)].map(lineShape);
97
+ const PHASE_SHAPES = [phaseText(OPEN.number, ''), phaseText(OPEN.number, OPEN.name)].map(lineShape);
98
+ const isSliceLine = (l) => SLICE_SHAPES.some((re) => re.test(l));
99
+ const isPhaseLine = (l) => PHASE_SHAPES.some((re) => re.test(l));
57
100
 
58
101
  // CHANGELOG.md's section for `version`: each phase it completes with all of that phase's slices,
59
102
  // then every other slice merge the sync records. merges and slices: [{ id, name, pr }];
@@ -62,7 +105,7 @@ export function changelogSection({ version, merges, phases = [] }) {
62
105
  const out = [`## ${version}`, ''];
63
106
  const named = new Set();
64
107
  for (const p of phases) {
65
- out.push(`Phase ${p.id.replace(/^P/, '')}${p.name ? `: ${p.name}` : ''}.`, '');
108
+ out.push(phaseLine(p), '');
66
109
  for (const s of p.slices) {
67
110
  out.push(sliceLine(s));
68
111
  named.add(s.id);
@@ -77,11 +120,21 @@ export function changelogSection({ version, merges, phases = [] }) {
77
120
  return `${out.join('\n').trimEnd()}\n`;
78
121
  }
79
122
 
80
- // The changelog with `section` on top, under the file's intro (everything before the first `## `).
123
+ // The one reading of a changelog heading. A section starts at a line `## <version>` or
124
+ // `## [<version>]`, each with or without text after it (a date). `headingVersion` gives the version
125
+ // a line names, or null when the line is not a section heading.
126
+ const isHeading = (l) => /^## /.test(l);
127
+ function headingVersion(l) {
128
+ if (!isHeading(l)) return null;
129
+ const first = l.replace(/^## /, '').split(/\s/)[0];
130
+ return /^\[.+\]$/.test(first) ? first.slice(1, -1) : first;
131
+ }
132
+
133
+ // The changelog with `section` on top, under the file's intro (everything before the first heading).
81
134
  export function prependSection(text, section) {
82
135
  if (text === null || text === '') return `# Changelog\n\n${section}`;
83
136
  const lines = text.split('\n');
84
- const at = lines.findIndex((l) => /^## /.test(l));
137
+ const at = lines.findIndex(isHeading);
85
138
  if (at < 0) return `${text.replace(/\n*$/, '\n\n')}${section}`;
86
139
  return [...lines.slice(0, at), ...`${section}\n`.split('\n').slice(0, -1), ...lines.slice(at)].join('\n');
87
140
  }
@@ -99,33 +152,123 @@ export function setVersion(text, version) {
99
152
  return next;
100
153
  }
101
154
 
102
- // The version field of package.json at `rev`, or null when the commit holds none.
103
- function versionAt(root, rev) {
104
- let text;
155
+ // The text of `file` (a POSIX path from the root) at `rev`, or null when the commit holds none.
156
+ function textAt(root, rev, file) {
105
157
  try {
106
- text = git(root, ['show', `${rev}:${PACKAGE}`]);
158
+ return git(root, ['show', `${rev}:${file}`]);
107
159
  } catch (e) {
108
160
  if (e instanceof GitError) return null;
109
161
  throw e;
110
162
  }
163
+ }
164
+
165
+ function jsonAt(root, rev, file) {
166
+ const text = textAt(root, rev, file);
167
+ if (text === null) return null;
111
168
  try {
112
- const v = JSON.parse(text).version;
113
- return typeof v === 'string' ? v : null;
169
+ return JSON.parse(text);
114
170
  } catch {
115
171
  return null;
116
172
  }
117
173
  }
118
174
 
119
- // The versions CHANGELOG.md's `## ` headings name at `rev`, newest first; [] when it holds none.
120
- function changelogVersionsAt(root, rev) {
121
- let text;
175
+ // The version field of package.json at `rev`, or null when the commit holds none.
176
+ function versionAt(root, rev) {
177
+ const v = jsonAt(root, rev, PACKAGE)?.version;
178
+ return typeof v === 'string' ? v : null;
179
+ }
180
+
181
+ // The version field of a package.json's text, or null when it holds none.
182
+ function versionOf(text) {
122
183
  try {
123
- text = git(root, ['show', `${rev}:${CHANGELOG}`]);
124
- } catch (e) {
125
- if (e instanceof GitError) return [];
126
- throw e;
184
+ const v = JSON.parse(text)?.version;
185
+ return typeof v === 'string' ? v : null;
186
+ } catch {
187
+ return null;
127
188
  }
128
- return text.split('\n').filter((l) => /^## /.test(l)).map((l) => l.replace(/^## /, '').split(/\s/)[0]);
189
+ }
190
+
191
+ // The lines of a changelog's sections: everything from its first heading on.
192
+ function sectionLines(text) {
193
+ const all = (text ?? '').split('\n');
194
+ const at = all.findIndex(isHeading);
195
+ return at < 0 ? [] : all.slice(at);
196
+ }
197
+
198
+ // Whether a changelog's text holds the section of `version`.
199
+ const holdsSection = (text, version) => sectionLines(text).some((l) => headingVersion(l) === version);
200
+
201
+ // Whether package.json at `rev` holds `version` and CHANGELOG.md at `rev` holds its section.
202
+ const holdsVersion = (root, rev, version) => versionAt(root, rev) === version && holdsSection(textAt(root, rev, CHANGELOG), version);
203
+
204
+ // Whether a changelog section names the slice `id` (P1/S-01 does not name P1/S-011).
205
+ function namesSlice(sections, id) {
206
+ const re = new RegExp(`(^|[^A-Za-z0-9/-])${id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![A-Za-z0-9])`);
207
+ return sections.some((l) => re.test(l));
208
+ }
209
+
210
+ // Whether the commit `rev` set the version: package.json at it holds a version and CHANGELOG.md at
211
+ // it holds that version's section, and its first parent does not hold both. So the commit brought
212
+ // the version, the section, or the two together. A first commit sets none, and neither does a
213
+ // commit whose first parent has no package.json version.
214
+ function setsVersion(root, rev) {
215
+ const now = versionAt(root, rev);
216
+ if (now === null || !holdsVersion(root, rev, now)) return false;
217
+ return versionAt(root, `${rev}^1`) !== null && !holdsVersion(root, `${rev}^1`, now);
218
+ }
219
+
220
+ const posix = (p) => p.split(path.sep).join('/');
221
+ const stateDir = (root, cfg) => posix(path.relative(root, kitPaths(root, cfg).state));
222
+ const nonEmpty = (out) => out.split('\n').map((l) => l.trim()).filter((l) => l !== '');
223
+
224
+ // Whether the commit `rev`, which set the version, set it by hand: CHANGELOG.md's section for that
225
+ // version, as it stands at `rev`, holds a line `changelogSection` does not write, or no slice line.
226
+ // A section of slice lines only (and, for a minor version, phase lines) is a sync's, however its
227
+ // pull request was merged and whatever the commit's subject.
228
+ function setByHand(root, rev) {
229
+ const lines = sectionLines(textAt(root, rev, CHANGELOG));
230
+ const version = versionAt(root, rev);
231
+ // `rev` set the version, so CHANGELOG.md at it holds the section.
232
+ const start = lines.findIndex((l) => headingVersion(l) === version);
233
+ const end = lines.findIndex((l, i) => i > start && isHeading(l));
234
+ const body = lines.slice(start + 1, end < 0 ? undefined : end).map((l) => l.trimEnd()).filter((l) => l !== '');
235
+ const minor = SEMVER.exec(String(version))?.[3] === '0';
236
+ return !(body.some(isSliceLine) && body.every((l) => isSliceLine(l) || (minor && isPhaseLine(l))));
237
+ }
238
+
239
+ // The commits of `rev`'s first-parent history that changed one of `paths`, newest first.
240
+ function firstParentCommits(root, rev, paths) {
241
+ return nonEmpty(git(root, ['log', '--first-parent', '-m', '--format=%H', rev, '--', ...paths]));
242
+ }
243
+
244
+ // The floor of D-92 at `merge`: the newest first-parent commit that set the version by hand; with
245
+ // none, the newest one that turned release.auto on (a first commit that holds it on counts). null
246
+ // when the history holds neither, and then no slice is versioned.
247
+ function floorOf(root, cfg, merge) {
248
+ // A version is set by a commit that changes package.json or CHANGELOG.md, whichever came last.
249
+ for (const c of firstParentCommits(root, merge, [PACKAGE, CHANGELOG])) {
250
+ if (setsVersion(root, c) && setByHand(root, c)) return c;
251
+ }
252
+ const config = posix(CONFIG_PATH);
253
+ const autoAt = (rev) => jsonAt(root, rev, config)?.release?.auto === true;
254
+ for (const c of firstParentCommits(root, merge, [config])) {
255
+ if (autoAt(c) && !autoAt(`${c}^1`)) return c;
256
+ }
257
+ return null;
258
+ }
259
+
260
+ // Where each slice begins at `merge`: Map(state file → the oldest commit of the first-parent
261
+ // history that brings it).
262
+ function sliceBegins(root, cfg, merge) {
263
+ const out = git(root, ['-c', 'core.quotepath=off', 'log', '--first-parent', '-m', '--no-renames', '--diff-filter=A', '--name-only', '--format=%x00%H', merge, '--', stateDir(root, cfg)]);
264
+ const begins = new Map();
265
+ // Newest first, so the last commit seen for a file is the oldest that brings it.
266
+ for (const chunk of out.split('\0')) {
267
+ const [sha, ...files] = nonEmpty(chunk);
268
+ if (!sha) continue;
269
+ for (const f of files) begins.set(f, sha);
270
+ }
271
+ return begins;
129
272
  }
130
273
 
131
274
  // The paths the release step may write: package.json, CHANGELOG.md and the files `update` renders.
@@ -145,29 +288,38 @@ function phaseName(phaseDir, phaseId) {
145
288
  return null;
146
289
  }
147
290
 
148
- // What the sync after `merge` sets, given the slice changes syncFromHost made: { version, section }
149
- // or null (see the header). Reads the slice states on disk, so it runs after the sync.
150
- export function releaseFor(root, cfg, changes, { merge = 'HEAD' } = {}) {
291
+ // What the sync on `merge` sets: { version, section } or null (see the header). Reads the slice
292
+ // states on disk, so it runs after the sync; everything else it reads from the commits up to `merge`.
293
+ export function releaseFor(root, cfg, { merge = 'HEAD' } = {}) {
151
294
  const bad = releaseAutoError(cfg);
152
295
  if (bad) throw new ConfigError([bad]);
153
296
  if (cfg.release?.auto !== true) return null;
154
- if (!Array.isArray(changes) || changes.length === 0) return null;
155
297
  if (!fs.existsSync(path.join(root, PACKAGE))) return null;
156
298
  const current = versionAt(root, merge);
157
299
  if (current === null) return null;
158
- // A first commit, or a merge that sets the version itself: no version from the sync. A merge sets
159
- // it itself when it changes package.json's version and CHANGELOG.md at the merge already holds
160
- // that version's section (the release slice's merge, or a sync pull request's).
161
- const before = versionAt(root, `${merge}^1`);
162
- if (before === null) return null;
163
- if (before !== current && changelogVersionsAt(root, merge).includes(current)) return null;
164
300
  const all = findSliceFiles(root, cfg).map((f) => {
165
301
  const s = parseSliceFile(readText(f.path), f.path);
166
302
  const st = readSlice(root, cfg, s.id);
167
303
  return { id: s.id, name: s.name, phase: f.phaseId, phaseDir: f.phaseDir, state: st.state, pr: st.pr?.number ?? null };
168
304
  });
169
- const byId = new Map(all.map((s) => [s.id, s]));
170
- const merges = changes.map((c) => ({ id: c.id, name: byId.get(c.id)?.name ?? '', pr: c.pr, phase: byId.get(c.id)?.phase }));
305
+ // The merged slices no changelog section at the merge names.
306
+ const sections = sectionLines(textAt(root, merge, CHANGELOG));
307
+ const unnamed = all.filter((s) => DONE.includes(s.state) && !namesSlice(sections, s.id));
308
+ if (unnamed.length === 0) return null;
309
+ const floor = floorOf(root, cfg, merge);
310
+ if (floor === null) return null;
311
+ // Less those that began at or before the floor: merged before it, or the slice that set it.
312
+ const after = nonEmpty(git(root, ['rev-list', '--first-parent', `${floor}..${merge}`]));
313
+ const begins = sliceBegins(root, cfg, merge);
314
+ const dir = stateDir(root, cfg);
315
+ const merges = [];
316
+ for (const s of unnamed) {
317
+ const at = after.indexOf(begins.get(`${dir}/${stateFileName(s.id)}`));
318
+ if (at < 0) continue;
319
+ merges.push({ id: s.id, name: s.name, pr: s.pr, phase: s.phase, at });
320
+ }
321
+ // In the order they began, oldest first; the slices of one commit in the order of their files.
322
+ merges.sort((x, y) => y.at - x.at);
171
323
  const phases = [];
172
324
  for (const id of [...new Set(merges.map((m) => m.phase).filter(Boolean))]) {
173
325
  const slices = all.filter((s) => s.phase === id);
@@ -180,16 +332,39 @@ export function releaseFor(root, cfg, changes, { merge = 'HEAD' } = {}) {
180
332
  return { version, section: changelogSection({ version, merges, phases }) };
181
333
  }
182
334
 
335
+ // Whether HEAD is the tip of the default branch: the local branch, or origin's when the clone has
336
+ // no local one. `status --sync --write` sets a version only there (issue #142).
337
+ export function onDefaultTip(root, cfg) {
338
+ const at = (ref) => {
339
+ try {
340
+ return git(root, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
341
+ } catch (e) {
342
+ if (e instanceof GitError) return null;
343
+ throw e;
344
+ }
345
+ };
346
+ const head = at('HEAD');
347
+ const tip = at(`refs/heads/${cfg.defaultBranch}`) ?? at(`refs/remotes/origin/${cfg.defaultBranch}`);
348
+ return head !== null && head === tip;
349
+ }
350
+
183
351
  // Writes what releaseFor computed: package.json's version, the changelog section, and the render at
184
352
  // that version (the kit's own checkout) or at the running kit's version (any other). `isKit` says
185
- // which; it defaults to whether `root` is the kit's checkout. Returns the release or null.
186
- export function applyRelease(root, cfg, changes, { merge = 'HEAD', isKit = isKitRoot(root) } = {}) {
187
- const release = releaseFor(root, cfg, changes, { merge });
353
+ // which; it defaults to whether `root` is the kit's checkout. Returns the release, or null when
354
+ // there is none or the files on disk already hold it (a second run on the same commit).
355
+ export function applyRelease(root, cfg, { merge = 'HEAD', isKit = isKitRoot(root) } = {}) {
356
+ const release = releaseFor(root, cfg, { merge });
188
357
  if (release === null) return null;
189
358
  const pkg = path.join(root, PACKAGE);
190
- writeText(pkg, setVersion(readText(pkg), release.version));
191
359
  const log = path.join(root, CHANGELOG);
192
- writeText(log, prependSection(fs.existsSync(log) ? readText(log) : null, release.section));
360
+ const pkgText = readText(pkg);
361
+ const logText = fs.existsSync(log) ? readText(log) : null;
362
+ // releaseFor reads the commits and this writes the files on disk. When package.json on disk holds
363
+ // the version computed and CHANGELOG.md on disk holds its section, an earlier run on this commit
364
+ // wrote them: this run writes nothing and sets no version.
365
+ if (versionOf(pkgText) === release.version && holdsSection(logText, release.version)) return null;
366
+ writeText(pkg, setVersion(pkgText, release.version));
367
+ writeText(log, prependSection(logText, release.section));
193
368
  const version = isKit ? release.version : kitVersion();
194
369
  applyUpdate(root, cfg, planUpdate(root, cfg, { version }), { version });
195
370
  return release;