From 6f8785097de00e763fd81f17689c088ed39cdf8b Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Mon, 2 Oct 2023 17:45:22 +0200 Subject: [PATCH] feat: detect bun as runtime (#5300) * feat: detect bun as runtime * chore: export bun as runtime * chore: fix test message --- packages/build-info/src/runtime/bun.test.ts | 27 +++++++++++++++++++++ packages/build-info/src/runtime/bun.ts | 7 ++++++ packages/build-info/src/runtime/index.ts | 3 ++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 packages/build-info/src/runtime/bun.test.ts create mode 100644 packages/build-info/src/runtime/bun.ts diff --git a/packages/build-info/src/runtime/bun.test.ts b/packages/build-info/src/runtime/bun.test.ts new file mode 100644 index 0000000000..65e7d4e789 --- /dev/null +++ b/packages/build-info/src/runtime/bun.test.ts @@ -0,0 +1,27 @@ +import { beforeEach, expect, test } from 'vitest' + +import { mockFileSystem } from '../../tests/mock-file-system.js' +import { NodeFS } from '../node/file-system.js' +import { Project } from '../project.js' + +beforeEach((ctx) => { + ctx.fs = new NodeFS() +}) + +test('detects node when bunfig.toml is present', async ({ fs }) => { + const cwd = mockFileSystem({ + 'bunfig.toml': '', + }) + + const detected = await new Project(fs, cwd).detectRuntime() + expect(detected[0].name).toBe('Bun') +}) + +test('detects node when bun.lockb is present', async ({ fs }) => { + const cwd = mockFileSystem({ + 'bun.lockb': '', + }) + + const detected = await new Project(fs, cwd).detectRuntime() + expect(detected[0].name).toBe('Bun') +}) diff --git a/packages/build-info/src/runtime/bun.ts b/packages/build-info/src/runtime/bun.ts new file mode 100644 index 0000000000..8b11e6f667 --- /dev/null +++ b/packages/build-info/src/runtime/bun.ts @@ -0,0 +1,7 @@ +import { LangRuntime } from './runtime.js' + +export class Bun extends LangRuntime { + id = 'bun' + name = 'Bun' + configFiles = ['bun.lockb', 'bunfig.toml'] +} diff --git a/packages/build-info/src/runtime/index.ts b/packages/build-info/src/runtime/index.ts index 9e832007c8..080500ba4c 100644 --- a/packages/build-info/src/runtime/index.ts +++ b/packages/build-info/src/runtime/index.ts @@ -1,4 +1,5 @@ import { Brew } from './brew.js' +import { Bun } from './bun.js' import { Emacs } from './cask.js' import { Go } from './go.js' import { Java } from './java.js' @@ -9,4 +10,4 @@ import { Ruby } from './ruby.js' import { Rust } from './rust.js' import { Swift } from './swift.js' -export const runtimes = [Node, Ruby, Brew, Emacs, Go, Java, Php, Rust, Swift, Python] +export const runtimes = [Node, Ruby, Brew, Bun, Emacs, Go, Java, Php, Rust, Swift, Python]