Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(migrations): migrate depTypes #16421

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
87d711d
migrate depTypes
RahulGautamSingh Jul 4, 2022
3f97d9e
migrate more depTypes
RahulGautamSingh Jul 5, 2022
4bd0c37
Revert "migrate more depTypes"
RahulGautamSingh Jul 5, 2022
6fec390
more migrations
RahulGautamSingh Jul 5, 2022
ff72b58
Update dep-types-migration.ts
RahulGautamSingh Jul 5, 2022
ac9d94b
Update dep-types-migration.ts
RahulGautamSingh Jul 5, 2022
ebcfa89
Merge branch 'main' into refactor/migrations_depTypes
RahulGautamSingh Jul 8, 2022
7dd9a9b
refactor: add tests and revert some changes
RahulGautamSingh Jul 8, 2022
e0b4c3f
add separate class for each dep-type
RahulGautamSingh Jul 10, 2022
9927a16
Update peer-dependencies-migration.ts
RahulGautamSingh Jul 10, 2022
ecc63a0
add tests
RahulGautamSingh Jul 10, 2022
4c57a31
update types
RahulGautamSingh Jul 11, 2022
f557f9f
modify test
RahulGautamSingh Jul 11, 2022
14a5eec
Merge branch 'main' into refactor/migrations_depTypes
RahulGautamSingh Jul 12, 2022
c2badcd
- Use regex to detect all depTypes
RahulGautamSingh Jul 15, 2022
c221397
Merge branch 'main' into refactor/migrations_depTypes
RahulGautamSingh Jul 15, 2022
32b3550
add new interface for depTypes
RahulGautamSingh Jul 15, 2022
5310f62
remove if-block
RahulGautamSingh Jul 16, 2022
41ff03c
Merge branch 'main' into refactor/migrations_depTypes
RahulGautamSingh Jul 16, 2022
e4ad9f6
Update lib/config/migrations/custom/dep-types-migration.ts
RahulGautamSingh Jul 19, 2022
561bb61
run prettier
RahulGautamSingh Jul 19, 2022
eb7b957
Update lib/config/migrations/custom/dep-types-migration.ts
viceice Jul 21, 2022
6433c8a
Merge branch 'main' into refactor/migrations_depTypes
viceice Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 9 additions & 32 deletions lib/config/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,9 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig {
'optionalDependencies',
'peerDependencies',
];

for (const [key, val] of Object.entries(newConfig)) {
if (depTypes.includes(key)) {
migratedConfig.packageRules = is.array(migratedConfig.packageRules)
? migratedConfig.packageRules
: [];
const depTypePackageRule = migrateConfig(
val as RenovateConfig
).migratedConfig;
depTypePackageRule.depTypeList = [key];
delete depTypePackageRule.packageRules;
migratedConfig.packageRules.push(depTypePackageRule);
delete migratedConfig[key];
} else if (is.string(val) && val.includes('{{baseDir}}')) {
if (is.string(val) && val.includes('{{baseDir}}')) {
migratedConfig[key] = val.replace(
regEx(/{{baseDir}}/g),
'{{packageFileDir}}'
Expand All @@ -70,26 +60,6 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig {
'{{semanticPrefix}}',
'{{#if semanticCommitType}}{{semanticCommitType}}{{#if semanticCommitScope}}({{semanticCommitScope}}){{/if}}: {{/if}}'
);
} else if (key === 'depTypes' && is.array(val)) {
val.forEach((depType) => {
if (is.object(depType) && !is.array(depType)) {
const depTypeName = (depType as any).depType;
if (depTypeName) {
migratedConfig.packageRules = is.array(
migratedConfig.packageRules
)
? migratedConfig.packageRules
: [];
const newPackageRule = migrateConfig(
depType as RenovateConfig
).migratedConfig;
delete newPackageRule.depType;
newPackageRule.depTypeList = [depTypeName];
migratedConfig.packageRules.push(newPackageRule);
}
}
});
delete migratedConfig.depTypes;
} else if (optionTypes[key] === 'object' && is.boolean(val)) {
migratedConfig[key] = { enabled: val };
} else if (optionTypes[key] === 'boolean') {
Expand All @@ -110,6 +80,13 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig {
for (const item of migratedConfig[key] as unknown[]) {
if (is.object(item) && !is.array(item)) {
const arrMigrate = migrateConfig(item as RenovateConfig);
if (
(item as PackageRule).matchDepTypes?.some((depType) =>
depTypes.includes(depType)
)
) {
delete arrMigrate.migratedConfig.packageRules;
viceice marked this conversation as resolved.
Show resolved Hide resolved
}
newArray.push(arrMigrate.migratedConfig);
} else {
newArray.push(item);
Expand Down
90 changes: 90 additions & 0 deletions lib/config/migrations/custom/dep-types-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { DepTypesMigration } from './dep-types-migration';

describe('config/migrations/custom/dep-types-migration', () => {
it('should only add depTypes to packageRules', () => {
expect(DepTypesMigration).toMigrate(
{
peerDependencies: {
versionStrategy: 'widen',
},
dependencies: {
versionStrategy: 'widen',
},
engines: {
rangeStrategy: 'auto',
},
optionalDependencies: {
versionStrategy: 'widen',
},
devDependencies: {
versionStrategy: 'widen',
},
depTypes: [
'dependencies',
{
depType: 'optionalDependencies',
respectLatest: false,
},
],
packageRules: [
{
packagePatterns: '^(@angular|typescript)' as never,
groupName: ['angular packages'] as never,
excludedPackageNames: 'foo',
},
{
packageNames: ['foo'],
packageRules: [
{
depTypeList: ['bar'],
automerge: true,
},
],
},
],
},
{
packageRules: [
{
packagePatterns: '^(@angular|typescript)' as never,
groupName: ['angular packages'] as never,
excludedPackageNames: 'foo',
},
{
packageNames: ['foo'],
packageRules: [
{
depTypeList: ['bar'],
automerge: true,
},
],
},
{
matchDepTypes: ['peerDependencies'],
versionStrategy: 'widen',
},
{
matchDepTypes: ['dependencies'],
versionStrategy: 'widen',
},
{
matchDepTypes: ['engines'],
rangeStrategy: 'auto',
},
{
matchDepTypes: ['optionalDependencies'],
versionStrategy: 'widen',
},
{
matchDepTypes: ['devDependencies'],
versionStrategy: 'widen',
},
{
matchDepTypes: ['optionalDependencies'],
respectLatest: false,
},
],
}
);
});
});
36 changes: 36 additions & 0 deletions lib/config/migrations/custom/dep-types-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import is from '@sindresorhus/is';
import type { PackageRule, PackageRuleInputConfig } from '../../types';
import { AbstractMigration } from '../base/abstract-migration';

interface DepTypesRule extends PackageRule, PackageRuleInputConfig {}
export class DepTypesMigration extends AbstractMigration {
viceice marked this conversation as resolved.
Show resolved Hide resolved
override readonly deprecated = true;
override readonly propertyName = /.*[d|D]ependencies$|engines$|depTypes$/;
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

override run(value: unknown, key: string): void {
const packageRules: PackageRule[] = this.get('packageRules') ?? [];
if (is.nonEmptyObject(value) && !is.array(value)) {
packageRules.push({
matchDepTypes: [key],
...value,
} as PackageRule);
}

if (is.array(value)) {
for (const depType of value as DepTypesRule[]) {
if (is.object(depType) && !is.array(depType)) {
const depTypeName = depType.depType;
if (depTypeName) {
delete depType.depType;
depType.matchDepTypes = [depTypeName];
packageRules.push({ ...(depType as PackageRule) });
}
}
}
}

if (packageRules.length) {
this.setHard('packageRules', packageRules);
}
}
}
2 changes: 2 additions & 0 deletions lib/config/migrations/migrations-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { BranchNameMigration } from './custom/branch-name-migration';
import { BranchPrefixMigration } from './custom/branch-prefix-migration';
import { CompatibilityMigration } from './custom/compatibility-migration';
import { ComposerIgnorePlatformReqsMigration } from './custom/composer-ignore-platform-reqs-migration';
import { DepTypesMigration } from './custom/dep-types-migration';
import { DryRunMigration } from './custom/dry-run-migration';
import { EnabledManagersMigration } from './custom/enabled-managers-migration';
import { ExtendsMigration } from './custom/extends-migration';
Expand Down Expand Up @@ -131,6 +132,7 @@ export class MigrationsService {
DryRunMigration,
RequireConfigMigration,
PackageFilesMigration,
DepTypesMigration,
PackageRulesMigration,
NodeMigration,
SemanticPrefixMigration,
Expand Down