dsh-plugin-toolkit 0.20.19 → 0.20.21

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,37 @@
1
+ ## 0.20.21
2
+
3
+ - **`doctor --fix --write` repairs a manifest saved with a UTF-8 BOM.** `doctor`
4
+ read the BOM away, but the repair write re-read the raw file with `JSON.parse`,
5
+ so it printed the planned `engines.dsh` edit and then failed with a bare
6
+ `Unexpected token` on the same manifest it had just accepted. Both repair
7
+ entry points (`doctor --fix` and `fix --engines`) now read through `doctor`'s
8
+ one BOM-aware manifest source, keep the existing indentation and line endings,
9
+ and write through one shared helper that starts from the BOM-stripped source,
10
+ so the rewritten file has no BOM (not a doubled one) and is valid JSON. A
11
+ write failure is now reported as a `manifest` failure by both commands instead
12
+ of escaping from `fix --engines`. Four process-level tests run the literal
13
+ `doctor . --fix --write` and `fix . --engines --write` from a temp plugin with
14
+ no `engines.dsh`: both repair a BOM copy and a no-BOM control, and both
15
+ normalize a doubled BOM without adding another one.
16
+
17
+ ## 0.20.20
18
+
19
+ - **A repeated `release --pr` is a no-op when the committed index already
20
+ carries the version.** The resume path noticed that the same version with the
21
+ same publish time needed no index write, but it still entered the PR
22
+ sequence; `git commit` then failed because there was nothing staged, and the
23
+ run stopped with a `market/<version>` branch left behind. An unchanged index
24
+ that is already committed now ends the release after the registry wait: it
25
+ prints `<index> already carried <version>; nothing to commit`, exits `0`,
26
+ leaves `git log -1` alone, and creates no branch even with `--pr` or
27
+ `--merge`. An entry that an earlier run without `--pr` wrote but did not
28
+ commit still goes through the branch and PR so the release is finished. A
29
+ different publish time still stops with both timestamps named. Three
30
+ consecutive CLI runs now assert exit `0` and an unchanged `git log -1`, and a
31
+ checked-in one-second-mismatch fixture pins the failure through the CLI as
32
+ well: exit `1`, both timestamps in the error, and no `market/<version>`
33
+ branch.
34
+
1
35
  ## 0.20.19
2
36
 
3
37
  - **`audit --home` expands `~` and `~\` before the scan, and a bare flag is
package/README.md CHANGED
@@ -976,7 +976,7 @@ The install reports success and nothing shows up. In this order:
976
976
  3. Create and push the tag, which starts the plugin's release workflow.
977
977
  4. Poll the registry until it actually serves that version, reporting each wait.
978
978
  5. Write the index entry with the publish time **the registry reports**, not the local clock. It waits for `time[version]` specifically: the abbreviated registry document has no `time` field, and an entry with a null timestamp is rejected by the market checker.
979
- 6. With `--pr`: commit that entry on `market/<version>`, push it, and open the pull request. With `--merge` as well: wait for `gh pr checks` to settle, then squash-merge.
979
+ 6. With `--pr`: commit that entry on `market/<version>`, push it, and open the pull request. With `--merge` as well: wait for `gh pr checks` to settle, then squash-merge. When the committed index already carries this version with the same publish time there is nothing to commit, so the branch and PR steps are skipped instead of failing at `git commit`. An entry written by an earlier run without `--pr` is still uncommitted, so a later `--pr` run commits it and opens the PR.
980
980
 
981
981
  ```sh
982
982
  npx dsh-plugin release . --pr --merge
@@ -990,7 +990,7 @@ checks settled after 1s (1 look(s))
990
990
  merged
991
991
  ```
992
992
 
993
- Without `--pr` it prints the `git add` / `gh pr create` commands instead of running them; `--dry-run` prints the whole sequence before anything happens. A re-run after a failure is safe: when the tag already points at HEAD it is reused rather than recreated, the release continues with the registry wait, and the same version with the same publish time is a no-op.
993
+ Without `--pr` it prints the `git add` / `gh pr create` commands instead of running them; `--dry-run` prints the whole sequence before anything happens. A re-run after a failure is safe: when the tag already points at HEAD it is reused rather than recreated, the release continues with the registry wait, and the same version with the same publish time is a no-op once the index entry is committed. A no-op release prints `<index> already carried <version>; nothing to commit`, exits `0`, leaves `git log -1` unchanged, and creates no `market/<version>` branch, even when `--pr` or `--merge` is passed. A different publish time is not a no-op: the release stops at `index`, names the indexed and registry timestamps in the error, exits `1`, and creates no `market/<version>` branch.
994
994
 
995
995
  If that tag points at another commit, the release does not move it. It exits `1`
996
996
  and names the tag, the commit it points at, HEAD, and the recovery:
@@ -1060,7 +1060,9 @@ npx dsh-plugin-toolkit@latest verify .
1060
1060
 
1061
1061
  **Will `doctor --fix` rewrite my `package.json`?**
1062
1062
  Only with `--write`. Without it the command prints the plan and stops; with it,
1063
- it applies the edits in the plan and runs the checks again.
1063
+ it applies the edits in the plan and runs the checks again. A manifest saved
1064
+ with a UTF-8 BOM is read and repaired through the same path, and the rewritten
1065
+ file no longer starts with the BOM; `fix --engines --write` uses that path too.
1064
1066
 
1065
1067
  **`doctor` passes, but the panel still does not appear. What next?**
1066
1068
  `doctor` checks the manifest and source without executing the plugin. `verify`
package/lib/audit.mjs CHANGED
@@ -11,7 +11,13 @@ import fs from 'node:fs';
11
11
  import os from 'node:os';
12
12
  import path from 'node:path';
13
13
 
14
- import { checkHostCompatibility, doctor, hostRange, version as manifestVersion } from './doctor.mjs';
14
+ import {
15
+ checkHostCompatibility,
16
+ doctor,
17
+ hostRange,
18
+ readManifestSource,
19
+ version as manifestVersion,
20
+ } from './doctor.mjs';
15
21
  import { hostCompatibility } from './compat.mjs';
16
22
  import { readGraph } from './dev.mjs';
17
23
  import { auditRemote, fixRemote } from './remote.mjs';
@@ -174,11 +180,10 @@ export function listInstalled({ home = DEFAULT_HOME } = {}) {
174
180
  }
175
181
  let manifest;
176
182
  try {
177
- // Strip the BOM the same way doctor does: a manifest saved by Notepad
178
- // is still readable, and treating it as unreadable would be a false
179
- // alarm in the other direction.
180
- const text = String(fs.readFileSync(manifestPath, 'utf8')).replace(/^\uFEFF/u, '').trim();
181
- manifest = JSON.parse(text);
183
+ // Read through the same BOM-aware path as doctor: a manifest saved
184
+ // by Notepad is still readable, and a parse failure keeps naming
185
+ // the file instead of only the JSON token.
186
+ manifest = readManifestSource(dir).manifest;
182
187
  } catch (error) {
183
188
  // A package.json that is listed in the profile but does not parse is
184
189
  // still an installed plugin, and "it does not parse" is exactly what
@@ -190,7 +195,7 @@ export function listInstalled({ home = DEFAULT_HOME } = {}) {
190
195
  name,
191
196
  profile,
192
197
  manifestPath,
193
- message: `${manifestPath} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,
198
+ message: error instanceof Error ? error.message : String(error),
194
199
  }),
195
200
  );
196
201
  }
package/lib/cli.mjs CHANGED
@@ -694,13 +694,13 @@ export async function run(argv, io = console, deps = {}) {
694
694
  }
695
695
 
696
696
  io.log(`tagged ${result.tag}, npm served ${name}@${version} after ${Math.round(result.waitedMs / 1000)}s`);
697
- if (result.indexUpdate !== null && result.indexUpdate.unchanged === true) {
697
+ if (result.indexUpdate !== null && result.pullRequest !== undefined) {
698
+ io.log(`updated ${result.indexUpdate.file} on ${result.pullRequest.branch}`);
699
+ } else if (result.indexUpdate !== null && result.indexUpdate.unchanged === true) {
698
700
  io.log(`${result.indexUpdate.file} already carried ${version}; nothing to commit`);
699
- } else if (result.indexUpdate !== null && result.pullRequest === undefined) {
701
+ } else if (result.indexUpdate !== null) {
700
702
  io.log(`updated ${result.indexUpdate.file} — commit it and open the PR:`);
701
703
  io.log(` git add ${result.indexUpdate.file} && git commit -m "market: ${version}" && gh pr create --fill`);
702
- } else if (result.indexUpdate !== null) {
703
- io.log(`updated ${result.indexUpdate.file} on ${result.pullRequest.branch}`);
704
704
  } else {
705
705
  io.log('no market/index.json here, so only the tag and the publish happened');
706
706
  }
package/lib/doctor.mjs CHANGED
@@ -55,7 +55,29 @@ function isRangeExpression(value) {
55
55
  return parseRange(value) !== null;
56
56
  }
57
57
 
58
- export function readManifest(dir) {
58
+ /**
59
+ * Remove every UTF-8 BOM at the start of a text file.
60
+ *
61
+ * One BOM is what Notepad writes; more than one is what a botched repair can
62
+ * leave behind. Stripping the run rather than a single character means a
63
+ * manifest that was already damaged is still readable, and a writer that starts
64
+ * from the stripped text cannot add another BOM on top.
65
+ */
66
+ export function stripBom(text) {
67
+ return String(text).replace(/^\uFEFF+/u, '');
68
+ }
69
+
70
+ /**
71
+ * Read the one local manifest every command reads.
72
+ *
73
+ * Notepad and some VS Code configurations save UTF-8 with a BOM. JSON.parse
74
+ * rejects it with a bare `Unexpected token`, so this is the single place that
75
+ * strips the BOM and names the file on failure. `raw` is the bytes as written:
76
+ * repair commands need it to keep the original indentation and line endings,
77
+ * and returning it here means the reader and the writer cannot disagree about
78
+ * which manifest is being edited.
79
+ */
80
+ export function readManifestSource(dir) {
59
81
  // `doctor '~/my-panel'` arrives with a literal tilde from cmd/PowerShell.
60
82
  // Resolve it here too, because this is also a public entry point.
61
83
  const target = resolvePath(dir);
@@ -63,16 +85,19 @@ export function readManifest(dir) {
63
85
  if (fs.existsSync(manifestPath) === false) {
64
86
  throw new Error(`no package.json in ${target}`);
65
87
  }
66
- // Notepad and some VS Code configurations save UTF-8 with a BOM. JSON.parse
67
- // rejects it with a bare `Unexpected token`, so strip it and name the file
68
- // on failure instead of leaving the user to guess which manifest broke.
69
- const text = String(fs.readFileSync(manifestPath, 'utf8')).replace(/^\uFEFF/u, '').trim();
88
+ const raw = String(fs.readFileSync(manifestPath, 'utf8'));
89
+ const text = stripBom(raw).trim();
70
90
  let manifest;
71
91
  try {
72
92
  manifest = JSON.parse(text);
73
93
  } catch (error) {
74
94
  throw new Error(`${manifestPath} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
75
95
  }
96
+ return { manifest, manifestPath, raw, target };
97
+ }
98
+
99
+ export function readManifest(dir) {
100
+ const { manifest, manifestPath } = readManifestSource(dir);
76
101
  return { manifest, manifestPath };
77
102
  }
78
103
 
package/lib/fix.mjs CHANGED
@@ -16,7 +16,7 @@ import fs from 'node:fs';
16
16
  import path from 'node:path';
17
17
 
18
18
  import { hostRangePlan, satisfiesRange } from './compat.mjs';
19
- import { checkHostRange, doctor, hostRange } from './doctor.mjs';
19
+ import { checkHostRange, doctor, hostRange, readManifestSource, stripBom } from './doctor.mjs';
20
20
  import { resolvePath } from './paths.mjs';
21
21
 
22
22
  /** The oldest host the toolkit itself supports, and the range `init` writes. */
@@ -147,12 +147,23 @@ function formatting(raw) {
147
147
  * prints is the edit the local command would make.
148
148
  */
149
149
  export function renderManifest(manifest, raw) {
150
- const { indent, eol, trailing } = formatting(raw);
150
+ const { indent, eol, trailing } = formatting(stripBom(raw));
151
151
  let text = JSON.stringify(manifest, null, indent);
152
152
  if (eol === '\r\n') text = text.replace(/\n/g, '\r\n');
153
153
  return `${text}${trailing}`;
154
154
  }
155
155
 
156
+ /**
157
+ * Write the one manifest both repair entry points edit.
158
+ *
159
+ * Rendering starts from the parsed JSON value and from the BOM-stripped source,
160
+ * so the BOM `readManifestSource` removed is never written back. Both commands
161
+ * use this helper, which keeps the no-doubled-BOM guarantee in one place.
162
+ */
163
+ function writeManifest({ manifestPath, manifest, raw }) {
164
+ fs.writeFileSync(manifestPath, renderManifest(manifest, raw));
165
+ }
166
+
156
167
  /** Split text for a diff without inventing a final empty line. */
157
168
  function diffLines(text) {
158
169
  const normalized = String(text).replace(/\r\n/gu, '\n');
@@ -266,10 +277,13 @@ export function fixEngines({ dir = '.', range, host, write = false, force = fals
266
277
  let raw;
267
278
  let manifest;
268
279
  try {
269
- raw = fs.readFileSync(manifestPath, 'utf8');
270
- manifest = JSON.parse(raw);
280
+ // Read through the same BOM-aware path `doctor` used to plan this edit.
281
+ // Parsing the raw file here would reject the very manifest the plan named.
282
+ const source = readManifestSource(target);
283
+ raw = source.raw;
284
+ manifest = source.manifest;
271
285
  } catch (error) {
272
- return failure('manifest', `cannot read ${manifestPath}: ${error instanceof Error ? error.message : String(error)}`);
286
+ return failure('manifest', error instanceof Error ? error.message : String(error));
273
287
  }
274
288
  if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest) === true) {
275
289
  return failure('manifest', `${manifestPath} does not hold a JSON object`);
@@ -296,12 +310,17 @@ export function fixEngines({ dir = '.', range, host, write = false, force = fals
296
310
  };
297
311
  }
298
312
 
299
- const content = renderManifest(planned.manifest, raw);
300
-
301
313
  let written = false;
302
314
  if (write === true) {
303
- fs.writeFileSync(manifestPath, content);
304
- written = true;
315
+ try {
316
+ writeManifest({ manifestPath, manifest: planned.manifest, raw });
317
+ written = true;
318
+ } catch (error) {
319
+ return failure(
320
+ 'manifest',
321
+ `cannot write ${manifestPath}: ${error instanceof Error ? error.message : String(error)}`,
322
+ );
323
+ }
305
324
  }
306
325
 
307
326
  return {
@@ -477,10 +496,11 @@ export function doctorFix({ dir = '.', range, host, write = false, dryRun = fals
477
496
  const files = [];
478
497
  if (write === true && dryRun !== true && manifestEdits.length > 0) {
479
498
  try {
480
- const raw = fs.readFileSync(planned.manifestPath, 'utf8');
481
- const next = JSON.parse(raw);
482
- for (const entry of manifestEdits) setField(next, entry.field, entry.after);
483
- fs.writeFileSync(planned.manifestPath, renderManifest(next, raw));
499
+ // The plan was made from the BOM-aware read; use the same source here so
500
+ // a manifest `doctor` accepted is not rejected at write time.
501
+ const { raw, manifest } = readManifestSource(planned.dir);
502
+ for (const entry of manifestEdits) setField(manifest, entry.field, entry.after);
503
+ writeManifest({ manifestPath: planned.manifestPath, manifest, raw });
484
504
  files.push(planned.manifestPath);
485
505
  } catch (error) {
486
506
  return failure(
package/lib/release.mjs CHANGED
@@ -81,6 +81,25 @@ export function workingTreeIsClean(dir, run) {
81
81
  return (run ?? ((args) => git(dir, args)))(['status', '--porcelain']) === '';
82
82
  }
83
83
 
84
+ /**
85
+ * True when the index file has a staged, unstaged, or untracked change.
86
+ *
87
+ * "The index already carries the version" and "the index has nothing to
88
+ * commit" are different states: a run without `--pr` writes the entry and
89
+ * leaves it uncommitted, and a later `--pr` run must carry that entry into the
90
+ * pull request rather than skipping it as a no-op.
91
+ */
92
+ function indexHasChanges(dir, indexFile, run) {
93
+ try {
94
+ const status = (run ?? ((args) => git(dir, args)))(['status', '--porcelain', '--', indexFile]);
95
+ return status !== '';
96
+ } catch {
97
+ // If git cannot answer, do not claim there is nothing to commit: let the PR
98
+ // sequence report the real failure instead of silently dropping the entry.
99
+ return true;
100
+ }
101
+ }
102
+
84
103
  /** The paths git would carry into the tag, so the message can name them. */
85
104
  export function dirtyPaths(dir, limit = 3, run) {
86
105
  const status = (run ?? ((args) => git(dir, args)))(['status', '--porcelain']);
@@ -278,13 +297,25 @@ export async function release(options) {
278
297
  indexUpdate,
279
298
  };
280
299
 
281
- if (options.pr !== true || indexUpdate === null) return result;
282
-
283
300
  // The index change is one line, but it still needs a branch, a pull request,
284
301
  // a green CI and a merge; doing that by hand is where "forgot to open the PR"
285
302
  // happens.
286
303
  const ghRunner = options.gh ?? defaultGh(indexRoot);
287
304
  const marketGit = options.marketGit ?? (indexRoot === root ? options.git : ((args) => git(indexRoot, args)));
305
+
306
+ if (options.pr !== true || indexUpdate === null) return result;
307
+
308
+ // An unchanged index is the resume path: a previous run already wrote the
309
+ // same version with the same publish time. When that entry is committed there
310
+ // is nothing to commit, so opening a branch would fail at `git commit` and
311
+ // leave a branch behind for a release that is already finished. An entry
312
+ // written by a run without `--pr` is still uncommitted, so it must go through
313
+ // the PR sequence even though this run did not change the file again.
314
+ // Git accepts `/` on every platform; `path.relative` uses `\` on Windows and
315
+ // a backslash in a pathspec is an escape, so normalise before passing it on.
316
+ const indexPathForGit = (path.relative(indexRoot, indexPath) || indexPathFile).split(path.sep).join('/');
317
+ if (indexUpdate.unchanged === true && indexHasChanges(indexRoot, indexPathForGit, marketGit) === false) return result;
318
+
288
319
  const pull = await openIndexPr({
289
320
  dir: indexRoot,
290
321
  git: marketGit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-toolkit",
3
- "version": "0.20.19",
3
+ "version": "0.20.21",
4
4
  "description": "Preflight, release and test DeepSeek Harness plugins: check a folder or any GitHub repository, wait for npm to actually serve the version, and keep the market index honest.",
5
5
  "type": "module",
6
6
  "bin": {