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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

make TsConfigResolver._parseJsonConfigFileContent() function public #1503

Open
niieani opened this issue Feb 5, 2024 · 0 comments
Open

make TsConfigResolver._parseJsonConfigFileContent() function public #1503

niieani opened this issue Feb 5, 2024 · 0 comments

Comments

@niieani
Copy link

niieani commented Feb 5, 2024

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

Hey @dsherret! Awesome project, thank you 馃檱!
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():

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):

getCompilerOptions() {
return this._parseJsonConfigFileContent().options;
}
getErrors() {
return this._parseJsonConfigFileContent().errors || [];
}

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.

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

No branches or pull requests

1 participant