fix(release): correct declared type of parallel in PublishOptions - #36877
Open
arpitbharadwaj1 wants to merge 1 commit into
Open
fix(release): correct declared type of parallel in PublishOptions#36877arpitbharadwaj1 wants to merge 1 commit into
parallel in PublishOptions#36877arpitbharadwaj1 wants to merge 1 commit into
Conversation
… to `number` `PublishOptions.parallel` was typed as `string` (inherited from `RunOptions.parallel` via `Partial<RunManyOptions>`), reflecting the raw CLI/yargs value before `readParallelFromArgsAndEnv()` normalizes it to a real number. Programmatic callers of `releasePublish()` (via `createAPI()`) receive the same `PublishOptions` type but never go through that CLI-only normalization. The value flows straight into `getThreadPoolSize()` in task-orchestrator.ts, where `NxArgs.parallel` is declared `number` and is used in `total = discrete + continuous` before being passed to `process.stdout.setMaxListeners(total + ...)`, which throws `ERR_INVALID_ARG_TYPE` when given a string. A type-correct programmatic caller (passing a string, per the old declared type) crashed at runtime; only passing a number (contradicting the declared type) worked. This fixes the type declaration only, using `Omit<Partial<RunManyOptions>, 'parallel'>` to override the inherited CLI-string type with the `number` type programmatic callers actually need. No runtime behavior changes. Closes nrwl#36777
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
👷 Deploy request for nx-dev pending review.Visit the deploys page to approve it
|
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.
Current Behavior
PublishOptions.parallelis typed asstring(inherited fromRunOptions.parallelinshared-options.ts,
via
PublishOptions = NxReleaseArgs & Partial<RunManyOptions> & {...}incommand-object.ts).
That type reflects the raw CLI/yargs value before normalization. On the CLI path, the raw string
is always passed through
readParallelFromArgsAndEnv()(shared-options.ts),
which coerces it to a real
numberbefore it reaches the task orchestrator.However, callers using the programmatic API — e.g. the
releasePublishfunction returned bycreateAPI(...)inpublish.ts,
used directly instead of going through
yargsReleaseCommand— never go through that normalizationstep. If such a caller passes
parallelas a numeric string (matching the declared TS type), itflows straight into
getThreadPoolSize()(task-orchestrator.ts):
getThreadPoolSizeonly coerces the sentinel values'true'/'false'/''/undefined— any otherstring (including a plain numeric string like
"3") passes through unchanged.totalthen reaches:setMaxListeners(n)requiresnto be anumberand throwsERR_INVALID_ARG_TYPEwhen given astring, so a type-correct programmatic caller crashes at runtime.
Expected Behavior
The declared type of
parallelshould match whatever a caller of the programmatic API is actuallyrequired to provide — a real
number, not astring.Fix
PublishOptions.parallelis now typed asnumber, usingOmit<Partial<RunManyOptions>, 'parallel'>to override the inherited CLI-string type (a plain intersection would otherwise collapse to
never).This is a type-only change — no runtime behavior is modified.
Repro
Passing
parallelas an actualnumber(contradicting the old declared type) avoided the crash,confirming the type declaration didn't match the runtime contract for this code path.
Closes #36777