Skip to content

Commit

Permalink
Merge pull request #20456 from storybookjs/remove-legacy-peer-deps
Browse files Browse the repository at this point in the history
CLI: Do not use legacy-peer-deps for npm
  • Loading branch information
shilman authored Jan 1, 2023
2 parents 62ba7cf + 1807073 commit b31c2d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
12 changes: 4 additions & 8 deletions code/lib/cli/src/js-package-manager/NPMProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,12 @@ describe('NPM Proxy', () => {
});
});
describe('npm7', () => {
it('should run `npm install --legacy-peer-deps`', () => {
it('should run `npm install`', () => {
const executeCommandSpy = jest.spyOn(npmProxy, 'executeCommand').mockReturnValue('7.1.0');

npmProxy.installDependencies();

expect(executeCommandSpy).toHaveBeenLastCalledWith(
'npm',
['install', '--legacy-peer-deps'],
expect.any(String)
);
expect(executeCommandSpy).toHaveBeenLastCalledWith('npm', ['install'], expect.any(String));
});
});
});
Expand All @@ -83,7 +79,7 @@ describe('NPM Proxy', () => {

expect(executeCommandSpy).toHaveBeenLastCalledWith(
'npm',
['install', '--legacy-peer-deps', '-D', '@storybook/preview-api'],
['install', '-D', '@storybook/preview-api'],
expect.any(String)
);
});
Expand Down Expand Up @@ -112,7 +108,7 @@ describe('NPM Proxy', () => {

expect(executeCommandSpy).toHaveBeenLastCalledWith(
'npm',
['uninstall', '--legacy-peer-deps', '@storybook/preview-api'],
['uninstall', '@storybook/preview-api'],
expect.any(String)
);
});
Expand Down
28 changes: 2 additions & 26 deletions code/lib/cli/src/js-package-manager/NPMProxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import semver from 'semver';

import { JsPackageManager } from './JsPackageManager';
import type { PackageJson } from './PackageJson';

Expand All @@ -26,38 +24,16 @@ export class NPMProxy extends JsPackageManager {
return this.executeCommand('npm', ['--version']);
}

hasLegacyPeerDeps() {
const result = this.executeCommand('npm', [
'config',
'get',
'legacy-peer-deps',
'--location=project',
]);
return result.trim() === 'true';
}

setLegacyPeerDeps() {
this.executeCommand('npm', ['config', 'set', 'legacy-peer-deps=true', '--location=project']);
}

needsLegacyPeerDeps(version: string) {
return semver.gte(version, '7.0.0') && !this.hasLegacyPeerDeps();
}

getInstallArgs(): string[] {
if (!this.installArgs) {
this.installArgs = this.needsLegacyPeerDeps(this.getNpmVersion())
? ['install', '--legacy-peer-deps']
: ['install'];
this.installArgs = ['install'];
}
return this.installArgs;
}

getUninstallArgs(): string[] {
if (!this.uninstallArgs) {
this.uninstallArgs = this.needsLegacyPeerDeps(this.getNpmVersion())
? ['uninstall', '--legacy-peer-deps']
: ['uninstall'];
this.uninstallArgs = ['uninstall'];
}
return this.uninstallArgs;
}
Expand Down

0 comments on commit b31c2d2

Please sign in to comment.