ts-repo-utils 5.2.1 → 6.0.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 (46) hide show
  1. package/README.md +133 -0
  2. package/dist/cmd/assert-repo-is-clean.d.mts +3 -0
  3. package/dist/cmd/assert-repo-is-clean.d.mts.map +1 -0
  4. package/dist/cmd/assert-repo-is-clean.mjs +32 -0
  5. package/dist/cmd/assert-repo-is-clean.mjs.map +1 -0
  6. package/dist/cmd/check-should-run-type-checks.d.mts +3 -0
  7. package/dist/cmd/check-should-run-type-checks.d.mts.map +1 -0
  8. package/dist/cmd/check-should-run-type-checks.mjs +40 -0
  9. package/dist/cmd/check-should-run-type-checks.mjs.map +1 -0
  10. package/dist/cmd/format-diff-from.d.mts +3 -0
  11. package/dist/cmd/format-diff-from.d.mts.map +1 -0
  12. package/dist/cmd/format-diff-from.mjs +44 -0
  13. package/dist/cmd/format-diff-from.mjs.map +1 -0
  14. package/dist/cmd/format-untracked.d.mts +3 -0
  15. package/dist/cmd/format-untracked.d.mts.map +1 -0
  16. package/dist/cmd/format-untracked.mjs +34 -0
  17. package/dist/cmd/format-untracked.mjs.map +1 -0
  18. package/dist/cmd/gen-index-ts.d.mts +3 -0
  19. package/dist/cmd/gen-index-ts.d.mts.map +1 -0
  20. package/dist/cmd/gen-index-ts.mjs +103 -0
  21. package/dist/cmd/gen-index-ts.mjs.map +1 -0
  22. package/dist/functions/exec-async.d.mts +18 -9
  23. package/dist/functions/exec-async.d.mts.map +1 -1
  24. package/dist/functions/exec-async.mjs +7 -13
  25. package/dist/functions/exec-async.mjs.map +1 -1
  26. package/dist/functions/format.mjs +1 -1
  27. package/dist/functions/gen-index.d.mts +5 -11
  28. package/dist/functions/gen-index.d.mts.map +1 -1
  29. package/dist/functions/gen-index.mjs +21 -15
  30. package/dist/functions/gen-index.mjs.map +1 -1
  31. package/dist/functions/should-run.d.mts +53 -13
  32. package/dist/functions/should-run.d.mts.map +1 -1
  33. package/dist/functions/should-run.mjs +82 -23
  34. package/dist/functions/should-run.mjs.map +1 -1
  35. package/dist/index.d.mts.map +1 -1
  36. package/package.json +18 -7
  37. package/src/cmd/assert-repo-is-clean.mts +28 -0
  38. package/src/cmd/check-should-run-type-checks.mts +43 -0
  39. package/src/cmd/format-diff-from.mts +49 -0
  40. package/src/cmd/format-untracked.mts +31 -0
  41. package/src/cmd/gen-index-ts.mts +147 -0
  42. package/src/functions/exec-async.mts +62 -27
  43. package/src/functions/exec-async.test.mts +501 -0
  44. package/src/functions/gen-index.mts +36 -30
  45. package/src/functions/should-run.mts +92 -27
  46. package/src/index.mts +0 -2
@@ -1,47 +1,112 @@
1
- import { pipe, Result } from 'ts-data-forge';
1
+ import { Result } from 'ts-data-forge';
2
2
  import '../node-global.mjs';
3
3
  import { getDiffFrom } from './diff.mjs';
4
4
 
5
5
  /**
6
- * Checks if TypeScript type checks should run based on the diff from
7
- * origin/main. Skips type checks if all changed files are documentation files,
8
- * spell check config, or other non-TypeScript files that don't affect type
9
- * checking.
6
+ * Checks if TypeScript type checks should run based on the diff from a base
7
+ * branch. Skips type checks if all changed files match the ignored patterns.
10
8
  *
11
- * Ignored file patterns:
9
+ * This function is typically used in CI/CD pipelines to determine whether
10
+ * expensive type checking operations should be performed. If all changed files
11
+ * are documentation, configuration, or other non-TypeScript files, type checks
12
+ * can be safely skipped to improve build performance.
12
13
  *
13
- * - '.cspell.json'
14
- * - '**.md'
15
- * - '**.txt'
16
- * - 'docs/**'
14
+ * @example
15
+ * ```typescript
16
+ * // Use default settings (compare against origin/main, ignore docs/md/txt files)
17
+ * await checkShouldRunTypeChecks();
17
18
  *
18
- * @returns A promise that resolves when the check is complete. Sets
19
- * GITHUB_OUTPUT environment variable with should_run=true/false if running in
20
- * GitHub Actions.
19
+ * // Custom ignore patterns
20
+ * await checkShouldRunTypeChecks({
21
+ * pathsIgnore: ['.eslintrc.json', 'docs/', '**.md', 'scripts/'],
22
+ * });
23
+ *
24
+ * // Custom base branch
25
+ * await checkShouldRunTypeChecks({
26
+ * baseBranch: 'origin/develop',
27
+ * });
28
+ * ```;
29
+ *
30
+ * @example
31
+ * GitHub Actions usage
32
+ * ```yaml
33
+ * - name: Check if type checks should run
34
+ * id: check_diff
35
+ * run: npx check-should-run-type-checks
36
+ *
37
+ * - name: Run type checks
38
+ * if: steps.check_diff.outputs.should_run == 'true'
39
+ * run: npm run type-check
40
+ * ```
41
+ *
42
+ * @param options - Configuration options
43
+ * @param options.pathsIgnore - Array of patterns to ignore when determining if
44
+ * type checks should run. Supports three pattern types:
45
+ *
46
+ * - **Exact file matches**: e.g., `.cspell.json` matches only that file
47
+ * - **Directory prefixes**: e.g., `docs/` matches any file in docs directory
48
+ * - **File extensions**: e.g., `**.md` matches any markdown file Defaults to:
49
+ * `['LICENSE', '.editorconfig', '.gitignore', '.cspell.json',
50
+ * '.markdownlint-cli2.mjs', '.npmignore', '.prettierignore',
51
+ * '.prettierrc', 'docs/', '**.md', '**.txt']`
52
+ *
53
+ * @param options.baseBranch - Base branch to compare against for determining
54
+ * changed files. Defaults to `'origin/main'`
55
+ * @returns A promise that resolves when the check is complete. The function
56
+ * will set the GITHUB_OUTPUT environment variable with `should_run=true` or
57
+ * `should_run=false` if running in GitHub Actions environment.
21
58
  */
22
- export const checkShouldRunTypeChecks = async (): Promise<void> => {
23
- // paths-ignore:
24
- // - '.cspell.json'
25
- // - '**.md'
26
- // - '**.txt'
27
- // - 'docs/**'
59
+ export const checkShouldRunTypeChecks = async (
60
+ options?: Readonly<{
61
+ pathsIgnore?: readonly string[];
62
+ baseBranch?: string;
63
+ }>,
64
+ ): Promise<void> => {
65
+ const pathsIgnore = options?.pathsIgnore ?? [
66
+ 'LICENSE',
67
+ '.editorconfig',
68
+ '.gitignore',
69
+ '.cspell.json',
70
+ '.markdownlint-cli2.mjs',
71
+ '.npmignore',
72
+ '.prettierignore',
73
+ '.prettierrc',
74
+ 'docs/',
75
+ '**.md',
76
+ '**.txt',
77
+ ];
78
+
79
+ const baseBranch = options?.baseBranch ?? 'origin/main';
28
80
 
29
81
  const GITHUB_OUTPUT = process.env['GITHUB_OUTPUT'];
30
82
 
31
- const files = await getDiffFrom('origin/main');
83
+ const files = await getDiffFrom(baseBranch);
32
84
 
33
85
  if (Result.isErr(files)) {
34
86
  console.error('Error getting diff:', files.value);
35
87
  process.exit(1);
36
88
  }
37
89
 
38
- const shouldRunTsChecks: boolean = !files.value.every(
39
- (file) =>
40
- file === '.cspell.json' ||
41
- file.startsWith('docs/') ||
42
- pipe(path.basename(file)).map(
43
- (filename) => filename.endsWith('.md') || filename.endsWith('.txt'),
44
- ).value,
90
+ const shouldRunTsChecks: boolean = !files.value.every((file) =>
91
+ pathsIgnore.some((pattern) => {
92
+ // Exact file match
93
+ if (pattern === file) {
94
+ return true;
95
+ }
96
+
97
+ // Directory prefix match (pattern ends with '/')
98
+ if (pattern.endsWith('/') && file.startsWith(pattern)) {
99
+ return true;
100
+ }
101
+
102
+ // File extension pattern match (pattern starts with '**.')
103
+ if (pattern.startsWith('**.')) {
104
+ const extension = pattern.slice(2); // Remove '**'
105
+ return path.basename(file).endsWith(extension);
106
+ }
107
+
108
+ return false;
109
+ }),
45
110
  );
46
111
 
47
112
  if (GITHUB_OUTPUT !== undefined) {
package/src/index.mts CHANGED
@@ -1,3 +1 @@
1
- /// <reference types="ts-type-forge" />
2
-
3
1
  export * from './functions/index.mjs';