watskeburt 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- package/{src → bin}/cli.mjs +1 -1
- package/bin/version.mjs +1 -0
- package/dist/cjs-bundle.cjs +1 -0
- package/dist/esm-bundle.mjs +1 -0
- package/package.json +30 -27
- package/types/watskeburt.d.ts +2 -2
- package/dist/cjs-bundle.js +0 -1
- package/src/convert-to-change-object.mjs +0 -113
- package/src/formatters/format.mjs +0 -18
- package/src/formatters/json.mjs +0 -9
- package/src/formatters/regex.mjs +0 -49
- package/src/git-primitives.mjs +0 -99
- package/src/main.mjs +0 -29
- package/src/version.mjs +0 -1
package/{src → bin}/cli.mjs
RENAMED
package/bin/version.mjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export const VERSION = "0.8.1";
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";var i=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var N=(n,e)=>{for(var t in e)i(n,t,{get:e[t],enumerable:!0})},A=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of w(e))!x.call(n,r)&&r!==t&&i(n,r,{get:()=>e[r],enumerable:!(o=E(e,r))||o.enumerable});return n};var _=n=>A(i({},"__esModule",{value:!0}),n);var F={};N(F,{getSHASync:()=>j,listSync:()=>k});module.exports=_(F);var p=require("os"),D=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,L=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,B={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function g(n){return B[n]||"unknown"}function U(n){let e=n.match(L),t={};if(e!=null&&e.groups){let o=g(e.groups.stagedChangeType),r=g(e.groups.unStagedChangeType);t.changeType=o==="unmodified"?r:o,e.groups.newName?(t.name=e.groups.newName,t.oldName=e.groups.name):t.name=e.groups.name}return t}function $(n){let e=n.match(D),t={};return e!=null&&e.groups&&(t.changeType=g(e.groups.changeType),e.groups.newName?(t.name=e.groups.newName,t.oldName=e.groups.name):t.name=e.groups.name),t}function l(n){return n.split(p.EOL).filter(Boolean).map(U).filter(({name:e,changeType:t})=>Boolean(e)&&Boolean(t))}function d(n){return n.split(p.EOL).filter(Boolean).map($).filter(({name:e,changeType:t})=>Boolean(e)&&Boolean(t))}var a=require("child_process");function h(n){return n instanceof Buffer?n.toString("utf8"):n}function O(n){throw n.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${n}`)}function c(n,e,t){var r;let o=t("git",n,{cwd:process.cwd(),env:process.env});if(o.error&&O(o.error),o.status===0)return h(o.stdout);throw new Error(e[(r=o.status)!=null?r:0]||`internal git error: ${o.status} (${h(o.stderr)})`)}function y(n=a.spawnSync){let e={129:`'${process.cwd()}' does not seem to be a git repository`};return c(["status","--porcelain"],e,n)}function S(n,e,t=a.spawnSync){let o={128:`revision '${n}' ${e?`(or '${e}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return c(e?["diff",n,e,"--name-status"]:["diff",n,"--name-status"],o,t)}function f(n=a.spawnSync){return c(["rev-parse","HEAD"],{},n).slice(0,40)}var C=require("path"),M=new Set([".cjs",".cjsx",".coffee",".csx",".cts",".js",".json",".jsx",".litcoffee",".ls",".mjs",".mts",".svelte",".ts",".tsx",".vue",".vuex"]),P=new Set(["modified","added","renamed","copied","untracked"]);function u(n,e=M,t=P){return`^(${n.filter(r=>t.has(r.changeType)).map(({name:r})=>r).filter(r=>e.has((0,C.extname)(r))).join("|")})$`}var R=2;function m(n){return JSON.stringify(n,null,R)}var v=n=>n,H=new Map([["regex",u],["json",m]]);function T(n,e){return(H.get(e!=null?e:"unknown")||v)(n)}function j(){return f()}function k(n,e,t){let o=n||f(),r=t||{},s=d(S(o,e));return r.trackedOnly||(s=s.concat(l(y()).filter(({changeType:I})=>I==="untracked"))),T(s,r.outputType)}0&&(module.exports={getSHASync,listSync});
|
@@ -0,0 +1 @@
|
|
1
|
+
import{EOL as m}from"node:os";var C=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,I=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,E={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function s(n){return E[n]||"unknown"}function w(n){let e=n.match(I),t={};if(e!=null&&e.groups){let r=s(e.groups.stagedChangeType),o=s(e.groups.unStagedChangeType);t.changeType=r==="unmodified"?o:r,e.groups.newName?(t.name=e.groups.newName,t.oldName=e.groups.name):t.name=e.groups.name}return t}function x(n){let e=n.match(C),t={};return e!=null&&e.groups&&(t.changeType=s(e.groups.changeType),e.groups.newName?(t.name=e.groups.newName,t.oldName=e.groups.name):t.name=e.groups.name),t}function T(n){return n.split(m).filter(Boolean).map(w).filter(({name:e,changeType:t})=>Boolean(e)&&Boolean(t))}function l(n){return n.split(m).filter(Boolean).map(x).filter(({name:e,changeType:t})=>Boolean(e)&&Boolean(t))}import{spawnSync as i}from"node:child_process";function d(n){return n instanceof Buffer?n.toString("utf8"):n}function N(n){throw n.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${n}`)}function g(n,e,t){let r=t("git",n,{cwd:process.cwd(),env:process.env});if(r.error&&N(r.error),r.status===0)return d(r.stdout);throw new Error(e[r.status??0]||`internal git error: ${r.status} (${d(r.stderr)})`)}function h(n=i){let e={129:`'${process.cwd()}' does not seem to be a git repository`};return g(["status","--porcelain"],e,n)}function y(n,e,t=i){let r={128:`revision '${n}' ${e?`(or '${e}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return g(e?["diff",n,e,"--name-status"]:["diff",n,"--name-status"],r,t)}function p(n=i){return g(["rev-parse","HEAD"],{},n).slice(0,40)}import{extname as A}from"node:path";var _=new Set([".cjs",".cjsx",".coffee",".csx",".cts",".js",".json",".jsx",".litcoffee",".ls",".mjs",".mts",".svelte",".ts",".tsx",".vue",".vuex"]),D=new Set(["modified","added","renamed","copied","untracked"]);function u(n,e=_,t=D){return`^(${n.filter(o=>t.has(o.changeType)).map(({name:o})=>o).filter(o=>e.has(A(o))).join("|")})$`}var L=2;function c(n){return JSON.stringify(n,null,L)}var O=n=>n,B=new Map([["regex",u],["json",c]]);function f(n,e){return(B.get(e??"unknown")||O)(n)}function Y(){return p()}function V(n,e,t){let r=n||p(),o=t||{},a=l(y(r,e));return o.trackedOnly||(a=a.concat(T(h()).filter(({changeType:S})=>S==="untracked"))),f(a,o.outputType)}export{Y as getSHASync,V as listSync};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "watskeburt",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.1",
|
4
4
|
"description": "List files changed since a git revision",
|
5
5
|
"keywords": [
|
6
6
|
"git",
|
@@ -19,24 +19,24 @@
|
|
19
19
|
"url": "https://sverweij.github.io"
|
20
20
|
},
|
21
21
|
"license": "MIT",
|
22
|
-
"bin": "
|
23
|
-
"main": "dist/cjs-bundle.
|
24
|
-
"module": "
|
22
|
+
"bin": "bin/cli.mjs",
|
23
|
+
"main": "dist/cjs-bundle.cjs",
|
24
|
+
"module": "dist/esm-bundle.mjs",
|
25
|
+
"type": "module",
|
25
26
|
"sideEffects": false,
|
26
27
|
"exports": {
|
27
28
|
".": [
|
28
29
|
{
|
29
|
-
"import": "./
|
30
|
-
"require": "./dist/cjs-bundle.
|
30
|
+
"import": "./dist/esm-bundle.mjs",
|
31
|
+
"require": "./dist/cjs-bundle.cjs"
|
31
32
|
},
|
32
|
-
"./dist/cjs-bundle.
|
33
|
+
"./dist/cjs-bundle.cjs"
|
33
34
|
]
|
34
35
|
},
|
35
36
|
"types": "types/watskeburt.d.ts",
|
36
37
|
"files": [
|
37
|
-
"
|
38
|
+
"bin",
|
38
39
|
"dist",
|
39
|
-
"!src/**/*.spec.mjs",
|
40
40
|
"!**/*.DS_Store",
|
41
41
|
"types",
|
42
42
|
"LICENSE",
|
@@ -66,6 +66,7 @@
|
|
66
66
|
"mocha": "10.1.0",
|
67
67
|
"npm-run-all": "4.1.5",
|
68
68
|
"prettier": "2.7.1",
|
69
|
+
"ts-node": "10.9.1",
|
69
70
|
"typescript": "4.8.4",
|
70
71
|
"upem": "7.3.0"
|
71
72
|
},
|
@@ -74,28 +75,30 @@
|
|
74
75
|
},
|
75
76
|
"scripts": {
|
76
77
|
"build": "npm-run-all --sequential build:version build:dist",
|
77
|
-
"build:version": "node tools/get-version.mjs >
|
78
|
-
"build:dist": "
|
78
|
+
"build:version": "node tools/get-version.mjs > bin/version.mjs",
|
79
|
+
"build:dist": "npm-run-all build:dist:*",
|
80
|
+
"build:dist:cjs": "esbuild src/main.ts --format=cjs --target=node12 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.cjs",
|
81
|
+
"build:dist:esm": "esbuild src/main.ts --format=esm --target=node16 --platform=node --bundle --global-name=wkbtesm --minify --outfile=dist/esm-bundle.mjs",
|
79
82
|
"check": "npm-run-all --parallel --aggregate-output lint depcruise test:cover",
|
80
83
|
"clean": "rm -rf dist",
|
81
|
-
"test": "mocha",
|
82
|
-
"test:cover": "c8 --check-coverage --statements 100 --branches 100 --functions 100 --lines 100 --exclude \"**/*.spec.
|
83
|
-
"depcruise": "depcruise src types --config --cache",
|
84
|
-
"depcruise:graph": "depcruise src types --cache --include-only '^(src|types)' --config --output-type dot | dot -T svg | tee docs/dependency-graph.svg | depcruise-wrap-stream-in-html > docs/dependency-graph.html",
|
85
|
-
"depcruise:graph:archi": "depcruise src --cache --include-only '^(src)' --config --output-type archi | dot -T svg | depcruise-wrap-stream-in-html > docs/high-level-dependency-graph.html",
|
86
|
-
"depcruise:graph:dev": "depcruise src --cache --include-only '^(src)' --prefix vscode://file/$(pwd)/ --config --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
|
87
|
-
"depcruise:graph:diff:dev": "depcruise src types --cache --include-only '^(src|types)' --
|
88
|
-
"depcruise:graph:diff:mermaid": "depcruise src types --cache --include-only '^(src|types)' --config --output-type mermaid --output-to - --
|
89
|
-
"depcruise:html": "depcruise src types --progress --cache --config --output-type err-html --output-to dependency-violation-report.html",
|
90
|
-
"depcruise:text": "depcruise src types --progress --cache --config --output-type text",
|
91
|
-
"depcruise:focus": "depcruise src types --progress --cache --config --output-type text --focus",
|
92
|
-
"depcruise:reaches": "depcruise src types --progress --cache --config --output-type text --reaches",
|
84
|
+
"test": "NODE_OPTIONS=--no-warnings mocha",
|
85
|
+
"test:cover": "NODE_OPTIONS=--no-warnings c8 --check-coverage --statements 100 --branches 100 --functions 100 --lines 100 --exclude \"**/*.spec.ts\" --reporter text-summary --reporter html --reporter json-summary mocha",
|
86
|
+
"depcruise": "depcruise bin dist src types --config --cache",
|
87
|
+
"depcruise:graph": "depcruise bin src types --cache --include-only '^(bin|dist|src|types)' --config --output-type dot | dot -T svg | tee docs/dependency-graph.svg | depcruise-wrap-stream-in-html > docs/dependency-graph.html",
|
88
|
+
"depcruise:graph:archi": "depcruise bin src --cache --include-only '^(bin|dist|src|types)' --config --output-type archi | dot -T svg | depcruise-wrap-stream-in-html > docs/high-level-dependency-graph.html",
|
89
|
+
"depcruise:graph:dev": "depcruise bin dist src types --cache --include-only '^(bin|dist|src|types)' --prefix vscode://file/$(pwd)/ --config --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
|
90
|
+
"depcruise:graph:diff:dev": "depcruise bin dist src types --cache --include-only '^(bin|dist|src|types)' --highlight \"$(node bin/cli.mjs main -T regex)\" --prefix vscode://file/$(pwd)/ --config --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
|
91
|
+
"depcruise:graph:diff:mermaid": "depcruise bin dist src types --cache --include-only '^(bin|dist|src|types)' --config --output-type mermaid --output-to - --highlight \"$(node bin/cli.mjs $SHA -T regex)\"",
|
92
|
+
"depcruise:html": "depcruise bin src types --progress --cache --config --output-type err-html --output-to dependency-violation-report.html",
|
93
|
+
"depcruise:text": "depcruise bin src types --progress --cache --config --output-type text",
|
94
|
+
"depcruise:focus": "depcruise bin src types --progress --cache --config --output-type text --focus",
|
95
|
+
"depcruise:reaches": "depcruise bin src types --progress --cache --config --output-type text --reaches",
|
93
96
|
"lint": "npm-run-all --parallel --aggregate-output lint:format lint:eslint lint:types",
|
94
97
|
"lint:fix": "npm-run-all --parallel --aggregate-output lint:format:fix lint:eslint:fix",
|
95
|
-
"lint:eslint": "eslint src types tools --cache --cache-location node_modules/.cache/eslint/",
|
96
|
-
"lint:eslint:fix": "eslint src types tools --fix --cache --cache-location node_modules/.cache/eslint/",
|
97
|
-
"lint:format": "prettier --check \"{src,tools}/**/*.mjs\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
|
98
|
-
"lint:format:fix": "prettier --loglevel warn --write \"{src,tools}/**/*.mjs\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
|
98
|
+
"lint:eslint": "eslint bin src types tools --cache --cache-location node_modules/.cache/eslint/",
|
99
|
+
"lint:eslint:fix": "eslint bin src types tools --fix --cache --cache-location node_modules/.cache/eslint/",
|
100
|
+
"lint:format": "prettier --check \"{bin,src,tools}/**/*.mjs\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
|
101
|
+
"lint:format:fix": "prettier --loglevel warn --write \"{bin,src,tools}/**/*.mjs\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
|
99
102
|
"lint:types": "tsc",
|
100
103
|
"scm:stage": "git add .",
|
101
104
|
"update-dependencies": "run-s upem:update upem:install lint:fix check",
|
package/types/watskeburt.d.ts
CHANGED
@@ -34,14 +34,14 @@ export interface IOptions {
|
|
34
34
|
* The type of output to deliver. Defaults to "object" - in which case
|
35
35
|
* the listSync function returns an IChange[] object
|
36
36
|
*/
|
37
|
-
outputType
|
37
|
+
outputType?: outputTypeType;
|
38
38
|
/**
|
39
39
|
* When true _only_ takes already tracked files into account.
|
40
40
|
* When false also takes untracked files into account.
|
41
41
|
*
|
42
42
|
* Defaults to false.
|
43
43
|
*/
|
44
|
-
trackedOnly
|
44
|
+
trackedOnly?: boolean;
|
45
45
|
}
|
46
46
|
|
47
47
|
/**
|
package/dist/cjs-bundle.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";var i=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var _=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},D=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!A.call(e,o)&&o!==n&&i(e,o,{get:()=>t[o],enumerable:!(r=x(t,o))||r.enumerable});return e};var L=e=>D(i({},"__esModule",{value:!0}),e);var P={};_(P,{getSHASync:()=>k,listSync:()=>F});module.exports=L(P);var c=require("os"),R=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,O=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,U={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function u(e){return U[e]||"unknown"}function $(e){let t=e.match(O),n={};if(t){let r=u(t.groups.stagedChangeType),o=u(t.groups.unStagedChangeType);n.changeType=r==="unmodified"?o:r,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function v(e){let t=e.match(R),n={};return t&&(n.changeType=u(t.groups.changeType),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function T(e){return e.split(c.EOL).filter(Boolean).map($).filter(({changeType:t})=>Boolean(t))}function S(e){return e.split(c.EOL).filter(Boolean).map(v).filter(({changeType:t})=>Boolean(t))}var s=require("child_process");function h(e){return e instanceof Buffer?e.toString("utf8"):e}function M(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function f(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env});if(r.error&&M(r.error),r.status===0)return h(r.stdout);throw new Error(t[r.status]||`internal git error: ${r.status} (${h(r.stderr)})`)}function N(e=s.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return f(["status","--porcelain"],t,e)}function y(e,t,n=s.spawnSync){let r={128:`revision '${e}' ${t?`(or '${t}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return f(t?["diff",e,t,"--name-status"]:["diff",e,"--name-status"],r,n)}function l(e=s.spawnSync){return f(["rev-parse","HEAD"],{},e).slice(0,40)}var E=require("path"),B=new Set([".cjs",".cjsx",".coffee",".csx",".cts",".js",".json",".jsx",".litcoffee",".ls",".mjs",".mts",".svelte",".ts",".tsx",".vue",".vuex"]),H=new Set(["modified","added","renamed","copied","untracked"]);function m(e,t=B,n=H){return`^(${e.filter(o=>n.has(o.changeType)).map(({name:o})=>o).filter(o=>t.has((0,E.extname)(o))).join("|")})$`}function p(e){return JSON.stringify(e,null,2)}var j=e=>e,I=new Map([["regex",m],["json",p]]);function g(e,t){return(I.get(t)||j)(e)}function k(){return l()}function F(e,t,n){let r=e||l(),o=t||null,d=n||{},a=S(y(r,o));return d.trackedOnly||(a=a.concat(T(N()).filter(({changeType:w})=>w==="untracked"))),g(a,d.outputType)}0&&(module.exports={getSHASync,listSync});
|
@@ -1,113 +0,0 @@
|
|
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
|
-
import { EOL } from "node:os";
|
6
|
-
|
7
|
-
const DIFF_NAME_STATUS_LINE_PATTERN =
|
8
|
-
/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/;
|
9
|
-
const DIFF_SHORT_STATUS_LINE_PATTERN =
|
10
|
-
/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/;
|
11
|
-
|
12
|
-
const CHANGE_CHAR_2_CHANGE_TYPE = {
|
13
|
-
A: "added",
|
14
|
-
C: "copied",
|
15
|
-
D: "deleted",
|
16
|
-
M: "modified",
|
17
|
-
R: "renamed",
|
18
|
-
T: "type changed",
|
19
|
-
U: "unmerged",
|
20
|
-
B: "pairing broken",
|
21
|
-
" ": "unmodified",
|
22
|
-
"?": "untracked",
|
23
|
-
"!": "ignored",
|
24
|
-
// X: "unknown"
|
25
|
-
};
|
26
|
-
|
27
|
-
function changeChar2ChangeType(pChar) {
|
28
|
-
// eslint-disable-next-line security/detect-object-injection
|
29
|
-
return CHANGE_CHAR_2_CHANGE_TYPE[pChar] || "unknown";
|
30
|
-
}
|
31
|
-
|
32
|
-
/**
|
33
|
-
*
|
34
|
-
* @param {string} pString
|
35
|
-
* @returns {import('../types/watskeburt').IChange}
|
36
|
-
*/
|
37
|
-
export function convertStatusLine(pString) {
|
38
|
-
const lMatchResult = pString.match(DIFF_SHORT_STATUS_LINE_PATTERN);
|
39
|
-
/** @type {import('../types/watskeburt').IChange} */
|
40
|
-
let lReturnValue = {};
|
41
|
-
|
42
|
-
if (lMatchResult) {
|
43
|
-
const lStagedChangeType = changeChar2ChangeType(
|
44
|
-
lMatchResult.groups.stagedChangeType
|
45
|
-
);
|
46
|
-
const lUnStagedChangeType = changeChar2ChangeType(
|
47
|
-
lMatchResult.groups.unStagedChangeType
|
48
|
-
);
|
49
|
-
|
50
|
-
lReturnValue.changeType =
|
51
|
-
lStagedChangeType === "unmodified"
|
52
|
-
? lUnStagedChangeType
|
53
|
-
: lStagedChangeType;
|
54
|
-
|
55
|
-
if (lMatchResult.groups.newName) {
|
56
|
-
lReturnValue.name = lMatchResult.groups.newName;
|
57
|
-
lReturnValue.oldName = lMatchResult.groups.name;
|
58
|
-
} else {
|
59
|
-
lReturnValue.name = lMatchResult.groups.name;
|
60
|
-
}
|
61
|
-
}
|
62
|
-
return lReturnValue;
|
63
|
-
}
|
64
|
-
|
65
|
-
/**
|
66
|
-
*
|
67
|
-
* @param {string} pString
|
68
|
-
* @returns {import('../types/watskeburt').IChange}
|
69
|
-
*/
|
70
|
-
export function convertDiffLine(pString) {
|
71
|
-
const lMatchResult = pString.match(DIFF_NAME_STATUS_LINE_PATTERN);
|
72
|
-
/** @type {import('../types/watskeburt').IChange} */
|
73
|
-
let lReturnValue = {};
|
74
|
-
|
75
|
-
if (lMatchResult) {
|
76
|
-
lReturnValue.changeType = changeChar2ChangeType(
|
77
|
-
lMatchResult.groups.changeType
|
78
|
-
);
|
79
|
-
if (lMatchResult.groups.newName) {
|
80
|
-
lReturnValue.name = lMatchResult.groups.newName;
|
81
|
-
lReturnValue.oldName = lMatchResult.groups.name;
|
82
|
-
} else {
|
83
|
-
lReturnValue.name = lMatchResult.groups.name;
|
84
|
-
}
|
85
|
-
}
|
86
|
-
return lReturnValue;
|
87
|
-
}
|
88
|
-
|
89
|
-
/**
|
90
|
-
*
|
91
|
-
* @param {string} pString
|
92
|
-
* @returns {import('../types/watskeburt').IChange[]}
|
93
|
-
*/
|
94
|
-
export function convertStatusLines(pString) {
|
95
|
-
return pString
|
96
|
-
.split(EOL)
|
97
|
-
.filter(Boolean)
|
98
|
-
.map(convertStatusLine)
|
99
|
-
.filter(({ changeType }) => Boolean(changeType));
|
100
|
-
}
|
101
|
-
|
102
|
-
/**
|
103
|
-
*
|
104
|
-
* @param {string} pString
|
105
|
-
* @returns {import('../types/watskeburt').IChange[]}
|
106
|
-
*/
|
107
|
-
export function convertDiffLines(pString) {
|
108
|
-
return pString
|
109
|
-
.split(EOL)
|
110
|
-
.filter(Boolean)
|
111
|
-
.map(convertDiffLine)
|
112
|
-
.filter(({ changeType }) => Boolean(changeType));
|
113
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import formatToRegex from "./regex.mjs";
|
2
|
-
import formatToJSON from "./json.mjs";
|
3
|
-
|
4
|
-
const identity = (pX) => pX;
|
5
|
-
const OUTPUT_TYPE_TO_FUNCTION = new Map([
|
6
|
-
["regex", formatToRegex],
|
7
|
-
["json", formatToJSON],
|
8
|
-
]);
|
9
|
-
|
10
|
-
/**
|
11
|
-
*
|
12
|
-
* @param {import("../../types/watskeburt.js").IChange[]} pChanges
|
13
|
-
* @param {import("../../types/watskeburt.js").outputTypeType} pOutputType
|
14
|
-
* @returns {string|import("../../types/watskeburt.js").IChange[]}
|
15
|
-
*/
|
16
|
-
export default function format(pChanges, pOutputType) {
|
17
|
-
return (OUTPUT_TYPE_TO_FUNCTION.get(pOutputType) || identity)(pChanges);
|
18
|
-
}
|
package/src/formatters/json.mjs
DELETED
package/src/formatters/regex.mjs
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
import { extname } from "node:path";
|
2
|
-
|
3
|
-
const DEFAULT_EXTENSIONS = new Set([
|
4
|
-
".cjs",
|
5
|
-
".cjsx",
|
6
|
-
".coffee",
|
7
|
-
".csx",
|
8
|
-
".cts",
|
9
|
-
".js",
|
10
|
-
".json",
|
11
|
-
".jsx",
|
12
|
-
".litcoffee",
|
13
|
-
".ls",
|
14
|
-
".mjs",
|
15
|
-
".mts",
|
16
|
-
".svelte",
|
17
|
-
".ts",
|
18
|
-
".tsx",
|
19
|
-
".vue",
|
20
|
-
".vuex",
|
21
|
-
]);
|
22
|
-
|
23
|
-
const DEFAULT_CHANGE_TYPES = new Set([
|
24
|
-
"modified",
|
25
|
-
"added",
|
26
|
-
"renamed",
|
27
|
-
"copied",
|
28
|
-
"untracked",
|
29
|
-
]);
|
30
|
-
/**
|
31
|
-
*
|
32
|
-
* @param {import('../types/watskeburt').IChange[]} pChanges
|
33
|
-
* @param {Set<string>} pExtensions
|
34
|
-
* @param {Set<import('../types/watskeburt').changeTypeType>} pChangeTypes
|
35
|
-
* @return {string}
|
36
|
-
*/
|
37
|
-
export default function formatToRegex(
|
38
|
-
pChanges,
|
39
|
-
pExtensions = DEFAULT_EXTENSIONS,
|
40
|
-
pChangeTypes = DEFAULT_CHANGE_TYPES
|
41
|
-
) {
|
42
|
-
const lChanges = pChanges
|
43
|
-
.filter((pChange) => pChangeTypes.has(pChange.changeType))
|
44
|
-
.map(({ name }) => name)
|
45
|
-
.filter((pName) => pExtensions.has(extname(pName)))
|
46
|
-
// .replace(/\./g, "\\\\.")
|
47
|
-
.join("|");
|
48
|
-
return `^(${lChanges})$`;
|
49
|
-
}
|
package/src/git-primitives.mjs
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
2
|
-
|
3
|
-
function stringifyOutStream(pError) {
|
4
|
-
if (pError instanceof Buffer) {
|
5
|
-
return pError.toString("utf8");
|
6
|
-
} else {
|
7
|
-
return pError;
|
8
|
-
}
|
9
|
-
}
|
10
|
-
|
11
|
-
function throwSpawnError(pError) {
|
12
|
-
if (pError.code === "ENOENT") {
|
13
|
-
throw new Error("git executable not found");
|
14
|
-
} else {
|
15
|
-
throw new Error(`internal spawn error: ${pError}`);
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
/**
|
20
|
-
*
|
21
|
-
* @param {string[]} pArguments
|
22
|
-
* @return {string}
|
23
|
-
* @throws {Error}
|
24
|
-
*/
|
25
|
-
function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
|
26
|
-
const lGitResult = pSpawnFunction("git", pArguments, {
|
27
|
-
cwd: process.cwd(),
|
28
|
-
// eslint-disable-next-line node/no-process-env
|
29
|
-
env: process.env,
|
30
|
-
});
|
31
|
-
|
32
|
-
if (lGitResult.error) {
|
33
|
-
throwSpawnError(lGitResult.error);
|
34
|
-
}
|
35
|
-
|
36
|
-
if (lGitResult.status === 0) {
|
37
|
-
return stringifyOutStream(lGitResult.stdout);
|
38
|
-
} else {
|
39
|
-
throw new Error(
|
40
|
-
pErrorMap[lGitResult.status] ||
|
41
|
-
`internal git error: ${lGitResult.status} (${stringifyOutStream(
|
42
|
-
lGitResult.stderr
|
43
|
-
)})`
|
44
|
-
);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
/**
|
49
|
-
*
|
50
|
-
* @returns {string}
|
51
|
-
* @throws {Error}
|
52
|
-
*/
|
53
|
-
export function getStatusShort(pSpawnFunction = spawnSync) {
|
54
|
-
const lErrorMap = {
|
55
|
-
129: `'${process.cwd()}' does not seem to be a git repository`,
|
56
|
-
};
|
57
|
-
return getGitResult(["status", "--porcelain"], lErrorMap, pSpawnFunction);
|
58
|
-
}
|
59
|
-
|
60
|
-
/**
|
61
|
-
*
|
62
|
-
* @param {string} pOldRevision the target to compare against (e.g. branch name, commit, tag etc)
|
63
|
-
* @param {string} pNewRevision Newer revision against which to compare. Leave out or pass
|
64
|
-
* null when you want to compare against the working tree
|
65
|
-
* @return {string}
|
66
|
-
* @throws {Error}
|
67
|
-
*/
|
68
|
-
export function getDiffLines(
|
69
|
-
pOldRevision,
|
70
|
-
pNewRevision,
|
71
|
-
pSpawnFunction = spawnSync
|
72
|
-
) {
|
73
|
-
const lErrorMap = {
|
74
|
-
128: `revision '${pOldRevision}' ${
|
75
|
-
pNewRevision ? `(or '${pNewRevision}') ` : ""
|
76
|
-
}unknown`,
|
77
|
-
129: `'${process.cwd()}' does not seem to be a git repository`,
|
78
|
-
};
|
79
|
-
|
80
|
-
return getGitResult(
|
81
|
-
pNewRevision
|
82
|
-
? ["diff", pOldRevision, pNewRevision, "--name-status"]
|
83
|
-
: ["diff", pOldRevision, "--name-status"],
|
84
|
-
lErrorMap,
|
85
|
-
pSpawnFunction
|
86
|
-
);
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
*
|
90
|
-
* @returns {string}
|
91
|
-
*/
|
92
|
-
export function getSHA1(pSpawnFunction = spawnSync) {
|
93
|
-
const lSha1Length = 40;
|
94
|
-
|
95
|
-
return getGitResult(["rev-parse", "HEAD"], {}, pSpawnFunction).slice(
|
96
|
-
0,
|
97
|
-
lSha1Length
|
98
|
-
);
|
99
|
-
}
|
package/src/main.mjs
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
convertDiffLines,
|
3
|
-
convertStatusLines,
|
4
|
-
} from "./convert-to-change-object.mjs";
|
5
|
-
import { getDiffLines, getSHA1, getStatusShort } from "./git-primitives.mjs";
|
6
|
-
import format from "./formatters/format.mjs";
|
7
|
-
|
8
|
-
/** @type {import("../types/watskeburt").getSHASync} */
|
9
|
-
export function getSHASync() {
|
10
|
-
return getSHA1();
|
11
|
-
}
|
12
|
-
|
13
|
-
/** @type {import("../types/watskeburt").listSync} */
|
14
|
-
export function listSync(pOldRevision, pNewRevision, pOptions) {
|
15
|
-
const lOldRevision = pOldRevision || getSHA1();
|
16
|
-
const lNewRevision = pNewRevision || null;
|
17
|
-
const lOptions = pOptions || {};
|
18
|
-
|
19
|
-
let lChanges = convertDiffLines(getDiffLines(lOldRevision, lNewRevision));
|
20
|
-
|
21
|
-
if (!lOptions.trackedOnly) {
|
22
|
-
lChanges = lChanges.concat(
|
23
|
-
convertStatusLines(getStatusShort()).filter(
|
24
|
-
({ changeType }) => changeType === "untracked"
|
25
|
-
)
|
26
|
-
);
|
27
|
-
}
|
28
|
-
return format(lChanges, lOptions.outputType);
|
29
|
-
}
|
package/src/version.mjs
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export const VERSION = "0.8.0";
|