watskeburt 0.5.1 → 0.7.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/LICENSE +1 -1
- package/README.md +13 -6
- package/dist/cjs-bundle.js +1 -1
- package/package.json +16 -15
- package/src/cli.mjs +7 -5
- package/src/formatters/format.mjs +6 -7
- package/src/git-primitives.mjs +14 -3
- package/src/main.mjs +8 -6
- package/src/version.mjs +1 -1
- package/types/watskeburt.d.ts +8 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
@@ -24,20 +24,27 @@ but for just this simple usage they're a bit overkill.
|
|
24
24
|
### :scroll: API
|
25
25
|
|
26
26
|
```javascript
|
27
|
-
// const {
|
28
|
-
import {
|
27
|
+
// const { listSync, getSHASync } = require("watskeburt"); // in commonjs contexts you can also require it
|
28
|
+
import { listSync, getSHASync } from "watskeburt";
|
29
29
|
|
30
30
|
// print the SHA1 of the current HEAD
|
31
|
-
console.log(
|
31
|
+
console.log(getSHASync());
|
32
32
|
|
33
33
|
// list all files that differ between 'main' and the current revision (including
|
34
34
|
// files not staged for commit and files not under revision control)
|
35
35
|
/** @type {import('watskeburt').IChange[]} */
|
36
|
-
const lChangedFiles =
|
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 =
|
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 a=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=a.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=a.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=a.spawnSync){return f(["rev-parse","HEAD"],{},e).slice(0,40)}var E=require("path"),B=new Set([".cjs",".cjsx",".coffee",".csx",".js",".json",".jsx",".litcoffee",".ls",".mjs",".svelte",".ts",".tsx",".vue",".vuex"]),H=new Set(["modified","added","renamed","copied","untracked"]);function p(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 m(e){return JSON.stringify(e,null,2)}var j=e=>e,I=new Map([["regex",p],["json",m]]);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||{},s=S(y(r,o));return d.trackedOnly||(s=s.concat(T(N()).filter(({changeType:w})=>w==="untracked"))),g(s,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.7.0",
|
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": "^9.1.1",
|
51
|
-
"@types/node": "^18.
|
52
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
51
|
+
"@types/node": "^18.6.3",
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
53
53
|
"c8": "^7.12.0",
|
54
|
-
"dependency-cruiser": "^11.
|
55
|
-
"esbuild": "^0.14.
|
56
|
-
"eslint": "^8.
|
54
|
+
"dependency-cruiser": "^11.14.1",
|
55
|
+
"esbuild": "^0.14.51",
|
56
|
+
"eslint": "^8.21.0",
|
57
57
|
"eslint-config-moving-meadow": "^3.0.0",
|
58
58
|
"eslint-config-prettier": "^8.5.0",
|
59
59
|
"eslint-plugin-budapestian": "^4.0.0",
|
@@ -78,15 +78,16 @@
|
|
78
78
|
"clean": "rm -rf dist",
|
79
79
|
"test": "mocha \"src/**/*.spec.mjs\"",
|
80
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 npm test",
|
81
|
-
"depcruise": "depcruise src types --config",
|
82
|
-
"depcruise:graph": "depcruise src types --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
|
-
"depcruise:graph:archi": "depcruise src --include-only '^(src)' --config --output-type archi | dot -T svg | depcruise-wrap-stream-in-html > docs/high-level-dependency-graph.html",
|
84
|
-
"depcruise:graph:dev": "depcruise src --include-only '^(src)' --prefix vscode://file/$(pwd)/ --config --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
|
85
|
-
"depcruise:graph:diff:dev": "depcruise src types --include-only '^(src|types)' --focus \"$(node src/cli.mjs main -T regex)\" --focus-depth 0 --prefix vscode://file/$(pwd)/ --config --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
|
86
|
-
"depcruise:graph:diff:mermaid": "depcruise src types --include-only '^(src|types)' --config --output-type mermaid --output-to - --focus \"$(node src/cli.mjs $SHA -T regex)\" --focus-depth 0",
|
87
|
-
"depcruise:html": "depcruise src --progress --config --output-type err-html --output-to dependency-violation-report.html",
|
88
|
-
"depcruise:text": "depcruise src --progress --config --output-type text",
|
89
|
-
"depcruise:focus": "depcruise src --progress --config --output-type text --focus",
|
81
|
+
"depcruise": "depcruise src types --config --cache",
|
82
|
+
"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
|
+
"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",
|
84
|
+
"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",
|
85
|
+
"depcruise:graph:diff:dev": "depcruise src types --cache --include-only '^(src|types)' --focus \"$(node src/cli.mjs main -T regex)\" --focus-depth 0 --prefix vscode://file/$(pwd)/ --config --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
|
86
|
+
"depcruise:graph:diff:mermaid": "depcruise src types --cache --include-only '^(src|types)' --config --output-type mermaid --output-to - --focus \"$(node src/cli.mjs $SHA -T regex)\" --focus-depth 0",
|
87
|
+
"depcruise:html": "depcruise src types --progress --cache --config --output-type err-html --output-to dependency-violation-report.html",
|
88
|
+
"depcruise:text": "depcruise src types --progress --cache --config --output-type text",
|
89
|
+
"depcruise:focus": "depcruise src types --progress --cache --config --output-type text --focus",
|
90
|
+
"depcruise:reaches": "depcruise src types --progress --cache --config --output-type text --reaches",
|
90
91
|
"lint": "npm-run-all --parallel --aggregate-output lint:format lint:eslint lint:types",
|
91
92
|
"lint:fix": "npm-run-all --parallel --aggregate-output lint:format:fix lint:eslint:fix",
|
92
93
|
"lint:eslint": "eslint src types tools --cache --cache-location node_modules/.cache/eslint/",
|
package/src/cli.mjs
CHANGED
@@ -2,22 +2,24 @@
|
|
2
2
|
/* eslint-disable no-console */
|
3
3
|
|
4
4
|
import { program } from "commander";
|
5
|
-
import {
|
5
|
+
import { listSync } from "./main.mjs";
|
6
6
|
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(
|
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,12 +1,11 @@
|
|
1
1
|
import formatToRegex from "./regex.mjs";
|
2
2
|
import formatToJSON from "./json.mjs";
|
3
3
|
|
4
|
-
const
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
const DEFAULT_OUTPUT_TYPE = "object";
|
4
|
+
const identity = (pX) => pX;
|
5
|
+
const OUTPUT_TYPE_TO_FUNCTION = new Map([
|
6
|
+
["regex", formatToRegex],
|
7
|
+
["json", formatToJSON],
|
8
|
+
]);
|
10
9
|
|
11
10
|
/**
|
12
11
|
*
|
@@ -15,5 +14,5 @@ const DEFAULT_OUTPUT_TYPE = "object";
|
|
15
14
|
* @returns {string|import("../../types/watskeburt.js").IChange[]}
|
16
15
|
*/
|
17
16
|
export default function format(pChanges, pOutputType) {
|
18
|
-
return OUTPUT_TYPE_TO_FUNCTION
|
17
|
+
return (OUTPUT_TYPE_TO_FUNCTION.get(pOutputType) || identity)(pChanges);
|
19
18
|
}
|
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
@@ -5,17 +5,19 @@ import {
|
|
5
5
|
import { getDiffLines, getSHA1, getStatusShort } from "./git-primitives.mjs";
|
6
6
|
import format from "./formatters/format.mjs";
|
7
7
|
|
8
|
-
/** @type {import("../types/watskeburt
|
9
|
-
export function
|
8
|
+
/** @type {import("../types/watskeburt").getSHASync} */
|
9
|
+
export function getSHASync() {
|
10
10
|
return getSHA1();
|
11
11
|
}
|
12
12
|
|
13
|
-
/** @type {import("../types/watskeburt
|
14
|
-
export function
|
15
|
-
const lOldRevision = pOldRevision ||
|
16
|
-
|
13
|
+
/** @type {import("../types/watskeburt").listSync} */
|
14
|
+
export function listSync(pOldRevision, pNewRevision, pOptions) {
|
15
|
+
const lOldRevision = pOldRevision || getSHA1();
|
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.7.0";
|
package/types/watskeburt.d.ts
CHANGED
@@ -32,14 +32,14 @@ export type outputTypeType = "regex" | "json" | "object";
|
|
32
32
|
export interface IOptions {
|
33
33
|
/**
|
34
34
|
* The type of output to deliver. Defaults to "object" - in which case
|
35
|
-
* the
|
35
|
+
* the listSync function returns an IChange[] object
|
36
36
|
*/
|
37
37
|
outputType: outputTypeType;
|
38
38
|
/**
|
39
39
|
* When true _only_ takes already tracked files into account.
|
40
|
-
* When
|
40
|
+
* When false also takes untracked files into account.
|
41
41
|
*
|
42
|
-
* Defaults to
|
42
|
+
* Defaults to false.
|
43
43
|
*/
|
44
44
|
trackedOnly: boolean;
|
45
45
|
}
|
@@ -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
|
-
export function
|
59
|
+
export function listSync(
|
58
60
|
pOldRevision?: string,
|
61
|
+
pNewRevision?: string,
|
59
62
|
pOptions?: IOptions
|
60
63
|
): IChange[] | string;
|
61
64
|
|
@@ -64,4 +67,4 @@ export function list(
|
|
64
67
|
*
|
65
68
|
* @throws {Error}
|
66
69
|
*/
|
67
|
-
export function
|
70
|
+
export function getSHASync(): string;
|