question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
DorianGreycommented, Jun 15, 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.

0reactions
GeeWeecommented, Jun 14, 2017

Strange. In my attempts I simply got an object with an “extends” key. That’d be awesome

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
The configuration from the base file are loaded first, then overridden by ... engine to improve performance, and makes a set of errors...
Read more >
Documentation - What is a tsconfig.json - TypeScript
The tsconfig.json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig.json file...
Read more >
Documentation - tsc CLI Options - TypeScript
Flag Type Default ‑‑allowJs boolean false ‑‑allowUmdGlobalAccess boolean false ‑‑allowUnreachableCode boolean
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
Docs on every TSConfig option - TypeScript
This config file will include all packages under ./typings and ./vendor/types , and no packages from ./node_modules/@types . All paths are relative to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found