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.
- package/README.md +133 -0
- package/dist/cmd/assert-repo-is-clean.d.mts +3 -0
- package/dist/cmd/assert-repo-is-clean.d.mts.map +1 -0
- package/dist/cmd/assert-repo-is-clean.mjs +32 -0
- package/dist/cmd/assert-repo-is-clean.mjs.map +1 -0
- package/dist/cmd/check-should-run-type-checks.d.mts +3 -0
- package/dist/cmd/check-should-run-type-checks.d.mts.map +1 -0
- package/dist/cmd/check-should-run-type-checks.mjs +40 -0
- package/dist/cmd/check-should-run-type-checks.mjs.map +1 -0
- package/dist/cmd/format-diff-from.d.mts +3 -0
- package/dist/cmd/format-diff-from.d.mts.map +1 -0
- package/dist/cmd/format-diff-from.mjs +44 -0
- package/dist/cmd/format-diff-from.mjs.map +1 -0
- package/dist/cmd/format-untracked.d.mts +3 -0
- package/dist/cmd/format-untracked.d.mts.map +1 -0
- package/dist/cmd/format-untracked.mjs +34 -0
- package/dist/cmd/format-untracked.mjs.map +1 -0
- package/dist/cmd/gen-index-ts.d.mts +3 -0
- package/dist/cmd/gen-index-ts.d.mts.map +1 -0
- package/dist/cmd/gen-index-ts.mjs +103 -0
- package/dist/cmd/gen-index-ts.mjs.map +1 -0
- package/dist/functions/exec-async.d.mts +18 -9
- package/dist/functions/exec-async.d.mts.map +1 -1
- package/dist/functions/exec-async.mjs +7 -13
- package/dist/functions/exec-async.mjs.map +1 -1
- package/dist/functions/format.mjs +1 -1
- package/dist/functions/gen-index.d.mts +5 -11
- package/dist/functions/gen-index.d.mts.map +1 -1
- package/dist/functions/gen-index.mjs +21 -15
- package/dist/functions/gen-index.mjs.map +1 -1
- package/dist/functions/should-run.d.mts +53 -13
- package/dist/functions/should-run.d.mts.map +1 -1
- package/dist/functions/should-run.mjs +82 -23
- package/dist/functions/should-run.mjs.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/package.json +18 -7
- package/src/cmd/assert-repo-is-clean.mts +28 -0
- package/src/cmd/check-should-run-type-checks.mts +43 -0
- package/src/cmd/format-diff-from.mts +49 -0
- package/src/cmd/format-untracked.mts +31 -0
- package/src/cmd/gen-index-ts.mts +147 -0
- package/src/functions/exec-async.mts +62 -27
- package/src/functions/exec-async.test.mts +501 -0
- package/src/functions/gen-index.mts +36 -30
- package/src/functions/should-run.mts +92 -27
- package/src/index.mts +0 -2
|
@@ -1,47 +1,112 @@
|
|
|
1
|
-
import {
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Use default settings (compare against origin/main, ignore docs/md/txt files)
|
|
17
|
+
* await checkShouldRunTypeChecks();
|
|
17
18
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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 (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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(
|
|
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
|
-
(
|
|
40
|
-
|
|
41
|
-
file
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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