dsh-plugin-toolkit 0.20.20 → 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 +16 -0
- package/README.md +3 -1
- package/lib/audit.mjs +12 -7
- package/lib/doctor.mjs +30 -5
- package/lib/fix.mjs +33 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
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
|
+
|
|
1
17
|
## 0.20.20
|
|
2
18
|
|
|
3
19
|
- **A repeated `release --pr` is a no-op when the committed index already
|
package/README.md
CHANGED
|
@@ -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 {
|
|
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
|
-
//
|
|
178
|
-
// is still readable, and
|
|
179
|
-
//
|
|
180
|
-
|
|
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:
|
|
198
|
+
message: error instanceof Error ? error.message : String(error),
|
|
194
199
|
}),
|
|
195
200
|
);
|
|
196
201
|
}
|
package/lib/doctor.mjs
CHANGED
|
@@ -55,7 +55,29 @@ function isRangeExpression(value) {
|
|
|
55
55
|
return parseRange(value) !== null;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
270
|
-
manifest
|
|
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',
|
|
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
|
-
|
|
304
|
-
|
|
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
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-toolkit",
|
|
3
|
-
"version": "0.20.
|
|
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": {
|