codeplane-ai 27.2.1 → 27.3.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 (2) hide show
  1. package/package.json +13 -13
  2. package/postinstall.mjs +100 -13
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "scripts": {
7
7
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
8
  },
9
- "version": "27.2.1",
9
+ "version": "27.3.0",
10
10
  "license": "MIT",
11
11
  "repository": {
12
12
  "type": "git",
@@ -17,17 +17,17 @@
17
17
  },
18
18
  "homepage": "https://github.com/devinoldenburg/codeplane",
19
19
  "optionalDependencies": {
20
- "codeplane-linux-arm64-musl": "27.2.1",
21
- "codeplane-linux-x64": "27.2.1",
22
- "codeplane-linux-x64-baseline-musl": "27.2.1",
23
- "codeplane-darwin-x64-baseline": "27.2.1",
24
- "codeplane-darwin-arm64": "27.2.1",
25
- "codeplane-linux-x64-baseline": "27.2.1",
26
- "codeplane-windows-arm64": "27.2.1",
27
- "codeplane-windows-x64-baseline": "27.2.1",
28
- "codeplane-linux-x64-musl": "27.2.1",
29
- "codeplane-linux-arm64": "27.2.1",
30
- "codeplane-windows-x64": "27.2.1",
31
- "codeplane-darwin-x64": "27.2.1"
20
+ "codeplane-linux-arm64-musl": "27.3.0",
21
+ "codeplane-linux-x64": "27.3.0",
22
+ "codeplane-linux-x64-baseline-musl": "27.3.0",
23
+ "codeplane-darwin-x64-baseline": "27.3.0",
24
+ "codeplane-darwin-arm64": "27.3.0",
25
+ "codeplane-linux-x64-baseline": "27.3.0",
26
+ "codeplane-windows-arm64": "27.3.0",
27
+ "codeplane-windows-x64-baseline": "27.3.0",
28
+ "codeplane-linux-x64-musl": "27.3.0",
29
+ "codeplane-linux-arm64": "27.3.0",
30
+ "codeplane-windows-x64": "27.3.0",
31
+ "codeplane-darwin-x64": "27.3.0"
32
32
  }
33
33
  }
package/postinstall.mjs CHANGED
@@ -47,25 +47,112 @@ function detectPlatformAndArch() {
47
47
  return { platform, arch }
48
48
  }
49
49
 
50
+ function supportsAvx2(platform, arch) {
51
+ if (arch !== "x64") return false
52
+
53
+ if (platform === "linux") {
54
+ try {
55
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
56
+ } catch {
57
+ return false
58
+ }
59
+ }
60
+
61
+ if (platform === "darwin") {
62
+ try {
63
+ const result = require("child_process").spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
64
+ encoding: "utf8",
65
+ timeout: 1500,
66
+ })
67
+ if (result.status !== 0) return false
68
+ return (result.stdout || "").trim() === "1"
69
+ } catch {
70
+ return false
71
+ }
72
+ }
73
+
74
+ if (platform === "windows") {
75
+ const cmd =
76
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
77
+ for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
78
+ try {
79
+ const result = require("child_process").spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
80
+ encoding: "utf8",
81
+ timeout: 3000,
82
+ windowsHide: true,
83
+ })
84
+ if (result.status !== 0) continue
85
+ const out = (result.stdout || "").trim().toLowerCase()
86
+ if (out === "true" || out === "1") return true
87
+ if (out === "false" || out === "0") return false
88
+ } catch {
89
+ continue
90
+ }
91
+ }
92
+ }
93
+
94
+ return false
95
+ }
96
+
97
+ function packageNames(platform, arch) {
98
+ const base = `codeplane-${platform}-${arch}`
99
+ const baseline = arch === "x64" && !supportsAvx2(platform, arch)
100
+
101
+ if (platform === "linux") {
102
+ const musl = (() => {
103
+ try {
104
+ if (fs.existsSync("/etc/alpine-release")) return true
105
+ } catch {}
106
+ try {
107
+ const result = require("child_process").spawnSync("ldd", ["--version"], { encoding: "utf8" })
108
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
109
+ } catch {
110
+ return false
111
+ }
112
+ })()
113
+
114
+ if (musl) {
115
+ if (arch === "x64") {
116
+ if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
117
+ return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
118
+ }
119
+ return [`${base}-musl`, base]
120
+ }
121
+
122
+ if (arch === "x64") {
123
+ if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
124
+ return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
125
+ }
126
+ return [base, `${base}-musl`]
127
+ }
128
+
129
+ if (arch === "x64") {
130
+ if (baseline) return [`${base}-baseline`, base]
131
+ return [base, `${base}-baseline`]
132
+ }
133
+
134
+ return [base]
135
+ }
136
+
50
137
  function findBinary() {
51
138
  const { platform, arch } = detectPlatformAndArch()
52
- const packageName = `codeplane-${platform}-${arch}`
53
139
  const binaryName = platform === "windows" ? "codeplane.exe" : "codeplane"
54
140
 
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}`)
141
+ for (const packageName of packageNames(platform, arch)) {
142
+ try {
143
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
144
+ const packageDir = path.dirname(packageJsonPath)
145
+ const binaryPath = path.join(packageDir, "bin", binaryName)
146
+ if (!fs.existsSync(binaryPath)) continue
147
+ return { binaryPath, binaryName }
148
+ } catch {
149
+ continue
63
150
  }
64
-
65
- return { binaryPath, binaryName }
66
- } catch (error) {
67
- throw new Error(`Could not find package ${packageName}: ${error.message}`, { cause: error })
68
151
  }
152
+
153
+ throw new Error(
154
+ `Could not find a matching Codeplane binary package for ${platform}/${arch}. Tried ${packageNames(platform, arch).join(", ")}`,
155
+ )
69
156
  }
70
157
 
71
158
  async function main() {