Skip to content

fix: recover no-* boolean aliases swallowed by parseArgs allowNegative (#1349) - #1381

Open
kuntal1461 wants to merge 1 commit into
apify:masterfrom
kuntal1461:fix/1349-no-optional-silently-ignored
Open

fix: recover no-* boolean aliases swallowed by parseArgs allowNegative (#1349)#1381
kuntal1461 wants to merge 1 commit into
apify:masterfrom
kuntal1461:fix/1349-no-optional-silently-ignored

Conversation

@kuntal1461

@kuntal1461 kuntal1461 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Problem

apify create --no-optional was silently ignored — optional deps always installed regardless of the flag.

Root cause: Node.js parseArgs with allowNegative: true intercepts any --no-X token before consulting the options table. For --no-optional, it strips the prefix and stores rawFlags['optional'] = false (even though optional is not a registered option). The registration of no-optional as a direct boolean option passes the strict: true validity check, but the value never lands under that key. _parseFlags then checks allMatchers = ['omit-optional-deps', 'no-optional'] against rawFlags, finds neither key, and leaves omitOptionalDeps undefined.

Empirically confirmed with Node.js 24.19.0:

parseArgs({ allowNegative: true, strict: true,
  options: { 'omit-optional-deps': { type: 'boolean', multiple: true },
             'no-optional':         { type: 'boolean', multiple: true } },
  args: ['--no-optional'] })
// rawFlags: { "optional": false }  <-- wrong key; 'no-optional' never set

Fix

Single insertion in _parseFlags (src/lib/command-framework/apify-command.ts): after the allMatchers lookup finds nothing, scan each no-* alias and check whether its stripped positive name is present in rawFlags with value false. If so, set rawFlag = true so the rest of the boolean-parsing path proceeds normally.

  • flags.ts is unchanged -- the no-optional registration must stay so strict: true does not throw when --no-optional is passed.
  • create.ts is unchanged -- aliases: ['no-optional'] is now correctly recovered.
  • The fix is general: any boolean flag that declares a no-* alias gets the same treatment automatically.

Testing

  • All 20 create-command tests pass (pnpm exec vitest run test/local/commands/create.test.ts).
  • Full local suite passes except 2 pre-existing Python path failures unrelated to this change.
  • Build clean (pnpm run build), lint+format pass (enforced by pre-commit hook).

Fixes #1349

Node.js parseArgs with allowNegative:true intercepts --no-X before the
options table lookup, storing rawFlags['X'] = false instead of
rawFlags['no-X'] = true. This caused apify create --no-optional to be
silently ignored: _parseFlags checked for 'no-optional' in rawFlags, found
nothing, and left omitOptionalDeps undefined, so optional deps always
installed regardless of the flag.

Fix: after the allMatchers lookup, scan any no-* aliases and check whether
their stripped positive name is stored as false in rawFlags. If found, set
rawFlag = true so the rest of the boolean parsing path proceeds normally.

Fixes apify#1349
@kuntal1461
kuntal1461 force-pushed the fix/1349-no-optional-silently-ignored branch from b6281ea to 52d4d4a Compare September 2, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apify create --no-optional is silently ignored

2 participants