From 0bdbff7eb4bee84efd792478c414fd188f613ede Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Wed, 6 Sep 2023 12:32:25 +0200 Subject: [PATCH 1/3] Strip color and inform the user how to dedupe --- .../cli/src/automigrate/helpers/getMigrationSummary.test.ts | 1 + code/lib/cli/src/automigrate/helpers/getMigrationSummary.ts | 5 +++++ code/lib/cli/src/js-package-manager/NPMProxy.ts | 4 ++++ code/lib/cli/src/js-package-manager/PNPMProxy.ts | 4 ++++ code/lib/cli/src/js-package-manager/Yarn1Proxy.ts | 4 ++++ code/lib/cli/src/js-package-manager/Yarn2Proxy.ts | 4 ++++ code/lib/cli/src/js-package-manager/types.ts | 1 + 7 files changed, 23 insertions(+) diff --git a/code/lib/cli/src/automigrate/helpers/getMigrationSummary.test.ts b/code/lib/cli/src/automigrate/helpers/getMigrationSummary.test.ts index 2b95a6658217..7049c7c0d835 100644 --- a/code/lib/cli/src/automigrate/helpers/getMigrationSummary.test.ts +++ b/code/lib/cli/src/automigrate/helpers/getMigrationSummary.test.ts @@ -32,6 +32,7 @@ describe('getMigrationSummary', () => { }, dependencies: {}, infoCommand: 'yarn why', + dedupeCommand: 'yarn dedupe', }; const logFile = '/path/to/log/file'; diff --git a/code/lib/cli/src/automigrate/helpers/getMigrationSummary.ts b/code/lib/cli/src/automigrate/helpers/getMigrationSummary.ts index 9e9d60df35c7..6a16e2ae3291 100644 --- a/code/lib/cli/src/automigrate/helpers/getMigrationSummary.ts +++ b/code/lib/cli/src/automigrate/helpers/getMigrationSummary.ts @@ -184,6 +184,11 @@ function getWarnings(installationMetadata: InstallationMetadata) { `${installationMetadata.infoCommand} ` )}` ); + messages.push( + `Please try de-duplicating these dependencies by running ${chalk.cyan( + `${installationMetadata.dedupeCommand}` + )}` + ); return messages; } diff --git a/code/lib/cli/src/js-package-manager/NPMProxy.ts b/code/lib/cli/src/js-package-manager/NPMProxy.ts index 519030d34a59..1613bac9bb5d 100644 --- a/code/lib/cli/src/js-package-manager/NPMProxy.ts +++ b/code/lib/cli/src/js-package-manager/NPMProxy.ts @@ -142,6 +142,9 @@ export class NPMProxy extends JsPackageManager { args: ['ls', '--json', '--depth=99', pipeToNull], // ignore errors, because npm ls will exit with code 1 if there are e.g. unmet peer dependencies ignoreError: true, + env: { + FORCE_COLOR: 'false', + }, }); try { @@ -272,6 +275,7 @@ export class NPMProxy extends JsPackageManager { dependencies: acc, duplicatedDependencies, infoCommand: 'npm ls --depth=1', + dedupeCommand: 'npm dedupe', }; } diff --git a/code/lib/cli/src/js-package-manager/PNPMProxy.ts b/code/lib/cli/src/js-package-manager/PNPMProxy.ts index d435ec397a05..57fb2ae9b075 100644 --- a/code/lib/cli/src/js-package-manager/PNPMProxy.ts +++ b/code/lib/cli/src/js-package-manager/PNPMProxy.ts @@ -101,6 +101,9 @@ export class PNPMProxy extends JsPackageManager { const commandResult = await this.executeCommand({ command: 'pnpm', args: ['list', pattern.map((p) => `"${p}"`).join(' '), '--json', '--depth=99'], + env: { + FORCE_COLOR: 'false', + }, }); try { @@ -287,6 +290,7 @@ export class PNPMProxy extends JsPackageManager { dependencies: acc, duplicatedDependencies, infoCommand: 'pnpm list --depth=1', + dedupeCommand: 'pnpm dedupe', }; } diff --git a/code/lib/cli/src/js-package-manager/Yarn1Proxy.ts b/code/lib/cli/src/js-package-manager/Yarn1Proxy.ts index 3793b7f54528..8d24e3676f4b 100644 --- a/code/lib/cli/src/js-package-manager/Yarn1Proxy.ts +++ b/code/lib/cli/src/js-package-manager/Yarn1Proxy.ts @@ -91,6 +91,9 @@ export class Yarn1Proxy extends JsPackageManager { const commandResult = await this.executeCommand({ command: 'yarn', args: ['list', '--pattern', pattern.map((p) => `"${p}"`).join(' '), '--recursive', '--json'], + env: { + FORCE_COLOR: 'false', + }, }); try { @@ -215,6 +218,7 @@ export class Yarn1Proxy extends JsPackageManager { dependencies: acc, duplicatedDependencies, infoCommand: 'yarn why', + dedupeCommand: 'yarn dedupe', }; } diff --git a/code/lib/cli/src/js-package-manager/Yarn2Proxy.ts b/code/lib/cli/src/js-package-manager/Yarn2Proxy.ts index a4d4484f554e..ebf7928d8aea 100644 --- a/code/lib/cli/src/js-package-manager/Yarn2Proxy.ts +++ b/code/lib/cli/src/js-package-manager/Yarn2Proxy.ts @@ -114,6 +114,9 @@ export class Yarn2Proxy extends JsPackageManager { pattern.map((p) => `"${p}"`).join(' '), `"${pattern}"`, ], + env: { + FORCE_COLOR: 'false', + }, }); try { @@ -286,6 +289,7 @@ export class Yarn2Proxy extends JsPackageManager { dependencies: acc, duplicatedDependencies, infoCommand: 'yarn why', + dedupeCommand: 'yarn dedupe', }; } diff --git a/code/lib/cli/src/js-package-manager/types.ts b/code/lib/cli/src/js-package-manager/types.ts index 165540de7a9d..ae8ad155669a 100644 --- a/code/lib/cli/src/js-package-manager/types.ts +++ b/code/lib/cli/src/js-package-manager/types.ts @@ -3,4 +3,5 @@ export type InstallationMetadata = { dependencies: Record; duplicatedDependencies: Record; infoCommand: string; + dedupeCommand: string; }; From 615384093b963d5972e76ba048fb3a4ab32fb809 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Wed, 6 Sep 2023 12:41:20 +0200 Subject: [PATCH 2/3] Update snapshots --- code/lib/cli/src/js-package-manager/NPMProxy.test.ts | 1 + code/lib/cli/src/js-package-manager/PNPMProxy.test.ts | 1 + code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts | 1 + code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts | 1 + 4 files changed, 4 insertions(+) diff --git a/code/lib/cli/src/js-package-manager/NPMProxy.test.ts b/code/lib/cli/src/js-package-manager/NPMProxy.test.ts index 667f173f99e8..60ba9e3e9a4a 100644 --- a/code/lib/cli/src/js-package-manager/NPMProxy.test.ts +++ b/code/lib/cli/src/js-package-manager/NPMProxy.test.ts @@ -379,6 +379,7 @@ describe('NPM Proxy', () => { expect(installations).toMatchInlineSnapshot(` Object { + "dedupeCommand": "npm dedupe", "dependencies": Object { "@storybook/addon-interactions": Array [ Object { diff --git a/code/lib/cli/src/js-package-manager/PNPMProxy.test.ts b/code/lib/cli/src/js-package-manager/PNPMProxy.test.ts index e59bd7354bcc..94ba1d1e7ed7 100644 --- a/code/lib/cli/src/js-package-manager/PNPMProxy.test.ts +++ b/code/lib/cli/src/js-package-manager/PNPMProxy.test.ts @@ -316,6 +316,7 @@ describe('PNPM Proxy', () => { expect(installations).toMatchInlineSnapshot(` Object { + "dedupeCommand": "pnpm dedupe", "dependencies": Object { "@storybook/addon-interactions": Array [ Object { diff --git a/code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts b/code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts index 3edf536f2a96..799fe8fb55cd 100644 --- a/code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts +++ b/code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts @@ -241,6 +241,7 @@ describe('Yarn 1 Proxy', () => { expect(installations).toMatchInlineSnapshot(` Object { + "dedupeCommand": "yarn dedupe", "dependencies": Object { "@storybook/addon-interactions": Array [ Object { diff --git a/code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts b/code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts index 51e5c1235cd4..0e1bb1276a30 100644 --- a/code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts +++ b/code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts @@ -219,6 +219,7 @@ describe('Yarn 2 Proxy', () => { expect(installations).toMatchInlineSnapshot(` Object { + "dedupeCommand": "yarn dedupe", "dependencies": Object { "@storybook/global": Array [ Object { From d98ff7603254fa85f941da12ef8188a6a8f04da1 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Wed, 6 Sep 2023 17:17:29 +0200 Subject: [PATCH 3/3] Update snapshots --- .../cli/src/automigrate/helpers/getMigrationSummary.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/lib/cli/src/automigrate/helpers/getMigrationSummary.test.ts b/code/lib/cli/src/automigrate/helpers/getMigrationSummary.test.ts index 7049c7c0d835..f5569ae2f49d 100644 --- a/code/lib/cli/src/automigrate/helpers/getMigrationSummary.test.ts +++ b/code/lib/cli/src/automigrate/helpers/getMigrationSummary.test.ts @@ -147,7 +147,9 @@ describe('getMigrationSummary', () => { @storybook/addon-essentials: 7.0.0, 7.1.0 - You can find more information for a given dependency by running yarn why " + You can find more information for a given dependency by running yarn why + + Please try de-duplicating these dependencies by running yarn dedupe" `); });