watskeburt 0.11.4 → 0.11.6
Sign up to get free protection for your applications and to get access to all the features.
package/README.md
CHANGED
@@ -82,7 +82,8 @@ The array of changes this returns looks like this:
|
|
82
82
|
|
83
83
|
### :shell: cli
|
84
84
|
|
85
|
-
For now there's also a simple command line interface
|
85
|
+
For now there's also a simple command line interface (which works from node ^16.19 and
|
86
|
+
node >=18.11).
|
86
87
|
|
87
88
|
```shell
|
88
89
|
# list all JavaScript-ish files changed since main in a regular expression
|
package/dist/cjs-bundle.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var l=Object.defineProperty;var
|
1
|
+
"use strict";var l=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var n in t)l(e,n,{get:t[n],enumerable:!0})},H=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of v(t))!_.call(e,s)&&s!==n&&l(e,s,{get:()=>t[s],enumerable:!(r=$(t,s))||r.enumerable});return e};var b=e=>H(l({},"__esModule",{value:!0}),e);var ee={};k(ee,{getSHA:()=>W,getSHASync:()=>Z,list:()=>K,listSync:()=>Q});module.exports=b(ee);var y=require("os"),B=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,U=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,j=new Map([["A","added"],["C","copied"],["D","deleted"],["M","modified"],["R","renamed"],["T","type changed"],["U","unmerged"],["B","pairing broken"],[" ","unmodified"],["?","untracked"],["!","ignored"]]);function d(e){return e.split(y.EOL).filter(Boolean).map(R).filter(({name:t,changeType:n})=>!!t&&!!n)}function R(e){let t=e.match(U),n={};if(t!=null&&t.groups){let r=m(t.groups.stagedChangeType),s=m(t.groups.unStagedChangeType);n.changeType=r==="unmodified"?s:r,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function T(e){return e.split(y.EOL).filter(Boolean).map(F).filter(({name:t,changeType:n})=>!!t&&!!n)}function F(e){let t=e.match(B),n={};return t!=null&&t.groups&&(n.changeType=m(t.groups.changeType),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function m(e){return j.get(e)??"unknown"}var c=require("child_process");function A(e=c.spawnSync){let t=new Map([[129,`'${process.cwd()}' does not seem to be a git repository`]]);return h(["status","--porcelain"],t,e)}function N(e,t,n=c.spawnSync){let r=new Map([[128,`revision '${e}' ${t?`(or '${t}') `:""}unknown`],[129,`'${process.cwd()}' does not seem to be a git repository`]]);return h(t?["diff",e,t,"--name-status"]:["diff",e,"--name-status"],r,n)}function S(e=c.spawnSync){return h(["rev-parse","HEAD"],new Map,e).slice(0,40)}function h(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env});if(r.error&&G(r.error),r.status===0)return M(r.stdout);throw new Error(t.get(r.status??0)||`internal git error: ${r.status} (${M(r.stderr)})`)}function M(e){return e instanceof Buffer?e.toString("utf8"):e}function G(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}var u=require("child_process");async function L(e=u.spawn){let t=new Map([[129,`'${process.cwd()}' does not seem to be a git repository`]]);return await C(["status","--porcelain"],t,e)}async function O(e,t,n=u.spawn){let r=new Map([[128,`revision '${e}' ${t?`(or '${t}') `:""}unknown`],[129,`'${process.cwd()}' does not seem to be a git repository`]]);return await C(t?["diff",e,t,"--name-status"]:["diff",e,"--name-status"],r,n)}async function w(e=u.spawn){return(await C(["rev-parse","HEAD"],new Map,e)).slice(0,40)}function C(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env}),s="",a="";return new Promise((p,i)=>{var g,x;(g=r.stdout)==null||g.on("data",o=>{s=s.concat(o)}),(x=r.stderr)==null||x.on("data",o=>{a=a.concat(o)}),r.on("close",o=>{o===0?p(D(s)):i(new Error(t.get(o??0)||`internal git error: ${o} (${D(a)})`))}),r.on("error",o=>{(o==null?void 0:o.code)==="ENOENT"?i(new Error("git executable not found")):i(new Error(`internal spawn error: ${o}`))})})}function D(e){return e instanceof Buffer?e.toString("utf8"):e}var P=require("path"),Y=new Set([".cjs",".cjsx",".coffee",".csx",".cts",".js",".json",".jsx",".litcoffee",".ls",".mjs",".mts",".svelte",".ts",".tsx",".vue",".vuex"]),V=new Set(["modified","added","renamed","copied","untracked"]);function I(e,t=Y,n=V){return`^(${e.filter(s=>n.has(s.changeType)).map(({name:s})=>s).filter(s=>t.has((0,P.extname)(s))).map(s=>s.replace(/\\/g,"\\\\").replace(/\./g,"\\.")).join("|")})$`}function E(e){return JSON.stringify(e,null,2)}var q=e=>e,z=new Map([["regex",I],["json",E]]);function f(e,t){return(z.get(t??"unknown")||q)(e)}async function K(e,t,n){let r=e||await w(),s=n||{},[a,p]=await Promise.all([O(r,t),s.trackedOnly?"":L()]),i=T(a);return s.trackedOnly||(i=i.concat(d(p).filter(({changeType:g})=>g==="untracked"))),f(i,s.outputType)}function Q(e,t,n){let r=e||S(),s=n||{},a=T(N(r,t));return s.trackedOnly||(a=a.concat(d(A()).filter(({changeType:p})=>p==="untracked"))),f(a,s.outputType)}function W(){return w()}function Z(){return S()}0&&(module.exports={getSHA,getSHASync,list,listSync});
|
@@ -1,19 +1,19 @@
|
|
1
1
|
import { EOL } from "node:os";
|
2
2
|
const DIFF_NAME_STATUS_LINE_PATTERN = /^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/;
|
3
3
|
const DIFF_SHORT_STATUS_LINE_PATTERN = /^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/;
|
4
|
-
const CHANGE_CHAR_2_CHANGE_TYPE =
|
5
|
-
A
|
6
|
-
C
|
7
|
-
D
|
8
|
-
M
|
9
|
-
R
|
10
|
-
T
|
11
|
-
U
|
12
|
-
B
|
13
|
-
" "
|
14
|
-
"?"
|
15
|
-
"!"
|
16
|
-
|
4
|
+
const CHANGE_CHAR_2_CHANGE_TYPE = new Map([
|
5
|
+
["A", "added"],
|
6
|
+
["C", "copied"],
|
7
|
+
["D", "deleted"],
|
8
|
+
["M", "modified"],
|
9
|
+
["R", "renamed"],
|
10
|
+
["T", "type changed"],
|
11
|
+
["U", "unmerged"],
|
12
|
+
["B", "pairing broken"],
|
13
|
+
[" ", "unmodified"],
|
14
|
+
["?", "untracked"],
|
15
|
+
["!", "ignored"],
|
16
|
+
]);
|
17
17
|
export function convertStatusLines(pString) {
|
18
18
|
return pString
|
19
19
|
.split(EOL)
|
@@ -64,5 +64,5 @@ export function convertDiffLine(pString) {
|
|
64
64
|
return lReturnValue;
|
65
65
|
}
|
66
66
|
function changeChar2ChangeType(pChar) {
|
67
|
-
return CHANGE_CHAR_2_CHANGE_TYPE
|
67
|
+
return CHANGE_CHAR_2_CHANGE_TYPE.get(pChar) ?? "unknown";
|
68
68
|
}
|
@@ -1,22 +1,25 @@
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
2
2
|
export function getStatusShortSync(pSpawnFunction = spawnSync) {
|
3
|
-
const lErrorMap =
|
4
|
-
129
|
5
|
-
|
3
|
+
const lErrorMap = new Map([
|
4
|
+
[129, `'${process.cwd()}' does not seem to be a git repository`],
|
5
|
+
]);
|
6
6
|
return getGitResultSync(["status", "--porcelain"], lErrorMap, pSpawnFunction);
|
7
7
|
}
|
8
8
|
export function getDiffLinesSync(pOldRevision, pNewRevision, pSpawnFunction = spawnSync) {
|
9
|
-
const lErrorMap =
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
const lErrorMap = new Map([
|
10
|
+
[
|
11
|
+
128,
|
12
|
+
`revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
|
13
|
+
],
|
14
|
+
[129, `'${process.cwd()}' does not seem to be a git repository`],
|
15
|
+
]);
|
13
16
|
return getGitResultSync(pNewRevision
|
14
17
|
? ["diff", pOldRevision, pNewRevision, "--name-status"]
|
15
18
|
: ["diff", pOldRevision, "--name-status"], lErrorMap, pSpawnFunction);
|
16
19
|
}
|
17
20
|
export function getSHASync(pSpawnFunction = spawnSync) {
|
18
21
|
const lSha1Length = 40;
|
19
|
-
return getGitResultSync(["rev-parse", "HEAD"],
|
22
|
+
return getGitResultSync(["rev-parse", "HEAD"], new Map(), pSpawnFunction).slice(0, lSha1Length);
|
20
23
|
}
|
21
24
|
function getGitResultSync(pArguments, pErrorMap, pSpawnFunction) {
|
22
25
|
const lGitResult = pSpawnFunction("git", pArguments, {
|
@@ -30,7 +33,7 @@ function getGitResultSync(pArguments, pErrorMap, pSpawnFunction) {
|
|
30
33
|
return stringifyOutStream(lGitResult.stdout);
|
31
34
|
}
|
32
35
|
else {
|
33
|
-
throw new Error(pErrorMap
|
36
|
+
throw new Error(pErrorMap.get(lGitResult.status ?? 0) ||
|
34
37
|
`internal git error: ${lGitResult.status} (${stringifyOutStream(lGitResult.stderr)})`);
|
35
38
|
}
|
36
39
|
}
|
@@ -1,16 +1,19 @@
|
|
1
1
|
import { spawn } from "node:child_process";
|
2
2
|
export async function getStatusShort(pSpawnFunction = spawn) {
|
3
|
-
const lErrorMap =
|
4
|
-
129
|
5
|
-
|
3
|
+
const lErrorMap = new Map([
|
4
|
+
[129, `'${process.cwd()}' does not seem to be a git repository`],
|
5
|
+
]);
|
6
6
|
const lResult = await getGitResult(["status", "--porcelain"], lErrorMap, pSpawnFunction);
|
7
7
|
return lResult;
|
8
8
|
}
|
9
9
|
export async function getDiffLines(pOldRevision, pNewRevision, pSpawnFunction = spawn) {
|
10
|
-
const lErrorMap =
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
const lErrorMap = new Map([
|
11
|
+
[
|
12
|
+
128,
|
13
|
+
`revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
|
14
|
+
],
|
15
|
+
[129, `'${process.cwd()}' does not seem to be a git repository`],
|
16
|
+
]);
|
14
17
|
const lResult = await getGitResult(pNewRevision
|
15
18
|
? ["diff", pOldRevision, pNewRevision, "--name-status"]
|
16
19
|
: ["diff", pOldRevision, "--name-status"], lErrorMap, pSpawnFunction);
|
@@ -18,7 +21,7 @@ export async function getDiffLines(pOldRevision, pNewRevision, pSpawnFunction =
|
|
18
21
|
}
|
19
22
|
export async function getSHA(pSpawnFunction = spawn) {
|
20
23
|
const lSha1Length = 40;
|
21
|
-
const lResult = await getGitResult(["rev-parse", "HEAD"],
|
24
|
+
const lResult = await getGitResult(["rev-parse", "HEAD"], new Map(), pSpawnFunction);
|
22
25
|
return lResult.slice(0, lSha1Length);
|
23
26
|
}
|
24
27
|
function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
|
@@ -40,7 +43,7 @@ function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
|
|
40
43
|
pResolve(stringifyOutStream(lStdOutData));
|
41
44
|
}
|
42
45
|
else {
|
43
|
-
pReject(new Error(pErrorMap
|
46
|
+
pReject(new Error(pErrorMap.get(pCode ?? 0) ||
|
44
47
|
`internal git error: ${pCode} (${stringifyOutStream(lStdErrorData)})`));
|
45
48
|
}
|
46
49
|
});
|
package/dist/esm/version.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "0.11.
|
1
|
+
export const VERSION = "0.11.6";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "watskeburt",
|
3
|
-
"version": "0.11.
|
3
|
+
"version": "0.11.6",
|
4
4
|
"description": "List files changed since a git revision",
|
5
5
|
"keywords": [
|
6
6
|
"git",
|
@@ -45,12 +45,12 @@
|
|
45
45
|
],
|
46
46
|
"devDependencies": {
|
47
47
|
"@types/mocha": "10.0.1",
|
48
|
-
"@types/node": "20.
|
49
|
-
"@typescript-eslint/eslint-plugin": "
|
48
|
+
"@types/node": "20.4.1",
|
49
|
+
"@typescript-eslint/eslint-plugin": "6.0.0",
|
50
50
|
"c8": "8.0.0",
|
51
|
-
"dependency-cruiser": "13.0
|
52
|
-
"esbuild": "0.18.
|
53
|
-
"eslint": "8.
|
51
|
+
"dependency-cruiser": "13.1.0",
|
52
|
+
"esbuild": "0.18.11",
|
53
|
+
"eslint": "8.44.0",
|
54
54
|
"eslint-config-moving-meadow": "4.0.2",
|
55
55
|
"eslint-config-prettier": "8.8.0",
|
56
56
|
"eslint-plugin-budapestian": "5.0.1",
|
@@ -62,13 +62,13 @@
|
|
62
62
|
"eslint-plugin-unicorn": "47.0.0",
|
63
63
|
"mocha": "10.2.0",
|
64
64
|
"npm-run-all": "4.1.5",
|
65
|
-
"prettier": "
|
65
|
+
"prettier": "3.0.0",
|
66
66
|
"ts-node": "10.9.1",
|
67
|
-
"typescript": "5.1.
|
67
|
+
"typescript": "5.1.6",
|
68
68
|
"upem": "8.0.0"
|
69
69
|
},
|
70
70
|
"engines": {
|
71
|
-
"node": "^16.
|
71
|
+
"node": "^16.14||>=18"
|
72
72
|
},
|
73
73
|
"scripts": {
|
74
74
|
"build": "npm-run-all --sequential build:clean build:version build:dist",
|
package/types/watskeburt.d.ts
CHANGED
@@ -76,7 +76,7 @@ export type IOptions = IFormatOptions | IInternalOptions;
|
|
76
76
|
export function listSync(
|
77
77
|
pOldRevision?: string,
|
78
78
|
pNewRevision?: string,
|
79
|
-
pOptions?: IInternalOptions
|
79
|
+
pOptions?: IInternalOptions,
|
80
80
|
): IChange[];
|
81
81
|
|
82
82
|
/**
|
@@ -95,7 +95,7 @@ export function listSync(
|
|
95
95
|
export function listSync(
|
96
96
|
pOldRevision?: string,
|
97
97
|
pNewRevision?: string,
|
98
|
-
pOptions?: IFormatOptions
|
98
|
+
pOptions?: IFormatOptions,
|
99
99
|
): string;
|
100
100
|
|
101
101
|
/**
|
@@ -113,7 +113,7 @@ export function listSync(
|
|
113
113
|
export function list(
|
114
114
|
pOldRevision?: string,
|
115
115
|
pNewRevision?: string,
|
116
|
-
pOptions?: IInternalOptions
|
116
|
+
pOptions?: IInternalOptions,
|
117
117
|
): Promise<IChange[]>;
|
118
118
|
|
119
119
|
/**
|
@@ -132,7 +132,7 @@ export function list(
|
|
132
132
|
export function list(
|
133
133
|
pOldRevision?: string,
|
134
134
|
pNewRevision?: string,
|
135
|
-
pOptions?: IFormatOptions
|
135
|
+
pOptions?: IFormatOptions,
|
136
136
|
): Promise<string>;
|
137
137
|
|
138
138
|
/**
|