-
Notifications
You must be signed in to change notification settings - Fork 106
chore: dual publish to npm #543
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 all commits
Commits
Show all changes
5 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
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
32 changes: 32 additions & 0 deletions
32
packages/@postgres-language-server/backend-jsonrpc/package.json
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,32 @@ | ||
| { | ||
| "name": "@postgres-language-server/backend-jsonrpc", | ||
| "version": "<placeholder>", | ||
| "main": "dist/index.js", | ||
| "scripts": { | ||
| "test": "bun test", | ||
| "test:ci": "bun build && bun test", | ||
| "build": "bun build ./src/index.ts --outdir ./dist --target node" | ||
| }, | ||
| "files": ["dist/", "README.md"], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/supabase-community/postgres-language-server.git", | ||
| "directory": "packages/@postgres-language-server/backend-jsonrpc" | ||
| }, | ||
| "author": "Supabase Community", | ||
| "bugs": "ttps://github.com/supabase-community/postgres-language-server/issues", | ||
| "description": "Bindings to the JSON-RPC Workspace API of the Postgres Language Tools daemon", | ||
| "keywords": ["TypeScript", "Postgres"], | ||
| "license": "MIT", | ||
| "publishConfig": { | ||
| "provenance": true | ||
| }, | ||
| "optionalDependencies": { | ||
| "@postgres-language-server/cli-win32-x64": "<placeholder>", | ||
| "@postgres-language-server/cli-win32-arm64": "<placeholder>", | ||
| "@postgres-language-server/cli-darwin-x64": "<placeholder>", | ||
| "@postgres-language-server/cli-darwin-arm64": "<placeholder>", | ||
| "@postgres-language-server/cli-linux-x64": "<placeholder>", | ||
| "@postgres-language-server/cli-linux-arm64": "<placeholder>" | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
packages/@postgres-language-server/backend-jsonrpc/src/command.ts
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,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; | ||
|
|
||
| const PLATFORMS: Partial< | ||
| Record< | ||
| NodeJS.Platform | "linux-musl", | ||
| Partial<Record<NodeJS.Architecture, string>> | ||
| > | ||
| > = { | ||
| win32: { | ||
| x64: "@postgres-language-server/cli-x86_64-windows-msvc/postgres-language-server.exe", | ||
| arm64: "@postgres-language-server/cli-aarch64-windows-msvc/postgres-language-server.exe", | ||
| }, | ||
| darwin: { | ||
| x64: "@postgres-language-server/cli-x86_64-apple-darwin/postgres-language-server", | ||
| arm64: "@postgres-language-server/cli-aarch64-apple-darwin/postgres-language-server", | ||
| }, | ||
| linux: { | ||
| x64: "@postgres-language-server/cli-x86_64-linux-gnu/postgres-language-server", | ||
| arm64: "@postgres-language-server/cli-aarch64-linux-gnu/postgres-language-server", | ||
| }, | ||
| "linux-musl": { | ||
| x64: "@postgres-language-server/cli-x86_64-linux-musl/postgres-language-server", | ||
| // 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; | ||
| } |
46 changes: 46 additions & 0 deletions
46
packages/@postgres-language-server/backend-jsonrpc/src/index.ts
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,46 @@ | ||
| import { getCommand } from "./command"; | ||
| import { createSocket } from "./socket"; | ||
| import { Transport } from "./transport"; | ||
| import { type Workspace, createWorkspace as wrapTransport } from "./workspace"; | ||
|
|
||
| /** | ||
| * Create an instance of the Workspace client connected to a remote daemon | ||
| * instance through the JSON-RPC protocol | ||
| * | ||
| * @returns A Workspace client, or null if the underlying platform is not supported | ||
| */ | ||
| export async function createWorkspace(): Promise<Workspace | null> { | ||
| const command = getCommand(); | ||
| if (!command) { | ||
| return null; | ||
| } | ||
|
|
||
| return createWorkspaceWithBinary(command); | ||
| } | ||
|
|
||
| /** | ||
| * Create an instance of the Workspace client connected to a remote daemon | ||
| * instance through the JSON-RPC protocol, using the provided command to spawn | ||
| * the daemon if necessary | ||
| * | ||
| * @param command Path to the binary | ||
| * @returns A Workspace client, or null if the underlying platform is not supported | ||
| */ | ||
| export async function createWorkspaceWithBinary( | ||
| command: string, | ||
| ): Promise<Workspace> { | ||
| const socket = await createSocket(command); | ||
| const transport = new Transport(socket); | ||
|
|
||
| await transport.request("initialize", { | ||
| capabilities: {}, | ||
| client_info: { | ||
| name: "@postgres-language-server/backend-jsonrpc", | ||
| version: "0.0.0", | ||
| }, | ||
| }); | ||
|
|
||
| return wrapTransport(transport); | ||
| } | ||
|
|
||
| export * from "./workspace"; |
47 changes: 47 additions & 0 deletions
47
packages/@postgres-language-server/backend-jsonrpc/src/socket.ts
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,47 @@ | ||
| import { spawn } from "node:child_process"; | ||
| import { type Socket, connect } from "node:net"; | ||
|
|
||
| function getSocket(command: string): Promise<string> { | ||
| return new Promise((resolve, reject) => { | ||
| const process = spawn(command, ["__print_socket"], { | ||
| stdio: "pipe", | ||
| }); | ||
|
|
||
| process.on("error", reject); | ||
|
|
||
| let pipeName = ""; | ||
| process.stdout.on("data", (data) => { | ||
| pipeName += data.toString("utf-8"); | ||
| }); | ||
|
|
||
| process.on("exit", (code) => { | ||
| if (code === 0) { | ||
| resolve(pipeName.trimEnd()); | ||
| } else { | ||
| reject( | ||
| new Error( | ||
| `Command '${command} __print_socket' exited with code ${code}`, | ||
| ), | ||
| ); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Ensure the daemon server is running and create a Socket connected to the RPC channel | ||
| * | ||
| * @param command Path to the daemon binary | ||
| * @returns Socket instance connected to the daemon | ||
| */ | ||
| export async function createSocket(command: string): Promise<Socket> { | ||
| const path = await getSocket(command); | ||
| const socket = connect(path); | ||
|
|
||
| await new Promise((resolve, reject) => { | ||
| socket.once("error", reject); | ||
| socket.once("ready", resolve); | ||
| }); | ||
|
|
||
| return socket; | ||
| } |
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.