@ldlework/workmark 1.1.0 → 1.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.
@@ -5,5 +5,7 @@ export interface ExecOptions {
5
5
  cwd: string;
6
6
  timeout?: number;
7
7
  }
8
+ export declare function execRaw(command: string, opts: ExecOptions): string;
8
9
  export declare function exec(command: string, opts: ExecOptions): CallToolResult;
10
+ export declare function execAsyncRaw(command: string, opts: ExecOptions): Promise<string>;
9
11
  export declare function execAsync(command: string, opts: ExecOptions): Promise<CallToolResult>;
@@ -25,32 +25,38 @@ export function fail(error) {
25
25
  }
26
26
  return { content: [{ type: "text", text: msg }], isError: true };
27
27
  }
28
- export function exec(command, opts) {
28
+ export function execRaw(command, opts) {
29
29
  const { cwd, timeout = 120_000 } = opts;
30
+ return execSync(command, {
31
+ cwd,
32
+ timeout,
33
+ encoding: "utf-8",
34
+ stdio: ["ignore", "pipe", "pipe"],
35
+ maxBuffer: 1024 * 1024 * 10,
36
+ });
37
+ }
38
+ export function exec(command, opts) {
30
39
  try {
31
- return ok(execSync(command, {
32
- cwd,
33
- timeout,
34
- encoding: "utf-8",
35
- stdio: ["ignore", "pipe", "pipe"],
36
- maxBuffer: 1024 * 1024 * 10,
37
- }));
40
+ return ok(execRaw(command, opts));
38
41
  }
39
42
  catch (e) {
40
43
  return fail(e);
41
44
  }
42
45
  }
43
46
  const execPromise = promisify(cpExec);
44
- export async function execAsync(command, opts) {
47
+ export async function execAsyncRaw(command, opts) {
45
48
  const { cwd, timeout = 120_000 } = opts;
49
+ const { stdout } = await execPromise(command, {
50
+ cwd,
51
+ timeout,
52
+ encoding: "utf-8",
53
+ maxBuffer: 1024 * 1024 * 10,
54
+ });
55
+ return stdout;
56
+ }
57
+ export async function execAsync(command, opts) {
46
58
  try {
47
- const { stdout } = await execPromise(command, {
48
- cwd,
49
- timeout,
50
- encoding: "utf-8",
51
- maxBuffer: 1024 * 1024 * 10,
52
- });
53
- return ok(stdout);
59
+ return ok(await execAsyncRaw(command, opts));
54
60
  }
55
61
  catch (e) {
56
62
  return fail(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldlework/workmark",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "main": "dist/lib/load.js",
6
6
  "bin": {
@@ -37,18 +37,20 @@ export interface ExecOptions {
37
37
  timeout?: number; // ms, default 120_000
38
38
  }
39
39
 
40
- export function exec(command: string, opts: ExecOptions): CallToolResult {
40
+ export function execRaw(command: string, opts: ExecOptions): string {
41
41
  const { cwd, timeout = 120_000 } = opts;
42
+ return execSync(command, {
43
+ cwd,
44
+ timeout,
45
+ encoding: "utf-8",
46
+ stdio: ["ignore", "pipe", "pipe"],
47
+ maxBuffer: 1024 * 1024 * 10,
48
+ });
49
+ }
50
+
51
+ export function exec(command: string, opts: ExecOptions): CallToolResult {
42
52
  try {
43
- return ok(
44
- execSync(command, {
45
- cwd,
46
- timeout,
47
- encoding: "utf-8",
48
- stdio: ["ignore", "pipe", "pipe"],
49
- maxBuffer: 1024 * 1024 * 10,
50
- }),
51
- );
53
+ return ok(execRaw(command, opts));
52
54
  } catch (e) {
53
55
  return fail(e);
54
56
  }
@@ -56,19 +58,26 @@ export function exec(command: string, opts: ExecOptions): CallToolResult {
56
58
 
57
59
  const execPromise = promisify(cpExec);
58
60
 
61
+ export async function execAsyncRaw(
62
+ command: string,
63
+ opts: ExecOptions,
64
+ ): Promise<string> {
65
+ const { cwd, timeout = 120_000 } = opts;
66
+ const { stdout } = await execPromise(command, {
67
+ cwd,
68
+ timeout,
69
+ encoding: "utf-8",
70
+ maxBuffer: 1024 * 1024 * 10,
71
+ });
72
+ return stdout;
73
+ }
74
+
59
75
  export async function execAsync(
60
76
  command: string,
61
77
  opts: ExecOptions,
62
78
  ): Promise<CallToolResult> {
63
- const { cwd, timeout = 120_000 } = opts;
64
79
  try {
65
- const { stdout } = await execPromise(command, {
66
- cwd,
67
- timeout,
68
- encoding: "utf-8",
69
- maxBuffer: 1024 * 1024 * 10,
70
- });
71
- return ok(stdout);
80
+ return ok(await execAsyncRaw(command, opts));
72
81
  } catch (e) {
73
82
  return fail(e);
74
83
  }