dsh-plugin-toolkit 0.20.28 → 0.20.30
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 +71 -0
- package/README.md +16 -7
- package/examples/aria.mjs +18 -0
- package/examples/baseline.mjs +14 -0
- package/examples/mount-a-bundle.mjs +16 -0
- package/examples/route-stubs.mjs +19 -0
- package/lib/cli.mjs +12 -1
- package/lib/fix.mjs +22 -6
- package/lib/readme-commands.mjs +43 -0
- package/lib/remote.mjs +11 -1
- package/lib/verify.mjs +6 -2
- package/package.json +7 -3
- package/scripts/compatibility-sample.mjs +62 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,74 @@
|
|
|
1
|
+
## 0.20.30
|
|
2
|
+
|
|
3
|
+
- **The compatibility sample is the shipped CLI's output, not a library
|
|
4
|
+
shortcut.** `scripts/compatibility-sample.mjs` used to call `run()` in
|
|
5
|
+
process; it now starts `bin/dsh-plugin.mjs` as a child with a preload that
|
|
6
|
+
answers GitHub from the checked-in `examples/compatibility-sample/` folder.
|
|
7
|
+
The README's `incompatible` block is therefore the executable's stdout, and
|
|
8
|
+
the script fails unless that process exits `1`, so the documented command's
|
|
9
|
+
flag parsing, output formatter and exit-code path are covered by the same
|
|
10
|
+
reproducible sample. The test still compares the script's output with the
|
|
11
|
+
README and fails if the section names a flag the CLI does not document.
|
|
12
|
+
|
|
13
|
+
- **`verify --no-mount` awaits an async host `apply()`, so a rejection is a
|
|
14
|
+
`host apply` failure instead of a printed success followed by a crash.** The
|
|
15
|
+
installed host half was called without `await`; an `async apply()` that threw
|
|
16
|
+
returned a rejected promise, verify printed `ok packed ... imported its host
|
|
17
|
+
half`, and Node then killed the process with an unhandled rejection and a
|
|
18
|
+
`Node.js v...` trace. The call is now awaited inside the same try/catch as the
|
|
19
|
+
synchronous throw, so both report the error message and exit `1` with no
|
|
20
|
+
success line. Checked-in async and sync fixtures pin the process boundary, and
|
|
21
|
+
the module-level test names the `host apply` check.
|
|
22
|
+
|
|
23
|
+
- **`fix --remote --host` rejects a bad version before it reads GitHub.** The
|
|
24
|
+
remote planner used to fetch `package.json` first and only then parse
|
|
25
|
+
`--host`, so `--host 0.3` against an unreachable GitHub reported "cannot
|
|
26
|
+
reach GitHub" instead of the typo, and a reachable run spent the
|
|
27
|
+
unauthenticated API request before exiting `2`. The range/host validation now
|
|
28
|
+
runs before the one GitHub request, from the same helper the local planner
|
|
29
|
+
and the post-read remote plan use, so both report the same message. An
|
|
30
|
+
explicit `--range` that is not a semver range gets the same early rejection.
|
|
31
|
+
Tests pin the sequential values, the invalid range, the leading-`v` control
|
|
32
|
+
that still plans `>=0.3.0 <1.0.0`, and the shipped CLI boundary where no
|
|
33
|
+
request may happen.
|
|
34
|
+
|
|
35
|
+
- **`audit --remote --host` rejects a value that is not a complete DSH
|
|
36
|
+
version.** A typo such as `--host banana`, a range such as `>=0.2.0`, or a
|
|
37
|
+
partial version such as `0.2` used to reach the compatibility parser, which
|
|
38
|
+
answered `unknown` for every repository; an otherwise clean batch then exited
|
|
39
|
+
`0` even though the host question was never answered. The CLI now exits `2`
|
|
40
|
+
with the value named before it reads a `--from` file or contacts GitHub, while
|
|
41
|
+
`v0.2.2` remains a valid version and still reaches the compatibility answer.
|
|
42
|
+
Tests pin the sequential value, the batch-before-file case, the process
|
|
43
|
+
boundary, and the leading-`v` control.
|
|
44
|
+
|
|
45
|
+
## 0.20.29
|
|
46
|
+
|
|
47
|
+
- **The tarball gate covers `examples/*.mjs` as well as `scripts/*.mjs`.** The
|
|
48
|
+
gate reads every `node <path>` command from `README.md` and `README.zh.md`,
|
|
49
|
+
compares the paths with `npm pack --dry-run --json` and with the published
|
|
50
|
+
`files` list, and names every missing path. Replaying the 0.20.12 file list
|
|
51
|
+
fails with the four example paths and `scripts/preview.mjs`; the current list
|
|
52
|
+
passes, so a future `files` edit that drops either kind of documented command
|
|
53
|
+
is caught before publication.
|
|
54
|
+
|
|
55
|
+
- **A fresh install ships the four `node examples/*.mjs` commands its README
|
|
56
|
+
cites.** `files` listed only `examples/compatibility-sample/`, so the four
|
|
57
|
+
testkit examples worked in a checkout and were absent after `npm pack` +
|
|
58
|
+
`npm install`. The published file list now names `mount-a-bundle.mjs`,
|
|
59
|
+
`route-stubs.mjs`, `baseline.mjs` and `aria.mjs`. A regression test reads the
|
|
60
|
+
commands from the shipped READMEs, packs and installs the tarball into a temp
|
|
61
|
+
prefix, and requires each installed example to exist and match the repository
|
|
62
|
+
byte for byte.
|
|
63
|
+
|
|
64
|
+
- **The BOM acceptance cases run through the real CLI.** Three checked-in
|
|
65
|
+
fixtures (`readme-plain`, `readme-bom`, `readme-bom-no-heading`) turn the
|
|
66
|
+
documented behavior into commands: the first two exit `0` with `ok`, and the
|
|
67
|
+
third exits `1` with the `readme` failure. The test asserts each fixture
|
|
68
|
+
README really does (or does not) start with U+FEFF before spawning
|
|
69
|
+
`bin/dsh-plugin.mjs doctor`, so a fixture that lost its BOM cannot make the
|
|
70
|
+
test pass for the wrong reason.
|
|
71
|
+
|
|
1
72
|
## 0.20.28
|
|
2
73
|
|
|
3
74
|
- **`doctor` reads a README saved with a UTF-8 BOM instead of calling its
|
package/README.md
CHANGED
|
@@ -464,7 +464,7 @@ verdict, and the remaining entries are reported without another request.
|
|
|
464
464
|
|
|
465
465
|
### Will this plugin install on my DSH?
|
|
466
466
|
|
|
467
|
-
The
|
|
467
|
+
The fifteen compatibility reports, from four repositories, all end with the same
|
|
468
468
|
question. Add `--host <version>` to a remote audit and it answers that question
|
|
469
469
|
for one repository. This is the output for `L3n3L/dsh-resume`, a real plugin
|
|
470
470
|
whose declared range stops before DSH 0.2.0, checked against the
|
|
@@ -490,9 +490,12 @@ real CLI path:
|
|
|
490
490
|
$ node scripts/compatibility-sample.mjs
|
|
491
491
|
```
|
|
492
492
|
|
|
493
|
-
(`npm run compatibility` runs the same script.) The
|
|
494
|
-
|
|
495
|
-
|
|
493
|
+
(`npm run compatibility` runs the same script.) The script starts the shipped
|
|
494
|
+
`bin/dsh-plugin.mjs` as a child process and answers its GitHub reads from the
|
|
495
|
+
checked-in folder, so the block above is that executable's stdout rather than a
|
|
496
|
+
library shortcut; it exits `0` only after the replayed command exited `1`. The
|
|
497
|
+
test suite runs the script and compares its output with the block above, so the
|
|
498
|
+
sample cannot drift from the flag parser, the formatter, or the README. Running
|
|
496
499
|
`dsh-plugin audit --remote L3n3L/dsh-resume --host 0.2.2-alpha.3` without the
|
|
497
500
|
sample audits the repository's current default branch instead; a README or
|
|
498
501
|
manifest change since 0.1.3 can add another `readme` or manifest failure to the
|
|
@@ -520,7 +523,10 @@ host-targeted repair for each repository that needs one. The help text lists
|
|
|
520
523
|
the same flags; a test fails if this section names a flag the CLI does not have.
|
|
521
524
|
A bare `--host` is a usage error, not an audit without the comparison: the
|
|
522
525
|
command exits `2` before it reads GitHub, and `--host --json` does not consume
|
|
523
|
-
the `--json` flag as a version.
|
|
526
|
+
the `--json` flag as a version. The value itself must be a complete version
|
|
527
|
+
(`0.2.2`, `v0.2.2`, or `0.2.2-alpha.3`): a range (`>=0.2.0`), a partial version
|
|
528
|
+
(`0.2`), or a tag name is rejected with exit `2` before any repository is read,
|
|
529
|
+
so a typo cannot turn into a clean-looking `unknown` row.
|
|
524
530
|
|
|
525
531
|
`--host` still names the running app URL for a local `audit`; on `--remote` it
|
|
526
532
|
is the DSH version to compare against. With `--json`, each finding gains
|
|
@@ -853,7 +859,10 @@ is still untouched. The same host-aware plan works with `--patch`:
|
|
|
853
859
|
`>=0.3.0 <1.0.0` and prints why. After cloning, `fix . --engines --host 0.3.0
|
|
854
860
|
--write` applies that same range; either path writes one that accepts the host
|
|
855
861
|
and rejects the next major. The remote reader strips a UTF-8 BOM, so a manifest
|
|
856
|
-
saved on Windows gives the same plan and the patch removes the BOM too.
|
|
862
|
+
saved on Windows gives the same plan and the patch removes the BOM too. A
|
|
863
|
+
`--host` or `--range` the planner cannot parse is refused before the GitHub
|
|
864
|
+
read, so a typo names the flag instead of looking like a network failure or
|
|
865
|
+
spending the unauthenticated request quota. `audit --remote --host <version> --patch-dir <dir>`
|
|
857
866
|
writes host-targeted repairs for a whole list. `git apply --check` is the dry
|
|
858
867
|
run: it fails before changing anything if the manifest moved since the diff was
|
|
859
868
|
printed. Commit the applied change as you would any other edit.
|
|
@@ -939,7 +948,7 @@ ok packed 5 file(s), installed the tarball, mounted the panel
|
|
|
939
948
|
My panel This panel came from dsh-plugin init. Clicks: 0
|
|
940
949
|
```
|
|
941
950
|
|
|
942
|
-
It packs, installs that tarball into a throwaway directory, then mounts the bundle **from the installed copy**. The host half is imported by the package's bare name, exactly as the loader imports it, so an `exports` map with no `.` entry fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` even when `main` names a working file; `verify --no-mount` reports that as a `root export` failure naming the missing `.` export. A package that declares neither `exports` nor `main` has no root module at all; there is nothing to import, and the success line says it skipped the host import instead of claiming one ran. When the `files` list drops the panel:
|
|
951
|
+
It packs, installs that tarball into a throwaway directory, then mounts the bundle **from the installed copy**. The host half is imported by the package's bare name, exactly as the loader imports it, so an `exports` map with no `.` entry fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` even when `main` names a working file; `verify --no-mount` reports that as a `root export` failure naming the missing `.` export. The host half is also called and awaited, so an `async apply()` that rejects is reported as a `host apply` failure instead of printing the success line and then crashing with an unhandled rejection. A package that declares neither `exports` nor `main` has no root module at all; there is nothing to import, and the success line says it skipped the host import instead of claiming one ran. When the `files` list drops the panel:
|
|
943
952
|
|
|
944
953
|
```sh
|
|
945
954
|
$ npx dsh-plugin-toolkit verify .
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What assistive tech sees, asserted the same way the rest of the panel is.
|
|
3
|
+
*
|
|
4
|
+
* Run: node examples/aria.mjs
|
|
5
|
+
*/
|
|
6
|
+
import { mountClient } from 'dsh-plugin-toolkit/testkit';
|
|
7
|
+
|
|
8
|
+
const panel = await mountClient({ file: 'fixtures/client-bundle/client.js', copy: { demo: { title: 'Demo' } } });
|
|
9
|
+
|
|
10
|
+
// expectAria names the attribute that differs, so a failure reads like a bug
|
|
11
|
+
// report instead of "expected true to equal false".
|
|
12
|
+
const live = panel.expectAria('[aria-live="polite"]', { live: 'polite', text: '0' });
|
|
13
|
+
console.log(`live region: ${live.live} -> "${live.text}"`);
|
|
14
|
+
|
|
15
|
+
const button = panel.expectAria('[aria-label]', { label: 'increment' });
|
|
16
|
+
console.log(`labelled control: ${button.label}`);
|
|
17
|
+
|
|
18
|
+
await panel.unmount();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A DOM baseline: normalised markup in a file, compared on every run.
|
|
3
|
+
*
|
|
4
|
+
* Run: node examples/baseline.mjs
|
|
5
|
+
* First run writes nothing; re-run with UPDATE_SNAPSHOTS=1 to create the file.
|
|
6
|
+
*/
|
|
7
|
+
import { expectSnapshot, mountClient } from 'dsh-plugin-toolkit/testkit';
|
|
8
|
+
|
|
9
|
+
const panel = await mountClient({ file: 'fixtures/client-bundle/client.js', copy: { demo: { title: 'Demo' } } });
|
|
10
|
+
|
|
11
|
+
const result = expectSnapshot(panel.html(), 'fixtures/client-bundle/__snapshots__', 'panel');
|
|
12
|
+
console.log(`baseline: ${result.status}`);
|
|
13
|
+
|
|
14
|
+
await panel.unmount();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shortest useful thing testkit does: mount a real client bundle and read
|
|
3
|
+
* what a user would see.
|
|
4
|
+
*
|
|
5
|
+
* Run: node examples/mount-a-bundle.mjs
|
|
6
|
+
*/
|
|
7
|
+
import { mountClient } from 'dsh-plugin-toolkit/testkit';
|
|
8
|
+
|
|
9
|
+
const panel = await mountClient({ file: 'fixtures/client-bundle/client.js', copy: { demo: { title: 'Demo' } } });
|
|
10
|
+
|
|
11
|
+
console.log(panel.text());
|
|
12
|
+
|
|
13
|
+
await panel.click('[data-testid="inc"]');
|
|
14
|
+
console.log(panel.text());
|
|
15
|
+
|
|
16
|
+
await panel.unmount();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A panel that talks to its host: answer the routes it asks for, then assert on
|
|
3
|
+
* what it did — including the requests themselves.
|
|
4
|
+
*
|
|
5
|
+
* Run: node examples/route-stubs.mjs
|
|
6
|
+
*/
|
|
7
|
+
import { createFetch, mountClient } from 'dsh-plugin-toolkit/testkit';
|
|
8
|
+
|
|
9
|
+
const stub = createFetch({
|
|
10
|
+
'/demo/report': { body: { score: 71 } },
|
|
11
|
+
'/demo/apply': () => ({ status: 201, body: { score: 92 } }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const panel = await mountClient({ file: 'fixtures/fetching-bundle/client.js', fetch: stub });
|
|
15
|
+
|
|
16
|
+
console.log(panel.text());
|
|
17
|
+
console.log(`asked for: ${stub.calls('/demo/report').length} route(s), undeclared route answers ${(await stub('/demo/nothing')).status}`);
|
|
18
|
+
|
|
19
|
+
await panel.unmount();
|
package/lib/cli.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
|
|
9
|
+
import { parseVersion } from './compat.mjs';
|
|
9
10
|
import { doctor } from './doctor.mjs';
|
|
10
11
|
import { DEFAULT_ENGINES, doctorFix, fixEngines } from './fix.mjs';
|
|
11
12
|
import { auditRemote, fixRemote } from './remote.mjs';
|
|
@@ -99,7 +100,7 @@ Flags
|
|
|
99
100
|
--from <file> with audit --remote: read owner/repo entries from <file>, one per line; - means standard input
|
|
100
101
|
--jobs <n> with audit --remote: read n repositories at once, default 4, capped at 8
|
|
101
102
|
--patch-dir <dir> with audit --remote: write one .patch per repository that needs a repair
|
|
102
|
-
--host <value> with audit: the running app URL; with audit --remote or fix: the DSH version to compare or aim at
|
|
103
|
+
--host <value> with audit: the running app URL; with audit --remote or fix: the complete DSH version to compare against or aim at
|
|
103
104
|
--json with audit --remote: print the findings as JSON, one object per repository
|
|
104
105
|
--index <path> index file, default market/index.json
|
|
105
106
|
--market <dir> with release: a checkout of the repository that holds the index
|
|
@@ -599,6 +600,16 @@ export async function run(argv, io = console, deps = {}) {
|
|
|
599
600
|
io.error(`dsh-plugin audit --jobs: ${error instanceof Error ? error.message : String(error)}`);
|
|
600
601
|
return 2;
|
|
601
602
|
}
|
|
603
|
+
// A remote `--host` is a complete DSH version, not a range or a label.
|
|
604
|
+
// Without this check a typo compared every repository against a version
|
|
605
|
+
// the parser cannot read, answered `unknown`, and could still exit 0 with
|
|
606
|
+
// a clean-looking report. Stop before reading a list file or GitHub.
|
|
607
|
+
if (options.host !== undefined && parseVersion(options.host) === null) {
|
|
608
|
+
io.error(
|
|
609
|
+
`dsh-plugin audit --remote --host needs a complete DSH version such as 0.2.2, got ${JSON.stringify(options.host)}`,
|
|
610
|
+
);
|
|
611
|
+
return 2;
|
|
612
|
+
}
|
|
602
613
|
if (from !== undefined && String(from).trim() === '') {
|
|
603
614
|
io.error('dsh-plugin audit --remote --from needs a file path, or - to read the list from standard input');
|
|
604
615
|
return 2;
|
package/lib/fix.mjs
CHANGED
|
@@ -83,6 +83,25 @@ function failure(check, message) {
|
|
|
83
83
|
return { ok: false, failures: [{ check, message }] };
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Validate `--range` and `--host` without reading a manifest.
|
|
88
|
+
*
|
|
89
|
+
* `fix --remote` calls this before its one GitHub request, so a typo in either
|
|
90
|
+
* flag is a usage error even when the network is down or rate-limited. The
|
|
91
|
+
* check is the same one `planEnginesEdit` runs after the read, which keeps the
|
|
92
|
+
* two entry points reporting one message for one bad value.
|
|
93
|
+
*/
|
|
94
|
+
export function validateEnginesRequest({ range, host } = {}) {
|
|
95
|
+
const requested = resolveEnginesRange({ range, host });
|
|
96
|
+
if (requested.error !== undefined) {
|
|
97
|
+
return failure('host', requested.error);
|
|
98
|
+
}
|
|
99
|
+
if (isHostRange(requested.proposed) === false) {
|
|
100
|
+
return failure('engines.dsh', `"${requested.proposed}" is not a semver range, so it would not clear the doctor check`);
|
|
101
|
+
}
|
|
102
|
+
return { ok: true, ...requested };
|
|
103
|
+
}
|
|
104
|
+
|
|
86
105
|
/**
|
|
87
106
|
* Decide what the `engines.dsh` edit should be for one manifest.
|
|
88
107
|
*
|
|
@@ -93,14 +112,11 @@ function failure(check, message) {
|
|
|
93
112
|
* ask for a replacement.
|
|
94
113
|
*/
|
|
95
114
|
export function planEnginesEdit(manifest, { range, host, force = false } = {}) {
|
|
96
|
-
const requested =
|
|
97
|
-
if (requested.
|
|
98
|
-
return
|
|
115
|
+
const requested = validateEnginesRequest({ range, host });
|
|
116
|
+
if (requested.ok !== true) {
|
|
117
|
+
return requested;
|
|
99
118
|
}
|
|
100
119
|
const { proposed } = requested;
|
|
101
|
-
if (isHostRange(proposed) === false) {
|
|
102
|
-
return failure('engines.dsh', `"${proposed}" is not a semver range, so it would not clear the doctor check`);
|
|
103
|
-
}
|
|
104
120
|
|
|
105
121
|
const current = hostRange(manifest);
|
|
106
122
|
const correct = current !== null && checkHostRange(manifest) === null;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `node <path>` command printed in a shipped README is a promise about the
|
|
3
|
+
* installed package. The READMEs are in `files`, but the paths they name are
|
|
4
|
+
* not automatically packed: `scripts/preview.mjs` and the four
|
|
5
|
+
* `examples/*.mjs` commands were documented while `files` left them out.
|
|
6
|
+
*
|
|
7
|
+
* The tarball gate reads the promise from the shipped READMEs instead of a
|
|
8
|
+
* copy in the test, so a command added to a README and a path dropped from
|
|
9
|
+
* `files` cannot drift apart between releases.
|
|
10
|
+
*/
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
|
|
14
|
+
// Both READMEs are in the published file list. A command documented only in
|
|
15
|
+
// the Chinese README is still a command an installed reader can try to run.
|
|
16
|
+
export const SHIPPED_READMES = ['README.md', 'README.zh.md'];
|
|
17
|
+
|
|
18
|
+
// Examples may live below a folder (examples/compatibility-sample/...); keep
|
|
19
|
+
// the capture broad enough for a nested path but restricted to the two
|
|
20
|
+
// directories the toolkit actually documents as runnable commands.
|
|
21
|
+
export const RUN_COMMAND = /\bnode\s+((?:scripts|examples)\/[A-Za-z0-9._/-]+\.mjs)\b/gu;
|
|
22
|
+
|
|
23
|
+
/** Every distinct runnable path the shipped READMEs tell a reader to pass to node. */
|
|
24
|
+
export function documentedRunCommands(root, readmes = SHIPPED_READMES) {
|
|
25
|
+
const found = new Map();
|
|
26
|
+
for (const readme of readmes) {
|
|
27
|
+
const file = path.join(root, readme);
|
|
28
|
+
if (fs.existsSync(file) === false) continue;
|
|
29
|
+
// A Windows checkout writes README.md with CRLF; the command is text, so
|
|
30
|
+
// normalize before matching the line a reader copies.
|
|
31
|
+
const text = fs.readFileSync(file, 'utf8').replace(/\r\n/gu, '\n');
|
|
32
|
+
for (const match of text.matchAll(RUN_COMMAND)) {
|
|
33
|
+
if (found.has(match[1]) === false) found.set(match[1], readme);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Documented paths that the given shipped-file list does not contain. */
|
|
40
|
+
export function missingRunCommands(documented, shipped) {
|
|
41
|
+
const files = new Set(shipped);
|
|
42
|
+
return [...documented.keys()].filter((command) => files.has(command) === false).sort();
|
|
43
|
+
}
|
package/lib/remote.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
rootEntry,
|
|
32
32
|
stripBom,
|
|
33
33
|
} from './doctor.mjs';
|
|
34
|
-
import { planEnginesEdit, renderManifest, unifiedDiff } from './fix.mjs';
|
|
34
|
+
import { planEnginesEdit, renderManifest, unifiedDiff, validateEnginesRequest } from './fix.mjs';
|
|
35
35
|
import { parseTarget as classifyTarget } from './github.mjs';
|
|
36
36
|
|
|
37
37
|
const API = 'https://api.github.com';
|
|
@@ -513,6 +513,16 @@ export async function fixRemote(
|
|
|
513
513
|
) {
|
|
514
514
|
if (typeof fetchImpl !== 'function') throw new Error('fixRemote needs a fetch implementation');
|
|
515
515
|
const parsed = parseTarget(target);
|
|
516
|
+
|
|
517
|
+
// Validate the flags before the read, not after it. A typo in `--host` used
|
|
518
|
+
// to look like a GitHub outage (or spend the unauthenticated quota) because
|
|
519
|
+
// the manifest was fetched before the version was parsed; the same error
|
|
520
|
+
// must win even when the network is unavailable.
|
|
521
|
+
const requested = validateEnginesRequest({ range, host });
|
|
522
|
+
if (requested.ok !== true) {
|
|
523
|
+
throw new Error(requested.failures[0].message);
|
|
524
|
+
}
|
|
525
|
+
|
|
516
526
|
const patchPath =
|
|
517
527
|
patch === undefined || patch === null || String(patch).trim() === '' ? null : path.resolve(expandHome(patch));
|
|
518
528
|
if (patchPath !== null && overwrite !== true && fs.existsSync(patchPath)) {
|
package/lib/verify.mjs
CHANGED
|
@@ -281,14 +281,18 @@ async function inspectScratch({ dir, mount, report, packed, scratch }) {
|
|
|
281
281
|
// restarts, so the activation itself is checked, not just the import.
|
|
282
282
|
if (hostFace !== null) {
|
|
283
283
|
try {
|
|
284
|
-
|
|
284
|
+
// An `async apply()` rejects after the call returns, so a bare call here
|
|
285
|
+
// used to print the success line and then take the whole CLI down with an
|
|
286
|
+
// unhandled rejection. Awaiting puts a rejecting host half in the same
|
|
287
|
+
// `host apply` failure path as a synchronous throw.
|
|
288
|
+
await hostFace.apply(undeclaredContext());
|
|
285
289
|
} catch (error) {
|
|
286
290
|
return {
|
|
287
291
|
ok: false,
|
|
288
292
|
stage: 'install',
|
|
289
293
|
failures: [{
|
|
290
294
|
check: 'host apply',
|
|
291
|
-
message: `apply() throws when a service it never declared is read, which fails the row: ${error.message}`,
|
|
295
|
+
message: `apply() throws when a service it never declared is read, which fails the row (a rejecting async apply is awaited the same way): ${error.message}`,
|
|
292
296
|
}],
|
|
293
297
|
files: packed.files,
|
|
294
298
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-toolkit",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.30",
|
|
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": {
|
|
@@ -26,10 +26,14 @@
|
|
|
26
26
|
"docs/badge.svg",
|
|
27
27
|
"docs/card.png",
|
|
28
28
|
"docs/ecosystem-audit-2026-11-03.txt",
|
|
29
|
+
"examples/aria.mjs",
|
|
30
|
+
"examples/baseline.mjs",
|
|
31
|
+
"examples/compatibility-sample/",
|
|
32
|
+
"examples/mount-a-bundle.mjs",
|
|
33
|
+
"examples/route-stubs.mjs",
|
|
29
34
|
"scripts/benchmark-audit.mjs",
|
|
30
35
|
"scripts/compatibility-sample.mjs",
|
|
31
|
-
"scripts/preview.mjs"
|
|
32
|
-
"examples/compatibility-sample/"
|
|
36
|
+
"scripts/preview.mjs"
|
|
33
37
|
],
|
|
34
38
|
"engines": {
|
|
35
39
|
"node": ">=18",
|
|
@@ -4,41 +4,50 @@
|
|
|
4
4
|
* GitHub request.
|
|
5
5
|
*
|
|
6
6
|
* `examples/compatibility-sample/package.json` is a checked-in copy of the
|
|
7
|
-
* manifest the README audits.
|
|
8
|
-
* the real `audit --remote
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* manifest the README audits. A preload installs a fake GitHub that serves that
|
|
8
|
+
* folder, then this script runs the real `dsh-plugin audit --remote
|
|
9
|
+
* <owner/repo> --host <version>` process. The quoted line therefore comes from
|
|
10
|
+
* the same executable, flag parser, formatter and exit-code path a reader runs,
|
|
11
|
+
* not from a hand-written example or a library-only shortcut.
|
|
11
12
|
*
|
|
12
13
|
* Run: node scripts/compatibility-sample.mjs
|
|
13
14
|
*/
|
|
15
|
+
import { spawnSync } from 'node:child_process';
|
|
14
16
|
import fs from 'node:fs';
|
|
17
|
+
import os from 'node:os';
|
|
15
18
|
import path from 'node:path';
|
|
16
19
|
import { fileURLToPath } from 'node:url';
|
|
17
20
|
|
|
18
|
-
import { run } from '../lib/cli.mjs';
|
|
19
|
-
|
|
20
21
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
21
|
-
const
|
|
22
|
+
const ROOT = path.join(HERE, '..');
|
|
23
|
+
const SAMPLE = path.join(ROOT, 'examples', 'compatibility-sample');
|
|
24
|
+
const BIN = path.join(ROOT, 'bin', 'dsh-plugin.mjs');
|
|
22
25
|
const TARGET = 'L3n3L/dsh-resume';
|
|
23
26
|
const HOST = '0.2.2-alpha.3';
|
|
24
27
|
|
|
28
|
+
// A CommonJS preload works on every Node version the package supports; an
|
|
29
|
+
// `--import` hook would require a newer Node than `engines` promises.
|
|
30
|
+
const PRELOAD = `
|
|
31
|
+
'use strict';
|
|
32
|
+
const fs = require('node:fs');
|
|
33
|
+
const path = require('node:path');
|
|
34
|
+
|
|
35
|
+
const sample = process.env.DSH_COMPATIBILITY_SAMPLE;
|
|
36
|
+
const target = process.env.DSH_COMPATIBILITY_TARGET;
|
|
37
|
+
|
|
25
38
|
function response(status, body) {
|
|
26
|
-
return {
|
|
27
|
-
ok: status >= 200 && status < 300,
|
|
28
|
-
status,
|
|
29
|
-
json: async () => body,
|
|
30
|
-
};
|
|
39
|
+
return { ok: status >= 200 && status < 300, status, json: async () => body };
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
const match = /^https
|
|
35
|
-
if (match === null ||
|
|
42
|
+
globalThis.fetch = async (url) => {
|
|
43
|
+
const match = /^https:\\/\\/api\\.github\\.com\\/repos\\/([^/]+)\\/([^/]+)\\/contents\\/([^?]+)/u.exec(String(url));
|
|
44
|
+
if (match === null || match[1] + '/' + match[2] !== target) return response(404, { message: 'Not Found' });
|
|
36
45
|
|
|
37
|
-
const file = decodeURIComponent(match[3]).replace(
|
|
38
|
-
const full = path.resolve(
|
|
46
|
+
const file = decodeURIComponent(match[3]).replace(/^\\.\\//u, '');
|
|
47
|
+
const full = path.resolve(sample, file);
|
|
39
48
|
// Keep the fake server inside the checked-in folder, even if a manifest ever
|
|
40
49
|
// points at a path outside it.
|
|
41
|
-
if (full.startsWith(
|
|
50
|
+
if (full.startsWith(sample + path.sep) === false || fs.existsSync(full) === false) {
|
|
42
51
|
return response(404, { message: 'Not Found' });
|
|
43
52
|
}
|
|
44
53
|
if (fs.statSync(full).isFile() === false) return response(404, { message: 'Not Found' });
|
|
@@ -46,19 +55,41 @@ function sampleFetch(url) {
|
|
|
46
55
|
encoding: 'base64',
|
|
47
56
|
content: fs.readFileSync(full).toString('base64'),
|
|
48
57
|
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const lines = [];
|
|
52
|
-
const io = {
|
|
53
|
-
log: (line) => lines.push(String(line)),
|
|
54
|
-
error: (line) => lines.push(String(line)),
|
|
55
58
|
};
|
|
59
|
+
`;
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
function replay() {
|
|
62
|
+
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-compatibility-sample-'));
|
|
63
|
+
const preload = path.join(scratch, 'github-preload.cjs');
|
|
64
|
+
try {
|
|
65
|
+
fs.writeFileSync(preload, PRELOAD);
|
|
66
|
+
const result = spawnSync(
|
|
67
|
+
process.execPath,
|
|
68
|
+
['--require', preload, BIN, 'audit', '--remote', TARGET, '--host', HOST],
|
|
69
|
+
{
|
|
70
|
+
cwd: ROOT,
|
|
71
|
+
encoding: 'utf8',
|
|
72
|
+
env: {
|
|
73
|
+
...process.env,
|
|
74
|
+
DSH_COMPATIBILITY_SAMPLE: SAMPLE,
|
|
75
|
+
DSH_COMPATIBILITY_TARGET: TARGET,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
if (result.error !== undefined) throw result.error;
|
|
80
|
+
const stderr = String(result.stderr ?? '').trim();
|
|
81
|
+
if (result.status !== 1) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`the compatibility sample answered ${result.status ?? 'no status'}; the documented incompatible answer exits 1${
|
|
84
|
+
stderr === '' ? '' : `\n${stderr}`
|
|
85
|
+
}`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
if (stderr !== '') throw new Error(`the compatibility sample wrote to stderr:\n${stderr}`);
|
|
89
|
+
return result.stdout;
|
|
90
|
+
} finally {
|
|
91
|
+
fs.rmSync(scratch, { recursive: true, force: true });
|
|
92
|
+
}
|
|
63
93
|
}
|
|
64
|
-
|
|
94
|
+
|
|
95
|
+
process.stdout.write(replay());
|