Skip to content

Commit

Permalink
[rush-lib] Fix Set config.ignoreCompatibilityDb when rush installation
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockfeng committed Aug 8, 2022
1 parent c613ad3 commit bc2f607
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "rush install/update should always set `config.ignoreCompatibilityDb` and print warning if the rush.json pnpmVersion specifies a version affected by this problem.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
9 changes: 7 additions & 2 deletions libraries/rush-lib/src/logic/base/BaseInstallManager.ts
Expand Up @@ -40,6 +40,11 @@ import { WebClient, WebClientResponse } from '../../utilities/WebClient';
import { SetupPackageRegistry } from '../setup/SetupPackageRegistry';
import { PnpmfileConfiguration } from '../pnpm/PnpmfileConfiguration';

/**
* Pnpm don't support --ignore-compatibility-db, so use --config.ignoreCompatibilityDb for now.
*/
export const pnpmIgnoreCompatibilityDbParameter: string = '--config.ignoreCompatibilityDb';

export interface IInstallManagerOptions {
/**
* Whether the global "--debug" flag was specified.
Expand Down Expand Up @@ -610,9 +615,9 @@ export abstract class BaseInstallManager {
}
if (
semver.gte(this._rushConfiguration.packageManagerToolVersion, '7.9.0') ||
semver.gte(this._rushConfiguration.packageManagerToolVersion, '6.34.0')
semver.satisfies(this._rushConfiguration.packageManagerToolVersion, '^6.34.0')
) {
args.push('--ignore-compatibility-db');
args.push(pnpmIgnoreCompatibilityDbParameter);
}
} else if (this._rushConfiguration.packageManager === 'yarn') {
args.push('--link-folder', 'yarn-link');
Expand Down
15 changes: 9 additions & 6 deletions libraries/rush-lib/src/logic/test/BaseInstallManager.test.ts
Expand Up @@ -4,7 +4,11 @@ import * as path from 'path';
import { ConsoleTerminalProvider } from '@rushstack/node-core-library';

import { PurgeManager } from '../PurgeManager';
import { BaseInstallManager, IInstallManagerOptions } from '../base/BaseInstallManager';
import {
BaseInstallManager,
IInstallManagerOptions,
pnpmIgnoreCompatibilityDbParameter
} from '../base/BaseInstallManager';

import { RushConfiguration } from '../../api/RushConfiguration';
import { RushGlobalFolder } from '../../api/RushGlobalFolder';
Expand Down Expand Up @@ -77,19 +81,20 @@ describe('BaseInstallManager Test', () => {

const argsPnpmV6: string[] = [];
fakeBaseInstallManager6.pushConfigurationArgs(argsPnpmV6, options);

expect(argsPnpmV6).not.toContain(pnpmIgnoreCompatibilityDbParameter);
expect(mockWrite.mock.calls[0][0]).toContain(
"Warning: Your rush.json specifies a pnpmVersion with a known issue that may cause unintended version selections. It's recommended to upgrade to PNPM >=6.34.0 or >=7.9.0. For details see: https://rushjs.io/link/pnpm-issue-5132"
);

const argsPnpmV7: string[] = [];
fakeBaseInstallManager7.pushConfigurationArgs(argsPnpmV7, options);
expect(argsPnpmV7).not.toContain(pnpmIgnoreCompatibilityDbParameter);
expect(mockWrite.mock.calls[0][0]).toContain(
"Warning: Your rush.json specifies a pnpmVersion with a known issue that may cause unintended version selections. It's recommended to upgrade to PNPM >=6.34.0 or >=7.9.0. For details see: https://rushjs.io/link/pnpm-issue-5132"
);
});

it('pnpm version gte 6.34.0 || gte 7.9.0 should add --ignore-compatibility-db', () => {
it(`pnpm version ^6.34.0 || gte 7.9.0 should add ${pnpmIgnoreCompatibilityDbParameter}`, () => {
const rushJsonFile: string = path.resolve(__dirname, 'ignoreCompatibilityDb/rush3.json');
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(rushJsonFile);
const purgeManager: typeof PurgeManager.prototype = new PurgeManager(rushConfiguration, rushGlobalFolder);
Expand All @@ -102,14 +107,12 @@ describe('BaseInstallManager Test', () => {
options
);

const expected = ['--ignore-compatibility-db'];

const mockWrite = jest.fn();
jest.spyOn(ConsoleTerminalProvider.prototype, 'write').mockImplementation(mockWrite);

const args: string[] = [];
fakeBaseInstallManager.pushConfigurationArgs(args, options);
expect(args).toEqual(expect.arrayContaining(expected));
expect(args).toContain(pnpmIgnoreCompatibilityDbParameter);

if (mockWrite.mock.calls.length) {
expect(mockWrite.mock.calls[0][0]).not.toContain(
Expand Down

0 comments on commit bc2f607

Please sign in to comment.