ts-repo-utils 6.1.0 → 6.2.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 +11 -7
- package/dist/cmd/assert-repo-is-clean.mjs +1 -1
- package/dist/cmd/check-should-run-type-checks.mjs +1 -1
- package/dist/cmd/format-diff-from.mjs +29 -8
- package/dist/cmd/format-diff-from.mjs.map +1 -1
- package/dist/cmd/format-uncommitted.d.mts +3 -0
- package/dist/cmd/format-uncommitted.d.mts.map +1 -0
- package/dist/cmd/format-uncommitted.mjs +59 -0
- package/dist/cmd/format-uncommitted.mjs.map +1 -0
- package/dist/cmd/gen-index-ts.mjs +1 -1
- package/dist/functions/diff.d.mts +32 -2
- package/dist/functions/diff.d.mts.map +1 -1
- package/dist/functions/diff.mjs +47 -29
- package/dist/functions/diff.mjs.map +1 -1
- package/dist/functions/exec-async.d.mts +2 -2
- package/dist/functions/exec-async.d.mts.map +1 -1
- package/dist/functions/format.d.mts +20 -11
- package/dist/functions/format.d.mts.map +1 -1
- package/dist/functions/format.mjs +134 -95
- package/dist/functions/format.mjs.map +1 -1
- package/dist/functions/index.mjs +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
- 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 +35 -9
- package/src/cmd/format-uncommitted.mts +67 -0
- package/src/cmd/gen-index-ts.mts +1 -1
- package/src/functions/diff.mts +85 -32
- package/src/functions/diff.test.mts +569 -102
- package/src/functions/exec-async.mts +2 -2
- package/src/functions/exec-async.test.mts +77 -47
- package/src/functions/format.mts +224 -141
- package/src/functions/format.test.mts +625 -20
- package/src/functions/workspace-utils/run-cmd-in-stages.test.mts +266 -0
- package/dist/cmd/format-untracked.d.mts +0 -3
- package/dist/cmd/format-untracked.d.mts.map +0 -1
- package/dist/cmd/format-untracked.mjs +0 -34
- package/dist/cmd/format-untracked.mjs.map +0 -1
- package/src/cmd/format-untracked.mts +0 -31
package/src/functions/diff.mts
CHANGED
|
@@ -2,7 +2,10 @@ import { type ExecException } from 'node:child_process';
|
|
|
2
2
|
import { Result } from 'ts-data-forge';
|
|
3
3
|
import '../node-global.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Get untracked files from the working tree (files not added to git). Runs `git
|
|
7
|
+
* ls-files --others --exclude-standard [--deleted]`
|
|
8
|
+
*/
|
|
6
9
|
export const getUntrackedFiles = async (
|
|
7
10
|
options?: Readonly<{
|
|
8
11
|
/** @default true */
|
|
@@ -12,35 +15,60 @@ export const getUntrackedFiles = async (
|
|
|
12
15
|
}>,
|
|
13
16
|
): Promise<
|
|
14
17
|
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
15
|
-
> =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
]
|
|
23
|
-
.filter((s) => s !== '')
|
|
24
|
-
.join(' '),
|
|
25
|
-
{ silent: options?.silent ?? false },
|
|
26
|
-
);
|
|
18
|
+
> =>
|
|
19
|
+
cmdResultToFiles({
|
|
20
|
+
cmd: `git ls-files --others --exclude-standard`,
|
|
21
|
+
cmdOptionToExcludeDeleted: '',
|
|
22
|
+
cmdOptionToIncludeDeleted: '--deleted',
|
|
23
|
+
options,
|
|
24
|
+
});
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Get untracked files from the working tree (files not added to git). Runs `git
|
|
28
|
+
* git diff --staged --name-only [--diff-filter=d]`
|
|
29
|
+
*/
|
|
30
|
+
export const getModifiedFiles = async (
|
|
31
|
+
options?: Readonly<{
|
|
32
|
+
/** @default true */
|
|
33
|
+
excludeDeleted?: boolean;
|
|
34
|
+
/** @default false */
|
|
35
|
+
silent?: boolean;
|
|
36
|
+
}>,
|
|
37
|
+
): Promise<
|
|
38
|
+
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
39
|
+
> =>
|
|
40
|
+
cmdResultToFiles({
|
|
41
|
+
cmd: `git diff --name-only`,
|
|
42
|
+
cmdOptionToExcludeDeleted: '--diff-filter=d',
|
|
43
|
+
cmdOptionToIncludeDeleted: '',
|
|
44
|
+
options,
|
|
45
|
+
});
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Get files that are staged for commit (files added with git add). Runs `git
|
|
49
|
+
* diff --staged --name-only [--diff-filter=d]`
|
|
50
|
+
*/
|
|
51
|
+
export const getStagedFiles = async (
|
|
52
|
+
options?: Readonly<{
|
|
53
|
+
/** @default true */
|
|
54
|
+
excludeDeleted?: boolean;
|
|
55
|
+
/** @default false */
|
|
56
|
+
silent?: boolean;
|
|
57
|
+
}>,
|
|
58
|
+
): Promise<
|
|
59
|
+
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
60
|
+
> =>
|
|
61
|
+
cmdResultToFiles({
|
|
62
|
+
cmd: `git diff --staged --name-only`,
|
|
63
|
+
cmdOptionToExcludeDeleted: '--diff-filter=d',
|
|
64
|
+
cmdOptionToIncludeDeleted: '',
|
|
65
|
+
options,
|
|
66
|
+
});
|
|
42
67
|
|
|
43
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Get files that differ from the specified base branch or commit. Runs `git
|
|
70
|
+
* diff --name-only <base> [--diff-filter=d]`
|
|
71
|
+
*/
|
|
44
72
|
export const getDiffFrom = async (
|
|
45
73
|
base: string,
|
|
46
74
|
options?: Readonly<{
|
|
@@ -51,13 +79,38 @@ export const getDiffFrom = async (
|
|
|
51
79
|
}>,
|
|
52
80
|
): Promise<
|
|
53
81
|
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
82
|
+
> =>
|
|
83
|
+
cmdResultToFiles({
|
|
84
|
+
cmd: `git diff --name-only ${base}`,
|
|
85
|
+
cmdOptionToExcludeDeleted: '--diff-filter=d',
|
|
86
|
+
cmdOptionToIncludeDeleted: '',
|
|
87
|
+
options,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const cmdResultToFiles = async ({
|
|
91
|
+
cmd,
|
|
92
|
+
cmdOptionToExcludeDeleted,
|
|
93
|
+
cmdOptionToIncludeDeleted,
|
|
94
|
+
options,
|
|
95
|
+
}: Readonly<{
|
|
96
|
+
cmd: string;
|
|
97
|
+
cmdOptionToExcludeDeleted: string;
|
|
98
|
+
cmdOptionToIncludeDeleted: string;
|
|
99
|
+
options?: Readonly<{
|
|
100
|
+
/** @default true */
|
|
101
|
+
excludeDeleted?: boolean;
|
|
102
|
+
/** @default false */
|
|
103
|
+
silent?: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
}>): Promise<
|
|
106
|
+
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
54
107
|
> => {
|
|
55
|
-
// Get files that differ from base branch/commit (excluding deleted files)
|
|
56
108
|
const result = await $(
|
|
57
109
|
[
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
110
|
+
cmd,
|
|
111
|
+
(options?.excludeDeleted ?? true)
|
|
112
|
+
? cmdOptionToExcludeDeleted
|
|
113
|
+
: cmdOptionToIncludeDeleted,
|
|
61
114
|
]
|
|
62
115
|
.filter((s) => s !== '')
|
|
63
116
|
.join(' '),
|
|
@@ -70,7 +123,7 @@ export const getDiffFrom = async (
|
|
|
70
123
|
|
|
71
124
|
const { stdout } = result.value;
|
|
72
125
|
|
|
73
|
-
// Parse git
|
|
126
|
+
// Parse git output
|
|
74
127
|
const files = stdout
|
|
75
128
|
.split('\n')
|
|
76
129
|
.map((line) => line.trim())
|