dsh-plugin-toolkit 0.20.29 → 0.20.31
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 +64 -0
- package/README.md +16 -7
- package/lib/cli.mjs +34 -2
- package/lib/fix.mjs +22 -6
- package/lib/remote.mjs +11 -1
- package/lib/verify.mjs +21 -4
- package/package.json +1 -1
- package/scripts/compatibility-sample.mjs +62 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
## 0.20.31
|
|
2
|
+
|
|
3
|
+
- **`index --index` with no path is a usage error, not a silent default.** A
|
|
4
|
+
bare `--index` used to store `undefined`, so the command read
|
|
5
|
+
`./market/index.json` and could exit `0` on an index the caller never named;
|
|
6
|
+
a CI step could therefore go green against the wrong file. The flag parser
|
|
7
|
+
now records the missing value separately, and the CLI exits `2` with
|
|
8
|
+
`--index` named before any index is read. A named path, whether
|
|
9
|
+
`--index market/index.json` or the positional form, still audits that file.
|
|
10
|
+
|
|
11
|
+
- **`verify` also awaits an async client `apply()` on its boot probe.** The
|
|
12
|
+
host half was made safe first; the mounted path then handed the client face a
|
|
13
|
+
bare context without waiting for the returned promise. A client `async
|
|
14
|
+
apply()` that rejected on that context escaped the probe, so the process died
|
|
15
|
+
with an unhandled rejection and a stack trace instead of naming the failure.
|
|
16
|
+
The probe now awaits the same way as the host, so the rejection is a `boot`
|
|
17
|
+
failure naming the error. An async client fixture pins the process boundary,
|
|
18
|
+
and a non-`Error` rejection now reports its value instead of `undefined` or a
|
|
19
|
+
second TypeError from reading `.message`.
|
|
20
|
+
|
|
21
|
+
## 0.20.30
|
|
22
|
+
|
|
23
|
+
- **The compatibility sample is the shipped CLI's output, not a library
|
|
24
|
+
shortcut.** `scripts/compatibility-sample.mjs` used to call `run()` in
|
|
25
|
+
process; it now starts `bin/dsh-plugin.mjs` as a child with a preload that
|
|
26
|
+
answers GitHub from the checked-in `examples/compatibility-sample/` folder.
|
|
27
|
+
The README's `incompatible` block is therefore the executable's stdout, and
|
|
28
|
+
the script fails unless that process exits `1`, so the documented command's
|
|
29
|
+
flag parsing, output formatter and exit-code path are covered by the same
|
|
30
|
+
reproducible sample. The test still compares the script's output with the
|
|
31
|
+
README and fails if the section names a flag the CLI does not document.
|
|
32
|
+
|
|
33
|
+
- **`verify --no-mount` awaits an async host `apply()`, so a rejection is a
|
|
34
|
+
`host apply` failure instead of a printed success followed by a crash.** The
|
|
35
|
+
installed host half was called without `await`; an `async apply()` that threw
|
|
36
|
+
returned a rejected promise, verify printed `ok packed ... imported its host
|
|
37
|
+
half`, and Node then killed the process with an unhandled rejection and a
|
|
38
|
+
`Node.js v...` trace. The call is now awaited inside the same try/catch as the
|
|
39
|
+
synchronous throw, so both report the error message and exit `1` with no
|
|
40
|
+
success line. Checked-in async and sync fixtures pin the process boundary, and
|
|
41
|
+
the module-level test names the `host apply` check.
|
|
42
|
+
|
|
43
|
+
- **`fix --remote --host` rejects a bad version before it reads GitHub.** The
|
|
44
|
+
remote planner used to fetch `package.json` first and only then parse
|
|
45
|
+
`--host`, so `--host 0.3` against an unreachable GitHub reported "cannot
|
|
46
|
+
reach GitHub" instead of the typo, and a reachable run spent the
|
|
47
|
+
unauthenticated API request before exiting `2`. The range/host validation now
|
|
48
|
+
runs before the one GitHub request, from the same helper the local planner
|
|
49
|
+
and the post-read remote plan use, so both report the same message. An
|
|
50
|
+
explicit `--range` that is not a semver range gets the same early rejection.
|
|
51
|
+
Tests pin the sequential values, the invalid range, the leading-`v` control
|
|
52
|
+
that still plans `>=0.3.0 <1.0.0`, and the shipped CLI boundary where no
|
|
53
|
+
request may happen.
|
|
54
|
+
|
|
55
|
+
- **`audit --remote --host` rejects a value that is not a complete DSH
|
|
56
|
+
version.** A typo such as `--host banana`, a range such as `>=0.2.0`, or a
|
|
57
|
+
partial version such as `0.2` used to reach the compatibility parser, which
|
|
58
|
+
answered `unknown` for every repository; an otherwise clean batch then exited
|
|
59
|
+
`0` even though the host question was never answered. The CLI now exits `2`
|
|
60
|
+
with the value named before it reads a `--from` file or contacts GitHub, while
|
|
61
|
+
`v0.2.2` remains a valid version and still reaches the compatibility answer.
|
|
62
|
+
Tests pin the sequential value, the batch-before-file case, the process
|
|
63
|
+
boundary, and the leading-`v` control.
|
|
64
|
+
|
|
1
65
|
## 0.20.29
|
|
2
66
|
|
|
3
67
|
- **The tarball gate covers `examples/*.mjs` as well as `scripts/*.mjs`.** The
|
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; the client half's boot probe is awaited the same way, so an async `apply()` that rejects on the bare context is a `boot` failure. 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 .
|
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
|
|
@@ -131,7 +132,19 @@ function flags(argv) {
|
|
|
131
132
|
parsed.patch = next === undefined || next.startsWith('--') === true ? '' : argv[++index];
|
|
132
133
|
}
|
|
133
134
|
else if (token === '--log') parsed.log = argv[++index];
|
|
134
|
-
else if (token === '--index')
|
|
135
|
+
else if (token === '--index') {
|
|
136
|
+
// A bare `--index` is a missing path, not a request for the default. The
|
|
137
|
+
// `index` command used to fall back to ./market/index.json and exit 0,
|
|
138
|
+
// so a CI step could go green on a different index than the one it
|
|
139
|
+
// named. Remember the missing value apart from the path itself, so the
|
|
140
|
+
// command can stop before reading any index.
|
|
141
|
+
const next = argv[index + 1];
|
|
142
|
+
if (next === undefined || next.startsWith('--') === true) {
|
|
143
|
+
parsed.indexMissing = true;
|
|
144
|
+
} else {
|
|
145
|
+
parsed.index = argv[++index];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
135
148
|
else if (token === '--tag-prefix') parsed.tagPrefix = argv[++index];
|
|
136
149
|
else if (token === '--budget') {
|
|
137
150
|
// A budget of `8m`, `0`, or `-1` is not a wait, and by the time the
|
|
@@ -254,6 +267,15 @@ export async function run(argv, io = console, deps = {}) {
|
|
|
254
267
|
return 0;
|
|
255
268
|
}
|
|
256
269
|
|
|
270
|
+
// `--index` names the file to audit or update. Without a value the `index`
|
|
271
|
+
// command used to read ./market/index.json and exit 0, which let a CI step
|
|
272
|
+
// pass against an index the caller never named. Reject the usage error here,
|
|
273
|
+
// before any command can read or write an index.
|
|
274
|
+
if (options.indexMissing === true || (options.index !== undefined && String(options.index).trim() === '')) {
|
|
275
|
+
io.error('dsh-plugin --index needs a path to an index file, for example: dsh-plugin index market/index.json');
|
|
276
|
+
return 2;
|
|
277
|
+
}
|
|
278
|
+
|
|
257
279
|
// `--host` means a URL for a local audit and a DSH version for a remote one,
|
|
258
280
|
// so a bare flag must stop before either reads anything. Otherwise the audit
|
|
259
281
|
// silently omits the compatibility answer the user asked for.
|
|
@@ -599,6 +621,16 @@ export async function run(argv, io = console, deps = {}) {
|
|
|
599
621
|
io.error(`dsh-plugin audit --jobs: ${error instanceof Error ? error.message : String(error)}`);
|
|
600
622
|
return 2;
|
|
601
623
|
}
|
|
624
|
+
// A remote `--host` is a complete DSH version, not a range or a label.
|
|
625
|
+
// Without this check a typo compared every repository against a version
|
|
626
|
+
// the parser cannot read, answered `unknown`, and could still exit 0 with
|
|
627
|
+
// a clean-looking report. Stop before reading a list file or GitHub.
|
|
628
|
+
if (options.host !== undefined && parseVersion(options.host) === null) {
|
|
629
|
+
io.error(
|
|
630
|
+
`dsh-plugin audit --remote --host needs a complete DSH version such as 0.2.2, got ${JSON.stringify(options.host)}`,
|
|
631
|
+
);
|
|
632
|
+
return 2;
|
|
633
|
+
}
|
|
602
634
|
if (from !== undefined && String(from).trim() === '') {
|
|
603
635
|
io.error('dsh-plugin audit --remote --from needs a file path, or - to read the list from standard input');
|
|
604
636
|
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;
|
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
|
@@ -80,6 +80,16 @@ function undeclaredContext() {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* A rejected `apply()` is not required to reject with an Error. Reading
|
|
85
|
+
* `.message` off a string (or `null`) either reports `undefined` or throws a
|
|
86
|
+
* second TypeError inside the handler, which hides the plugin's own reason.
|
|
87
|
+
*/
|
|
88
|
+
function failureText(error) {
|
|
89
|
+
if (error instanceof Error) return error.message;
|
|
90
|
+
return String(error);
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
/**
|
|
84
94
|
* A declared path can be a pattern: `exports["./locale/*.json"]` names a folder
|
|
85
95
|
* of files, and `npm pack` lists the files it actually shipped. Exact set
|
|
@@ -281,14 +291,18 @@ async function inspectScratch({ dir, mount, report, packed, scratch }) {
|
|
|
281
291
|
// restarts, so the activation itself is checked, not just the import.
|
|
282
292
|
if (hostFace !== null) {
|
|
283
293
|
try {
|
|
284
|
-
|
|
294
|
+
// An `async apply()` rejects after the call returns, so a bare call here
|
|
295
|
+
// used to print the success line and then take the whole CLI down with an
|
|
296
|
+
// unhandled rejection. Awaiting puts a rejecting host half in the same
|
|
297
|
+
// `host apply` failure path as a synchronous throw.
|
|
298
|
+
await hostFace.apply(undeclaredContext());
|
|
285
299
|
} catch (error) {
|
|
286
300
|
return {
|
|
287
301
|
ok: false,
|
|
288
302
|
stage: 'install',
|
|
289
303
|
failures: [{
|
|
290
304
|
check: 'host apply',
|
|
291
|
-
message: `apply() throws when a service it never declared is read, which fails the row: ${error
|
|
305
|
+
message: `apply() throws when a service it never declared is read, which fails the row (a rejecting async apply is awaited the same way): ${failureText(error)}`,
|
|
292
306
|
}],
|
|
293
307
|
files: packed.files,
|
|
294
308
|
};
|
|
@@ -328,9 +342,12 @@ async function inspectScratch({ dir, mount, report, packed, scratch }) {
|
|
|
328
342
|
faceProblems.push('the client module declares no inject list, so the loader calls apply() before its services exist');
|
|
329
343
|
}
|
|
330
344
|
try {
|
|
331
|
-
|
|
345
|
+
// An async client `apply()` rejects after the call returns, exactly like
|
|
346
|
+
// the host half. Awaiting it here keeps a late rejection inside this
|
|
347
|
+
// probe instead of letting it kill the process after the success line.
|
|
348
|
+
await face.apply(absentContext());
|
|
332
349
|
} catch (error) {
|
|
333
|
-
faceProblems.push(`apply() throws when the services are absent, which fails the web boot: ${error
|
|
350
|
+
faceProblems.push(`apply() throws when the services are absent, which fails the web boot (a rejecting async apply is awaited the same way): ${failureText(error)}`);
|
|
334
351
|
}
|
|
335
352
|
await panel.unmount();
|
|
336
353
|
if (faceProblems.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-toolkit",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.31",
|
|
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": {
|
|
@@ -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());
|