@pixelml/claw 0.0.0-dev-202512250746

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.
Files changed (3) hide show
  1. package/bin/claw +99 -0
  2. package/package.json +23 -0
  3. package/postinstall.mjs +122 -0
package/bin/claw ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+
3
+ import childProcess from "child_process"
4
+ import fs from "fs"
5
+ import path from "path"
6
+ import os from "os"
7
+ import { fileURLToPath } from "url"
8
+
9
+ function run(target, args = process.argv.slice(2), options = {}) {
10
+ const result = childProcess.spawnSync(target, args, {
11
+ stdio: "inherit",
12
+ ...options,
13
+ })
14
+ if (result.error) {
15
+ console.error(result.error.message)
16
+ process.exit(1)
17
+ }
18
+ const code = typeof result.status === "number" ? result.status : 0
19
+ process.exit(code)
20
+ }
21
+
22
+ const envPath = process.env.CLAW_BIN_PATH
23
+ if (envPath) {
24
+ run(envPath)
25
+ }
26
+
27
+ const __filename = fileURLToPath(import.meta.url)
28
+ const scriptPath = fs.realpathSync(__filename)
29
+ const scriptDir = path.dirname(scriptPath)
30
+ const pkgRoot = path.resolve(scriptDir, "..")
31
+
32
+ const platformMap = {
33
+ darwin: "darwin",
34
+ linux: "linux",
35
+ win32: "windows",
36
+ }
37
+ const archMap = {
38
+ x64: "x64",
39
+ arm64: "arm64",
40
+ arm: "arm",
41
+ }
42
+
43
+ let platform = platformMap[os.platform()]
44
+ if (!platform) {
45
+ platform = os.platform()
46
+ }
47
+ let arch = archMap[os.arch()]
48
+ if (!arch) {
49
+ arch = os.arch()
50
+ }
51
+ const base = "claw-" + platform + "-" + arch
52
+ const binary = platform === "windows" ? "claw.exe" : "claw"
53
+
54
+ function findBinary(startDir) {
55
+ let current = startDir
56
+ for (; ;) {
57
+ const modules = path.join(current, "node_modules")
58
+ if (fs.existsSync(modules)) {
59
+ const entries = fs.readdirSync(modules)
60
+ for (const entry of entries) {
61
+ if (!entry.startsWith(base)) {
62
+ continue
63
+ }
64
+ const candidate = path.join(modules, entry, "bin", binary)
65
+ if (fs.existsSync(candidate)) {
66
+ return candidate
67
+ }
68
+ }
69
+ }
70
+ const parent = path.dirname(current)
71
+ if (parent === current) {
72
+ return
73
+ }
74
+ current = parent
75
+ }
76
+ }
77
+
78
+ const resolved = findBinary(scriptDir)
79
+ if (resolved) {
80
+ run(resolved)
81
+ } else {
82
+ // Fallback to running source in dev
83
+ const sourceIndex = path.resolve(pkgRoot, "src/index.ts")
84
+ if (fs.existsSync(sourceIndex)) {
85
+ run("bun", ["run", "--cwd", pkgRoot, "--conditions=browser", sourceIndex, ...process.argv.slice(2)], {
86
+ env: {
87
+ ...process.env,
88
+ CLAW_CWD: process.cwd(),
89
+ },
90
+ })
91
+ } else {
92
+ console.error(
93
+ 'It seems that your package manager failed to install the right version of the Claw CLI for your platform. You can try manually installing the "' +
94
+ base +
95
+ '" package',
96
+ )
97
+ process.exit(1)
98
+ }
99
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@pixelml/claw",
3
+ "bin": {
4
+ "@pixelml/claw": "./bin/@pixelml/claw"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
+ },
9
+ "version": "0.0.0-dev-202512250746",
10
+ "optionalDependencies": {
11
+ "@pixelml/claw-linux-arm64": "0.0.0-dev-202512250746",
12
+ "@pixelml/claw-linux-x64": "0.0.0-dev-202512250746",
13
+ "@pixelml/claw-linux-x64-baseline": "0.0.0-dev-202512250746",
14
+ "@pixelml/claw-linux-arm64-musl": "0.0.0-dev-202512250746",
15
+ "@pixelml/claw-linux-x64-musl": "0.0.0-dev-202512250746",
16
+ "@pixelml/claw-linux-x64-baseline-musl": "0.0.0-dev-202512250746",
17
+ "@pixelml/claw-darwin-arm64": "0.0.0-dev-202512250746",
18
+ "@pixelml/claw-darwin-x64": "0.0.0-dev-202512250746",
19
+ "@pixelml/claw-darwin-x64-baseline": "0.0.0-dev-202512250746",
20
+ "@pixelml/claw-windows-x64": "0.0.0-dev-202512250746",
21
+ "@pixelml/claw-windows-x64-baseline": "0.0.0-dev-202512250746"
22
+ }
23
+ }
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs"
4
+ import path from "path"
5
+ import os from "os"
6
+ import { fileURLToPath } from "url"
7
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const require = createRequire(import.meta.url)
11
+
12
+ function detectPlatformAndArch() {
13
+ // Map platform names
14
+ let platform
15
+ switch (os.platform()) {
16
+ case "darwin":
17
+ platform = "darwin"
18
+ break
19
+ case "linux":
20
+ platform = "linux"
21
+ break
22
+ case "win32":
23
+ platform = "windows"
24
+ break
25
+ default:
26
+ platform = os.platform()
27
+ break
28
+ }
29
+
30
+ // Map architecture names
31
+ let arch
32
+ switch (os.arch()) {
33
+ case "x64":
34
+ arch = "x64"
35
+ break
36
+ case "arm64":
37
+ arch = "arm64"
38
+ break
39
+ case "arm":
40
+ arch = "arm"
41
+ break
42
+ default:
43
+ arch = os.arch()
44
+ break
45
+ }
46
+
47
+ return { platform, arch }
48
+ }
49
+
50
+ function findBinary() {
51
+ const { platform, arch } = detectPlatformAndArch()
52
+ const packageName = `claw-${platform}-${arch}`
53
+ const binaryName = platform === "windows" ? "claw.exe" : "claw"
54
+
55
+ try {
56
+ // Use require.resolve to find the package
57
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
58
+ const packageDir = path.dirname(packageJsonPath)
59
+ const binaryPath = path.join(packageDir, "bin", binaryName)
60
+
61
+ if (!fs.existsSync(binaryPath)) {
62
+ throw new Error(`Binary not found at ${binaryPath}`)
63
+ }
64
+
65
+ return { binaryPath, binaryName }
66
+ } catch (error) {
67
+ throw new Error(`Could not find package ${packageName}: ${error.message}`)
68
+ }
69
+ }
70
+
71
+ function prepareBinDirectory(binaryName) {
72
+ const binDir = path.join(__dirname, "bin")
73
+ const targetPath = path.join(binDir, binaryName)
74
+
75
+ // Ensure bin directory exists
76
+ if (!fs.existsSync(binDir)) {
77
+ fs.mkdirSync(binDir, { recursive: true })
78
+ }
79
+
80
+ // Remove existing binary/symlink if it exists
81
+ if (fs.existsSync(targetPath)) {
82
+ fs.unlinkSync(targetPath)
83
+ }
84
+
85
+ return { binDir, targetPath }
86
+ }
87
+
88
+ function symlinkBinary(sourcePath, binaryName) {
89
+ const { targetPath } = prepareBinDirectory(binaryName)
90
+
91
+ fs.symlinkSync(sourcePath, targetPath)
92
+ console.log(`claw binary symlinked: ${targetPath} -> ${sourcePath}`)
93
+
94
+ // Verify the file exists after operation
95
+ if (!fs.existsSync(targetPath)) {
96
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
97
+ }
98
+ }
99
+
100
+ async function main() {
101
+ try {
102
+ if (os.platform() === "win32") {
103
+ // On Windows, the .exe is already included in the package and bin field points to it
104
+ // No postinstall setup needed
105
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
106
+ return
107
+ }
108
+
109
+ const { binaryPath, binaryName } = findBinary()
110
+ symlinkBinary(binaryPath, binaryName)
111
+ } catch (error) {
112
+ console.error("Failed to setup claw binary:", error.message)
113
+ process.exit(1)
114
+ }
115
+ }
116
+
117
+ try {
118
+ main()
119
+ } catch (error) {
120
+ console.error("Postinstall script error:", error.message)
121
+ process.exit(0)
122
+ }