From 636bb590c36bf134040f59c6d06fb1c2d45081d0 Mon Sep 17 00:00:00 2001 From: Florian PAUL Date: Thu, 17 Oct 2024 16:01:05 +0200 Subject: [PATCH] fix: metadata checks fail when migration file contains an element without a before --- .../helpers/config-metadata-comparison.helper.ts | 3 ++- .../src/core/comparator/metadata-comparator.interface.ts | 3 ++- .../src/core/comparator/metadata-comparison.helper.ts | 4 ++-- .../helpers/localization-metadata-comparison.helper.ts | 3 ++- .../helpers/styling-metadata-comparison.helper.ts | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/@o3r/components/builders/metadata-check/helpers/config-metadata-comparison.helper.ts b/packages/@o3r/components/builders/metadata-check/helpers/config-metadata-comparison.helper.ts index 1664f2ff3b..c30f5b69d6 100644 --- a/packages/@o3r/components/builders/metadata-check/helpers/config-metadata-comparison.helper.ts +++ b/packages/@o3r/components/builders/metadata-check/helpers/config-metadata-comparison.helper.ts @@ -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); diff --git a/packages/@o3r/extractors/src/core/comparator/metadata-comparator.interface.ts b/packages/@o3r/extractors/src/core/comparator/metadata-comparator.interface.ts index 08cf3981b8..0ed1bfc4af 100644 --- a/packages/@o3r/extractors/src/core/comparator/metadata-comparator.interface.ts +++ b/packages/@o3r/extractors/src/core/comparator/metadata-comparator.interface.ts @@ -29,8 +29,9 @@ export interface MetadataComparator boolean; + isMigrationDataMatch: (metadataItem: MetadataItem, migrationItem: MigrationMetadataItem, metadataType: string) => boolean; } /** diff --git a/packages/@o3r/extractors/src/core/comparator/metadata-comparison.helper.ts b/packages/@o3r/extractors/src/core/comparator/metadata-comparison.helper.ts index f546a11fbd..6da496725d 100644 --- a/packages/@o3r/extractors/src/core/comparator/metadata-comparison.helper.ts +++ b/packages/@o3r/extractors/src/core/comparator/metadata-comparison.helper.ts @@ -33,7 +33,7 @@ function checkMetadataFile( 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`)); @@ -41,7 +41,7 @@ function checkMetadataFile( } 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; diff --git a/packages/@o3r/localization/builders/metadata-check/helpers/localization-metadata-comparison.helper.ts b/packages/@o3r/localization/builders/metadata-check/helpers/localization-metadata-comparison.helper.ts index 84ae66b3e2..9583f7502b 100644 --- a/packages/@o3r/localization/builders/metadata-check/helpers/localization-metadata-comparison.helper.ts +++ b/packages/@o3r/localization/builders/metadata-check/helpers/localization-metadata-comparison.helper.ts @@ -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; /** diff --git a/packages/@o3r/styling/builders/metadata-check/helpers/styling-metadata-comparison.helper.ts b/packages/@o3r/styling/builders/metadata-check/helpers/styling-metadata-comparison.helper.ts index b39574c8ad..e64dbf56e2 100644 --- a/packages/@o3r/styling/builders/metadata-check/helpers/styling-metadata-comparison.helper.ts +++ b/packages/@o3r/styling/builders/metadata-check/helpers/styling-metadata-comparison.helper.ts @@ -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