-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 TypeScript declarations with @nx/esbuild:esbuild #20688
Comments
@castleadmin Hey, thanks for expressing interest on this, do you have any suggestions on how you'd want to do this? |
Hi @jaysoo, for the suggested case I would do the following
|
@jaysoo What do you think about the new feature? Should I start implementing a concrete solution? |
When can we expect this feature? |
I should be able to implement the feature within the next 2 weeks. |
What is missing to complete this feature? It seems the MR is open and ready for review. I am happy to contribute if there is anything needed to complete the feature 👍 |
Here is the way I have fixed it:
so I create first dts with clean:true and then build esbuild with "deleteOutputPath": false. I know it's ugly but it works =) Addititionally I had to create a dedicated tsconfig too to use: "declaration": true and "emitDeclarationOnly": true, |
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior esbuild doesn't support the creation of declaration files (*.d.ts) and probably never will (see evanw/esbuild#95). Since declaration files are essential for published libraries, it would be great if @nx/esbuild:esbuild would provide an option to output them. ## Expected Behavior - Introduced a new boolean valued `declaration` option for the `esbuild` executor - If `declaration` or the tsconfig option [declaration](https://www.typescriptlang.org/tsconfig#declaration) is true, then the TypeScript compiler is used before esbuild to generate the declarations - The output directory structure of the declarations can be influenced by setting the TypeScript rootDir via the `declarationRootDir` option ## Related Issue(s) #20688 ### Additional Comment Please note that the generated declaration files directory structure is affected by the tsconfig `rootDir` property. For a library that doesn't reference other libraries inside the monorepo, the `rootDir` property can be changed freely. If a library inside the monorepo is referenced the `rootDir` property must be set to the workspace root. The `tsc` executor has a sophisticated check that automatically sets the `rootDir` to the workspace root if a library is referenced. https://github.com/nrwl/nx/blob/master/packages/js/src/executors/tsc/tsc.impl.ts#L104 This check is quite complex and specific to the `tsc` executor options. Therefore, it hasn't been included inside the esbuild implementation. The current implementation leaves it to the user to solve the edge case by removing the `declarationRootDir` option or by setting the `declarationRootDir` to `.`. In the future, it might make sense to generalize and use the `tsc` executor check.
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior esbuild doesn't support the creation of declaration files (*.d.ts) and probably never will (see evanw/esbuild#95). Since declaration files are essential for published libraries, it would be great if @nx/esbuild:esbuild would provide an option to output them. ## Expected Behavior - Introduced a new boolean valued `declaration` option for the `esbuild` executor - If `declaration` or the tsconfig option [declaration](https://www.typescriptlang.org/tsconfig#declaration) is true, then the TypeScript compiler is used before esbuild to generate the declarations - The output directory structure of the declarations can be influenced by setting the TypeScript rootDir via the `declarationRootDir` option ## Related Issue(s) #20688 ### Additional Comment Please note that the generated declaration files directory structure is affected by the tsconfig `rootDir` property. For a library that doesn't reference other libraries inside the monorepo, the `rootDir` property can be changed freely. If a library inside the monorepo is referenced the `rootDir` property must be set to the workspace root. The `tsc` executor has a sophisticated check that automatically sets the `rootDir` to the workspace root if a library is referenced. https://github.com/nrwl/nx/blob/master/packages/js/src/executors/tsc/tsc.impl.ts#L104 This check is quite complex and specific to the `tsc` executor options. Therefore, it hasn't been included inside the esbuild implementation. The current implementation leaves it to the user to solve the edge case by removing the `declarationRootDir` option or by setting the `declarationRootDir` to `.`. In the future, it might make sense to generalize and use the `tsc` executor check. (cherry picked from commit 7f32d86)
Hello! Looks like this has been resolved in #21084 so I will close this issue. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Description
esbuild doesn't support the creation of declaration files (*.d.ts) and probably never will (see evanw/esbuild#95).
Since declaration files are essential for published libraries,
it would be great if
@nx/esbuild:esbuild
would provide an option to output them.Motivation
Declaration files (*.d.ts) are essential for published libraries.
Suggested Implementation
The commonly accepted workaround is to run a tsc build before the esbuild build that only outputs the declaration files.
This additional build step could be provided as a
@nx/esbuild:esbuild
option.Alternate Implementations
Implement the additional build step in the
@nx/js:library
generator for publishable libraries.The text was updated successfully, but these errors were encountered: