-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Support --peer
for install to install peer deps as well
#4689
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "peer-opt", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"dependencies": { | ||
"commander": "^2.9.0" | ||
}, | ||
"peerDependencies": { | ||
"qs": "6.3.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ function normalizeFlags(config: Config, rawFlags: Object): Flags { | |
frozenLockfile: !!rawFlags.frozenLockfile, | ||
linkDuplicates: !!rawFlags.linkDuplicates, | ||
checkFiles: !!rawFlags.checkFiles, | ||
includePeerDeps: !!rawFlags.peer, | ||
|
||
// add | ||
peer: !!rawFlags.peer, | ||
|
@@ -254,6 +255,9 @@ export class Install { | |
if (manifest.optionalDependencies && manifest.optionalDependencies[exclude]) { | ||
delete manifest.optionalDependencies[exclude]; | ||
} | ||
if (manifest.peerDependencies && manifest.peerDependencies[exclude]) { | ||
delete manifest.peerDependencies[exclude]; | ||
} | ||
} | ||
}; | ||
|
||
|
@@ -318,6 +322,9 @@ export class Install { | |
pushDeps('dependencies', projectManifestJson, {hint: null, optional: false}, true); | ||
pushDeps('devDependencies', projectManifestJson, {hint: 'dev', optional: false}, !this.config.production); | ||
pushDeps('optionalDependencies', projectManifestJson, {hint: 'optional', optional: true}, true); | ||
if (this.flags.includePeerDeps) { | ||
pushDeps('peerDependencies', projectManifestJson, {hint: 'peer', optional: false}, !this.config.production); | ||
} | ||
|
||
if (this.config.workspaceRootFolder) { | ||
const workspaceLoc = cwdIsRoot ? loc : path.join(this.config.lockfileFolder, filename); | ||
|
@@ -344,6 +351,9 @@ export class Install { | |
pushDeps('dependencies', workspaceManifest, {hint: null, optional: false}, true); | ||
pushDeps('devDependencies', workspaceManifest, {hint: 'dev', optional: false}, !this.config.production); | ||
pushDeps('optionalDependencies', workspaceManifest, {hint: 'optional', optional: true}, true); | ||
if (this.flags.includePeerDeps) { | ||
pushDeps('peerDependencies', workspaceManifest, {hint: 'peer', optional: false}, !this.config.production); | ||
} | ||
} | ||
} | ||
const virtualDependencyManifest: Manifest = { | ||
|
@@ -355,6 +365,7 @@ export class Install { | |
dependencies: workspaceDependencies, | ||
devDependencies: {...workspaceManifestJson.devDependencies}, | ||
optionalDependencies: {...workspaceManifestJson.optionalDependencies}, | ||
peerDependencies: this.flags.includePeerDeps ? {...workspaceManifestJson.peerDependencies} : {}, | ||
}; | ||
workspaceLayout.virtualManifestName = virtualDependencyManifest.name; | ||
const virtualDep = {}; | ||
|
@@ -917,13 +928,8 @@ export function hasWrapper(commander: Object, args: Array<string>): boolean { | |
|
||
export function setFlags(commander: Object) { | ||
commander.usage('install [flags]'); | ||
commander.option('--peer', 'explicitly install peer dependencies as well'); | ||
commander.option('-g, --global', 'DEPRECATED'); | ||
commander.option('-S, --save', 'DEPRECATED - save package to your `dependencies`'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove these? They are deprecated but removing them is a breaking change and we don't want to release a major version just yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They aren't deprecated so much as simply invalid. They won't do anything anymore so why report them as deprecated? The I left There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing deprecated features doesn't require a major per semver. I don't have a problem removing them, since it's been pretty clear for quite a long time now that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, I thought these options did not work at all with (Note that this only removes the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this is still a hard-breaking change. I'll ask React guys to see what they do. I think they start deprecating in feature updates and only remove them in major releases which makes sense.
The feature is always there. These are just legacy flags from NPM but AFAIK they do work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They don't work per-se, but generate a 'suggested command line'. https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js#L951-L975 @qfox Can you remove their removal from this PR? I think we should focus on the peer dependency itself, removing the deprecated commands will be a separate PR :) |
||
commander.option('-D, --save-dev', 'DEPRECATED - save package to your `devDependencies`'); | ||
commander.option('-P, --save-peer', 'DEPRECATED - save package to your `peerDependencies`'); | ||
commander.option('-O, --save-optional', 'DEPRECATED - save package to your `optionalDependencies`'); | ||
commander.option('-E, --save-exact', 'DEPRECATED'); | ||
commander.option('-T, --save-tilde', 'DEPRECATED'); | ||
} | ||
|
||
export async function install(config: Config, reporter: Reporter, flags: Object, lockfile: Lockfile): Promise<void> { | ||
|
@@ -934,16 +940,10 @@ export async function install(config: Config, reporter: Reporter, flags: Object, | |
} | ||
|
||
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> { | ||
let lockfile; | ||
let error = 'installCommandRenamed'; | ||
if (flags.lockfile === false) { | ||
lockfile = new Lockfile(); | ||
} else { | ||
lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter); | ||
} | ||
|
||
if (args.length) { | ||
const exampleArgs = args.slice(); | ||
let command = 'add'; | ||
let error = 'installCommandRenamed'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change relevant to the new feature? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Guess I'll remove the refactor. |
||
let exampleArgs = args.slice(); | ||
|
||
if (flags.saveDev) { | ||
exampleArgs.push('--dev'); | ||
|
@@ -960,14 +960,20 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |
if (flags.saveTilde) { | ||
exampleArgs.push('--tilde'); | ||
} | ||
let command = 'add'; | ||
|
||
if (flags.global) { | ||
error = 'globalFlagRemoved'; | ||
command = 'global add'; | ||
} | ||
throw new MessageError(reporter.lang(error, `yarn ${command} ${exampleArgs.join(' ')}`)); | ||
} | ||
|
||
let lockfile; | ||
if (flags.lockfile === false) { | ||
lockfile = new Lockfile(); | ||
} else { | ||
lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter); | ||
} | ||
await install(config, reporter, flags, lockfile); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arcanis I feel like this would change the lockfile resolution based on the flag which is not something we want.
I feel like we should drop the if block and use the following line:
Even then, I feel like this will be a big change in the final resolution. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. Whether it's a valid point is probably going to be a plain decision by the product owner.
Either we support this and running the command will invalidate the cache if used inconsistently (with and without the flag). The user may complain about the cache being broken, or it may not notice it at all. We could print a warning for this if that's desirable.
Or we don't support this feature. In that case we should mention a wontfix in the ticket, perhaps state the reason why, and close it.
I don't think it's worth a major version bump for making this a default behavior (see #4689 (comment))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BYK I think there is a precedent for this (namely, the
--flat
option). But that's something that would be solved if peer dependencies were installed by default rather than via a flag (which I still think would make sense).