-
Notifications
You must be signed in to change notification settings - Fork 596
chore(instr-undici): use tsup for cjs,esm output #2954
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2954 +/- ##
=======================================
Coverage ? 89.01%
=======================================
Files ? 188
Lines ? 9221
Branches ? 1900
=======================================
Hits ? 8208
Misses ? 1013
Partials ? 0 🚀 New features to boost your workflow:
|
|
esbuild has a mentioned-in-documentation-but-never-explained config option ...however there's a bug in tsup where it either drops or puts a wrong type of file extension in requires/imports (either .mjs trying to load extensionless .js (commonjs) or (when package.json has type: module) .cjs files trying to load .js (esm)) - this snippet has worked for me in the second case but it requires a config file to add a plugin |
@t2t2 thanks for the info about In last JS SIG (2025-07-23) there was a comment about the potential performance benefit of having the code in a single file. So I'll keep the current options for now. This PR is now ready to compare with #2955. I'll add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Looks a lot easier than I expected thankfully
"{projectRoot}/build", | ||
"{projectRoot}/dist" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we need both build and dist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because I couldn't find an option to change the destination dir in tsup. So for now nx needs to cache build and dist. If we move forward with this all packages will have the compilation output to dist so the bukd folder will disappear from this config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry meant to mark this as approved before not just "comment"
Does that mean you prefer this solution over #2955? |
@david-luna do you think it would be feasible to use |
There was some offline discussion on your two PRs, but not hard decision on preference for either of your PRs yet. |
A possible example of doing so manually might be (I haven't tested): https://github.com/open-feature/js-sdk/blob/dc1970e717a8cbe7261d52d993c8811059718bed/packages/server/package.json#L21-L23 |
Which problem is this PR solving?
OpenTelemetry JS modules do not have valid ESM files in the compilation result. See open-telemetry/opentelemetry-js#3989
This PR is an attempt to fix it with adding a new tool named
tsup
which compiles the code withesbuild
under the hood.The scope is reduced to
@opentelemetry/instrumentation-undici
because this implies changes in the toolchain and needs to be discussed in the Javascript SIGShort description of the changes
tsup
dependencytsup
package.json
to get the proper mapping foe cjs and esm modules"exports"
sectionfiles
sectionNOTES:
tsc
but IMO it is odd to have a type error it in compilation time but in testtsup
does emit, in this case, a single file with all the instrumentation code instead of emit a single file per.ts
file. Not sure if this is a good or bad thingNotice
This PR is meant to be reviewed along with #2955 which does the same but using the current toolchain of the repo. The intention is to have a conversation on the path we want to take about tooling. Should we stick to the current tools (for compilation) or change them?