Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Do not use legacy-peer-deps for npm #20456

Merged
merged 2 commits into from Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions code/lib/cli/src/js-package-manager/NPMProxy.test.ts
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
@@ -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