From e064c5e40da736aeb598eec9897e9f9313dc4477 Mon Sep 17 00:00:00 2001 From: Ghislain Piot Date: Sat, 7 Sep 2024 16:11:17 +0000 Subject: [PATCH] feat(manager): add bun-version manager (#29998) Co-authored-by: Rhys Arkins Co-authored-by: Sebastian Poxhofer --- lib/modules/manager/api.ts | 2 + lib/modules/manager/bun-version/index.spec.ts | 57 +++++++++++++++++++ lib/modules/manager/bun-version/index.ts | 36 ++++++++++++ lib/modules/manager/bun-version/readme.md | 1 + 4 files changed, 96 insertions(+) create mode 100644 lib/modules/manager/bun-version/index.spec.ts create mode 100644 lib/modules/manager/bun-version/index.ts create mode 100644 lib/modules/manager/bun-version/readme.md diff --git a/lib/modules/manager/api.ts b/lib/modules/manager/api.ts index 664444223f467c..8e7271cd3aa320 100644 --- a/lib/modules/manager/api.ts +++ b/lib/modules/manager/api.ts @@ -13,6 +13,7 @@ import * as bitbucketPipelines from './bitbucket-pipelines'; import * as bitrise from './bitrise'; import * as buildkite from './buildkite'; import * as bun from './bun'; +import * as bunVersion from './bun-version'; import * as bundler from './bundler'; import * as cake from './cake'; import * as cargo from './cargo'; @@ -115,6 +116,7 @@ api.set('bitbucket-pipelines', bitbucketPipelines); api.set('bitrise', bitrise); api.set('buildkite', buildkite); api.set('bun', bun); +api.set('bun-version', bunVersion); api.set('bundler', bundler); api.set('cake', cake); api.set('cargo', cargo); diff --git a/lib/modules/manager/bun-version/index.spec.ts b/lib/modules/manager/bun-version/index.spec.ts new file mode 100644 index 00000000000000..038c31e48b1dc4 --- /dev/null +++ b/lib/modules/manager/bun-version/index.spec.ts @@ -0,0 +1,57 @@ +import { extractPackageFile } from '.'; + +describe('modules/manager/bun-version/index', () => { + describe('extractPackageFile()', () => { + it('returns a result', () => { + const res = extractPackageFile('1.1.15\n'); + expect(res?.deps).toEqual([ + { + depName: 'Bun', + packageName: 'bun', + currentValue: '1.1.15', + datasource: 'npm', + }, + ]); + }); + + it('handles empty files', () => { + const res = extractPackageFile(''); + expect(res).toBeNull(); + }); + + it('handles no newline at the end', () => { + const res = extractPackageFile('1.1.15'); + expect(res).not.toBeNull(); + }); + + it('handles multiple lines', () => { + const res = extractPackageFile('1.1.15\n1.1.16\n'); + expect(res).toBeNull(); + }); + + it('handles invalid versions', () => { + const res = extractPackageFile('notaversion\n'); + expect(res?.deps).toEqual([ + { + depName: 'Bun', + packageName: 'bun', + currentValue: 'notaversion', + datasource: 'npm', + skipReason: 'invalid-version', + }, + ]); + }); + + it('handles ranges', () => { + const res = extractPackageFile('1.0\n'); + expect(res?.deps).toEqual([ + { + depName: 'Bun', + packageName: 'bun', + currentValue: '1.0', + datasource: 'npm', + }, + ]); + }); + }); +}); diff --git a/lib/modules/manager/bun-version/index.ts b/lib/modules/manager/bun-version/index.ts new file mode 100644 index 00000000000000..80cc49e96f7b17 --- /dev/null +++ b/lib/modules/manager/bun-version/index.ts @@ -0,0 +1,36 @@ +import type { Category } from '../../../constants'; +import { NpmDatasource } from '../../datasource/npm'; +import { id, isValid } from '../../versioning/npm'; + +import type { PackageDependency, PackageFileContent } from '../types'; + +export const supportedDatasources = [NpmDatasource.id]; + +export const defaultConfig = { + fileMatch: ['(^|/)\\.bun-version$'], + versioning: id, +}; + +export const categories: Category[] = ['js']; + +export function extractPackageFile(content: string): PackageFileContent | null { + if (!content) { + return null; + } + + if (content.split('\n').length > 2) { + return null; + } + + const dep: PackageDependency = { + depName: 'Bun', + packageName: 'bun', + currentValue: content.trim(), + datasource: NpmDatasource.id, + }; + + if (!isValid(content.trim())) { + dep.skipReason = 'invalid-version'; + } + return { deps: [dep] }; +} diff --git a/lib/modules/manager/bun-version/readme.md b/lib/modules/manager/bun-version/readme.md new file mode 100644 index 00000000000000..8fea47b4721afc --- /dev/null +++ b/lib/modules/manager/bun-version/readme.md @@ -0,0 +1 @@ +Simply keeps the `.bun-version` file updated.