Skip to content

Commit

Permalink
fix(core): whitelist registries that support obtaining migration conf…
Browse files Browse the repository at this point in the history
…ig 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 nrwl#16387, nrwl#10223
  • Loading branch information
CNManning committed Apr 20, 2023
1 parent 16e4061 commit a1ead00
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/nx/src/command-line/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
satisfies,
valid,
} from 'semver';
import { URL } from 'url';
import { promisify } from 'util';
import {
MigrationsJson,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a1ead00

Please sign in to comment.