Skip to content

Commit

Permalink
feat: adds the dlx command type
Browse files Browse the repository at this point in the history
  • Loading branch information
jits authored Nov 1, 2024
1 parent 2c96f3e commit b62e4c6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/src/content/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PackageManagers from '../../components/PackageManagers.astro'
## Features

- Support for various package managers: [npm](https://www.npmjs.com), [yarn](https://yarnpkg.com), [pnpm](https://pnpm.io), [bun](https://bun.sh) & [ni](https://github.com/antfu/ni).
- Support for various types of command: [`add`](/usage/#add), [`create`](/usage/#create), [`exec`](/usage/#exec), [`run`](/usage/#run) & [`remove`](/usage/#remove).
- Support for various types of command: [`add`](/usage/#add), [`create`](/usage/#create), [`dlx`](/usage/#dlx), [`exec`](/usage/#exec), [`run`](/usage/#run) & [`remove`](/usage/#remove).
- Synced tabs between each instance on the same page.
- Customizable output with [extra arguments](/usage/#extra-arguments), [comments](/usage/#comment) & [prefixes](/usage/#prefix).

Expand Down
12 changes: 12 additions & 0 deletions docs/src/content/docs/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ The code above generates the following commands:

<PackageManagers type="create" pkg="astro@latest" />

### `dlx`

To fetch and execute a package binary, without installing it as a dependency, you can use the `dlx` type and specify extra arguments using the `args` prop.

```mdx title="src/content/docs/example.mdx" 'type="dlx"'
<PackageManagers type="dlx" pkg="serve" args="public" />
```

The code above generates the following commands:

<PackageManagers type="dlx" pkg="serve" args="public" />

### `exec`

To execute a package binary, you can use the `exec` type and specify extra arguments using the `args` prop.
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight-package-managers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ By this one:
## Features

- Support for various package managers: [npm](https://www.npmjs.com), [yarn](https://yarnpkg.com), [pnpm](https://pnpm.io), [bun](https://bun.sh) & [ni](https://github.com/antfu/ni).
- Support for various types of command: [`add`](https://starlight-package-managers.vercel.app/usage/#add), [`create`](https://starlight-package-managers.vercel.app/usage/#create), [`exec`](https://starlight-package-managers.vercel.app/usage/#exec), [`run`](https://starlight-package-managers.vercel.app/usage/#run) & [`remove`](https://starlight-package-managers.vercel.app/usage/#remove).
- Support for various types of command: [`add`](https://starlight-package-managers.vercel.app/usage/#add), [`create`](https://starlight-package-managers.vercel.app/usage/#create), [`dlx`](https://starlight-package-managers.vercel.app/usage/#dlx), [`exec`](https://starlight-package-managers.vercel.app/usage/#exec), [`run`](https://starlight-package-managers.vercel.app/usage/#run) & [`remove`](https://starlight-package-managers.vercel.app/usage/#remove).
- Synced tabs between each instance on the same page.
- Customizable output with [extra arguments](https://starlight-package-managers.vercel.app/usage/#extra-arguments), [comments](https://starlight-package-managers.vercel.app/usage/#comment) & [prefixes](https://starlight-package-managers.vercel.app/usage/#prefix).

Expand Down
9 changes: 7 additions & 2 deletions packages/starlight-package-managers/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const commands: Commands = {
add: 'npm i',
create: 'npm create',
devOption: '-D',
dlx: 'npx',
exec: 'npx',
run: 'npm run',
remove: 'npm uninstall',
Expand All @@ -15,6 +16,7 @@ const commands: Commands = {
add: 'yarn add',
create: 'yarn create',
devOption: '-D',
dlx: 'yarn dlx',
exec: 'yarn',
run: 'yarn run',
remove: 'yarn remove',
Expand All @@ -23,20 +25,23 @@ const commands: Commands = {
add: 'pnpm add',
create: 'pnpm create',
devOption: '-D',
dlx: 'pnpm dlx',
exec: 'pnpm',
run: 'pnpm run',
remove: 'pnpm remove',
},
bun: {
add: 'bun add',
devOption: '-d',
dlx: 'bunx',
exec: 'bunx',
run: 'bun run',
remove: 'bun remove',
},
ni: {
add: 'ni',
devOption: '-D',
dlx: 'nlx',
exec: 'nlx',
run: 'nr',
remove: 'nun',
Expand Down Expand Up @@ -88,7 +93,7 @@ export function getCommand(
}

if (options.args && options.args.length > 0) {
if (pkgManager === 'npm' && type !== 'exec' && type !== 'run') {
if (pkgManager === 'npm' && type !== 'dlx' && type !== 'exec' && type !== 'run') {
command += ' --'
}

Expand All @@ -98,7 +103,7 @@ export function getCommand(
return command
}

export type CommandType = 'add' | 'create' | 'exec' | 'run' | 'remove'
export type CommandType = 'add' | 'create' | 'dlx' | 'exec' | 'run' | 'remove'

export interface CommandOptions {
args?: string
Expand Down
12 changes: 12 additions & 0 deletions packages/starlight-package-managers/tests/unit/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ pnpm create astro`,
})
})

describe('dlx', () => {
test("should generate the 'dlx' command", () => {
expect(getCommands('dlx', 'serve', { args: 'public' })).toEqual([
'npx serve public',
'yarn dlx serve public',
'pnpm dlx serve public',
'bunx serve public',
'nlx serve public',
])
})
})

describe('exec', () => {
test("should generate the 'exec' command", () => {
expect(getCommands('exec', 'astro', { args: 'add solid' })).toEqual([
Expand Down

0 comments on commit b62e4c6

Please sign in to comment.