hookset 1.3.0 → 1.4.1
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 +6 -1
- package/dist/changesets.d.ts +37 -0
- package/dist/changesets.js +102 -0
- package/dist/context.js +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/worktrees.js +3 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -97,6 +97,11 @@ hookset worktrees --prune # remove the clean ones whose commits are all on a re
|
|
|
97
97
|
| `context` | CLAUDE.md, its `@`-imports and every skill, command and subagent description (less the skills marked `disable-model-invocation: true`) come to more tokens than `context.tokens` in `.claude/hookset.json`; `--update` lowers that ceiling and never raises it |
|
|
98
98
|
| `worktrees` | git refused to remove a worktree `--prune` chose. Only a worktree that is not the main or current one, not locked, has an empty `git status`, has every commit on a remote and is unchanged for `--older-than` days (default 3) is removed, with `git worktree remove` (never `--force`); branches are kept. `--include-local-commits` lets a commit that is only on this machine go too. `git worktree lock <path>` keeps any worktree out of every sweep |
|
|
99
99
|
|
|
100
|
+
The shared `changeset-gate` workflow imports `src/changesets.ts` at the tag `lefthook.yml`
|
|
101
|
+
pins: every package whose shipped files changed (source that is not a test, fixture or
|
|
102
|
+
snapshot, or a manifest beyond `devDependencies`) must be named in one of the PR's changesets,
|
|
103
|
+
or the PR carries the `skip-changeset` label. A test-only change needs no changeset.
|
|
104
|
+
|
|
100
105
|
## Migrating
|
|
101
106
|
|
|
102
107
|
The switch is one command, `npx hookset init`, and husky's folder comes out:
|
|
@@ -138,7 +143,7 @@ No suite is graded against this package yet, so there is no compatibility number
|
|
|
138
143
|
|
|
139
144
|
| Import | What it gives you |
|
|
140
145
|
| :-- | :-- |
|
|
141
|
-
| `hookset` | `parseRemotes()`, `checkRepo()`, `checkText()`, `initRepo()`, `lefthookTemplate()`, `loadStations()` and `program` |
|
|
146
|
+
| `hookset` | `parseRemotes()`, `checkRepo()`, `checkText()`, `initRepo()`, `lefthookTemplate()`, `loadStations()`, `coverage()`, `coverageText()` and `program` |
|
|
142
147
|
|
|
143
148
|
The `hookset` bin is that API, declared once on burgee.
|
|
144
149
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** The files that can need a changeset, as the gate's `paths` input names them. */
|
|
2
|
+
export declare const DEFAULT_PATHS: string;
|
|
3
|
+
/** The package names a changeset's front matter releases. */
|
|
4
|
+
export declare const releasesOf: (text: string) => string[];
|
|
5
|
+
/** A changeset file: a markdown file directly under .changeset/, other than its README. */
|
|
6
|
+
export declare const isChangeset: (path: string) => boolean;
|
|
7
|
+
/** A manifest whose only change is `devDependencies`, given its text at the base and at the head. */
|
|
8
|
+
export declare const devOnly: (base: string | undefined, head: string | undefined) => boolean;
|
|
9
|
+
export interface Needed {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** The folder under the repository, `packages/<dir>`. */
|
|
12
|
+
readonly dir: string;
|
|
13
|
+
/** The shipped files that changed in it. */
|
|
14
|
+
readonly files: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
export interface Coverage {
|
|
17
|
+
/** The changesets the pull request adds or edits. */
|
|
18
|
+
readonly changesets: readonly string[];
|
|
19
|
+
/** Every package with a shipped change, by name. */
|
|
20
|
+
readonly needed: readonly Needed[];
|
|
21
|
+
/** The packages no changeset names. */
|
|
22
|
+
readonly uncovered: readonly Needed[];
|
|
23
|
+
}
|
|
24
|
+
export interface CoverageInput {
|
|
25
|
+
/** The checkout of the pull request's head. */
|
|
26
|
+
readonly root: string;
|
|
27
|
+
/** Every path the pull request changes, from `git diff --name-only <base>...<head>`. */
|
|
28
|
+
readonly changed: readonly string[];
|
|
29
|
+
/** A file's text at the merge base, `undefined` when it did not exist there. */
|
|
30
|
+
readonly baseText: (path: string) => string | undefined;
|
|
31
|
+
/** The regular expression over paths that can need a changeset. */
|
|
32
|
+
readonly paths?: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** Which packages the change ships, and which of them no changeset names. */
|
|
35
|
+
export declare const coverage: (input: CoverageInput) => Coverage;
|
|
36
|
+
/** The result as a person reads it, ending with the fix when a package is not covered. */
|
|
37
|
+
export declare const coverageText: (result: Coverage) => string;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
export const DEFAULT_PATHS = String.raw `^packages/[^/]+/(src|package\.json)`;
|
|
4
|
+
const TEST = /\/__(?:tests|fixtures|mocks)__\/|\.(?:test|spec)\.[cm]?[jt]sx?$|\.snap$/u;
|
|
5
|
+
const BUMPS = new Set(['major', 'minor', 'patch', 'none']);
|
|
6
|
+
const unquoted = (key) => {
|
|
7
|
+
const quote = key[0];
|
|
8
|
+
if (quote !== '"' && quote !== "'")
|
|
9
|
+
return key;
|
|
10
|
+
return key.endsWith(quote) ? key.slice(1, -1) : undefined;
|
|
11
|
+
};
|
|
12
|
+
const releaseOf = (line) => {
|
|
13
|
+
const colon = line.lastIndexOf(':');
|
|
14
|
+
if (!BUMPS.has(line.slice(colon + 1).trim()))
|
|
15
|
+
return undefined;
|
|
16
|
+
const name = unquoted(line.slice(0, colon).trim());
|
|
17
|
+
return name === undefined || name === '' || /["'\s]/u.test(name) ? undefined : name;
|
|
18
|
+
};
|
|
19
|
+
export const releasesOf = (text) => {
|
|
20
|
+
const lines = text.replace(/\r\n/gu, '\n').split('\n');
|
|
21
|
+
if (lines[0]?.trim() !== '---')
|
|
22
|
+
return [];
|
|
23
|
+
const end = lines.indexOf('---', 1);
|
|
24
|
+
if (end === -1)
|
|
25
|
+
return [];
|
|
26
|
+
return lines.slice(1, end).flatMap((line) => releaseOf(line) ?? []);
|
|
27
|
+
};
|
|
28
|
+
export const isChangeset = (path) => /^\.changeset\/[^/]+\.md$/u.test(path) && path.toLowerCase() !== '.changeset/readme.md';
|
|
29
|
+
export const devOnly = (base, head) => {
|
|
30
|
+
if (base === undefined || head === undefined)
|
|
31
|
+
return false;
|
|
32
|
+
try {
|
|
33
|
+
const [a, b] = [base, head].map((text) => {
|
|
34
|
+
const { devDependencies: _dev, ...rest } = JSON.parse(text);
|
|
35
|
+
return JSON.stringify(rest);
|
|
36
|
+
});
|
|
37
|
+
return a === b;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const readJson = (file) => {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const configOf = (root) => {
|
|
52
|
+
const config = readJson(join(root, '.changeset', 'config.json')) ?? {};
|
|
53
|
+
const ignore = Array.isArray(config.ignore) ? config.ignore.filter((one) => typeof one === 'string') : [];
|
|
54
|
+
const privatePackages = config.privatePackages;
|
|
55
|
+
return { ignore, privateVersioned: privatePackages?.version !== false };
|
|
56
|
+
};
|
|
57
|
+
const globMatches = (glob, name) => new RegExp(`^${glob.replace(/[.+?^${}()|[\]\\]/gu, String.raw `\$&`).replaceAll('*', '.*')}$`, 'u').test(name);
|
|
58
|
+
const shippedByDir = (input) => {
|
|
59
|
+
const paths = new RegExp(input.paths ?? DEFAULT_PATHS, 'u');
|
|
60
|
+
const byDir = new Map();
|
|
61
|
+
for (const path of input.changed) {
|
|
62
|
+
if (!paths.test(path) || TEST.test(path))
|
|
63
|
+
continue;
|
|
64
|
+
const dir = path.split('/').slice(0, 2).join('/');
|
|
65
|
+
const head = join(input.root, path);
|
|
66
|
+
const headText = existsSync(head) ? readFileSync(head, 'utf8') : undefined;
|
|
67
|
+
if (path === `${dir}/package.json` && devOnly(input.baseText(path), headText))
|
|
68
|
+
continue;
|
|
69
|
+
byDir.set(dir, [...(byDir.get(dir) ?? []), path]);
|
|
70
|
+
}
|
|
71
|
+
return byDir;
|
|
72
|
+
};
|
|
73
|
+
const neededIn = (root, config, dir, files) => {
|
|
74
|
+
const manifest = readJson(join(root, dir, 'package.json'));
|
|
75
|
+
if (typeof manifest?.name !== 'string')
|
|
76
|
+
return undefined;
|
|
77
|
+
const { name } = manifest;
|
|
78
|
+
if (config.ignore.some((glob) => globMatches(glob, name)))
|
|
79
|
+
return undefined;
|
|
80
|
+
if (manifest.private === true && !config.privateVersioned)
|
|
81
|
+
return undefined;
|
|
82
|
+
return { name, dir, files };
|
|
83
|
+
};
|
|
84
|
+
export const coverage = (input) => {
|
|
85
|
+
const config = configOf(input.root);
|
|
86
|
+
const changesets = input.changed.filter((path) => isChangeset(path) && existsSync(join(input.root, path)));
|
|
87
|
+
const named = new Set(changesets.flatMap((path) => releasesOf(readFileSync(join(input.root, path), 'utf8'))));
|
|
88
|
+
const needed = [...shippedByDir(input)].flatMap(([dir, files]) => neededIn(input.root, config, dir, files) ?? []);
|
|
89
|
+
return { changesets, needed, uncovered: needed.filter((one) => !named.has(one.name)) };
|
|
90
|
+
};
|
|
91
|
+
export const coverageText = (result) => {
|
|
92
|
+
if (result.needed.length === 0)
|
|
93
|
+
return 'changesets: no package ships a change (tests, fixtures and devDependencies need none)';
|
|
94
|
+
if (result.uncovered.length === 0) {
|
|
95
|
+
return `changesets: ${result.needed.map((one) => one.name).join(', ')} named in ${result.changesets.join(', ')}`;
|
|
96
|
+
}
|
|
97
|
+
const lines = result.uncovered.map((one) => ` ${one.name} (${one.files.join(', ')})`);
|
|
98
|
+
const fix = result.changesets.length === 0
|
|
99
|
+
? `fix: run 'npx changeset' for ${result.uncovered.map((one) => one.name).join(', ')}, or add the 'skip-changeset' label for internal-only work`
|
|
100
|
+
: `fix: add ${result.uncovered.map((one) => `"${one.name}": patch`).join(', ')} (or the right bump) to a changeset, or add the 'skip-changeset' label for internal-only work`;
|
|
101
|
+
return [`changesets: ${String(result.uncovered.length)} package(s) ship a change no changeset names:`, ...lines, fix].join('\n');
|
|
102
|
+
};
|
package/dist/context.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join, posix } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
const packageRoot = () => fileURLToPath(new URL('..', import.meta.url));
|
|
5
|
+
const loadStations = (pkg) => JSON.parse(readFileSync(join(pkg, 'stations.json')).toString());
|
|
4
6
|
const CHARS_PER_TOKEN = 4;
|
|
5
7
|
const LARGEST_SHOWN = 5;
|
|
6
8
|
const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---/;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/worktrees.js
CHANGED
|
@@ -80,8 +80,7 @@ async function inspect(l, main, o) {
|
|
|
80
80
|
if (!main && !current)
|
|
81
81
|
facts.idleDays = Math.max(0, (o.now - newestUnder(l.path)) / DAY_MS);
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
return { ...facts, ...sized, keep: keepReason(facts, o.olderThanDays, o.keepLocalCommits), removed: false };
|
|
83
|
+
return { ...facts, keep: keepReason(facts, o.olderThanDays, o.keepLocalCommits), removed: false };
|
|
85
84
|
}
|
|
86
85
|
async function prune(repo, worktrees, git) {
|
|
87
86
|
for (const w of worktrees.filter((t) => t.keep === undefined)) {
|
|
@@ -102,11 +101,11 @@ export async function sweepWorktrees(repo, options = {}) {
|
|
|
102
101
|
git,
|
|
103
102
|
top: (await git(repo, ['rev-parse', '--show-toplevel'])).out.trim(),
|
|
104
103
|
now: options.now ?? Date.now(),
|
|
105
|
-
size: options.size === true,
|
|
106
104
|
olderThanDays: options.olderThanDays ?? DEFAULT_OLDER_THAN_DAYS,
|
|
107
105
|
keepLocalCommits: options.keepLocalCommits ?? true,
|
|
108
106
|
};
|
|
109
|
-
const
|
|
107
|
+
const inspected = await Promise.all(parseWorktrees(listed.out).map((l, index) => inspect(l, index === 0, o)));
|
|
108
|
+
const worktrees = options.size === true ? inspected.map((w) => (w.missing ? w : { ...w, bytes: bytesUnder(w.path) })) : inspected;
|
|
110
109
|
const pruned = options.prune === true && (await prune(repo, worktrees, git));
|
|
111
110
|
const failed = worktrees.filter((w) => w.error !== undefined).map((w) => w.path);
|
|
112
111
|
const result = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hookset",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Git hooks presets for AI coding agents: lefthook presets pulled by a pinned tag, a Claude Code hook pack that denies skipped hooks, and `hookset init` and `check`. No dependency outside the burgee family. A husky migration path.",
|
|
6
6
|
"keywords": [
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"bellpull": "^2.0.3",
|
|
61
|
-
"burgee": "^2.2.
|
|
61
|
+
"burgee": "^2.2.4"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"vitest": "^5.0.1"
|