发布包

为了通过 Yarn 共享你的包给全世界的其他开发者,你需要先发布它。

当你用 Yarn 发布一个包它会进入 npm registry 用于全球分发。

登录到 npm

如果你还没有,你需要先 创建一个 npm 账号。一旦完成你就可以在 Yarn 里设置你的用户名和 email。

yarn login

这将提示你输入用户名和 email。 然而它不会问你密码。 Yarn 不持有你的密码或任何会话。 当你发布或修改 npm 上的东西,你需要输入你的密码。

发布你的包

一旦你写完包的所有代码,测试完并且准备发布,你就可以开始:

yarn publish

首先你将被询问要发布的新版本号:

[1/4] Bumping version...
info Current version: 1.0.0
question New version: _____

接着你将被要求输入你的 npm 密码:

[2/4] Logging in...
info npm username: your-npm-username
info npm username: you@example.com
question npm password: ____________

最后,Yarn 将发布包并且注销你的会话。

[3/4] Publishing...
success Published.
[4/4] Revoking token...
success Revoked login token.
✨  Done in 10.53s.

每次你想发布一个新版本,你可以随着上面相同的流程。

访问你的包

你的包现在应该在 https://www.npmjs.com/package/my-new-project 并且你应该可以安装它:

yarn add my-new-project

你也可以在 npm registry 里看所有信息:

yarn info my-new-project
{ name: 'my-new-project',
  description: 'My New Project description.',
  'dist-tags': { latest: '1.0.0' },
  versions: [ '1.0.0' ],
  maintainers: [ { name: 'Your Name', email: 'you@example.com' } ],
  time:
  { modified: '2017-10-12T00:22:35+00:00',
    created: '2017-10-12T00:22:35+00:00',
    '1.0.0': '2017-10-12T00:22:35+00:00' },
  homepage: 'https://my-new-project-website.com/',
  keywords: [ 'cool', 'useful', 'stuff' ],
  repository:
   { url: 'https://example.com/your-username/my-new-project',
     type: 'git' },
  contributors:
   [ { name: 'Your Friend',
       email: 'their-email@example.com',
       url: 'http://their-website.com' },
     { name: 'Another Friend',
       email: 'another-email@example.com',
       url: 'https://another-website.org' } ],
  author: { name: 'Your Name', email: 'you@example.com' },
  bugs: { url: 'https://github.com/you/my-new-project/issues' },
  license: 'MIT',
  readmeFilename: 'README.md',
  version: '1.0.0',
  main: 'index.js',
  files: [ 'index.js', 'lib/*.js', 'bin/*.js' ],
  bin: { 'my-new-project-cli': 'bin/my-new-project-cli.js' },
  dist:
   { shasum: '908bc9a06fa4421e96ceda243c1ee1789b0dc763',
     tarball: 'https://registry.npmjs.org/my-new-project/-/my-new-project-1.0.0.tgz' },
  directories: {} }