watskeburt
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -9,3 +9,3 @@ import { EOL } from "node:os"; | ||
-> When you don't pass a revision at all old-revision defaults to the current one. | ||
-> When you don't pass a revision old-revision defaults to the current one. | ||
@@ -12,0 +12,0 @@ Options: |
import { parseDiffLines } from "./parse-diff-lines.js"; | ||
import { parseStatusLines } from "./parse-status-lines.js"; | ||
import * as primitives from "./git-primitives.js"; | ||
import format from "./formatters/format.js"; | ||
export async function list(pOptions) { | ||
@@ -16,6 +15,10 @@ const lOldRevision = pOptions?.oldRevision || (await primitives.getSHA()); | ||
parseStatusLines(lStatusLines).filter( | ||
({ changeType }) => changeType === "untracked", | ||
({ type: changeType }) => changeType === "untracked", | ||
), | ||
); | ||
} | ||
if (!lOptions.outputType) { | ||
return lChanges; | ||
} | ||
const { format } = await import("./format/format.js"); | ||
return format(lChanges, lOptions.outputType); | ||
@@ -22,0 +25,0 @@ } |
@@ -10,3 +10,5 @@ import { EOL } from "node:os"; | ||
.map(parseDiffLine) | ||
.filter(({ name, changeType }) => Boolean(name) && Boolean(changeType)); | ||
.filter( | ||
({ name, type: changeType }) => Boolean(name) && Boolean(changeType), | ||
); | ||
} | ||
@@ -17,5 +19,3 @@ export function parseDiffLine(pString) { | ||
if (lMatchResult?.groups) { | ||
lReturnValue.changeType = changeChar2ChangeType( | ||
lMatchResult.groups.changeType, | ||
); | ||
lReturnValue.type = changeChar2ChangeType(lMatchResult.groups.changeType); | ||
if (lMatchResult.groups.newName) { | ||
@@ -22,0 +22,0 @@ lReturnValue.name = lMatchResult.groups.newName; |
@@ -10,3 +10,5 @@ import { EOL } from "node:os"; | ||
.map(parseStatusLine) | ||
.filter(({ name, changeType }) => Boolean(name) && Boolean(changeType)); | ||
.filter( | ||
({ name, type: changeType }) => Boolean(name) && Boolean(changeType), | ||
); | ||
} | ||
@@ -23,3 +25,3 @@ export function parseStatusLine(pString) { | ||
); | ||
lReturnValue.changeType = | ||
lReturnValue.type = | ||
lStagedChangeType === "unmodified" | ||
@@ -26,0 +28,0 @@ ? lUnStagedChangeType |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "3.0.0"; | ||
export const VERSION = "4.0.0"; |
{ | ||
"name": "watskeburt", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "List files changed since a git revision", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,17 +5,2 @@ # watskeburt | ||
## what's this do? | ||
A micro-lib to retrieve an array of file names that were changed since a | ||
revision. Also sports a cli for use outside of JavaScript c.s. | ||
## why? | ||
I needed something simple and robust to support some upcoming features in | ||
[dependency-cruiser](https://github.com/sverweij/dependency-cruiser) and to | ||
run standalone to use _in combination_ with dependency-cruiser. | ||
There are a few specialized packages like this on npm, but it seems they've | ||
fallen out of maintenance. More generic packages are still maintained, | ||
but for just this simple usage they're a bit overkill. | ||
## :construction_worker: usage | ||
@@ -34,3 +19,3 @@ | ||
/** @type {import('watskeburt').IChange[]} */ | ||
const lChangedFiles = await list("main"); | ||
const lChangedFiles = await list({ oldRevision: "main" }); | ||
@@ -40,11 +25,14 @@ // list all files that differ between 'v0.6.1' and 'v0.7.1' (by definition | ||
/** @type {import('watskeburt').IChange[]} */ | ||
const lChangedFiles = await list("v0.6.1", "v0.7.1"); | ||
const lChangedFiles = await list({ | ||
oldRevision: "v0.6.1", | ||
newRevision: "v0.7.1", | ||
}); | ||
// list all files that differ between 'main' and the current revision | ||
// (excluding files not staged for commit) | ||
/** @type {import('watskeburt').IChange[]|string} */ | ||
const lChangedFiles = await list({ | ||
oldRevision: "main", | ||
// this compares the working tree with the oldRevision. If you want to compare | ||
// to another branch or revision you can pass that in a `newRevision` field | ||
trackedOnly: false, // when set to true leaves out files not under revision control | ||
outputType: "object", // other options: "json" and "regex" (as used in the CLI) | ||
outputType: "json", // options: "object", "json" and "regex" | ||
}); | ||
@@ -59,7 +47,7 @@ ``` | ||
name: "doc/cli.md", | ||
changeType: "modified", | ||
type: "modified", | ||
}, | ||
{ | ||
name: "test/thing.spec.mjs", | ||
changeType: "renamed", | ||
type: "renamed", | ||
oldName: "test/old-thing.spec.mjs", | ||
@@ -69,3 +57,3 @@ }, | ||
name: "src/not-tracked-yet.mjs", | ||
changeType: "untracked", | ||
type: "untracked", | ||
}, | ||
@@ -77,3 +65,3 @@ ]; | ||
There's also a simple command line interface (which works from node >=18.11). | ||
Works with node >=18.11 | ||
@@ -86,8 +74,7 @@ ```shell | ||
By default this returns a regex that contains all changed files that could be | ||
source files in the JavaScript ecosystem (.js, .mjs, .ts, .tsx ...) that can | ||
be used in e.g. the `--focus` and `--reaches` filters of dependency-cruiser. | ||
This emits a regex that contains all changed files that could be | ||
source files in the JavaScript ecosystem (.js, .mjs, .ts, .tsx ...). It can | ||
be used in e.g. dependency-cruiser's `--focus` and `--reaches` filters. | ||
The JSON output (which looks a lot like the array above) is unfiltered and | ||
also contains other extensions. | ||
The JSON output (= the array above, serialized) also contains other extensions. | ||
@@ -99,3 +86,3 @@ ``` | ||
-> When you don't pass a revision at all old-revision defaults to the current one. | ||
-> When you don't pass a revision old-revision defaults to the current one. | ||
@@ -109,2 +96,12 @@ Options: | ||
## why? | ||
I needed something robust to support caching in | ||
[dependency-cruiser](https://github.com/sverweij/dependency-cruiser) and to | ||
run standalone to use _in combination_ with dependency-cruiser. | ||
A few specialized packages like this existed, but they had fallen out of | ||
maintenance. More generic packages still were maintained, but for my use | ||
case they were overkill. | ||
## 🇳🇱 what does 'watskeburt' mean? | ||
@@ -115,4 +112,2 @@ | ||
_watskeburt_ is a fast pronunciation of the Dutch "wat is er gebeurd?" | ||
(_what has happened?_) or "wat er is gebeurd" (_what has happened_). It's | ||
also the title of a song by the Dutch band "De Jeugd van Tegenwoordig" | ||
(_Youth these days_). | ||
(_what has happened?_) or "wat er is gebeurd" (_what has happened_). |
@@ -1,2 +0,2 @@ | ||
export type changeTypeType = | ||
export type changeType = | ||
| "added" | ||
@@ -23,3 +23,3 @@ | "copied" | ||
*/ | ||
changeType: changeTypeType; | ||
type: changeType; | ||
/** | ||
@@ -31,21 +31,18 @@ * if the file was renamed: what the old file's name was | ||
export type outputTypeType = "regex" | "json" | "object"; | ||
export type outputTypeType = "regex" | "json"; | ||
export interface IBaseOptions { | ||
/** | ||
* The revision against which to compare. E.g. a commit-hash, | ||
* a branch or a tag. When not passed defaults to the _current_ | ||
* commit hash (if there's any) | ||
* The revision against which to compare. When not passed defaults to the | ||
* _current_ commit hash (if there's any) | ||
*/ | ||
oldRevision?: string; | ||
/** | ||
* Newer revision against which to compare. Leave out or pass | ||
* null when you want to compare against the working tree | ||
* Newer revision against which to compare. Leave out when you want to | ||
* compare against the working tree | ||
*/ | ||
newRevision?: string; | ||
/** | ||
* When true _only_ takes already tracked files into account. | ||
* When false also takes untracked files into account. | ||
* | ||
* Defaults to false. | ||
* When true only takes already tracked files into account. | ||
* When false also takes untracked files into account (default) | ||
*/ | ||
@@ -57,4 +54,3 @@ trackedOnly?: boolean; | ||
/** | ||
* The type of output to deliver. Defaults to "object" - in which case | ||
* the listSync function returns an IChange[] object | ||
* The type of output to deliver. | ||
*/ | ||
@@ -66,6 +62,6 @@ outputType: "regex" | "json"; | ||
/** | ||
* The type of output to deliver. Defaults to "object" - in which case | ||
* the listSync function returns an IChange[] object | ||
* The type of output to deliver. undefined/ left out | ||
* the outputType defaults to a list of `IChange`s | ||
*/ | ||
outputType?: "object"; | ||
outputType?: undefined; | ||
} | ||
@@ -76,3 +72,3 @@ | ||
/** | ||
* returns a promise of a list of files changed since pOldRevision. | ||
* promises a list of files changed since pOldRevision. | ||
* | ||
@@ -84,3 +80,3 @@ * @throws {Error} | ||
/** | ||
* returns a promise of a list of files changed since pOldRevision, formatted | ||
* promises a list of files changed since pOldRevision, formatted | ||
* into a string as a pOptions.outputType | ||
@@ -93,3 +89,3 @@ * | ||
/** | ||
* Returns the SHA1 of the current HEAD | ||
* Promises the SHA1 of the current HEAD | ||
* | ||
@@ -96,0 +92,0 @@ * @throws {Error} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16600
397
104