Skip to content

Commit

Permalink
refactor!: do less when no formatting is needed, renames attributes -…
Browse files Browse the repository at this point in the history
… BREAKING (#45)

## Description

- stops doing a function call (or even importing the formatter) when no
formatting is needed
- enames lots of things for clarity and grammatical correctness. The 
BREAKING bit: the changeType attribute in an IChange is now called type
(BREAKING)
- with this, simplifies the format function to have 0 branches
- also ensures we use node:assert/strict always over node:assert


## Motivation and Context

- when running this as a library function this reduces overhead, bot on
import (as the formatting function is imported only then when it's
needed) and at runtime (skipping 2 function calls and a lookup).
- clear and concise naming makes using the package easier.

As a side effect of this PR the distribution size of the package reduces
from 6.1kB (17.1kB unpacked) to 5.9kb (16.9kB unpacked)

## How Has This Been Tested?

- [x] green ci
- [x] adapted automated non-regression tests

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [x] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
  • Loading branch information
sverweij authored Feb 24, 2024
1 parent 925402d commit 763f292
Show file tree
Hide file tree
Showing 30 changed files with 307 additions and 302 deletions.
19 changes: 17 additions & 2 deletions .dependency-cruiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export default {
reachable: false,
},
},
{
name: "use-assert-strict",
comment:
"This module uses 'node:assert'. It's better to use 'node:assert/strict' instead.",
severity: "error",
from: {},
to: {
path: "^assert$",
dependencyTypes: ["core"],
},
},
/* rules from the 'recommended' preset: */
{
name: "no-circular",
Expand Down Expand Up @@ -245,7 +256,7 @@ export default {
path: "node_modules",
},
moduleSystems: ["es6"],
prefix: "vscode://file/${process.cwd()}/",
prefix: `vscode://file/${process.cwd()}/`,
tsPreCompilationDeps: true,
tsConfig: {
fileName: "./tsconfig.json",
Expand Down Expand Up @@ -278,7 +289,11 @@ export default {
},
{
criteria: { source: ".spec.ts" },
attributes: { fillcolor: "#ccccff" },
attributes: {
fontcolor: "gray",
color: "gray",
fillcolor: "#faffff",
},
},
],
dependencies: [
Expand Down
32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

Get changed files & their statuses since any git _revision_

## what's this do?

A micro-lib to retrieve an array of file names that were changed since a
revision. Also sports a cli.

## :construction_worker: usage

### :scroll: API
Expand All @@ -31,7 +26,7 @@ const lChangedFiles = await list({
});

// list all files that differ between 'main' and the current revision
// (_excluding_ files not staged for commit)
// (excluding files not staged for commit)
/** @type {import('watskeburt').IChange[]|string} */
const lChangedFiles = await list({
oldRevision: "main",
Expand All @@ -46,16 +41,16 @@ The array of changes this returns looks like this:
[
{
name: "doc/cli.md",
changeType: "modified",
type: "modified",
},
{
name: "test/thing.spec.mjs",
changeType: "renamed",
type: "renamed",
oldName: "test/old-thing.spec.mjs",
},
{
name: "src/not-tracked-yet.mjs",
changeType: "untracked",
type: "untracked",
},
];
```
Expand All @@ -70,19 +65,18 @@ $ npx watskeburt main
^(src/cli[.]mjs|src/formatters/regex[.]mjs|src/version[.]mjs)$
```

By default this emits a regex that contains all changed files that could be
source files in the JavaScript ecosystem (.js, .mjs, .ts, .tsx ...). It's can
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 (= the array above, serialized) is unfiltered and
also contains other extensions.
The JSON output (= the array above, serialized) also contains other extensions.

```
Usage: watskeburt [options] [old-revision] [new-revision]
lists files & their statuses since [old-revision] or between [old-revision] and [new-revision].
-> 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.
Options:
-T, --outputType <type> what format to emit (choices: "json", "regex", default: "regex")
Expand All @@ -97,15 +91,13 @@ 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 exist, but it they've fallen out of
maintenance. More generic packages are still maintained, but for my simple use
case they're overkill.
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?

Wazzup.

_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_).
2 changes: 1 addition & 1 deletion dist/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions dist/format/format.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/formatters/json.js → dist/format/json.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/formatters/regex.js → dist/format/regex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions dist/formatters/format.js

This file was deleted.

7 changes: 5 additions & 2 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/parse-diff-lines.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions dist/parse-status-lines.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 763f292

Please sign in to comment.