Description
Since IDEs like VS Code use tsconfig.json
to figure out how to parse a project, it makes sense for all the other build tools (gulp, broccoli, webpack, etc) to pull the tsc config from tsconfig.json
as well, instead of having their own custom way to configure tsc.
In order for this to be seamless, Typescript needs to provide a way to parse tsconfig.json to CompilerOptions
object. tsc
already does this internally, but all of the apis it uses are private.
I've put together my own converter for Angular/broccoli-typescript, but it will get stale with the next version of typescript until I update my option mappings. See ts-config-converter.ts
added in angular/angular#4779
I believe that this task is so common that it should be part of typescripts public api.
cc: @alexeagle
Activity
[-]Provide an api to convert tsconfig.json to CompilerOptions[/-][+]Provide an API to convert tsconfig.json to CompilerOptions[/+]mhegazy commentedon Oct 16, 2015
here you go: https://github.com/Microsoft/TypeScript/blob/master/lib/typescript.d.ts#L1536-L1555
use
ts.parseConfigFile
to parse the text. if you want to parse the JSON the same way as the compiler does as well (currently using JSON.parse, but possibly in the future do something more interesting allowing comments for instance) usets.parseConfigFileText
IgorMinar commentedon Oct 16, 2015
Awesome. That's what I need.
Is the filename option significant? We also have a use case where the configuration is an object already in the tsconfig format, so I would just serialize it and pass it in as text with bogus filename. Will there be any problems with that?
mhegazy commentedon Oct 16, 2015
in parseConfigFileTextToJson the name is used only for the error message.
https://github.com/Microsoft/TypeScript/blob/master/src/compiler/commandLineParser.ts#L401
in parseJsonConfigFileContent basePath is expected to be the location of the tscongfig, as all files path in the options are considered relative to the file location.
https://github.com/Microsoft/TypeScript/blob/master/src/compiler/commandLineParser.ts#L416
IgorMinar commentedon Oct 17, 2015
I tried using
parseJsonConfigFileContent
but it feels too heavyweight since it requires me to implementParseConfigHost
.All I want is:
Could that be a thing?
vladima commentedon Oct 17, 2015
I don't see why not, we already have this code as nested function of
parseJsonConfigFileContent
.Also as a temporary workaround for now you can use something like this
IgorMinar commentedon Oct 17, 2015
That worked! It's a bit awkward, but it works. Thanks Vladimir.
On Sat, Oct 17, 2015 at 4:49 PM Vladimir Matveev notifications@github.com
wrote:
vladima commentedon Oct 19, 2015
@IgorMinar
convertCompilerOptionsFromJson
will be available in todays nightly buildwycats commentedon Mar 20, 2016
@mhegazy @vladima This is getting pretty frustrating; it just broke again.
Here's what we had to do to get it working on
typescript@next
: tildeio/broccoli-typescript-compiler@ff874d9?w=1Can you recommend a stable API we can use?
wycats commentedon Mar 20, 2016
See also tildeio/broccoli-typescript-compiler#7.
We're very eager to get on a supported, stable path here, but can't seem to find one.
vladima commentedon Mar 20, 2016
@wycats apologies, this breaking change was not intentional. I'll revert
convertCompilerOptionsFromJson
to the shape it used to be in 1.8wycats commentedon Mar 21, 2016
@vladima is there any way we can get the tests of this functionality to be considered regressions, so people don't just change them at the same time as the functionality?
Maybe a note in the tests?
vladima commentedon Mar 21, 2016
I'll add tests on our side to make sure that public surface of the API is not changed in an unexpected way
REACT_APP_NODE_PATH
instead ofNODE_PATH
wmonk/create-react-app-typescript#178MartinJohns commentedon Dec 10, 2017
@vladima Unfortunately the
host
can't be set toundefined
anymore, as the type is notts.ParseConfigHost | undefined
. I don't see a way to use this function anymore.alexeagle commentedon Dec 12, 2017