ts-repo-utils 7.1.1 → 7.3.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.
- package/README.md +264 -249
- package/dist/cmd/assert-repo-is-clean.mjs +2 -1
- package/dist/cmd/assert-repo-is-clean.mjs.map +1 -1
- package/dist/cmd/check-should-run-type-checks.mjs +2 -1
- package/dist/cmd/check-should-run-type-checks.mjs.map +1 -1
- package/dist/cmd/format-diff-from.mjs +9 -1
- package/dist/cmd/format-diff-from.mjs.map +1 -1
- package/dist/cmd/format-uncommitted.mjs +9 -1
- package/dist/cmd/format-uncommitted.mjs.map +1 -1
- package/dist/cmd/gen-index-ts.mjs +2 -1
- package/dist/cmd/gen-index-ts.mjs.map +1 -1
- package/dist/functions/format.d.mts +7 -0
- package/dist/functions/format.d.mts.map +1 -1
- package/dist/functions/format.mjs +21 -5
- package/dist/functions/format.mjs.map +1 -1
- package/dist/functions/index.d.mts +1 -0
- package/dist/functions/index.d.mts.map +1 -1
- package/dist/functions/index.mjs +1 -0
- package/dist/functions/index.mjs.map +1 -1
- package/dist/functions/is-directly-executed.d.mts +2 -0
- package/dist/functions/is-directly-executed.d.mts.map +1 -0
- package/dist/functions/is-directly-executed.mjs +6 -0
- package/dist/functions/is-directly-executed.mjs.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/node-global.d.mts.map +1 -1
- package/dist/node-global.mjs +3 -0
- package/dist/node-global.mjs.map +1 -1
- package/package.json +6 -6
- package/src/cmd/assert-repo-is-clean.mts +1 -1
- package/src/cmd/check-should-run-type-checks.mts +1 -1
- package/src/cmd/format-diff-from.mts +9 -1
- package/src/cmd/format-uncommitted.mts +9 -1
- package/src/cmd/gen-index-ts.mts +1 -1
- package/src/functions/format.mts +36 -4
- package/src/functions/index.mts +1 -0
- package/src/functions/is-directly-executed.mts +4 -0
- package/src/node-global.mts +4 -2
package/src/functions/format.mts
CHANGED
|
@@ -19,6 +19,7 @@ export const formatFiles = async (
|
|
|
19
19
|
options?: Readonly<{
|
|
20
20
|
silent?: boolean;
|
|
21
21
|
ignore?: (filePath: string) => boolean;
|
|
22
|
+
ignoreUnknown?: boolean;
|
|
22
23
|
}>,
|
|
23
24
|
): Promise<Result<undefined, readonly unknown[]>> => {
|
|
24
25
|
const silent = options?.silent ?? false;
|
|
@@ -66,6 +67,15 @@ export const formatFiles = async (
|
|
|
66
67
|
return Result.ok(undefined);
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
if (
|
|
71
|
+
(options?.ignoreUnknown ?? true) &&
|
|
72
|
+
fileInfo.inferredParser === null
|
|
73
|
+
) {
|
|
74
|
+
// Silently skip files with no parser
|
|
75
|
+
conditionalEcho(`Skipping file (no parser): ${filePath}`);
|
|
76
|
+
return Result.ok(undefined);
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
// Format the content
|
|
70
80
|
const formatted = await prettier.format(content, {
|
|
71
81
|
...prettierOptions,
|
|
@@ -170,9 +180,15 @@ const ignoreDirs: readonly string[] = [
|
|
|
170
180
|
*/
|
|
171
181
|
export const formatFilesGlob = async (
|
|
172
182
|
pathGlob: string,
|
|
173
|
-
options?: Readonly<{
|
|
183
|
+
options?: Readonly<{
|
|
184
|
+
silent?: boolean;
|
|
185
|
+
ignoreUnknown?: boolean;
|
|
186
|
+
ignore?: (filePath: string) => boolean;
|
|
187
|
+
}>,
|
|
174
188
|
): Promise<Result<undefined, unknown>> => {
|
|
175
189
|
const silent = options?.silent ?? false;
|
|
190
|
+
const ignoreUnknown = options?.ignoreUnknown ?? true;
|
|
191
|
+
const ignore = options?.ignore;
|
|
176
192
|
const conditionalEcho = silent ? () => {} : echo;
|
|
177
193
|
|
|
178
194
|
try {
|
|
@@ -188,7 +204,7 @@ export const formatFilesGlob = async (
|
|
|
188
204
|
return Result.ok(undefined);
|
|
189
205
|
}
|
|
190
206
|
|
|
191
|
-
return await formatFiles(files, { silent });
|
|
207
|
+
return await formatFiles(files, { silent, ignoreUnknown, ignore });
|
|
192
208
|
} catch (error) {
|
|
193
209
|
if (!silent) {
|
|
194
210
|
console.error('Error in formatFiles:', error);
|
|
@@ -208,6 +224,8 @@ export const formatUncommittedFiles = async (
|
|
|
208
224
|
modified?: boolean;
|
|
209
225
|
staged?: boolean;
|
|
210
226
|
silent?: boolean;
|
|
227
|
+
ignoreUnknown?: boolean;
|
|
228
|
+
ignore?: (filePath: string) => boolean;
|
|
211
229
|
}>,
|
|
212
230
|
): Promise<
|
|
213
231
|
Result<
|
|
@@ -220,6 +238,8 @@ export const formatUncommittedFiles = async (
|
|
|
220
238
|
modified = true,
|
|
221
239
|
staged = true,
|
|
222
240
|
silent = false,
|
|
241
|
+
ignoreUnknown = true,
|
|
242
|
+
ignore,
|
|
223
243
|
} = options ?? {};
|
|
224
244
|
|
|
225
245
|
const mut_files: string[] = [];
|
|
@@ -266,7 +286,11 @@ export const formatUncommittedFiles = async (
|
|
|
266
286
|
mut_files.push(...stagedFilesResult.value);
|
|
267
287
|
}
|
|
268
288
|
|
|
269
|
-
return formatFiles(Arr.uniq(mut_files), {
|
|
289
|
+
return formatFiles(Arr.uniq(mut_files), {
|
|
290
|
+
silent,
|
|
291
|
+
ignoreUnknown,
|
|
292
|
+
ignore,
|
|
293
|
+
});
|
|
270
294
|
};
|
|
271
295
|
|
|
272
296
|
/**
|
|
@@ -289,6 +313,8 @@ export const formatDiffFrom = async (
|
|
|
289
313
|
includeModified?: boolean;
|
|
290
314
|
includeStaged?: boolean;
|
|
291
315
|
silent?: boolean;
|
|
316
|
+
ignoreUnknown?: boolean;
|
|
317
|
+
ignore?: (filePath: string) => boolean;
|
|
292
318
|
}>,
|
|
293
319
|
): Promise<
|
|
294
320
|
Result<
|
|
@@ -306,6 +332,8 @@ export const formatDiffFrom = async (
|
|
|
306
332
|
includeUntracked = true,
|
|
307
333
|
includeModified = true,
|
|
308
334
|
includeStaged = true,
|
|
335
|
+
ignoreUnknown = true,
|
|
336
|
+
ignore,
|
|
309
337
|
} = options ?? {};
|
|
310
338
|
|
|
311
339
|
const conditionalEcho = silent ? () => {} : echo;
|
|
@@ -375,5 +403,9 @@ export const formatDiffFrom = async (
|
|
|
375
403
|
return Result.ok(undefined);
|
|
376
404
|
}
|
|
377
405
|
|
|
378
|
-
return formatFiles(allFiles, {
|
|
406
|
+
return formatFiles(allFiles, {
|
|
407
|
+
silent,
|
|
408
|
+
ignoreUnknown,
|
|
409
|
+
ignore,
|
|
410
|
+
});
|
|
379
411
|
};
|
package/src/functions/index.mts
CHANGED
package/src/node-global.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
/* eslint-disable import/no-internal-modules */
|
|
1
2
|
import { default as glob_ } from 'fast-glob';
|
|
2
3
|
import * as fs_ from 'node:fs/promises';
|
|
3
4
|
import * as path_ from 'node:path';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
6
5
|
import { $ as $_ } from './functions/exec-async.mjs';
|
|
6
|
+
import { isDirectlyExecuted as isDirectlyExecuted_ } from './functions/is-directly-executed.mjs';
|
|
7
7
|
|
|
8
8
|
const globalsDef = {
|
|
9
9
|
$: $_,
|
|
@@ -12,6 +12,7 @@ const globalsDef = {
|
|
|
12
12
|
path: path_,
|
|
13
13
|
fs: fs_,
|
|
14
14
|
glob: glob_,
|
|
15
|
+
isDirectlyExecuted: isDirectlyExecuted_,
|
|
15
16
|
} as const;
|
|
16
17
|
|
|
17
18
|
// eslint-disable-next-line functional/immutable-data
|
|
@@ -24,4 +25,5 @@ declare global {
|
|
|
24
25
|
const path: typeof path_;
|
|
25
26
|
const fs: typeof fs_;
|
|
26
27
|
const glob: typeof glob_;
|
|
28
|
+
// const isDirectlyExecuted: typeof isDirectlyExecuted_;
|
|
27
29
|
}
|