Skip to content

Commit

Permalink
feat(manager): add bun-version manager (#29998)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <[email protected]>
Co-authored-by: Sebastian Poxhofer <[email protected]>
  • Loading branch information
3 people authored Sep 7, 2024
1 parent a91d646 commit e064c5e
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/modules/manager/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
57 changes: 57 additions & 0 deletions lib/modules/manager/bun-version/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
},
]);
});
});
});
36 changes: 36 additions & 0 deletions lib/modules/manager/bun-version/index.ts
Original file line number Diff line number Diff line change
@@ -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] };
}
1 change: 1 addition & 0 deletions lib/modules/manager/bun-version/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simply keeps the `.bun-version` file updated.

0 comments on commit e064c5e

Please sign in to comment.