@ericsanchezok/synergy 1.2.2 → 1.2.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.
@@ -0,0 +1,124 @@
1
+ const childProcess = require("child_process")
2
+ const fs = require("fs")
3
+ const os = require("os")
4
+ const path = require("path")
5
+
6
+ function mapPlatform(input) {
7
+ switch (input) {
8
+ case "darwin":
9
+ return "darwin"
10
+ case "linux":
11
+ return "linux"
12
+ case "win32":
13
+ return "windows"
14
+ default:
15
+ return input
16
+ }
17
+ }
18
+
19
+ function mapArch(input) {
20
+ switch (input) {
21
+ case "x64":
22
+ return "x64"
23
+ case "arm64":
24
+ return "arm64"
25
+ case "arm":
26
+ return "arm"
27
+ default:
28
+ return input
29
+ }
30
+ }
31
+
32
+ function commandOutput(command, args) {
33
+ try {
34
+ const result = childProcess.spawnSync(command, args, {
35
+ encoding: "utf8",
36
+ stdio: ["ignore", "pipe", "pipe"],
37
+ })
38
+ if (result.error) return ""
39
+ return `${result.stdout || ""}${result.stderr || ""}`
40
+ } catch {
41
+ return ""
42
+ }
43
+ }
44
+
45
+ function detectArch(platform, arch) {
46
+ if (platform === "darwin" && arch === "x64") {
47
+ const translated = commandOutput("sysctl", ["-n", "sysctl.proc_translated"]).trim()
48
+ if (translated === "1") return "arm64"
49
+ }
50
+ return arch
51
+ }
52
+
53
+ function detectMusl(platform) {
54
+ if (platform !== "linux") return false
55
+ if (fs.existsSync("/etc/alpine-release")) return true
56
+ return /musl/i.test(commandOutput("ldd", ["--version"]))
57
+ }
58
+
59
+ function detectBaseline(platform, arch) {
60
+ if (arch !== "x64") return false
61
+ if (platform === "linux") {
62
+ try {
63
+ return !/avx2/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
64
+ } catch {
65
+ return false
66
+ }
67
+ }
68
+ if (platform === "darwin") {
69
+ return commandOutput("sysctl", ["-n", "hw.optional.avx2_0"]).trim() !== "1"
70
+ }
71
+ return false
72
+ }
73
+
74
+ function detectRuntimeTarget() {
75
+ const platform = mapPlatform(os.platform())
76
+ const arch = detectArch(platform, mapArch(os.arch()))
77
+ return {
78
+ platform,
79
+ arch,
80
+ musl: detectMusl(platform),
81
+ baseline: detectBaseline(platform, arch),
82
+ }
83
+ }
84
+
85
+ function candidatePackageNames(scope = "@ericsanchezok") {
86
+ const target = detectRuntimeTarget()
87
+ const base = `${scope}/synergy-${target.platform}-${target.arch}`
88
+ const candidates = []
89
+
90
+ if (target.baseline && target.musl) candidates.push(`${base}-baseline-musl`)
91
+ if (target.musl) candidates.push(`${base}-musl`)
92
+ if (target.baseline) candidates.push(`${base}-baseline`)
93
+ candidates.push(base)
94
+
95
+ return [...new Set(candidates)]
96
+ }
97
+
98
+ function packageBinaryName() {
99
+ return os.platform() === "win32" ? "synergy.exe" : "synergy"
100
+ }
101
+
102
+ function findInstalledBinary(startDir) {
103
+ const binary = packageBinaryName()
104
+ let current = startDir
105
+ for (;;) {
106
+ const modules = path.join(current, "node_modules")
107
+ if (fs.existsSync(modules)) {
108
+ for (const packageName of candidatePackageNames()) {
109
+ const candidate = path.join(modules, packageName, "bin", binary)
110
+ if (fs.existsSync(candidate)) return candidate
111
+ }
112
+ }
113
+ const parent = path.dirname(current)
114
+ if (parent === current) return
115
+ current = parent
116
+ }
117
+ }
118
+
119
+ module.exports = {
120
+ candidatePackageNames,
121
+ detectRuntimeTarget,
122
+ findInstalledBinary,
123
+ packageBinaryName,
124
+ }
package/bin/synergy CHANGED
@@ -3,7 +3,6 @@
3
3
  const childProcess = require("child_process")
4
4
  const fs = require("fs")
5
5
  const path = require("path")
6
- const os = require("os")
7
6
 
8
7
  function run(target) {
9
8
  const result = childProcess.spawnSync(target, process.argv.slice(2), {
@@ -25,65 +24,14 @@ if (envPath) {
25
24
  const scriptPath = fs.realpathSync(__filename)
26
25
  const scriptDir = path.dirname(scriptPath)
27
26
 
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 = "synergy-" + platform + "-" + arch
48
- const scopedBase = "@ericsanchezok/" + base
49
- const binary = platform === "windows" ? "synergy.exe" : "synergy"
50
-
51
- function findBinary(startDir) {
52
- let current = startDir
53
- for (;;) {
54
- const modules = path.join(current, "node_modules")
55
- if (fs.existsSync(modules)) {
56
- // Check scoped package first (@ericsanchezok/synergy-windows-x64)
57
- const scopedCandidate = path.join(modules, scopedBase, "bin", binary)
58
- if (fs.existsSync(scopedCandidate)) {
59
- return scopedCandidate
60
- }
61
- // Fallback: check non-scoped packages
62
- const entries = fs.readdirSync(modules)
63
- for (const entry of entries) {
64
- if (!entry.startsWith(base)) {
65
- continue
66
- }
67
- const candidate = path.join(modules, entry, "bin", binary)
68
- if (fs.existsSync(candidate)) {
69
- return candidate
70
- }
71
- }
72
- }
73
- const parent = path.dirname(current)
74
- if (parent === current) {
75
- return
76
- }
77
- current = parent
78
- }
79
- }
27
+ const { findInstalledBinary, candidatePackageNames } = require(path.join(scriptDir, "platform-package.cjs"))
80
28
 
81
- const resolved = findBinary(scriptDir)
29
+ const resolved = findInstalledBinary(scriptDir)
82
30
  if (!resolved) {
31
+ const names = candidatePackageNames()
83
32
  console.error(
84
- 'It seems that your package manager failed to install the right version of the Synergy CLI for your platform. You can try manually installing the "' +
85
- scopedBase +
86
- '" package',
33
+ "It seems that your package manager failed to install the right version of the Synergy CLI for your platform. You can try manually installing one of: " +
34
+ names.join(", "),
87
35
  )
88
36
  process.exit(1)
89
37
  }
package/package.json CHANGED
@@ -6,19 +6,19 @@
6
6
  "scripts": {
7
7
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
8
  },
9
- "version": "1.2.2",
9
+ "version": "1.2.3",
10
10
  "optionalDependencies": {
11
- "@ericsanchezok/synergy-linux-x64-baseline": "1.2.2",
12
- "@ericsanchezok/synergy-darwin-x64": "1.2.2",
13
- "@ericsanchezok/synergy-linux-arm64": "1.2.2",
14
- "@ericsanchezok/synergy-windows-x64-baseline": "1.2.2",
15
- "@ericsanchezok/synergy-darwin-x64-baseline": "1.2.2",
16
- "@ericsanchezok/synergy-windows-x64": "1.2.2",
17
- "@ericsanchezok/synergy-linux-arm64-musl": "1.2.2",
18
- "@ericsanchezok/synergy-linux-x64-baseline-musl": "1.2.2",
19
- "@ericsanchezok/synergy-darwin-arm64": "1.2.2",
20
- "@ericsanchezok/synergy-linux-x64-musl": "1.2.2",
21
- "@ericsanchezok/synergy-linux-x64": "1.2.2"
11
+ "@ericsanchezok/synergy-linux-x64-baseline": "1.2.3",
12
+ "@ericsanchezok/synergy-darwin-x64": "1.2.3",
13
+ "@ericsanchezok/synergy-linux-arm64": "1.2.3",
14
+ "@ericsanchezok/synergy-windows-x64-baseline": "1.2.3",
15
+ "@ericsanchezok/synergy-darwin-x64-baseline": "1.2.3",
16
+ "@ericsanchezok/synergy-windows-x64": "1.2.3",
17
+ "@ericsanchezok/synergy-linux-arm64-musl": "1.2.3",
18
+ "@ericsanchezok/synergy-linux-x64-baseline-musl": "1.2.3",
19
+ "@ericsanchezok/synergy-darwin-arm64": "1.2.3",
20
+ "@ericsanchezok/synergy-linux-x64-musl": "1.2.3",
21
+ "@ericsanchezok/synergy-linux-x64": "1.2.3"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
package/postinstall.mjs CHANGED
@@ -9,63 +9,26 @@ import { createRequire } from "module"
9
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
10
  const require = createRequire(import.meta.url)
11
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
- }
12
+ // Load shared platform detection from platform-package.cjs (co-located in bin/)
13
+ const platformPkg = require(path.join(__dirname, "bin/platform-package.cjs"))
49
14
 
50
15
  function findBinary() {
51
- const { platform, arch } = detectPlatformAndArch()
52
- const packageName = `@ericsanchezok/synergy-${platform}-${arch}`
53
- const binaryName = platform === "windows" ? "synergy.exe" : "synergy"
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}`)
16
+ const candidates = platformPkg.candidatePackageNames()
17
+ const binaryName = platformPkg.packageBinaryName()
18
+
19
+ for (const packageName of candidates) {
20
+ try {
21
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
22
+ const packageDir = path.dirname(packageJsonPath)
23
+ const binaryPath = path.join(packageDir, "bin", binaryName)
24
+
25
+ if (fs.existsSync(binaryPath)) {
26
+ return { binaryPath, binaryName }
27
+ }
28
+ } catch {}
68
29
  }
30
+
31
+ throw new Error(`Could not find a platform package for this system. Tried: ${candidates.join(", ")}`)
69
32
  }
70
33
 
71
34
  function prepareBinDirectory(binaryName) {