-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
docs: add Deno to the package manager tabs #2395
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?
Changes from 2 commits
185e83a
4c753ee
70945e5
aa20426
5a60f34
6d9e576
1d743b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,15 @@ | |
| * Package manager helpers. | ||
| * | ||
| * Converts an `npm`/`npx` command into the equivalent command for the other | ||
| * supported package managers (Yarn, pnpm, Bun) so docs can show a single, | ||
| * supported package managers (Yarn, pnpm, Bun, Deno) so docs can show a single, | ||
| * authored npm command and let readers pick their tool of choice. | ||
| * | ||
| * Authors write the npm command they already know; everything else is derived. | ||
| * Commands that have no clean cross-manager equivalent (e.g. `npm install | ||
| * <pkg> --no-save`) should stay as a plain fenced code block instead. | ||
| */ | ||
|
|
||
| export const PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm', 'bun'] as const; | ||
| export const PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm', 'bun', 'deno'] as const; | ||
|
|
||
| export type PackageManager = (typeof PACKAGE_MANAGERS)[number]; | ||
|
|
||
|
|
@@ -19,6 +19,7 @@ export const PACKAGE_MANAGER_LABELS: Record<PackageManager, string> = { | |
| yarn: 'yarn', | ||
| pnpm: 'pnpm', | ||
| bun: 'bun', | ||
| deno: 'deno', | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -38,6 +39,7 @@ const sameForAll = (command: string): CommandMap => ({ | |
| yarn: command, | ||
| pnpm: command, | ||
| bun: command, | ||
| deno: command, | ||
| }); | ||
|
|
||
| const join = (...parts: (string | false | undefined)[]): string => | ||
|
|
@@ -52,14 +54,15 @@ export function convertPackageManagerCommand(command: string): CommandMap { | |
| const tokens = command.trim().split(/\s+/); | ||
| const [bin, sub, ...rest] = tokens; | ||
|
|
||
| // npx codemod@latest ... -> yarn/pnpm dlx, bunx | ||
| // npx codemod@latest ... -> yarn/pnpm dlx, bunx, deno x | ||
| if (bin === 'npx') { | ||
| const exec = tokens.slice(1).join(' '); | ||
| return { | ||
| npm: join('npx', exec), | ||
| yarn: join('yarn dlx', exec), | ||
| pnpm: join('pnpm dlx', exec), | ||
| bun: join('bunx', exec), | ||
| deno: exec ? join('deno x', exec) : null, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -73,7 +76,7 @@ export function convertPackageManagerCommand(command: string): CommandMap { | |
| const packages = rest.filter((t) => !t.startsWith('-')); | ||
| const isDev = flags.some((f) => DEV_FLAGS.has(f)); | ||
| const isGlobal = flags.some((f) => GLOBAL_FLAGS.has(f)); | ||
| // `--no-save` only exists on npm and Bun; Yarn and pnpm have no equivalent. | ||
| // `--no-save` only exists on npm and Bun; Yarn, pnpm and Deno have no equivalent. | ||
| const hasNoSave = flags.includes('--no-save'); | ||
| const extra = flags.filter( | ||
| (f) => !DEV_FLAGS.has(f) && !GLOBAL_FLAGS.has(f) && !SAVE_FLAGS.has(f) | ||
|
|
@@ -88,6 +91,7 @@ export function convertPackageManagerCommand(command: string): CommandMap { | |
| yarn: join('yarn install', extras), | ||
| pnpm: join('pnpm install', extras), | ||
| bun: join('bun install', extras), | ||
| deno: join('deno install', extras), | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -102,6 +106,9 @@ export function convertPackageManagerCommand(command: string): CommandMap { | |
| ? null | ||
| : join('pnpm add', isDev && '--save-dev', isGlobal && '--global', pkgs, extras), | ||
| bun: join('bun add', isDev && '--dev', isGlobal && '--global', pkgs, extras), | ||
| // Deno adds to deno.json/package.json; it has no `--no-save`, and global | ||
| // tool installs use a different verb (`deno install -g`), so skip those. | ||
| deno: hasNoSave || isGlobal ? null : join('deno add', isDev && '--dev', pkgs, extras), | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -117,6 +124,7 @@ export function convertPackageManagerCommand(command: string): CommandMap { | |
| yarn: isGlobal ? join('yarn global remove', pkgs) : join('yarn remove', pkgs), | ||
| pnpm: join('pnpm remove', isGlobal && '--global', pkgs), | ||
| bun: join('bun remove', isGlobal && '--global', pkgs), | ||
| deno: isGlobal ? null : join('deno remove', pkgs), | ||
|
Contributor
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. I'm pretty sure that Deno allows uninstalling packages installed globally. BTW Deno docs say that
Author
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. Thanks for the catch, actually it looks like
Author
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. Good catch, thanks! Fixed β global removals now map to |
||
| }; | ||
| } | ||
|
|
||
|
|
@@ -130,13 +138,15 @@ export function convertPackageManagerCommand(command: string): CommandMap { | |
| yarn: join('yarn init', args), | ||
| pnpm: join('pnpm init', args), | ||
| bun: join('bun init', args), | ||
| deno: join('deno init', args), | ||
| }; | ||
| } | ||
| return { | ||
| npm: command, | ||
| yarn: join('yarn create', args), | ||
| pnpm: join('pnpm create', args), | ||
| bun: join('bun create', args), | ||
| deno: join('deno create --npm', args), | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -147,6 +157,7 @@ export function convertPackageManagerCommand(command: string): CommandMap { | |
| yarn: join('yarn', args), | ||
| pnpm: join('pnpm', args), | ||
| bun: join('bun run', args), | ||
| deno: join('deno task', args), | ||
| }; | ||
| } | ||
|
|
||
|
|
||
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.
If deno has no
--no-savethen why do you returntrueinstead ofnull(like you wrote in the description)1? For consistency it would be better to change this to chained ternary operators to match the structure used for other package managers (it would also fix the problem described in the previous sentence).According to your docs
deno addis an alias todeno install- usingdeno installwould allow you to use this way of "assembling" the command usingjointo include global installs. And nothing prevents you from usingdeno installwhenisGlobalis true anddeno addwhen it's false.Footnotes
LLMs generating code frequently write one thing in description and something completely else in code. β©
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.
Thanks for the review, I did another pass on this one and corrected the mistake here and in
deno xinvocation. I also removed the comment here since it's not really needed.