Skip to content

Publishing Packages

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.1 command.

Prerequisites

  • Ensure you have Meteor 3 installed. You can check your Meteor version and automatically download it if it's missing:
    bash
    meteor --version --release=3.0.1
  • Have a Meteor developer account. You can create one at Meteor's official website.

Step-by-Step Guide

1. Set Up Your Package

First, you need to create a package directory and set up your package structure.

  1. Create the package structure:
bash
meteor create --package user:package
cd package
  1. Edit the package.js file: This file contains metadata about your package and its dependencies. Here's an example structure:
javascript
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:

javascript
api.versionsFrom(['2.3', '3.0']);
  1. Create the main module file:
bash
touch my-package.js
  1. Create a test file (optional but recommended):
bash
touch my-package-tests.js

2. Develop Your Package

Add your package logic in my-package.js. For example:

javascript
export const greet = (name) => {
  return `Hello, ${name}!`;
};

3. Test Your Package

Before publishing, ensure your package works as expected.

  1. Run tests:
bash
meteor test-packages ./ --driver-package meteortesting:mocha
  1. Fix any issues encountered during testing.

4. Publish Your Package

Once your package is ready and tested, you can publish it using the following command:

bash
meteor publish --release=3.0.1

You can replace 3.0.1 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.

5. Verify Your Package

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:

bash
meteor add user:package

Tips

  • Versioning: Follow semantic versioning for your package versions to ensure compatibility and proper version management.
  • Documentation: Provide thorough documentation in the README.md file to help users understand how to use your package.
  • Git Repository: Keep your package source code in a version-controlled repository like GitHub for easy collaboration and updates.

By following these steps, you should be able to publish your Meteor packages with Meteor 3 successfully. Happy coding!