@henryqw/pi-herdr 0.1.3 → 0.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 +1 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +12 -1
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -13,8 +13,7 @@ npm install @henryqw/pi-herdr
|
|
|
13
13
|
```ts
|
|
14
14
|
import { createHerdrClient } from "@henryqw/pi-herdr";
|
|
15
15
|
|
|
16
|
-
const herdr = createHerdrClient((
|
|
17
|
-
pi.exec(command, [...args], options));
|
|
16
|
+
const herdr = createHerdrClient(pi.exec.bind(pi));
|
|
18
17
|
const response = await herdr.json(["agent", "list"], { cwd: ctx.cwd });
|
|
19
18
|
```
|
|
20
19
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export interface HerdrExecResult {
|
|
|
4
4
|
stderr: string;
|
|
5
5
|
killed?: boolean;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
/** Mutable-array executor, compatible with a bound `pi.exec`. Args are copied by createHerdrClient. */
|
|
8
|
+
export type HerdrExecutor<Options> = (command: string, args: string[], options: Options) => Promise<HerdrExecResult>;
|
|
8
9
|
export interface HerdrClient<Options> {
|
|
9
10
|
exec(args: readonly string[], options: Options): Promise<HerdrExecResult>;
|
|
10
11
|
run(args: readonly string[], options: Options): Promise<string>;
|
|
@@ -13,3 +14,5 @@ export interface HerdrClient<Options> {
|
|
|
13
14
|
export declare function createHerdrClient<Options>(execute: HerdrExecutor<Options>): HerdrClient<Options>;
|
|
14
15
|
export declare function herdrCommandFailure(args: readonly string[], result: HerdrExecResult): string;
|
|
15
16
|
export declare function hasHerdrErrorCode(result: Pick<HerdrExecResult, "stdout" | "stderr">, expected: string): boolean;
|
|
17
|
+
/** Lock a Herdr worktree checkout path while mutating it via the Herdr CLI. */
|
|
18
|
+
export declare function withWorktreeLock<T>(checkout: string, operation: () => Promise<T>): Promise<T>;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { lock } from "proper-lockfile";
|
|
1
2
|
export function createHerdrClient(execute) {
|
|
2
3
|
const exec = async (args, options) => {
|
|
3
4
|
if (!Array.isArray(args) || args.some((arg) => typeof arg !== "string")) {
|
|
4
5
|
throw new TypeError("Herdr command arguments must be an array of strings");
|
|
5
6
|
}
|
|
6
|
-
return await execute("herdr", args, options);
|
|
7
|
+
return await execute("herdr", [...args], options);
|
|
7
8
|
};
|
|
8
9
|
const run = async (args, options) => {
|
|
9
10
|
const result = await exec(args, options);
|
|
@@ -42,6 +43,16 @@ export function hasHerdrErrorCode(result, expected) {
|
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
45
|
}
|
|
46
|
+
/** Lock a Herdr worktree checkout path while mutating it via the Herdr CLI. */
|
|
47
|
+
export async function withWorktreeLock(checkout, operation) {
|
|
48
|
+
const release = await lock(checkout);
|
|
49
|
+
try {
|
|
50
|
+
return await operation();
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
await release();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
45
56
|
function herdrCommandName(args) {
|
|
46
57
|
return ["herdr", ...args.slice(0, 2)].join(" ");
|
|
47
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henryqw/pi-herdr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared client for interacting with Herdr from Node.js tools and Pi packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
"prepack": "npm run build",
|
|
33
33
|
"pack:check": "npm pack --dry-run"
|
|
34
34
|
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/proper-lockfile": "^4.1.4"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"proper-lockfile": "^4.1.2"
|
|
40
|
+
},
|
|
35
41
|
"repository": {
|
|
36
42
|
"type": "git",
|
|
37
43
|
"url": "git+https://github.com/HenryQW/pi-packages.git",
|