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' (#16423)

Co-authored-by: Craigory Coppola <[email protected]>
  • Loading branch information
CNManning and AgentEnder authored Apr 20, 2023
1 parent db6e14e commit a7c14fc
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 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,33 @@ 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', 'artifactory'].some((v) =>
registry.includes(v)
)
) {
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 a7c14fc

Please sign in to comment.