watskeburt 0.11.1 → 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -87,7 +87,7 @@ For now there's also a simple command line interface
87
87
  ```shell
88
88
  # list all JavaScript-ish files changed since main in a regular expression
89
89
  $ npx watskeburt main
90
- ^(src/cli.mjs|src/formatters/regex.mjs|src/version.mjs)$
90
+ ^(src/cli\.mjs|src/formatters/regex\.mjs|src/version\.mjs)$
91
91
  ```
92
92
 
93
93
  By default this returns a regex that contains all changed files that could be
@@ -98,17 +98,17 @@ The JSON output (which looks a lot like the array above) is unfiltered and
98
98
  also contains other extensions.
99
99
 
100
100
  ```
101
- Usage: cli [options] [revision]
101
+ Usage: watskeburt [options] [old-revision] [new-revision]
102
102
 
103
- lists files & their statuses since [revision].
103
+ lists files & their statuses since [old-revision] or between [old-revision] and [new-revision].
104
104
 
105
- -> When you don't pass a revision the revision defaults to the current one.
105
+ -> When you don't pass a revision at all old-revision defaults to the current one.
106
106
 
107
107
  Options:
108
- -V, --version output the version number
109
- -T, --output-type <type> json,regex (default: "regex")
110
- --tracked-only only take tracked files into account (default: false)
111
- -h, --help display help for command
108
+ -T, --outputType <type> what format to emit (choices: "json", "regex", default: "regex")
109
+ --trackedOnly only take tracked files into account (default: false)
110
+ -V, --version output the version number
111
+ -h, --help display help for command
112
112
  ```
113
113
 
114
114
  ## 🇳🇱 what does 'watskeburt' mean?
@@ -116,4 +116,4 @@ Options:
116
116
  _watskeburt_ is a fast pronunciation of the Dutch "wat is er gebeurd?"
117
117
  (_what has happened?_) or "wat er is gebeurd" (_what has happened_). It's
118
118
  also the title of a song by the Dutch band "De Jeugd van Tegenwoordig"
119
- (_Youth these days..._).
119
+ (_Youth these days_).
package/bin/cli.js CHANGED
@@ -1,29 +1,5 @@
1
1
  #!/usr/bin/env node
2
- /* eslint-disable no-console */
3
- import { EOL } from "node:os";
4
- import { Option, program } from "commander";
5
- import { list } from "../dist/esm/main.js";
6
- import { VERSION } from "./version.js";
7
2
 
8
- program
9
- .description(
10
- "lists files & their statuses since [old-revision] " +
11
- "or between [old-revision] and [new-revision]." +
12
- `${EOL}${EOL}` +
13
- "-> When you don't pass a revision at all old-revision defaults to the current one."
14
- )
15
- .addOption(
16
- new Option("-T, --output-type <type>", "what format to emit")
17
- .choices(["json", "regex"])
18
- .default("regex")
19
- )
20
- .option("--tracked-only", "only take tracked files into account", false)
21
- .arguments("[old-revision] [new-revision]")
22
- .version(VERSION)
23
- .parse(process.argv);
3
+ import { cli } from "../dist/esm/cli.js";
24
4
 
25
- try {
26
- console.log(await list(program.args[0], program.args[1], program.opts()));
27
- } catch (pError) {
28
- console.error(`ERROR: ${pError.message}`);
29
- }
5
+ await cli();
@@ -1 +1 @@
1
- "use strict";var y=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var b=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0})},B=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!M.call(t,o)&&o!==n&&y(t,o,{get:()=>e[o],enumerable:!(r=_(e,o))||r.enumerable});return t};var H=t=>B(y({},"__esModule",{value:!0}),t);var K={};b(K,{getSHA:()=>m,getSHASync:()=>p,list:()=>z,listSync:()=>q});module.exports=H(K);var T=require("os"),U=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,j=/^(?<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 d(t){return R[t]??"unknown"}function v(t){let e=t.match(j),n={};if(e!=null&&e.groups){let r=d(e.groups.stagedChangeType),o=d(e.groups.unStagedChangeType);n.changeType=r==="unmodified"?o:r,e.groups.newName?(n.name=e.groups.newName,n.oldName=e.groups.name):n.name=e.groups.name}return n}function F(t){let e=t.match(U),n={};return e!=null&&e.groups&&(n.changeType=d(e.groups.changeType),e.groups.newName?(n.name=e.groups.newName,n.oldName=e.groups.name):n.name=e.groups.name),n}function h(t){return t.split(T.EOL).filter(Boolean).map(v).filter(({name:e,changeType:n})=>!!e&&!!n)}function S(t){return t.split(T.EOL).filter(Boolean).map(F).filter(({name:e,changeType:n})=>!!e&&!!n)}var u=require("child_process");function N(t){return t instanceof Buffer?t.toString("utf8"):t}function G(t){throw t.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${t}`)}function w(t,e,n){let r=n("git",t,{cwd:process.cwd(),env:process.env});if(r.error&&G(r.error),r.status===0)return N(r.stdout);throw new Error(e[r.status??0]||`internal git error: ${r.status} (${N(r.stderr)})`)}function A(t=u.spawnSync){let e={129:`'${process.cwd()}' does not seem to be a git repository`};return w(["status","--porcelain"],e,t)}function D(t,e,n=u.spawnSync){let r={128:`revision '${t}' ${e?`(or '${e}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return w(e?["diff",t,e,"--name-status"]:["diff",t,"--name-status"],r,n)}function p(t=u.spawnSync){return w(["rev-parse","HEAD"],{},t).slice(0,40)}var L=require("path"),X=new Set([".cjs",".cjsx",".coffee",".csx",".cts",".js",".json",".jsx",".litcoffee",".ls",".mjs",".mts",".svelte",".ts",".tsx",".vue",".vuex"]),J=new Set(["modified","added","renamed","copied","untracked"]);function C(t,e=X,n=J){return`^(${t.filter(o=>n.has(o.changeType)).map(({name:o})=>o).filter(o=>e.has((0,L.extname)(o))).join("|")})$`}function I(t){return JSON.stringify(t,null,2)}var Y=t=>t,V=new Map([["regex",C],["json",I]]);function f(t,e){return(V.get(e??"unknown")||Y)(t)}var l=require("child_process");function O(t){return t instanceof Buffer?t.toString("utf8"):t}function E(t,e,n){let r=n("git",t,{cwd:process.cwd(),env:process.env}),o="",a="";return new Promise((c,i)=>{var g,x;(g=r.stdout)==null||g.on("data",s=>{o=o.concat(s)}),(x=r.stderr)==null||x.on("data",s=>{a=a.concat(s)}),r.on("close",s=>{s===0?c(O(o)):i(new Error(e[s??0]||`internal git error: ${s} (${O(a)})`))}),r.on("error",s=>{(s==null?void 0:s.code)==="ENOENT"?i(new Error("git executable not found")):i(new Error(`internal spawn error: ${s}`))})})}async function $(t=l.spawn){let e={129:`'${process.cwd()}' does not seem to be a git repository`};return await E(["status","--porcelain"],e,t)}async function P(t,e,n=l.spawn){let r={128:`revision '${t}' ${e?`(or '${e}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return await E(e?["diff",t,e,"--name-status"]:["diff",t,"--name-status"],r,n)}async function m(t=l.spawn){return(await E(["rev-parse","HEAD"],{},t)).slice(0,40)}function q(t,e,n){let r=t||p(),o=n||{},a=S(D(r,e));return o.trackedOnly||(a=a.concat(h(A()).filter(({changeType:c})=>c==="untracked"))),f(a,o.outputType)}async function z(t,e,n){let r=t||await m(),o=n||{},[a,c]=await Promise.all([P(r,e),o.trackedOnly?"":$()]),i=S(a);return o.trackedOnly||(i=i.concat(h(c).filter(({changeType:g})=>g==="untracked"))),f(i,o.outputType)}0&&(module.exports={getSHA,getSHASync,list,listSync});
1
+ "use strict";var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)l(e,n,{get:t[n],enumerable:!0})},H=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of _(t))!k.call(e,s)&&s!==n&&l(e,s,{get:()=>t[s],enumerable:!(r=v(t,s))||r.enumerable});return e};var b=e=>H(l({},"__esModule",{value:!0}),e);var ee={};M(ee,{getSHA:()=>W,getSHASync:()=>Z,list:()=>K,listSync:()=>Q});module.exports=b(ee);var y=require("os"),B=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,U=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,j={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function d(e){return e.split(y.EOL).filter(Boolean).map(R).filter(({name:t,changeType:n})=>!!t&&!!n)}function R(e){let t=e.match(U),n={};if(t!=null&&t.groups){let r=m(t.groups.stagedChangeType),s=m(t.groups.unStagedChangeType);n.changeType=r==="unmodified"?s:r,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function T(e){return e.split(y.EOL).filter(Boolean).map(F).filter(({name:t,changeType:n})=>!!t&&!!n)}function F(e){let t=e.match(B),n={};return t!=null&&t.groups&&(n.changeType=m(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 j[e]??"unknown"}var p=require("child_process");function N(e=p.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return h(["status","--porcelain"],t,e)}function D(e,t,n=p.spawnSync){let r={128:`revision '${e}' ${t?`(or '${t}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return h(t?["diff",e,t,"--name-status"]:["diff",e,"--name-status"],r,n)}function S(e=p.spawnSync){return h(["rev-parse","HEAD"],{},e).slice(0,40)}function h(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env});if(r.error&&G(r.error),r.status===0)return A(r.stdout);throw new Error(t[r.status??0]||`internal git error: ${r.status} (${A(r.stderr)})`)}function A(e){return e instanceof Buffer?e.toString("utf8"):e}function G(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}var u=require("child_process");async function O(e=u.spawn){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return await C(["status","--porcelain"],t,e)}async function P(e,t,n=u.spawn){let r={128:`revision '${e}' ${t?`(or '${t}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return await C(t?["diff",e,t,"--name-status"]:["diff",e,"--name-status"],r,n)}async function w(e=u.spawn){return(await C(["rev-parse","HEAD"],{},e)).slice(0,40)}function C(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env}),s="",i="";return new Promise((c,a)=>{var g,x;(g=r.stdout)==null||g.on("data",o=>{s=s.concat(o)}),(x=r.stderr)==null||x.on("data",o=>{i=i.concat(o)}),r.on("close",o=>{o===0?c(L(s)):a(new Error(t[o??0]||`internal git error: ${o} (${L(i)})`))}),r.on("error",o=>{(o==null?void 0:o.code)==="ENOENT"?a(new Error("git executable not found")):a(new Error(`internal spawn error: ${o}`))})})}function L(e){return e instanceof Buffer?e.toString("utf8"):e}var $=require("path"),Y=new Set([".cjs",".cjsx",".coffee",".csx",".cts",".js",".json",".jsx",".litcoffee",".ls",".mjs",".mts",".svelte",".ts",".tsx",".vue",".vuex"]),V=new Set(["modified","added","renamed","copied","untracked"]);function I(e,t=Y,n=V){return`^(${e.filter(s=>n.has(s.changeType)).map(({name:s})=>s).filter(s=>t.has((0,$.extname)(s))).map(s=>s.replace(/\\/g,"\\\\").replace(/\./g,"\\.")).join("|")})$`}function E(e){return JSON.stringify(e,null,2)}var q=e=>e,z=new Map([["regex",I],["json",E]]);function f(e,t){return(z.get(t??"unknown")||q)(e)}async function K(e,t,n){let r=e||await w(),s=n||{},[i,c]=await Promise.all([P(r,t),s.trackedOnly?"":O()]),a=T(i);return s.trackedOnly||(a=a.concat(d(c).filter(({changeType:g})=>g==="untracked"))),f(a,s.outputType)}function Q(e,t,n){let r=e||S(),s=n||{},i=T(D(r,t));return s.trackedOnly||(i=i.concat(d(N()).filter(({changeType:c})=>c==="untracked"))),f(i,s.outputType)}function W(){return w()}function Z(){return S()}0&&(module.exports={getSHA,getSHASync,list,listSync});
@@ -0,0 +1,63 @@
1
+ import { EOL } from "node:os";
2
+ import { parseArgs } from "node:util";
3
+ import { list } from "./main.js";
4
+ import { VERSION } from "./version.js";
5
+ const HELP_MESSAGE = `Usage: watskeburt [options] [old-revision] [new-revision]
6
+
7
+ lists files & their statuses since [old-revision] or between [old-revision] and [new-revision].
8
+
9
+ -> When you don't pass a revision at all old-revision defaults to the current one.
10
+
11
+ Options:
12
+ -T, --outputType <type> what format to emit (choices: "json", "regex", default: "regex")
13
+ --trackedOnly only take tracked files into account (default: false)
14
+ -V, --version output the version number
15
+ -h, --help display help for command${EOL}`;
16
+ export async function cli(pArguments = process.argv.slice(2), pOutStream = process.stdout, pErrorStream = process.stderr) {
17
+ try {
18
+ const lArguments = getArguments(pArguments);
19
+ if (lArguments.values.help) {
20
+ pOutStream.write(HELP_MESSAGE);
21
+ return;
22
+ }
23
+ if (lArguments.values.version) {
24
+ pOutStream.write(`${VERSION}${EOL}`);
25
+ return;
26
+ }
27
+ if (!outputTypeIsValid(lArguments.values.outputType)) {
28
+ pErrorStream.write(`error: option '-T, --outputType <type>' argument '${lArguments.values.outputType}' is invalid. Allowed choices are json, regex.${EOL}`);
29
+ process.exitCode = 1;
30
+ return;
31
+ }
32
+ const lResult = await list(lArguments.positionals[0], lArguments.positionals[1], lArguments.values);
33
+ pOutStream.write(`${lResult}${EOL}`);
34
+ }
35
+ catch (pError) {
36
+ pErrorStream.write(`${EOL}ERROR: ${pError.message}${EOL}${EOL}`);
37
+ process.exitCode = 1;
38
+ }
39
+ }
40
+ function getArguments(pArguments) {
41
+ return parseArgs({
42
+ args: pArguments,
43
+ options: {
44
+ outputType: {
45
+ type: "string",
46
+ short: "T",
47
+ default: "regex",
48
+ },
49
+ trackedOnly: {
50
+ type: "boolean",
51
+ default: false,
52
+ },
53
+ help: { type: "boolean", short: "h", default: false },
54
+ version: { type: "boolean", short: "V", default: false },
55
+ },
56
+ strict: true,
57
+ allowPositionals: true,
58
+ tokens: false,
59
+ });
60
+ }
61
+ function outputTypeIsValid(pOutputType) {
62
+ return ["json", "regex"].includes(pOutputType);
63
+ }
@@ -14,8 +14,12 @@ const CHANGE_CHAR_2_CHANGE_TYPE = {
14
14
  "?": "untracked",
15
15
  "!": "ignored",
16
16
  };
17
- function changeChar2ChangeType(pChar) {
18
- return CHANGE_CHAR_2_CHANGE_TYPE[pChar] ?? "unknown";
17
+ export function convertStatusLines(pString) {
18
+ return pString
19
+ .split(EOL)
20
+ .filter(Boolean)
21
+ .map(convertStatusLine)
22
+ .filter(({ name, changeType }) => Boolean(name) && Boolean(changeType));
19
23
  }
20
24
  export function convertStatusLine(pString) {
21
25
  const lMatchResult = pString.match(DIFF_SHORT_STATUS_LINE_PATTERN);
@@ -37,6 +41,13 @@ export function convertStatusLine(pString) {
37
41
  }
38
42
  return lReturnValue;
39
43
  }
44
+ export function convertDiffLines(pString) {
45
+ return pString
46
+ .split(EOL)
47
+ .filter(Boolean)
48
+ .map(convertDiffLine)
49
+ .filter(({ name, changeType }) => Boolean(name) && Boolean(changeType));
50
+ }
40
51
  export function convertDiffLine(pString) {
41
52
  const lMatchResult = pString.match(DIFF_NAME_STATUS_LINE_PATTERN);
42
53
  const lReturnValue = {};
@@ -52,17 +63,6 @@ export function convertDiffLine(pString) {
52
63
  }
53
64
  return lReturnValue;
54
65
  }
55
- export function convertStatusLines(pString) {
56
- return pString
57
- .split(EOL)
58
- .filter(Boolean)
59
- .map(convertStatusLine)
60
- .filter(({ name, changeType }) => Boolean(name) && Boolean(changeType));
61
- }
62
- export function convertDiffLines(pString) {
63
- return pString
64
- .split(EOL)
65
- .filter(Boolean)
66
- .map(convertDiffLine)
67
- .filter(({ name, changeType }) => Boolean(name) && Boolean(changeType));
66
+ function changeChar2ChangeType(pChar) {
67
+ return CHANGE_CHAR_2_CHANGE_TYPE[pChar] ?? "unknown";
68
68
  }
@@ -30,6 +30,7 @@ export default function formatToRegex(pChanges, pExtensions = DEFAULT_EXTENSIONS
30
30
  .filter((pChange) => pChangeTypes.has(pChange.changeType))
31
31
  .map(({ name }) => name)
32
32
  .filter((pName) => pExtensions.has(extname(pName)))
33
+ .map((pName) => pName.replace(/\\/g, "\\\\").replace(/\./g, "\\."))
33
34
  .join("|");
34
35
  return `^(${lChanges})$`;
35
36
  }
@@ -1,19 +1,22 @@
1
1
  import { spawnSync } from "node:child_process";
2
- function stringifyOutStream(pError) {
3
- if (pError instanceof Buffer) {
4
- return pError.toString("utf8");
5
- }
6
- else {
7
- return pError;
8
- }
2
+ export function getStatusShortSync(pSpawnFunction = spawnSync) {
3
+ const lErrorMap = {
4
+ 129: `'${process.cwd()}' does not seem to be a git repository`,
5
+ };
6
+ return getGitResultSync(["status", "--porcelain"], lErrorMap, pSpawnFunction);
9
7
  }
10
- function throwSpawnError(pError) {
11
- if (pError.code === "ENOENT") {
12
- throw new Error("git executable not found");
13
- }
14
- else {
15
- throw new Error(`internal spawn error: ${pError}`);
16
- }
8
+ export function getDiffLinesSync(pOldRevision, pNewRevision, pSpawnFunction = spawnSync) {
9
+ const lErrorMap = {
10
+ 128: `revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
11
+ 129: `'${process.cwd()}' does not seem to be a git repository`,
12
+ };
13
+ return getGitResultSync(pNewRevision
14
+ ? ["diff", pOldRevision, pNewRevision, "--name-status"]
15
+ : ["diff", pOldRevision, "--name-status"], lErrorMap, pSpawnFunction);
16
+ }
17
+ export function getSHASync(pSpawnFunction = spawnSync) {
18
+ const lSha1Length = 40;
19
+ return getGitResultSync(["rev-parse", "HEAD"], {}, pSpawnFunction).slice(0, lSha1Length);
17
20
  }
18
21
  function getGitResultSync(pArguments, pErrorMap, pSpawnFunction) {
19
22
  const lGitResult = pSpawnFunction("git", pArguments, {
@@ -31,22 +34,19 @@ function getGitResultSync(pArguments, pErrorMap, pSpawnFunction) {
31
34
  `internal git error: ${lGitResult.status} (${stringifyOutStream(lGitResult.stderr)})`);
32
35
  }
33
36
  }
34
- export function getStatusShortSync(pSpawnFunction = spawnSync) {
35
- const lErrorMap = {
36
- 129: `'${process.cwd()}' does not seem to be a git repository`,
37
- };
38
- return getGitResultSync(["status", "--porcelain"], lErrorMap, pSpawnFunction);
39
- }
40
- export function getDiffLinesSync(pOldRevision, pNewRevision, pSpawnFunction = spawnSync) {
41
- const lErrorMap = {
42
- 128: `revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
43
- 129: `'${process.cwd()}' does not seem to be a git repository`,
44
- };
45
- return getGitResultSync(pNewRevision
46
- ? ["diff", pOldRevision, pNewRevision, "--name-status"]
47
- : ["diff", pOldRevision, "--name-status"], lErrorMap, pSpawnFunction);
37
+ function stringifyOutStream(pError) {
38
+ if (pError instanceof Buffer) {
39
+ return pError.toString("utf8");
40
+ }
41
+ else {
42
+ return pError;
43
+ }
48
44
  }
49
- export function getSHASync(pSpawnFunction = spawnSync) {
50
- const lSha1Length = 40;
51
- return getGitResultSync(["rev-parse", "HEAD"], {}, pSpawnFunction).slice(0, lSha1Length);
45
+ function throwSpawnError(pError) {
46
+ if (pError.code === "ENOENT") {
47
+ throw new Error("git executable not found");
48
+ }
49
+ else {
50
+ throw new Error(`internal spawn error: ${pError}`);
51
+ }
52
52
  }
@@ -1,11 +1,25 @@
1
1
  import { spawn } from "node:child_process";
2
- function stringifyOutStream(pBufferOrString) {
3
- if (pBufferOrString instanceof Buffer) {
4
- return pBufferOrString.toString("utf8");
5
- }
6
- else {
7
- return pBufferOrString;
8
- }
2
+ export async function getStatusShort(pSpawnFunction = spawn) {
3
+ const lErrorMap = {
4
+ 129: `'${process.cwd()}' does not seem to be a git repository`,
5
+ };
6
+ const lResult = await getGitResult(["status", "--porcelain"], lErrorMap, pSpawnFunction);
7
+ return lResult;
8
+ }
9
+ export async function getDiffLines(pOldRevision, pNewRevision, pSpawnFunction = spawn) {
10
+ const lErrorMap = {
11
+ 128: `revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
12
+ 129: `'${process.cwd()}' does not seem to be a git repository`,
13
+ };
14
+ const lResult = await getGitResult(pNewRevision
15
+ ? ["diff", pOldRevision, pNewRevision, "--name-status"]
16
+ : ["diff", pOldRevision, "--name-status"], lErrorMap, pSpawnFunction);
17
+ return lResult;
18
+ }
19
+ export async function getSHA(pSpawnFunction = spawn) {
20
+ const lSha1Length = 40;
21
+ const lResult = await getGitResult(["rev-parse", "HEAD"], {}, pSpawnFunction);
22
+ return lResult.slice(0, lSha1Length);
9
23
  }
10
24
  function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
11
25
  const lGit = pSpawnFunction("git", pArguments, {
@@ -40,25 +54,11 @@ function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
40
54
  });
41
55
  });
42
56
  }
43
- export async function getStatusShort(pSpawnFunction = spawn) {
44
- const lErrorMap = {
45
- 129: `'${process.cwd()}' does not seem to be a git repository`,
46
- };
47
- const lResult = await getGitResult(["status", "--porcelain"], lErrorMap, pSpawnFunction);
48
- return lResult;
49
- }
50
- export async function getDiffLines(pOldRevision, pNewRevision, pSpawnFunction = spawn) {
51
- const lErrorMap = {
52
- 128: `revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
53
- 129: `'${process.cwd()}' does not seem to be a git repository`,
54
- };
55
- const lResult = await getGitResult(pNewRevision
56
- ? ["diff", pOldRevision, pNewRevision, "--name-status"]
57
- : ["diff", pOldRevision, "--name-status"], lErrorMap, pSpawnFunction);
58
- return lResult;
59
- }
60
- export async function getSHA(pSpawnFunction = spawn) {
61
- const lSha1Length = 40;
62
- const lResult = await getGitResult(["rev-parse", "HEAD"], {}, pSpawnFunction);
63
- return lResult.slice(0, lSha1Length);
57
+ function stringifyOutStream(pBufferOrString) {
58
+ if (pBufferOrString instanceof Buffer) {
59
+ return pBufferOrString.toString("utf8");
60
+ }
61
+ else {
62
+ return pBufferOrString;
63
+ }
64
64
  }
package/dist/esm/main.js CHANGED
@@ -1,22 +1,13 @@
1
1
  import { convertDiffLines, convertStatusLines, } from "./convert-to-change-object.js";
2
- import { getDiffLinesSync, getSHASync, getStatusShortSync, } from "./git-primitives-sync.js";
2
+ import * as primitivesSync from "./git-primitives-sync.js";
3
+ import * as primitives from "./git-primitives.js";
3
4
  import format from "./formatters/format.js";
4
- import { getDiffLines, getStatusShort, getSHA } from "./git-primitives.js";
5
- export function listSync(pOldRevision, pNewRevision, pOptions) {
6
- const lOldRevision = pOldRevision || getSHASync();
7
- const lOptions = pOptions || {};
8
- let lChanges = convertDiffLines(getDiffLinesSync(lOldRevision, pNewRevision));
9
- if (!lOptions.trackedOnly) {
10
- lChanges = lChanges.concat(convertStatusLines(getStatusShortSync()).filter(({ changeType }) => changeType === "untracked"));
11
- }
12
- return format(lChanges, lOptions.outputType);
13
- }
14
5
  export async function list(pOldRevision, pNewRevision, pOptions) {
15
- const lOldRevision = pOldRevision || (await getSHA());
6
+ const lOldRevision = pOldRevision || (await primitives.getSHA());
16
7
  const lOptions = pOptions || {};
17
8
  const [lDiffLines, lStatusLines] = await Promise.all([
18
- getDiffLines(lOldRevision, pNewRevision),
19
- !lOptions.trackedOnly ? getStatusShort() : "",
9
+ primitives.getDiffLines(lOldRevision, pNewRevision),
10
+ !lOptions.trackedOnly ? primitives.getStatusShort() : "",
20
11
  ]);
21
12
  let lChanges = convertDiffLines(lDiffLines);
22
13
  if (!lOptions.trackedOnly) {
@@ -24,5 +15,18 @@ export async function list(pOldRevision, pNewRevision, pOptions) {
24
15
  }
25
16
  return format(lChanges, lOptions.outputType);
26
17
  }
27
- export { getSHASync } from "./git-primitives-sync.js";
28
- export { getSHA } from "./git-primitives.js";
18
+ export function listSync(pOldRevision, pNewRevision, pOptions) {
19
+ const lOldRevision = pOldRevision || primitivesSync.getSHASync();
20
+ const lOptions = pOptions || {};
21
+ let lChanges = convertDiffLines(primitivesSync.getDiffLinesSync(lOldRevision, pNewRevision));
22
+ if (!lOptions.trackedOnly) {
23
+ lChanges = lChanges.concat(convertStatusLines(primitivesSync.getStatusShortSync()).filter(({ changeType }) => changeType === "untracked"));
24
+ }
25
+ return format(lChanges, lOptions.outputType);
26
+ }
27
+ export function getSHA() {
28
+ return primitives.getSHA();
29
+ }
30
+ export function getSHASync() {
31
+ return primitivesSync.getSHASync();
32
+ }
@@ -0,0 +1 @@
1
+ export const VERSION = "0.11.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watskeburt",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "description": "List files changed since a git revision",
5
5
  "keywords": [
6
6
  "git",
@@ -43,17 +43,14 @@
43
43
  "package.json",
44
44
  "README.md"
45
45
  ],
46
- "dependencies": {
47
- "commander": "10.0.1"
48
- },
49
46
  "devDependencies": {
50
47
  "@types/mocha": "10.0.1",
51
- "@types/node": "18.16.2",
52
- "@typescript-eslint/eslint-plugin": "5.59.1",
53
- "c8": "7.13.0",
54
- "dependency-cruiser": "13.0.0-beta-5",
55
- "esbuild": "0.17.18",
56
- "eslint": "8.39.0",
48
+ "@types/node": "20.2.5",
49
+ "@typescript-eslint/eslint-plugin": "5.59.7",
50
+ "c8": "7.14.0",
51
+ "dependency-cruiser": "13.0.2",
52
+ "esbuild": "0.17.19",
53
+ "eslint": "8.41.0",
57
54
  "eslint-config-moving-meadow": "4.0.2",
58
55
  "eslint-config-prettier": "8.8.0",
59
56
  "eslint-plugin-budapestian": "5.0.1",
@@ -62,7 +59,7 @@
62
59
  "eslint-plugin-mocha": "10.1.0",
63
60
  "eslint-plugin-node": "11.1.0",
64
61
  "eslint-plugin-security": "1.7.1",
65
- "eslint-plugin-unicorn": "46.0.0",
62
+ "eslint-plugin-unicorn": "47.0.0",
66
63
  "mocha": "10.2.0",
67
64
  "npm-run-all": "4.1.5",
68
65
  "prettier": "2.8.8",
@@ -70,21 +67,12 @@
70
67
  "typescript": "5.0.4",
71
68
  "upem": "7.3.2"
72
69
  },
73
- "upem": {
74
- "policies": [
75
- {
76
- "package": "dependency-cruiser",
77
- "policy": "wanted",
78
- "because": "we're beta testing v13 & policy 'latest' would downgraded it back to v12 again"
79
- }
80
- ]
81
- },
82
70
  "engines": {
83
- "node": "^14||^16||>=18"
71
+ "node": "^16.19||^18.11||>=20"
84
72
  },
85
73
  "scripts": {
86
74
  "build": "npm-run-all --sequential build:clean build:version build:dist",
87
- "build:version": "ts-node --esm tools/get-version.ts > bin/version.js",
75
+ "build:version": "node --no-warnings --loader ts-node/esm tools/get-version.ts > src/version.ts",
88
76
  "build:clean": "rm -rf dist/*",
89
77
  "build:dist": "npm-run-all build:dist:*",
90
78
  "build:dist:cjs": "esbuild src/main.ts --format=cjs --target=node14 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.cjs",
package/bin/version.js DELETED
@@ -1,2 +0,0 @@
1
- // generated by tools/get-version.ts - edits will be overwritten
2
- export const VERSION = "0.11.1";