Skip to content

Commit

Permalink
fix(bun): lowercase -D paremeter if the agent is bun (antfu-collectiv…
Browse files Browse the repository at this point in the history
…e#90)

Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
eggsy and antfu authored Jul 14, 2022
1 parent 6a229cd commit 299d8e7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ ni vite
# bun add vite
```

```
```bash
ni @types/node -D

# npm i @types/node -D
# yarn add @types/node -D
# pnpm add -D @types/node
# bun add -D @types/node
# bun add -d @types/node
```

```bash
Expand All @@ -55,6 +53,7 @@ ni --frozen
# npm ci
# yarn install --frozen-lockfile
# pnpm install --frozen-lockfile
# bun install --no-save
```

```bash
Expand Down Expand Up @@ -101,6 +100,7 @@ nr -
```bash
nx vitest

# (not available for bun)
# npx vitest
# yarn dlx vitest
# pnpm dlx vitest
Expand All @@ -113,6 +113,7 @@ nx vitest
```bash
nu

# (not available for bun)
# npm upgrade
# yarn upgrade
# pnpm update
Expand All @@ -121,7 +122,7 @@ nu
```bash
nu -i

# (not available for npm)
# (not available for npm & bun)
# yarn upgrade-interactive
# pnpm update -i
```
Expand Down Expand Up @@ -158,6 +159,7 @@ nci
# npm ci
# yarn install --frozen-lockfile
# pnpm install --frozen-lockfile
# bun install --no-save
```

if the corresponding node manager is not present, this command will install it globally along the way.
Expand All @@ -172,6 +174,7 @@ na
# npm
# yarn
# pnpm
# bun
```

```bash
Expand All @@ -180,6 +183,7 @@ na run foo
# npm run foo
# yarn run foo
# pnpm run foo
# bun run foo
```

<br>
Expand Down
7 changes: 3 additions & 4 deletions src/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ const bun = {
'frozen': 'bun install --no-save',
'global': 'bun add -g {0}',
'add': 'bun add {0}',
// bun doesn't include an upgrade and execute command as of now
'upgrade': 'bun add {0}',
'upgrade-interactive': 'bun add {0}',
'execute': 'echo Bun does not support execute command, yet.',
'upgrade': null,
'upgrade-interactive': null,
'execute': null,
'uninstall': 'bun remove {0}',
'global_uninstall': 'bun remove -g {0}',
}
Expand Down
4 changes: 4 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const parseNi = <Runner>((agent, args, ctx) => {
process.exit(0)
}

// bun use `-d` instead of `-D`, #90
if (agent === 'bun')
args = args.map(i => i === '-D' ? '-d' : i)

if (args.includes('-g'))
return getCommand(agent, 'global', exclude(args, '-g'))

Expand Down
2 changes: 2 additions & 0 deletions test/ni/bun.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ test('empty', _('', 'bun install'))

test('single add', _('axios', 'bun add axios'))

test('add dev', _('vite -D', 'bun add vite -d'))

test('multiple', _('eslint @types/node', 'bun add eslint @types/node'))

test('global', _('eslint -g', 'bun add -g eslint'))
Expand Down
8 changes: 4 additions & 4 deletions test/nu/bun.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { expect, test } from 'vitest'
import { parseNu } from '../../src/commands'

const agent = 'bun'
const _ = (arg: string, expected: string) => () => {
const _ = (arg: string, expected: string | null) => () => {
expect(
parseNu(agent, arg.split(' ').filter(Boolean)),
).toBe(
expected,
)
}

test('empty', _('', 'bun add'))

test('interactive', _('-i', 'bun add'))
test.fails('empty', _('', null))
test.fails('interactive', _('-i', null))
test.fails('interactive latest', _('-i --latest', null))

0 comments on commit 299d8e7

Please sign in to comment.