-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
π 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
parseCommandLinedoes not work for the--buildcase in its doc comment, and have the error reported when--buildis encountered. Maybe also exposeisBuildandparseBuildCommand. - 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.