dsh-plugin-toolkit 0.20.46 → 0.20.47

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,19 @@
1
+ ## 0.20.47
2
+
3
+ - **`verify` judges the tarball it installs, not the separate dry run.** A
4
+ non-idempotent `prepack` could write `client.js` during `npm pack --dry-run`
5
+ and remove it during the real `npm pack`, so `verify --no-mount` checked a
6
+ file list that did not describe the archive it installed and printed
7
+ `ok packed` for a tarball with no panel. The file-list check now reads npm's
8
+ file list for the exact tarball the install step receives, so a missing
9
+ `client.js` stops at `pack` and exits 1. A `prepack` that generates the panel
10
+ still passes, and the unchanged `init` scaffold still exits 0 with `ok
11
+ packed`. `test/verify-prepack.test.mjs` pins the non-idempotent fixture at the
12
+ library and the shipped CLI beside the generated, missing, and scaffold
13
+ controls. It also packs the fixture twice to prove the regression premise:
14
+ the dry run lists `client.js` and the real tarball omits it, so the fixture
15
+ cannot silently stop reproducing the bug.
16
+
1
17
  ## 0.20.46
2
18
 
3
19
  - **`index` rejects two plugin entries that share a name before auditing
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. 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.
83
+ The order matters. Packing first means the check reads the file list from the tarball `verify` installs, not the folder you have and not a separate dry run whose `prepack` output can differ. 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
 
@@ -1055,7 +1055,7 @@ ok packed 5 file(s), installed the tarball, mounted the panel
1055
1055
  My panel This panel came from dsh-plugin init. Clicks: 0
1056
1056
  ```
1057
1057
 
1058
- 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:
1058
+ It packs, reads that tarball's file list, installs the same tarball into a throwaway directory, then mounts the bundle **from the installed copy**. The file list therefore describes the archive users would get, so a `client.js` that a non-idempotent `prepack` writes only during the dry run no longer passes. 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:
1059
1059
 
1060
1060
  ```sh
1061
1061
  $ npx dsh-plugin-toolkit verify .
package/lib/verify.mjs CHANGED
@@ -26,6 +26,15 @@ function packJson(dir) {
26
26
  return { files: (document.files ?? []).map((entry) => entry.path), filename: document.filename, size: document.size };
27
27
  }
28
28
 
29
+ /**
30
+ * Pack once, and report the files npm put in *that* tarball.
31
+ *
32
+ * The returned list is the one `verify` has to judge: it describes the archive
33
+ * npm install is about to receive. A dry-run list is not enough, because npm
34
+ * runs `prepack` for the dry run too. A non-idempotent hook can produce a
35
+ * different file set the second time, so a tarball that omits the declared
36
+ * `client.js` would still pass a check made against the dry run.
37
+ */
29
38
  function packTarball(dir, destination) {
30
39
  const output = run('npm', ['pack', '--pack-destination', destination, '--json'], {
31
40
  cwd: dir,
@@ -33,7 +42,11 @@ function packTarball(dir, destination) {
33
42
  stdio: ['ignore', 'pipe', 'pipe'],
34
43
  });
35
44
  const [document] = JSON.parse(output);
36
- return path.join(destination, document.filename);
45
+ return {
46
+ tarball: path.join(destination, document.filename),
47
+ files: (document.files ?? []).map((entry) => entry.path),
48
+ size: document.size,
49
+ };
37
50
  }
38
51
 
39
52
  /**
@@ -183,9 +196,12 @@ export async function verify({ dir, mount = true }) {
183
196
  }
184
197
  const failures = [];
185
198
 
186
- let packed;
199
+ // Keep the dry run as a cheap preflight, but do not trust its file list: a
200
+ // non-idempotent `prepack` may put `client.js` in the dry-run list and omit it
201
+ // from the tarball npm builds next. That second invocation is the archive
202
+ // `verify` installs, so its own file list is the one checked below.
187
203
  try {
188
- packed = packJson(root);
204
+ packJson(root);
189
205
  } catch (error) {
190
206
  return {
191
207
  ok: false,
@@ -195,44 +211,56 @@ export async function verify({ dir, mount = true }) {
195
211
  };
196
212
  }
197
213
 
198
- // Everything package.json points at has to be inside the tarball, or the
199
- // installed plugin is missing its own code.
200
- const shipped = new Set(packed.files);
201
- for (const target of declaredPaths(report.manifest)) {
202
- if (shipsPath(shipped, target) === false) {
203
- failures.push({
204
- check: 'pack',
205
- message: `the tarball does not contain ${target}, so the installed plugin would be missing it`,
206
- });
214
+ const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-plugin-verify-'));
215
+ try {
216
+ let packed;
217
+ try {
218
+ packed = packTarball(root, scratch);
219
+ } catch (error) {
220
+ return {
221
+ ok: false,
222
+ stage: 'pack',
223
+ failures: [{ check: 'pack', message: `npm pack failed: ${String(error.stderr ?? error.message).trim().split('\n').slice(-1)[0]}` }],
224
+ files: [],
225
+ };
207
226
  }
208
- }
209
- // The client bundle is usually found by convention (`client.js`), so it is
210
- // not in `declaredPaths` — but it still has to be in the tarball.
211
- const repoEntry = resolveEntry(root, report.manifest);
212
- if (repoEntry !== null) {
213
- const relative = path.relative(root, repoEntry).split(path.sep).join('/');
214
- if (shipsPath(shipped, relative) === false) {
215
- failures.push({
216
- check: 'pack',
217
- message: `the tarball does not contain ${relative}, so the installed plugin has no panel`,
218
- });
227
+
228
+ // Everything package.json points at has to be inside the tarball, or the
229
+ // installed plugin is missing its own code.
230
+ const shipped = new Set(packed.files);
231
+ for (const target of declaredPaths(report.manifest)) {
232
+ if (shipsPath(shipped, target) === false) {
233
+ failures.push({
234
+ check: 'pack',
235
+ message: `the tarball does not contain ${target}, so the installed plugin would be missing it`,
236
+ });
237
+ }
238
+ }
239
+ // The client bundle is usually found by convention (`client.js`), so it is
240
+ // not in `declaredPaths` — but it still has to be in the tarball.
241
+ const repoEntry = resolveEntry(root, report.manifest);
242
+ if (repoEntry !== null) {
243
+ const relative = path.relative(root, repoEntry).split(path.sep).join('/');
244
+ if (shipsPath(shipped, relative) === false) {
245
+ failures.push({
246
+ check: 'pack',
247
+ message: `the tarball does not contain ${relative}, so the installed plugin has no panel`,
248
+ });
249
+ }
219
250
  }
220
- }
221
251
 
222
- if (failures.length > 0) return { ok: false, stage: 'pack', failures, files: packed.files };
252
+ if (failures.length > 0) return { ok: false, stage: 'pack', failures, files: packed.files };
223
253
 
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
- }
254
+ // `prepack` has now run, so whatever it generates is on disk. Ask every
255
+ // source check again, even when the first pass was clean: `prepack` can also
256
+ // make a previously passing package worse, for example by writing a
257
+ // `client.js` that no `dsh.client` declaration serves. Reading the folder
258
+ // after the pack is the only way to judge what was actually shipped.
259
+ const checked = doctor(root);
260
+ if (checked.failures.length > 0) {
261
+ return { ok: false, stage: 'doctor', failures: checked.failures, files: packed.files };
262
+ }
233
263
 
234
- const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-plugin-verify-'));
235
- try {
236
264
  return await inspectScratch({ dir: root, mount, report: checked, packed, scratch });
237
265
  } finally {
238
266
  // Verify runs repeatedly in CI; leaving a full install tree behind each
@@ -266,8 +294,7 @@ async function importInstalledRoot(name, scratch) {
266
294
  async function inspectScratch({ dir, mount, report, packed, scratch }) {
267
295
  let installed;
268
296
  try {
269
- const tarball = packTarball(dir, scratch);
270
- run('npm', ['install', tarball, '--prefix', path.join(scratch, 'install'), '--no-save', '--ignore-scripts', '--no-audit', '--no-fund'], {
297
+ run('npm', ['install', packed.tarball, '--prefix', path.join(scratch, 'install'), '--no-save', '--ignore-scripts', '--no-audit', '--no-fund'], {
271
298
  cwd: scratch,
272
299
  encoding: 'utf8',
273
300
  stdio: ['ignore', 'pipe', 'pipe'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-toolkit",
3
- "version": "0.20.46",
3
+ "version": "0.20.47",
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": {