How to Publish your Yarn Package to the npm Registry
In the last tutorial we learnt how to create a package, the tutorial you are about to read will show how to publish the created package.
If you want to share your package with other developers around the world, aside the ones in your team through Yarn; you will need to publish it first.
Your package will go to the npm registry once you publish it using Yarn. The npm registry is used to distribute packages globally.
Logging into npm
You will need to create an npm account if you don't have one. Once you have done that you can then setup your username and email in Yarn.
yarn login
when you run the command above it will prompt you for your username and email. However, yarn will not request a password from you. Whenever you want to publish or modify something on npm, you will have to enter your password then.
Publishing your package
When you write the code for your package, tested it and you are sure you are ready to publish it, you will need to run the command below to start things up:
yarn publish
A. The first thing that yarn requests from you is a new version to publish:
[1/4] Bumping version...
info Current version: 1.0.0
question New version: _____
B. The next thing that will be required is your npm password:
[2/4] Logging in...
info npm username: your-npm-username
info npm username: [email protected]
question npm password: ____________
C. The final thing yarn will do, is to publish the package and revoke your session token.
[3/4] Publishing...
success Published.
[4/4] Revoking token...
success Revoked login token.
Done in 10.53s.
This is the flow for publishing a new version of your package.
Accessing your package
The package you just uploaded should be available at https://www.npmjs.com/package/my-new-project and it is should also be available for installation by running:
yarn add my-new-project
If you want to see all the info in the npm registry run the code below:
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: '[email protected]' } ],
time:
{ modified: '2019-10-04T14:13:23+00:00',
created: '2019-10-04T14:13:23+00:00',
'1.0.0': '2019-10-04T14:13:23+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: '[email protected]',
url: 'http://their-website.com' },
{ name: 'Another Friend',
email: '[email protected]',
url: 'https://another-website.org' } ],
author: { name: 'Your Name', email: '[email protected]' },
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: {} }
Previous:
Creating your first Yarn Package with Git integration.
Next:
Understanding dependencies in Yarn packages.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/yarn/publishing-a-package.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics