Skip to content

Commit

Permalink
fix(core): migrate should not fail under certain circumstances (#10225)
Browse files Browse the repository at this point in the history
Closes #10144
  • Loading branch information
AgentEnder committed May 10, 2022
1 parent 99252cc commit 6025ce5
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions packages/nx/src/command-line/migrate.ts
Expand Up @@ -804,6 +804,15 @@ async function isMigratingToNewMajor(from: string, to: string) {
return major(from) < major(to);
}

function readNxVersion(packageJson: PackageJson) {
return (
packageJson?.devDependencies?.['nx'] ??
packageJson?.dependencies?.['nx'] ??
packageJson?.devDependencies?.['@nrwl/workspace'] ??
packageJson?.dependencies?.['@nrwl/workspace']
);
}

async function generateMigrationsJsonAndUpdatePackageJson(
root: string,
opts: {
Expand All @@ -818,20 +827,25 @@ async function generateMigrationsJsonAndUpdatePackageJson(
let originalPackageJson = readJsonFile<PackageJson>(
join(root, 'package.json')
);
if (
['nx', '@nrwl/workspace'].includes(opts.targetPackage) &&
(await isMigratingToNewMajor(
originalPackageJson.devDependencies?.['nx'] ??
originalPackageJson.devDependencies?.['@nrwl/workspace'],
opts.targetVersion
))
) {
await connectToNxCloudCommand(
'We noticed you are migrating to a new major version, but are not taking advantage of Nx Cloud. Nx Cloud can make your CI up to 10 times faster. Learn more about it here: nx.app. Would you like to add it?'
);
originalPackageJson = readJsonFile<PackageJson>(
join(root, 'package.json')
);

try {
if (
['nx', '@nrwl/workspace'].includes(opts.targetPackage) &&
(await isMigratingToNewMajor(
readNxVersion(originalPackageJson),
opts.targetVersion
))
) {
await connectToNxCloudCommand(
'We noticed you are migrating to a new major version, but are not taking advantage of Nx Cloud. Nx Cloud can make your CI up to 10 times faster. Learn more about it here: nx.app. Would you like to add it?'
);
originalPackageJson = readJsonFile<PackageJson>(
join(root, 'package.json')
);
}
} catch {
// The above code is to remind folks when updating to a new major and not currently using Nx cloud.
// If for some reason it fails, it shouldn't affect the overall migration process
}

logger.info(`Fetching meta data about packages.`);
Expand Down

1 comment on commit 6025ce5

@vercel
Copy link

@vercel vercel bot commented on 6025ce5 May 10, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nx-dev – ./

nx.dev
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.