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.
Files changed (38) hide show
  1. package/README.md +264 -249
  2. package/dist/cmd/assert-repo-is-clean.mjs +2 -1
  3. package/dist/cmd/assert-repo-is-clean.mjs.map +1 -1
  4. package/dist/cmd/check-should-run-type-checks.mjs +2 -1
  5. package/dist/cmd/check-should-run-type-checks.mjs.map +1 -1
  6. package/dist/cmd/format-diff-from.mjs +9 -1
  7. package/dist/cmd/format-diff-from.mjs.map +1 -1
  8. package/dist/cmd/format-uncommitted.mjs +9 -1
  9. package/dist/cmd/format-uncommitted.mjs.map +1 -1
  10. package/dist/cmd/gen-index-ts.mjs +2 -1
  11. package/dist/cmd/gen-index-ts.mjs.map +1 -1
  12. package/dist/functions/format.d.mts +7 -0
  13. package/dist/functions/format.d.mts.map +1 -1
  14. package/dist/functions/format.mjs +21 -5
  15. package/dist/functions/format.mjs.map +1 -1
  16. package/dist/functions/index.d.mts +1 -0
  17. package/dist/functions/index.d.mts.map +1 -1
  18. package/dist/functions/index.mjs +1 -0
  19. package/dist/functions/index.mjs.map +1 -1
  20. package/dist/functions/is-directly-executed.d.mts +2 -0
  21. package/dist/functions/is-directly-executed.d.mts.map +1 -0
  22. package/dist/functions/is-directly-executed.mjs +6 -0
  23. package/dist/functions/is-directly-executed.mjs.map +1 -0
  24. package/dist/index.mjs +1 -0
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/node-global.d.mts.map +1 -1
  27. package/dist/node-global.mjs +3 -0
  28. package/dist/node-global.mjs.map +1 -1
  29. package/package.json +6 -6
  30. package/src/cmd/assert-repo-is-clean.mts +1 -1
  31. package/src/cmd/check-should-run-type-checks.mts +1 -1
  32. package/src/cmd/format-diff-from.mts +9 -1
  33. package/src/cmd/format-uncommitted.mts +9 -1
  34. package/src/cmd/gen-index-ts.mts +1 -1
  35. package/src/functions/format.mts +36 -4
  36. package/src/functions/index.mts +1 -0
  37. package/src/functions/is-directly-executed.mts +4 -0
  38. package/src/node-global.mts +4 -2
@@ -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<{ silent?: boolean }>,
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), { silent });
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, { silent });
406
+ return formatFiles(allFiles, {
407
+ silent,
408
+ ignoreUnknown,
409
+ ignore,
410
+ });
379
411
  };
@@ -5,5 +5,6 @@ export * from './diff.mjs';
5
5
  export * from './exec-async.mjs';
6
6
  export * from './format.mjs';
7
7
  export * from './gen-index.mjs';
8
+ export * from './is-directly-executed.mjs';
8
9
  export * from './should-run.mjs';
9
10
  export * from './workspace-utils/index.mjs';
@@ -0,0 +1,4 @@
1
+ import { fileURLToPath } from 'node:url';
2
+
3
+ export const isDirectlyExecuted = (fileUrl: string): boolean =>
4
+ fileURLToPath(fileUrl) === process.argv[1];
@@ -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
  }