Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] Let typescript load the config file, instead of tsconfig package #245

Closed
DorianGrey opened this issue Jun 13, 2017 · 5 comments

Comments

@DorianGrey
Copy link
Contributor

Hi there,

I've just switched some of my playground projects to use ts-jest instead of my own typescript preprocessor.
While I really appreciate to have less code to maintain, I've recognized that ts-jest uses a quite complex way to load the configuration file built upon the tsconfig package.

And I'm wondering why. Typescript itself offers a readConfigFile function:

import * as tsc from "typescript";

const result = tsc.readConfigFile("tsconfig.json", tsc.sys.readFile);

In this example, result.config would contain the config in case everything worked fine, or some diagnostics in result.error in case it failed to read it.
It would be especially useful in terms of the extends property, which is handled automatically (and its handling in the TS source looks by far more complicated than the one from ts-jest).

Any thoughts?

@kulshekhar
Copy link
Owner

I can't recall all details of why it is read in the way it is, currently, but this is definitely worth a look

@GeeWee
Copy link
Collaborator

GeeWee commented Jun 14, 2017

using tsc.readconfigfile for me only results in a parsing of the actual JSON - I'm unsure how to translate that to an actual compilerOptions object.

Would love a PR.

@DorianGrey
Copy link
Contributor Author

The result of tsc.readConfigFile is an object with either a config field containing the parsed file content, or an error field indicating that something went horribly wrong.
In case of the config object, that one would contain the compilerOptions field as defined in the config file, possible merged from multiple ones in case the reader had to follow the extends directive at least one time.

I'll see if I can get some spare time tomorrow, and I'll take care of a PR.

@GeeWee
Copy link
Collaborator

GeeWee commented Jun 14, 2017

Strange. In my attempts I simply got an object with an "extends" key.
That'd be awesome

@DorianGrey
Copy link
Contributor Author

DorianGrey commented Jun 14, 2017

Hm... yes, things seem to be a bit more complicated, though I'm a bit surprised - I recently used the same for a PR in another project, and things worked fine. I'll dig a little bit deeper into this...

€dit: Ok, after taking a closer look, I can confirm that tsc.readConfigFile does not follow the extends directive. It's a bit surprising to me, since I've seen that working without a problem in several projects, not only mine - otherwise, I wouldn't have suggest to go this way.

However, after checking out how TypeScript's cli is picking up the config, it seems to involve the usage of tsc.parseJsonConfigFileContent as well. Due to the source, this one recursively follows the extends entry, picking up the referenced files and merging the options as intended. I'll see if I can get that working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants