feat(fvm): Support v3 config file (#28665)

This commit is contained in:
Lennart Schmidt 2024-04-29 15:09:44 +02:00 committed by GitHub
parent 8965a398d7
commit 644c4a1733
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 49 additions and 23 deletions

View file

@ -23,7 +23,7 @@ describe('modules/manager/fvm/extract', () => {
).toBeNull();
});
it('returns a result', () => {
it('returns a result for .fvm/fvm_config.json', () => {
const res = extractPackageFile(
'{"flutterSdkVersion": "2.10.1", "flavors": {}}',
packageFile,
@ -38,7 +38,19 @@ describe('modules/manager/fvm/extract', () => {
]);
});
it('supports non range', () => {
it('returns a result for .fvmrc', () => {
const res = extractPackageFile('{"flutter": "2.10.1"}', packageFile);
expect(res?.deps).toEqual([
{
currentValue: '2.10.1',
datasource: 'flutter-version',
depName: 'flutter',
packageName: 'flutter/flutter',
},
]);
});
it('supports non range for .fvm/fvm_config.json', () => {
const res = extractPackageFile(
'{"flutterSdkVersion": "stable", "flavors": {}}',
packageFile,
@ -52,5 +64,17 @@ describe('modules/manager/fvm/extract', () => {
},
]);
});
it('supports non range for .fvmrc', () => {
const res = extractPackageFile('{"flutter": "stable"}', packageFile);
expect(res?.deps).toEqual([
{
currentValue: 'stable',
datasource: 'flutter-version',
depName: 'flutter',
packageName: 'flutter/flutter',
},
]);
});
});
});

View file

@ -1,38 +1,33 @@
import is from '@sindresorhus/is';
import { logger } from '../../../logger';
import { Json } from '../../../util/schema-utils';
import { FlutterVersionDatasource } from '../../datasource/flutter-version';
import type { PackageDependency, PackageFileContent } from '../types';
interface FvmConfig {
flutterSdkVersion: string;
}
import { FvmConfig } from './schema';
export function extractPackageFile(
content: string,
packageFile: string,
): PackageFileContent | null {
let fvmConfig: FvmConfig;
let flutterVersion: string | undefined;
try {
fvmConfig = JSON.parse(content);
const config = Json.pipe(FvmConfig).parse(content);
flutterVersion = config.flutter ?? config.flutterSdkVersion;
if (!flutterVersion) {
logger.debug(
{ contents: config },
'FVM config does not have a flutter version specified',
);
return null;
}
} catch (err) {
logger.debug({ packageFile, err }, 'Invalid FVM config');
return null;
}
if (!fvmConfig.flutterSdkVersion) {
logger.debug(
{ contents: fvmConfig },
'FVM config does not have flutterSdkVersion specified',
);
return null;
} else if (!is.string(fvmConfig.flutterSdkVersion)) {
logger.debug({ contents: fvmConfig }, 'flutterSdkVersion must be a string');
return null;
}
const dep: PackageDependency = {
depName: 'flutter',
currentValue: fvmConfig.flutterSdkVersion,
currentValue: flutterVersion,
datasource: FlutterVersionDatasource.id,
packageName: 'flutter/flutter',
};

View file

@ -6,6 +6,6 @@ export { extractPackageFile } from './extract';
export const supportedDatasources = [FlutterVersionDatasource.id];
export const defaultConfig = {
fileMatch: ['(^|/)\\.fvm/fvm_config\\.json$'],
fileMatch: ['(^|/)\\.fvm/fvm_config\\.json$', '(^|/)\\.fvmrc$'],
versioning: semverVersioning.id,
};

View file

@ -1 +1 @@
Keeps the `.fvm/fvm_config.json` file updated.
Keeps the `.fvmrc` file or older `.fvm/fvm_config.json` file updated.

View file

@ -0,0 +1,7 @@
import { z } from 'zod';
export const FvmConfig = z.object({
flutterSdkVersion: z.string().optional(),
flutter: z.string().optional(),
});
export type FvmConfig = z.infer<typeof FvmConfig>;