watskeburt 0.6.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +9 -2
- package/dist/cjs-bundle.js +1 -1
- package/package.json +29 -23
- package/src/cli.mjs +6 -4
- package/src/convert-to-change-object.mjs +1 -1
- package/src/formatters/regex.mjs +2 -0
- package/src/git-primitives.mjs +14 -3
- package/src/main.mjs +4 -2
- package/src/version.mjs +1 -1
- package/types/watskeburt.d.ts +3 -0
package/README.md
CHANGED
@@ -35,9 +35,16 @@ console.log(getSHASync());
|
|
35
35
|
/** @type {import('watskeburt').IChange[]} */
|
36
36
|
const lChangedFiles = listSync("main");
|
37
37
|
|
38
|
-
//
|
38
|
+
// list all files that differ between 'v0.6.1' and 'v0.7.1' (by definition
|
39
|
+
// won't include files staged for commit and/ or not under revision control)
|
40
|
+
/** @type {import('watskeburt').IChange[]} */
|
41
|
+
const lChangedFiles = listSync("v0.6.1", "v0.7.1");
|
42
|
+
|
43
|
+
// As a third parameter you can pass some options
|
44
|
+
// (pass null as the second parameter if you only want to compare between
|
45
|
+
// a revision and the working tree):
|
39
46
|
/** @type {import('watskeburt').IChange[]|string} */
|
40
|
-
const lChangedFiles = listSync("main", {
|
47
|
+
const lChangedFiles = listSync("main", null, {
|
41
48
|
trackedOnly: false, // when set to true leaves out files not under revision control
|
42
49
|
outputType: "object", // other options: "json" and "regex" (as used in the CLI)
|
43
50
|
});
|
package/dist/cjs-bundle.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var
|
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});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "watskeburt",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.8.0",
|
4
4
|
"description": "List files changed since a git revision",
|
5
5
|
"keywords": [
|
6
6
|
"git",
|
@@ -44,28 +44,30 @@
|
|
44
44
|
"README.md"
|
45
45
|
],
|
46
46
|
"dependencies": {
|
47
|
-
"commander": "
|
47
|
+
"commander": "9.4.1"
|
48
48
|
},
|
49
49
|
"devDependencies": {
|
50
|
-
"@types/mocha": "
|
51
|
-
"@types/node": "
|
52
|
-
"@typescript-eslint/eslint-plugin": "
|
53
|
-
"c8": "
|
54
|
-
"dependency-cruiser": "
|
55
|
-
"esbuild": "
|
56
|
-
"eslint": "
|
57
|
-
"eslint-config-moving-meadow": "
|
58
|
-
"eslint-config-prettier": "
|
59
|
-
"eslint-plugin-budapestian": "
|
60
|
-
"eslint-plugin-
|
61
|
-
"eslint-plugin-
|
62
|
-
"eslint-plugin-
|
63
|
-
"eslint-plugin-
|
64
|
-
"eslint-plugin-
|
65
|
-
"
|
66
|
-
"
|
67
|
-
"
|
68
|
-
"
|
50
|
+
"@types/mocha": "10.0.0",
|
51
|
+
"@types/node": "18.11.3",
|
52
|
+
"@typescript-eslint/eslint-plugin": "5.40.1",
|
53
|
+
"c8": "7.12.0",
|
54
|
+
"dependency-cruiser": "11.17.0",
|
55
|
+
"esbuild": "0.15.12",
|
56
|
+
"eslint": "8.26.0",
|
57
|
+
"eslint-config-moving-meadow": "4.0.2",
|
58
|
+
"eslint-config-prettier": "8.5.0",
|
59
|
+
"eslint-plugin-budapestian": "5.0.1",
|
60
|
+
"eslint-plugin-eslint-comments": "3.2.0",
|
61
|
+
"eslint-plugin-import": "2.26.0",
|
62
|
+
"eslint-plugin-mocha": "10.1.0",
|
63
|
+
"eslint-plugin-node": "11.1.0",
|
64
|
+
"eslint-plugin-security": "1.5.0",
|
65
|
+
"eslint-plugin-unicorn": "44.0.2",
|
66
|
+
"mocha": "10.1.0",
|
67
|
+
"npm-run-all": "4.1.5",
|
68
|
+
"prettier": "2.7.1",
|
69
|
+
"typescript": "4.8.4",
|
70
|
+
"upem": "7.3.0"
|
69
71
|
},
|
70
72
|
"engines": {
|
71
73
|
"node": "^12.20||^14||>=16"
|
@@ -76,8 +78,8 @@
|
|
76
78
|
"build:dist": "esbuild src/main.mjs --format=cjs --target=node12 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.js",
|
77
79
|
"check": "npm-run-all --parallel --aggregate-output lint depcruise test:cover",
|
78
80
|
"clean": "rm -rf dist",
|
79
|
-
"test": "mocha
|
80
|
-
"test:cover": "c8 --check-coverage --statements 100 --branches 100 --functions 100 --lines 100 --exclude \"**/*.spec.mjs\" --reporter text-summary --reporter html --reporter json-summary
|
81
|
+
"test": "mocha",
|
82
|
+
"test:cover": "c8 --check-coverage --statements 100 --branches 100 --functions 100 --lines 100 --exclude \"**/*.spec.mjs\" --reporter text-summary --reporter html --reporter json-summary mocha",
|
81
83
|
"depcruise": "depcruise src types --config --cache",
|
82
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",
|
83
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",
|
@@ -96,6 +98,10 @@
|
|
96
98
|
"lint:format:fix": "prettier --loglevel warn --write \"{src,tools}/**/*.mjs\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
|
97
99
|
"lint:types": "tsc",
|
98
100
|
"scm:stage": "git add .",
|
101
|
+
"update-dependencies": "run-s upem:update upem:install lint:fix check",
|
102
|
+
"upem-outdated": "npm outdated --json --long | upem --dry-run",
|
103
|
+
"upem:install": "npm install",
|
104
|
+
"upem:update": "npm outdated --json --long | upem | pbcopy && pbpaste",
|
99
105
|
"version": "npm-run-all --sequential clean build lint depcruise:graph scm:stage"
|
100
106
|
},
|
101
107
|
"eslintIgnore": [
|
package/src/cli.mjs
CHANGED
@@ -7,17 +7,19 @@ import { VERSION } from "./version.mjs";
|
|
7
7
|
|
8
8
|
program
|
9
9
|
.description(
|
10
|
-
"lists files & their statuses since [revision]
|
11
|
-
"
|
10
|
+
"lists files & their statuses since [old-revision] " +
|
11
|
+
"or between [old-revision] and [new-revision]." +
|
12
|
+
"\n\n" +
|
13
|
+
"-> When you don't pass a revision at all old-revision defaults to the current one."
|
12
14
|
)
|
13
15
|
.version(VERSION)
|
14
16
|
.option("-T, --output-type <type>", "json,regex", "regex")
|
15
17
|
.option("--tracked-only", "only take tracked files into account", false)
|
16
|
-
.arguments("[revision]")
|
18
|
+
.arguments("[old-revision] [new-revision]")
|
17
19
|
.parse(process.argv);
|
18
20
|
|
19
21
|
try {
|
20
|
-
console.log(listSync(program.args[0], program.opts()));
|
22
|
+
console.log(listSync(program.args[0], program.args[1], program.opts()));
|
21
23
|
} catch (pError) {
|
22
24
|
console.error(`ERROR: ${pError.message}`);
|
23
25
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// the security (and unicorn) plugins don't seem to detect named caption
|
2
2
|
// groups very well - false-flagging below regular expressions to be susceptible
|
3
|
-
// to redos
|
3
|
+
// to redos attacks.
|
4
4
|
/* eslint-disable unicorn/no-unsafe-regex, security/detect-unsafe-regex */
|
5
5
|
import { EOL } from "node:os";
|
6
6
|
|
package/src/formatters/regex.mjs
CHANGED
package/src/git-primitives.mjs
CHANGED
@@ -60,16 +60,27 @@ export function getStatusShort(pSpawnFunction = spawnSync) {
|
|
60
60
|
/**
|
61
61
|
*
|
62
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
|
63
65
|
* @return {string}
|
64
66
|
* @throws {Error}
|
65
67
|
*/
|
66
|
-
export function getDiffLines(
|
68
|
+
export function getDiffLines(
|
69
|
+
pOldRevision,
|
70
|
+
pNewRevision,
|
71
|
+
pSpawnFunction = spawnSync
|
72
|
+
) {
|
67
73
|
const lErrorMap = {
|
68
|
-
128: `revision '${pOldRevision}'
|
74
|
+
128: `revision '${pOldRevision}' ${
|
75
|
+
pNewRevision ? `(or '${pNewRevision}') ` : ""
|
76
|
+
}unknown`,
|
69
77
|
129: `'${process.cwd()}' does not seem to be a git repository`,
|
70
78
|
};
|
79
|
+
|
71
80
|
return getGitResult(
|
72
|
-
|
81
|
+
pNewRevision
|
82
|
+
? ["diff", pOldRevision, pNewRevision, "--name-status"]
|
83
|
+
: ["diff", pOldRevision, "--name-status"],
|
73
84
|
lErrorMap,
|
74
85
|
pSpawnFunction
|
75
86
|
);
|
package/src/main.mjs
CHANGED
@@ -11,11 +11,13 @@ export function getSHASync() {
|
|
11
11
|
}
|
12
12
|
|
13
13
|
/** @type {import("../types/watskeburt").listSync} */
|
14
|
-
export function listSync(pOldRevision, pOptions) {
|
14
|
+
export function listSync(pOldRevision, pNewRevision, pOptions) {
|
15
15
|
const lOldRevision = pOldRevision || getSHA1();
|
16
|
-
|
16
|
+
const lNewRevision = pNewRevision || null;
|
17
17
|
const lOptions = pOptions || {};
|
18
18
|
|
19
|
+
let lChanges = convertDiffLines(getDiffLines(lOldRevision, lNewRevision));
|
20
|
+
|
19
21
|
if (!lOptions.trackedOnly) {
|
20
22
|
lChanges = lChanges.concat(
|
21
23
|
convertStatusLines(getStatusShort()).filter(
|
package/src/version.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "0.
|
1
|
+
export const VERSION = "0.8.0";
|
package/types/watskeburt.d.ts
CHANGED
@@ -50,12 +50,15 @@ export interface IOptions {
|
|
50
50
|
* @param pOldRevision The revision against which to compare. E.g. a commit-hash,
|
51
51
|
* a branch or a tag. When not passed defaults to the _current_
|
52
52
|
* commit hash (if there's any)
|
53
|
+
* @param pNewRevision Newer revision against which to compare. Leave out or pass
|
54
|
+
* null when you want to compare against the working tree
|
53
55
|
* @param pOptions Options that influence how the changes are returned and that
|
54
56
|
* filter what is returned and
|
55
57
|
* @throws {Error}
|
56
58
|
*/
|
57
59
|
export function listSync(
|
58
60
|
pOldRevision?: string,
|
61
|
+
pNewRevision?: string,
|
59
62
|
pOptions?: IOptions
|
60
63
|
): IChange[] | string;
|
61
64
|
|