fix: binary entrypoint output and shim type declarations - #512
Merged
Conversation
- keep the modules that only a binary entrypoint uses out of the script output, since a binary is only ever run by node (denoland#319) - allow a single binary entrypoint to go without a name, which uses the package name as the name of the command (denoland#338) - point the binary at the script output when there's no esm output, which was pointing at a file that didn't exist - add the type declarations of a shim to the dev dependencies whether or not the tests are included in the output (denoland#409) Closes denoland#319 Closes denoland#338 Closes denoland#409
- keep an entrypoint that's also an export out of the binary only files, which was leaving it out of the script output - don't error for a top level await in a file that isn't in the script output - dedupe the type declarations of a shim that's in both the shims and the test shims - add end to end coverage and document the behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #319
Closes #338
Closes #409
Four related fixes.
A binary's modules are no longer in the script output (#319)
A binary is only ever run by Node.js, so emitting its modules to
script/as well asesm/was dead weight. The transform now returns the output files that are only reachable from a binary entrypoint and they're left out of the script program. A module that something else uses (an export entrypoint or a test) still goes to both.Following your note on the issue, the reachability is computed in the rust code. As a side effect a binary may now use a top level await even when the package has a CommonJS output.
A binary entrypoint may go without a name (#338)
{ kind: "bin", path: "./cli.ts" }produced"bin": { "undefined": "./esm/cli.js" }. It now emits the string form, which npm treats as the package name being the command:nameis optional onEntryPointnow, and it errors when an export entrypoint has no name or when there are multiple binaries and one of them has no name.The binary pointed at a file that doesn't exist
With
esModule: falsethe"bin"entry still pointed at./esm/.... It now points at the script output in that case.Shim type declarations reach the dev dependencies (#409)
A shim's
typesPackage(ex.@types/wsfor the webSocket shim) went into the test environment's dependencies, so it was dropped whentestwasfalseand the output failed to type check. They now go through the types dependencies that #509 added, which always reachdevDependencies.