Skip to content

Commit

Permalink
feat: Add support for install command
Browse files Browse the repository at this point in the history
  • Loading branch information
YonicDev committed Feb 2, 2025
1 parent 2d46934 commit 3a017ff
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-fans-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'starlight-package-managers': minor
---

Added support for the `install` command, for installing all dependencies specified in the package.json file.
14 changes: 14 additions & 0 deletions docs/src/content/docs/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ The code above generates the following commands:

<PackageManagers type="exec" pkg="astro" args="add solid" />

### `install`

To install all dependencies, you can use the `install` type, with no other props specified.

```mdx title="src/content/docs/example.mdx" 'type="exec"' 'args="add solid"'
import { PackageManagers } from 'starlight-package-managers'

<PackageManagers type="install" />
```

The code above generates the following commands:

<PackageManagers type="install" />

### `run`

To run a script defined in the package's manifest file, you can use the `run` type and specify the name of the name of the script 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), [`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).
- 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), [`install`](https://starlight-package-managers.vercel.app/usage/#install), [`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
7 changes: 6 additions & 1 deletion packages/starlight-package-managers/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const commands: Commands = {
devOption: '-D',
dlx: 'npx',
exec: 'npx',
install: 'npm install',
run: 'npm run',
remove: 'npm uninstall',
},
Expand All @@ -19,6 +20,7 @@ const commands: Commands = {
devOption: '-D',
dlx: 'yarn dlx',
exec: 'yarn',
install: 'yarn install',
run: 'yarn run',
remove: 'yarn remove',
},
Expand All @@ -28,6 +30,7 @@ const commands: Commands = {
devOption: '-D',
dlx: 'pnpx',
exec: 'pnpm',
install: 'pnpm install',
run: 'pnpm run',
remove: 'pnpm remove',
},
Expand All @@ -36,6 +39,7 @@ const commands: Commands = {
devOption: '-d',
dlx: 'bunx',
exec: 'bunx',
install: 'bun install',
run: 'bun run',
remove: 'bun remove',
},
Expand All @@ -44,6 +48,7 @@ const commands: Commands = {
devOption: '-D',
dlx: 'nlx',
exec: 'nlx',
install: 'ni',
run: 'nr',
remove: 'nun',
},
Expand Down Expand Up @@ -109,7 +114,7 @@ export function getCommand(
return command
}

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

export interface CommandOptions {
args?: string
Expand Down
36 changes: 36 additions & 0 deletions packages/starlight-package-managers/tests/unit/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,42 @@ describe('exec', () => {
})
})

describe('install', () => {
test("should generate the 'install' command", () => {
expect(getCommands('install', '', {})).toEqual(['npm install', 'yarn install', 'pnpm install', 'bun install', 'ni'])
})

test("should generate the 'install' command with a comment", () => {
expect(getCommands('install', '', { comment: 'install dependencies' })).toEqual([
`# install dependencies
npm install`,
`# install dependencies
yarn install`,
`# install dependencies
pnpm install`,
`# install dependencies
bun install`,
`# install dependencies
ni`,
])
})

test("should generate the 'install' command with a comment including the package manager", () => {
expect(getCommands('install', '', { comment: 'install dependencies with {PKG} and {PKG}' })).toEqual([
`# install dependencies with npm and npm
npm install`,
`# install dependencies with yarn and yarn
yarn install`,
`# install dependencies with pnpm and pnpm
pnpm install`,
`# install dependencies with bun and bun
bun install`,
`# install dependencies with ni and ni
ni`,
])
})
})

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

0 comments on commit 3a017ff

Please sign in to comment.