watskeburt 2.0.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2022-2023 Sander Verweij
3
+ Copyright (c) 2022-2024 Sander Verweij
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -37,11 +37,11 @@ const lChangedFiles = await list("main");
37
37
  /** @type {import('watskeburt').IChange[]} */
38
38
  const lChangedFiles = await list("v0.6.1", "v0.7.1");
39
39
 
40
- // As a third parameter you can pass some options
41
- // (pass null as the second parameter if you only want to compare between
42
- // a revision and the working tree):
43
40
  /** @type {import('watskeburt').IChange[]|string} */
44
- const lChangedFiles = await list("main", null, {
41
+ const lChangedFiles = await list({
42
+ oldRevision: "main",
43
+ // this compares the working tree with the oldRevision. If you want to compare
44
+ // to another branch or revision you can pass that in a `newRevision` field
45
45
  trackedOnly: false, // when set to true leaves out files not under revision control
46
46
  outputType: "object", // other options: "json" and "regex" (as used in the CLI)
47
47
  });
@@ -69,8 +69,7 @@ The array of changes this returns looks like this:
69
69
 
70
70
  ### :shell: cli
71
71
 
72
- For now there's also a simple command line interface (which works from node ^16.19 and
73
- node >=18.11).
72
+ There's also a simple command line interface (which works from node >=18.11).
74
73
 
75
74
  ```shell
76
75
  # list all JavaScript-ish files changed since main in a regular expression
package/dist/cli.js CHANGED
@@ -36,11 +36,11 @@ export async function cli(
36
36
  process.exitCode = pErrorExitCode;
37
37
  return;
38
38
  }
39
- const lResult = await list(
40
- lArguments.positionals[0],
41
- lArguments.positionals[1],
42
- lArguments.values,
43
- );
39
+ const lResult = await list({
40
+ ...lArguments.values,
41
+ oldRevision: lArguments.positionals[0],
42
+ newRevision: lArguments.positionals[1],
43
+ });
44
44
  pOutStream.write(`${lResult}${EOL}`);
45
45
  } catch (pError) {
46
46
  pErrorStream.write(`${EOL}ERROR: ${pError.message}${EOL}${EOL}`);
@@ -18,9 +18,7 @@ export async function getDiffLines(
18
18
  const lErrorMap = new Map([
19
19
  [
20
20
  128,
21
- `revision '${pOldRevision}' ${
22
- pNewRevision ? `(or '${pNewRevision}') ` : ""
23
- }unknown`,
21
+ `revision '${pOldRevision}' ${pNewRevision ? `(or '${pNewRevision}') ` : ""}unknown`,
24
22
  ],
25
23
  [129, `'${process.cwd()}' does not seem to be a git repository`],
26
24
  ]);
@@ -63,9 +61,7 @@ function getGitResult(pArguments, pErrorMap, pSpawnFunction) {
63
61
  pReject(
64
62
  new Error(
65
63
  pErrorMap.get(pCode ?? 0) ||
66
- `internal git error: ${pCode} (${stringifyOutStream(
67
- lStdErrorData,
68
- )})`,
64
+ `internal git error: ${pCode} (${stringifyOutStream(lStdErrorData)})`,
69
65
  ),
70
66
  );
71
67
  }
package/dist/main.js CHANGED
@@ -2,11 +2,11 @@ import { parseDiffLines } from "./parse-diff-lines.js";
2
2
  import { parseStatusLines } from "./parse-status-lines.js";
3
3
  import * as primitives from "./git-primitives.js";
4
4
  import format from "./formatters/format.js";
5
- export async function list(pOldRevision, pNewRevision, pOptions) {
6
- const lOldRevision = pOldRevision || (await primitives.getSHA());
5
+ export async function list(pOptions) {
6
+ const lOldRevision = pOptions?.oldRevision || (await primitives.getSHA());
7
7
  const lOptions = pOptions || {};
8
8
  const [lDiffLines, lStatusLines] = await Promise.all([
9
- primitives.getDiffLines(lOldRevision, pNewRevision),
9
+ primitives.getDiffLines(lOldRevision, pOptions?.newRevision),
10
10
  !lOptions.trackedOnly ? primitives.getStatusShort() : "",
11
11
  ]);
12
12
  let lChanges = parseDiffLines(lDiffLines);
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "2.0.4";
1
+ export const VERSION = "3.0.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watskeburt",
3
- "version": "2.0.4",
3
+ "version": "3.0.0",
4
4
  "description": "List files changed since a git revision",
5
5
  "keywords": [
6
6
  "git",
@@ -44,62 +44,10 @@
44
44
  "package.json",
45
45
  "README.md"
46
46
  ],
47
- "devDependencies": {
48
- "@types/node": "20.10.5",
49
- "@typescript-eslint/eslint-plugin": "6.16.0",
50
- "c8": "8.0.1",
51
- "dependency-cruiser": "15.5.0",
52
- "eslint": "8.56.0",
53
- "eslint-config-moving-meadow": "4.0.2",
54
- "eslint-config-prettier": "9.1.0",
55
- "eslint-plugin-budapestian": "6.0.0",
56
- "eslint-plugin-eslint-comments": "3.2.0",
57
- "eslint-plugin-import": "2.29.1",
58
- "eslint-plugin-mocha": "10.2.0",
59
- "eslint-plugin-node": "11.1.0",
60
- "eslint-plugin-security": "2.1.0",
61
- "eslint-plugin-unicorn": "50.0.1",
62
- "npm-run-all": "4.1.5",
63
- "prettier": "3.1.1",
64
- "tsx": "4.7.0",
65
- "typescript": "5.3.3",
66
- "upem": "9.0.2"
67
- },
68
47
  "engines": {
69
48
  "node": "^18||>=20"
70
49
  },
71
50
  "scripts": {
72
- "build": "npm-run-all --sequential build:clean build:version build:dist build:format",
73
- "build:version": "tsx tools/get-version.ts > src/version.ts",
74
- "build:clean": "rm -rf dist/*",
75
- "build:dist": "tsc",
76
- "build:format": "prettier --log-level warn --write dist/",
77
- "check": "npm-run-all --parallel --aggregate-output lint depcruise test:cover",
78
- "clean": "rm -rf dist",
79
- "test": "tsx --test-reporter ./tools/dot-with-summary.reporter.js --test src/*.spec.ts src/**/*.spec.ts",
80
- "test:cover": "c8 npm test",
81
- "depcruise": "depcruise dist src types",
82
- "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",
83
- "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",
84
- "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",
85
- "depcruise:graph:diff:dev": "depcruise dist src types --include-only '^(dist|src|types)' --highlight \"$(node dist/run-cli.js main -T regex)\" --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser",
86
- "depcruise:graph:diff:mermaid": "depcruise dist src types --include-only '^(dist|src|types)' --output-type mermaid --output-to - --highlight \"$(node dist/run-cli.js $SHA -T regex)\"",
87
- "depcruise:html": "depcruise src types --progress --output-type err-html --output-to dependency-violation-report.html",
88
- "depcruise:text": "depcruise src types --progress --output-type text",
89
- "depcruise:focus": "depcruise src types --progress --output-type text --focus",
90
- "depcruise:reaches": "depcruise src types --progress --output-type text --reaches",
91
- "format": "prettier --write \"{src,tools}/**/*.{js,ts}\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
92
- "format:check": "prettier --log-level warn --check \"{src,tools}/**/*.ts\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"",
93
- "lint": "npm-run-all --parallel --aggregate-output format:check lint:eslint lint:types",
94
- "lint:fix": "npm-run-all --parallel --aggregate-output format lint:eslint:fix",
95
- "lint:eslint": "eslint src types tools --cache --cache-location node_modules/.cache/eslint/",
96
- "lint:eslint:fix": "eslint src types tools --fix --cache --cache-location node_modules/.cache/eslint/",
97
- "lint:types": "tsc --noEmit",
98
- "scm:stage": "git add .",
99
- "update-dependencies": "run-s upem:update upem:install lint:fix check",
100
- "upem-outdated": "npm outdated --json --long | upem --dry-run",
101
- "upem:install": "npm install",
102
- "upem:update": "npm outdated --json --long | upem | pbcopy && pbpaste",
103
- "version": "npm-run-all --sequential clean build lint depcruise:graph scm:stage"
51
+ "test": "echo for test, build and static analysis scripts: see the github repository"
104
52
  }
105
53
  }
@@ -29,12 +29,18 @@ export interface IChange {
29
29
 
30
30
  export type outputTypeType = "regex" | "json" | "object";
31
31
 
32
- export interface IFormatOptions {
32
+ export interface IBaseOptions {
33
33
  /**
34
- * The type of output to deliver. Defaults to "object" - in which case
35
- * the listSync function returns an IChange[] object
34
+ * The revision against which to compare. E.g. a commit-hash,
35
+ * a branch or a tag. When not passed defaults to the _current_
36
+ * commit hash (if there's any)
36
37
  */
37
- outputType: "regex" | "json";
38
+ oldRevision?: string;
39
+ /**
40
+ * Newer revision against which to compare. Leave out or pass
41
+ * null when you want to compare against the working tree
42
+ */
43
+ newRevision?: string;
38
44
  /**
39
45
  * When true _only_ takes already tracked files into account.
40
46
  * When false also takes untracked files into account.
@@ -44,59 +50,38 @@ export interface IFormatOptions {
44
50
  trackedOnly?: boolean;
45
51
  }
46
52
 
47
- export interface IInternalOptions {
53
+ export interface IFormatOptions extends IBaseOptions {
48
54
  /**
49
55
  * The type of output to deliver. Defaults to "object" - in which case
50
56
  * the listSync function returns an IChange[] object
51
57
  */
52
- outputType?: "object";
58
+ outputType: "regex" | "json";
59
+ }
60
+
61
+ export interface IInternalOptions extends IBaseOptions {
53
62
  /**
54
- * When true _only_ takes already tracked files into account.
55
- * When false also takes untracked files into account.
56
- *
57
- * Defaults to false.
63
+ * The type of output to deliver. Defaults to "object" - in which case
64
+ * the listSync function returns an IChange[] object
58
65
  */
59
- trackedOnly?: boolean;
66
+ outputType?: "object";
60
67
  }
61
68
 
62
69
  export type IOptions = IFormatOptions | IInternalOptions;
63
70
 
64
71
  /**
65
- * returns promise of a list of files changed since pOldRevision.
72
+ * returns a promise of a list of files changed since pOldRevision.
66
73
  *
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
74
  * @throws {Error}
75
75
  */
76
- export function list(
77
- pOldRevision?: string,
78
- pNewRevision?: string,
79
- pOptions?: IInternalOptions,
80
- ): Promise<IChange[]>;
76
+ export function list(pOptions?: IInternalOptions): Promise<IChange[]>;
81
77
 
82
78
  /**
83
- * returns promise a list of files changed since pOldRevision, formatted into a
84
- * string as a pOptions.outputType
79
+ * returns a promise of a list of files changed since pOldRevision, formatted
80
+ * into a string as a pOptions.outputType
85
81
  *
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
82
  * @throws {Error}
94
83
  */
95
- export function list(
96
- pOldRevision?: string,
97
- pNewRevision?: string,
98
- pOptions?: IFormatOptions,
99
- ): Promise<string>;
84
+ export function list(pOptions?: IFormatOptions): Promise<string>;
100
85
 
101
86
  /**
102
87
  * Returns the SHA1 of the current HEAD