显示一个包的信息。

yarn info []

这个命令会拉取包的信息并返回为树格式,包不必安装到本地。


1. yarn info react


1. yarn info vx.x.x
2. { name: 'react',
3. version: '15.4.0-rc.2',
4. description: 'React is a JavaScript library for building user interfaces.',
5. time: { modified: '2016-10-06T22:09:27.397Z', ... } ... }

这个命令默认的报告样式时单引号序列化的。 要输出有效的 JSON 行格式,使用标准的 —json 标志:


1. yarn info react --json


1. {"type":"inspect","data":{"name":"react","time":{...}}}
2. {"type":"finished","data":417}

指定版本的信息

追加 @[version] 到包名参数来提供那个特定版本的信息:


1. yarn info react@15.3.0


1. yarn info vx.x.x
2. { name: 'react',
3. version: '15.3.0',
4. description: 'React is a JavaScript library for building user interfaces.',
5. time: { modified: '2016-10-06T22:09:27.397Z', ... } ... }

选择特定字段

如果提供了可选字段参数,那么只有树的那部分被返回。


1. yarn info react description


1. yarn info vx.x.x
2. React is a JavaScript library for building user interfaces.

或检查可用的版本:


1. yarn info 反应版本


1. yarn info v1.1.0
2. [ '0.0.1',
3. '0.0.2',
4. '0.0.3',
5. (等)

如果指定的字段在一个内嵌的对象里,则返回子树:


1. yarn info react time


1. yarn info vx.x.x
2. { modified: '2016-10-06T22:09:27.397Z',
3. created: '2011-10-26T17:46:21.942Z', ... }

5. yarn info react time --json
6. {"type":"inspect","data":{"modified":"2016-10-06T22:09:27.397Z","created":...}}
7. ...

获取 readme 字段

请注意,默认情况下,yarn info 不返回 readme 字段(因为它通常很长)。要显式请求那个字段,使用第二个参数:


1. yarn info react readme


1. yarn info vx.x.x
2. ## react

4. An npm package to get you immediate access to
5. [React](https://facebook.github.io/react/).
6. ...

原文: https://yarnpkg.com/zh-Hans/docs/cli/info