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

tsConfig argument conflates two different objects #117

Closed
vbraun opened this issue Apr 18, 2023 · 0 comments · Fixed by #118
Closed

tsConfig argument conflates two different objects #117

vbraun opened this issue Apr 18, 2023 · 0 comments · Fixed by #118

Comments

@vbraun
Copy link
Contributor

vbraun commented Apr 18, 2023

The documentation says

Could also be an object representing a pre-parsed typescript config.

but that could be two different things:

1) raw json

Meaning that you read the tsconfig.json file and apply JSON.parse()

In this case, the compiler options are tsconfig.compilerOptions. The module setting tsconfig.compilerOptions.module is a string, for example 'CommonJs'. And if you want to be able to resolve index.ts files then it better be that value.

filing-cabinet still needs to convert the raw json to typescript's own format before using it.

2) parsed using typescript's api to parse the config file

That is, using typescript.parseJsonSourceFileConfigFileContent

In this case, the compiler options are tsconfig.options. The module setting tsconfig.options.module is a number, for example the number-based enum value typescript.ModuleKind.CommonJS. And if you want to be able to resolve index.ts files then it better be that value.

This is the preferred usage if you care about resolution speed for multiple files as typescript doesn't have to re-parse its configuration.

There is no api to go from 2) back to 1), only from 1) to 2).

Problem

Passing 2) into filing-cabinet means that the module is typescript configuration is accidentally undefined. Filing-cabinet then defaults to typescript.ModuleKind.AMD which does not include index.ts files.

madge tries to hack around that by trying to convert 2) back to 1), but unsuccessfully so: pahen/madge#271, pahen/madge#322

Instead, filing-cabinet should accept both kinds of tsConfig objects and handle them according to wether tsConfig.compilerOptions or tsConfig.options is present.

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

Successfully merging a pull request may close this issue.

1 participant