dsh-plugin-toolkit 0.20.40 → 0.20.41

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,59 @@
1
+ ## 0.20.41
2
+
3
+ - **`index` rejects an unauditable market index instead of reporting it clean
4
+ or crashing.** A plugin without `versions` disappeared from the audit loop, a
5
+ `versions` string was read as an empty list and exited `0`, and an entry
6
+ without `version` or with a non-SemVer `version` either passed or produced a
7
+ raw TypeError. The command now validates the top-level `plugins` array, each
8
+ plugin's name and `versions` array, and each entry's SemVer `version` before
9
+ reading `engines.dsh`. Every finding exits `1` and names the index file plus
10
+ the plugin, entry position, or version at fault; invalid JSON and a missing
11
+ file name the path too. A valid `market/index.json` still exits `0` with its
12
+ `ok` line. `test/index-shape.test.mjs` pins the four reported shapes, a
13
+ top-level missing `plugins` array, invalid JSON, the valid SemVer controls,
14
+ and the clean CLI path.
15
+ - **`verify` packs before the source-only file checks, so a `prepack`-generated
16
+ `client.js` is no longer rejected.** `doctor` reads the working copy, but npm
17
+ runs `prepack` before it builds the tarball. A plugin that generated its panel
18
+ in that hook was complete after `npm pack` and incomplete before it, so
19
+ `verify --no-mount` stopped at `client entry` / `client declaration` and never
20
+ packed the file it was looking for. Those checks now wait until after the
21
+ pack; a file that is still missing fails at `pack` naming it. Manifest and
22
+ root-export failures still stop before npm is asked, and a `files` list that
23
+ omits a path already on disk still stops at `doctor`. That includes a missing
24
+ `files` list, a `dsh.client.platform` other than `web`, and a client bundle
25
+ shipped without the `dsh.client` declaration or the `./client` export: no
26
+ file hook can add a manifest declaration, so verify reports those at `doctor`
27
+ and does not run the hook. After the pack, `doctor` runs again even when the
28
+ first pass was clean: a hook that writes a `client.js` the manifest never
29
+ declares is rejected instead of passing a panel the host will not serve.
30
+ `test/verify-prepack.test.mjs` spawns the shipped CLI on a generated-client
31
+ fixture, checks `npm pack --dry-run --json` lists `client.js`, keeps a
32
+ control whose `prepack` writes nothing red at `pack`, and covers the
33
+ generated-but-undeclared panel.
34
+ - **`audit --home` refuses an explicit path that is not a directory.** A
35
+ missing path, a regular file and a dangling symlink all made `listInstalled`
36
+ find no `profiles/` below the path, so the command printed "no plugins
37
+ installed in any profile" and exited `0`; a CI gate passed on a profile the
38
+ audit never read. The CLI now stats the resolved path first, exits `2` with
39
+ `--home` and that resolved path in the message, and prints no report. An
40
+ existing empty directory still exits `0` with the empty line, and omitting
41
+ `--home` still scans `~/.dsh`. `test/audit-home-not-directory.test.mjs` pins
42
+ the three invalid shapes at the process boundary plus both controls.
43
+ - **`init --title ""` is refused instead of writing a scaffold whose own test
44
+ does not parse.** An explicit empty (or whitespace-only) title reached the
45
+ template and became `assert.match(panel.text(), //)` in the generated
46
+ `test/panel.test.mjs`; `//` starts a comment, so the first `npm test` in a
47
+ brand-new plugin died with a generated `SyntaxError`. The CLI now exits `2`
48
+ with a message that names `--title` and the default to pass
49
+ (`--title "My panel"`), before it creates the target directory; a direct
50
+ `init()` caller gets the same refusal as a `title` failure and no files are
51
+ written. The template renderer that actually embeds the title refuses it as
52
+ well, so a future caller cannot regenerate the assertion by bypassing the
53
+ CLI. Omitting `--title` still gets the `My panel` template default, and a
54
+ normal title is unchanged. `test/init.test.mjs` covers fresh targets,
55
+ whitespace-only titles, `--force`, and the CLI exit code.
56
+
1
57
  ## 0.20.40
2
58
 
3
59
  - **`doctor`'s subdirectory ignore matcher understands npm extglob patterns.**
package/README.md CHANGED
@@ -80,7 +80,7 @@ npx dsh-plugin-toolkit@latest release . --pr --merge
80
80
 
81
81
  ![Five steps, and the failure each one catches](https://raw.githubusercontent.com/WJDdidi-1/dsh-plugin-toolkit/main/docs/pipeline.svg)
82
82
 
83
- The order matters. Packing first means the check reads the file list npm will publish, not the folder you have. Installing the tarball means the root is imported by its bare specifier — the package name the loader uses — not by a file path taken from `main` or `exports["."]`. Node ignores `main` once `exports` exists, so a package whose `exports` map has no `"."` entry fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` at that step even though the file is present. Mounting means the client bundle is actually executed, in jsdom, with a host that records what it registered.
83
+ The order matters. Packing first means the check reads the file list npm will publish, not the folder you have. Installing the tarball means the root is imported by its bare specifier — the package name the loader uses — not by a file path taken from `main` or `exports["."]`. Node ignores `main` once `exports` exists, so a package whose `exports` map has no `"."` entry fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` at that step even though the file is present. Mounting means the client bundle is actually executed, in jsdom, with a host that records what it registered. Packing first also means a panel built by a `prepack` hook exists when the source checks run: the hook has written it into the folder before `doctor`'s file checks are asked again.
84
84
 
85
85
  Each step exists because a plugin once got past the step before it and still installed into nothing.
86
86
 
@@ -131,7 +131,7 @@ created 8 file(s) in /Users/you/my-panel
131
131
  next: npm install && npm test && npm run doctor
132
132
  ```
133
133
 
134
- What you get is not a snippet: it is a plugin whose `doctor` already passes (`engines.dsh`, the patch file, the `files` list), with a client bundle that registers a sidebar tab, a testkit test for it, and a CI workflow that runs both. `init` refuses a directory that is not empty unless you pass `--force`, and refuses a name npm would refuse — those are the two mistakes that cost the most time later.
134
+ What you get is not a snippet: it is a plugin whose `doctor` already passes (`engines.dsh`, the patch file, the `files` list), with a client bundle that registers a sidebar tab, a testkit test for it, and a CI workflow that runs both. `init` refuses a directory that is not empty unless you pass `--force`, a name npm would refuse, and a blank `--title` (pass one, such as `--title "My panel"`) — mistakes that cost the most time later.
135
135
 
136
136
  Every command that takes a path expands a leading `~` before touching the filesystem. The tool, not the shell, expands `~` for these arguments: `cmd` and PowerShell pass `"~/my-panel"` through literally, while a POSIX shell usually expands it first. `init '~/my-panel' --name my-panel` writes into your home directory (the same files `init ~/my-panel` writes on a POSIX shell), and `doctor '~/my-panel'` reads it back. The Windows spelling `~\my-panel` works too; a directory literally named `~` is never created.
137
137
 
@@ -319,7 +319,12 @@ exit code.
319
319
  `~\.dsh` expand. A bare `--home`, or one followed by another flag such as
320
320
  `--timeout 50` or `--json`, is a missing value rather than a request to scan
321
321
  `$HOME/.dsh` or a folder literally named after the flag: the command exits `2`,
322
- names `--home`, and prints no profile report.
322
+ names `--home`, and prints no profile report. An explicit `--home` must be an
323
+ existing directory: a missing path, a regular file and a dangling symlink each
324
+ exit `2` naming `--home` and the resolved path, instead of printing "no plugins
325
+ installed in any profile" for a home the audit never read. An existing empty
326
+ directory still exits `0` with that line, and omitting `--home` still scans the
327
+ default `~/.dsh`.
323
328
 
324
329
  Without `--host` the loaded column is `?`, because guessing would be worse than
325
330
  saying nothing. Only packages that declare a `dsh` field are audited — the rest of
@@ -401,8 +406,11 @@ forgets `client.js` passes it and fails only after `npm i`.
401
406
  `command: doctor` stops at the manifest checks (fast, no install), and
402
407
  `command: index` audits `market/index.json` instead, failing on any version whose
403
408
  `engines.dsh` is missing or is not a semver range (a malformed value such as
404
- `>=banana`, or a single pinned version such as `0.2.0`, both fail). Pin
405
- `version:` if you would rather not track the latest release.
409
+ `>=banana`, or a single pinned version such as `0.2.0`, both fail). It also
410
+ rejects an index it cannot audit: a missing `plugins` or `versions` array, a
411
+ plugin entry without a name, a version entry without `version`, and a
412
+ non-SemVer `version`. Each failure names the file and the plugin or entry.
413
+ Pin `version:` if you would rather not track the latest release.
406
414
 
407
415
  ## Check a plugin you have not cloned
408
416
 
@@ -751,7 +759,7 @@ the diff in the terminal.
751
759
 
752
760
  The `root export` check is a source check, not an install. `doctor` resolves the module the loader imports — `exports["."]` when it is a string or a conditions object (`default`, `import`, `require`, `node`, `module-sync`), otherwise `main` — then checks that the path is a readable regular file, removes comments and the contents of string, template and regex literals, and looks for a real export. A missing file, a directory and an unreadable file are reported as `root export` failures naming the target instead of being skipped or raising a raw `EISDIR`; on a directory the install would have failed at import too. It accepts `export function apply`, `export async function apply`, `export const apply = ...` (also `let` and `var`), `export { apply }` (including `export { helper as apply }`), `exports.apply = ...`, and an `apply` property in `module.exports = { ... }`. A comment such as `// TODO: export function apply() {}` is not an export, and `doctor` never imports or runs the plugin to decide.
753
761
 
754
- `verify --no-mount` does not reopen the path `doctor` read. It imports the installed package by its bare name, the way the loader does, so Node's `exports` resolution decides. An `exports` map with no `.` entry therefore fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` even when `main` names a working file, and `verify` reports a `root export` failure naming the missing `.` export instead of passing. `verify --no-mount` still runs `doctor` first, so a root the source check already rejects stops at that same check instead of packing. `npm test` spawns the shipped CLI for both commands on the comment-only fixtures and the missing-file, missing-conditions-file, string-root missing-file and directory fixtures, requires every one to exit `1` with a `root export:` line and no raw `EISDIR`, and requires `verify` to report `stopped at doctor` rather than a `pack:` failure. The unmodified scaffold still passes both commands.
762
+ `verify --no-mount` does not reopen the path `doctor` read. It imports the installed package by its bare name, the way the loader does, so Node's `exports` resolution decides. An `exports` map with no `.` entry therefore fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` even when `main` names a working file, and `verify` reports a `root export` failure naming the missing `.` export instead of passing. `verify --no-mount` still runs the manifest and root-export checks before packing, so a root the source check already rejects stops at that same check instead of packing. The checks for files a `prepack` hook can generate — `patch file`, `client entry`, `client declaration`, and a `files` list that names a path not yet on disk — wait until after `npm pack` has run, because the tarball contains what that hook wrote even though the folder did not. If those files are still missing after the pack, `verify` reports the same `doctor` checks. It runs that post-pack pass even when the first was clean, so a hook that writes a `client.js` nothing declares is rejected instead of shipping a panel the host never serves. `npm test` spawns the shipped CLI for both commands on the comment-only fixtures and the missing-file, missing-conditions-file, string-root missing-file and directory fixtures, requires every one to exit `1` with a `root export:` line and no raw `EISDIR`, and requires `verify` to report `stopped at doctor` rather than a `pack:` failure. The unmodified scaffold still passes both commands.
755
763
 
756
764
  Exit code is `0` when the plugin can be installed and `1` when it cannot, so it drops into CI unchanged. `doctor --remote` and `audit --remote` run the same manifest and README checks (`name`, `version`, `engines.dsh`, `dsh field`, `files list`, `readme`) against the `package.json` and README GitHub serves, then check the files the manifest points at, so a bad package name or a README with no Requirements heading is reported before a clone or install. The `name` check is pinned at the process boundary: `npm test` expects the shipped CLI to reject a missing, empty and malformed name (`accepted=0/3`) and to accept a valid plain or scoped control.
757
765
 
package/lib/cli.mjs CHANGED
@@ -11,10 +11,10 @@ import { doctor } from './doctor.mjs';
11
11
  import { DEFAULT_ENGINES, doctorFix, fixEngines, validateEnginesRequest } from './fix.mjs';
12
12
  import { auditRemote, fixRemote } from './remote.mjs';
13
13
  import { expandHome, resolvePath } from './paths.mjs';
14
- import { init } from './init.mjs';
14
+ import { checkTitle, init } from './init.mjs';
15
15
  import { verify } from './verify.mjs';
16
16
  import { plan, release } from './release.mjs';
17
- import { auditVersions, readIndex } from './index-file.mjs';
17
+ import { auditVersions, readIndex, validateIndex } from './index-file.mjs';
18
18
  import { CAUSES, explain, lastCauseLine, verdict } from './explain.mjs';
19
19
 
20
20
  export const HELP = `dsh-plugin — preflight and release DeepSeek Harness plugins
@@ -319,6 +319,29 @@ function remoteTarget(options) {
319
319
  return typeof positional === 'string' ? positional.trim() : '';
320
320
  }
321
321
 
322
+ /**
323
+ * A `--home` that exists but is not a folder is not a profile with no plugins.
324
+ * `listInstalled` would find no `profiles/` below it and the command would
325
+ * print the clean "no plugins installed" line with exit 0, so a CI gate would
326
+ * pass on a path the audit never read. The caller resolves the path first, so
327
+ * the message names the exact folder it tried instead of the literal spelling.
328
+ */
329
+ function profileHomeProblem(home) {
330
+ let stat;
331
+ try {
332
+ stat = fs.statSync(home);
333
+ } catch (error) {
334
+ const detail =
335
+ error?.code === 'ENOENT'
336
+ ? 'the path does not exist'
337
+ : `the path cannot be read (${error?.code ?? 'filesystem error'})`;
338
+ return `dsh-plugin audit --home ${home} is not a directory: ${detail}`;
339
+ }
340
+ if (stat.isDirectory() === true) return null;
341
+ const detail = stat.isFile() === true ? 'the path is a regular file' : 'the path is not a folder';
342
+ return `dsh-plugin audit --home ${home} is not a directory: ${detail}`;
343
+ }
344
+
322
345
  function printFailures(failures, io = console) {
323
346
  for (const failure of failures) {
324
347
  io.error(` ✗ ${failure.check}: ${failure.message}`);
@@ -696,6 +719,14 @@ export async function run(argv, io = console, deps = {}) {
696
719
  io.error('dsh-plugin init: --name <package-name> is required');
697
720
  return 2;
698
721
  }
722
+ // `--title ""` is a supplied-but-blank value, like a blank `--index`: it is
723
+ // invalid usage, so stop before the target directory is created. Library
724
+ // callers get the same refusal from `init()` itself.
725
+ const titleProblem = checkTitle(options.title);
726
+ if (titleProblem !== null) {
727
+ io.error(`dsh-plugin init: ${titleProblem}`);
728
+ return 2;
729
+ }
699
730
  const result = init({ dir, name: options.name, title: options.title, force: options.force === true });
700
731
  if (result.ok !== true) {
701
732
  io.error(`dsh-plugin init: ${result.failures[0].message}`);
@@ -715,9 +746,29 @@ export async function run(argv, io = console, deps = {}) {
715
746
  ? dir
716
747
  : path.join(dir, 'market/index.json')
717
748
  : resolvePath(options.index);
718
- const index = readIndex(target);
749
+ let index;
750
+ try {
751
+ index = readIndex(target);
752
+ } catch (error) {
753
+ // A missing file or invalid JSON is a failure of the named index, not a
754
+ // stack trace from JSON.parse. Name the path so a CI log says which file
755
+ // the command could not audit.
756
+ io.error(`dsh-plugin index: ${target}: ${error instanceof Error ? error.message : String(error)}`);
757
+ return 1;
758
+ }
759
+
760
+ // Shape first: auditVersions() assumes a plugin has an array of version
761
+ // objects. Without this pass, a missing `versions` looked like a clean
762
+ // empty list and a missing `version` produced a raw TypeError.
763
+ const shapeFindings = validateIndex(index);
764
+ if (shapeFindings.length > 0) {
765
+ io.error(`dsh-plugin index: ${target}`);
766
+ for (const finding of shapeFindings) io.error(` ✗ ${finding.entry}: ${finding.problem}`);
767
+ return 1;
768
+ }
769
+
719
770
  let problems = 0;
720
- for (const plugin of index.plugins ?? []) {
771
+ for (const plugin of index.plugins) {
721
772
  const audit = auditVersions(index, plugin.name);
722
773
  if (audit.length === 0) {
723
774
  io.log(`ok ${plugin.name}: ${plugin.versions.length} version(s) all carry engines.dsh`);
@@ -805,8 +856,16 @@ export async function run(argv, io = console, deps = {}) {
805
856
  }
806
857
  return result.ok === true ? 0 : 1;
807
858
  }
859
+ const home = options.home === undefined ? undefined : resolvePath(options.home);
860
+ if (home !== undefined) {
861
+ const problem = profileHomeProblem(home);
862
+ if (problem !== null) {
863
+ io.error(problem);
864
+ return 2;
865
+ }
866
+ }
808
867
  const result = await audit({
809
- home: options.home === undefined ? undefined : resolvePath(options.home),
868
+ home,
810
869
  host: options.host,
811
870
  timeoutMs: options.timeout,
812
871
  io,
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import fs from 'node:fs';
8
8
 
9
+ import { parseStrictVersion } from './compat.mjs';
9
10
  import { checkHostRange } from './doctor.mjs';
10
11
  import { resolvePath } from './paths.mjs';
11
12
 
@@ -18,6 +19,101 @@ export function findPlugin(index, name) {
18
19
  return plugins.find((entry) => entry.name === name) ?? null;
19
20
  }
20
21
 
22
+ function isRecord(value) {
23
+ return value !== null && typeof value === 'object' && Array.isArray(value) === false;
24
+ }
25
+
26
+ /** True for a value the market index can use as a name or version. */
27
+ function nonEmptyString(value) {
28
+ return typeof value === 'string' && value.trim() !== '';
29
+ }
30
+
31
+ /**
32
+ * The index shape that has to be true before `auditVersions()` is meaningful.
33
+ *
34
+ * The command used to read `index.plugins ?? []` and audit each entry in
35
+ * place. A plugin without `versions`, a `versions` string, or an entry with no
36
+ * `version` either disappeared (the old code treated a non-array as an empty
37
+ * list) or crashed on `plugin.name` and printed a raw TypeError. Every finding
38
+ * names the plugin and, where one exists, the entry position or version, so a
39
+ * CI log points at the JSON line to edit instead of at the command.
40
+ */
41
+ export function validateIndex(index) {
42
+ if (isRecord(index) === false) {
43
+ return [{ entry: 'index', problem: 'the market index is not a JSON object' }];
44
+ }
45
+ if (Array.isArray(index.plugins) === false) {
46
+ return [
47
+ {
48
+ entry: 'plugins',
49
+ problem:
50
+ index.plugins === undefined
51
+ ? 'the market index has no "plugins" array'
52
+ : '"plugins" is not an array; expected a list of plugin entries',
53
+ },
54
+ ];
55
+ }
56
+
57
+ const findings = [];
58
+ index.plugins.forEach((plugin, pluginPosition) => {
59
+ if (isRecord(plugin) === false) {
60
+ findings.push({ entry: `plugins[${pluginPosition}]`, problem: 'the plugin entry is not an object' });
61
+ return;
62
+ }
63
+
64
+ const name = nonEmptyString(plugin.name) ? plugin.name : `plugins[${pluginPosition}]`;
65
+ if (nonEmptyString(plugin.name) === false) {
66
+ findings.push({
67
+ entry: name,
68
+ problem:
69
+ plugin.name === undefined
70
+ ? 'the plugin entry has no "name"'
71
+ : '"name" is not a non-empty string',
72
+ });
73
+ }
74
+
75
+ if (Array.isArray(plugin.versions) === false) {
76
+ findings.push({
77
+ entry: name,
78
+ problem:
79
+ plugin.versions === undefined
80
+ ? 'has no "versions" array; every plugin must list its published versions'
81
+ : '"versions" is not an array; expected a list of version entries',
82
+ });
83
+ return;
84
+ }
85
+
86
+ plugin.versions.forEach((entry, entryPosition) => {
87
+ const label = `${name} versions[${entryPosition}]`;
88
+ if (isRecord(entry) === false) {
89
+ findings.push({ entry: label, problem: 'the version entry is not an object' });
90
+ return;
91
+ }
92
+ if (nonEmptyString(entry.version) === false) {
93
+ findings.push({
94
+ entry: label,
95
+ problem:
96
+ entry.version === undefined
97
+ ? 'the version entry has no "version"'
98
+ : '"version" is not a non-empty string',
99
+ });
100
+ return;
101
+ }
102
+ // The market index repeats the package's version, so it uses the same
103
+ // strict SemVer parser `doctor` and `release` do. Build metadata is
104
+ // valid SemVer and accepted; a range, a leading `v`, a partial version
105
+ // or a malformed identifier is not.
106
+ if (parseStrictVersion(entry.version) === null) {
107
+ findings.push({
108
+ entry: `${name}@${entry.version}`,
109
+ problem: `version "${entry.version}" is not semver`,
110
+ });
111
+ }
112
+ });
113
+ });
114
+ return findings;
115
+ }
116
+
21
117
  /** The version objects the validator understands, newest first. */
22
118
  export function buildEntry({ version, publishTimestamp, hostRange }) {
23
119
  const entry = {
package/lib/init.mjs CHANGED
@@ -25,6 +25,19 @@ export function checkName(name) {
25
25
  return null;
26
26
  }
27
27
 
28
+ // A blank `--title` used to reach the template and produce `//` in the
29
+ // generated test: `assert.match(panel.text(), //)` is a line comment, not an
30
+ // empty regular expression, so the first `npm test` in a new plugin failed on
31
+ // a generated `SyntaxError`. An omitted title still gets the template default;
32
+ // a title the user supplied but left blank is a usage error.
33
+ export function checkTitle(title) {
34
+ if (title === undefined) return null;
35
+ if (typeof title !== 'string' || title.trim() === '') {
36
+ return '--title needs a panel title, for example --title "My panel"';
37
+ }
38
+ return null;
39
+ }
40
+
28
41
  // `--title` is user input written into JavaScript source, so it cannot go in
29
42
  // raw: an apostrophe closes a single-quoted string and a parenthesis changes
30
43
  // the meaning of a regular-expression literal. Quote both deliberately.
@@ -177,6 +190,14 @@ test('the panel renders and its button counts', async () => {
177
190
  }
178
191
 
179
192
  export function files({ name, title = 'My panel', version = '0.1.0' }) {
193
+ // `files()` is the layer that actually embeds the title in JavaScript source.
194
+ // Guard it as well as `init()`, so a future caller cannot render the broken
195
+ // `assert.match(panel.text(), //)` assertion by skipping the CLI guard.
196
+ const titleProblem = checkTitle(title);
197
+ if (titleProblem !== null) {
198
+ throw new Error(titleProblem);
199
+ }
200
+
180
201
  const slug = name.includes('/') ? name.split('/')[1] : name;
181
202
  return {
182
203
  'package.json': manifest({ name, title, version }),
@@ -194,6 +215,11 @@ export function init({ dir, name, title, force = false }) {
194
215
  const problem = checkName(name);
195
216
  if (problem !== null) return { ok: false, failures: [{ check: 'name', message: problem }] };
196
217
 
218
+ // Refuse before resolving the target or creating any directory: a caller
219
+ // that supplied an empty title should not find a half-written scaffold.
220
+ const titleProblem = checkTitle(title);
221
+ if (titleProblem !== null) return { ok: false, failures: [{ check: 'title', message: titleProblem }] };
222
+
197
223
  // `init '~/my-panel'` reaches this function with the tilde intact on
198
224
  // cmd/PowerShell. Expand it here as well as in the CLI so a direct caller
199
225
  // cannot create a directory literally named `~` either.
package/lib/verify.mjs CHANGED
@@ -11,7 +11,7 @@ import fs from 'node:fs';
11
11
  import os from 'node:os';
12
12
  import path from 'node:path';
13
13
 
14
- import { doctor, declaredPaths, missingDeclaredPaths, rootEntry } from './doctor.mjs';
14
+ import { doctor, declaredPaths, exportTarget, missingDeclaredPaths, rootEntry } from './doctor.mjs';
15
15
  import { resolveEntry } from './dev.mjs';
16
16
  import { resolvePath } from './paths.mjs';
17
17
  import { run } from './exec.mjs';
@@ -124,10 +124,61 @@ function defersPatchToPack(report) {
124
124
  );
125
125
  }
126
126
 
127
+ /**
128
+ * Whether a `client declaration` failure names a file `prepack` could create.
129
+ *
130
+ * `checkClientDeclaration` reports two different defects under one check name.
131
+ * The first is a file that is not on disk yet: a `prepack` hook may build it, so
132
+ * the check waits for the pack. The other is a manifest defect — a platform
133
+ * other than `web`, no `exports["./client"]` for the host to serve, or a bundle
134
+ * shipped without the `dsh.client` declaration that makes the host serve it. No
135
+ * file hook can add a declaration, so those stop at `doctor`; otherwise verify
136
+ * would run arbitrary build code before reporting an error it already knows.
137
+ */
138
+ function clientDeclarationMayBeGenerated(manifest) {
139
+ const client = manifest.dsh?.client;
140
+ if (client === undefined || client === null) return false;
141
+ if (client.platform !== undefined && client.platform !== 'web') return false;
142
+ const exported = manifest.exports;
143
+ const subpath = typeof exported === 'string' ? undefined : exportTarget(exported?.['./client']);
144
+ return typeof subpath === 'string';
145
+ }
146
+
147
+ /**
148
+ * Whether every failure `doctor` found is about a file `prepack` could still
149
+ * generate.
150
+ *
151
+ * `doctor` reads the working copy; `npm pack` runs `prepack` first and reads
152
+ * what that hook wrote. A package that builds `client.js` in `prepack` is
153
+ * therefore complete in the tarball and incomplete in the folder before the
154
+ * pack. Asking doctor before packing rejected exactly that package, so those
155
+ * file checks wait until after `npm pack` has run and doctor reads the folder
156
+ * npm is about to pack.
157
+ *
158
+ * A `files` list that omits a path already on disk is a manifest bug, not a
159
+ * generated file: no hook can put that declaration back. Keep stopping at
160
+ * doctor for it. A path that is absent may be generated, so it is deferred. A
161
+ * `files list` failure with no missing path (there is no `files` list at all)
162
+ * is a manifest bug too, and an empty missing list must not count as "every
163
+ * absent path can be generated".
164
+ */
165
+ function defersSourceChecksToPack(report, root) {
166
+ if (report.failures.length === 0) return false;
167
+ if (defersPatchToPack(report)) return true;
168
+ const missing = missingDeclaredPaths(report.manifest, root);
169
+ const absent = (target) => fs.existsSync(path.join(root, target)) === false;
170
+ return report.failures.every((failure) => {
171
+ if (failure.check === 'client entry' || failure.check === 'patch file') return true;
172
+ if (failure.check === 'client declaration') return clientDeclarationMayBeGenerated(report.manifest);
173
+ if (failure.check !== 'files list') return false;
174
+ return missing.length > 0 && missing.every(absent);
175
+ });
176
+ }
177
+
127
178
  export async function verify({ dir, mount = true }) {
128
179
  const root = resolvePath(dir);
129
180
  const report = doctor(root);
130
- if (report.failures.length > 0 && defersPatchToPack(report) === false) {
181
+ if (report.failures.length > 0 && defersSourceChecksToPack(report, root) === false) {
131
182
  return { ok: false, stage: 'doctor', failures: report.failures, files: [] };
132
183
  }
133
184
  const failures = [];
@@ -170,9 +221,19 @@ export async function verify({ dir, mount = true }) {
170
221
 
171
222
  if (failures.length > 0) return { ok: false, stage: 'pack', failures, files: packed.files };
172
223
 
224
+ // `prepack` has now run, so whatever it generates is on disk. Ask every
225
+ // source check again, even when the first pass was clean: `prepack` can also
226
+ // make a previously passing package worse, for example by writing a
227
+ // `client.js` that no `dsh.client` declaration serves. Reading the folder
228
+ // after the pack is the only way to judge what was actually shipped.
229
+ const checked = doctor(root);
230
+ if (checked.failures.length > 0) {
231
+ return { ok: false, stage: 'doctor', failures: checked.failures, files: packed.files };
232
+ }
233
+
173
234
  const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-plugin-verify-'));
174
235
  try {
175
- return await inspectScratch({ dir: root, mount, report, packed, scratch });
236
+ return await inspectScratch({ dir: root, mount, report: checked, packed, scratch });
176
237
  } finally {
177
238
  // Verify runs repeatedly in CI; leaving a full install tree behind each
178
239
  // 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.40",
3
+ "version": "0.20.41",
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": {