@anonymous-dev/0x0-git 0.2.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.
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-git 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_GIT_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-git-" + platform + "-" + arch
48
+ const binary = platform === "windows" ? "0x0-git.exe" : "0x0-git"
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-git 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-git",
3
+ "bin": {
4
+ "0x0-git": "./bin/0x0-git"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
+ },
9
+ "version": "0.2.0",
10
+ "license": "MIT",
11
+ "optionalDependencies": {
12
+ "@anonymous-dev/0x0-git-linux-x64": "0.2.0",
13
+ "@anonymous-dev/0x0-git-windows-x64": "0.2.0",
14
+ "@anonymous-dev/0x0-git-linux-arm64": "0.2.0",
15
+ "@anonymous-dev/0x0-git-linux-arm64-musl": "0.2.0",
16
+ "@anonymous-dev/0x0-git-darwin-arm64": "0.2.0",
17
+ "@anonymous-dev/0x0-git-darwin-x64": "0.2.0",
18
+ "@anonymous-dev/0x0-git-linux-x64-musl": "0.2.0",
19
+ "@anonymous-dev/0x0-git-windows-x64-baseline": "0.2.0",
20
+ "@anonymous-dev/0x0-git-linux-x64-baseline": "0.2.0",
21
+ "@anonymous-dev/0x0-git-darwin-x64-baseline": "0.2.0",
22
+ "@anonymous-dev/0x0-git-linux-x64-baseline-musl": "0.2.0"
23
+ }
24
+ }
@@ -0,0 +1,156 @@
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
+ const useColor = !process.env.NO_COLOR && process.stdout.isTTY
13
+ const bold = (s) => (useColor ? `\x1b[1m${s}\x1b[0m` : s)
14
+ const green = (s) => (useColor ? `\x1b[32m${s}\x1b[0m` : s)
15
+ const yellow = (s) => (useColor ? `\x1b[33m${s}\x1b[0m` : s)
16
+
17
+ function detectPlatformAndArch() {
18
+ let platform
19
+ switch (os.platform()) {
20
+ case "darwin":
21
+ platform = "darwin"
22
+ break
23
+ case "linux":
24
+ platform = "linux"
25
+ break
26
+ case "win32":
27
+ platform = "windows"
28
+ break
29
+ default:
30
+ platform = os.platform()
31
+ break
32
+ }
33
+
34
+ let arch
35
+ switch (os.arch()) {
36
+ case "x64":
37
+ arch = "x64"
38
+ break
39
+ case "arm64":
40
+ arch = "arm64"
41
+ break
42
+ case "arm":
43
+ arch = "arm"
44
+ break
45
+ default:
46
+ arch = os.arch()
47
+ break
48
+ }
49
+
50
+ return { platform, arch }
51
+ }
52
+
53
+ function findBinary() {
54
+ const { platform, arch } = detectPlatformAndArch()
55
+ const binaryName = platform === "windows" ? "0x0-git.exe" : "0x0-git"
56
+ const scope = process.env.ZEROXZERO_NPM_SCOPE || "@anonymous-dev"
57
+ const names = [`${scope}/0x0-git-${platform}-${arch}`, `0x0-git-${platform}-${arch}`]
58
+
59
+ for (const packageName of names) {
60
+ try {
61
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
62
+ const packageDir = path.dirname(packageJsonPath)
63
+ const binaryPath = path.join(packageDir, "bin", binaryName)
64
+ if (!fs.existsSync(binaryPath)) {
65
+ continue
66
+ }
67
+ return { binaryPath, binaryName }
68
+ } catch {
69
+ continue
70
+ }
71
+ }
72
+
73
+ throw new Error(`Could not find platform package for 0x0-git-${platform}-${arch}`)
74
+ }
75
+
76
+ function getVersion() {
77
+ try {
78
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"))
79
+ return pkg.version || "unknown"
80
+ } catch {
81
+ return "unknown"
82
+ }
83
+ }
84
+
85
+ function checkServer() {
86
+ const scope = process.env.ZEROXZERO_NPM_SCOPE || "@anonymous-dev"
87
+ try {
88
+ const pkgPath = require.resolve(`${scope}/0x0/package.json`)
89
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
90
+ return { found: true, version: pkg.version, scope }
91
+ } catch {
92
+ return { found: false, scope }
93
+ }
94
+ }
95
+
96
+ function stripAnsi(s) {
97
+ // eslint-disable-next-line no-control-regex
98
+ return s.replace(/\x1b\[[0-9;]*m/g, "")
99
+ }
100
+
101
+ function printBox(lines) {
102
+ const maxVisual = Math.max(...lines.map((l) => stripAnsi(l).length))
103
+ const width = maxVisual + 4
104
+ const top = ` ┌${"─".repeat(width)}┐`
105
+ const bot = ` └${"─".repeat(width)}┘`
106
+ const empty = ` │${" ".repeat(width)}│`
107
+
108
+ console.log("")
109
+ console.log(top)
110
+ console.log(empty)
111
+ for (const line of lines) {
112
+ const pad = width - 2 - stripAnsi(line).length
113
+ console.log(` │ ${line}${" ".repeat(Math.max(0, pad))}│`)
114
+ }
115
+ console.log(empty)
116
+ console.log(bot)
117
+ console.log("")
118
+ }
119
+
120
+ async function main() {
121
+ try {
122
+ if (os.platform() === "win32") {
123
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
124
+ return
125
+ }
126
+
127
+ const { binaryPath } = findBinary()
128
+ const { platform, arch } = detectPlatformAndArch()
129
+ const version = getVersion()
130
+
131
+ const lines = [bold(`0x0-git v${version}`), ""]
132
+ lines.push(`${green("✓")} Platform: ${platform}-${arch}`)
133
+ lines.push(`${green("✓")} Binary verified`)
134
+
135
+ const server = checkServer()
136
+ if (server.found) {
137
+ lines.push(`${green("✓")} Server: ${server.scope}/0x0 v${server.version}`)
138
+ } else {
139
+ lines.push(`${yellow("!")} Server: ${server.scope}/0x0 not found`)
140
+ lines.push(` Install: npm install -g ${server.scope}/0x0`)
141
+ }
142
+
143
+ lines.push("")
144
+ lines.push(`Run: ${bold("0x0-git --help")}`)
145
+
146
+ printBox(lines)
147
+ } catch (error) {
148
+ console.error("Failed to setup 0x0-git binary:", error.message)
149
+ process.exit(1)
150
+ }
151
+ }
152
+
153
+ main().catch((error) => {
154
+ console.error("Postinstall script error:", error.message)
155
+ process.exit(0)
156
+ })