watskeburt 3.0.0 → 4.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 +28 -33
- package/dist/cli.js +1 -1
- package/dist/format/format.js +9 -0
- package/dist/{formatters → format}/json.js +1 -1
- package/dist/{formatters → format}/regex.js +2 -2
- package/dist/main.js +5 -2
- package/dist/parse-diff-lines.js +4 -4
- package/dist/parse-status-lines.js +4 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/types/watskeburt.d.ts +16 -20
- package/dist/formatters/format.js +0 -12
package/README.md
CHANGED
|
@@ -2,21 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Get changed files & their statuses since any git _revision_
|
|
4
4
|
|
|
5
|
-
## what's this do?
|
|
6
|
-
|
|
7
|
-
A micro-lib to retrieve an array of file names that were changed since a
|
|
8
|
-
revision. Also sports a cli for use outside of JavaScript c.s.
|
|
9
|
-
|
|
10
|
-
## why?
|
|
11
|
-
|
|
12
|
-
I needed something simple and robust to support some upcoming features in
|
|
13
|
-
[dependency-cruiser](https://github.com/sverweij/dependency-cruiser) and to
|
|
14
|
-
run standalone to use _in combination_ with dependency-cruiser.
|
|
15
|
-
|
|
16
|
-
There are a few specialized packages like this on npm, but it seems they've
|
|
17
|
-
fallen out of maintenance. More generic packages are still maintained,
|
|
18
|
-
but for just this simple usage they're a bit overkill.
|
|
19
|
-
|
|
20
5
|
## :construction_worker: usage
|
|
21
6
|
|
|
22
7
|
### :scroll: API
|
|
@@ -30,20 +15,23 @@ console.log(await getSHA());
|
|
|
30
15
|
// list all files that differ between 'main' and the current revision (including
|
|
31
16
|
// files not staged for commit and files not under revision control)
|
|
32
17
|
/** @type {import('watskeburt').IChange[]} */
|
|
33
|
-
const lChangedFiles = await list("main");
|
|
18
|
+
const lChangedFiles = await list({ oldRevision: "main" });
|
|
34
19
|
|
|
35
20
|
// list all files that differ between 'v0.6.1' and 'v0.7.1' (by definition
|
|
36
21
|
// won't include files staged for commit and/ or not under revision control)
|
|
37
22
|
/** @type {import('watskeburt').IChange[]} */
|
|
38
|
-
const lChangedFiles = await list(
|
|
23
|
+
const lChangedFiles = await list({
|
|
24
|
+
oldRevision: "v0.6.1",
|
|
25
|
+
newRevision: "v0.7.1",
|
|
26
|
+
});
|
|
39
27
|
|
|
28
|
+
// list all files that differ between 'main' and the current revision
|
|
29
|
+
// (excluding files not staged for commit)
|
|
40
30
|
/** @type {import('watskeburt').IChange[]|string} */
|
|
41
31
|
const lChangedFiles = await list({
|
|
42
32
|
oldRevision: "main",
|
|
43
|
-
// this compares the working tree with the oldRevision. If you want to compare
|
|
44
|
-
// to another branch or revision you can pass that in a `newRevision` field
|
|
45
33
|
trackedOnly: false, // when set to true leaves out files not under revision control
|
|
46
|
-
outputType: "
|
|
34
|
+
outputType: "json", // options: "object", "json" and "regex"
|
|
47
35
|
});
|
|
48
36
|
```
|
|
49
37
|
|
|
@@ -53,23 +41,23 @@ The array of changes this returns looks like this:
|
|
|
53
41
|
[
|
|
54
42
|
{
|
|
55
43
|
name: "doc/cli.md",
|
|
56
|
-
|
|
44
|
+
type: "modified",
|
|
57
45
|
},
|
|
58
46
|
{
|
|
59
47
|
name: "test/thing.spec.mjs",
|
|
60
|
-
|
|
48
|
+
type: "renamed",
|
|
61
49
|
oldName: "test/old-thing.spec.mjs",
|
|
62
50
|
},
|
|
63
51
|
{
|
|
64
52
|
name: "src/not-tracked-yet.mjs",
|
|
65
|
-
|
|
53
|
+
type: "untracked",
|
|
66
54
|
},
|
|
67
55
|
];
|
|
68
56
|
```
|
|
69
57
|
|
|
70
58
|
### :shell: cli
|
|
71
59
|
|
|
72
|
-
|
|
60
|
+
Works with node >=18.11
|
|
73
61
|
|
|
74
62
|
```shell
|
|
75
63
|
# list all JavaScript-ish files changed since main in a regular expression
|
|
@@ -77,19 +65,18 @@ $ npx watskeburt main
|
|
|
77
65
|
^(src/cli[.]mjs|src/formatters/regex[.]mjs|src/version[.]mjs)$
|
|
78
66
|
```
|
|
79
67
|
|
|
80
|
-
|
|
81
|
-
source files in the JavaScript ecosystem (.js, .mjs, .ts, .tsx ...)
|
|
82
|
-
be used in e.g.
|
|
68
|
+
This emits a regex that contains all changed files that could be
|
|
69
|
+
source files in the JavaScript ecosystem (.js, .mjs, .ts, .tsx ...). It can
|
|
70
|
+
be used in e.g. dependency-cruiser's `--focus` and `--reaches` filters.
|
|
83
71
|
|
|
84
|
-
The JSON output (
|
|
85
|
-
also contains other extensions.
|
|
72
|
+
The JSON output (= the array above, serialized) also contains other extensions.
|
|
86
73
|
|
|
87
74
|
```
|
|
88
75
|
Usage: watskeburt [options] [old-revision] [new-revision]
|
|
89
76
|
|
|
90
77
|
lists files & their statuses since [old-revision] or between [old-revision] and [new-revision].
|
|
91
78
|
|
|
92
|
-
-> When you don't pass a revision
|
|
79
|
+
-> When you don't pass a revision old-revision defaults to the current one.
|
|
93
80
|
|
|
94
81
|
Options:
|
|
95
82
|
-T, --outputType <type> what format to emit (choices: "json", "regex", default: "regex")
|
|
@@ -98,11 +85,19 @@ Options:
|
|
|
98
85
|
-h, --help display help for command
|
|
99
86
|
```
|
|
100
87
|
|
|
88
|
+
## why?
|
|
89
|
+
|
|
90
|
+
I needed something robust to support caching in
|
|
91
|
+
[dependency-cruiser](https://github.com/sverweij/dependency-cruiser) and to
|
|
92
|
+
run standalone to use _in combination_ with dependency-cruiser.
|
|
93
|
+
|
|
94
|
+
A few specialized packages like this existed, but they had fallen out of
|
|
95
|
+
maintenance. More generic packages still were maintained, but for my use
|
|
96
|
+
case they were overkill.
|
|
97
|
+
|
|
101
98
|
## 🇳🇱 what does 'watskeburt' mean?
|
|
102
99
|
|
|
103
100
|
Wazzup.
|
|
104
101
|
|
|
105
102
|
_watskeburt_ is a fast pronunciation of the Dutch "wat is er gebeurd?"
|
|
106
|
-
(_what has happened?_) or "wat er is gebeurd" (_what has happened_).
|
|
107
|
-
also the title of a song by the Dutch band "De Jeugd van Tegenwoordig"
|
|
108
|
-
(_Youth these days_).
|
|
103
|
+
(_what has happened?_) or "wat er is gebeurd" (_what has happened_).
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ const HELP_MESSAGE = `Usage: watskeburt [options] [old-revision] [new-revision]
|
|
|
6
6
|
|
|
7
7
|
lists files & their statuses since [old-revision] or between [old-revision] and [new-revision].
|
|
8
8
|
|
|
9
|
-
-> When you don't pass a revision
|
|
9
|
+
-> When you don't pass a revision old-revision defaults to the current one.
|
|
10
10
|
|
|
11
11
|
Options:
|
|
12
12
|
-T, --outputType <type> what format to emit (choices: "json", "regex", default: "regex")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import formatAsRegex from "./regex.js";
|
|
2
|
+
import formatAsJSON from "./json.js";
|
|
3
|
+
const OUTPUT_TYPE_TO_FUNCTION = new Map([
|
|
4
|
+
["regex", formatAsRegex],
|
|
5
|
+
["json", formatAsJSON],
|
|
6
|
+
]);
|
|
7
|
+
export function format(pChanges, pOutputType) {
|
|
8
|
+
return OUTPUT_TYPE_TO_FUNCTION.get(pOutputType)(pChanges);
|
|
9
|
+
}
|
|
@@ -25,7 +25,7 @@ const DEFAULT_CHANGE_TYPES = new Set([
|
|
|
25
25
|
"copied",
|
|
26
26
|
"untracked",
|
|
27
27
|
]);
|
|
28
|
-
export default function
|
|
28
|
+
export default function formatAsRegex(
|
|
29
29
|
pChanges,
|
|
30
30
|
pExtensions = DEFAULT_EXTENSIONS,
|
|
31
31
|
pChangeTypes = DEFAULT_CHANGE_TYPES,
|
|
@@ -33,7 +33,7 @@ export default function formatToRegex(
|
|
|
33
33
|
const lChanges = pChanges
|
|
34
34
|
.filter(
|
|
35
35
|
(pChange) =>
|
|
36
|
-
pChangeTypes.has(pChange.
|
|
36
|
+
pChangeTypes.has(pChange.type) &&
|
|
37
37
|
pExtensions.has(extname(pChange.name)),
|
|
38
38
|
)
|
|
39
39
|
.map(({ name }) => name.replace(/\\/g, "\\\\").replace(/\./g, "[.]"))
|
package/dist/main.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parseDiffLines } from "./parse-diff-lines.js";
|
|
2
2
|
import { parseStatusLines } from "./parse-status-lines.js";
|
|
3
3
|
import * as primitives from "./git-primitives.js";
|
|
4
|
-
import format from "./formatters/format.js";
|
|
5
4
|
export async function list(pOptions) {
|
|
6
5
|
const lOldRevision = pOptions?.oldRevision || (await primitives.getSHA());
|
|
7
6
|
const lOptions = pOptions || {};
|
|
@@ -13,10 +12,14 @@ export async function list(pOptions) {
|
|
|
13
12
|
if (!lOptions.trackedOnly) {
|
|
14
13
|
lChanges = lChanges.concat(
|
|
15
14
|
parseStatusLines(lStatusLines).filter(
|
|
16
|
-
({ changeType }) => changeType === "untracked",
|
|
15
|
+
({ type: changeType }) => changeType === "untracked",
|
|
17
16
|
),
|
|
18
17
|
);
|
|
19
18
|
}
|
|
19
|
+
if (!lOptions.outputType) {
|
|
20
|
+
return lChanges;
|
|
21
|
+
}
|
|
22
|
+
const { format } = await import("./format/format.js");
|
|
20
23
|
return format(lChanges, lOptions.outputType);
|
|
21
24
|
}
|
|
22
25
|
export function getSHA() {
|
package/dist/parse-diff-lines.js
CHANGED
|
@@ -7,15 +7,15 @@ export function parseDiffLines(pString) {
|
|
|
7
7
|
.split(EOL)
|
|
8
8
|
.filter(Boolean)
|
|
9
9
|
.map(parseDiffLine)
|
|
10
|
-
.filter(
|
|
10
|
+
.filter(
|
|
11
|
+
({ name, type: changeType }) => Boolean(name) && Boolean(changeType),
|
|
12
|
+
);
|
|
11
13
|
}
|
|
12
14
|
export function parseDiffLine(pString) {
|
|
13
15
|
const lMatchResult = pString.match(DIFF_NAME_STATUS_LINE_PATTERN);
|
|
14
16
|
const lReturnValue = {};
|
|
15
17
|
if (lMatchResult?.groups) {
|
|
16
|
-
lReturnValue.
|
|
17
|
-
lMatchResult.groups.changeType,
|
|
18
|
-
);
|
|
18
|
+
lReturnValue.type = changeChar2ChangeType(lMatchResult.groups.changeType);
|
|
19
19
|
if (lMatchResult.groups.newName) {
|
|
20
20
|
lReturnValue.name = lMatchResult.groups.newName;
|
|
21
21
|
lReturnValue.oldName = lMatchResult.groups.name;
|
|
@@ -7,7 +7,9 @@ export function parseStatusLines(pString) {
|
|
|
7
7
|
.split(EOL)
|
|
8
8
|
.filter(Boolean)
|
|
9
9
|
.map(parseStatusLine)
|
|
10
|
-
.filter(
|
|
10
|
+
.filter(
|
|
11
|
+
({ name, type: changeType }) => Boolean(name) && Boolean(changeType),
|
|
12
|
+
);
|
|
11
13
|
}
|
|
12
14
|
export function parseStatusLine(pString) {
|
|
13
15
|
const lMatchResult = pString.match(DIFF_SHORT_STATUS_LINE_PATTERN);
|
|
@@ -19,7 +21,7 @@ export function parseStatusLine(pString) {
|
|
|
19
21
|
const lUnStagedChangeType = changeChar2ChangeType(
|
|
20
22
|
lMatchResult.groups.unStagedChangeType,
|
|
21
23
|
);
|
|
22
|
-
lReturnValue.
|
|
24
|
+
lReturnValue.type =
|
|
23
25
|
lStagedChangeType === "unmodified"
|
|
24
26
|
? lUnStagedChangeType
|
|
25
27
|
: lStagedChangeType;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "
|
|
1
|
+
export const VERSION = "4.0.0";
|
package/package.json
CHANGED
package/types/watskeburt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type changeType =
|
|
2
2
|
| "added"
|
|
3
3
|
| "copied"
|
|
4
4
|
| "deleted"
|
|
@@ -20,63 +20,59 @@ export interface IChange {
|
|
|
20
20
|
/**
|
|
21
21
|
* how the file was changed
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
type: changeType;
|
|
24
24
|
/**
|
|
25
25
|
* if the file was renamed: what the old file's name was
|
|
26
26
|
*/
|
|
27
27
|
oldName?: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export type outputTypeType = "regex" | "json"
|
|
30
|
+
export type outputTypeType = "regex" | "json";
|
|
31
31
|
|
|
32
32
|
export interface IBaseOptions {
|
|
33
33
|
/**
|
|
34
|
-
* The revision against which to compare.
|
|
35
|
-
*
|
|
36
|
-
* commit hash (if there's any)
|
|
34
|
+
* The revision against which to compare. When not passed defaults to the
|
|
35
|
+
* _current_ commit hash (if there's any)
|
|
37
36
|
*/
|
|
38
37
|
oldRevision?: string;
|
|
39
38
|
/**
|
|
40
|
-
* Newer revision against which to compare. Leave out
|
|
41
|
-
*
|
|
39
|
+
* Newer revision against which to compare. Leave out when you want to
|
|
40
|
+
* compare against the working tree
|
|
42
41
|
*/
|
|
43
42
|
newRevision?: string;
|
|
44
43
|
/**
|
|
45
|
-
* When true
|
|
46
|
-
* When false also takes untracked files into account
|
|
47
|
-
*
|
|
48
|
-
* Defaults to false.
|
|
44
|
+
* When true only takes already tracked files into account.
|
|
45
|
+
* When false also takes untracked files into account (default)
|
|
49
46
|
*/
|
|
50
47
|
trackedOnly?: boolean;
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
export interface IFormatOptions extends IBaseOptions {
|
|
54
51
|
/**
|
|
55
|
-
* The type of output to deliver.
|
|
56
|
-
* the listSync function returns an IChange[] object
|
|
52
|
+
* The type of output to deliver.
|
|
57
53
|
*/
|
|
58
54
|
outputType: "regex" | "json";
|
|
59
55
|
}
|
|
60
56
|
|
|
61
57
|
export interface IInternalOptions extends IBaseOptions {
|
|
62
58
|
/**
|
|
63
|
-
* The type of output to deliver.
|
|
64
|
-
* the
|
|
59
|
+
* The type of output to deliver. undefined/ left out
|
|
60
|
+
* the outputType defaults to a list of `IChange`s
|
|
65
61
|
*/
|
|
66
|
-
outputType?:
|
|
62
|
+
outputType?: undefined;
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
export type IOptions = IFormatOptions | IInternalOptions;
|
|
70
66
|
|
|
71
67
|
/**
|
|
72
|
-
*
|
|
68
|
+
* promises a list of files changed since pOldRevision.
|
|
73
69
|
*
|
|
74
70
|
* @throws {Error}
|
|
75
71
|
*/
|
|
76
72
|
export function list(pOptions?: IInternalOptions): Promise<IChange[]>;
|
|
77
73
|
|
|
78
74
|
/**
|
|
79
|
-
*
|
|
75
|
+
* promises a list of files changed since pOldRevision, formatted
|
|
80
76
|
* into a string as a pOptions.outputType
|
|
81
77
|
*
|
|
82
78
|
* @throws {Error}
|
|
@@ -84,7 +80,7 @@ export function list(pOptions?: IInternalOptions): Promise<IChange[]>;
|
|
|
84
80
|
export function list(pOptions?: IFormatOptions): Promise<string>;
|
|
85
81
|
|
|
86
82
|
/**
|
|
87
|
-
*
|
|
83
|
+
* Promises the SHA1 of the current HEAD
|
|
88
84
|
*
|
|
89
85
|
* @throws {Error}
|
|
90
86
|
*/
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import formatToRegex from "./regex.js";
|
|
2
|
-
import formatToJSON from "./json.js";
|
|
3
|
-
const identity = (pX) => pX;
|
|
4
|
-
const OUTPUT_TYPE_TO_FUNCTION = new Map([
|
|
5
|
-
["regex", formatToRegex],
|
|
6
|
-
["json", formatToJSON],
|
|
7
|
-
]);
|
|
8
|
-
export default function format(pChanges, pOutputType) {
|
|
9
|
-
return (OUTPUT_TYPE_TO_FUNCTION.get(pOutputType ?? "unknown") || identity)(
|
|
10
|
-
pChanges,
|
|
11
|
-
);
|
|
12
|
-
}
|