-
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
feat(bundling): added support for declarations (*.d.ts) #21084
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 5136a13. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 6 targets
Sent with 💌 from NxCloud. |
Any progress on this? My team is waiting for it. |
f1adbfb
to
5136a13
Compare
Tested this locally, and the tests on CI seem to pass, so I am going to merge. However, once |
Thank you
What approach would you recommend in the context of Project Crystal? |
An esbuild plugin could be a viable alternative to support declaration file builds. esbuild-plugin-d.ts is listed on the esbuild plugin page and provides the needed functionality. Another solution that doesn't rely on third-party plugins would be to split the current implementation into 2 commands.
If the clearing of the output directory and caching doesn't interfere, then a solution that uses 2 commands should work fine. |
👍🏻 This is what I currently do (though an OOB integrated solution would be nice!) |
<!-- 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)
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
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
declaration
option for theesbuild
executordeclaration
or the tsconfig option declaration is true,then the TypeScript compiler is used before esbuild to generate the declarations
declarationRootDir
optionRelated 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 therootDir
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 thedeclarationRootDir
to.
.In the future, it might make sense to generalize and use the
tsc
executor check.