mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
feat(fvm): Support v3 config file (#28665)
This commit is contained in:
parent
8965a398d7
commit
644c4a1733
5 changed files with 49 additions and 23 deletions
|
@ -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',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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',
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -1 +1 @@
|
|||
Keeps the `.fvm/fvm_config.json` file updated.
|
||||
Keeps the `.fvmrc` file or older `.fvm/fvm_config.json` file updated.
|
||||
|
|
7
lib/modules/manager/fvm/schema.ts
Normal file
7
lib/modules/manager/fvm/schema.ts
Normal 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>;
|
Loading…
Reference in a new issue