From a1ead00111d6c1cfefd0637d54955a118c547739 Mon Sep 17 00:00:00 2001 From: Chris Manning Date: Thu, 20 Apr 2023 15:42:02 +1200 Subject: [PATCH 1/2] fix(core): whitelist registries that support obtaining migration config via 'npm view' Registries other than npmjs.org may not support obtaining non standard package metadata via 'npm view'. In the event that migration config is not returned when using other registries, migration will fallback to determining config using install. closed #16387, #10223 --- packages/nx/src/command-line/migrate.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/command-line/migrate.ts b/packages/nx/src/command-line/migrate.ts index 5bc0f16831430..b5576936a2580 100644 --- a/packages/nx/src/command-line/migrate.ts +++ b/packages/nx/src/command-line/migrate.ts @@ -13,6 +13,7 @@ import { satisfies, valid, } from 'semver'; +import { URL } from 'url'; import { promisify } from 'util'; import { MigrationsJson, @@ -933,14 +934,29 @@ async function getPackageMigrationsConfigFromRegistry( const result = await packageRegistryView( packageName, packageVersion, - 'nx-migrations ng-update --json' + 'nx-migrations ng-update dist --json' ); if (!result) { return null; } - return readNxMigrateConfig(JSON.parse(result)); + const json = JSON.parse(result); + + if (!json['nx-migrations'] && !json['ng-update']) { + const registry = new URL('dist' in json ? json.dist.tarball : json.tarball) + .hostname; + + // Registries other than npmjs and the local registry may not support full metadata via npm view + // so throw error so that fetcher falls back to getting config via install + if (!['registry.npmjs.org', 'localhost'].includes(registry)) { + throw new Error( + `Getting migration config from registry is not supported from ${registry}` + ); + } + } + + return readNxMigrateConfig(json); } async function downloadPackageMigrationsFromRegistry( From 49649c3396886879c7e4d8a0d607ed0f8772f8f6 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 20 Apr 2023 16:13:06 -0400 Subject: [PATCH 2/2] fix(core): add artifactory opt-out --- packages/nx/src/command-line/migrate.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/command-line/migrate.ts b/packages/nx/src/command-line/migrate.ts index b5576936a2580..5611f0f7a8b8f 100644 --- a/packages/nx/src/command-line/migrate.ts +++ b/packages/nx/src/command-line/migrate.ts @@ -949,7 +949,11 @@ async function getPackageMigrationsConfigFromRegistry( // Registries other than npmjs and the local registry may not support full metadata via npm view // so throw error so that fetcher falls back to getting config via install - if (!['registry.npmjs.org', 'localhost'].includes(registry)) { + if ( + !['registry.npmjs.org', 'localhost', 'artifactory'].some((v) => + registry.includes(v) + ) + ) { throw new Error( `Getting migration config from registry is not supported from ${registry}` );