Skip to content

Commit

Permalink
fix(core): ensure migrate works with yarn PnP (#21824)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Feb 20, 2024
1 parent ca3965f commit e864d35
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/nx/src/command-line/migrate/command-object.ts
Expand Up @@ -3,7 +3,10 @@ import * as path from 'path';
import { runNxSync } from '../../utils/child-process';
import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
import { execSync } from 'child_process';
import { getPackageManagerCommand } from '../../utils/package-manager';
import {
detectPackageManager,
getPackageManagerCommand,
} from '../../utils/package-manager';
import { writeJsonFile } from '../../utils/fileutils';
import { workspaceRoot } from '../../utils/workspace-root';

Expand Down Expand Up @@ -133,7 +136,8 @@ function runMigration() {
function nxCliPath() {
const version = process.env.NX_MIGRATE_CLI_VERSION || 'latest';
try {
const packageManager = getPackageManagerCommand();
const packageManager = detectPackageManager();
const pmc = getPackageManagerCommand(packageManager);

const { dirSync } = require('tmp');
const tmpDir = dirSync().name;
Expand All @@ -143,8 +147,22 @@ function nxCliPath() {
},
license: 'MIT',
});
if (pmc.preInstall) {
// ensure package.json and repo in tmp folder is set to a proper package manager state
execSync(pmc.preInstall, {
cwd: tmpDir,
stdio: ['ignore', 'ignore', 'ignore'],
});
// if it's berry ensure we set the node_linker to node-modules
if (packageManager === 'yarn' && pmc.ciInstall.includes('immutable')) {
execSync(pmc.preInstall, {
cwd: 'yarn config set nodeLinker node-modules',
stdio: ['ignore', 'ignore', 'ignore'],
});
}
}

execSync(packageManager.install, {
execSync(pmc.install, {
cwd: tmpDir,
stdio: ['ignore', 'ignore', 'ignore'],
});
Expand Down

0 comments on commit e864d35

Please sign in to comment.