You are no doubt familiar with the packages that come with meteor, such as accounts-ui and underscore. There are the community-written packages on atmosphere like iron-router and jade. But what if you need to maintain your own super-secret package, or fork one that already exists? Local packages are what you need.
Publish with Relations
The example that I'll use in this post is publish-with-relations (PWR for short). It's a package that helps create reactive joins - something that is planned to be part of meteor core. PWR is incredibly useful but versions prior to this commit have a serious memory leak, and can't be recommended for production. Until the version gets bumped, I strongly recommend using a local copy.
You will need to tell meteor where to find the local packages on your system. Simply add an environment variable called
METEOR_PACKAGE_DIRS which points to the root package directory. Just edit your
~/.profile, (or whatever is appropriate for your OS) with the following:
All subdirectories under that path will be recursively searched first whenever you run
meteor add. Remember to source this file or start a new console window so the variable it set.
Create the Package
I typically start with a clean directory and copy over only the files I need, but for brevity let's just clone the existing repository. This will fetch the latest commit which is all we need to make this example work.
> cd "$HOME/path/to/packages"
> git clone "https://github.com/erundook/meteor-publish-with-relations.git" publish-with-relations
Modify package.js as needed
For newer packages you may not need this step, however if you are modifying code written prior to meteor 0.9 you will need to update your
package.js to the latest API specification. For PWR it should look something like:
summary: 'Publish associated collections at once.'
Add the Package
Finally we'll create a demo app and add our version of PWR.
> meteor create demo
> cd demo
> meteor add publish-with-relations
And that's it! You should now see
publish-with-relations in your