fix(core): ensure yarn runs install with correct version (#17997)
This commit is contained in:
parent
21007d8922
commit
d0c37727c5
@ -23,7 +23,7 @@ export async function createSandbox(packageManager: PackageManager) {
|
|||||||
`Installing dependencies with ${packageManager}`
|
`Installing dependencies with ${packageManager}`
|
||||||
).start();
|
).start();
|
||||||
|
|
||||||
const { install } = getPackageManagerCommand(packageManager);
|
const { install, preInstall } = getPackageManagerCommand(packageManager);
|
||||||
|
|
||||||
const tmpDir = dirSync().name;
|
const tmpDir = dirSync().name;
|
||||||
try {
|
try {
|
||||||
@ -39,6 +39,10 @@ export async function createSandbox(packageManager: PackageManager) {
|
|||||||
);
|
);
|
||||||
generatePackageManagerFiles(tmpDir, packageManager);
|
generatePackageManagerFiles(tmpDir, packageManager);
|
||||||
|
|
||||||
|
if (preInstall) {
|
||||||
|
await execAndWait(preInstall, tmpDir);
|
||||||
|
}
|
||||||
|
|
||||||
await execAndWait(install, tmpDir);
|
await execAndWait(install, tmpDir);
|
||||||
|
|
||||||
installSpinner.succeed();
|
installSpinner.succeed();
|
||||||
|
|||||||
@ -36,6 +36,7 @@ export function getPackageManagerCommand(
|
|||||||
): {
|
): {
|
||||||
install: string;
|
install: string;
|
||||||
exec: string;
|
exec: string;
|
||||||
|
preInstall?: string;
|
||||||
} {
|
} {
|
||||||
const [pmMajor, pmMinor] =
|
const [pmMajor, pmMinor] =
|
||||||
getPackageManagerVersion(packageManager).split('.');
|
getPackageManagerVersion(packageManager).split('.');
|
||||||
@ -45,6 +46,9 @@ export function getPackageManagerCommand(
|
|||||||
const useBerry = +pmMajor >= 2;
|
const useBerry = +pmMajor >= 2;
|
||||||
const installCommand = 'yarn install --silent';
|
const installCommand = 'yarn install --silent';
|
||||||
return {
|
return {
|
||||||
|
preInstall: useBerry
|
||||||
|
? 'yarn set version stable'
|
||||||
|
: 'yarn set version classic',
|
||||||
install: useBerry
|
install: useBerry
|
||||||
? installCommand
|
? installCommand
|
||||||
: `${installCommand} --ignore-scripts`,
|
: `${installCommand} --ignore-scripts`,
|
||||||
|
|||||||
@ -464,12 +464,20 @@ export function ensurePackage<T extends any = any>(
|
|||||||
|
|
||||||
console.log(`Fetching ${pkg}...`);
|
console.log(`Fetching ${pkg}...`);
|
||||||
const packageManager = detectPackageManager();
|
const packageManager = detectPackageManager();
|
||||||
|
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
|
||||||
|
const preInstallCommand = getPackageManagerCommand(packageManager).preInstall;
|
||||||
|
if (preInstallCommand) {
|
||||||
|
// ensure package.json and repo in tmp folder is set to a proper package manager state
|
||||||
|
execSync(preInstallCommand, {
|
||||||
|
cwd: tempDir,
|
||||||
|
stdio: isVerbose ? 'inherit' : 'ignore',
|
||||||
|
});
|
||||||
|
}
|
||||||
let addCommand = getPackageManagerCommand(packageManager).addDev;
|
let addCommand = getPackageManagerCommand(packageManager).addDev;
|
||||||
if (packageManager === 'pnpm') {
|
if (packageManager === 'pnpm') {
|
||||||
addCommand = 'pnpm add -D'; // we need to ensure that we are not using workspace command
|
addCommand = 'pnpm add -D'; // we need to ensure that we are not using workspace command
|
||||||
}
|
}
|
||||||
|
|
||||||
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
|
|
||||||
execSync(`${addCommand} ${pkg}@${requiredVersion}`, {
|
execSync(`${addCommand} ${pkg}@${requiredVersion}`, {
|
||||||
cwd: tempDir,
|
cwd: tempDir,
|
||||||
stdio: isVerbose ? 'inherit' : 'ignore',
|
stdio: isVerbose ? 'inherit' : 'ignore',
|
||||||
|
|||||||
@ -15,6 +15,7 @@ const execAsync = promisify(exec);
|
|||||||
export type PackageManager = 'yarn' | 'pnpm' | 'npm';
|
export type PackageManager = 'yarn' | 'pnpm' | 'npm';
|
||||||
|
|
||||||
export interface PackageManagerCommands {
|
export interface PackageManagerCommands {
|
||||||
|
preInstall?: string;
|
||||||
install: string;
|
install: string;
|
||||||
ciInstall: string;
|
ciInstall: string;
|
||||||
add: string;
|
add: string;
|
||||||
@ -64,6 +65,9 @@ export function getPackageManagerCommand(
|
|||||||
const useBerry = gte(yarnVersion, '2.0.0');
|
const useBerry = gte(yarnVersion, '2.0.0');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
preInstall: useBerry
|
||||||
|
? 'yarn set version stable'
|
||||||
|
: 'yarn set version classic',
|
||||||
install: 'yarn',
|
install: 'yarn',
|
||||||
ciInstall: useBerry
|
ciInstall: useBerry
|
||||||
? 'yarn install --immutable'
|
? 'yarn install --immutable'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user