-
Notifications
You must be signed in to change notification settings - Fork 5
watch bt releases on npm, update local bt version on update #2067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Cedric / ViaDézo1er (viadezo1er)
wants to merge
2
commits into
main
Choose a base branch
from
cedric/publish-bt-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "braintrust": minor | ||
| --- | ||
|
|
||
| feat: ship the `bt` CLI with the SDK. Installing `braintrust` now exposes a `bt` command in `node_modules/.bin` that runs the prebuilt native binary for your platform (delivered via `@braintrust/bt-*` optional dependencies). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env node | ||
| "use strict"; | ||
|
|
||
| // Launcher for the `bt` CLI. The native binary ships in a per-platform | ||
| // package (`@braintrust/bt-<platform>`) listed as an optionalDependency of | ||
| // `braintrust`; npm/pnpm install only the one matching the host. This script | ||
| // resolves that binary and forwards argv + exit code. | ||
|
|
||
| const { spawnSync } = require("node:child_process"); | ||
|
|
||
| const PLATFORM_PACKAGES = { | ||
| "darwin-arm64": "@braintrust/bt-darwin-arm64", | ||
| "darwin-x64": "@braintrust/bt-darwin-x64", | ||
| "linux-arm64": "@braintrust/bt-linux-arm64", | ||
| "linux-x64-glibc": "@braintrust/bt-linux-x64", | ||
| "linux-x64-musl": "@braintrust/bt-linux-x64-musl", | ||
| "win32-arm64": "@braintrust/bt-win32-arm64", | ||
| "win32-x64": "@braintrust/bt-win32-x64", | ||
| }; | ||
|
|
||
| function detectLibc() { | ||
| if (process.platform !== "linux") return null; | ||
| try { | ||
| const report = process.report && process.report.getReport(); | ||
| if (report && report.header && report.header.glibcVersionRuntime) { | ||
| return "glibc"; | ||
| } | ||
| return "musl"; | ||
| } catch { | ||
| return "glibc"; | ||
| } | ||
| } | ||
|
|
||
| function platformKey() { | ||
| const { platform, arch } = process; | ||
| if (platform === "linux" && arch === "x64") { | ||
| return `linux-x64-${detectLibc()}`; | ||
| } | ||
| return `${platform}-${arch}`; | ||
| } | ||
|
|
||
| function binaryName() { | ||
| return process.platform === "win32" ? "bt.exe" : "bt"; | ||
| } | ||
|
|
||
| function resolveBinary() { | ||
| const pkg = PLATFORM_PACKAGES[platformKey()]; | ||
| if (!pkg) { | ||
| throw new Error( | ||
| `No prebuilt bt binary for ${process.platform}-${process.arch}. ` + | ||
| `Supported platforms: ${Object.keys(PLATFORM_PACKAGES).join(", ")}.`, | ||
| ); | ||
| } | ||
| try { | ||
| return require.resolve(`${pkg}/bin/${binaryName()}`); | ||
| } catch (err) { | ||
| throw new Error( | ||
| `Failed to locate the bt binary from "${pkg}". It is an optional ` + | ||
| `dependency of "braintrust"; reinstall your dependencies to fetch ` + | ||
| `it (${err.message}).`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| const result = spawnSync(resolveBinary(), process.argv.slice(2), { | ||
| stdio: "inherit", | ||
| windowsHide: true, | ||
| }); | ||
| if (result.error) throw result.error; | ||
| if (result.signal) process.kill(process.pid, result.signal); | ||
| process.exit(result.status ?? 1); | ||
| } catch (err) { | ||
| console.error(`bt: ${err.message}`); | ||
| process.exit(1); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be a .cjs file I think. In general, let's follow https://github.com/getsentry/sentry-cli/blob/master/scripts/install.js or https://blog.sentry.io/publishing-binaries-on-npm/ to the tee. The logs are very intentional there and we should log similar things to ensure people are not confused when installing the package and things fail.
I also have an example repo on how this should look like: https://github.com/lforst/npm-binary-example