-
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 3 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,60 @@ | ||
| // Unit tests for binary resolution logic. | ||
| // The extension bundles a cross-platform mdsmith binary that works on | ||
| // all platforms from a single .vsix install; these tests verify the | ||
| // fallback behavior when bundling fails. | ||
|
|
||
| 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", 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 (Unix)", () => { | ||
| const extensionPath = "/ext"; | ||
| const bundledPath = join(extensionPath, "node_modules", ".bin", "mdsmith"); | ||
|
|
||
| // Mock: bundled binary exists | ||
| const fileExists = mock((path) => path === bundledPath); | ||
|
Claude marked this conversation as resolved.
|
||
|
|
||
| const result = resolveBinary("mdsmith", extensionPath, "linux", fileExists); | ||
| expect(result).toBe(bundledPath); | ||
| expect(fileExists).toHaveBeenCalledWith(bundledPath); | ||
| }); | ||
|
|
||
| test("returns bundled binary when default path and bundled exists (Windows)", () => { | ||
| const extensionPath = "/ext"; | ||
| const bundledPath = join(extensionPath, "node_modules", ".bin", "mdsmith.cmd"); | ||
|
|
||
| // Mock: bundled binary exists | ||
| const fileExists = mock((path) => path === bundledPath); | ||
|
|
||
|
Claude marked this conversation as resolved.
|
||
| const result = resolveBinary("mdsmith", extensionPath, "win32", 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", 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", 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,61 @@ | ||
| // Binary resolution logic for the mdsmith extension. | ||
| // The extension bundles a cross-platform mdsmith binary from npm that | ||
| // works on all supported platforms (Linux, macOS, Windows) via a single | ||
| // .vsix install. This module resolves the bundled binary when the user | ||
| // leaves the default "mdsmith" path, falling back to PATH if bundling | ||
| // failed. | ||
|
Claude marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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 | ||
| // the bundled binary at node_modules/.bin/mdsmith (Unix) or | ||
| // node_modules/.bin/mdsmith.cmd (Windows). The @mdsmith/cli npm package | ||
| // ships with platform-specific binaries as optional dependencies, so | ||
| // a single extension install works on all platforms. If the bundled | ||
| // binary exists, return its absolute path. Otherwise return the | ||
| // configured path unchanged so the LanguageClient resolves it against | ||
| // PATH (fallback for proxy/offline install failures). | ||
| // | ||
| // The extensionPath should be the vscode.ExtensionContext.extensionPath | ||
| // (the directory containing package.json and node_modules/). | ||
| // | ||
| // The optional platform and fileExists parameters are for testing; in | ||
| // production they default to process.platform and fs.existsSync. | ||
| export function resolveBinary( | ||
| configuredPath: string, | ||
| extensionPath: string, | ||
| platform: string = process.platform, | ||
| 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 the bundled binary | ||
| // from @mdsmith/cli. The npm package ships with platform-specific | ||
| // binaries (linux-x64, darwin-arm64, win32-x64, etc.) as optional | ||
| // dependencies; npm installs ALL of them during packaging (regardless | ||
| // of build platform), so a single .vsix works on Linux, macOS, and | ||
| // Windows. The bin wrapper (mdsmith.js) selects the correct binary | ||
| // at runtime. The wrapper lives at node_modules/.bin/mdsmith (Unix) | ||
| // or node_modules/.bin/mdsmith.cmd (Windows). | ||
|
Claude marked this conversation as resolved.
Outdated
|
||
| const binDir = join(extensionPath, "node_modules", ".bin"); | ||
| const unixBin = join(binDir, "mdsmith"); | ||
| const winBin = join(binDir, "mdsmith.cmd"); | ||
|
|
||
| // Prefer the platform-appropriate wrapper if it exists. | ||
| const candidate = platform === "win32" ? winBin : unixBin; | ||
| if (fileExists(candidate)) { | ||
| return candidate; | ||
| } | ||
|
|
||
| // The bundled binary does not exist (optional dependency install | ||
| // failed, or this is a dev build without npm install). Fall back | ||
| // to the bare "mdsmith" string so the LanguageClient resolves it | ||
| // against the shell PATH (same as before bundling). | ||
| 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.