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

tsconfig for single-file transforms #366

Closed
LarsDenBakker opened this issue Sep 2, 2020 · 8 comments
Closed

tsconfig for single-file transforms #366

LarsDenBakker opened this issue Sep 2, 2020 · 8 comments

Comments

@LarsDenBakker
Copy link

From what I can tell, the single file transforms don't pick up the user's tsconfig. Is this correct? I'm just double checking so that I know what to document for people using our tools which use esbuild.

Perhaps it would be useful to document the tsconfig logic in the readme.

@Akimyou
Copy link

Akimyou commented Sep 3, 2020

// index.js
const esbuild = require("esbuild");
const codeContent = `
const name: string = '111';
const render = () => {
    return <div>Hello</div>;
};
`;
console.log(esbuild.transformSync(codeContent, { loader: 'tsx', tsconfig: '../tsconfig.json' }));
// tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "module": "ESNext",
    "jsx": "preserve",
    "jsxFactory": "h",
    "jsxFragmentFactory": "Fragment",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"]
}

Please have a try. The esbuild.transformSync result no respect to tsconfig.json.

@LarsDenBakker
Copy link
Author

@Akimyou sorry I didn't specify this, I meant reading the tsconfig of the user implicitly. There are rules around which files are affected by a tsconfig, and you need to crawl the file system to find the nearest config. I'd rather not re-implement that in my tools.

@Akimyou
Copy link

Akimyou commented Sep 3, 2020

@LarsDenBakker , But the esbuild.build func respect to tsconfig.json. The different behavior is confused.

@bennypowers
Copy link

Being able to use tsconfig in the transform method as well as build would be useful in a number of cases.

For example: transforming a file that is part of a project which uses paths in tsconfig. Since 0e0a9fb, esbuild respects the paths option, but only if the tsconfig is at play.

@evanw
Copy link
Owner

evanw commented Sep 6, 2020

From what I can tell, the single file transforms don't pick up the user's tsconfig. Is this correct? I'm just double checking so that I know what to document for people using our tools which use esbuild.

This is correct, and is by design. The intent of the transform API call is to do an isolated transformation without touching the file system. If you need to touch the file system, you should use the build API call without bundling enabled. Part of the reason for this is that the transform API works in places without a file system, such as in the web browser, while the build API requires a file system to work.

@Akimyou
Copy link

Akimyou commented Sep 7, 2020

@evanw , I understand. But is possible the build api accept code content and return result content as transform api?

@evanw
Copy link
Owner

evanw commented Sep 7, 2020

is possible the build api accept code content and return result content as transform api?

Yes. The build API has a stdin option for passing it a string directly without reading from the file system, and also has a write: false option for returning the raw output file contents instead of writing them to the file system. It's not as nice to use as the transform API because it supports a wider set of use cases, but it is possible.

@LarsDenBakker
Copy link
Author

I'll close this issue since the question was answered. Thanks!

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