为什么我会选择 yarn 的 "resolutions" 而不是显式依赖?
Why would I choose yarn's "resolutions" over an explicit dependency?
我正在阅读 yarn resolutions RFC 并停在了这里:
The devDependencies
, optionalDependencies
and dependencies
fields always take precedence over the resolutions
field: if the user defines explicitly a dependency there, it means that he wants that version, even if it's specified with a non-exact specification. So the resolutions
field only applies to nested-dependencies. Nevertheless, in case of incompatibility between the specification of a non-nested dependency version and a resolution, a warning is issued.
如果我可以通过通常的依赖项字段强制执行依赖项的版本,我为什么要选择(看似)更复杂的 "resolutions" 字段?
您可以通过通常的依赖项字段强制执行依赖项的版本,仅适用于直接包依赖项,而不是那些依赖项的依赖项。 resolutions
字段需要在整个项目中为所有传递依赖项强制执行依赖项版本。
本节阐明了通常的依赖字段和直接依赖的解析之间的优先级。对于直接依赖的情况,通常的依赖字段优先。在您先声明决议然后执行 yarn add foo@version
的情况下,您希望您的包在那之后使用 foo@version
,即使您之前声明了 resolutions: {foo: 'old_version'}
。[=14] =]
我正在阅读 yarn resolutions RFC 并停在了这里:
The
devDependencies
,optionalDependencies
anddependencies
fields always take precedence over theresolutions
field: if the user defines explicitly a dependency there, it means that he wants that version, even if it's specified with a non-exact specification. So theresolutions
field only applies to nested-dependencies. Nevertheless, in case of incompatibility between the specification of a non-nested dependency version and a resolution, a warning is issued.
如果我可以通过通常的依赖项字段强制执行依赖项的版本,我为什么要选择(看似)更复杂的 "resolutions" 字段?
您可以通过通常的依赖项字段强制执行依赖项的版本,仅适用于直接包依赖项,而不是那些依赖项的依赖项。 resolutions
字段需要在整个项目中为所有传递依赖项强制执行依赖项版本。
本节阐明了通常的依赖字段和直接依赖的解析之间的优先级。对于直接依赖的情况,通常的依赖字段优先。在您先声明决议然后执行 yarn add foo@version
的情况下,您希望您的包在那之后使用 foo@version
,即使您之前声明了 resolutions: {foo: 'old_version'}
。[=14] =]