ts-repo-utils 7.8.2 → 7.9.0

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 (62) hide show
  1. package/README.md +10 -0
  2. package/dist/cmd/assert-repo-is-clean.mjs +1 -1
  3. package/dist/cmd/assert-repo-is-clean.mjs.map +1 -1
  4. package/dist/cmd/check-should-run-type-checks.mjs +1 -1
  5. package/dist/cmd/check-should-run-type-checks.mjs.map +1 -1
  6. package/dist/cmd/format-diff-from.mjs +1 -1
  7. package/dist/cmd/format-diff-from.mjs.map +1 -1
  8. package/dist/cmd/format-uncommitted.mjs +1 -1
  9. package/dist/cmd/format-uncommitted.mjs.map +1 -1
  10. package/dist/cmd/gen-index-ts.mjs +1 -1
  11. package/dist/cmd/gen-index-ts.mjs.map +1 -1
  12. package/dist/entry-point.d.mts.map +1 -1
  13. package/dist/functions/assert-ext.d.mts.map +1 -1
  14. package/dist/functions/assert-ext.mjs.map +1 -1
  15. package/dist/functions/assert-path-exists.d.mts.map +1 -1
  16. package/dist/functions/assert-path-exists.mjs.map +1 -1
  17. package/dist/functions/assert-repo-is-clean.d.mts.map +1 -1
  18. package/dist/functions/assert-repo-is-clean.mjs.map +1 -1
  19. package/dist/functions/create-result-assert.d.mts.map +1 -1
  20. package/dist/functions/create-result-assert.mjs.map +1 -1
  21. package/dist/functions/exec-async.mjs.map +1 -1
  22. package/dist/functions/format.d.mts +4 -4
  23. package/dist/functions/format.d.mts.map +1 -1
  24. package/dist/functions/format.mjs +3 -3
  25. package/dist/functions/format.mjs.map +1 -1
  26. package/dist/functions/gen-index.d.mts.map +1 -1
  27. package/dist/functions/gen-index.mjs.map +1 -1
  28. package/dist/functions/should-run.d.mts.map +1 -1
  29. package/dist/functions/should-run.mjs.map +1 -1
  30. package/dist/functions/workspace-utils/execute-parallel.d.mts.map +1 -1
  31. package/dist/functions/workspace-utils/execute-parallel.mjs.map +1 -1
  32. package/dist/functions/workspace-utils/get-workspace-packages.d.mts.map +1 -1
  33. package/dist/functions/workspace-utils/get-workspace-packages.mjs.map +1 -1
  34. package/dist/functions/workspace-utils/run-cmd-in-parallel.d.mts.map +1 -1
  35. package/dist/functions/workspace-utils/run-cmd-in-parallel.mjs.map +1 -1
  36. package/dist/functions/workspace-utils/run-cmd-in-stages.d.mts.map +1 -1
  37. package/dist/functions/workspace-utils/run-cmd-in-stages.mjs.map +1 -1
  38. package/dist/node-global.d.mts.map +1 -1
  39. package/package.json +17 -19
  40. package/src/cmd/assert-repo-is-clean.mts +2 -1
  41. package/src/cmd/check-should-run-type-checks.mts +2 -1
  42. package/src/cmd/format-diff-from.mts +2 -1
  43. package/src/cmd/format-uncommitted.mts +3 -1
  44. package/src/cmd/gen-index-ts.mts +8 -2
  45. package/src/entry-point.mts +1 -0
  46. package/src/functions/assert-ext.mts +4 -0
  47. package/src/functions/assert-path-exists.mts +2 -0
  48. package/src/functions/assert-repo-is-clean.mts +9 -0
  49. package/src/functions/create-result-assert.mts +1 -0
  50. package/src/functions/diff.test.mts +76 -0
  51. package/src/functions/exec-async.mts +4 -0
  52. package/src/functions/exec-async.test.mts +42 -0
  53. package/src/functions/format.mts +26 -7
  54. package/src/functions/format.test.mts +109 -0
  55. package/src/functions/gen-index.mts +16 -0
  56. package/src/functions/should-run.mts +2 -0
  57. package/src/functions/workspace-utils/execute-parallel.mts +23 -0
  58. package/src/functions/workspace-utils/get-workspace-packages.mts +5 -0
  59. package/src/functions/workspace-utils/run-cmd-in-parallel.mts +5 -0
  60. package/src/functions/workspace-utils/run-cmd-in-stages.mts +5 -0
  61. package/src/functions/workspace-utils/run-cmd-in-stages.test.mts +13 -0
  62. package/src/node-global.mts +7 -0
@@ -18,7 +18,7 @@ export const formatFiles = async (
18
18
  files: readonly string[],
19
19
  options?: Readonly<{
20
20
  silent?: boolean;
21
- ignore?: (filePath: string) => boolean;
21
+ ignore?: false | ((filePath: string) => boolean);
22
22
  ignoreUnknown?: boolean;
23
23
  }>,
24
24
  ): Promise<Result<undefined, readonly unknown[]>> => {
@@ -28,6 +28,7 @@ export const formatFiles = async (
28
28
 
29
29
  if (files.length === 0) {
30
30
  conditionalEcho('No files to format');
31
+
31
32
  return Result.ok(undefined);
32
33
  }
33
34
 
@@ -45,6 +46,7 @@ export const formatFiles = async (
45
46
  } catch {
46
47
  // File doesn't exist, skip it
47
48
  conditionalEcho(`Skipping non-existent file: ${filePath}`);
49
+
48
50
  return Result.ok(undefined);
49
51
  }
50
52
 
@@ -60,10 +62,11 @@ export const formatFiles = async (
60
62
  });
61
63
 
62
64
  if (
63
- fileInfo.ignored ||
64
- (options?.ignore ?? defaultIgnoreFn)(filePath)
65
+ options?.ignore !== false &&
66
+ (fileInfo.ignored || (options?.ignore ?? defaultIgnoreFn)(filePath))
65
67
  ) {
66
68
  conditionalEcho(`Skipping ignored file: ${filePath}`);
69
+
67
70
  return Result.ok(undefined);
68
71
  }
69
72
 
@@ -73,6 +76,7 @@ export const formatFiles = async (
73
76
  ) {
74
77
  // Silently skip files with no parser
75
78
  conditionalEcho(`Skipping file (no parser): ${filePath}`);
79
+
76
80
  return Result.ok(undefined);
77
81
  }
78
82
 
@@ -87,6 +91,7 @@ export const formatFiles = async (
87
91
  conditionalEcho(`Unchanged: ${filePath}`);
88
92
  } else {
89
93
  await fs.writeFile(filePath, formatted, 'utf8');
94
+
90
95
  conditionalEcho(`Formatted: ${filePath}`);
91
96
  }
92
97
 
@@ -95,6 +100,7 @@ export const formatFiles = async (
95
100
  if (!silent) {
96
101
  console.error(`Error formatting ${filePath}:`, error);
97
102
  }
103
+
98
104
  return Result.err(error);
99
105
  }
100
106
  }),
@@ -102,6 +108,7 @@ export const formatFiles = async (
102
108
 
103
109
  if (results.every((r) => r.status === 'fulfilled')) {
104
110
  const fulfilled = results.map((r) => r.value);
111
+
105
112
  if (fulfilled.every(Result.isOk)) {
106
113
  return Result.ok(undefined);
107
114
  } else {
@@ -191,24 +198,28 @@ export const formatFilesGlob = async (
191
198
  options?: Readonly<{
192
199
  silent?: boolean;
193
200
  ignoreUnknown?: boolean;
194
- ignore?: (filePath: string) => boolean;
201
+ ignore?: false | ((filePath: string) => boolean);
195
202
  }>,
196
203
  ): Promise<Result<undefined, unknown>> => {
197
204
  const silent = options?.silent ?? false;
205
+
198
206
  const ignoreUnknown = options?.ignoreUnknown ?? true;
207
+
199
208
  const ignore = options?.ignore;
209
+
200
210
  const conditionalEcho = silent ? () => {} : echo;
201
211
 
202
212
  try {
203
213
  // Find all files matching the glob
204
214
  const files = await glob(pathGlob, {
205
215
  absolute: true,
206
- ignore: ['**/node_modules/**', '**/.git/**'],
216
+ ignore: ignore === false ? [] : ['**/node_modules/**', '**/.git/**'],
207
217
  dot: true,
208
218
  });
209
219
 
210
220
  if (files.length === 0) {
211
221
  conditionalEcho('No files found matching pattern:', pathGlob);
222
+
212
223
  return Result.ok(undefined);
213
224
  }
214
225
 
@@ -217,6 +228,7 @@ export const formatFilesGlob = async (
217
228
  if (!silent) {
218
229
  console.error('Error in formatFiles:', error);
219
230
  }
231
+
220
232
  return Result.err(error);
221
233
  }
222
234
  };
@@ -233,7 +245,7 @@ export const formatUncommittedFiles = async (
233
245
  staged?: boolean;
234
246
  silent?: boolean;
235
247
  ignoreUnknown?: boolean;
236
- ignore?: (filePath: string) => boolean;
248
+ ignore?: false | ((filePath: string) => boolean);
237
249
  }>,
238
250
  ): Promise<
239
251
  Result<
@@ -262,6 +274,7 @@ export const formatUncommittedFiles = async (
262
274
  untrackedFilesResult.value,
263
275
  );
264
276
  }
277
+
265
278
  return untrackedFilesResult;
266
279
  }
267
280
 
@@ -275,6 +288,7 @@ export const formatUncommittedFiles = async (
275
288
  if (!silent) {
276
289
  console.error('Error getting changed files:', diffFilesResult.value);
277
290
  }
291
+
278
292
  return diffFilesResult;
279
293
  }
280
294
 
@@ -288,6 +302,7 @@ export const formatUncommittedFiles = async (
288
302
  if (!silent) {
289
303
  console.error('Error getting changed files:', stagedFilesResult.value);
290
304
  }
305
+
291
306
  return stagedFilesResult;
292
307
  }
293
308
 
@@ -322,7 +337,7 @@ export const formatDiffFrom = async (
322
337
  includeStaged?: boolean;
323
338
  silent?: boolean;
324
339
  ignoreUnknown?: boolean;
325
- ignore?: (filePath: string) => boolean;
340
+ ignore?: false | ((filePath: string) => boolean);
326
341
  }>,
327
342
  ): Promise<
328
343
  Result<
@@ -355,10 +370,12 @@ export const formatDiffFrom = async (
355
370
  if (!silent) {
356
371
  console.error('Error getting changed files:', diffFromBaseResult.value);
357
372
  }
373
+
358
374
  return diffFromBaseResult;
359
375
  }
360
376
 
361
377
  const diffFiles = diffFromBaseResult.value;
378
+
362
379
  const mut_allFiles: string[] = diffFiles.slice();
363
380
 
364
381
  // If includeUntracked is true, also get untracked files
@@ -375,6 +392,7 @@ export const formatDiffFrom = async (
375
392
  if (!silent) {
376
393
  console.error(`Error getting ${type} files:`, filesResult.value);
377
394
  }
395
+
378
396
  return filesResult;
379
397
  }
380
398
 
@@ -408,6 +426,7 @@ export const formatDiffFrom = async (
408
426
 
409
427
  if (allFiles.length === 0) {
410
428
  conditionalEcho('No files to format');
429
+
411
430
  return Result.ok(undefined);
412
431
  }
413
432