@anonymous-dev/0x0 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/bin/0x0 +109 -0
  3. package/package.json +24 -0
  4. package/postinstall.mjs +127 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 0x0
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/0x0 ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ const childProcess = require("child_process")
4
+ const fs = require("fs")
5
+ const path = require("path")
6
+ const os = require("os")
7
+
8
+ function run(target) {
9
+ const result = childProcess.spawnSync(target, process.argv.slice(2), {
10
+ stdio: "inherit",
11
+ })
12
+ if (result.error) {
13
+ console.error(result.error.message)
14
+ process.exit(1)
15
+ }
16
+ const code = typeof result.status === "number" ? result.status : 0
17
+ process.exit(code)
18
+ }
19
+
20
+ const envPath = process.env.ZEROXZERO_BIN_PATH
21
+ if (envPath) {
22
+ run(envPath)
23
+ }
24
+
25
+ const scriptPath = fs.realpathSync(__filename)
26
+ const scriptDir = path.dirname(scriptPath)
27
+
28
+ const platformMap = {
29
+ darwin: "darwin",
30
+ linux: "linux",
31
+ win32: "windows",
32
+ }
33
+ const archMap = {
34
+ x64: "x64",
35
+ arm64: "arm64",
36
+ arm: "arm",
37
+ }
38
+
39
+ let platform = platformMap[os.platform()]
40
+ if (!platform) {
41
+ platform = os.platform()
42
+ }
43
+ let arch = archMap[os.arch()]
44
+ if (!arch) {
45
+ arch = os.arch()
46
+ }
47
+ const base = "0x0-" + platform + "-" + arch
48
+ const binary = platform === "windows" ? "0x0.exe" : "0x0"
49
+ const scope = process.env.ZEROXZERO_NPM_SCOPE || "@anonymous-dev"
50
+
51
+ function findBinary(startDir) {
52
+ try {
53
+ const scoped = require.resolve(scope + "/" + base + "/package.json")
54
+ const candidate = path.join(path.dirname(scoped), "bin", binary)
55
+ if (fs.existsSync(candidate)) {
56
+ return candidate
57
+ }
58
+ } catch {}
59
+ let current = startDir
60
+ for (;;) {
61
+ const modules = path.join(current, "node_modules")
62
+ if (fs.existsSync(modules)) {
63
+ const entries = fs.readdirSync(modules)
64
+ for (const entry of entries) {
65
+ if (entry.startsWith("@")) {
66
+ const scoped = path.join(modules, entry)
67
+ if (!fs.existsSync(scoped)) {
68
+ continue
69
+ }
70
+ const items = fs.readdirSync(scoped)
71
+ for (const item of items) {
72
+ if (!item.startsWith(base)) {
73
+ continue
74
+ }
75
+ const candidate = path.join(scoped, item, "bin", binary)
76
+ if (fs.existsSync(candidate)) {
77
+ return candidate
78
+ }
79
+ }
80
+ continue
81
+ }
82
+ if (!entry.startsWith(base)) {
83
+ continue
84
+ }
85
+ const candidate = path.join(modules, entry, "bin", binary)
86
+ if (fs.existsSync(candidate)) {
87
+ return candidate
88
+ }
89
+ }
90
+ }
91
+ const parent = path.dirname(current)
92
+ if (parent === current) {
93
+ return
94
+ }
95
+ current = parent
96
+ }
97
+ }
98
+
99
+ const resolved = findBinary(scriptDir)
100
+ if (!resolved) {
101
+ console.error(
102
+ 'It seems that your package manager failed to install the right version of the 0x0 CLI for your platform. You can try manually installing the "' +
103
+ base +
104
+ '" package',
105
+ )
106
+ process.exit(1)
107
+ }
108
+
109
+ run(resolved)
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@anonymous-dev/0x0",
3
+ "bin": {
4
+ "0x0": "./bin/0x0"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
+ },
9
+ "version": "0.1.0",
10
+ "license": "MIT",
11
+ "optionalDependencies": {
12
+ "@anonymous-dev/0x0-linux-x64-baseline": "0.1.0",
13
+ "@anonymous-dev/0x0-linux-x64": "0.1.0",
14
+ "@anonymous-dev/0x0-darwin-arm64": "0.1.0",
15
+ "@anonymous-dev/0x0-darwin-x64-baseline": "0.1.0",
16
+ "@anonymous-dev/0x0-darwin-x64": "0.1.0",
17
+ "@anonymous-dev/0x0-windows-x64": "0.1.0",
18
+ "@anonymous-dev/0x0-linux-x64-baseline-musl": "0.1.0",
19
+ "@anonymous-dev/0x0-linux-arm64": "0.1.0",
20
+ "@anonymous-dev/0x0-linux-arm64-musl": "0.1.0",
21
+ "@anonymous-dev/0x0-windows-x64-baseline": "0.1.0",
22
+ "@anonymous-dev/0x0-linux-x64-musl": "0.1.0"
23
+ }
24
+ }
@@ -0,0 +1,127 @@
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 binaryName = platform === "windows" ? "0x0.exe" : "0x0"
53
+ const scope = process.env.ZEROXZERO_NPM_SCOPE || "@anonymous-dev"
54
+ const names = [`${scope}/0x0-${platform}-${arch}`, `0x0-${platform}-${arch}`, `zeroxzero-${platform}-${arch}`]
55
+
56
+ for (const packageName of names) {
57
+ try {
58
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
59
+ const packageDir = path.dirname(packageJsonPath)
60
+ const binaryPath = path.join(packageDir, "bin", binaryName)
61
+ if (!fs.existsSync(binaryPath)) {
62
+ continue
63
+ }
64
+ return { binaryPath, binaryName }
65
+ } catch {
66
+ continue
67
+ }
68
+ }
69
+
70
+ throw new Error(`Could not find platform package for 0x0-${platform}-${arch}`)
71
+ }
72
+
73
+ function prepareBinDirectory(binaryName) {
74
+ const binDir = path.join(__dirname, "bin")
75
+ const targetPath = path.join(binDir, binaryName)
76
+
77
+ // Ensure bin directory exists
78
+ if (!fs.existsSync(binDir)) {
79
+ fs.mkdirSync(binDir, { recursive: true })
80
+ }
81
+
82
+ // Remove existing binary/symlink if it exists
83
+ if (fs.existsSync(targetPath)) {
84
+ fs.unlinkSync(targetPath)
85
+ }
86
+
87
+ return { binDir, targetPath }
88
+ }
89
+
90
+ function symlinkBinary(sourcePath, binaryName) {
91
+ const { targetPath } = prepareBinDirectory(binaryName)
92
+
93
+ fs.symlinkSync(sourcePath, targetPath)
94
+ console.log(`0x0 binary symlinked: ${targetPath} -> ${sourcePath}`)
95
+
96
+ // Verify the file exists after operation
97
+ if (!fs.existsSync(targetPath)) {
98
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
99
+ }
100
+ }
101
+
102
+ async function main() {
103
+ try {
104
+ if (os.platform() === "win32") {
105
+ // On Windows, the .exe is already included in the package and bin field points to it
106
+ // No postinstall setup needed
107
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
108
+ return
109
+ }
110
+
111
+ // On non-Windows platforms, just verify the binary package exists
112
+ // Don't replace the wrapper script - it handles binary execution
113
+ const { binaryPath } = findBinary()
114
+ console.log(`Platform binary verified at: ${binaryPath}`)
115
+ console.log("Wrapper script will handle binary execution")
116
+ } catch (error) {
117
+ console.error("Failed to setup 0x0 binary:", error.message)
118
+ process.exit(1)
119
+ }
120
+ }
121
+
122
+ try {
123
+ main()
124
+ } catch (error) {
125
+ console.error("Postinstall script error:", error.message)
126
+ process.exit(0)
127
+ }