Skip to content

Commit

Permalink
Use terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
iclanton committed Dec 3, 2024
1 parent 9f9072c commit 8d85c7c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
8 changes: 4 additions & 4 deletions libraries/rush-lib/src/logic/installManager/InstallHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
JsonFile,
LockFile
} from '@rushstack/node-core-library';
import { Colorize } from '@rushstack/terminal';
import { Colorize, ITerminal } from '@rushstack/terminal';

import { LastInstallFlag } from '../../api/LastInstallFlag';
import type { PackageManagerName } from '../../api/packageManager/PackageManager';
Expand Down Expand Up @@ -39,7 +39,8 @@ export class InstallHelpers {
public static generateCommonPackageJson(
rushConfiguration: RushConfiguration,
subspace: Subspace,
dependencies: Map<string, string> = new Map<string, string>()
dependencies: Map<string, string> = new Map<string, string>(),
terminal: ITerminal
): void {
const commonPackageJson: ICommonPackageJson = {
dependencies: {},
Expand Down Expand Up @@ -76,8 +77,7 @@ export class InstallHelpers {
rushConfiguration.rushConfigurationJson.pnpmVersion !== undefined &&
semver.lt(rushConfiguration.rushConfigurationJson.pnpmVersion, '9.0.0')
) {
// eslint-disable-next-line no-console
console.warn(
terminal.writeWarningLine(
Colorize.yellow(
`Your version of pnpm (${rushConfiguration.rushConfigurationJson.pnpmVersion}) ` +
`doesn't support the "globalIgnoredOptionalDependencies" field in ` +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ export class RushInstallManager extends BaseInstallManager {
InstallHelpers.generateCommonPackageJson(
this.rushConfiguration,
this.rushConfiguration.defaultSubspace,
commonDependencies
commonDependencies,
this._terminal
);

stopwatch.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export class WorkspaceInstallManager extends BaseInstallManager {
}

// Write the common package.json
InstallHelpers.generateCommonPackageJson(this.rushConfiguration, subspace, undefined);
InstallHelpers.generateCommonPackageJson(this.rushConfiguration, subspace, undefined, this._terminal);

// Save the generated workspace file. Don't update the file timestamp unless the content has changed,
// since "rush install" will consider this timestamp
Expand Down
21 changes: 20 additions & 1 deletion libraries/rush-lib/src/logic/test/InstallHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@
import { InstallHelpers } from '../installManager/InstallHelpers';
import { RushConfiguration } from '../../api/RushConfiguration';
import { type IPackageJson, JsonFile } from '@rushstack/node-core-library';
import { StringBufferTerminalProvider, Terminal } from '@rushstack/terminal';

describe('InstallHelpers', () => {
describe('generateCommonPackageJson', () => {
const originalJsonFileSave = JsonFile.save;
const mockJsonFileSave: jest.Mock = jest.fn();
let terminal: Terminal;
let terminalProvider: StringBufferTerminalProvider;

beforeAll(() => {
JsonFile.save = mockJsonFileSave;
});

beforeEach(() => {
terminalProvider = new StringBufferTerminalProvider();
terminal = new Terminal(terminalProvider);
});

afterEach(() => {
expect({
output: terminalProvider.getOutput({ normalizeSpecialCharacters: true }),
verbose: terminalProvider.getVerbose({ normalizeSpecialCharacters: true }),
error: terminalProvider.getDebugOutput({ normalizeSpecialCharacters: true }),
warning: terminalProvider.getWarningOutput({ normalizeSpecialCharacters: true }),
debug: terminalProvider.getDebugOutput({ normalizeSpecialCharacters: true })
}).toMatchSnapshot('Terminal Output');
mockJsonFileSave.mockClear();
});

afterAll(() => {
JsonFile.save = originalJsonFileSave;
});
Expand All @@ -26,7 +44,8 @@ describe('InstallHelpers', () => {
InstallHelpers.generateCommonPackageJson(
rushConfiguration,
rushConfiguration.defaultSubspace,
undefined
undefined,
terminal
);
const packageJson: IPackageJson = mockJsonFileSave.mock.calls[0][0];
expect(packageJson).toEqual(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InstallHelpers generateCommonPackageJson generates correct package json with pnpm configurations: Terminal Output 1`] = `
Object {
"debug": "",
"error": "",
"output": "",
"verbose": "",
"warning": "",
}
`;

0 comments on commit 8d85c7c

Please sign in to comment.