-
Notifications
You must be signed in to change notification settings - Fork 105
fix(backendjsonrpc): fix command #520
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
358a6e7
fix: unused test
juleswritescode 0c78d7f
fix(backendjsonrpc): fix command
juleswritescode 9c33bfa
Update crates/pgt_hover/tests/hover_integration_tests.rs
juleswritescode dfa9b01
Merge branch 'main' into fix/backend-jsonrpc-binary
juleswritescode 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
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 |
---|---|---|
@@ -1,36 +1,74 @@ | ||
import { execSync } from "node:child_process"; | ||
|
||
/** | ||
* Gets the path of the binary for the current platform | ||
* | ||
* @returns Filesystem path to the binary, or null if no prebuilt distribution exists for the current platform | ||
*/ | ||
export function getCommand(): string | null { | ||
const { platform, arch } = process; | ||
|
||
type PlatformPaths = { | ||
[P in NodeJS.Platform]?: { | ||
[A in NodeJS.Architecture]?: string; | ||
}; | ||
}; | ||
|
||
const PLATFORMS: PlatformPaths = { | ||
win32: { | ||
x64: "@postgrestools/cli-win32-x64/postgrestools.exe", | ||
arm64: "@postgrestools/cli-win32-arm64/postgrestools.exe", | ||
}, | ||
darwin: { | ||
x64: "@postgrestools/cli-darwin-x64/postgrestools", | ||
arm64: "@postgrestools/cli-darwin-arm64/postgrestools", | ||
}, | ||
linux: { | ||
x64: "@postgrestools/cli-linux-x64/postgrestools", | ||
arm64: "@postgrestools/cli-linux-arm64/postgrestools", | ||
}, | ||
}; | ||
|
||
const binPath = PLATFORMS?.[platform]?.[arch]; | ||
if (!binPath) { | ||
return null; | ||
} | ||
|
||
return require.resolve(binPath); | ||
const { platform, arch } = process; | ||
|
||
const PLATFORMS: Partial< | ||
Record< | ||
NodeJS.Platform | "linux-musl", | ||
Partial<Record<NodeJS.Architecture, string>> | ||
> | ||
> = { | ||
win32: { | ||
x64: "@postgrestools/cli-x86_64-windows-msvc/postgrestools.exe", | ||
arm64: "@postgrestools/cli-aarch64-windows-msvc/postgrestools.exe", | ||
}, | ||
darwin: { | ||
x64: "@postgrestools/cli-x86_64-apple-darwin/postgrestools", | ||
arm64: "@postgrestools/cli-aarch64-apple-darwin/postgrestools", | ||
}, | ||
linux: { | ||
x64: "@postgrestools/cli-x86_64-linux-gnu/postgrestools", | ||
arm64: "@postgrestools/cli-aarch64-linux-gnu/postgrestools", | ||
}, | ||
"linux-musl": { | ||
x64: "@postgrestools/cli-x86_64-linux-musl/postgrestools", | ||
// no arm64 build for musl | ||
}, | ||
}; | ||
|
||
function isMusl() { | ||
let stderr = ""; | ||
try { | ||
stderr = execSync("ldd --version", { | ||
stdio: [ | ||
"ignore", // stdin | ||
"pipe", // stdout – glibc systems print here | ||
"pipe", // stderr – musl systems print here | ||
], | ||
}).toString(); | ||
} catch (err: unknown) { | ||
if (hasStdErr(err)) { | ||
stderr = err.stderr; | ||
} | ||
} | ||
if (stderr.indexOf("musl") > -1) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function getPlatform(): NodeJS.Platform | "linux-musl" { | ||
if (platform === "linux") { | ||
return isMusl() ? "linux-musl" : "linux"; | ||
} | ||
|
||
return platform; | ||
} | ||
|
||
const binPath = PLATFORMS?.[getPlatform()]?.[arch]; | ||
if (!binPath) { | ||
return null; | ||
} | ||
|
||
return require.resolve(binPath); | ||
} | ||
|
||
function hasStdErr(err: unknown): err is { stderr: string } { | ||
return !!(err as any)?.stderr; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.