fix(core): whitelist registries that support obtaining migration config via 'npm view' (#16423)

Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
This commit is contained in:
Chris Manning 2023-04-21 09:40:19 +12:00 committed by GitHub
parent db6e14eca5
commit a7c14fca1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ import {
satisfies,
valid,
} from 'semver';
import { URL } from 'url';
import { promisify } from 'util';
import {
MigrationsJson,
@ -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(