@nodeve/checks 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -18
- package/dist/bin/catalog.js +3 -93
- package/dist/bin/catalog.js.map +1 -1
- package/dist/bin/check.d.ts +3 -0
- package/dist/bin/check.d.ts.map +1 -0
- package/dist/bin/check.js +69 -0
- package/dist/bin/check.js.map +1 -0
- package/dist/bin/clones.js +3 -58
- package/dist/bin/clones.js.map +1 -1
- package/dist/bin/commit-msg.js +3 -81
- package/dist/bin/commit-msg.js.map +1 -1
- package/dist/bin/doc-tokens.js +3 -66
- package/dist/bin/doc-tokens.js.map +1 -1
- package/dist/bin/file-size.js +3 -64
- package/dist/bin/file-size.js.map +1 -1
- package/dist/bin/helper-collisions.js +3 -92
- package/dist/bin/helper-collisions.js.map +1 -1
- package/dist/bin/inline-dupes.js +3 -77
- package/dist/bin/inline-dupes.js.map +1 -1
- package/dist/bin/page-size.js +3 -43
- package/dist/bin/page-size.js.map +1 -1
- package/dist/bin/require-deps.js +3 -47
- package/dist/bin/require-deps.js.map +1 -1
- package/dist/bin/reshape.js +3 -139
- package/dist/bin/reshape.js.map +1 -1
- package/dist/checks/catalog.d.ts +3 -0
- package/dist/checks/catalog.d.ts.map +1 -0
- package/dist/checks/catalog.js +100 -0
- package/dist/checks/catalog.js.map +1 -0
- package/dist/checks/clones.d.ts +3 -0
- package/dist/checks/clones.d.ts.map +1 -0
- package/dist/checks/clones.js +107 -0
- package/dist/checks/clones.js.map +1 -0
- package/dist/checks/commit-msg.d.ts +3 -0
- package/dist/checks/commit-msg.d.ts.map +1 -0
- package/dist/checks/commit-msg.js +88 -0
- package/dist/checks/commit-msg.js.map +1 -0
- package/dist/checks/doc-tokens.d.ts +13 -0
- package/dist/checks/doc-tokens.d.ts.map +1 -0
- package/dist/checks/doc-tokens.js +40 -0
- package/dist/checks/doc-tokens.js.map +1 -0
- package/dist/checks/file-size.d.ts +14 -0
- package/dist/checks/file-size.d.ts.map +1 -0
- package/dist/checks/file-size.js +36 -0
- package/dist/checks/file-size.js.map +1 -0
- package/dist/checks/helper-collisions.d.ts +3 -0
- package/dist/checks/helper-collisions.d.ts.map +1 -0
- package/dist/checks/helper-collisions.js +105 -0
- package/dist/checks/helper-collisions.js.map +1 -0
- package/dist/checks/inline-dupes.d.ts +3 -0
- package/dist/checks/inline-dupes.d.ts.map +1 -0
- package/dist/checks/inline-dupes.js +87 -0
- package/dist/checks/inline-dupes.js.map +1 -0
- package/dist/checks/page-size.d.ts +15 -0
- package/dist/checks/page-size.d.ts.map +1 -0
- package/dist/checks/page-size.js +32 -0
- package/dist/checks/page-size.js.map +1 -0
- package/dist/checks/require-deps.d.ts +19 -0
- package/dist/checks/require-deps.d.ts.map +1 -0
- package/dist/checks/require-deps.js +48 -0
- package/dist/checks/require-deps.js.map +1 -0
- package/dist/checks/reshape.d.ts +3 -0
- package/dist/checks/reshape.d.ts.map +1 -0
- package/dist/checks/reshape.js +138 -0
- package/dist/checks/reshape.js.map +1 -0
- package/dist/lib/bin.d.ts +9 -2
- package/dist/lib/bin.d.ts.map +1 -1
- package/dist/lib/bin.js +9 -4
- package/dist/lib/bin.js.map +1 -1
- package/dist/lib/config.d.ts +9 -39
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +12 -5
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/defaults.d.ts +22 -11
- package/dist/lib/defaults.d.ts.map +1 -1
- package/dist/lib/defaults.js +18 -16
- package/dist/lib/defaults.js.map +1 -1
- package/dist/lib/length.d.ts +62 -0
- package/dist/lib/length.d.ts.map +1 -0
- package/dist/lib/length.js +121 -0
- package/dist/lib/length.js.map +1 -0
- package/dist/lib/registry.d.ts +6 -0
- package/dist/lib/registry.d.ts.map +1 -0
- package/dist/lib/registry.js +34 -0
- package/dist/lib/registry.js.map +1 -0
- package/dist/lib/report.d.ts +40 -0
- package/dist/lib/report.d.ts.map +1 -0
- package/dist/lib/report.js +28 -0
- package/dist/lib/report.js.map +1 -0
- package/dist/lib/runner.d.ts +43 -0
- package/dist/lib/runner.d.ts.map +1 -0
- package/dist/lib/runner.js +41 -0
- package/dist/lib/runner.js.map +1 -0
- package/lefthook.checks.yml +31 -25
- package/nodeve.checks.defaults.js +18 -16
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# @nodeve/checks
|
|
2
2
|
|
|
3
|
-
Org-wide commit-gate checks and helper-index generators, shared across nodeve repos. Each check
|
|
3
|
+
Org-wide commit-gate checks and helper-index generators, shared across nodeve repos. Each check reads an optional per-repo `nodeve.checks.js` and derives the repo root from git — so it behaves the same whatever directory the hook runner invokes it from. Wiring is via lefthook.
|
|
4
|
+
|
|
5
|
+
All checks run through one dispatcher, **`nodeve-check`**:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
nodeve-check # run the whole pre-commit suite, summary-first
|
|
9
|
+
nodeve-check file-size # run one check (paths/flags after the name)
|
|
10
|
+
nodeve-check file-size --explain # show its full remediation prose
|
|
11
|
+
nodeve-check list # list the check names
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Every check renders the **same uniform block** — `<glyph> <name> — <summary>`, indented detail rows, and the check's remediation guidance — so the parallel gate's failure output is scannable rather than a wall of per-check formats. `--explain` expands each check's bulky per-finding detail inline (clones code fragments, inline-dupes file lists), which is otherwise summarized. A bare `nodeve-check` prints a status line per check, a tally, then a detail block for each that failed or warned.
|
|
4
15
|
|
|
5
16
|
## Install
|
|
6
17
|
|
|
@@ -23,22 +34,38 @@ Copy `node_modules/@nodeve/checks/nodeve.checks.defaults.js` to your repo root a
|
|
|
23
34
|
|
|
24
35
|
## Checks
|
|
25
36
|
|
|
26
|
-
|
|
|
37
|
+
| Check | What it gates | Default |
|
|
27
38
|
| --- | --- | --- |
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
37
|
-
| `
|
|
39
|
+
| `doc-tokens` | markdown over a line/token budget | on (`CLAUDE.md`, `guide/`, `docs/`) |
|
|
40
|
+
| `reshape` | callbacks that reproduce their input shape (no-op / pick / clone) | on (`apps/`, `packages/`) |
|
|
41
|
+
| `inline-dupes` | non-exported top-level names declared in 2+ files | on (`apps/`, `packages/`) |
|
|
42
|
+
| `helper-collisions` | local helpers that fuzzily match a dependency export | on (needs lib-names index) |
|
|
43
|
+
| `clones` | structural copy-paste (duplicated code blocks) via jscpd v5 | on (`apps/`, `packages/`; no-op if the jscpd binary isn't installed) |
|
|
44
|
+
| `page-size` | files over a per-glob line budget | on (`*+page.svelte` >280; no-op where the glob matches nothing) |
|
|
45
|
+
| `file-size` | TS sources over a line budget (warn >225, fail >300) | on (`apps/`, `packages/`) |
|
|
46
|
+
| `catalog` | dependency versions not single-sourced from a workspace catalog | on (a workspace must declare a catalog) |
|
|
47
|
+
| `require-deps` | org-required deps missing from the workspace catalog | on (`remeda`; set `deps: []` to opt out) |
|
|
48
|
+
| `commit-msg` | commit message off Conventional Commits, or a sizeable change with no body | on (`commit-msg` hook; body required past 50 changed lines) |
|
|
49
|
+
|
|
50
|
+
Run any of them as `nodeve-check <name>`. Each also has a standalone `nodeve-check-<name>` bin (identical behavior) for direct invocation.
|
|
38
51
|
|
|
39
52
|
`commit-msg` is the one gate that runs on the `commit-msg` hook rather than `pre-commit`: lefthook hands it the message file (`{1}`). It validates the header against Conventional Commits — `<type>(<scope>)!: <subject>`, where `type` must be one of `commitMsg.types` (the standard set) and the subject stays under `maxSubjectLength`. Past `commitMsg.bodyRequiredOverLines` changed lines — measured from the **staged** diff, not the commit type — a body becomes mandatory, because at that size the subject alone can't carry the "why". Merge, revert, and `fixup!`/`squash!`/`amend!` messages are skipped (git or rebase owns those). Set `commitMsg: { enforce: false }` to opt out, or `requireScope: true` to also mandate a scope.
|
|
40
53
|
|
|
41
|
-
`
|
|
54
|
+
`doc-tokens`, `page-size` and `file-size` are one engine (`lib/length.ts`) over one config shape — scope `globs`, a default `warn` and/or `fail` tier, and per-glob `overrides`. A tier bounds `maxLines` and/or `maxTokens` (omit an axis to leave it unbounded); `fail` blocks the commit, `warn` only nudges. An override merges its tiers per-axis over the default for files matching its glob (later overrides win), or drops them with `tiers: 'exempt'` — that one mechanism covers a one-off bigger budget, a soft pre-warn, and a full exemption alike:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
export default {
|
|
58
|
+
fileSize: {
|
|
59
|
+
// long-but-cohesive CLIs get 400 lines; everything else stays at the 225/300 default
|
|
60
|
+
overrides: [{ glob: 'packages/scripts/*.ts', tiers: { fail: { maxLines: 400 } } }],
|
|
61
|
+
},
|
|
62
|
+
docTokens: {
|
|
63
|
+
overrides: [{ glob: 'packages/content/README.md', tiers: { fail: { maxLines: 200 } } }],
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`page-size` is the opt-in member: its default `globs` is empty, so only files a configured override glob matches get a budget. `require-deps` keeps the org's blessed libraries single-sourced and visibly expected: it fails when the workspace catalog (default or a named group) doesn't define a required name. It checks the catalog, not each package's deps — so it doesn't force the dep on packages that don't use it, it just guarantees the version is there to adopt with `catalog:`. Defaults to requiring `remeda`; set `requireDeps: { deps: [] }` to opt out.
|
|
42
69
|
|
|
43
70
|
`catalog` works with both pnpm (catalog in `pnpm-workspace.yaml`) and Bun (catalog in `package.json#workspaces`) — it auto-detects whichever the repo uses. A workspace is **required** to declare a catalog: a repo with none fails the gate, since the point is keeping versions aligned. Every dependency (deps, devDeps, and peers alike) must reference `catalog:` rather than a literal pin. Opt a repo out deliberately with `catalog: { enforce: false }`.
|
|
44
71
|
|
|
@@ -59,7 +86,7 @@ A reinvention often borrows a _different_ library's name, which shares no tokens
|
|
|
59
86
|
|
|
60
87
|
`clones` is the structural counterpart to the name-based gates: it shells [jscpd v5](https://jscpd.dev) (a fast Rust copy-paste detector) over `clones.paths` and fails on any duplicated block past `clones.minTokens`/`minLines`. It catches reuse hiding in function _bodies_ that `inline-dupes`/`helper-collisions` can't see by name. Tune `minTokens`/`threshold`, narrow with `clones.ignore` globs, or `--warn` to downgrade. jscpd's native binary is an optional dependency, so the gate cleanly no-ops where it isn't installed rather than blocking a commit.
|
|
61
88
|
|
|
62
|
-
All blocking checks accept `--warn` (report-only, exit 0); `doc-tokens` accepts `--report` to list the whole backlog without failing. Pass explicit paths to scope a run (lefthook passes `{staged_files}`).
|
|
89
|
+
All blocking checks accept `--warn` (report-only, exit 0) and `--explain` (expand the remediation prose under the result); `doc-tokens` accepts `--report` to list the whole backlog without failing. Pass explicit paths to scope a run (lefthook passes `{staged_files}`).
|
|
63
90
|
|
|
64
91
|
## Fixers
|
|
65
92
|
|
|
@@ -69,14 +96,15 @@ Unlike the gates above, fixers mutate staged files and let lefthook re-stage the
|
|
|
69
96
|
|
|
70
97
|
### Running ad hoc
|
|
71
98
|
|
|
72
|
-
|
|
99
|
+
`nodeve-check` is a **bin**, not a package script, so `pnpm run` / `bun run` won't find it — those run `package.json#scripts`. Invoke it through `exec` instead, which resolves `node_modules/.bin` for you (no hardcoded path needed):
|
|
73
100
|
|
|
74
101
|
```sh
|
|
75
|
-
pnpm exec nodeve-check
|
|
76
|
-
bunx nodeve-check
|
|
102
|
+
pnpm exec nodeve-check doc-tokens 'README.md' # or: pnpm nodeve-check doc-tokens ...
|
|
103
|
+
bunx nodeve-check doc-tokens 'README.md' # Bun repos
|
|
104
|
+
pnpm exec nodeve-check # whole suite, summary-first
|
|
77
105
|
```
|
|
78
106
|
|
|
79
|
-
Quote globs so your shell doesn't expand them before the
|
|
107
|
+
Quote globs so your shell doesn't expand them before the check sees them. Day to day you shouldn't need this — the checks run through lefthook on commit.
|
|
80
108
|
|
|
81
109
|
## Generators
|
|
82
110
|
|
package/dist/bin/catalog.js
CHANGED
|
@@ -1,95 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* dependency must reference the default `catalog` or a named `catalogs.<group>`
|
|
6
|
-
* with the `catalog:` protocol (a `workspace:*` reference to a sibling is fine
|
|
7
|
-
* too). Two breaches fail the commit:
|
|
8
|
-
*
|
|
9
|
-
* 1. A package pins a literal version (e.g. "yaml": "^2.9.0"). It must read
|
|
10
|
-
* "catalog:" (or "catalog:<group>") so the version lives once, centrally.
|
|
11
|
-
* 2. A package references a catalog group that doesn't exist, or — for the
|
|
12
|
-
* default catalog — a name the catalog doesn't define (a typo that wouldn't
|
|
13
|
-
* resolve).
|
|
14
|
-
*
|
|
15
|
-
* One purpose, two layouts: the catalog lives in `pnpm-workspace.yaml` (pnpm) or
|
|
16
|
-
* in the root `package.json#workspaces` (Bun). This auto-detects whichever the
|
|
17
|
-
* repo uses, so it gates familiar (bun), nodeve, and platform (pnpm) alike.
|
|
18
|
-
*
|
|
19
|
-
* On by default. A workspace is REQUIRED to declare a catalog — a workspace with
|
|
20
|
-
* no catalog at all fails, since the whole point is keeping versions aligned.
|
|
21
|
-
* Set `catalog.enforce: false` in nodeve.checks.js to deliberately opt a repo out.
|
|
22
|
-
*/
|
|
23
|
-
import { readFileSync } from 'node:fs';
|
|
24
|
-
import { join } from 'node:path';
|
|
25
|
-
import { loadGate } from '../lib/bin.js';
|
|
26
|
-
import { readWorkspace, workspaceManifests } from '../lib/repo.js';
|
|
27
|
-
const { root, cfg, verbose } = await loadGate('catalog');
|
|
28
|
-
if (!cfg.enforce)
|
|
29
|
-
process.exit(0);
|
|
30
|
-
const ws = readWorkspace(root);
|
|
31
|
-
if (!ws) {
|
|
32
|
-
if (verbose)
|
|
33
|
-
console.log('catalog: no workspace manifest found — nothing to enforce');
|
|
34
|
-
process.exit(0);
|
|
35
|
-
}
|
|
36
|
-
// A workspace must declare a catalog — alignment is the point, so "no catalog"
|
|
37
|
-
// is itself a failure, not a free pass. Opt a repo out deliberately with
|
|
38
|
-
// `catalog.enforce: false` rather than by omitting the catalog.
|
|
39
|
-
if (Object.keys(ws.catalog).length === 0 && Object.keys(ws.catalogs).length === 0) {
|
|
40
|
-
console.error('\n✖ this workspace declares no catalog.\n\n' +
|
|
41
|
-
' Every workspace must single-source its dependency versions through a\n' +
|
|
42
|
-
' catalog. Add a `catalog:` block to pnpm-workspace.yaml (or\n' +
|
|
43
|
-
' `workspaces.catalog` in package.json for Bun), move your versions into\n' +
|
|
44
|
-
' it, and reference them with "catalog:".\n\n' +
|
|
45
|
-
' To deliberately opt out, set `catalog: { enforce: false }` in nodeve.checks.js.\n');
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
const manifests = workspaceManifests(root, ws);
|
|
49
|
-
const DEP_FIELDS = [
|
|
50
|
-
'dependencies',
|
|
51
|
-
'devDependencies',
|
|
52
|
-
'peerDependencies',
|
|
53
|
-
'optionalDependencies',
|
|
54
|
-
];
|
|
55
|
-
const ALLOWLIST = new Set(cfg.allowlist);
|
|
56
|
-
const errors = [];
|
|
57
|
-
for (const manifest of manifests) {
|
|
58
|
-
const pkg = JSON.parse(readFileSync(join(root, manifest), 'utf8'));
|
|
59
|
-
for (const field of DEP_FIELDS) {
|
|
60
|
-
const deps = pkg[field] ?? {};
|
|
61
|
-
for (const [name, version] of Object.entries(deps)) {
|
|
62
|
-
if (ALLOWLIST.has(`${manifest}::${name}`))
|
|
63
|
-
continue;
|
|
64
|
-
// Local references, not version pins — single-sourcing doesn't apply.
|
|
65
|
-
if (/^(workspace|link|file):/.test(version))
|
|
66
|
-
continue;
|
|
67
|
-
if (!version.startsWith('catalog:')) {
|
|
68
|
-
// Rule 1: literal version pin — every dependency must go through a catalog.
|
|
69
|
-
errors.push(`${manifest}: "${name}": "${version}" — pin it in a root catalog and use "catalog:" (or "catalog:<group>")`);
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
// Rule 2: the referenced catalog must actually define this dependency.
|
|
73
|
-
const group = version.slice('catalog:'.length); // "" → the default catalog
|
|
74
|
-
const table = group === '' ? ws.catalog : ws.catalogs[group];
|
|
75
|
-
if (!table) {
|
|
76
|
-
errors.push(`${manifest}: "${name}": "${version}" — no catalog group named "${group}" in the workspace`);
|
|
77
|
-
}
|
|
78
|
-
else if (!(name in table)) {
|
|
79
|
-
const where = group === '' ? 'the default catalog' : `catalog "${group}"`;
|
|
80
|
-
errors.push(`${manifest}: "${name}": "${version}" — ${where} does not define "${name}"`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (errors.length === 0) {
|
|
86
|
-
if (verbose)
|
|
87
|
-
console.log('catalog: clean');
|
|
88
|
-
process.exit(0);
|
|
89
|
-
}
|
|
90
|
-
console.error('\n✖ every dependency version must be single-sourced from a workspace catalog:\n');
|
|
91
|
-
for (const e of errors)
|
|
92
|
-
console.error(` ${e}`);
|
|
93
|
-
console.error('\n Add the version to the catalog (pnpm-workspace.yaml or package.json#workspaces),\n reference it with "catalog:", then reinstall.\n');
|
|
94
|
-
process.exit(1);
|
|
2
|
+
import { catalog } from '../checks/catalog.js';
|
|
3
|
+
import { runBin } from '../lib/runner.js';
|
|
4
|
+
await runBin(catalog);
|
|
95
5
|
//# sourceMappingURL=catalog.js.map
|
package/dist/bin/catalog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/bin/catalog.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/bin/catalog.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/bin/check.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `nodeve-check` — the single front door to the checks.
|
|
4
|
+
*
|
|
5
|
+
* nodeve-check <name> [paths…] [--explain] [--warn] [--verbose] [--report]
|
|
6
|
+
* Run one check (identical to the `nodeve-check-<name>` bin). `--explain`
|
|
7
|
+
* expands its full remediation prose under the result.
|
|
8
|
+
* nodeve-check Run the whole pre-commit suite, summary-first: a
|
|
9
|
+
* nodeve-check all status line per check, then a detail block for each
|
|
10
|
+
* that failed or warned. Exits 1 if any blocked.
|
|
11
|
+
* nodeve-check list List the available check names.
|
|
12
|
+
*
|
|
13
|
+
* The per-check bins stay (lefthook shells them per job, so the gate keeps its
|
|
14
|
+
* parallel run + summary tree). This dispatcher is the friendly hand-run path —
|
|
15
|
+
* `pnpm exec nodeve-check file-size` — and the one-shot whole-suite preview.
|
|
16
|
+
*/
|
|
17
|
+
import { parseArgs } from '../lib/config.js';
|
|
18
|
+
import { byName, CHECKS, PRE_COMMIT } from '../lib/registry.js';
|
|
19
|
+
import { exitCode, glyph, render } from '../lib/report.js';
|
|
20
|
+
import { emit, runCheck } from '../lib/runner.js';
|
|
21
|
+
const argv = process.argv.slice(2);
|
|
22
|
+
// First non-flag token is the subcommand; everything else (paths + flags) is the
|
|
23
|
+
// check's own argv, so the subcommand never leaks in as a path.
|
|
24
|
+
const cmdIdx = argv.findIndex((a) => !a.startsWith('--'));
|
|
25
|
+
const cmd = cmdIdx === -1 ? undefined : argv[cmdIdx];
|
|
26
|
+
const passthrough = cmdIdx === -1 ? argv : [...argv.slice(0, cmdIdx), ...argv.slice(cmdIdx + 1)];
|
|
27
|
+
if (cmd === 'list') {
|
|
28
|
+
for (const c of CHECKS)
|
|
29
|
+
console.log(c.name);
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
if (cmd && cmd !== 'all') {
|
|
33
|
+
const check = byName.get(cmd);
|
|
34
|
+
if (!check) {
|
|
35
|
+
process.stderr.write(`\n✖ unknown check: ${cmd}\n run \`nodeve-check list\` to see them\n\n`);
|
|
36
|
+
process.exit(2);
|
|
37
|
+
}
|
|
38
|
+
const { result, gate } = await runCheck(check, passthrough);
|
|
39
|
+
emit(check, result, gate);
|
|
40
|
+
process.exit(exitCode(result, gate.warn));
|
|
41
|
+
}
|
|
42
|
+
// Whole-suite run: every pre-commit check (commit-msg runs on its own hook).
|
|
43
|
+
const flags = parseArgs(passthrough);
|
|
44
|
+
const results = [];
|
|
45
|
+
for (const check of PRE_COMMIT) {
|
|
46
|
+
const { result } = await runCheck(check, passthrough);
|
|
47
|
+
results.push({ check, result });
|
|
48
|
+
}
|
|
49
|
+
// Summary first: one aligned status line per check.
|
|
50
|
+
const pad = Math.max(...PRE_COMMIT.map((c) => c.name.length));
|
|
51
|
+
const tally = { pass: 0, warn: 0, fail: 0, skip: 0 };
|
|
52
|
+
const lines = [`\nnodeve-check · ${results.length} checks\n`];
|
|
53
|
+
for (const { check, result } of results) {
|
|
54
|
+
tally[result.status]++;
|
|
55
|
+
const note = result.status === 'pass' || result.status === 'skip' ? '' : ` ${result.summary}`;
|
|
56
|
+
lines.push(` ${glyph(result.status)} ${check.name.padEnd(pad)}${note}`);
|
|
57
|
+
}
|
|
58
|
+
lines.push(`\n ${tally.fail} failed · ${tally.warn} warned · ${tally.pass} passed · ${tally.skip} skipped`);
|
|
59
|
+
process.stdout.write(lines.join('\n') + '\n');
|
|
60
|
+
// Then a detail block for each check that failed or warned.
|
|
61
|
+
const detailed = results.filter((r) => r.result.status === 'fail' || r.result.status === 'warn');
|
|
62
|
+
if (detailed.length > 0) {
|
|
63
|
+
process.stdout.write('\n' + '─'.repeat(56) + '\n');
|
|
64
|
+
for (const { check, result } of detailed)
|
|
65
|
+
process.stdout.write('\n' + render(check.name, result, { explain: check.explain }) + '\n');
|
|
66
|
+
process.stdout.write('\n');
|
|
67
|
+
}
|
|
68
|
+
process.exit(tally.fail > 0 && !flags.warn ? 1 : 0);
|
|
69
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/bin/check.ts"],"names":[],"mappings":"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"}
|
package/dist/bin/clones.js
CHANGED
|
@@ -1,60 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* large clones living in function bodies, which the name-based gates
|
|
6
|
-
* (`inline-dupes`, `helper-collisions`) can't see. A clone is a whole-tree
|
|
7
|
-
* property, so like `inline-dupes` this scans the configured `paths` in full.
|
|
8
|
-
*
|
|
9
|
-
* jscpd does the detection, the reporting, AND the pass/fail (its `--threshold`),
|
|
10
|
-
* so this bin just shells it and surfaces its output — quiet on a clean run,
|
|
11
|
-
* printing jscpd's `consoleFull` listing when it fails: each duplicated block with
|
|
12
|
-
* both file locations and the offending code inline, not just a summary table.
|
|
13
|
-
* Escape hatches are jscpd's own: narrow scope with `clones.ignore` globs, or
|
|
14
|
-
* `--warn` to downgrade the whole gate to report-only.
|
|
15
|
-
*
|
|
16
|
-
* jscpd's platform binary ships as an optionalDependency, so a partial or offline
|
|
17
|
-
* install can leave it absent — then this no-ops (exit 0) rather than blocking the
|
|
18
|
-
* commit, matching `helper-collisions`'s behaviour when its lib index is missing.
|
|
19
|
-
*/
|
|
20
|
-
import { spawnSync } from 'node:child_process';
|
|
21
|
-
import { createRequire } from 'node:module';
|
|
22
|
-
import { loadGate } from '../lib/bin.js';
|
|
23
|
-
const { root, cfg, warn, verbose } = await loadGate('clones');
|
|
24
|
-
let launcher;
|
|
25
|
-
try {
|
|
26
|
-
launcher = createRequire(import.meta.url).resolve('jscpd/run-jscpd.js');
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
if (verbose)
|
|
30
|
-
console.log('clones: jscpd binary not installed — skipping');
|
|
31
|
-
process.exit(0);
|
|
32
|
-
}
|
|
33
|
-
// Missing dirs (e.g. `apps/` in a repo that has none) are tolerated by jscpd, so
|
|
34
|
-
// the configured paths go through as-is. `--absolute` makes the reported paths
|
|
35
|
-
// unambiguous and clickable regardless of which path arg they came from.
|
|
36
|
-
const jscpdRun = spawnSync(process.execPath, [
|
|
37
|
-
launcher,
|
|
38
|
-
...cfg.paths,
|
|
39
|
-
'--absolute',
|
|
40
|
-
'--min-tokens', String(cfg.minTokens),
|
|
41
|
-
'--min-lines', String(cfg.minLines),
|
|
42
|
-
'--mode', cfg.mode,
|
|
43
|
-
'--format', cfg.formats.join(','),
|
|
44
|
-
'--ignore', cfg.ignore.join(','),
|
|
45
|
-
'--reporters', 'consoleFull',
|
|
46
|
-
'--threshold', String(cfg.threshold),
|
|
47
|
-
], { cwd: root, encoding: 'utf8' });
|
|
48
|
-
// jscpd exits non-zero only when duplication crosses `--threshold`. Stay silent on
|
|
49
|
-
// a clean run (unless --verbose); on a violation print jscpd's clone listing and
|
|
50
|
-
// fail — `--warn` downgrades that to report-only.
|
|
51
|
-
if (jscpdRun.status === 0) {
|
|
52
|
-
if (verbose)
|
|
53
|
-
process.stdout.write(jscpdRun.stdout ?? '');
|
|
54
|
-
process.exit(0);
|
|
55
|
-
}
|
|
56
|
-
process.stdout.write(jscpdRun.stdout ?? '');
|
|
57
|
-
if (jscpdRun.stderr)
|
|
58
|
-
process.stderr.write(jscpdRun.stderr);
|
|
59
|
-
process.exit(warn ? 0 : (jscpdRun.status ?? 1));
|
|
2
|
+
import { clones } from '../checks/clones.js';
|
|
3
|
+
import { runBin } from '../lib/runner.js';
|
|
4
|
+
await runBin(clones);
|
|
60
5
|
//# sourceMappingURL=clones.js.map
|
package/dist/bin/clones.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clones.js","sourceRoot":"","sources":["../../src/bin/clones.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"clones.js","sourceRoot":"","sources":["../../src/bin/clones.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/bin/commit-msg.js
CHANGED
|
@@ -1,83 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* Unlike the other checks this runs on the `commit-msg` hook, not `pre-commit`:
|
|
7
|
-
* lefthook passes the path to the message file as `{1}`, which arrives here as
|
|
8
|
-
* the first positional arg. The header is matched against
|
|
9
|
-
* `<type>(<scope>)!: <subject>`; `type` must be one of `commitMsg.types` (the
|
|
10
|
-
* standard Conventional set by default) and the subject is length-capped.
|
|
11
|
-
*
|
|
12
|
-
* WHY a conditional body: a one-line subject is fine for a small, self-evident
|
|
13
|
-
* change, but past `commitMsg.bodyRequiredOverLines` changed lines (measured
|
|
14
|
-
* from the STAGED diff via `git diff --cached --numstat`) the "what" no longer
|
|
15
|
-
* implies the "why" — those commits must include a body. Size, not the declared
|
|
16
|
-
* type, is what decides a change needs explaining.
|
|
17
|
-
*
|
|
18
|
-
* Skipped automatically: merge commits, reverts, and fixup!/squash!/amend!
|
|
19
|
-
* autosquash messages — git or rebase authors and consumes those. An empty
|
|
20
|
-
* message is left alone too, since git aborts that commit on its own.
|
|
21
|
-
*
|
|
22
|
-
* `commitMsg.enforce: false` opts a repo out; `--warn` downgrades to report-only.
|
|
23
|
-
*/
|
|
24
|
-
import { readFileSync } from 'node:fs';
|
|
25
|
-
import { loadGate } from '../lib/bin.js';
|
|
26
|
-
import { stagedDiffLines } from '../lib/repo.js';
|
|
27
|
-
const { root, cfg, paths, warn } = await loadGate('commitMsg');
|
|
28
|
-
if (!cfg.enforce)
|
|
29
|
-
process.exit(0);
|
|
30
|
-
const msgPath = paths[0];
|
|
31
|
-
if (!msgPath) {
|
|
32
|
-
console.error('\n✖ commit-msg: no message file path given (expected lefthook `{1}`).\n');
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
const raw = readFileSync(msgPath, 'utf8');
|
|
36
|
-
// git ignores comment lines and everything after the `# >8` scissors line (added
|
|
37
|
-
// by `commit --verbose`), so strip both before reading — otherwise the diff dump
|
|
38
|
-
// would read as a body and the comment hints would skew the header.
|
|
39
|
-
const scissors = raw.indexOf('\n# ------------------------ >8');
|
|
40
|
-
const lines = (scissors === -1 ? raw : raw.slice(0, scissors))
|
|
41
|
-
.split('\n')
|
|
42
|
-
.filter((l) => !l.startsWith('#'));
|
|
43
|
-
const headerIdx = lines.findIndex((l) => l.trim().length > 0);
|
|
44
|
-
const header = headerIdx === -1 ? '' : lines[headerIdx].trim();
|
|
45
|
-
// Empty message → the user is aborting; git rejects it without our help.
|
|
46
|
-
if (header === '')
|
|
47
|
-
process.exit(0);
|
|
48
|
-
// Messages git or an autosquash rebase generates and later consumes — not ours to gate.
|
|
49
|
-
if (/^(merge |revert "|fixup!|squash!|amend!)/i.test(header))
|
|
50
|
-
process.exit(0);
|
|
51
|
-
const problems = [];
|
|
52
|
-
const m = header.match(/^(?<type>\w+)(?:\((?<scope>[^)]+)\))?(?<bang>!)?: (?<subject>.+)$/);
|
|
53
|
-
if (!m?.groups) {
|
|
54
|
-
problems.push(`header doesn't match "<type>(<scope>): <subject>" — got ${JSON.stringify(header)}`);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const { type, scope, subject } = m.groups;
|
|
58
|
-
if (cfg.types.length > 0 && !cfg.types.includes(type))
|
|
59
|
-
problems.push(`type "${type}" is not allowed — use one of: ${cfg.types.join(', ')}`);
|
|
60
|
-
if (cfg.requireScope && !scope)
|
|
61
|
-
problems.push('a scope is required: <type>(<scope>): <subject>');
|
|
62
|
-
if (subject.length > cfg.maxSubjectLength)
|
|
63
|
-
problems.push(`subject is ${subject.length} chars, over the ${cfg.maxSubjectLength}-char limit`);
|
|
64
|
-
}
|
|
65
|
-
// A body is any non-empty content separated from the header by a blank line.
|
|
66
|
-
const after = lines.slice(headerIdx + 1);
|
|
67
|
-
const hasBody = after.length > 1 && after[0].trim() === '' && after.slice(1).some((l) => l.trim().length > 0);
|
|
68
|
-
const changed = stagedDiffLines(root);
|
|
69
|
-
if (changed > cfg.bodyRequiredOverLines && !hasBody)
|
|
70
|
-
problems.push(`this commit changes ${changed} lines (> ${cfg.bodyRequiredOverLines}) and needs a body — ` +
|
|
71
|
-
'add a blank line after the subject, then explain WHY the change is needed');
|
|
72
|
-
if (problems.length === 0)
|
|
73
|
-
process.exit(0);
|
|
74
|
-
console.error('\n✖ commit-msg:');
|
|
75
|
-
for (const p of problems)
|
|
76
|
-
console.error(` • ${p}`);
|
|
77
|
-
console.error('\nConventional Commits — <type>(<optional scope>): <subject>\n' +
|
|
78
|
-
` allowed types: ${cfg.types.join(', ')}\n` +
|
|
79
|
-
' example:\n' +
|
|
80
|
-
' feat(checks): add commit-message gate\n\n' +
|
|
81
|
-
' Sizeable changes need a body after a blank line explaining the why.\n');
|
|
82
|
-
process.exit(warn ? 0 : 1);
|
|
2
|
+
import { commitMsg } from '../checks/commit-msg.js';
|
|
3
|
+
import { runBin } from '../lib/runner.js';
|
|
4
|
+
await runBin(commitMsg);
|
|
83
5
|
//# sourceMappingURL=commit-msg.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-msg.js","sourceRoot":"","sources":["../../src/bin/commit-msg.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"commit-msg.js","sourceRoot":"","sources":["../../src/bin/commit-msg.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/bin/doc-tokens.js
CHANGED
|
@@ -1,68 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* WHY: always-loaded / frequently-linked docs cost tokens and attention. Caps
|
|
6
|
-
* enforce the terse-docs convention ("past ~150 lines, split into a dir with an
|
|
7
|
-
* index") mechanically. Tokens are the better proxy — a dense paragraph costs
|
|
8
|
-
* more than the same lines of bullets — so both dimensions are bounded.
|
|
9
|
-
*
|
|
10
|
-
* Tokenizer is js-tiktoken `o200k_base` (OpenAI BPE). Claude's is unpublished
|
|
11
|
-
* and differs, so this is a stable *proxy* for budgeting, not an exact count —
|
|
12
|
-
* good enough to catch bloat, consistent run-to-run.
|
|
13
|
-
*
|
|
14
|
-
* Scope: the `docTokens.enforce` pathspecs are what the gate fails on.
|
|
15
|
-
* `--report` lists every over-budget file without failing —
|
|
16
|
-
* the backlog worklist. Pass explicit paths to check only those (lefthook
|
|
17
|
-
* `{staged_files}`). Scoping is via `git ls-files` — gitignored paths are never
|
|
18
|
-
* measured unless passed explicitly.
|
|
19
|
-
*/
|
|
20
|
-
import { getEncoding } from 'js-tiktoken';
|
|
21
|
-
import { readFileSync } from 'node:fs';
|
|
22
|
-
import { join } from 'node:path';
|
|
23
|
-
import { loadGate } from '../lib/bin.js';
|
|
24
|
-
import {} from '../lib/config.js';
|
|
25
|
-
import { gitFiles } from '../lib/repo.js';
|
|
26
|
-
const { root, cfg, paths, report } = await loadGate('docTokens');
|
|
27
|
-
const DEFAULT = { maxLines: cfg.maxLines, maxTokens: cfg.maxTokens };
|
|
28
|
-
const enc = getEncoding('o200k_base');
|
|
29
|
-
function measure(path) {
|
|
30
|
-
const text = readFileSync(join(root, path), 'utf8');
|
|
31
|
-
return {
|
|
32
|
-
path,
|
|
33
|
-
lines: text.split('\n').length - 1,
|
|
34
|
-
tokens: enc.encode(text).length,
|
|
35
|
-
limit: { ...DEFAULT, ...cfg.overrides[path] },
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function overBudget({ lines, tokens, limit }) {
|
|
39
|
-
return lines > limit.maxLines || tokens > limit.maxTokens;
|
|
40
|
-
}
|
|
41
|
-
function formatRow({ path, lines, tokens, limit }) {
|
|
42
|
-
const flags = [
|
|
43
|
-
lines > limit.maxLines ? `${lines}/${limit.maxLines}L` : null,
|
|
44
|
-
tokens > limit.maxTokens ? `${tokens}/${limit.maxTokens}T` : null,
|
|
45
|
-
]
|
|
46
|
-
.filter(Boolean)
|
|
47
|
-
.join(' ');
|
|
48
|
-
return ` ${flags.padEnd(22)} ${path}`;
|
|
49
|
-
}
|
|
50
|
-
const scope = paths.length > 0 ? paths : gitFiles(root, cfg.enforce);
|
|
51
|
-
const oversized = scope
|
|
52
|
-
.map(measure)
|
|
53
|
-
.filter(overBudget)
|
|
54
|
-
.sort((a, b) => b.tokens - a.tokens);
|
|
55
|
-
if (report) {
|
|
56
|
-
console.log(`Doc-size backlog (limit ${DEFAULT.maxLines}L / ${DEFAULT.maxTokens}T) — ${oversized.length} over:`);
|
|
57
|
-
for (const o of oversized)
|
|
58
|
-
console.log(formatRow(o));
|
|
59
|
-
process.exit(0);
|
|
60
|
-
}
|
|
61
|
-
if (oversized.length > 0) {
|
|
62
|
-
console.error(`\n✖ markdown over budget (${DEFAULT.maxLines} lines / ${DEFAULT.maxTokens} tokens) — split into a dir with an index:\n`);
|
|
63
|
-
for (const o of oversized)
|
|
64
|
-
console.error(formatRow(o));
|
|
65
|
-
console.error('');
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
2
|
+
import { docTokens } from '../checks/doc-tokens.js';
|
|
3
|
+
import { runBin } from '../lib/runner.js';
|
|
4
|
+
await runBin(docTokens);
|
|
68
5
|
//# sourceMappingURL=doc-tokens.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-tokens.js","sourceRoot":"","sources":["../../src/bin/doc-tokens.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"doc-tokens.js","sourceRoot":"","sources":["../../src/bin/doc-tokens.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/bin/file-size.js
CHANGED
|
@@ -1,66 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* blocks the commit.
|
|
6
|
-
*
|
|
7
|
-
* WHY: file size is the cheapest proxy for "this unit took on more than one
|
|
8
|
-
* job." Past ~200-250 lines a module usually mixes responsibilities, which
|
|
9
|
-
* works against SoC/SRP and makes the pieces harder to test in isolation. The
|
|
10
|
-
* gate doesn't prescribe the split — that's a judgement call — it just forces
|
|
11
|
-
* the step-back: what are the distinct responsibilities here, and can each one
|
|
12
|
-
* own its own file (one reason to change apiece), grouped in a directory without
|
|
13
|
-
* adding friction at the call sites?
|
|
14
|
-
*
|
|
15
|
-
* Scope: `fileSize.globs` (default `apps/`, `packages/` `.ts`). Unlike the other
|
|
16
|
-
* `.ts` checks this does NOT auto-skip tests or declaration files — a long file
|
|
17
|
-
* is a long file. Genuinely-single-responsibility files that run long (a big
|
|
18
|
-
* schema, a lookup table, a table-driven test) go in `fileSize.allowlist` with
|
|
19
|
-
* a WHY comment. `--warn` downgrades a hard offender to report-only (exit 0).
|
|
20
|
-
*/
|
|
21
|
-
import { loadGate } from '../lib/bin.js';
|
|
22
|
-
import { gitFiles, lineCount } from '../lib/repo.js';
|
|
23
|
-
const { root, cfg, paths, warn, verbose, allowlist } = await loadGate('fileSize');
|
|
24
|
-
// All tracked files in scope, narrowed to staged paths (lefthook `{staged_files}`)
|
|
25
|
-
// when given so a commit only pays for what it touches.
|
|
26
|
-
const matched = gitFiles(root, cfg.globs);
|
|
27
|
-
const targets = paths.length > 0 ? matched.filter((f) => paths.includes(f)) : matched;
|
|
28
|
-
const failing = [];
|
|
29
|
-
const warning = [];
|
|
30
|
-
for (const path of targets) {
|
|
31
|
-
if (allowlist.has(path))
|
|
32
|
-
continue;
|
|
33
|
-
const lines = lineCount(root, path);
|
|
34
|
-
if (lines > cfg.maxLines)
|
|
35
|
-
failing.push({ path, lines });
|
|
36
|
-
else if (lines > cfg.warnLines)
|
|
37
|
-
warning.push({ path, lines });
|
|
38
|
-
}
|
|
39
|
-
const byLines = (a, b) => b.lines - a.lines;
|
|
40
|
-
if (warning.length > 0) {
|
|
41
|
-
console.error(`\n⚠ file(s) over the ${cfg.warnLines}-line soft budget — worth a look:\n`);
|
|
42
|
-
for (const h of warning.sort(byLines))
|
|
43
|
-
console.error(` ${String(h.lines).padStart(5)}/${cfg.warnLines}L ${h.path}`);
|
|
44
|
-
console.error('');
|
|
45
|
-
}
|
|
46
|
-
if (failing.length === 0) {
|
|
47
|
-
if (verbose && warning.length === 0)
|
|
48
|
-
console.error('✓ file-size: all files within budget');
|
|
49
|
-
process.exit(0);
|
|
50
|
-
}
|
|
51
|
-
console.error(`\n✖ file(s) over the ${cfg.maxLines}-line budget:\n`);
|
|
52
|
-
for (const h of failing.sort(byLines))
|
|
53
|
-
console.error(` ${String(h.lines).padStart(5)}/${cfg.maxLines}L ${h.path}`);
|
|
54
|
-
console.error(`
|
|
55
|
-
A large file usually means one file is doing several jobs. Step back:
|
|
56
|
-
• Name the distinct responsibilities — can each move to its own module
|
|
57
|
-
(one reason to change per file)?
|
|
58
|
-
• Pull pure helpers into a file that can be unit-tested on its own.
|
|
59
|
-
• Group the related files in a directory, but only if the split doesn't add
|
|
60
|
-
friction at the call sites.
|
|
61
|
-
If it's genuinely one responsibility that just runs long (a schema, a lookup
|
|
62
|
-
table, a table-driven test), add the path to fileSize.allowlist in
|
|
63
|
-
nodeve.checks.js with a WHY comment. --warn downgrades this to report-only.
|
|
64
|
-
`);
|
|
65
|
-
process.exit(warn ? 0 : 1);
|
|
2
|
+
import { fileSize } from '../checks/file-size.js';
|
|
3
|
+
import { runBin } from '../lib/runner.js';
|
|
4
|
+
await runBin(fileSize);
|
|
66
5
|
//# sourceMappingURL=file-size.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-size.js","sourceRoot":"","sources":["../../src/bin/file-size.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"file-size.js","sourceRoot":"","sources":["../../src/bin/file-size.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC"}
|