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

[service] Use service to discover and parse tsconfig and discover matched source files #9

Closed
cspotcode opened this issue Jan 28, 2019 · 2 comments

Comments

@cspotcode
Copy link

cspotcode commented Jan 28, 2019

This is a situation I've encountered that actually has an easy workaround, but I thought I'd share it in case anyone else is trying to do the same.

Use-case

I want to discover the tsconfig for a directory, get the parsed compiler options, and get a list of source files.

Right now, the API leads one to believe that they must know the name of a source file first, rather than discovering the source files from the tsconfig.

Workaround

Try to parse a .ts file that you know does not exist. This will trigger tsconfig discovery and the creation of a language service.

import { TypeScriptService } from '@ts-tools/service';
const service = new TypeScriptService();
service.transpileFile('DOES NOT EXIST.ts', {
  tsconfigFileName : 'tsconfig.json',
  getCompilerOptions = (baseHost, tsconfigOptions) =>tsconfigOptions
});
const runningService = service.runningServices.get('tsconfig.json')!;
// Grab parsed compilerOptions
console.dir(runningService.languageService.getProgram()!.getCompilerOptions());
// Grab parsed set of source files
console.dir(runningService.rootFileNames);
@AviVahl
Copy link
Owner

AviVahl commented Jan 28, 2019

The service provides on-demand transpilation capabilities. Meaning, upon needing to transpile some .ts/x file, it will do the necessary work.

Loading config explicitly can be easier using createBaseHost yourself (also exported from the package) and parsing the config using typescript. I did something similar in @ts-tools/build: https://github.com/AviVahl/ts-tools/blob/%40ts-tools/build%400.1.8/packages/build/src/build.ts#L63

I may provide a config loading API as a warmup for the service. Could save config lookup work for the files already included in the pre-loaded config.

@AviVahl
Copy link
Owner

AviVahl commented Feb 17, 2019

check out the new APIs in the upcoming service@2.0.0.

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

2 participants