diff --git a/.changeset/dull-pillows-unite.md b/.changeset/dull-pillows-unite.md new file mode 100644 index 0000000000..2a4dcd2d3e --- /dev/null +++ b/.changeset/dull-pillows-unite.md @@ -0,0 +1,5 @@ +--- +"@janus-idp/cli": patch +--- + +fix(cli): add a flag to relax semver checks. This change updates the CLI to add an option to relax the semver checks on a per-package basis to cater for plugins where it is known there should be runtime compabability due to no interface changes. 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 d80c039e02..6fec606c95 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 @@ -60,6 +60,7 @@ export async function backend(opts: OptionValues): Promise { const packagesToEmbed = (opts.embedPackage || []) as string[]; const allowNative = (opts.allowNativePackage || []) as string[]; const suppressNative = (opts.suppressNativePackage || []) as string[]; + const ignoreVersionCheck = (opts.ignoreVersionCheck || []) as string[]; const monoRepoPackages = await getPackages(paths.targetDir); const embeddedResolvedPackages = await searchEmbedded( pkg, @@ -302,7 +303,11 @@ throw new Error( `Hoisting peer dependencies of embedded packages to the main package`, ); const mainPeerDependencies = mainPkg.peerDependencies || {}; - addToMainDependencies(embeddedPeerDependencies, mainPeerDependencies); + addToMainDependencies( + embeddedPeerDependencies, + mainPeerDependencies, + ignoreVersionCheck, + ); if (Object.keys(mainPeerDependencies).length > 0) { mainPkg.peerDependencies = mainPeerDependencies; } 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 2e51bac878..2156a23215 100644 --- a/packages/cli/src/commands/export-dynamic-plugin/backend-utils.ts +++ b/packages/cli/src/commands/export-dynamic-plugin/backend-utils.ts @@ -21,6 +21,8 @@ import semver from 'semver'; import path from 'path'; +import { Task } from '../../lib/tasks'; + export function addToDependenciesForModule( dependency: { name: string; version: string }, dependencies: { [key: string]: string }, @@ -43,24 +45,22 @@ export function addToDependenciesForModule( existingDependencyMinVersion && semver.satisfies(existingDependencyMinVersion, dependency.version) ) { - console.log( + Task.log( `Several compatible versions ('${existingDependencyVersion}', '${dependency.version}') of the same transitive dependency ('${dependency.name}') for embedded module ('${module}'): keeping '${existingDependencyVersion}'`, ); return; } - const newDependencyMinVersion = semver.minVersion(dependency.version); if ( newDependencyMinVersion && semver.satisfies(newDependencyMinVersion, existingDependencyVersion) ) { dependencies[dependency.name] = dependency.version; - console.log( + Task.log( `Several compatible versions ('${existingDependencyVersion}', '${dependency.version}') of the same transitive dependency ('${dependency.name}') for embedded module ('${module}'): keeping '${dependency.version}'`, ); return; } - throw new Error( `Several incompatible versions ('${existingDependencyVersion}', '${dependency.version}') of the same transitive dependency ('${dependency.name}') for embedded module ('${module}')`, ); @@ -69,6 +69,7 @@ export function addToDependenciesForModule( export function addToMainDependencies( dependenciesToAdd: { [key: string]: string }, mainDependencies: { [key: string]: string }, + ignoreVersionCheck: string[] = [], ): void { for (const dep in dependenciesToAdd) { if (!Object.prototype.hasOwnProperty.call(dependenciesToAdd, dep)) { @@ -81,18 +82,23 @@ export function addToMainDependencies( } if (existingVersion !== dependenciesToAdd[dep]) { const existingMinVersion = semver.minVersion(existingVersion); - if ( existingMinVersion && semver.satisfies(existingMinVersion, dependenciesToAdd[dep]) ) { - console.log( + Task.log( `The version of a dependency ('${dep}') of an embedded module differs from the main module's dependencies: '${dependenciesToAdd[dep]}', '${existingVersion}': keeping it as it is compatible`, ); } else { - throw new Error( - `The version of a dependency ('${dep}') of an embedded module conflicts with main module dependencies: '${dependenciesToAdd[dep]}', '${existingVersion}': cannot proceed!`, - ); + if (!ignoreVersionCheck.includes(dep)) { + throw new Error( + `The version of a dependency ('${dep}') of an embedded module conflicts with main module dependencies: '${dependenciesToAdd[dep]}', '${existingVersion}': cannot proceed!`, + ); + } else { + Task.log( + `The version of a dependency ('${dep}') of an embedded module conflicts with the main module's dependencies: '${dependenciesToAdd[dep]}', '${existingVersion}': however this has been overridden`, + ); + } } } } diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index ac9b14ff1c..faa81320d0 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -113,6 +113,10 @@ export function registerScriptCommand(program: Command) { '--suppress-native-package [package-name...]', 'Optional list of native package names to be excluded from the exported plugin', ) + .option( + '--ignore-version-check [packageName...]', + 'Optional list of package names to ignore when doing semver dependency checks', + ) .option( '--no-install', 'Do not run `yarn install` to fill the dynamic plugin `node_modules` folder (backend plugin only).',