dsh-plugin-toolkit 0.20.12 → 0.20.13
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 +66 -0
- package/README.md +114 -37
- package/examples/compatibility-sample/README.md +11 -2
- package/examples/compatibility-sample/package.json +1 -1
- package/lib/audit.mjs +8 -5
- package/lib/benchmark.mjs +1 -1
- package/lib/cli.mjs +28 -11
- package/lib/compat.mjs +14 -7
- package/lib/dev.mjs +15 -11
- package/lib/doctor.mjs +77 -13
- package/lib/fix.mjs +66 -28
- package/lib/github.mjs +4 -3
- package/lib/index-file.mjs +3 -2
- package/lib/init.mjs +8 -3
- package/lib/paths.mjs +38 -0
- package/lib/release.mjs +27 -15
- package/lib/remote.mjs +39 -49
- package/lib/verify.mjs +7 -5
- package/package.json +1 -1
package/lib/remote.mjs
CHANGED
|
@@ -14,20 +14,23 @@
|
|
|
14
14
|
* network call is injectable so the tests never touch GitHub.
|
|
15
15
|
*/
|
|
16
16
|
import fs from 'node:fs';
|
|
17
|
-
import os from 'node:os';
|
|
18
17
|
import path from 'node:path';
|
|
19
18
|
|
|
19
|
+
import { expandHome } from './paths.mjs';
|
|
20
20
|
import {
|
|
21
|
+
checkDshField,
|
|
21
22
|
checkFilesList,
|
|
22
23
|
checkHostCompatibility,
|
|
23
24
|
checkHostRange,
|
|
25
|
+
checkName,
|
|
26
|
+
checkReadmeText,
|
|
24
27
|
checkVersion,
|
|
25
28
|
exportTarget,
|
|
26
29
|
exportsApply,
|
|
27
30
|
hostRange,
|
|
28
31
|
rootEntry,
|
|
29
32
|
} from './doctor.mjs';
|
|
30
|
-
import {
|
|
33
|
+
import { planEnginesEdit, renderManifest, unifiedDiff } from './fix.mjs';
|
|
31
34
|
import { parseTarget as classifyTarget } from './github.mjs';
|
|
32
35
|
|
|
33
36
|
const API = 'https://api.github.com';
|
|
@@ -116,25 +119,9 @@ function resetSentence(info) {
|
|
|
116
119
|
*/
|
|
117
120
|
const UNREADABLE = Symbol('unreadable');
|
|
118
121
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* `--patch ~/repair.patch` is the obvious way to write the example, and on
|
|
123
|
-
* Windows `cmd`/PowerShell leave the tilde alone, so `path.resolve('~/x')`
|
|
124
|
-
* quietly creates a directory literally named `~` inside the current working
|
|
125
|
-
* directory. Expanding here keeps the documented example working on every
|
|
126
|
-
* platform the plugin runs on.
|
|
127
|
-
*/
|
|
128
|
-
export function expandHome(value, home = os.homedir()) {
|
|
129
|
-
const text = String(value ?? '').trim();
|
|
130
|
-
if (text === '' || /^~($|[\\/])/u.test(text) === false) {
|
|
131
|
-
return text;
|
|
132
|
-
}
|
|
133
|
-
// `~\x` only ever means the Windows spelling of a child path, so treat
|
|
134
|
-
// both separators as separators here; path.join then uses the host one.
|
|
135
|
-
const rest = text.slice(1).replace(/^[\\/]+/u, '').split(/[\\/]+/u).join('/');
|
|
136
|
-
return path.join(home, rest);
|
|
137
|
-
}
|
|
122
|
+
// `expandHome` used to live here, and the path tests import it from this
|
|
123
|
+
// module. Keep that export while the shared implementation lives in paths.mjs.
|
|
124
|
+
export { expandHome };
|
|
138
125
|
|
|
139
126
|
|
|
140
127
|
/**
|
|
@@ -370,9 +357,15 @@ export async function auditRemote(
|
|
|
370
357
|
});
|
|
371
358
|
}
|
|
372
359
|
|
|
360
|
+
checked.push(['name', checkName(manifest)]);
|
|
373
361
|
checked.push(['version', checkVersion(manifest)]);
|
|
374
362
|
const enginesCheck = checkHostRange(manifest);
|
|
375
363
|
checked.push(['engines.dsh', enginesCheck]);
|
|
364
|
+
// `doctor` reads this field before it looks at the tree: a manifest with
|
|
365
|
+
// `dsh: {}` has no patch for the host to load, and the file checks below only
|
|
366
|
+
// find a missing patch when one is declared. Run the same manifest-only check
|
|
367
|
+
// here so a remote repository cannot pass with an empty `dsh` field.
|
|
368
|
+
checked.push(['dsh field', checkDshField(manifest)]);
|
|
376
369
|
checked.push(['files list', checkFilesList(manifest)]);
|
|
377
370
|
for (const [check, message] of checked) if (typeof message === 'string' && message.length > 0) fail(check, message);
|
|
378
371
|
|
|
@@ -455,8 +448,18 @@ export async function auditRemote(
|
|
|
455
448
|
}
|
|
456
449
|
}
|
|
457
450
|
|
|
451
|
+
// `doctor` reads the README text too: a repository can have a README with no
|
|
452
|
+
// Requirements section, or one that omits the host range it declares. Ask the
|
|
453
|
+
// same questions here so the remote verdict matches a checkout. A fallback
|
|
454
|
+
// `README` (no extension) is still read, but the shared message names
|
|
455
|
+
// README.md because that is the file the market convention expects.
|
|
458
456
|
const readme = (await exists('README.md')) ?? (await exists('README'));
|
|
459
|
-
if (readme === null)
|
|
457
|
+
if (readme === null) {
|
|
458
|
+
fail('readme', 'the repository has no README, so a reader cannot tell how to install it or what it needs');
|
|
459
|
+
} else if (readme !== UNREADABLE) {
|
|
460
|
+
const message = checkReadmeText(readme, manifest);
|
|
461
|
+
if (message !== null) fail('readme', message);
|
|
462
|
+
}
|
|
460
463
|
|
|
461
464
|
return withHost({
|
|
462
465
|
target: parsed,
|
|
@@ -506,15 +509,6 @@ export async function fixRemote(
|
|
|
506
509
|
) {
|
|
507
510
|
if (typeof fetchImpl !== 'function') throw new Error('fixRemote needs a fetch implementation');
|
|
508
511
|
const parsed = parseTarget(target);
|
|
509
|
-
const requested = resolveEnginesRange({ range, host });
|
|
510
|
-
if (requested.error !== undefined) {
|
|
511
|
-
throw new Error(requested.error);
|
|
512
|
-
}
|
|
513
|
-
const { proposed } = requested;
|
|
514
|
-
if (isHostRange(proposed) === false) {
|
|
515
|
-
throw new Error(`"${proposed}" is not a semver range, so it would not clear the doctor check`);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
512
|
const patchPath =
|
|
519
513
|
patch === undefined || patch === null || String(patch).trim() === '' ? null : path.resolve(expandHome(patch));
|
|
520
514
|
if (patchPath !== null && overwrite !== true && fs.existsSync(patchPath)) {
|
|
@@ -539,11 +533,12 @@ export async function fixRemote(
|
|
|
539
533
|
throw new Error(`package.json at ${parsed.slug} does not hold a JSON object`);
|
|
540
534
|
}
|
|
541
535
|
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
536
|
+
const planned = planEnginesEdit(manifest, { range, host, force });
|
|
537
|
+
if (planned.ok !== true) {
|
|
538
|
+
throw new Error(planned.failures[0].message);
|
|
539
|
+
}
|
|
540
|
+
const { proposed, current } = planned;
|
|
541
|
+
if (planned.noop === true) {
|
|
547
542
|
return {
|
|
548
543
|
ok: true,
|
|
549
544
|
target: parsed,
|
|
@@ -556,19 +551,14 @@ export async function fixRemote(
|
|
|
556
551
|
patchPath,
|
|
557
552
|
patchWritten: false,
|
|
558
553
|
reason: 'already-correct',
|
|
559
|
-
host:
|
|
560
|
-
nextMajor:
|
|
561
|
-
why:
|
|
554
|
+
host: planned.host,
|
|
555
|
+
nextMajor: planned.nextMajor,
|
|
556
|
+
why: planned.why,
|
|
562
557
|
diff: '',
|
|
563
558
|
};
|
|
564
559
|
}
|
|
565
560
|
|
|
566
|
-
const
|
|
567
|
-
manifest.engines !== null && typeof manifest.engines === 'object' && Array.isArray(manifest.engines) === false
|
|
568
|
-
? manifest.engines
|
|
569
|
-
: {};
|
|
570
|
-
const next = { ...manifest, engines: { ...engines, dsh: proposed } };
|
|
571
|
-
const content = renderManifest(next, raw);
|
|
561
|
+
const content = renderManifest(planned.manifest, raw);
|
|
572
562
|
const diff = unifiedDiff(raw, content, { file: 'package.json' });
|
|
573
563
|
|
|
574
564
|
let patchWritten = false;
|
|
@@ -598,10 +588,10 @@ export async function fixRemote(
|
|
|
598
588
|
written: false,
|
|
599
589
|
patchPath,
|
|
600
590
|
patchWritten,
|
|
601
|
-
reason:
|
|
602
|
-
host:
|
|
603
|
-
nextMajor:
|
|
604
|
-
why:
|
|
591
|
+
reason: planned.reason,
|
|
592
|
+
host: planned.host,
|
|
593
|
+
nextMajor: planned.nextMajor,
|
|
594
|
+
why: planned.why,
|
|
605
595
|
diff,
|
|
606
596
|
};
|
|
607
597
|
}
|
package/lib/verify.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import path from 'node:path';
|
|
|
13
13
|
|
|
14
14
|
import { doctor, declaredPaths, missingDeclaredPaths, rootEntry } from './doctor.mjs';
|
|
15
15
|
import { resolveEntry } from './dev.mjs';
|
|
16
|
+
import { resolvePath } from './paths.mjs';
|
|
16
17
|
import { run } from './exec.mjs';
|
|
17
18
|
|
|
18
19
|
function packJson(dir) {
|
|
@@ -114,7 +115,8 @@ function defersPatchToPack(report) {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
export async function verify({ dir, mount = true }) {
|
|
117
|
-
const
|
|
118
|
+
const root = resolvePath(dir);
|
|
119
|
+
const report = doctor(root);
|
|
118
120
|
if (report.failures.length > 0 && defersPatchToPack(report) === false) {
|
|
119
121
|
return { ok: false, stage: 'doctor', failures: report.failures, files: [] };
|
|
120
122
|
}
|
|
@@ -122,7 +124,7 @@ export async function verify({ dir, mount = true }) {
|
|
|
122
124
|
|
|
123
125
|
let packed;
|
|
124
126
|
try {
|
|
125
|
-
packed = packJson(
|
|
127
|
+
packed = packJson(root);
|
|
126
128
|
} catch (error) {
|
|
127
129
|
return {
|
|
128
130
|
ok: false,
|
|
@@ -145,9 +147,9 @@ export async function verify({ dir, mount = true }) {
|
|
|
145
147
|
}
|
|
146
148
|
// The client bundle is usually found by convention (`client.js`), so it is
|
|
147
149
|
// not in `declaredPaths` — but it still has to be in the tarball.
|
|
148
|
-
const repoEntry = resolveEntry(
|
|
150
|
+
const repoEntry = resolveEntry(root, report.manifest);
|
|
149
151
|
if (repoEntry !== null) {
|
|
150
|
-
const relative = path.relative(
|
|
152
|
+
const relative = path.relative(root, repoEntry).split(path.sep).join('/');
|
|
151
153
|
if (shipsPath(shipped, relative) === false) {
|
|
152
154
|
failures.push({
|
|
153
155
|
check: 'pack',
|
|
@@ -160,7 +162,7 @@ export async function verify({ dir, mount = true }) {
|
|
|
160
162
|
|
|
161
163
|
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-plugin-verify-'));
|
|
162
164
|
try {
|
|
163
|
-
return await inspectScratch({ dir, mount, report, packed, scratch });
|
|
165
|
+
return await inspectScratch({ dir: root, mount, report, packed, scratch });
|
|
164
166
|
} finally {
|
|
165
167
|
// Verify runs repeatedly in CI; leaving a full install tree behind each
|
|
166
168
|
// time fills the runner's disk. Remove it whether the run passed or failed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-toolkit",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.13",
|
|
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": {
|