dsh-plugin-toolkit 0.20.17 → 0.20.18

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,20 @@
1
+ ## 0.20.18
2
+
3
+ - **`verify` resolves the installed root the way the loader does.** It used to
4
+ import the file `main` named, so a tarball whose `exports` map had no `.`
5
+ entry passed `verify --no-mount` even though `import("<name>")` failed with
6
+ `ERR_PACKAGE_PATH_NOT_EXPORTED`. The installed copy is now imported by its
7
+ bare package name from a probe module beside it, so Node's own `exports`
8
+ resolution decides. The missing `.` entry is reported as a `root export`
9
+ failure and the command exits `1`; the same fixture with `exports["."]` exits
10
+ `0` and prints `imported its host half`. A package that declares neither
11
+ `exports` nor `main` still has no root module to import, so its success line
12
+ keeps saying the host import was skipped. Two checked-in fixtures
13
+ (`test/fixtures/verify-exports-no-dot` and `verify-exports-dot`) now pin both
14
+ sides through the shipped CLI process, including the exit code, so `npm test`
15
+ fails if the no-`.` tarball ever exits `0` again. The README states that the
16
+ bare specifier, not a file path, is what `verify` imports.
17
+
1
18
  ## 0.20.17
2
19
 
3
20
  - **`audit` reports a declared bundle whose folder is gone.** When a package
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 export is imported the way the loader imports it. 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.
84
84
 
85
85
  Each step exists because a plugin once got past the step before it and still installed into nothing.
86
86
 
@@ -692,9 +692,11 @@ the diff in the terminal.
692
692
  | `patch file` | The path declared above must be a real file |
693
693
  | `client entry` | If `dsh.client` is declared, the bundle has to be there |
694
694
  | `files list` | Every path `package.json` points at (`exports`, patch, client) must be covered by `files` |
695
- | `root export` | The loader imports the bare package name; if that module is missing, is a directory, is the CLI, or exports no `apply`, the row mounts nothing while the install reports success |
695
+ | `root export` | The loader imports the bare package name; if that module is missing, is a directory, is the CLI, exports no `apply`, or the `exports` map has no `.` entry, the row mounts nothing while the install reports success |
696
696
 
697
- 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. `verify --no-mount` runs `doctor` first, so it stops at that same check instead of packing a package whose root cannot load; `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.
697
+ 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.
698
+
699
+ `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.
698
700
 
699
701
  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.
700
702
 
@@ -923,7 +925,7 @@ ok packed 5 file(s), installed the tarball, mounted the panel
923
925
  My panel This panel came from dsh-plugin init. Clicks: 0
924
926
  ```
925
927
 
926
- It packs, installs that tarball into a throwaway directory, then mounts the bundle **from the installed copy**. A bundle that only inserts a subpath patch needs no root module; in that case 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:
928
+ 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:
927
929
 
928
930
  ```sh
929
931
  $ npx dsh-plugin-toolkit verify .
package/lib/verify.mjs CHANGED
@@ -170,6 +170,23 @@ export async function verify({ dir, mount = true }) {
170
170
  }
171
171
  }
172
172
 
173
+ /**
174
+ * Import the installed package exactly as the loader does: `import(name)` from
175
+ * a module that sits beside the installed copy. Resolving the bare specifier
176
+ * here, rather than reading `main` or `exports["."]` ourselves, means Node's
177
+ * own rules decide whether the root is importable. That is what catches an
178
+ * `exports` map with no `.` entry: Node ignores `main` once `exports` exists,
179
+ * so the bare import fails with ERR_PACKAGE_PATH_NOT_EXPORTED while the file
180
+ * `main` names is still present.
181
+ */
182
+ async function importInstalledRoot(name, scratch) {
183
+ const { pathToFileURL } = await import('node:url');
184
+ const probe = path.join(scratch, 'install', 'verify-root.mjs');
185
+ fs.writeFileSync(probe, `export default await import(${JSON.stringify(name)});\n`);
186
+ const loaded = await import(pathToFileURL(probe).href);
187
+ return loaded.default;
188
+ }
189
+
173
190
  /**
174
191
  * The part of `verify` that needs the installed copy. It runs inside the
175
192
  * scratch directory's try/finally, so every stage here is cleaned up whether
@@ -207,40 +224,52 @@ async function inspectScratch({ dir, mount, report, packed, scratch }) {
207
224
  // the same import here is the only way to know the row will have an apply —
208
225
  // 0.8.0 shipped a package whose root export was the CLI, installed cleanly,
209
226
  // and mounted nothing.
227
+ //
228
+ // Importing the file `main` names would be a different question. Node ignores
229
+ // `main` as soon as a package has an `exports` map, so a map with no `.` entry
230
+ // fails `import(name)` with ERR_PACKAGE_PATH_NOT_EXPORTED even when `main`
231
+ // points at a working module. The probe module below lives beside the
232
+ // installed package, so the bare specifier is resolved by the same algorithm
233
+ // the loader uses, not by the toolkit's own location.
210
234
  const rootFile = rootEntry(report.manifest);
235
+ const declaredRoot =
236
+ (report.manifest.exports !== undefined && report.manifest.exports !== null) ||
237
+ typeof report.manifest.main === 'string';
211
238
  let hostFace = null;
212
- // A bundle that inserts a subpath plugin needs no root module, so there is
213
- // nothing to import. The success line must not claim it imported a host half
214
- // that was skipped.
239
+ // A bundle that inserts a subpath plugin and declares no root at all needs no
240
+ // root module, so there is nothing to import. The success line must not claim
241
+ // it imported a host half that was skipped.
215
242
  let hostImported = false;
216
- if (rootFile !== null) {
217
- const absolute = path.join(installed, rootFile);
218
- if (fs.existsSync(absolute) === false) {
219
- return {
220
- ok: false,
221
- stage: 'install',
222
- failures: [{ check: 'root export', message: `the tarball does not ship ${rootFile}, which package.json points the loader at` }],
223
- files: packed.files,
224
- };
225
- }
243
+ if (declaredRoot === true) {
244
+ let loaded;
226
245
  try {
227
- const { pathToFileURL } = await import('node:url');
228
- const loaded = await import(pathToFileURL(absolute).href);
229
- hostFace = loaded;
230
- hostImported = true;
231
- if (typeof loaded.apply !== 'function') {
246
+ loaded = await importInstalledRoot(report.manifest.name, scratch);
247
+ } catch (error) {
248
+ if (error?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
232
249
  return {
233
250
  ok: false,
234
251
  stage: 'install',
235
- failures: [{ check: 'root export', message: `the installed ${rootFile} exports no apply, so the loader's row mounts nothing` }],
252
+ failures: [{
253
+ check: 'root export',
254
+ message: 'the installed package has no exports["."], so importing its bare name fails with ERR_PACKAGE_PATH_NOT_EXPORTED; add a "." entry that names the module exporting apply',
255
+ }],
236
256
  files: packed.files,
237
257
  };
238
258
  }
239
- } catch (error) {
240
259
  return {
241
260
  ok: false,
242
261
  stage: 'install',
243
- failures: [{ check: 'root export', message: `the installed ${rootFile} does not import: ${error.message}` }],
262
+ failures: [{ check: 'root export', message: `the installed ${rootFile ?? report.manifest.name} does not import: ${error.message}` }],
263
+ files: packed.files,
264
+ };
265
+ }
266
+ hostFace = loaded;
267
+ hostImported = true;
268
+ if (typeof loaded.apply !== 'function') {
269
+ return {
270
+ ok: false,
271
+ stage: 'install',
272
+ failures: [{ check: 'root export', message: `the installed ${rootFile ?? report.manifest.name} exports no apply, so the loader's row mounts nothing` }],
244
273
  files: packed.files,
245
274
  };
246
275
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-toolkit",
3
- "version": "0.20.17",
3
+ "version": "0.20.18",
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": {