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

Support for custom TSConfig path #226

Closed
iamakulov opened this issue Jul 5, 2020 · 5 comments
Closed

Support for custom TSConfig path #226

iamakulov opened this issue Jul 5, 2020 · 5 comments

Comments

@iamakulov
Copy link

Hey,

Is there a chance ESBuild would support specifying a custom path to tsconfig.json/jsconfig.json?

Prior art

TypeScript supports passing a custom path to tsconfig.json using the -p (or --project) CLI parameter:

tsc -p tsconfig.tests.json

Use cases

My use-case: the project I’m working on uses ESBuild for development and webpack for production. To run ESBuild, we have to replace one package with a custom mock. We do this through tsconfig.json’s paths:

{
    "compilerOptions": {
        "paths": {
            ...
            "linaria": ["./environment/linaria-esbuild-mock.ts"]
        },
    }
}

However, putting this into the primary tsconfig.json results in a bad DX. (E.g., Ctrl+clicking linaria imports now leads to the mock instead of the original file.) It would be great if we had tsconfig.esbuild.json with necessary overrides – and were able to point ESBuild to use it.

Other use-cases: A few projects I saw used tsconfig.test.json for custom test configs (e.g., for custom include/exclude configuration).

@evanw
Copy link
Owner

evanw commented Jul 6, 2020

I see why this would be useful, but I'm having trouble figuring out what the right implementation would be. There can be many tsconfig.json files spread throughout a directory tree. Does this force-override all of them? Just one of them? Is it only a fallback if no tsconfig.json file is found? Does there need to be some way of configuring different overrides for different directories?

@iamakulov
Copy link
Author

iamakulov commented Jul 7, 2020

I see why this would be useful, but I'm having trouble figuring out what the right implementation would be. There can be many tsconfig.json files spread throughout a directory tree. Does this force-override all of them? Just one of them? Is it only a fallback if no tsconfig.json file is found? Does there need to be some way of configuring different overrides for different directories?

I’d follow the TS implementation:

Using tsconfig.json or jsconfig.json

  • By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.
  • By invoking tsc with no input files and a --project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file, or a path to a valid .json file containing the configurations.

Source

Which means:

  • tsconfig.jsons in child directories are ignored. (E.g., see this test project: here, both root.ts and a/a.ts are compiled to ES5 – even though a/tsconfig.json specifies "target": "ESNext".)
  • If you specify an explicit tsconfig.json path, it will override any automatically detected tsconfig.json

@evanw
Copy link
Owner

evanw commented Jul 8, 2020

Thanks for finding this information! After reading that, I agree that following the TypeScript implementation does sound like the right thing to do.

@evanw evanw closed this as completed in 9ac27fa Jul 11, 2020
@seriouscoderone
Copy link

I have a related issue, where I want to bundle the tsconfig compilerOptions.paths as "nodeModules", but it only looks at the package.json https://github.com/aws/aws-cdk/blob/b2037d3b1a63715f71587681c84a5fd34be939a7/packages/%40aws-cdk/aws-lambda-nodejs/lib/util.ts#L91

@uglycoyote
Copy link

uglycoyote commented Oct 1, 2021

I'm not clear on whether this issue was closed because it was implemented, or denied? Is there currently a way to esbuild to set a custom tsconfig path? I could not find anything in the command line options list.

I'm in this situation becuase I'm combining esbuild and another bundler on the same repo. Currently i have tsconfig's target property set to es5, but my esbuild doesn't know how to transform a bunch of the features used in the codebase to es5, forcing me to switch it to es6. But using es6 breaks my existing build with the other bundler, so I would like to keep using what works (es5) when building with that bundler, and use es6 for esbuild.

EDIT: nevermind, sorry I didn't realize at first that it was linking a revision above which fixed this.

For future reference of anyone ending up here first:

The option is:

  --tsconfig=...            Use this tsconfig.json file instead of other ones

and it's here in the docs https://esbuild.github.io/api/#tsconfig

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

4 participants