为了通过 Yarn 共享你的包给全世界的其他开发者,你需要先发布它。
通过 Yarn 发布的包会托管在 npm registry 上,用于全球分发。
登录到 npm
如果你从未登录过,那就先创建一个 npm 账号。创建完成后,在 Yarn 里设置用户名和email。
1. yarn login
这个命令会提示你输入用户名和 email, 但不需要输入密码。 Yarn 不保存你的密码,也不保持任何 Session。 当你真正发布或者修改 npm 上的包时,才需要输入密码。
发布你的包
在你写完代码、测试通过、准备发布的时候,你可以执行:
1. yarn publish
首先,需要输入新的版本号:
1. [1/4] Bumping version...
2. info Current version: 1.0.0
3. question New version: _____
之后,输入 npm 密码:
1. [2/4] Logging in...
2. info npm username: your-npm-username
3. info npm username: you@example.com
4. question npm password: ____________
最后,Yarn 将发布包并且注销你的会话。
1. [3/4] Publishing...
2. success Published.
3. [4/4] Revoking token...
4. success Revoked login token.
5. ✨ Done in 10.53s.
每次发布都可以遵循上述流程。
访问你的包
你应该可以通过 https://www.npmjs.com/package/my-new-project 来访问新上传的包,也可以通过以下命令安装:
1. yarn add my-new-project
你也可以看到 npm registry 里的全部信息:
1. yarn info my-new-project
1. { name: 'my-new-project',
2. description: 'My New Project description.',
3. 'dist-tags': { latest: '1.0.0' },
4. versions: [ '1.0.0' ],
5. maintainers: [ { name: 'Your Name', email: 'you@example.com' } ],
6. time:
7. { modified: '2018-12-05T09:28:54+00:00',
8. created: '2018-12-05T09:28:54+00:00',
9. '1.0.0': '2018-12-05T09:28:54+00:00' },
10. homepage: 'https://my-new-project-website.com/',
11. keywords: [ 'cool', 'useful', 'stuff' ],
12. repository:
13. { url: 'https://example.com/your-username/my-new-project',
14. type: 'git' },
15. contributors:
16. [ { name: 'Your Friend',
17. email: 'their-email@example.com',
18. url: 'http://their-website.com' },
19. { name: 'Another Friend',
20. email: 'another-email@example.com',
21. url: 'https://another-website.org' } ],
22. author: { name: 'Your Name', email: 'you@example.com' },
23. bugs: { url: 'https://github.com/you/my-new-project/issues' },
24. license: 'MIT',
25. readmeFilename: 'README.md',
26. version: '1.0.0',
27. main: 'index.js',
28. files: [ 'index.js', 'lib/*.js', 'bin/*.js' ],
29. bin: { 'my-new-project-cli': 'bin/my-new-project-cli.js' },
30. dist:
31. { shasum: '908bc9a06fa4421e96ceda243c1ee1789b0dc763',
32. tarball: 'https://registry.npmjs.org/my-new-project/-/my-new-project-1.0.0.tgz' },
33. directories: {} }
