Skip to content

Commit

Permalink
Add run to build command when using bun
Browse files Browse the repository at this point in the history
If the package manager is bun and the command is build generate 'bun run
build' as the command to invoke the build script instead of the built-in
'bun build' command.
  • Loading branch information
Hornwitser committed Nov 17, 2024
1 parent 9201bdb commit 65d53d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions __test__/getCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ describe('getCommand', () => {
expect(getCommand('pnpm', 'dev')).toBe('pnpm dev')
expect(getCommand('pnpm', 'build')).toBe('pnpm build')
})
it('should generate the correct command for bun', () => {
expect(getCommand('bun', 'install')).toBe('bun install')
expect(getCommand('bun', 'dev')).toBe('bun dev')
expect(getCommand('bun', 'build')).toBe('bun run build')

Check failure on line 23 in __test__/getCommand.spec.ts

View workflow job for this annotation

GitHub Actions / Build the package

__test__/getCommand.spec.ts > getCommand > should generate the correct command for bun

AssertionError: expected '${packageManager} run build' to be 'bun run build' // Object.is equality Expected: "bun run build" Received: "${packageManager} run build" ❯ __test__/getCommand.spec.ts:23:40
})
})
5 changes: 5 additions & 0 deletions utils/getCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ export default function getCommand(packageManager: string, scriptName: string, a
if (scriptName === 'install') {
return packageManager === 'yarn' ? 'yarn' : `${packageManager} install`
}
if (scriptName === 'build') {
return packageManager === 'npm' || packageManager === 'bun'
? '${packageManager} run build'
: `${packageManager} build`
}

if (args) {
return packageManager === 'npm'
Expand Down

0 comments on commit 65d53d2

Please sign in to comment.