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

fix: metadata checks fail when migration file contains an element without a before #2299

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const getConfigurationArray = (content: ComponentConfigOutput[]): ComponentConfi

const getConfigurationPropertyName = (config: ComponentConfigOutput) => `${config.library}#${config.name}` + (config.properties.length ? ` ${config.properties[0].name}` : '');

const isMigrationConfigurationDataMatch = (config: ComponentConfigOutput, migrationData: MigrationConfigData) =>
const isMigrationConfigurationDataMatch = (config: ComponentConfigOutput, migrationData: MigrationConfigData, metadataType: string) =>
metadataType === 'CONFIG' &&
migrationData.libraryName === config.library
&& (!migrationData.configName || migrationData.configName === config.name)
&& (!migrationData.propertyName || config.properties[0]?.name === migrationData.propertyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export interface MetadataComparator<MetadataItem, MigrationMetadataItem, Metadat
* Returns true if a migration item matches a metadata item.
* @param metadataItem Metadata item
* @param migrationItem Migration item
* @param metadataType Type of the metadata
*/
isMigrationDataMatch: (metadataItem: MetadataItem, migrationItem: MigrationMetadataItem) => boolean;
isMigrationDataMatch: (metadataItem: MetadataItem, migrationItem: MigrationMetadataItem, metadataType: string) => boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ function checkMetadataFile<MetadataItem, MigrationMetadataItem, MetadataFile>(
continue;
}

const migrationMetadataValue = migrationData.find((metadata) => comparator.isMigrationDataMatch(lastValue, metadata.before));
const migrationMetadataValue = migrationData.find((metadata) => metadata.before && comparator.isMigrationDataMatch(lastValue, metadata.before, metadata.contentType));

if (!migrationMetadataValue) {
errors.push(new Error(`Property ${comparator.getIdentifier(lastValue)} has been modified but is not documented in the migration document`));
continue;
}

if (migrationMetadataValue.after) {
const isNewValueInNewMetadata = newMetadataArray.some((newValue) => comparator.isMigrationDataMatch(newValue, migrationMetadataValue.after!));
const isNewValueInNewMetadata = newMetadataArray.some((newValue) => comparator.isMigrationDataMatch(newValue, migrationMetadataValue.after!, migrationMetadataValue.contentType));
if (!isNewValueInNewMetadata) {
errors.push(new Error(`Property ${comparator.getIdentifier(lastValue)} has been modified but the new property is not present in the new metadata`));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const getLocalizationArray = (content: LocalizationMetadata) => content;

const getLocalizationName = (localization: JSONLocalization) => localization.key;

const isMigrationLocalizationDataMatch = (localization: JSONLocalization, migrationData: MigrationLocalizationMetadata) => getLocalizationName(localization) === migrationData.key;
const isMigrationLocalizationDataMatch = (localization: JSONLocalization, migrationData: MigrationLocalizationMetadata, metadataType: string) =>
metadataType === 'LOCALIZATION' && getLocalizationName(localization) === migrationData.key;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const getCssVariablesArray = (content: CssMetadata): CssVariable[] => Object.key

const getCssVariableName = (cssVariable: CssVariable) => cssVariable.name;

const isMigrationCssVariableDataMatch = (cssVariable: CssVariable, migrationData: MigrationStylingData) => getCssVariableName(cssVariable) === migrationData.name;
const isMigrationCssVariableDataMatch = (cssVariable: CssVariable, migrationData: MigrationStylingData, metadataType: string) =>
metadataType === 'STYLE' && getCssVariableName(cssVariable) === migrationData.name;

/**
* Comparator used to compare one version of styling metadata with another
Expand Down
Loading