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