dsherret / dsherret/ts-morph

make TsConfigResolver._parseJsonConfigFileContent() function public

Open
#1,503 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Is your feature request related to a problem? Please describe.**

Hey @dsherret! Awesome project, thank you :bow:!
I'm working on a small package that would help rename specifiers on-the-fly when using multiple TS compilation targets.
To create the TS Program I need to support project references, but currently the `TsConfigResolver` class does not expose those.

Hence, to recreate the tsProgram correctly I have to write this code that uses the private method `tsConfigResolver._parseJsonConfigFileContent()`:

```ts
const tfsHost = new TransactionalFileSystem({
fileSystem: fsHost,
skipLoadingLibFiles: true,
libFolderPath: undefined,
});

const standardizedTsConfigPath =
tfsHost.getStandardizedAbsolutePath(tsConfigFilePath);

const encoding = "utf-8";
const tsConfigResolver = new TsConfigResolver(
tfsHost,
standardizedTsConfigPath,
encoding,
) as unknown as PrivateTsConfigResolver;
// ^^ need to cast this to include the private method

const tsConfigContent = tsConfigResolver._parseJsonConfigFileContent();

const tsProgram = ts.createProgram({
options: tsConfigContent.options,
configFileParsingDiagnostics: tsConfigContent.errors,
projectReferences: tsConfigContent.projectReferences,
// ^^ here
rootNames: [],
});
```

**Describe the solution you'd like**

Ideally, the TsConfigResolver would expose the full config contents. Currently it only exposes these two (`getCompilerOptions`, `getErrors`):

https://github.com/dsherret/ts-morph/blob/930779a0d3699be35ab17bbe9dd26ec00350fe53/packages/common/src/tsconfig/TsConfigResolver.ts#L21-L27

Either adding a public method like `getParsedCommandLine()` or exposing `parseJsonConfigFileContent()` as public would solve my problem.

**Describe alternatives you've considered**

Alternative I've considered is to copy and paste a bunch of code from ts-morph and including that in my project. Not ideal, since I'd need to sync that every time the upstream changes.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.