@houserules/payload 0.0.0 → 0.1.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@houserules/payload",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "houserules: shared payload libraries, copied into .claude/scripts/lib and executed on bare node with zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"typescript": "^6.0.3",
|
|
78
78
|
"vitest": "^4.1.10",
|
|
79
79
|
"wireit": "^0.14.13",
|
|
80
|
-
"@houserules/test": "0.
|
|
80
|
+
"@houserules/test": "0.1.0"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"build": "wireit",
|
|
@@ -95,6 +95,19 @@ export declare function resolveTargetCommands(override: string[] | null | undefi
|
|
|
95
95
|
* the command.
|
|
96
96
|
*/
|
|
97
97
|
export declare function runsAtRepoRoot(block: RunnerBlock | undefined): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* The work tree root, throwing outside one. Memoized per process, keyed by the cwd it was
|
|
100
|
+
* resolved from.
|
|
101
|
+
*
|
|
102
|
+
* The memo is the point. `loadConfigSafe()` resolves the root internally and the hook
|
|
103
|
+
* calling it usually resolved the root too, so a hook invocation spawned
|
|
104
|
+
* `git rev-parse --show-toplevel` twice. A hook is a one-shot process, so the answer cannot
|
|
105
|
+
* go stale within one.
|
|
106
|
+
*
|
|
107
|
+
* The key is the cwd because the answer depends on it, and a long-lived caller such as a
|
|
108
|
+
* test can chdir between calls. Only a successful resolution is memoized, so a throw stays
|
|
109
|
+
* a throw and `repoRootSafe()` keeps reporting null outside a work tree.
|
|
110
|
+
*/
|
|
98
111
|
export declare function repoRoot(): string;
|
|
99
112
|
/**
|
|
100
113
|
* `repoRoot()` for a script that must not crash. Returns null outside a git work tree, or
|
|
@@ -135,5 +148,9 @@ export declare function loadConfig(root?: string, { required }?: {
|
|
|
135
148
|
* The loader hooks must use. It never exits and never throws, returning an empty config
|
|
136
149
|
* in the worst case. A hook that crashes on a missing or broken config is noise on every
|
|
137
150
|
* single tool call.
|
|
151
|
+
*
|
|
152
|
+
* @param root Pass the root when the caller already resolved one, which skips the git
|
|
153
|
+
* spawn entirely. `proc.mts` holds its own root memo, so a script that resolved the root
|
|
154
|
+
* through that one would otherwise still pay a second spawn here.
|
|
138
155
|
*/
|
|
139
|
-
export declare function loadConfigSafe(): HouseConfig;
|
|
156
|
+
export declare function loadConfigSafe(root?: string): HouseConfig;
|
|
@@ -26,12 +26,32 @@ export function resolveTargetCommands(override, blockCommands) {
|
|
|
26
26
|
export function runsAtRepoRoot(block) {
|
|
27
27
|
return !(block?.filterFlag ?? DEFAULT_FILTER_FLAG);
|
|
28
28
|
}
|
|
29
|
+
const rootByCwd = new Map();
|
|
30
|
+
/**
|
|
31
|
+
* The work tree root, throwing outside one. Memoized per process, keyed by the cwd it was
|
|
32
|
+
* resolved from.
|
|
33
|
+
*
|
|
34
|
+
* The memo is the point. `loadConfigSafe()` resolves the root internally and the hook
|
|
35
|
+
* calling it usually resolved the root too, so a hook invocation spawned
|
|
36
|
+
* `git rev-parse --show-toplevel` twice. A hook is a one-shot process, so the answer cannot
|
|
37
|
+
* go stale within one.
|
|
38
|
+
*
|
|
39
|
+
* The key is the cwd because the answer depends on it, and a long-lived caller such as a
|
|
40
|
+
* test can chdir between calls. Only a successful resolution is memoized, so a throw stays
|
|
41
|
+
* a throw and `repoRootSafe()` keeps reporting null outside a work tree.
|
|
42
|
+
*/
|
|
29
43
|
export function repoRoot() {
|
|
30
|
-
|
|
44
|
+
const cwd = process.cwd();
|
|
45
|
+
const cached = rootByCwd.get(cwd);
|
|
46
|
+
if (cached !== undefined)
|
|
47
|
+
return cached;
|
|
48
|
+
const root = execSync('git rev-parse --show-toplevel', {
|
|
31
49
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
32
50
|
})
|
|
33
51
|
.toString()
|
|
34
52
|
.trim();
|
|
53
|
+
rootByCwd.set(cwd, root);
|
|
54
|
+
return root;
|
|
35
55
|
}
|
|
36
56
|
/**
|
|
37
57
|
* `repoRoot()` for a script that must not crash. Returns null outside a git work tree, or
|
|
@@ -120,10 +140,14 @@ export function loadConfig(root = repoRoot(), { required = true } = {}) {
|
|
|
120
140
|
* The loader hooks must use. It never exits and never throws, returning an empty config
|
|
121
141
|
* in the worst case. A hook that crashes on a missing or broken config is noise on every
|
|
122
142
|
* single tool call.
|
|
143
|
+
*
|
|
144
|
+
* @param root Pass the root when the caller already resolved one, which skips the git
|
|
145
|
+
* spawn entirely. `proc.mts` holds its own root memo, so a script that resolved the root
|
|
146
|
+
* through that one would otherwise still pay a second spawn here.
|
|
123
147
|
*/
|
|
124
|
-
export function loadConfigSafe() {
|
|
148
|
+
export function loadConfigSafe(root) {
|
|
125
149
|
try {
|
|
126
|
-
return loadConfig(repoRoot(), { required: false });
|
|
150
|
+
return loadConfig(root ?? repoRoot(), { required: false });
|
|
127
151
|
}
|
|
128
152
|
catch {
|
|
129
153
|
return EMPTY;
|