Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ build-all:
@for p in $(PLATFORMS); do $(MAKE) build-platform PLATFORM=$$p; done

test: build
SYNC_AGENTS_BIN=bin/sync-agents npx bats test/sync-agents.bats
npx bats test/sync-agents.bats

test-go: test

Expand Down
30 changes: 16 additions & 14 deletions bin/sync-agents.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node
// Launcher: prefer the Go binary shipped via the matching platform package
// (@brickhouse-tech/sync-agents-<os>-<arch>); fall back to the bash script
// at src/sh/sync-agents.sh so the package never bricks on an unsupported
// triple.
// Launcher: resolve the Go binary shipped via the matching platform package
// (@brickhouse-tech/sync-agents-<os>-<arch>). Exits with a clear error on
// unsupported triples rather than silently falling back to a bash script.

const { spawnSync } = require("node:child_process");
const path = require("node:path");
Expand All @@ -17,22 +16,25 @@ function resolveGoBinary() {
const candidate = path.join(path.dirname(pkgJson), "bin", exe);
if (fs.existsSync(candidate)) return candidate;
} catch {
// platform package not installed (npm skipped it via os/cpu mismatch
// or it failed as an optionalDependency); fall through to bash.
// platform package not installed or not available for this triple.
}
return null;
}

function fallbackShellScript() {
return path.join(__dirname, "..", "src", "sh", "sync-agents.sh");
}
const target = resolveGoBinary();

const target = resolveGoBinary() ?? fallbackShellScript();
const isShell = target.endsWith(".sh");
if (!target) {
console.error(
`sync-agents: no pre-built binary for ${process.platform}/${process.arch}.\n` +
`Install via one of the supported channels:\n` +
` go install github.com/brickhouse-tech/sync-agents@latest\n` +
` brew install brickhouse-tech/tap/sync-agents\n` +
` https://github.com/brickhouse-tech/sync-agents/releases`
);
process.exit(1);
}

const result = spawnSync(isShell ? "bash" : target, isShell ? [target, ...process.argv.slice(2)] : process.argv.slice(2), {
stdio: "inherit",
});
const result = spawnSync(target, process.argv.slice(2), { stdio: "inherit" });

if (result.error) {
console.error(`sync-agents: failed to exec ${target}: ${result.error.message}`);
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"sync-agents": "bin/sync-agents.js"
},
"files": [
"bin/sync-agents.js",
"src/**/*"
"bin/sync-agents.js"
],
"optionalDependencies": {
"@brickhouse-tech/sync-agents-darwin-arm64": "0.2.5",
Expand All @@ -38,9 +37,7 @@
"picomatch": ">=4.0.4"
},
"scripts": {
"lint": "shellcheck src/sh/*.sh",
"test": "npx concurrently --names \"sh,go\" -c \"cyan,magenta\" \"npm run test:sh\" \"npm run test:go\"",
"test:sh": "npx bats test/",
"test": "make test",
"test:go": "make test",
"prepare": "make install",
"prepack": "node scripts/sync-optional-deps.js",
Expand All @@ -50,7 +47,6 @@
"@commitlint/cli": "^21",
"@commitlint/config-conventional": "^21",
"commitlint": "21",
"concurrently": "^9.2.1",
"sort-package-json": ">=3"
}
}
Loading
Loading