watskeburt 0.11.0 → 0.11.2
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 +6 -5
- package/bin/version.js +1 -1
- package/dist/cjs-bundle.cjs +1 -1
- package/dist/esm/convert-to-change-object.js +0 -6
- package/dist/esm/formatters/regex.js +1 -1
- package/dist/esm/git-primitives-sync.js +0 -12
- package/dist/esm/git-primitives.js +0 -12
- package/dist/esm/main.js +20 -16
- package/package.json +8 -17
package/README.md
CHANGED
@@ -35,13 +35,14 @@ console.log(getSHASync());
|
|
35
35
|
// files not staged for commit and files not under revision control)
|
36
36
|
/** @type {import('watskeburt').IChange[]} */
|
37
37
|
const lChangedFiles = await list("main");
|
38
|
-
// or
|
38
|
+
// or with the synchronous interface:
|
39
39
|
// const lChangedFiles = listSync("main");
|
40
40
|
|
41
41
|
// list all files that differ between 'v0.6.1' and 'v0.7.1' (by definition
|
42
42
|
// won't include files staged for commit and/ or not under revision control)
|
43
43
|
/** @type {import('watskeburt').IChange[]} */
|
44
44
|
const lChangedFiles = await list("v0.6.1", "v0.7.1");
|
45
|
+
// or with the synchronous interface:
|
45
46
|
// const lChangedFiles = listSync("v0.6.1", "v0.7.1");
|
46
47
|
|
47
48
|
// As a third parameter you can pass some options
|
@@ -52,8 +53,8 @@ const lChangedFiles = await list("main", null, {
|
|
52
53
|
trackedOnly: false, // when set to true leaves out files not under revision control
|
53
54
|
outputType: "object", // other options: "json" and "regex" (as used in the CLI)
|
54
55
|
});
|
55
|
-
// or with synchronous
|
56
|
-
// const lChangedFiles =
|
56
|
+
// or with the synchronous interface:
|
57
|
+
// const lChangedFiles = listSync("main", null, {
|
57
58
|
// trackedOnly: false, // when set to true leaves out files not under revision control
|
58
59
|
// outputType: "object", // other options: "json" and "regex" (as used in the CLI)
|
59
60
|
// });
|
@@ -86,7 +87,7 @@ For now there's also a simple command line interface
|
|
86
87
|
```shell
|
87
88
|
# list all JavaScript-ish files changed since main in a regular expression
|
88
89
|
$ npx watskeburt main
|
89
|
-
^(src/cli
|
90
|
+
^(src/cli\.mjs|src/formatters/regex\.mjs|src/version\.mjs)$
|
90
91
|
```
|
91
92
|
|
92
93
|
By default this returns a regex that contains all changed files that could be
|
@@ -115,4 +116,4 @@ Options:
|
|
115
116
|
_watskeburt_ is a fast pronunciation of the Dutch "wat is er gebeurd?"
|
116
117
|
(_what has happened?_) or "wat er is gebeurd" (_what has happened_). It's
|
117
118
|
also the title of a song by the Dutch band "De Jeugd van Tegenwoordig"
|
118
|
-
(_Youth these
|
119
|
+
(_Youth these days_).
|
package/bin/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
// generated by tools/get-version.ts - edits will be overwritten
|
2
|
-
export const VERSION = "0.11.
|
2
|
+
export const VERSION = "0.11.2";
|
package/dist/cjs-bundle.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var
|
1
|
+
"use strict";var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var n in e)l(t,n,{get:e[n],enumerable:!0})},H=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of _(e))!k.call(t,s)&&s!==n&&l(t,s,{get:()=>e[s],enumerable:!(r=v(e,s))||r.enumerable});return t};var b=t=>H(l({},"__esModule",{value:!0}),t);var tt={};M(tt,{getSHA:()=>W,getSHASync:()=>Z,list:()=>K,listSync:()=>Q});module.exports=b(tt);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={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function m(t){return j[t]??"unknown"}function R(t){let e=t.match(U),n={};if(e!=null&&e.groups){let r=m(e.groups.stagedChangeType),s=m(e.groups.unStagedChangeType);n.changeType=r==="unmodified"?s:r,e.groups.newName?(n.name=e.groups.newName,n.oldName=e.groups.name):n.name=e.groups.name}return n}function F(t){let e=t.match(B),n={};return e!=null&&e.groups&&(n.changeType=m(e.groups.changeType),e.groups.newName?(n.name=e.groups.newName,n.oldName=e.groups.name):n.name=e.groups.name),n}function d(t){return t.split(y.EOL).filter(Boolean).map(R).filter(({name:e,changeType:n})=>!!e&&!!n)}function T(t){return t.split(y.EOL).filter(Boolean).map(F).filter(({name:e,changeType:n})=>!!e&&!!n)}var p=require("child_process");function A(t){return t instanceof Buffer?t.toString("utf8"):t}function G(t){throw t.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${t}`)}function S(t,e,n){let r=n("git",t,{cwd:process.cwd(),env:process.env});if(r.error&&G(r.error),r.status===0)return A(r.stdout);throw new Error(e[r.status??0]||`internal git error: ${r.status} (${A(r.stderr)})`)}function N(t=p.spawnSync){let e={129:`'${process.cwd()}' does not seem to be a git repository`};return S(["status","--porcelain"],e,t)}function D(t,e,n=p.spawnSync){let r={128:`revision '${t}' ${e?`(or '${e}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return S(e?["diff",t,e,"--name-status"]:["diff",t,"--name-status"],r,n)}function h(t=p.spawnSync){return S(["rev-parse","HEAD"],{},t).slice(0,40)}var u=require("child_process");function L(t){return t instanceof Buffer?t.toString("utf8"):t}function w(t,e,n){let r=n("git",t,{cwd:process.cwd(),env:process.env}),s="",i="";return new Promise((c,a)=>{var g,x;(g=r.stdout)==null||g.on("data",o=>{s=s.concat(o)}),(x=r.stderr)==null||x.on("data",o=>{i=i.concat(o)}),r.on("close",o=>{o===0?c(L(s)):a(new Error(e[o??0]||`internal git error: ${o} (${L(i)})`))}),r.on("error",o=>{(o==null?void 0:o.code)==="ENOENT"?a(new Error("git executable not found")):a(new Error(`internal spawn error: ${o}`))})})}async function O(t=u.spawn){let e={129:`'${process.cwd()}' does not seem to be a git repository`};return await w(["status","--porcelain"],e,t)}async function P(t,e,n=u.spawn){let r={128:`revision '${t}' ${e?`(or '${e}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return await w(e?["diff",t,e,"--name-status"]:["diff",t,"--name-status"],r,n)}async function C(t=u.spawn){return(await w(["rev-parse","HEAD"],{},t)).slice(0,40)}var $=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(t,e=Y,n=V){return`^(${t.filter(s=>n.has(s.changeType)).map(({name:s})=>s).filter(s=>e.has((0,$.extname)(s))).map(s=>s.replace(/\./g,"\\.")).join("|")})$`}function E(t){return JSON.stringify(t,null,2)}var q=t=>t,z=new Map([["regex",I],["json",E]]);function f(t,e){return(z.get(e??"unknown")||q)(t)}async function K(t,e,n){let r=t||await C(),s=n||{},[i,c]=await Promise.all([P(r,e),s.trackedOnly?"":O()]),a=T(i);return s.trackedOnly||(a=a.concat(d(c).filter(({changeType:g})=>g==="untracked"))),f(a,s.outputType)}function Q(t,e,n){let r=t||h(),s=n||{},i=T(D(r,e));return s.trackedOnly||(i=i.concat(d(N()).filter(({changeType:c})=>c==="untracked"))),f(i,s.outputType)}function W(){return C()}function Z(){return h()}0&&(module.exports={getSHA,getSHASync,list,listSync});
|
@@ -1,7 +1,3 @@
|
|
1
|
-
// the security (and unicorn) plugins don't seem to detect named caption
|
2
|
-
// groups very well - false-flagging below regular expressions to be susceptible
|
3
|
-
// to redos attacks.
|
4
|
-
/* eslint-disable unicorn/no-unsafe-regex, security/detect-unsafe-regex */
|
5
1
|
import { EOL } from "node:os";
|
6
2
|
const DIFF_NAME_STATUS_LINE_PATTERN = /^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/;
|
7
3
|
const DIFF_SHORT_STATUS_LINE_PATTERN = /^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/;
|
@@ -17,10 +13,8 @@ const CHANGE_CHAR_2_CHANGE_TYPE = {
|
|
17
13
|
" ": "unmodified",
|
18
14
|
"?": "untracked",
|
19
15
|
"!": "ignored",
|
20
|
-
// X: "unknown"
|
21
16
|
};
|
22
17
|
function changeChar2ChangeType(pChar) {
|
23
|
-
// eslint-disable-next-line security/detect-object-injection
|
24
18
|
return CHANGE_CHAR_2_CHANGE_TYPE[pChar] ?? "unknown";
|
25
19
|
}
|
26
20
|
export function convertStatusLine(pString) {
|
@@ -30,7 +30,7 @@ export default function formatToRegex(pChanges, pExtensions = DEFAULT_EXTENSIONS
|
|
30
30
|
.filter((pChange) => pChangeTypes.has(pChange.changeType))
|
31
31
|
.map(({ name }) => name)
|
32
32
|
.filter((pName) => pExtensions.has(extname(pName)))
|
33
|
-
|
33
|
+
.map((pName) => pName.replace(/\./g, "\\."))
|
34
34
|
.join("|");
|
35
35
|
return `^(${lChanges})$`;
|
36
36
|
}
|
@@ -7,7 +7,6 @@ function stringifyOutStream(pError) {
|
|
7
7
|
return pError;
|
8
8
|
}
|
9
9
|
}
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
11
10
|
function throwSpawnError(pError) {
|
12
11
|
if (pError.code === "ENOENT") {
|
13
12
|
throw new Error("git executable not found");
|
@@ -16,13 +15,9 @@ function throwSpawnError(pError) {
|
|
16
15
|
throw new Error(`internal spawn error: ${pError}`);
|
17
16
|
}
|
18
17
|
}
|
19
|
-
/**
|
20
|
-
* @throws {Error}
|
21
|
-
*/
|
22
18
|
function getGitResultSync(pArguments, pErrorMap, pSpawnFunction) {
|
23
19
|
const lGitResult = pSpawnFunction("git", pArguments, {
|
24
20
|
cwd: process.cwd(),
|
25
|
-
// eslint-disable-next-line node/no-process-env
|
26
21
|
env: process.env,
|
27
22
|
});
|
28
23
|
if (lGitResult.error) {
|
@@ -36,19 +31,12 @@ function getGitResultSync(pArguments, pErrorMap, pSpawnFunction) {
|
|
36
31
|
`internal git error: ${lGitResult.status} (${stringifyOutStream(lGitResult.stderr)})`);
|
37
32
|
}
|
38
33
|
}
|
39
|
-
/**
|
40
|
-
* @throws {Error}
|
41
|
-
*/
|
42
34
|
export function getStatusShortSync(pSpawnFunction = spawnSync) {
|
43
35
|
const lErrorMap = {
|
44
36
|
129: `'${process.cwd()}' does not seem to be a git repository`,
|
45
37
|
};
|
46
38
|
return getGitResultSync(["status", "--porcelain"], lErrorMap, pSpawnFunction);
|
47
39
|
}
|
48
|
-
/**
|
49
|
-
*
|
50
|
-
* @throws {Error}
|
51
|
-
*/
|
52
40
|
export function getDiffLinesSync(pOldRevision, pNewRevision, pSpawnFunction = spawnSync) {
|
53
41
|
const lErrorMap = {
|
54
42
|
128: `revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
|
@@ -1,4 +1,3 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
1
|
import { spawn } from "node:child_process";
|
3
2
|
function stringifyOutStream(pBufferOrString) {
|
4
3
|
if (pBufferOrString instanceof Buffer) {
|
@@ -8,13 +7,9 @@ function stringifyOutStream(pBufferOrString) {
|
|
8
7
|
return pBufferOrString;
|
9
8
|
}
|
10
9
|
}
|
11
|
-
/**
|
12
|
-
* @throws {Error}
|
13
|
-
*/
|
14
10
|
function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
|
15
11
|
const lGit = pSpawnFunction("git", pArguments, {
|
16
12
|
cwd: process.cwd(),
|
17
|
-
// eslint-disable-next-line node/no-process-env
|
18
13
|
env: process.env,
|
19
14
|
});
|
20
15
|
let lStdOutData = "";
|
@@ -45,9 +40,6 @@ function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
|
|
45
40
|
});
|
46
41
|
});
|
47
42
|
}
|
48
|
-
/**
|
49
|
-
* @throws {Error}
|
50
|
-
*/
|
51
43
|
export async function getStatusShort(pSpawnFunction = spawn) {
|
52
44
|
const lErrorMap = {
|
53
45
|
129: `'${process.cwd()}' does not seem to be a git repository`,
|
@@ -55,10 +47,6 @@ export async function getStatusShort(pSpawnFunction = spawn) {
|
|
55
47
|
const lResult = await getGitResult(["status", "--porcelain"], lErrorMap, pSpawnFunction);
|
56
48
|
return lResult;
|
57
49
|
}
|
58
|
-
/**
|
59
|
-
*
|
60
|
-
* @throws {Error}
|
61
|
-
*/
|
62
50
|
export async function getDiffLines(pOldRevision, pNewRevision, pSpawnFunction = spawn) {
|
63
51
|
const lErrorMap = {
|
64
52
|
128: `revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
|
package/dist/esm/main.js
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
import { convertDiffLines, convertStatusLines, } from "./convert-to-change-object.js";
|
2
|
-
import
|
2
|
+
import * as primitivesSync from "./git-primitives-sync.js";
|
3
|
+
import * as primitives from "./git-primitives.js";
|
3
4
|
import format from "./formatters/format.js";
|
4
|
-
import { getDiffLines, getStatusShort, getSHA } from "./git-primitives.js";
|
5
|
-
export function listSync(pOldRevision, pNewRevision, pOptions) {
|
6
|
-
const lOldRevision = pOldRevision || getSHASync();
|
7
|
-
const lOptions = pOptions || {};
|
8
|
-
let lChanges = convertDiffLines(getDiffLinesSync(lOldRevision, pNewRevision));
|
9
|
-
if (!lOptions.trackedOnly) {
|
10
|
-
lChanges = lChanges.concat(convertStatusLines(getStatusShortSync()).filter(({ changeType }) => changeType === "untracked"));
|
11
|
-
}
|
12
|
-
return format(lChanges, lOptions.outputType);
|
13
|
-
}
|
14
5
|
export async function list(pOldRevision, pNewRevision, pOptions) {
|
15
|
-
const lOldRevision = pOldRevision || (await getSHA());
|
6
|
+
const lOldRevision = pOldRevision || (await primitives.getSHA());
|
16
7
|
const lOptions = pOptions || {};
|
17
8
|
const [lDiffLines, lStatusLines] = await Promise.all([
|
18
|
-
getDiffLines(lOldRevision, pNewRevision),
|
19
|
-
lOptions.trackedOnly ?
|
9
|
+
primitives.getDiffLines(lOldRevision, pNewRevision),
|
10
|
+
!lOptions.trackedOnly ? primitives.getStatusShort() : "",
|
20
11
|
]);
|
21
12
|
let lChanges = convertDiffLines(lDiffLines);
|
22
13
|
if (!lOptions.trackedOnly) {
|
@@ -24,5 +15,18 @@ export async function list(pOldRevision, pNewRevision, pOptions) {
|
|
24
15
|
}
|
25
16
|
return format(lChanges, lOptions.outputType);
|
26
17
|
}
|
27
|
-
export
|
28
|
-
|
18
|
+
export function listSync(pOldRevision, pNewRevision, pOptions) {
|
19
|
+
const lOldRevision = pOldRevision || primitivesSync.getSHASync();
|
20
|
+
const lOptions = pOptions || {};
|
21
|
+
let lChanges = convertDiffLines(primitivesSync.getDiffLinesSync(lOldRevision, pNewRevision));
|
22
|
+
if (!lOptions.trackedOnly) {
|
23
|
+
lChanges = lChanges.concat(convertStatusLines(primitivesSync.getStatusShortSync()).filter(({ changeType }) => changeType === "untracked"));
|
24
|
+
}
|
25
|
+
return format(lChanges, lOptions.outputType);
|
26
|
+
}
|
27
|
+
export function getSHA() {
|
28
|
+
return primitives.getSHA();
|
29
|
+
}
|
30
|
+
export function getSHASync() {
|
31
|
+
return primitivesSync.getSHASync();
|
32
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "watskeburt",
|
3
|
-
"version": "0.11.
|
3
|
+
"version": "0.11.2",
|
4
4
|
"description": "List files changed since a git revision",
|
5
5
|
"keywords": [
|
6
6
|
"git",
|
@@ -48,12 +48,12 @@
|
|
48
48
|
},
|
49
49
|
"devDependencies": {
|
50
50
|
"@types/mocha": "10.0.1",
|
51
|
-
"@types/node": "
|
52
|
-
"@typescript-eslint/eslint-plugin": "5.59.
|
51
|
+
"@types/node": "20.1.4",
|
52
|
+
"@typescript-eslint/eslint-plugin": "5.59.5",
|
53
53
|
"c8": "7.13.0",
|
54
|
-
"dependency-cruiser": "13.0.0
|
55
|
-
"esbuild": "0.17.
|
56
|
-
"eslint": "8.
|
54
|
+
"dependency-cruiser": "13.0.0",
|
55
|
+
"esbuild": "0.17.19",
|
56
|
+
"eslint": "8.40.0",
|
57
57
|
"eslint-config-moving-meadow": "4.0.2",
|
58
58
|
"eslint-config-prettier": "8.8.0",
|
59
59
|
"eslint-plugin-budapestian": "5.0.1",
|
@@ -62,7 +62,7 @@
|
|
62
62
|
"eslint-plugin-mocha": "10.1.0",
|
63
63
|
"eslint-plugin-node": "11.1.0",
|
64
64
|
"eslint-plugin-security": "1.7.1",
|
65
|
-
"eslint-plugin-unicorn": "
|
65
|
+
"eslint-plugin-unicorn": "47.0.0",
|
66
66
|
"mocha": "10.2.0",
|
67
67
|
"npm-run-all": "4.1.5",
|
68
68
|
"prettier": "2.8.8",
|
@@ -70,21 +70,12 @@
|
|
70
70
|
"typescript": "5.0.4",
|
71
71
|
"upem": "7.3.2"
|
72
72
|
},
|
73
|
-
"upem": {
|
74
|
-
"policies": [
|
75
|
-
{
|
76
|
-
"package": "dependency-cruiser",
|
77
|
-
"policy": "wanted",
|
78
|
-
"because": "we're beta testing v13 & policy 'latest' would downgraded it back to v12 again"
|
79
|
-
}
|
80
|
-
]
|
81
|
-
},
|
82
73
|
"engines": {
|
83
74
|
"node": "^14||^16||>=18"
|
84
75
|
},
|
85
76
|
"scripts": {
|
86
77
|
"build": "npm-run-all --sequential build:clean build:version build:dist",
|
87
|
-
"build:version": "ts-node
|
78
|
+
"build:version": "node --no-warnings --loader ts-node/esm tools/get-version.ts > bin/version.js",
|
88
79
|
"build:clean": "rm -rf dist/*",
|
89
80
|
"build:dist": "npm-run-all build:dist:*",
|
90
81
|
"build:dist:cjs": "esbuild src/main.ts --format=cjs --target=node14 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.cjs",
|