-
Notifications
You must be signed in to change notification settings - Fork 1
Investigating mdsmith bundling in VS Code extension #247
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 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ca61bc0
Bundle mdsmith binary from npm into VS Code extension
Claude af51d07
Fix comments to reflect single cross-platform extension install
Claude 05b8198
Refactor binary resolution to be testable without mocking globals
Claude ba928f0
Implement proper binary bundling via build-time copy to dist/bin/
Claude 1646960
Update documentation to reflect build-time binary bundling
Claude 3054e34
Fix CI linting issues in VS Code extension README
Claude 41fd6de
Update docs and comments to reflect platform bundling limitation
Claude 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
Some comments aren't visible on the classic Files Changed page.
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
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,72 @@ | ||
| // Unit tests for binary resolution logic. | ||
| // The extension bundles cross-platform mdsmith binaries into dist/bin/ | ||
| // during the build step; these tests verify the resolution logic and | ||
| // fallback behavior. | ||
|
|
||
| import { describe, expect, mock, test } from "bun:test"; | ||
| import { join } from "node:path"; | ||
| import { resolveBinary } from "./binary"; | ||
|
|
||
| describe("resolveBinary", () => { | ||
| test("returns custom path unchanged when user specifies non-default", () => { | ||
| const fileExists = mock(() => false); | ||
| const result = resolveBinary("/custom/path/to/mdsmith", "/ext", "linux", "x64", fileExists); | ||
| expect(result).toBe("/custom/path/to/mdsmith"); | ||
| // Should not even attempt to check for bundled binary | ||
| expect(fileExists).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test("returns bundled binary when default path and bundled exists (Linux x64)", () => { | ||
| const extensionPath = "/ext"; | ||
| const bundledPath = join(extensionPath, "dist", "bin", "linux-x64-mdsmith"); | ||
|
|
||
| // Mock: bundled binary exists | ||
| const fileExists = mock((path) => path === bundledPath); | ||
|
Claude marked this conversation as resolved.
|
||
|
|
||
| const result = resolveBinary("mdsmith", extensionPath, "linux", "x64", fileExists); | ||
| expect(result).toBe(bundledPath); | ||
| expect(fileExists).toHaveBeenCalledWith(bundledPath); | ||
| }); | ||
|
|
||
| test("returns bundled binary when default path and bundled exists (macOS arm64)", () => { | ||
| const extensionPath = "/ext"; | ||
| const bundledPath = join(extensionPath, "dist", "bin", "darwin-arm64-mdsmith"); | ||
|
|
||
| // Mock: bundled binary exists | ||
| const fileExists = mock((path) => path === bundledPath); | ||
|
|
||
|
Claude marked this conversation as resolved.
|
||
| const result = resolveBinary("mdsmith", extensionPath, "darwin", "arm64", fileExists); | ||
| expect(result).toBe(bundledPath); | ||
| expect(fileExists).toHaveBeenCalledWith(bundledPath); | ||
| }); | ||
|
|
||
| test("returns bundled binary when default path and bundled exists (Windows x64)", () => { | ||
| const extensionPath = "/ext"; | ||
| const bundledPath = join(extensionPath, "dist", "bin", "win32-x64-mdsmith.exe"); | ||
|
|
||
| // Mock: bundled binary exists | ||
| const fileExists = mock((path) => path === bundledPath); | ||
|
|
||
| const result = resolveBinary("mdsmith", extensionPath, "win32", "x64", fileExists); | ||
| expect(result).toBe(bundledPath); | ||
| expect(fileExists).toHaveBeenCalledWith(bundledPath); | ||
| }); | ||
|
|
||
| test("falls back to default path when bundled binary does not exist", () => { | ||
| // Mock: no bundled binary | ||
| const fileExists = mock(() => false); | ||
|
|
||
| const result = resolveBinary("mdsmith", "/ext", "linux", "x64", fileExists); | ||
| expect(result).toBe("mdsmith"); | ||
| // Should have checked for bundled binary | ||
| expect(fileExists).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test("returns custom bare name unchanged", () => { | ||
| const fileExists = mock(() => false); | ||
| const result = resolveBinary("my-mdsmith-fork", "/ext", "linux", "x64", fileExists); | ||
| expect(result).toBe("my-mdsmith-fork"); | ||
| // Should not check for bundled binary when not the default | ||
| expect(fileExists).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
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,65 @@ | ||
| // Binary resolution logic for the mdsmith extension. | ||
| // The extension bundles cross-platform mdsmith binaries from npm packages | ||
| // into dist/bin/ during the build step. This module resolves the correct | ||
| // platform binary when the user leaves the default "mdsmith" path, falling | ||
| // back to PATH if bundling failed or binaries are unavailable. | ||
|
|
||
| import { existsSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
|
|
||
| // resolveBinary returns the path to the mdsmith binary. When the | ||
| // configured path is the bare string "mdsmith", it first checks for | ||
| // bundled binaries in dist/bin/ (copied there by build.ts from the | ||
| // @mdsmith/* npm packages). Platform-specific binaries are named like | ||
| // "linux-x64-mdsmith", "win32-x64-mdsmith.exe", etc. If the bundled | ||
| // binary exists, return its absolute path. Otherwise return the | ||
| // configured path unchanged so the LanguageClient resolves it against | ||
| // PATH (fallback for dev builds or when optional deps failed to install). | ||
| // | ||
| // Cross-platform bundling: The build script copies binaries from ALL | ||
| // @mdsmith/* platform packages (linux-x64, darwin-arm64, win32-x64, etc.) | ||
| // into dist/bin/. This works even with `vsce package --no-dependencies` | ||
| // because dist/ is included in the .vsix. At runtime, this function | ||
| // selects the binary matching the user's OS+arch. | ||
|
Claude marked this conversation as resolved.
Outdated
Claude marked this conversation as resolved.
Outdated
|
||
| // | ||
| // The extensionPath should be the vscode.ExtensionContext.extensionPath | ||
| // (the directory containing package.json and dist/). | ||
| // | ||
| // The optional platform, arch, and fileExists parameters are for testing; | ||
| // in production they default to process.platform, process.arch, and fs.existsSync. | ||
| export function resolveBinary( | ||
| configuredPath: string, | ||
| extensionPath: string, | ||
| platform: string = process.platform, | ||
| arch: string = process.arch, | ||
| fileExists: (path: string) => boolean = existsSync | ||
| ): string { | ||
| // If the user specified a custom path (not the bare "mdsmith"), | ||
| // honor it exactly — they know what they want. | ||
| if (configuredPath !== "mdsmith") { | ||
| return configuredPath; | ||
| } | ||
|
|
||
| // The user left the default "mdsmith". Check for bundled binaries | ||
| // in dist/bin/. The build script copies them there with names like | ||
| // "linux-x64-mdsmith", "win32-x64-mdsmith.exe". | ||
|
|
||
| // Map Node's process.platform and process.arch to our package names | ||
| const platformArch = `${platform}-${arch}`; | ||
| const binaryName = platform === "win32" ? "mdsmith.exe" : "mdsmith"; | ||
| const bundledBinary = join( | ||
| extensionPath, | ||
| "dist", | ||
| "bin", | ||
| `${platformArch}-${binaryName}` | ||
| ); | ||
|
|
||
| if (fileExists(bundledBinary)) { | ||
| return bundledBinary; | ||
| } | ||
|
|
||
| // The bundled binary does not exist (build step didn't run, or | ||
| // optional dependencies weren't installed). Fall back to the bare | ||
| // "mdsmith" string so the LanguageClient resolves it against PATH. | ||
| return configuredPath; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.