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

Custom includes from original tsconfig.json #65

Open
ghost opened this issue Feb 13, 2024 · 3 comments
Open

Custom includes from original tsconfig.json #65

ghost opened this issue Feb 13, 2024 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 13, 2024

We're using tsc-files in our pre-commit hook to check the staged files. When running the script, I was getting errors from tsc-files that were related to the Nativewind library, that I wasn't getting when running plain tsc. As it turns out, this was related to the files that we include in the projects tsconfig.json and that some of these includes are also required when running tsc-files.

Since tsc-files just generates an empty array without an option to fill the "includes" section, I created a patch that includes a new field from the tsconfig.json called "tsc-files-include" in the "includes"-Array from the generated tsconfig.json.

Patch:

diff --git a/node_modules/tsc-files/cli.js b/node_modules/tsc-files/cli.js
index 7544d0d..e738637 100755
--- a/node_modules/tsc-files/cli.js
+++ b/node_modules/tsc-files/cli.js
@@ -53,7 +53,7 @@ const tmpTsconfig = {
     skipLibCheck: true,
   },
   files,
-  include: [],
+  include: [...tsconfig['tsc-files-include']],
 }
 fs.writeFileSync(tmpTsconfigPath, JSON.stringify(tmpTsconfig, null, 2))

New field in tsconfig.json:

{
  "include": [
    ...,
    "app.d.ts"
  ],
  "tsc-files-include": [
    "app.d.ts"
  ]
}

Do you think there's a way to provide some kind of configuration option for the values of the "includes"-Array of the generated tsconfig.json?

@gustavopch
Copy link
Owner

Why not pass the files as args to the CLI like tsc-files foo.ts app.d.ts? It achieves the same result without having to create new API surface.

@dawsonc623
Copy link

I just ran into an issue similar to this.

I use tsc-files for lint-staged, and I have .d.ts files in my project that are currently included with the include in my tsconfig.json file that end up excluded from tsc-files if they do not happen to be part of the change set. This causes my commit hook to fail in cases where any of the files passed to tsc-files need any of those .d.ts files.

I can fix this by adding these files to the lint-staged configuration that calls tsc-files, but it feels a smidge clunky to have to manage inclusion of my .d.ts files in two places. It would be nicer to manage it all from my tsconfig.json since that is naturally where I go when I see errors related to missing declarations.

@gustavopch
Copy link
Owner

As an alternative, you could use jq to read your custom property from tsconfig.json and pass to tsc-files.

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