Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,17 @@ export class GDF {
get bunVersion() {
if (this.#packager !== 'bun') return

const pinned = this.#pj.packageManager?.match(/^bun@(\d+\.\d+\.\d+)(?:\+[^ ]+)?$/)?.[1]
if (pinned) return pinned

try {
return execSync('bun --version', { encoding: 'utf8' })
const version = execSync('bun --version', { encoding: 'utf8' })
.match(/\d+\.\d+\.\d+/)?.[0]
if (version) return version
} catch {
}

return '1'
}

// classic version of yarn (installed by default)
Expand Down
16 changes: 16 additions & 0 deletions test/gdf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,22 @@ describe('gdf: packagers', function() {
expect(sandbox().read('Dockerfile')).to.include('ARG PNPM_VERSION=9.1.2')
})

it('generates a usable Bun image without a local Bun installation', async function() {
sandbox().write('bun.lock', '')
await sandbox().run({ packageManager: 'bun@1.2.20' })
expect(sandbox().read('Dockerfile')).to.include('ARG BUN_VERSION=1.2.20\n')

await sandbox().run({})
Comment thread
tomr-fly marked this conversation as resolved.
Resolved
expect(sandbox().read('Dockerfile')).to.include('ARG BUN_VERSION=1\n')
})

it('prefers the project Bun version over the installed version', async function() {
sandbox().stub('bun', 'echo 1.1.20\n')
sandbox().write('bun.lock', '')
await sandbox().run({ packageManager: 'bun@1.2.20' })
expect(sandbox().read('Dockerfile')).to.include('ARG BUN_VERSION=1.2.20\n')
})

for (const lockfile of ['bun.lockb', 'bun.lock']) {
it(`uses bun with a ${lockfile}`, async function() {
sandbox().stub('bun', 'echo 1.1.20\n')
Expand Down
Loading