gustavopch / tsc-files

A tiny tool to run `tsc` on specific files without ignoring tsconfig.json
MIT License
223 stars 48 forks source link

tsc-files does not work with composite projects / --build flag does not work #64

Open FFdhorkin opened 11 months ago

FFdhorkin commented 11 months ago

I have a composite typescript project; according to the docs, you need to add -b/--build to your tsc args in order to build this.

However, tsc-files does not work with this flag.

My root package.json has this:

{
    "lint-staged": {
        "*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}": [
            "tsc-files --build",
            "eslint --cache --ignore-path .gitignore ${ESLINT_FIX:-}"
        ]
    }
}

which results in this error:

error TS6369: Option '--build' must be the first command line argument.

Originally, I had tsc-files --noEmit there, but that doesn't work with composite projects; it causes these type of errors:

error TS6305: Output file '/repo/path/dist/foo.d.ts' has not been built from source file '/repo/path/src/foo.ts'. The file is in the program because: Part of 'files' list in tsconfig.json

But it's not actually in the files list of the tsconfig.json, meaning that tsc-files is the origin of that error, too. Since the TS docs say composite requires you to have emit turned on, that's probably the issue there. (That said, removing --noEmit results in the same errors)

gustavopch commented 11 months ago

For composite projects, I suggest you to use incremental build instead of tsc-files: https://www.typescriptlang.org/tsconfig/incremental.html

FFdhorkin commented 11 months ago

I only switched the project from a single project to composite this week, because one library required CommonJS. Compiling the original project w/ tsc & incremental is noticably slower than the tsc-files version was :/ (we previously had incremental turned on, but I'm not sure whether tsc-files actually does incremental)