-
Notifications
You must be signed in to change notification settings - Fork 126
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
fix: add bin
field to npm compat tarballs
#284
Open
lucacasonato
wants to merge
1
commit into
main
Choose a base branch
from
npm_bin_field
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE npm_tarballs ADD COLUMN bin jsonb NOT NULL DEFAULT '{}'; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -447,3 +447,39 @@ case, you can un-ignore the `dist/` directory by using a negation in the | |
|
||
In this case, the `dist/` directory will be included when publishing, even | ||
though it is listed in the `.gitignore` file. | ||
|
||
## Publishing command line interfaces (CLIs) | ||
|
||
JSR supports publishing of command-line interfaces (CLIs) as part of a package. | ||
This allows package users to execute your CLI from the command line using | ||
`deno run`, `npx`, `yarn dlx`, and similar tools. | ||
|
||
Unlike npm, JSR does not have a special field in the `jsr.json` / `deno.json` to | ||
specify bin entrypoints. Instead, include the bin entrypoints in the `exports` | ||
field. If your package only has a single bin entrypoint and no other | ||
entrypoints, you can specify it as the default entrypoint in the `exports` | ||
field. | ||
|
||
```json | ||
// jsr.json | ||
{ | ||
"name": "@luca/greet", | ||
"version": "1.0.0", | ||
"exports": { | ||
".": "./cli.ts" | ||
} | ||
} | ||
``` | ||
|
||
Deno users will be able to use this CLI with `deno run`, as they can with any | ||
remote package: `deno run jsr:@luca/greet`. If the bin is instead specified in a | ||
non-default exports, they can still call it: `deno run jsr:@luca/greet/bin`. | ||
|
||
For users using [JSR's npm compatibility layer](/docs/npm-compatibility), a | ||
`bin` field is added to the `package.json` in the generated npm compatible | ||
tarball. JSR will put all files specified in the `exports` in this field that | ||
contain a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)#Examples). JSR | ||
Comment on lines
+479
to
+481
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs should specify what shebang should universal code use. I believe it should be a Node shebang, since Deno will ignore it. |
||
will automatically determine a binary name based on the package name and exports | ||
key (`<PACKAGE_NAME>-<EXPORT_KEY>`, except for the root `.` export, where the | ||
key is just `<PACKAGE_NAME>`). A package author can override the binary name by | ||
specifying a `// @jsrBin=<BIN_NAME>` comment in the relevant JS/TS file. |
Oops, something went wrong.
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.
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.
That might make it difficult to publish existing packages to JSR, unless https://github.com/nodejs/modules/issues/274
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.
Why do you say so? Your bin entrypoint does not have to be in the root entrypoint.
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.
I'm not exactly thrilled about having to resort to hacks, or rethink my
package.json
to match JSR.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.
I'd be fine with this if JSR transpiled
import.meta.main
to something Node can understand.