From 8d85c7c6542b09bb8a4caa0da047dc3cb5070b65 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Mon, 2 Dec 2024 22:56:43 -0500 Subject: [PATCH] Use terminal. --- .../logic/installManager/InstallHelpers.ts | 8 +++---- .../installManager/RushInstallManager.ts | 3 ++- .../installManager/WorkspaceInstallManager.ts | 2 +- .../src/logic/test/InstallHelpers.test.ts | 21 ++++++++++++++++++- .../__snapshots__/InstallHelpers.test.ts.snap | 11 ++++++++++ 5 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 libraries/rush-lib/src/logic/test/__snapshots__/InstallHelpers.test.ts.snap diff --git a/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts b/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts index 9d4feeea65a..3d34b13c0cb 100644 --- a/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts +++ b/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts @@ -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'; @@ -39,7 +39,8 @@ export class InstallHelpers { public static generateCommonPackageJson( rushConfiguration: RushConfiguration, subspace: Subspace, - dependencies: Map = new Map() + dependencies: Map = new Map(), + terminal: ITerminal ): void { const commonPackageJson: ICommonPackageJson = { dependencies: {}, @@ -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 ` + diff --git a/libraries/rush-lib/src/logic/installManager/RushInstallManager.ts b/libraries/rush-lib/src/logic/installManager/RushInstallManager.ts index 03b9c506d8d..5761b45c529 100644 --- a/libraries/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/libraries/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -379,7 +379,8 @@ export class RushInstallManager extends BaseInstallManager { InstallHelpers.generateCommonPackageJson( this.rushConfiguration, this.rushConfiguration.defaultSubspace, - commonDependencies + commonDependencies, + this._terminal ); stopwatch.stop(); diff --git a/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts b/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts index 8308aef00c8..c6f59c5264b 100644 --- a/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts +++ b/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts @@ -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 diff --git a/libraries/rush-lib/src/logic/test/InstallHelpers.test.ts b/libraries/rush-lib/src/logic/test/InstallHelpers.test.ts index e943f877654..32be66eabd8 100644 --- a/libraries/rush-lib/src/logic/test/InstallHelpers.test.ts +++ b/libraries/rush-lib/src/logic/test/InstallHelpers.test.ts @@ -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; }); @@ -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( diff --git a/libraries/rush-lib/src/logic/test/__snapshots__/InstallHelpers.test.ts.snap b/libraries/rush-lib/src/logic/test/__snapshots__/InstallHelpers.test.ts.snap new file mode 100644 index 00000000000..7f122921b53 --- /dev/null +++ b/libraries/rush-lib/src/logic/test/__snapshots__/InstallHelpers.test.ts.snap @@ -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": "", +} +`;