Skip to content

Commit

Permalink
Add --legacy-peer-deps for NPM7 install
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed Mar 3, 2021
1 parent 2613f77 commit 3140735
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/cli/src/js-package-manager/NPMProxy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import semver from '@storybook/semver';
import { JsPackageManager } from './JsPackageManager';

export class NPMProxy extends JsPackageManager {
readonly type = 'npm';

installArgs: string[] | undefined;

initPackageJson() {
return this.executeCommand('npm', ['init', '-y']);
}
Expand All @@ -15,8 +18,18 @@ export class NPMProxy extends JsPackageManager {
return `npm run ${command}`;
}

getInstallArgs(): string[] {
if (!this.installArgs) {
const version = this.executeCommand('npm', ['--version']);
this.installArgs = semver.gte(version, '7.0.0')
? ['--legacy-peer-deps', 'install']
: ['install'];
}
return this.installArgs;
}

protected runInstall(): void {
this.executeCommand('npm', ['install'], 'inherit');
this.executeCommand('npm', this.getInstallArgs(), 'inherit');
}

protected runAddDeps(dependencies: string[], installAsDevDependencies: boolean): void {
Expand All @@ -26,7 +39,7 @@ export class NPMProxy extends JsPackageManager {
args = ['-D', ...args];
}

this.executeCommand('npm', ['install', ...args], 'inherit');
this.executeCommand('npm', [...this.getInstallArgs(), ...args], 'inherit');
}

protected runGetVersions<T extends boolean>(
Expand Down

0 comments on commit 3140735

Please sign in to comment.