dsh-plugin-toolkit 0.20.32 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/lib/fix.mjs +46 -12
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
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
+
1
16
  ## 0.20.32
2
17
 
3
18
  - **Every value-taking flag rejects a missing value instead of falling back to
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.32",
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": {