From 374eef52cfd4b54cee25323a2bb1dee83433b08c Mon Sep 17 00:00:00 2001 From: OpenShift Cherrypick Robot Date: Tue, 21 Jan 2025 13:56:28 +0100 Subject: [PATCH] fix(cli): extend --ignore-version-check [release-1.4] (#2619) fix(cli): extend --ignore-version-check This change updates the cli's --ignore-version-check flag to also ignore the check performed on a embedded transitive dependencies that are moved to peer dependencies, when it is known that the mismatch is runtime compatible. Signed-off-by: Stan Lewis Co-authored-by: Stan Lewis --- .changeset/stale-penguins-tan.md | 7 +++++ .../backend-embed-as-code.ts | 10 +++---- .../backend-embed-as-dependencies.ts | 11 ++++---- .../export-dynamic-plugin/backend-utils.ts | 28 +++++++++++++------ 4 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 .changeset/stale-penguins-tan.md diff --git a/.changeset/stale-penguins-tan.md b/.changeset/stale-penguins-tan.md new file mode 100644 index 0000000000..0fc5d685a4 --- /dev/null +++ b/.changeset/stale-penguins-tan.md @@ -0,0 +1,7 @@ +--- +"@janus-idp/cli": patch +--- + +fix(cli): extend --ignore-version-check + +This change updates the cli's --ignore-version-check flag to also ignore the check performed on an embedded transitive dependencies that are moved to peer dependencies, when it is known that the mismatch is runtime compatible. diff --git a/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-code.ts b/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-code.ts index a3dc08467a..b417ebb4a1 100644 --- a/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-code.ts +++ b/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-code.ts @@ -168,14 +168,14 @@ export async function backend( embedModules({ filter: filter, addDependency: (embeddedModule, dependencyName, newDependencyVersion) => - addToDependenciesForModule( - { + addToDependenciesForModule({ + dependency: { name: dependencyName, version: newDependencyVersion, }, - dependenciesToAdd, - embeddedModule, - ), + dependencies: dependenciesToAdd, + module: embeddedModule, + }), }), ); diff --git a/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts b/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts index 6fec606c95..5fcc152b4b 100644 --- a/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts +++ b/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts @@ -221,11 +221,12 @@ throw new Error( if (embeddedPkg.peerDependencies) { Object.entries(embeddedPkg.peerDependencies).forEach( ([name, version]) => { - addToDependenciesForModule( - { name, version }, - embeddedPeerDependencies, - embeddedPkg.name, - ); + addToDependenciesForModule({ + dependency: { name, version }, + dependencies: embeddedPeerDependencies, + ignoreVersionCheck, + module: embeddedPkg.name, + }); }, ); } diff --git a/packages/cli/src/commands/export-dynamic-plugin/backend-utils.ts b/packages/cli/src/commands/export-dynamic-plugin/backend-utils.ts index 2156a23215..00a1894252 100644 --- a/packages/cli/src/commands/export-dynamic-plugin/backend-utils.ts +++ b/packages/cli/src/commands/export-dynamic-plugin/backend-utils.ts @@ -23,11 +23,17 @@ import path from 'path'; import { Task } from '../../lib/tasks'; -export function addToDependenciesForModule( - dependency: { name: string; version: string }, - dependencies: { [key: string]: string }, - module: string, -): void { +export function addToDependenciesForModule({ + dependency, + dependencies, + ignoreVersionCheck = [], + module, +}: { + dependency: { name: string; version: string }; + dependencies: { [key: string]: string }; + ignoreVersionCheck?: string[]; + module: string; +}): void { const existingDependencyVersion = dependencies[dependency.name]; if (existingDependencyVersion === undefined) { dependencies[dependency.name] = dependency.version; @@ -61,9 +67,15 @@ export function addToDependenciesForModule( ); return; } - throw new Error( - `Several incompatible versions ('${existingDependencyVersion}', '${dependency.version}') of the same transitive dependency ('${dependency.name}') for embedded module ('${module}')`, - ); + if (!ignoreVersionCheck.includes(dependency.name)) { + throw new Error( + `Several incompatible versions ('${existingDependencyVersion}', '${dependency.version}') of the same transitive dependency ('${dependency.name}') for embedded module ('${module}')`, + ); + } else { + Task.log( + `Several incompatible versions ('${existingDependencyVersion}', '${dependency.version}') of the same transitive dependency ('${dependency.name}') for embedded module ('${module}') however this has been overridden to use '${dependency.version}'`, + ); + } } export function addToMainDependencies(