@chrysb/alphaclaw 0.8.3-beta.2 → 0.8.3-beta.3

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": "@chrysb/alphaclaw",
3
- "version": "0.8.3-beta.2",
3
+ "version": "0.8.3-beta.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -20,12 +20,13 @@
20
20
  "files": [
21
21
  "bin/",
22
22
  "lib/",
23
- "patches/"
23
+ "patches/",
24
+ "scripts/apply-openclaw-patches.js"
24
25
  ],
25
26
  "scripts": {
26
27
  "start": "node bin/alphaclaw.js start",
27
28
  "build:ui": "node scripts/build-ui.mjs",
28
- "postinstall": "patch-package",
29
+ "postinstall": "node ./scripts/apply-openclaw-patches.js",
29
30
  "test": "vitest run",
30
31
  "test:watch": "vitest",
31
32
  "test:watchdog": "vitest run tests/server/watchdog.test.js tests/server/watchdog-db.test.js tests/server/routes-watchdog.test.js",
@@ -0,0 +1,99 @@
1
+ /**
2
+ * patch-package resolves paths relative to the npm/yarn project root (where the
3
+ * lockfile lives). When this package's postinstall runs, process.cwd() is often
4
+ * this package directory, so a plain `patch-package` call treats that as the
5
+ * app root and looks for ./node_modules/openclaw under it — but openclaw is
6
+ * usually hoisted to the consumer's top-level node_modules.
7
+ *
8
+ * This script finds the real install root (directory containing a lockfile) and
9
+ * runs patch-package there with --patch-dir pointing at our bundled patches/.
10
+ */
11
+ const { spawnSync } = require("child_process");
12
+ const fs = require("fs");
13
+ const path = require("path");
14
+
15
+ const kAlphaclawRoot = path.join(__dirname, "..");
16
+
17
+ const findProjectRootFromOpenclawDir = (openclawDir) => {
18
+ let dir = path.resolve(openclawDir);
19
+ for (let i = 0; i < 30; i += 1) {
20
+ if (
21
+ fs.existsSync(path.join(dir, "package-lock.json")) ||
22
+ fs.existsSync(path.join(dir, "yarn.lock")) ||
23
+ fs.existsSync(path.join(dir, "pnpm-lock.yaml"))
24
+ ) {
25
+ return dir;
26
+ }
27
+ const parent = path.dirname(dir);
28
+ if (parent === dir) break;
29
+ dir = parent;
30
+ }
31
+ return path.dirname(path.dirname(openclawDir));
32
+ };
33
+
34
+ const main = () => {
35
+ const patchesDir = path.join(kAlphaclawRoot, "patches");
36
+ if (!fs.existsSync(patchesDir)) {
37
+ return;
38
+ }
39
+ const hasPatch = fs
40
+ .readdirSync(patchesDir)
41
+ .some((name) => name.endsWith(".patch"));
42
+ if (!hasPatch) {
43
+ return;
44
+ }
45
+
46
+ let openclawMainPath;
47
+ try {
48
+ openclawMainPath = require.resolve("openclaw", { paths: [kAlphaclawRoot] });
49
+ } catch {
50
+ return;
51
+ }
52
+
53
+ const openclawDir = (() => {
54
+ let dir = path.dirname(openclawMainPath);
55
+ for (let i = 0; i < 8; i += 1) {
56
+ const pkgPath = path.join(dir, "package.json");
57
+ if (fs.existsSync(pkgPath)) {
58
+ try {
59
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
60
+ if (pkg.name === "openclaw") return dir;
61
+ } catch {
62
+ /* continue */
63
+ }
64
+ }
65
+ const parent = path.dirname(dir);
66
+ if (parent === dir) break;
67
+ dir = parent;
68
+ }
69
+ return path.dirname(path.dirname(openclawMainPath));
70
+ })();
71
+ const projectRoot = findProjectRootFromOpenclawDir(openclawDir);
72
+
73
+ let relPatchDir = path.relative(projectRoot, patchesDir);
74
+ if (relPatchDir.startsWith("..") || path.isAbsolute(relPatchDir)) {
75
+ console.error(
76
+ "[@chrysb/alphaclaw] patch-package: could not resolve patch dir relative to project root",
77
+ );
78
+ process.exit(1);
79
+ }
80
+ relPatchDir = relPatchDir.split(path.sep).join("/");
81
+
82
+ const patchPackageMain = require.resolve("patch-package/dist/index.js", {
83
+ paths: [kAlphaclawRoot],
84
+ });
85
+
86
+ const result = spawnSync(
87
+ process.execPath,
88
+ [patchPackageMain, "--patch-dir", relPatchDir],
89
+ { cwd: projectRoot, stdio: "inherit", env: process.env },
90
+ );
91
+ if (result.error) {
92
+ throw result.error;
93
+ }
94
+ if (result.status !== 0 && result.status !== null) {
95
+ process.exit(result.status);
96
+ }
97
+ };
98
+
99
+ main();