@syengup/friday-channel-next 0.1.6 → 0.1.7

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.
@@ -1,20 +1,45 @@
1
- import { readdirSync } from "node:fs";
2
- import { join } from "node:path";
1
+ import { execSync } from "node:child_process";
2
+ import { readdirSync, realpathSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
3
4
  let cache = null;
5
+ function resolveOpenClawDistFromBin() {
6
+ try {
7
+ const whichCmd = process.platform === "win32" ? "where" : "which";
8
+ const raw = execSync(`${whichCmd} openclaw`, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
9
+ const binPath = raw.split("\n")[0].trim();
10
+ if (!binPath)
11
+ return null;
12
+ const real = realpathSync(binPath);
13
+ const dist = join(dirname(real), "dist");
14
+ readdirSync(dist); // throw if not a readable directory
15
+ return dist;
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ }
4
21
  function resolveOpenClawDist() {
5
- for (const root of [
22
+ // Priority order:
23
+ // 1. OPENCLAW_DIST env var (explicit override, works everywhere)
24
+ // 2. Resolve the `openclaw` binary on PATH → dist/ (robust, cross-platform)
25
+ // 3. Platform-specific standard install paths
26
+ const fromBin = resolveOpenClawDistFromBin();
27
+ const candidates = [
28
+ process.env.OPENCLAW_DIST,
29
+ fromBin,
6
30
  join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"),
7
31
  "/opt/homebrew/lib/node_modules/openclaw/dist",
8
32
  "/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist",
9
33
  "/usr/local/lib/node_modules/openclaw/dist",
10
- ]) {
34
+ ].filter((v) => typeof v === "string" && v.length > 0);
35
+ for (const root of candidates) {
11
36
  try {
12
37
  readdirSync(root);
13
38
  return root;
14
39
  }
15
40
  catch { }
16
41
  }
17
- throw new Error("OpenClaw dist directory not found");
42
+ throw new Error("OpenClaw dist directory not found. Set OPENCLAW_DIST env var.");
18
43
  }
19
44
  export async function loadNodePairingModule() {
20
45
  if (cache)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syengup/friday-channel-next",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "OpenClaw Friday Next Apple channel plugin",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,18 +1,43 @@
1
- import { readdirSync } from "node:fs";
2
- import { join } from "node:path";
1
+ import { execSync } from "node:child_process";
2
+ import { readdirSync, realpathSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
3
4
 
4
5
  let cache: { listNodePairing: Function; approveNodePairing: Function } | null = null;
5
6
 
7
+ function resolveOpenClawDistFromBin(): string | null {
8
+ try {
9
+ const whichCmd = process.platform === "win32" ? "where" : "which";
10
+ const raw = execSync(`${whichCmd} openclaw`, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
11
+ const binPath = raw.split("\n")[0].trim();
12
+ if (!binPath) return null;
13
+ const real = realpathSync(binPath);
14
+ const dist = join(dirname(real), "dist");
15
+ readdirSync(dist); // throw if not a readable directory
16
+ return dist;
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+
6
22
  function resolveOpenClawDist(): string {
7
- for (const root of [
23
+ // Priority order:
24
+ // 1. OPENCLAW_DIST env var (explicit override, works everywhere)
25
+ // 2. Resolve the `openclaw` binary on PATH → dist/ (robust, cross-platform)
26
+ // 3. Platform-specific standard install paths
27
+ const fromBin = resolveOpenClawDistFromBin();
28
+ const candidates: string[] = [
29
+ process.env.OPENCLAW_DIST,
30
+ fromBin,
8
31
  join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"),
9
32
  "/opt/homebrew/lib/node_modules/openclaw/dist",
10
33
  "/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist",
11
34
  "/usr/local/lib/node_modules/openclaw/dist",
12
- ]) {
35
+ ].filter((v): v is string => typeof v === "string" && v.length > 0);
36
+
37
+ for (const root of candidates) {
13
38
  try { readdirSync(root); return root; } catch {}
14
39
  }
15
- throw new Error("OpenClaw dist directory not found");
40
+ throw new Error("OpenClaw dist directory not found. Set OPENCLAW_DIST env var.");
16
41
  }
17
42
 
18
43
  export async function loadNodePairingModule(): Promise<{