watskeburt 0.11.5 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -24,26 +24,21 @@ but for just this simple usage they're a bit overkill.
24
24
  ### :scroll: API
25
25
 
26
26
  ```javascript
27
- // const { listSync, getSHASync } = require("watskeburt"); // in commonjs contexts you can also require it
28
- import { list, getSHA, listSync, getSHASync } from "watskeburt";
27
+ // const { list, getSHA } = require("watskeburt"); // in commonjs contexts you can also require it
28
+ import { list, getSHA } from "watskeburt";
29
29
 
30
30
  // print the SHA1 of the current HEAD
31
31
  console.log(await getSHA());
32
- console.log(getSHASync());
33
32
 
34
33
  // list all files that differ between 'main' and the current revision (including
35
34
  // files not staged for commit and files not under revision control)
36
35
  /** @type {import('watskeburt').IChange[]} */
37
36
  const lChangedFiles = await list("main");
38
- // or with the synchronous interface:
39
- // const lChangedFiles = listSync("main");
40
37
 
41
38
  // list all files that differ between 'v0.6.1' and 'v0.7.1' (by definition
42
39
  // won't include files staged for commit and/ or not under revision control)
43
40
  /** @type {import('watskeburt').IChange[]} */
44
41
  const lChangedFiles = await list("v0.6.1", "v0.7.1");
45
- // or with the synchronous interface:
46
- // const lChangedFiles = listSync("v0.6.1", "v0.7.1");
47
42
 
48
43
  // As a third parameter you can pass some options
49
44
  // (pass null as the second parameter if you only want to compare between
@@ -53,11 +48,6 @@ const lChangedFiles = await list("main", null, {
53
48
  trackedOnly: false, // when set to true leaves out files not under revision control
54
49
  outputType: "object", // other options: "json" and "regex" (as used in the CLI)
55
50
  });
56
- // or with the synchronous interface:
57
- // const lChangedFiles = listSync("main", null, {
58
- // trackedOnly: false, // when set to true leaves out files not under revision control
59
- // outputType: "object", // other options: "json" and "regex" (as used in the CLI)
60
- // });
61
51
  ```
62
52
 
63
53
  The array of changes this returns looks like this:
package/dist/esm/cli.js CHANGED
@@ -1,63 +1,3 @@
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
- }
1
+ #!/usr/bin/env node
2
+ import { cli } from "./execute-cli.js";
3
+ await cli();
@@ -1,19 +1,19 @@
1
1
  import { EOL } from "node:os";
2
2
  const DIFF_NAME_STATUS_LINE_PATTERN = /^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/;
3
3
  const DIFF_SHORT_STATUS_LINE_PATTERN = /^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/;
4
- const CHANGE_CHAR_2_CHANGE_TYPE = {
5
- A: "added",
6
- C: "copied",
7
- D: "deleted",
8
- M: "modified",
9
- R: "renamed",
10
- T: "type changed",
11
- U: "unmerged",
12
- B: "pairing broken",
13
- " ": "unmodified",
14
- "?": "untracked",
15
- "!": "ignored",
16
- };
4
+ const CHANGE_CHAR_2_CHANGE_TYPE = new Map([
5
+ ["A", "added"],
6
+ ["C", "copied"],
7
+ ["D", "deleted"],
8
+ ["M", "modified"],
9
+ ["R", "renamed"],
10
+ ["T", "type changed"],
11
+ ["U", "unmerged"],
12
+ ["B", "pairing broken"],
13
+ [" ", "unmodified"],
14
+ ["?", "untracked"],
15
+ ["!", "ignored"],
16
+ ]);
17
17
  export function convertStatusLines(pString) {
18
18
  return pString
19
19
  .split(EOL)
@@ -64,5 +64,5 @@ export function convertDiffLine(pString) {
64
64
  return lReturnValue;
65
65
  }
66
66
  function changeChar2ChangeType(pChar) {
67
- return CHANGE_CHAR_2_CHANGE_TYPE[pChar] ?? "unknown";
67
+ return CHANGE_CHAR_2_CHANGE_TYPE.get(pChar) ?? "unknown";
68
68
  }
@@ -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, pErrorExitCode = 1) {
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 = pErrorExitCode;
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 = pErrorExitCode;
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
+ }
@@ -1,16 +1,19 @@
1
1
  import { spawn } from "node:child_process";
2
2
  export async function getStatusShort(pSpawnFunction = spawn) {
3
- const lErrorMap = {
4
- 129: `'${process.cwd()}' does not seem to be a git repository`,
5
- };
3
+ const lErrorMap = new Map([
4
+ [129, `'${process.cwd()}' does not seem to be a git repository`],
5
+ ]);
6
6
  const lResult = await getGitResult(["status", "--porcelain"], lErrorMap, pSpawnFunction);
7
7
  return lResult;
8
8
  }
9
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
- };
10
+ const lErrorMap = new Map([
11
+ [
12
+ 128,
13
+ `revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
14
+ ],
15
+ [129, `'${process.cwd()}' does not seem to be a git repository`],
16
+ ]);
14
17
  const lResult = await getGitResult(pNewRevision
15
18
  ? ["diff", pOldRevision, pNewRevision, "--name-status"]
16
19
  : ["diff", pOldRevision, "--name-status"], lErrorMap, pSpawnFunction);
@@ -18,7 +21,7 @@ export async function getDiffLines(pOldRevision, pNewRevision, pSpawnFunction =
18
21
  }
19
22
  export async function getSHA(pSpawnFunction = spawn) {
20
23
  const lSha1Length = 40;
21
- const lResult = await getGitResult(["rev-parse", "HEAD"], {}, pSpawnFunction);
24
+ const lResult = await getGitResult(["rev-parse", "HEAD"], new Map(), pSpawnFunction);
22
25
  return lResult.slice(0, lSha1Length);
23
26
  }
24
27
  function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
@@ -40,7 +43,7 @@ function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
40
43
  pResolve(stringifyOutStream(lStdOutData));
41
44
  }
42
45
  else {
43
- pReject(new Error(pErrorMap[pCode ?? 0] ||
46
+ pReject(new Error(pErrorMap.get(pCode ?? 0) ||
44
47
  `internal git error: ${pCode} (${stringifyOutStream(lStdErrorData)})`));
45
48
  }
46
49
  });
package/dist/esm/main.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { convertDiffLines, convertStatusLines, } from "./convert-to-change-object.js";
2
- import * as primitivesSync from "./git-primitives-sync.js";
3
2
  import * as primitives from "./git-primitives.js";
4
3
  import format from "./formatters/format.js";
5
4
  export async function list(pOldRevision, pNewRevision, pOptions) {
@@ -15,18 +14,6 @@ export async function list(pOldRevision, pNewRevision, pOptions) {
15
14
  }
16
15
  return format(lChanges, lOptions.outputType);
17
16
  }
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
17
  export function getSHA() {
28
18
  return primitives.getSHA();
29
19
  }
30
- export function getSHASync() {
31
- return primitivesSync.getSHASync();
32
- }
@@ -1 +1 @@
1
- export const VERSION = "0.11.5";
1
+ export const VERSION = "0.12.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watskeburt",
3
- "version": "0.11.5",
3
+ "version": "0.12.0",
4
4
  "description": "List files changed since a git revision",
5
5
  "keywords": [
6
6
  "git",
@@ -19,23 +19,21 @@
19
19
  "url": "https://sverweij.github.io"
20
20
  },
21
21
  "license": "MIT",
22
- "bin": "bin/cli.js",
23
- "main": "dist/cjs-bundle.cjs",
22
+ "bin": "dist/esm/cli.js",
23
+ "main": "dist/esm/main.js",
24
24
  "module": "dist/esm/main.js",
25
25
  "type": "module",
26
26
  "sideEffects": false,
27
27
  "exports": {
28
28
  ".": [
29
29
  {
30
- "import": "./dist/esm/main.js",
31
- "require": "./dist/cjs-bundle.cjs"
30
+ "import": "./dist/esm/main.js"
32
31
  },
33
- "./dist/cjs-bundle.cjs"
32
+ "./dist/esm/main.js"
34
33
  ]
35
34
  },
36
35
  "types": "types/watskeburt.d.ts",
37
36
  "files": [
38
- "bin",
39
37
  "dist",
40
38
  "!**/*.DS_Store",
41
39
  "types",
@@ -44,13 +42,11 @@
44
42
  "README.md"
45
43
  ],
46
44
  "devDependencies": {
47
- "@types/mocha": "10.0.1",
48
- "@types/node": "20.3.1",
49
- "@typescript-eslint/eslint-plugin": "5.60.0",
45
+ "@types/node": "20.4.1",
46
+ "@typescript-eslint/eslint-plugin": "6.0.0",
50
47
  "c8": "8.0.0",
51
- "dependency-cruiser": "13.0.3",
52
- "esbuild": "0.18.5",
53
- "eslint": "8.43.0",
48
+ "dependency-cruiser": "13.1.0",
49
+ "eslint": "8.44.0",
54
50
  "eslint-config-moving-meadow": "4.0.2",
55
51
  "eslint-config-prettier": "8.8.0",
56
52
  "eslint-plugin-budapestian": "5.0.1",
@@ -60,11 +56,10 @@
60
56
  "eslint-plugin-node": "11.1.0",
61
57
  "eslint-plugin-security": "1.7.1",
62
58
  "eslint-plugin-unicorn": "47.0.0",
63
- "mocha": "10.2.0",
64
59
  "npm-run-all": "4.1.5",
65
- "prettier": "2.8.8",
60
+ "prettier": "3.0.0",
66
61
  "ts-node": "10.9.1",
67
- "typescript": "5.1.3",
62
+ "typescript": "5.1.6",
68
63
  "upem": "8.0.0"
69
64
  },
70
65
  "engines": {
@@ -74,29 +69,28 @@
74
69
  "build": "npm-run-all --sequential build:clean build:version build:dist",
75
70
  "build:version": "node --no-warnings --loader ts-node/esm tools/get-version.ts > src/version.ts",
76
71
  "build:clean": "rm -rf dist/*",
77
- "build:dist": "npm-run-all build:dist:*",
78
- "build:dist:cjs": "esbuild src/main.ts --format=cjs --target=node14 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.cjs",
79
- "build:dist:esm": "tsc",
72
+ "build:dist": "tsc",
80
73
  "check": "npm-run-all --parallel --aggregate-output lint depcruise test:cover",
81
74
  "clean": "rm -rf dist",
82
- "test": "NODE_OPTIONS=--no-warnings mocha",
83
- "test:cover": "NODE_OPTIONS=--no-warnings c8 mocha",
84
- "depcruise": "depcruise bin dist src types",
85
- "depcruise:graph": "depcruise bin src types --include-only '^(bin|dist|src|types)' --output-type dot | dot -T svg | tee docs/dependency-graph.svg | depcruise-wrap-stream-in-html > docs/dependency-graph.html",
86
- "depcruise:graph:archi": "depcruise bin src --include-only '^(bin|dist|src|types)' --output-type archi | dot -T svg | depcruise-wrap-stream-in-html > docs/high-level-dependency-graph.html",
87
- "depcruise:graph:dev": "depcruise bin dist src types --include-only '^(bin|dist|src|types)' --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
88
- "depcruise:graph:diff:dev": "depcruise bin dist src types --include-only '^(bin|dist|src|types)' --highlight \"$(node bin/cli.js main -T regex)\" --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
89
- "depcruise:graph:diff:mermaid": "depcruise bin dist src types --include-only '^(bin|dist|src|types)' --output-type mermaid --output-to - --highlight \"$(node bin/cli.js $SHA -T regex)\"",
90
- "depcruise:html": "depcruise bin src types --progress --output-type err-html --output-to dependency-violation-report.html",
91
- "depcruise:text": "depcruise bin src types --progress --output-type text",
92
- "depcruise:focus": "depcruise bin src types --progress --output-type text --focus",
93
- "depcruise:reaches": "depcruise bin src types --progress --output-type text --reaches",
94
- "format": "prettier --write \"{bin,src,tools}/**/*.{js,ts}\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
95
- "format:check": "prettier --loglevel warn --check \"{bin,src,tools}/**/*.ts\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
75
+ "test": "node --no-warnings --loader 'ts-node/esm' --test-reporter dot --test src/*.spec.ts src/**/*.spec.ts",
76
+ "test:cover": "c8 npm test",
77
+ "test:only-for-node-16-without-the-test-reporter": "node --no-warnings --loader 'ts-node/esm' --test src/*.spec.ts src/**/*.spec.ts",
78
+ "depcruise": "depcruise dist src types",
79
+ "depcruise:graph": "depcruise src types --include-only '^(dist|src|types)' --output-type dot | dot -T svg | tee docs/dependency-graph.svg | depcruise-wrap-stream-in-html > docs/dependency-graph.html",
80
+ "depcruise:graph:archi": "depcruise src --include-only '^(dist|src|types)' --output-type archi | dot -T svg | depcruise-wrap-stream-in-html > docs/high-level-dependency-graph.html",
81
+ "depcruise:graph:dev": "depcruise dist src types --include-only '^(dist|src|types)' --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
82
+ "depcruise:graph:diff:dev": "depcruise dist src types --include-only '^(dist|src|types)' --highlight \"$(node dist/esm/cli.js main -T regex)\" --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
83
+ "depcruise:graph:diff:mermaid": "depcruise dist src types --include-only '^(dist|src|types)' --output-type mermaid --output-to - --highlight \"$(node dist/esm/cli.js $SHA -T regex)\"",
84
+ "depcruise:html": "depcruise src types --progress --output-type err-html --output-to dependency-violation-report.html",
85
+ "depcruise:text": "depcruise src types --progress --output-type text",
86
+ "depcruise:focus": "depcruise src types --progress --output-type text --focus",
87
+ "depcruise:reaches": "depcruise src types --progress --output-type text --reaches",
88
+ "format": "prettier --write \"{src,tools}/**/*.{js,ts}\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
89
+ "format:check": "prettier --log-level warn --check \"{src,tools}/**/*.ts\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
96
90
  "lint": "npm-run-all --parallel --aggregate-output format:check lint:eslint lint:types",
97
91
  "lint:fix": "npm-run-all --parallel --aggregate-output format lint:eslint:fix",
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/",
92
+ "lint:eslint": "eslint src types tools --cache --cache-location node_modules/.cache/eslint/",
93
+ "lint:eslint:fix": "eslint src types tools --fix --cache --cache-location node_modules/.cache/eslint/",
100
94
  "lint:types": "tsc --noEmit",
101
95
  "scm:stage": "git add .",
102
96
  "update-dependencies": "run-s upem:update upem:install lint:fix check",
@@ -61,43 +61,6 @@ export interface IInternalOptions {
61
61
 
62
62
  export type IOptions = IFormatOptions | IInternalOptions;
63
63
 
64
- /**
65
- * returns a list of files changed since pOldRevision.
66
- *
67
- * @param pOldRevision The revision against which to compare. E.g. a commit-hash,
68
- * a branch or a tag. When not passed defaults to the _current_
69
- * commit hash (if there's any)
70
- * @param pNewRevision Newer revision against which to compare. Leave out or pass
71
- * null when you want to compare against the working tree
72
- * @param pOptions Options that influence how the changes are returned and that
73
- * filter what is returned and
74
- * @throws {Error}
75
- */
76
- export function listSync(
77
- pOldRevision?: string,
78
- pNewRevision?: string,
79
- pOptions?: IInternalOptions
80
- ): IChange[];
81
-
82
- /**
83
- * returns a list of files changed since pOldRevision formatted into a string
84
- * as pOptions.outputType
85
- *
86
- * @param pOldRevision The revision against which to compare. E.g. a commit-hash,
87
- * a branch or a tag. When not passed defaults to the _current_
88
- * commit hash (if there's any)
89
- * @param pNewRevision Newer revision against which to compare. Leave out or pass
90
- * null when you want to compare against the working tree
91
- * @param pOptions Options that influence how the changes are returned and that
92
- * filter what is returned and
93
- * @throws {Error}
94
- */
95
- export function listSync(
96
- pOldRevision?: string,
97
- pNewRevision?: string,
98
- pOptions?: IFormatOptions
99
- ): string;
100
-
101
64
  /**
102
65
  * returns promise of a list of files changed since pOldRevision.
103
66
  *
@@ -113,7 +76,7 @@ export function listSync(
113
76
  export function list(
114
77
  pOldRevision?: string,
115
78
  pNewRevision?: string,
116
- pOptions?: IInternalOptions
79
+ pOptions?: IInternalOptions,
117
80
  ): Promise<IChange[]>;
118
81
 
119
82
  /**
@@ -132,16 +95,9 @@ export function list(
132
95
  export function list(
133
96
  pOldRevision?: string,
134
97
  pNewRevision?: string,
135
- pOptions?: IFormatOptions
98
+ pOptions?: IFormatOptions,
136
99
  ): Promise<string>;
137
100
 
138
- /**
139
- * Returns the SHA1 of the current HEAD
140
- *
141
- * @throws {Error}
142
- */
143
- export function getSHASync(): string;
144
-
145
101
  /**
146
102
  * Returns the SHA1 of the current HEAD
147
103
  *
package/bin/cli.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { cli } from "../dist/esm/cli.js";
4
-
5
- await cli();
@@ -1 +0,0 @@
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});
@@ -1,52 +0,0 @@
1
- import { spawnSync } from "node:child_process";
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);
7
- }
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);
20
- }
21
- function getGitResultSync(pArguments, pErrorMap, pSpawnFunction) {
22
- const lGitResult = pSpawnFunction("git", pArguments, {
23
- cwd: process.cwd(),
24
- env: process.env,
25
- });
26
- if (lGitResult.error) {
27
- throwSpawnError(lGitResult.error);
28
- }
29
- if (lGitResult.status === 0) {
30
- return stringifyOutStream(lGitResult.stdout);
31
- }
32
- else {
33
- throw new Error(pErrorMap[lGitResult.status ?? 0] ||
34
- `internal git error: ${lGitResult.status} (${stringifyOutStream(lGitResult.stderr)})`);
35
- }
36
- }
37
- function stringifyOutStream(pError) {
38
- if (pError instanceof Buffer) {
39
- return pError.toString("utf8");
40
- }
41
- else {
42
- return pError;
43
- }
44
- }
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
- }