microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
99.06k stars 12.29k forks source link

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

Open CraigMacomber opened 3 days ago

CraigMacomber commented 3 days ago

πŸ”Ž Search Terms

parseCommandLine build

πŸ•— Version & Regression Information

⏯ 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:

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.

jakebailey commented 3 days ago

This isn't wholly unexpected as parseCommandLine returns ParsedCommandLine which is explicitly just one tsconfig, not for use with build mode. Exposing something to be able to parse the whole thing doesn't seem too unreasonable to me. @sheetalkamat what do you think?