Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the list of Typescript files that tsc will compile?

I'm trying to write a grunt task in a Typescript project to measure some statistics of the source files. To do that, I have a function that takes a single source file, runs typescript.createSourceFile from it, and does some stuff to the returned AST. The problem is finding all the files to iterate over: I'd like to get exactly the same list of files that tsc -p tsconfig.json will compile later. The intention is to filter out some files from that list and then iterate over the filtered list.

I imagine I'd use the typescript module to do this, but I can't find a function to do it. I found the place in the tsc source that turns tsconfig into a list of files, and it seems to be using a function that's not exported.

like image 413
Dan Hulme Avatar asked Nov 20 '18 16:11

Dan Hulme


People also ask

How are TypeScript files compiled?

The TypeScript compiler compiles these files and outputs the JavaScript with . js extension by keeping the same file name as the individual input file. The TypeScript compiler also preserves the original file path, hence the . js output file will be generated where the input file was in the directory structure.

How do I compile all ts files in a folder?

Open a terminal and run tsc -w , it'll compile any . ts file in src directory into .

What does tsc command do TypeScript?

The tsc command envokes the TypeScript compiler. When no command-line options are present, this command looks for the tsconfig. json file. If no tsconfig.

How do I get tsc TypeScript?

TypeScript is available as a package on the npm registry available as "typescript" . You will need a copy of Node. js as an environment to run the package. Then you use a dependency manager like npm, yarn or pnpm to download TypeScript into your project.


1 Answers

tsc --listFiles --noEmit

This will list the files that tsc will compile based on the tsconfig.json it uses.

like image 109
Muthukumar Avatar answered Oct 24 '22 21:10

Muthukumar