Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yarn's registry just redirects to npmjs, and can be in lock files, but still shows npm's url for the tarball 🤔 interesting.

I think this is fine.

throw new Error(
`Getting migration config from registry is not supported from ${registry}`
);
}
}

return readNxMigrateConfig(json);
}

async function downloadPackageMigrationsFromRegistry(
Expand Down