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();
|
).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a result', () => {
|
it('returns a result for .fvm/fvm_config.json', () => {
|
||||||
const res = extractPackageFile(
|
const res = extractPackageFile(
|
||||||
'{"flutterSdkVersion": "2.10.1", "flavors": {}}',
|
'{"flutterSdkVersion": "2.10.1", "flavors": {}}',
|
||||||
packageFile,
|
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(
|
const res = extractPackageFile(
|
||||||
'{"flutterSdkVersion": "stable", "flavors": {}}',
|
'{"flutterSdkVersion": "stable", "flavors": {}}',
|
||||||
packageFile,
|
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 { logger } from '../../../logger';
|
||||||
|
import { Json } from '../../../util/schema-utils';
|
||||||
import { FlutterVersionDatasource } from '../../datasource/flutter-version';
|
import { FlutterVersionDatasource } from '../../datasource/flutter-version';
|
||||||
import type { PackageDependency, PackageFileContent } from '../types';
|
import type { PackageDependency, PackageFileContent } from '../types';
|
||||||
|
import { FvmConfig } from './schema';
|
||||||
interface FvmConfig {
|
|
||||||
flutterSdkVersion: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function extractPackageFile(
|
export function extractPackageFile(
|
||||||
content: string,
|
content: string,
|
||||||
packageFile: string,
|
packageFile: string,
|
||||||
): PackageFileContent | null {
|
): PackageFileContent | null {
|
||||||
let fvmConfig: FvmConfig;
|
let flutterVersion: string | undefined;
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
logger.debug({ packageFile, err }, 'Invalid FVM config');
|
logger.debug({ packageFile, err }, 'Invalid FVM config');
|
||||||
return null;
|
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 = {
|
const dep: PackageDependency = {
|
||||||
depName: 'flutter',
|
depName: 'flutter',
|
||||||
currentValue: fvmConfig.flutterSdkVersion,
|
currentValue: flutterVersion,
|
||||||
datasource: FlutterVersionDatasource.id,
|
datasource: FlutterVersionDatasource.id,
|
||||||
packageName: 'flutter/flutter',
|
packageName: 'flutter/flutter',
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,6 @@ export { extractPackageFile } from './extract';
|
||||||
export const supportedDatasources = [FlutterVersionDatasource.id];
|
export const supportedDatasources = [FlutterVersionDatasource.id];
|
||||||
|
|
||||||
export const defaultConfig = {
|
export const defaultConfig = {
|
||||||
fileMatch: ['(^|/)\\.fvm/fvm_config\\.json$'],
|
fileMatch: ['(^|/)\\.fvm/fvm_config\\.json$', '(^|/)\\.fvmrc$'],
|
||||||
versioning: semverVersioning.id,
|
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