dsh-plugin-toolkit 0.20.5 → 0.20.7

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,24 @@
1
+ ## 0.20.7
2
+
3
+ - **`dsh-plugin release --budget` rejects a value that is not a positive
4
+ number of seconds.** `--budget 8m`, `--budget 0`, `--budget -1` and a
5
+ missing value now stop during flag parsing with `--budget needs a positive
6
+ number of seconds`, exit `2`, and create neither a local nor a remote tag,
7
+ instead of pushing the tag and then waiting on a nonsensical interval. A
8
+ positive value still reaches the registry wait.
9
+
10
+ ## 0.20.6
11
+
12
+ - **`dsh-plugin doctor` reads `files` globs the way `npm pack` does.** A
13
+ `"files": ["*.js"]` entry covers root-level JavaScript only, so a nested
14
+ `exports["./client"]` at `lib/client.js` now fails the files-list check with
15
+ that path named instead of passing `doctor` and disappearing from the tarball.
16
+ `lib/*.js`, `lib/*` and `lib/**` keep their npm meanings.
17
+ - **The remote audit applies that same files-list check.** A repository whose
18
+ `"files": ["*.js"]` leaves its `exports["./client"]` out of the tarball now
19
+ produces a `files list` finding from `doctor --remote` and `audit --remote`,
20
+ and the audit exits 1 instead of printing `clean`.
21
+
1
22
  ## 0.20.5
2
23
 
3
24
  - **`dsh-plugin doctor` reads a `package.json` saved with a UTF-8 BOM.**
package/README.md CHANGED
@@ -965,10 +965,18 @@ Honest list, so nobody plans around a feature that does not exist:
965
965
  ## Changelog
966
966
 
967
967
  [`CHANGELOG.md`](CHANGELOG.md) lists what changed in each release, including
968
- the `0.20.5` fixes: `doctor` reads a `package.json` saved with a UTF-8 BOM
969
- instead of failing with a bare `Unexpected token`, and `init --title` escapes a
970
- `/` in the generated `test/panel.test.mjs`, so a title like `Input/Output panel`
971
- leaves a scaffold that parses and passes its own `npm test`. The `0.20.4` fix
968
+ the `0.20.7` fix: `release --budget` rejects a value that is not a positive
969
+ number of seconds — `8m`, `0`, `-1` or a missing value — with exit `2` before
970
+ any local or remote tag is created, instead of pushing the tag and then waiting.
971
+ The `0.20.6` fixes are recorded too: `doctor` reads a `files` glob the way
972
+ `npm pack` does, so a `"files": ["*.js"]` entry no longer hides a nested
973
+ `exports["./client"]`, and
974
+ `doctor --remote`/`audit --remote` apply the same files-list check instead of
975
+ printing `clean`. The `0.20.5` fixes are recorded too: `doctor` reads a
976
+ `package.json` saved with a UTF-8 BOM instead of failing with a bare
977
+ `Unexpected token`, and `init --title` escapes a `/` in the generated
978
+ `test/panel.test.mjs`, so a title like `Input/Output panel` leaves a scaffold
979
+ that parses and passes its own `npm test`. The `0.20.4` fix
972
980
  is recorded too: `verify` deletes its scratch install directory in a
973
981
  `finally`, so a passing run and one that stops at install or mount no longer
974
982
  leave a `dsh-plugin-verify-*` tree under `TMPDIR`. The `0.20.3` host-range
package/lib/cli.mjs CHANGED
@@ -100,7 +100,7 @@ Flags
100
100
  --market <dir> with release: a checkout of the repository that holds the index
101
101
  --publish with release: run npm publish here, for repos without a publish workflow
102
102
  --tag-prefix <prefix> default plugin-v
103
- --budget <seconds> how long to wait for npm, default 480
103
+ --budget <seconds> how long to wait for npm, a positive number, default 480
104
104
  --pr commit the index on a branch, push it, open the pull request
105
105
  --merge with --pr: wait for checks, then squash-merge
106
106
  --base <branch> base branch for the pull request, default main
@@ -127,7 +127,18 @@ function flags(argv) {
127
127
  else if (token === '--log') parsed.log = argv[++index];
128
128
  else if (token === '--index') parsed.index = argv[++index];
129
129
  else if (token === '--tag-prefix') parsed.tagPrefix = argv[++index];
130
- else if (token === '--budget') parsed.budget = Number(argv[++index]);
130
+ else if (token === '--budget') {
131
+ // A budget of `8m`, `0`, or `-1` is not a wait, and by the time the
132
+ // registry loop notices, the tag is already pushed. Validate the flag
133
+ // here, before any command can reach `git tag`.
134
+ const raw = argv[++index];
135
+ const seconds = Number(raw);
136
+ if (raw === undefined || String(raw).trim() === '' || Number.isFinite(seconds) === false || seconds <= 0) {
137
+ parsed.budgetError = raw;
138
+ } else {
139
+ parsed.budget = seconds;
140
+ }
141
+ }
131
142
  else if (token === '--slot') parsed.slot = argv[++index];
132
143
  else if (token === '--surface') parsed.surface = argv[++index];
133
144
  else if (token === '--html') parsed.html = true;
@@ -200,6 +211,14 @@ export async function run(argv, io = console, deps = {}) {
200
211
  const options = flags(rest);
201
212
  const dir = path.resolve(options.positional[0] ?? '.');
202
213
 
214
+ // `--budget` is validated while parsing, so an invalid value stops here:
215
+ // before the release sequence reads the manifest, tags, or pushes anything.
216
+ if (Object.prototype.hasOwnProperty.call(options, 'budgetError') === true) {
217
+ const got = options.budgetError === undefined ? 'nothing' : JSON.stringify(options.budgetError);
218
+ io.error(`dsh-plugin: --budget needs a positive number of seconds, got ${got}`);
219
+ return 2;
220
+ }
221
+
203
222
  if (command === undefined || command === 'help' || command === '--help') {
204
223
  io.log(HELP);
205
224
  return 0;
package/lib/doctor.mjs CHANGED
@@ -209,19 +209,136 @@ export function declaredPaths(manifest) {
209
209
  return [...paths];
210
210
  }
211
211
 
212
- /** A `files` entry covers a path when it is equal, a parent folder, or a glob prefix. */
212
+ const GLOB_MAGIC = /[*?{}[\]]/u;
213
+
214
+ /** npm compares tarball paths with forward slashes and no leading `./` or `/`. */
215
+ function packagePath(value) {
216
+ return String(value)
217
+ .replace(/\\/gu, '/')
218
+ .replace(/^(?:\.\/)+/u, '')
219
+ .replace(/^\/+/u, '');
220
+ }
221
+
222
+ function escapeRegExp(value) {
223
+ return value.replace(/[\\^$.*+?()[\]{}|]/gu, '\\$&');
224
+ }
225
+
226
+ /** `{a,b}` is the one brace form npm's minimatch accepts for `files` entries. */
227
+ function expandBraces(pattern) {
228
+ const start = pattern.indexOf('{');
229
+ if (start === -1) return [pattern];
230
+ let depth = 0;
231
+ let end = -1;
232
+ for (let index = start; index < pattern.length; index += 1) {
233
+ if (pattern[index] === '{') depth += 1;
234
+ else if (pattern[index] === '}') {
235
+ depth -= 1;
236
+ if (depth === 0) {
237
+ end = index;
238
+ break;
239
+ }
240
+ }
241
+ }
242
+ if (end === -1) return [pattern];
243
+ const body = pattern.slice(start + 1, end);
244
+ const parts = [];
245
+ let current = '';
246
+ depth = 0;
247
+ for (const char of body) {
248
+ if (char === '{') depth += 1;
249
+ else if (char === '}') depth -= 1;
250
+ if (char === ',' && depth === 0) {
251
+ parts.push(current);
252
+ current = '';
253
+ } else {
254
+ current += char;
255
+ }
256
+ }
257
+ parts.push(current);
258
+ if (parts.length === 1) return [pattern];
259
+ const prefix = pattern.slice(0, start);
260
+ const suffix = pattern.slice(end + 1);
261
+ return parts.flatMap((part) => expandBraces(`${prefix}${part}${suffix}`));
262
+ }
263
+
264
+ /** One glob alternative, with `*` kept inside a path segment and `**` crossing them. */
265
+ function globSource(pattern) {
266
+ let source = '';
267
+ for (let index = 0; index < pattern.length; index += 1) {
268
+ const char = pattern[index];
269
+ if (char === '*') {
270
+ if (pattern[index + 1] === '*') {
271
+ while (pattern[index + 1] === '*') index += 1;
272
+ if (pattern[index + 1] === '/') {
273
+ index += 1;
274
+ source += '(?:[^/]+/)*';
275
+ } else {
276
+ source += '.*';
277
+ }
278
+ } else {
279
+ source += '[^/]*';
280
+ }
281
+ } else if (char === '?') {
282
+ source += '[^/]';
283
+ } else if (char === '[') {
284
+ const close = pattern.indexOf(']', index + 1);
285
+ if (close === -1) {
286
+ source += '\\[';
287
+ } else {
288
+ let body = pattern.slice(index + 1, close);
289
+ let negate = '';
290
+ if (body.startsWith('!') || body.startsWith('^')) {
291
+ negate = '^';
292
+ body = body.slice(1);
293
+ }
294
+ source += `[${negate}${body.replace(/\\/gu, '\\\\')}]`;
295
+ index = close;
296
+ }
297
+ } else if (char === '{' || char === '}') {
298
+ source += `\\${char}`;
299
+ } else {
300
+ source += escapeRegExp(char);
301
+ }
302
+ }
303
+ return source;
304
+ }
305
+
306
+ function globMatches(value, pattern) {
307
+ const alternatives = expandBraces(pattern).map(globSource);
308
+ const source = alternatives.length === 1 ? alternatives[0] : `(?:${alternatives.join('|')})`;
309
+ return new RegExp(`^${source}$`, 'iu').test(value);
310
+ }
311
+
312
+ /**
313
+ * A `files` entry covers a path when it is equal, a parent folder, or a glob
314
+ * that npm's own packer would expand to that path. `*` does not cross a
315
+ * directory separator: `"files": ["*.js"]` ships root-level JavaScript only,
316
+ * while `lib/*.js` covers direct children of `lib` and `lib/**` (or npm's
317
+ * `lib/*` shorthand) covers the subtree.
318
+ */
213
319
  export function isShipped(target, files) {
320
+ const wanted = packagePath(target);
214
321
  return files.some((entry) => {
215
- const clean = entry.replace(/^\//, '');
216
- if (clean.includes('*') === true) {
217
- const [head] = clean.split('*');
218
- return head === '' || target.startsWith(head);
322
+ if (typeof entry !== 'string') return false;
323
+ let clean = packagePath(entry);
324
+ if (clean === '' || clean === '.') return false;
325
+ if (GLOB_MAGIC.test(clean) === false) {
326
+ // npm treats a folder entry as "everything below it", with or without a
327
+ // trailing slash: `"files": ["lib"]` ships lib/index.js.
328
+ clean = clean.replace(/\/+$/u, '');
329
+ if (clean === '') return false;
330
+ return wanted === clean || wanted.startsWith(`${clean}/`);
331
+ }
332
+ // npm appends `*` to a `dir/*` entry, making it a subtree pattern.
333
+ if (clean.endsWith('/*') === true) clean += '*';
334
+ if (globMatches(wanted, clean) === true) return true;
335
+ // minimatch's matchBase: a pattern with no slash can match a basename, but
336
+ // ignore-walk still has to have traversed every parent directory first.
337
+ if (clean.includes('/') === false) {
338
+ const segments = wanted.split('/');
339
+ return segments.length > 1 && segments.every((segment) => globMatches(segment, clean));
219
340
  }
220
- // npm treats a folder entry as "everything below it", with or without a
221
- // trailing slash: `"files": ["lib"]` ships lib/index.js.
222
- if (clean.endsWith('/') === true) return target.startsWith(clean);
223
- if (target.startsWith(`${clean}/`) === true) return true;
224
- return target === clean;
341
+ return false;
225
342
  });
226
343
  }
227
344
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-toolkit",
3
- "version": "0.20.5",
3
+ "version": "0.20.7",
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": {