fix: --completion outputs wrong script name when run via Bun#1826
Open
Paul-Goulpie wants to merge 2 commits intofirecow:masterfrom
Open
fix: --completion outputs wrong script name when run via Bun#1826Paul-Goulpie wants to merge 2 commits intofirecow:masterfrom
Paul-Goulpie wants to merge 2 commits intofirecow:masterfrom
Conversation
- yargs derives $0 from process.argv[0] which resolves to "bun"
when running via `bun run src/index.ts`
- call .scriptName("gitlab-ci-local") on the yargs instance
before showCompletionScript() to override $0
- completion script now correctly references gitlab-ci-local
in markers, function name, and complete directive
- Add test case that runs the CLI as a subprocess via execSync to capture console.log output, which Bun implements natively and cannot be intercepted with vi.spyOn - Assert completion output references gitlab-ci-local, not bun - Register test in the forks pool (isolated process per file) since it spawns subprocesses - Exclude from the threads pool to prevent worker init failure
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix: --completion outputs wrong script name when run via Bun
Problem
Running
gitlab-ci-local --completiongenerated a bash completionscript referencing
buninstead ofgitlab-ci-local:###-begin-bun-completions-###
...
mapfile -t type_list < <(bun --get-yargs-completions "${args[@]}")
...
complete -o bashdefault -o default -F _bun_yargs_completions bun
###-end-bun-completions-###
When run via
bun run src/index.ts, yargs derives$0fromprocess.argv[0], which resolves to thebunbinary instead ofthe command name. The
handler.tscompletion branch was creatinga fresh yargs instance without overriding this value.
Fix
Call
.scriptName("gitlab-ci-local")on the yargs instance beforeshowCompletionScript()to explicitly set$0.Test
Added a subprocess-based regression test.
vi.spyOn(console, "log")cannot intercept the output because Bun implements
console.lognatively — the test runs the CLI via
execSyncand asserts thegenerated script references
gitlab-ci-localthroughout.The test is registered in the
forksvitest pool and excluded fromthreadsto avoid worker initialisation failures.Summary by cubic
Fixes --completion so the generated bash script uses
gitlab-ci-localinstead ofbunwhen run viabun. Ensures the markers, function name, and complete directive reference the correct command.yargs.scriptName("gitlab-ci-local") before.showCompletionScript()to override$0(whichyargsderived fromprocess.argv[0]asbun).execSyncand asserts all references usegitlab-ci-local; test runs in theforkspool and is excluded fromthreads.Written for commit 1eb7b49. Summary will update on new commits.