watskeburt 0.7.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable no-console */
3
3
 
4
4
  import { program } from "commander";
5
- import { listSync } from "./main.mjs";
5
+ import { listSync } from "../dist/esm-bundle.mjs";
6
6
  import { VERSION } from "./version.mjs";
7
7
 
8
8
  program
@@ -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.7.0",
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": "src/cli.mjs",
23
- "main": "dist/cjs-bundle.js",
24
- "module": "src/main.mjs",
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": "./src/main.mjs",
30
- "require": "./dist/cjs-bundle.js"
30
+ "import": "./dist/esm-bundle.mjs",
31
+ "require": "./dist/cjs-bundle.cjs"
31
32
  },
32
- "./dist/cjs-bundle.js"
33
+ "./dist/cjs-bundle.cjs"
33
34
  ]
34
35
  },
35
36
  "types": "types/watskeburt.d.ts",
36
37
  "files": [
37
- "src",
38
+ "bin",
38
39
  "dist",
39
- "!src/**/*.spec.mjs",
40
40
  "!**/*.DS_Store",
41
41
  "types",
42
42
  "LICENSE",
@@ -44,58 +44,67 @@
44
44
  "README.md"
45
45
  ],
46
46
  "dependencies": {
47
- "commander": "^9.3.0"
47
+ "commander": "9.4.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@types/mocha": "^9.1.1",
51
- "@types/node": "^18.6.3",
52
- "@typescript-eslint/eslint-plugin": "^5.32.0",
53
- "c8": "^7.12.0",
54
- "dependency-cruiser": "^11.14.1",
55
- "esbuild": "^0.14.51",
56
- "eslint": "^8.21.0",
57
- "eslint-config-moving-meadow": "^3.0.0",
58
- "eslint-config-prettier": "^8.5.0",
59
- "eslint-plugin-budapestian": "^4.0.0",
60
- "eslint-plugin-import": "^2.26.0",
61
- "eslint-plugin-mocha": "^10.1.0",
62
- "eslint-plugin-node": "^11.1.0",
63
- "eslint-plugin-security": "^1.5.0",
64
- "eslint-plugin-unicorn": "^43.0.2",
65
- "mocha": "^10.0.0",
66
- "npm-run-all": "^4.1.5",
67
- "prettier": "^2.7.1",
68
- "typescript": "^4.7.4"
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
+ "ts-node": "10.9.1",
70
+ "typescript": "4.8.4",
71
+ "upem": "7.3.0"
69
72
  },
70
73
  "engines": {
71
74
  "node": "^12.20||^14||>=16"
72
75
  },
73
76
  "scripts": {
74
77
  "build": "npm-run-all --sequential build:version build:dist",
75
- "build:version": "node tools/get-version.mjs > src/version.mjs",
76
- "build:dist": "esbuild src/main.mjs --format=cjs --target=node12 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.js",
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",
77
82
  "check": "npm-run-all --parallel --aggregate-output lint depcruise test:cover",
78
83
  "clean": "rm -rf dist",
79
- "test": "mocha \"src/**/*.spec.mjs\"",
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 --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",
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",
91
96
  "lint": "npm-run-all --parallel --aggregate-output lint:format lint:eslint lint:types",
92
97
  "lint:fix": "npm-run-all --parallel --aggregate-output lint:format:fix lint:eslint:fix",
93
- "lint:eslint": "eslint src types tools --cache --cache-location node_modules/.cache/eslint/",
94
- "lint:eslint:fix": "eslint src types tools --fix --cache --cache-location node_modules/.cache/eslint/",
95
- "lint:format": "prettier --check \"{src,tools}/**/*.mjs\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
96
- "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}\"",
97
102
  "lint:types": "tsc",
98
103
  "scm:stage": "git add .",
104
+ "update-dependencies": "run-s upem:update upem:install lint:fix check",
105
+ "upem-outdated": "npm outdated --json --long | upem --dry-run",
106
+ "upem:install": "npm install",
107
+ "upem:update": "npm outdated --json --long | upem | pbcopy && pbpaste",
99
108
  "version": "npm-run-all --sequential clean build lint depcruise:graph scm:stage"
100
109
  },
101
110
  "eslintIgnore": [
@@ -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: outputTypeType;
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: boolean;
44
+ trackedOnly?: boolean;
45
45
  }
46
46
 
47
47
  /**
@@ -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 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});
@@ -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
- }
@@ -1,9 +0,0 @@
1
- const INDENT = 2;
2
- /**
3
- *
4
- * @param {import('../types/watskeburt').IChange[]} pChanges
5
- * @return {string}
6
- */
7
- export default function formatToJSON(pChanges) {
8
- return JSON.stringify(pChanges, null, INDENT);
9
- }
@@ -1,47 +0,0 @@
1
- import { extname } from "node:path";
2
-
3
- const DEFAULT_EXTENSIONS = new Set([
4
- ".cjs",
5
- ".cjsx",
6
- ".coffee",
7
- ".csx",
8
- ".js",
9
- ".json",
10
- ".jsx",
11
- ".litcoffee",
12
- ".ls",
13
- ".mjs",
14
- ".svelte",
15
- ".ts",
16
- ".tsx",
17
- ".vue",
18
- ".vuex",
19
- ]);
20
-
21
- const DEFAULT_CHANGE_TYPES = new Set([
22
- "modified",
23
- "added",
24
- "renamed",
25
- "copied",
26
- "untracked",
27
- ]);
28
- /**
29
- *
30
- * @param {import('../types/watskeburt').IChange[]} pChanges
31
- * @param {Set<string>} pExtensions
32
- * @param {Set<import('../types/watskeburt').changeTypeType>} pChangeTypes
33
- * @return {string}
34
- */
35
- export default function formatToRegex(
36
- pChanges,
37
- pExtensions = DEFAULT_EXTENSIONS,
38
- pChangeTypes = DEFAULT_CHANGE_TYPES
39
- ) {
40
- const lChanges = pChanges
41
- .filter((pChange) => pChangeTypes.has(pChange.changeType))
42
- .map(({ name }) => name)
43
- .filter((pName) => pExtensions.has(extname(pName)))
44
- // .replace(/\./g, "\\\\.")
45
- .join("|");
46
- return `^(${lChanges})$`;
47
- }
@@ -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.7.0";