-
-
Notifications
You must be signed in to change notification settings - Fork 23
feat(plugin-completion): support Bun runtimes #556
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
4 commits
Select commit
Hold shift + click to select a range
31bcf27
feat(plugin-completion): support Bun runtimes
ReoHakase ea008a9
docs(plugin-completion): simplify runtime support notes
ReoHakase 36d0b5e
fix(plugin-completion): split runtime detection helper
ReoHakase 0597abc
fix(plugin-completion): keep runtime detector internal
ReoHakase 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
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
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,153 @@ | ||
| /** | ||
| * @author kazuya kawaguchi (a.k.a. kazupon) | ||
| * @license MIT | ||
| */ | ||
|
|
||
| import { describe, expect, test } from 'vitest' | ||
| import { | ||
| detectRuntimeFromGlobals, | ||
| joinExecParts, | ||
| resolveBunExecParts, | ||
| resolveNodeExecParts, | ||
| shellQuote | ||
| } from './utils.ts' | ||
|
|
||
| import type { ProcessLike } from './utils.ts' | ||
|
|
||
| function createProcess(overrides: Partial<ProcessLike> = {}): ProcessLike { | ||
| return { | ||
| argv: ['/usr/local/bin/node', './cli.ts'], | ||
| execArgv: [], | ||
| execPath: '/usr/local/bin/node', | ||
| release: { | ||
| name: 'node' | ||
| }, | ||
| ...overrides | ||
| } | ||
| } | ||
|
|
||
| describe('detectRuntimeFromGlobals', () => { | ||
| test('prioritizes Bun over Deno and Node-compatible process', () => { | ||
| expect( | ||
| detectRuntimeFromGlobals({ | ||
| Bun: {}, | ||
| Deno: {}, | ||
| process: createProcess() | ||
| }) | ||
| ).toBe('bun') | ||
| }) | ||
|
|
||
| test('prioritizes Deno over Node-compatible process', () => { | ||
| expect( | ||
| detectRuntimeFromGlobals({ | ||
| Deno: {}, | ||
| process: createProcess() | ||
| }) | ||
| ).toBe('deno') | ||
| }) | ||
|
|
||
| test('detects Node from process release name', () => { | ||
| expect( | ||
| detectRuntimeFromGlobals({ | ||
| process: createProcess() | ||
| }) | ||
| ).toBe('node') | ||
| }) | ||
| }) | ||
|
|
||
| describe('resolveNodeExecParts', () => { | ||
| test('resolves Node source execution', () => { | ||
| expect(resolveNodeExecParts(createProcess())).toEqual(['/usr/local/bin/node', './cli.ts']) | ||
| }) | ||
| }) | ||
|
|
||
| describe('resolveBunExecParts', () => { | ||
| test('resolves Bun source execution', () => { | ||
| expect( | ||
| resolveBunExecParts( | ||
| createProcess({ | ||
| argv: ['/usr/local/bin/bun', './src/cli.ts'], | ||
| execPath: '/usr/local/bin/bun' | ||
| }) | ||
| ) | ||
| ).toEqual(['/usr/local/bin/bun', './src/cli.ts']) | ||
| }) | ||
|
|
||
| test('resolves Bun source execution with execArgv', () => { | ||
| expect( | ||
| resolveBunExecParts( | ||
| createProcess({ | ||
| argv: ['/usr/local/bin/bun', './src/cli.ts'], | ||
| execArgv: ['--smol'], | ||
| execPath: '/usr/local/bin/bun' | ||
| }) | ||
| ) | ||
| ).toEqual(['/usr/local/bin/bun', '--smol', './src/cli.ts']) | ||
| }) | ||
|
|
||
| test('resolves Bun single binary on Unix', () => { | ||
| expect( | ||
| resolveBunExecParts( | ||
| createProcess({ | ||
| argv: ['/tmp/my-cli'], | ||
| execPath: '/tmp/my-cli' | ||
| }) | ||
| ) | ||
| ).toEqual(['/tmp/my-cli']) | ||
| }) | ||
|
|
||
| test('resolves Bun single binary on Windows', () => { | ||
| expect( | ||
| resolveBunExecParts( | ||
| createProcess({ | ||
| argv: ['C:\\tools\\my-cli.exe'], | ||
| execPath: 'C:\\tools\\my-cli.exe' | ||
| }) | ||
| ) | ||
| ).toEqual(['C:\\tools\\my-cli.exe']) | ||
| }) | ||
|
|
||
| test('resolves Bun Unix virtual compiled entry', () => { | ||
| expect( | ||
| resolveBunExecParts( | ||
| createProcess({ | ||
| argv: ['/usr/local/bin/bun', '/$bunfs/root/main.js'], | ||
| execPath: '/usr/local/bin/bun' | ||
| }) | ||
| ) | ||
| ).toEqual(['/usr/local/bin/bun']) | ||
| }) | ||
|
|
||
| test('resolves Bun Windows virtual compiled entry', () => { | ||
| expect( | ||
| resolveBunExecParts( | ||
| createProcess({ | ||
| argv: ['C:\\tools\\bun.exe', 'B:\\~BUN\\root.js'], | ||
| execPath: 'C:\\tools\\bun.exe' | ||
| }) | ||
| ) | ||
| ).toEqual(['C:\\tools\\bun.exe']) | ||
| }) | ||
| }) | ||
|
|
||
| describe('shellQuote', () => { | ||
| test('escapes spaces and single quotes', () => { | ||
| expect(shellQuote("/tmp/my cli's/bin")).toBe(`'/tmp/my cli'\\''s/bin'`) | ||
| }) | ||
|
|
||
| test('joins quoted exec parts without extra spaces', () => { | ||
| expect(joinExecParts(['/tmp/my cli/bin', "--flag=it's", './cli.ts'])).toBe( | ||
| String.raw`'/tmp/my cli/bin' '--flag=it'\\''s' ./cli.ts` | ||
| ) | ||
| }) | ||
|
|
||
| test('escapes metacharacters for generated double-quoted shell assignment', () => { | ||
| expect( | ||
| joinExecParts(['/tmp/$(touch pwn)/my cli', '--loader=`touch pwn`', './"quoted".ts']) | ||
| ).toBe("'/tmp/\\$(touch pwn)/my cli' '--loader=\\`touch pwn\\`' './\\\"quoted\\\".ts'") | ||
| }) | ||
|
|
||
| test('preserves backslashes through generated double-quoted shell assignment', () => { | ||
| expect(joinExecParts(['C:\\tools\\my cli.exe'])).toBe("'C:\\\\tools\\\\my cli.exe'") | ||
| }) | ||
| }) |
Oops, something went wrong.
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.
I think we can keep the README simpler here.
Instead of adding a dedicated
Runtime Supportsection with Bun-specific implementation details, it may be enough to update the existing warning and theShell Completion Setupprerequisites so users know that Node.js and Bun are supported while Deno is not supported yet.The current Bun-specific text explains internal details such as the compiled-executable detection heuristic, which feels more appropriate for code comments, tests, or the PR description than for end-user documentation.
For the README, I think it is clearer to keep the focus on what users need to do to set up shell completions.
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.
Addressed in ea008a9. I removed the dedicated Runtime Support section and kept the README focused on the warning and setup prerequisites.