Skip to content

parseCommandLine fails with --build and --forceΒ #59095

@CraigMacomber

Description

@CraigMacomber

πŸ”Ž Search Terms

parseCommandLine build

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried (5.1 and 5.4)

⏯ Playground Link

No response

πŸ’» Code

When using the typescript package programatically, the function parseCommandLine is exported. Implementation: https://github.com/microsoft/TypeScript/blob/main/src/compiler/commandLineParser.ts#L1999

As far as I can tell, this function is public but undocumented. It seems like you should be able to give it command line arguments and have it parse them, and it usually works. However, if you give it --build and --forceit errors with"Compiler option '--force' may only be used with '--build'."` which is confusing since it is used with --build.

πŸ™ Actual behavior

"Compiler option '--force' may only be used with '--build'." which is confusing since it is used with --build.

πŸ™‚ Expected behavior

One of:

  • Document that parseCommandLine does not work for the --build case in its doc comment, and have the error reported when --build is encountered. Maybe also expose isBuild and parseBuildCommand.
  • Support --build, and only emit "Compiler option '--force' may only be used with '--build'." when --build is not provided.

Additional information about the issue

I believe when TypeScript is parsing its command line inputs it does not use this function for the "build" case, based on https://github.com/microsoft/TypeScript/blob/main/src/compiler/executeCommandLine.ts#L752, which is how it works when running tsc, but not in parseCommandLine. In that case it uses parseBuildCommand, which is @internal.

Metadata

Metadata

Assignees

Labels

APIRelates to the public API for TypeScriptFix AvailableA PR has been opened for this issueGood First IssueWell scoped, documented and has the green lightIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions