Repository navigation
fix(parse): leave an omitted array option absent - #177
Merged
Merged
Conversation
setByType ran over every array-typed option on each parsed key, so an option declared with `type: []` but never passed was wrapped as `[undefined]` as soon as any unrelated option appeared in argv. Only transform keys that are actually present on the options object. Closes cacjs#175
sxzz
approved these changes
Oct 11, 2026
1 of 3 tasks
1 task
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.
Closes #175.
Problem
An option declared with
type: []but never passed on the command line ends up as[undefined]as soon as any unrelated option appears in argv:Consumers that check
if (options.externals)or spread the options into a config object get a truthy one-element array ofundefinedinstead of nothing.Cause
In
CAC#mri,setByType(options, transforms)is called once per parsed key.setByTypethen loops over all array-typed transforms, not just the key that was actually set:With no parsed keys at all the loop body never runs, which is why the plain
node bincase looks fine. Passing--typegives the outer loop one iteration,setByTyperuns, and[undefined].flat()is written to the untouchedexternalskey.Fix
Only transform keys that are actually present on the options object:
key in obj(rather than a value check) keeps an explicitly-set falsy orundefinedvalue transformable, and still lets a declareddefaultbe wrapped into an array as before.Test
Added a regression test in
tests/index.test.tscovering the three states: option omitted entirely, option omitted while an unrelated option is passed, and option actually passed. It fails onmain([undefined]vs absent) and passes with the fix.Validation:
pnpm vitest run→ 18/18 passing,pnpm lintandpnpm typecheckclean.