dsh-plugin-toolkit 0.20.31 → 0.20.33

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,32 @@
1
+ ## 0.20.33
2
+
3
+ - **`fix --remote --patch` keeps a CRLF manifest's line endings in the diff.**
4
+ The diff splitter normalized `\r\n` to `\n`, so a `package.json` saved on
5
+ Windows produced hunks whose context and removed lines lacked the carriage
6
+ return. The saved patch then failed `git apply --check` against the very
7
+ checkout it described, dead-ending the documented batch repair. The splitter
8
+ now keeps the `\r` as part of each line, so the patch body is CRLF when the
9
+ manifest is and LF when it is not; the same shared diff also fixes
10
+ `audit --remote --patch-dir` repairs. A hunk that reaches a manifest without
11
+ a final newline now carries the standard ``
12
+ marker, so `git apply --check` accepts those bytes too.
13
+ `test/fix-remote-crlf.test.mjs` runs the CLI for both line-ending styles and
14
+ checks each patch with `git apply --check`.
15
+
16
+ ## 0.20.32
17
+
18
+ - **Every value-taking flag rejects a missing value instead of falling back to
19
+ a default or swallowing the next option.** `--range`, `--log`, `--tag-prefix`,
20
+ `--base`, `--market`, `--timeout`, `--debounce`, `--slot`, `--surface`,
21
+ `--dest`, `--entry`, `--build`, `--title` and `--name` share the guard
22
+ `--index`, `--host` and `--home` already had. Before this, `fix --engines
23
+ --range --write` stored `--write` as the range and failed later with a semver
24
+ error, while `release --dry-run --tag-prefix` silently planned the default
25
+ `plugin-v` prefix. Each now exits `2`, names the flag, and stops before
26
+ reading a file or planning a release. A valid value still reaches the
27
+ command, and `test/value-flag-contract.test.mjs` pins the whole family at the
28
+ process boundary.
29
+
1
30
  ## 0.20.31
2
31
 
3
32
  - **`index --index` with no path is a usage error, not a silent default.** A
package/README.md CHANGED
@@ -1077,6 +1077,14 @@ merged
1077
1077
  | 1 | A check failed, an installed plugin was not loaded by the running app, or the release stopped (the failing stage is named) |
1078
1078
  | 2 | Unknown command, invalid usage, or a remote request that could not be completed |
1079
1079
 
1080
+ A flag that takes a value must be given one. When `--range`, `--log`,
1081
+ `--tag-prefix`, `--base`, `--market`, `--timeout`, `--debounce`, `--slot`,
1082
+ `--surface`, `--dest`, `--entry`, `--build`, `--title`, `--name`, `--index`,
1083
+ `--host`, `--home`, `--budget`, `--patch`, `--from`, `--jobs` or `--patch-dir`
1084
+ is the last token, or is followed by another flag, the command exits `2` and
1085
+ names the flag instead of falling back to a default or consuming the next
1086
+ option as the value.
1087
+
1080
1088
  `fix <owner>/<repo> --remote` exits `0` both when it prints a diff for a missing
1081
1089
  `engines.dsh` and when the manifest already declares a range that clears the
1082
1090
  check; the second case prints `ok ... nothing to apply` and writes no diff.
package/lib/cli.mjs CHANGED
@@ -116,22 +116,58 @@ Flags
116
116
  --force with init: write into a directory that is not empty; with fix --remote --patch or audit --patch-dir: overwrite an existing patch file
117
117
  `;
118
118
 
119
+ const MISSING_VALUE_MESSAGES = {
120
+ '--range': '--range needs a semver range, for example --range ">=0.3.0 <1.0.0"',
121
+ '--log': '--log needs a log file path, for example --log ~/.dsh/logs/install.log',
122
+ '--tag-prefix': '--tag-prefix needs a prefix, for example --tag-prefix plugin-v',
123
+ '--base': '--base needs a branch name, for example --base main',
124
+ '--market': '--market needs a checkout path, for example --market ../market-repo',
125
+ '--timeout': '--timeout needs a number of milliseconds',
126
+ '--debounce': '--debounce needs a number of milliseconds',
127
+ '--slot': '--slot needs a slot name, for example --slot sidebar.right.pane.tab',
128
+ '--surface': '--surface needs a surface name, for example --surface sidebar',
129
+ '--dest': '--dest needs a directory path',
130
+ '--entry': '--entry needs a file path',
131
+ '--build': '--build needs a command, for example --build "npm run build"',
132
+ '--title': '--title needs a panel title, for example --title "My panel"',
133
+ };
134
+
119
135
  function flags(argv) {
120
- const parsed = { positional: [] };
136
+ const parsed = { positional: [], missingValues: [] };
121
137
  for (let index = 0; index < argv.length; index += 1) {
122
138
  const token = argv[index];
139
+ // A value-taking flag must be followed by its value, not by another flag or
140
+ // the end of the line. The old branches read `argv[++index]` unconditionally,
141
+ // so `--range --write` made `--write` the range and `--tag-prefix` silently
142
+ // fell back to the default. Remember the missing flag so `run()` can stop at
143
+ // usage validation before reading a file or planning a release.
144
+ const take = (flag) => {
145
+ const next = argv[index + 1];
146
+ if (next === undefined || next.startsWith('--') === true) {
147
+ parsed.missingValues.push(flag);
148
+ return null;
149
+ }
150
+ index += 1;
151
+ return next;
152
+ };
123
153
  if (token === '--dry-run') parsed.dryRun = true;
124
154
  else if (token === '--engines') parsed.engines = true;
125
155
  else if (token === '--fix') parsed.fix = true;
126
156
  else if (token === '--write') parsed.write = true;
127
- else if (token === '--range') parsed.range = argv[++index];
157
+ else if (token === '--range') {
158
+ const value = take('--range');
159
+ if (value !== null) parsed.range = value;
160
+ }
128
161
  else if (token === '--patch') {
129
162
  // Leave the value blank when the next token is another flag; the fix
130
163
  // branch reports the missing path instead of swallowing that flag.
131
164
  const next = argv[index + 1];
132
165
  parsed.patch = next === undefined || next.startsWith('--') === true ? '' : argv[++index];
133
166
  }
134
- else if (token === '--log') parsed.log = argv[++index];
167
+ else if (token === '--log') {
168
+ const value = take('--log');
169
+ if (value !== null) parsed.log = value;
170
+ }
135
171
  else if (token === '--index') {
136
172
  // A bare `--index` is a missing path, not a request for the default. The
137
173
  // `index` command used to fall back to ./market/index.json and exit 0,
@@ -145,7 +181,10 @@ function flags(argv) {
145
181
  parsed.index = argv[++index];
146
182
  }
147
183
  }
148
- else if (token === '--tag-prefix') parsed.tagPrefix = argv[++index];
184
+ else if (token === '--tag-prefix') {
185
+ const value = take('--tag-prefix');
186
+ if (value !== null) parsed.tagPrefix = value;
187
+ }
149
188
  else if (token === '--budget') {
150
189
  // A budget of `8m`, `0`, or `-1` is not a wait, and by the time the
151
190
  // registry loop notices, the tag is already pushed. Validate the flag
@@ -158,16 +197,40 @@ function flags(argv) {
158
197
  parsed.budget = seconds;
159
198
  }
160
199
  }
161
- else if (token === '--slot') parsed.slot = argv[++index];
162
- else if (token === '--surface') parsed.surface = argv[++index];
200
+ else if (token === '--slot') {
201
+ const value = take('--slot');
202
+ if (value !== null) parsed.slot = value;
203
+ }
204
+ else if (token === '--surface') {
205
+ const value = take('--surface');
206
+ if (value !== null) parsed.surface = value;
207
+ }
163
208
  else if (token === '--html') parsed.html = true;
164
- else if (token === '--name') parsed.name = argv[++index];
165
- else if (token === '--title') parsed.title = argv[++index];
209
+ else if (token === '--name') {
210
+ // The init branch already has a precise "required" message; remember a
211
+ // missing value so a following flag is not consumed as the package name.
212
+ const next = argv[index + 1];
213
+ if (next === undefined || next.startsWith('--') === true) parsed.nameMissing = true;
214
+ else parsed.name = argv[++index];
215
+ }
216
+ else if (token === '--title') {
217
+ const value = take('--title');
218
+ if (value !== null) parsed.title = value;
219
+ }
166
220
  else if (token === '--force') parsed.force = true;
167
221
  else if (token === '--no-mount') parsed.noMount = true;
168
- else if (token === '--dest') parsed.dest = argv[++index];
169
- else if (token === '--entry') parsed.entry = argv[++index];
170
- else if (token === '--build') parsed.build = argv[++index];
222
+ else if (token === '--dest') {
223
+ const value = take('--dest');
224
+ if (value !== null) parsed.dest = value;
225
+ }
226
+ else if (token === '--entry') {
227
+ const value = take('--entry');
228
+ if (value !== null) parsed.entry = value;
229
+ }
230
+ else if (token === '--build') {
231
+ const value = take('--build');
232
+ if (value !== null) parsed.build = value;
233
+ }
171
234
  else if (token === '--host') {
172
235
  // A bare `--host` is a missing value, not permission to swallow the next
173
236
  // flag. `audit --remote --host --json` used to compare every repository
@@ -209,8 +272,14 @@ function flags(argv) {
209
272
  else if (value !== true) parsed.remote = parsed.remote === true ? value : `${parsed.remote},${value}`;
210
273
  } else if (token === '--json') parsed.json = true;
211
274
  else if (token === '--once') parsed.once = true;
212
- else if (token === '--debounce') parsed.debounce = Number(argv[++index]);
213
- else if (token === '--timeout') parsed.timeout = Number(argv[++index]);
275
+ else if (token === '--debounce') {
276
+ const value = take('--debounce');
277
+ if (value !== null) parsed.debounce = Number(value);
278
+ }
279
+ else if (token === '--timeout') {
280
+ const value = take('--timeout');
281
+ if (value !== null) parsed.timeout = Number(value);
282
+ }
214
283
  else if (token === '--pr') parsed.pr = true;
215
284
  else if (token === '--merge') parsed.merge = true;
216
285
  else if (token === '--publish') parsed.publish = true;
@@ -228,8 +297,14 @@ function flags(argv) {
228
297
  parsed.home = argv[++index];
229
298
  }
230
299
  }
231
- else if (token === '--base') parsed.base = argv[++index];
232
- else if (token === '--market') parsed.market = argv[++index];
300
+ else if (token === '--base') {
301
+ const value = take('--base');
302
+ if (value !== null) parsed.base = value;
303
+ }
304
+ else if (token === '--market') {
305
+ const value = take('--market');
306
+ if (value !== null) parsed.market = value;
307
+ }
233
308
  else if (token.startsWith('--') === true) throw new Error(`unknown flag ${token}`);
234
309
  else parsed.positional.push(token);
235
310
  }
@@ -267,6 +342,23 @@ export async function run(argv, io = console, deps = {}) {
267
342
  return 0;
268
343
  }
269
344
 
345
+ // `--name` has its own required-argument wording, but a following option is
346
+ // still a missing value rather than the package name.
347
+ if (options.nameMissing === true) {
348
+ io.error('dsh-plugin init: --name <package-name> is required');
349
+ return 2;
350
+ }
351
+
352
+ // Every value-taking flag is validated here, before a command can read a
353
+ // file, plan a release, or consume the next option as its value. A missing
354
+ // value is invalid usage, not a request for the flag's default.
355
+ if (options.missingValues.length > 0) {
356
+ const flag = options.missingValues[0];
357
+ const message = MISSING_VALUE_MESSAGES[flag] ?? `${flag} needs a value`;
358
+ io.error(`dsh-plugin ${command}: ${message}`);
359
+ return 2;
360
+ }
361
+
270
362
  // `--index` names the file to audit or update. Without a value the `index`
271
363
  // command used to read ./market/index.json and exit 0, which let a CI step
272
364
  // pass against an index the caller never named. Reject the usage error here,
@@ -562,7 +654,7 @@ export async function run(argv, io = console, deps = {}) {
562
654
  }
563
655
 
564
656
  if (command === 'init') {
565
- if (options.name === undefined) {
657
+ if (options.name === undefined || options.nameMissing === true) {
566
658
  io.error('dsh-plugin init: --name <package-name> is required');
567
659
  return 2;
568
660
  }
package/lib/fix.mjs CHANGED
@@ -180,18 +180,32 @@ function writeManifest({ manifestPath, manifest, raw }) {
180
180
  fs.writeFileSync(manifestPath, renderManifest(manifest, raw));
181
181
  }
182
182
 
183
- /** Split text for a diff without inventing a final empty line. */
183
+ /**
184
+ * Split text for a diff without inventing a final empty line.
185
+ *
186
+ * Split on `\n` only. For a CRLF manifest the `\r` stays at the end of each
187
+ * line and travels into the patch body, where it is part of the file's content
188
+ * and the only thing that makes the hunk match the checkout. Normalizing it
189
+ * away here produced LF hunks that `git apply --check` refused on Windows
190
+ * line endings. `noFinalNewline` is reported separately because a patch whose
191
+ * hunk reaches the last line has to say so with the standard marker.
192
+ */
184
193
  function diffLines(text) {
185
- const normalized = String(text).replace(/\r\n/gu, '\n');
186
- const lines = normalized.split('\n');
194
+ const value = String(text);
195
+ const lines = value.split('\n');
196
+ const noFinalNewline = lines.length > 0 && lines[lines.length - 1] !== '';
187
197
  if (lines.length > 0 && lines[lines.length - 1] === '') lines.pop();
188
- return lines;
198
+ return { lines, noFinalNewline };
189
199
  }
190
200
 
191
201
  /** A line-by-line edit script, equal lines first and deletions before additions. */
192
202
  function lineOperations(before, after) {
193
- const left = diffLines(before);
194
- const right = diffLines(after);
203
+ const leftInfo = diffLines(before);
204
+ const rightInfo = diffLines(after);
205
+ const left = leftInfo.lines;
206
+ const right = rightInfo.lines;
207
+ const lastLeft = left.length - 1;
208
+ const lastRight = right.length - 1;
195
209
  const common = Array.from({ length: left.length + 1 }, () => new Uint32Array(right.length + 1));
196
210
  for (let i = left.length - 1; i >= 0; i -= 1) {
197
211
  for (let j = right.length - 1; j >= 0; j -= 1) {
@@ -205,19 +219,37 @@ function lineOperations(before, after) {
205
219
  let j = 0;
206
220
  while (i < left.length && j < right.length) {
207
221
  if (left[i] === right[j]) {
208
- operations.push({ type: ' ', text: left[i] });
222
+ const atEnd = i === lastLeft && j === lastRight;
223
+ if (atEnd === true && leftInfo.noFinalNewline !== rightInfo.noFinalNewline) {
224
+ // Same text, different final newline: context cannot express that, so
225
+ // replace the line and let the markers say which side ends without one.
226
+ operations.push({ type: '-', text: left[i], noNewline: leftInfo.noFinalNewline });
227
+ operations.push({ type: '+', text: right[j], noNewline: rightInfo.noFinalNewline });
228
+ } else {
229
+ operations.push({
230
+ type: ' ',
231
+ text: left[i],
232
+ noNewline: atEnd === true && (leftInfo.noFinalNewline || rightInfo.noFinalNewline),
233
+ });
234
+ }
209
235
  i += 1;
210
236
  j += 1;
211
237
  } else if (common[i + 1][j] >= common[i][j + 1]) {
212
- operations.push({ type: '-', text: left[i] });
238
+ operations.push({ type: '-', text: left[i], noNewline: i === lastLeft && leftInfo.noFinalNewline });
213
239
  i += 1;
214
240
  } else {
215
- operations.push({ type: '+', text: right[j] });
241
+ operations.push({ type: '+', text: right[j], noNewline: j === lastRight && rightInfo.noFinalNewline });
216
242
  j += 1;
217
243
  }
218
244
  }
219
- while (i < left.length) operations.push({ type: '-', text: left[i++] });
220
- while (j < right.length) operations.push({ type: '+', text: right[j++] });
245
+ while (i < left.length) {
246
+ operations.push({ type: '-', text: left[i], noNewline: i === lastLeft && leftInfo.noFinalNewline });
247
+ i += 1;
248
+ }
249
+ while (j < right.length) {
250
+ operations.push({ type: '+', text: right[j], noNewline: j === lastRight && rightInfo.noFinalNewline });
251
+ j += 1;
252
+ }
221
253
  return operations;
222
254
  }
223
255
 
@@ -265,7 +297,9 @@ export function unifiedDiff(before, after, { file = 'package.json', context = 3
265
297
  const newStart = newCount === 0 ? newBefore[from] : newBefore[from] + 1;
266
298
  lines.push(`@@ -${oldStart},${oldCount} +${newStart},${newCount} @@`);
267
299
  for (let index = from; index < to; index += 1) {
268
- lines.push(`${operations[index].type}${operations[index].text}`);
300
+ const operation = operations[index];
301
+ lines.push(`${operation.type}${operation.text}`);
302
+ if (operation.noNewline === true) lines.push('\');
269
303
  }
270
304
  }
271
305
  return `${lines.join('\n')}\n`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-toolkit",
3
- "version": "0.20.31",
3
+ "version": "0.20.33",
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": {