watskeburt 0.3.0 → 0.4.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/README.md CHANGED
@@ -40,16 +40,17 @@ source files in the JavaScript ecosystem (.js, .mjs, .ts, .tsx ...) that can
40
40
  be used in e.g. the `--focus` filter of dependency-cruiser:
41
41
 
42
42
  ```
43
- Usage: cli [options] <revision>
43
+ Usage: cli [options] [revision]
44
44
 
45
- lists files & their statuses since <revision>
45
+ lists files & their statuses since [revision].
46
46
 
47
- Options:
48
- -V, --version output the version number
49
- -T, --output-type <type> json,regex (default: "regex")
50
- --tracked-only only take tracked files into account (default: false)
51
- -h, --help display help for command
47
+ -> When you don't pass a revision the revision defaults to the current one.
52
48
 
49
+ Options:
50
+ -V, --version output the version number
51
+ -T, --output-type <type> json,regex (default: "regex")
52
+ --tracked-only only take tracked files into account (default: false)
53
+ -h, --help display help for command
53
54
  ```
54
55
 
55
56
  ### :scroll: API
@@ -75,7 +76,6 @@ An array of changes looks something like this:
75
76
  name: "test/thing.spec.mjs",
76
77
  changeType: "renamed",
77
78
  oldName: "test/old-thing.spec.mjs",
78
- similarity: 66,
79
79
  },
80
80
  { name: "src/not-tracked-yet.mjs", changeType: "untracked" },
81
81
  ];
@@ -1 +1 @@
1
- var i=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},C=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of w(t))!x.call(e,o)&&o!==n&&i(e,o,{get:()=>t[o],enumerable:!(r=y(t,o))||r.enumerable});return e};var A=e=>C(i({},"__esModule",{value:!0}),e);var M={};E(M,{getSHA:()=>B,list:()=>j});module.exports=A(M);var u=require("os"),_=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,D=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,R={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function s(e){return R[e]||"unknown"}function L(e){let t=e.match(D),n={};if(t){let r=s(t.groups.stagedChangeType),o=s(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 U(e){let t=e.match(_),n={};return t&&(n.changeType=s(t.groups.changeType),t.groups.similarity&&(n.similarity=Number.parseInt(t.groups.similarity,10)),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function l(e){return e.split(u.EOL).filter(Boolean).map(L).filter(({changeType:t})=>Boolean(t))}function g(e){return e.split(u.EOL).filter(Boolean).map(U).filter(({changeType:t})=>Boolean(t))}var a=require("child_process");function d(e){return e instanceof Buffer?e.toString("utf8"):e}function O(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function c(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env});if(r.error&&O(r.error),r.status===0)return d(r.stdout);throw new Error(t[r.status]||`internal git error: ${r.status} (${d(r.stderr)})`)}function T(e=a.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return c(["status","--porcelain"],t,e)}function h(e,t=a.spawnSync){let n={128:`revision '${e}' unknown `,129:`'${process.cwd()}' does not seem to be a git repository`};return c(["diff",e,"--name-status"],n,t)}function S(e=a.spawnSync){return c(["rev-parse","HEAD"],{},e).slice(0,40)}var N=require("path");function f(e,t=[".js",".jsx",".mjs",".cjs",".ts",".tsx",".vue",".vuex",".json"],n=["modified","added","renamed","copied","untracked"]){return`^(${e.filter(o=>n.includes(o.changeType)).map(({name:o})=>o).filter(o=>t.includes((0,N.extname)(o))).join("|")})$`}function p(e){return JSON.stringify(e,null,2)}var v={regex:f,json:p,object:e=>e},$="object";function m(e,t){return v[t||$](e)}function j(e,t){let n=g(h(e)),r=t||{};return r.trackedOnly||(n=n.concat(l(T()).filter(({changeType:o})=>o==="untracked"))),m(n,r.outputType)}function B(){return S()}0&&(module.exports={getSHA,list});
1
+ var s=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},_=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of E(t))!C.call(e,o)&&o!==n&&s(e,o,{get:()=>t[o],enumerable:!(r=x(t,o))||r.enumerable});return e};var R=e=>_(s({},"__esModule",{value:!0}),e);var H={};A(H,{getSHA:()=>w,list:()=>M});module.exports=R(H);var u=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]+))?$/,O={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function i(e){return O[e]||"unknown"}function U(e){let t=e.match(L),n={};if(t){let r=i(t.groups.stagedChangeType),o=i(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(D),n={};return t&&(n.changeType=i(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 e.split(u.EOL).filter(Boolean).map(U).filter(({changeType:t})=>Boolean(t))}function g(e){return e.split(u.EOL).filter(Boolean).map(v).filter(({changeType:t})=>Boolean(t))}var a=require("child_process");function d(e){return e instanceof Buffer?e.toString("utf8"):e}function $(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function c(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env});if(r.error&&$(r.error),r.status===0)return d(r.stdout);throw new Error(t[r.status]||`internal git error: ${r.status} (${d(r.stderr)})`)}function T(e=a.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return c(["status","--porcelain"],t,e)}function h(e,t=a.spawnSync){let n={128:`revision '${e}' unknown `,129:`'${process.cwd()}' does not seem to be a git repository`};return c(["diff",e,"--name-status"],n,t)}function S(e=a.spawnSync){return c(["rev-parse","HEAD"],{},e).slice(0,40)}var N=require("path");function f(e,t=[".js",".jsx",".mjs",".cjs",".ts",".tsx",".vue",".vuex",".json"],n=["modified","added","renamed","copied","untracked"]){return`^(${e.filter(o=>n.includes(o.changeType)).map(({name:o})=>o).filter(o=>t.includes((0,N.extname)(o))).join("|")})$`}function p(e){return JSON.stringify(e,null,2)}var j={regex:f,json:p,object:e=>e},B="object";function l(e,t){return j[t||B](e)}function w(){return S()}function M(e,t){let n=e||w(),r=g(h(n)),o=t||{};return o.trackedOnly||(r=r.concat(m(T()).filter(({changeType:y})=>y==="untracked"))),l(r,o.outputType)}0&&(module.exports={getSHA,list});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watskeburt",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "List files changed since a git revision",
5
5
  "keywords": [
6
6
  "git",
@@ -62,7 +62,8 @@
62
62
  "eslint-plugin-unicorn": "^43.0.1",
63
63
  "mocha": "^10.0.0",
64
64
  "npm-run-all": "^4.1.5",
65
- "prettier": "^2.7.1"
65
+ "prettier": "^2.7.1",
66
+ "typescript": "^4.7.4"
66
67
  },
67
68
  "engines": {
68
69
  "node": "^12.20||^14||>=16"
@@ -71,6 +72,7 @@
71
72
  "build": "npm-run-all --sequential build:version build:dist",
72
73
  "build:version": "node tools/get-version.mjs > src/version.mjs",
73
74
  "build:dist": "esbuild src/main.mjs --format=cjs --target=node12 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.js",
75
+ "check": "npm-run-all --parallel --aggregate-output lint depcruise test:cover",
74
76
  "clean": "rm -rf dist",
75
77
  "test": "mocha \"src/**/*.spec.mjs\"",
76
78
  "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",
package/src/cli.mjs CHANGED
@@ -6,19 +6,18 @@ import { list } from "./main.mjs";
6
6
  import { VERSION } from "./version.mjs";
7
7
 
8
8
  program
9
- .description("lists files & their statuses since <revision>")
9
+ .description(
10
+ "lists files & their statuses since [revision].\n\n" +
11
+ "-> When you don't pass a revision the revision defaults to the current one."
12
+ )
10
13
  .version(VERSION)
11
14
  .option("-T, --output-type <type>", "json,regex", "regex")
12
15
  .option("--tracked-only", "only take tracked files into account", false)
13
- .arguments("<revision>")
16
+ .arguments("[revision]")
14
17
  .parse(process.argv);
15
18
 
16
- if (program.args[0]) {
17
- try {
18
- console.log(list(program.args[0], program.opts()));
19
- } catch (pError) {
20
- console.error(`ERROR: ${pError.message}`);
21
- }
22
- } else {
23
- program.help();
19
+ try {
20
+ console.log(list(program.args[0], program.opts()));
21
+ } catch (pError) {
22
+ console.error(`ERROR: ${pError.message}`);
24
23
  }
@@ -76,12 +76,6 @@ export function convertDiffLine(pString) {
76
76
  lReturnValue.changeType = changeChar2ChangeType(
77
77
  lMatchResult.groups.changeType
78
78
  );
79
- if (lMatchResult.groups.similarity) {
80
- lReturnValue.similarity = Number.parseInt(
81
- lMatchResult.groups.similarity,
82
- 10
83
- );
84
- }
85
79
  if (lMatchResult.groups.newName) {
86
80
  lReturnValue.name = lMatchResult.groups.newName;
87
81
  lReturnValue.oldName = lMatchResult.groups.name;
package/src/main.mjs CHANGED
@@ -5,9 +5,15 @@ 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.js").getSHA} */
9
+ export function getSHA() {
10
+ return getSHA1();
11
+ }
12
+
8
13
  /** @type {import("../types/watskeburt.js").list} */
9
14
  export function list(pOldRevision, pOptions) {
10
- let lChanges = convertDiffLines(getDiffLines(pOldRevision));
15
+ const lOldRevision = pOldRevision || getSHA();
16
+ let lChanges = convertDiffLines(getDiffLines(lOldRevision));
11
17
  const lOptions = pOptions || {};
12
18
 
13
19
  if (!lOptions.trackedOnly) {
@@ -19,8 +25,3 @@ export function list(pOldRevision, pOptions) {
19
25
  }
20
26
  return format(lChanges, lOptions.outputType);
21
27
  }
22
-
23
- /** @type {import("../types/watskeburt.js").getSHA} */
24
- export function getSHA() {
25
- return getSHA1();
26
- }
package/src/version.mjs CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.3.0";
1
+ export const VERSION = "0.4.0";
@@ -21,10 +21,6 @@ export interface IChange {
21
21
  * how the file was changed
22
22
  */
23
23
  changeType: changeTypeType;
24
- /**
25
- * if the file was renamed: the % of similarity (range: 0 - 100)
26
- */
27
- similarity?: Number;
28
24
  /**
29
25
  * if the file was renamed: what the old file's name was
30
26
  */
@@ -52,14 +48,15 @@ export interface IOptions {
52
48
  * returns a list of files changed since pOldRevision.
53
49
  *
54
50
  * @param pOldRevision the revision against which to compare. E.g. a commit-hash,
55
- * a branch or a tag.
51
+ * a branch or a tag. When not passed defaults to the _current_
52
+ * commit hash (if there's any)
56
53
  * @param pOptions Options that influence how the changes are returned and that
57
54
  * filter what is returned and
58
55
  * @throws {Error}
59
56
  */
60
57
  export function list(
61
- pOldRevision: string,
62
- pOptions: IOptions
58
+ pOldRevision?: string,
59
+ pOptions?: IOptions
63
60
  ): IChange[] | string;
64
61
 
65
62
  /**