Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 13 additions & 7 deletions packages/nx/src/command-line/migrate/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as pc from 'picocolors';
import { exec, execSync, type StdioOptions } from 'child_process';
import { prompt } from 'enquirer';
import { dirname, join } from 'path';
import { joinPathFragments } from '../../utils/path';
import {
clean,
coerce,
Expand Down Expand Up @@ -978,7 +979,10 @@ function createFetcher() {
setCache(packageName, resolvedVersion);
return getPackageMigrationsUsingRegistry(packageName, resolvedVersion);
})
.catch(() => {
.catch((e) => {
logger.verbose(
`Failed to get migrations from registry for ${packageName}@${packageVersion}: ${e.message}. Falling back to install.`
);
logger.info(`Fetching ${packageName}@${packageVersion}`);

return getPackageMigrationsUsingInstall(packageName, packageVersion);
Expand Down Expand Up @@ -1115,7 +1119,7 @@ async function downloadPackageMigrationsFromRegistry(

const migrations = await extractFileFromTarball(
join(dir, tarballPath),
join('package', migrationsFilePath),
joinPathFragments('package', migrationsFilePath),
join(dir, migrationsFilePath)
).then((path) => readJsonFile<MigrationsJson>(path));

Expand Down Expand Up @@ -1148,6 +1152,10 @@ async function getPackageMigrationsUsingInstall(

await execAsync(`${pmc.add} ${packageName}@${packageVersion}`, {
cwd: dir,
env: {
...process.env,
npm_config_legacy_peer_deps: 'true',
},
});

const {
Expand All @@ -1163,11 +1171,9 @@ async function getPackageMigrationsUsingInstall(

result = { ...migrations, packageGroup, version: packageJson.version };
} catch (e) {
output.warn({
title: `Failed to fetch migrations for ${packageName}@${packageVersion}`,
bodyLines: [e.message],
});
return {};
throw new Error(
`Failed to fetch migrations for ${packageName}@${packageVersion}: ${e.message}`
);
} finally {
await cleanup();
}
Expand Down
21 changes: 8 additions & 13 deletions packages/nx/src/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,19 +610,14 @@ export async function packageRegistryPack(
pkg: string,
version: string
): Promise<{ tarballPath: string }> {
let pm = detectPackageManager();
if (pm === 'yarn' || pm === 'bun') {
/**
* `(p)npm pack` will download a tarball of the specified version,
* whereas `yarn` pack creates a tarball of the active workspace, so it
* does not work for getting the content of a library.
*
* @see https://github.com/nrwl/nx/pull/9667#discussion_r842553994
*
* bun doesn't currently support pack
*/
pm = 'npm';
}
/**
* Only `npm pack` supports downloading a tarball of a specified remote
* package. `yarn` packs the active workspace, `pnpm pack` only packs
* the local project, and `bun` doesn't support pack.
*
* @see https://github.com/nrwl/nx/pull/9667#discussion_r842553994
*/
const pm = 'npm';

const { stdout } = await execAsync(`${pm} pack ${pkg}@${version}`, {
cwd,
Expand Down
Loading