v3-docs/v3-migration-docs/guide/publishing-packages.md
Publishing a Meteor package involves a few key steps, including setting up your package, testing it, and finally publishing it to the Meteor package repository. Here's a brief guide on how to publish Meteor packages using Meteor 3, specifically with the meteor publish --release=3.0.3 command.
meteor --version --release=3.0.3
First, you need to create a package directory and set up your package structure.
meteor create --package user:package
cd package
package.js file:
This file contains metadata about your package and its dependencies. Here's an example structure:Package.describe({
name: 'user:package',
version: '0.0.1',
summary: 'A brief description of my package',
git: 'https://github.com/myusername/my-package',
documentation: 'README.md'
});
Package.onUse(function(api) {
api.versionsFrom('3.0');
api.use('ecmascript');
api.mainModule('my-package.js');
});
Package.onTest(function(api) {
api.use('ecmascript');
api.use('tinytest');
api.use('user:package');
api.mainModule('my-package-tests.js');
});
If the package is also intended to work with Meteor 2 you can use:
api.versionsFrom(['2.3', '3.0']);
touch my-package.js
touch my-package-tests.js
Add your package logic in my-package.js. For example:
export const greet = (name) => {
return `Hello, ${name}!`;
};
Before publishing, ensure your package works as expected.
meteor test-packages ./ --driver-package meteortesting:mocha
Once your package is ready and tested, you can publish it using the following command:
meteor publish --release=3.0.3
You can replace 3.0.3 with the appropriate release version. If you omit the --release flag, it will default to the latest official Meteor version, which at the time of this writing is Meteor 2. That way packages published without specifying a release will not be compatible with Meteor 3, as there will probably be a fibers related error.
Login if prompted: You will be asked to log in with your Meteor developer account credentials if you aren't already logged in.
Publish confirmation: After logging in, your package will be published to the Meteor package repository.
To ensure your package has been published correctly, you can search for it in the Meteor package repository or try to add it to a Meteor project:
meteor add user:package
README.md file to help users understand how to use your package.By following these steps, you should be able to publish your Meteor packages with Meteor 3 successfully. Happy coding!