Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share private meteor packages between multiple projects?

Tags:

meteor

If you want to use a package between two projects, what's the best way to handle it. Considering two scenarios :-

First Scenario

Git Repository with the two projects like

root folder
    -- Mobile App Folder
    -- Web Folder

So both projets are in the same repository

Second Scenario

Each project is in separate Git repositories and we want to share the package between those projects.

What's a good ways to handle each scenario? ( Either using the same method for both, or different methods for each scenario)

like image 585
Keith Nicholas Avatar asked Mar 26 '15 21:03

Keith Nicholas


People also ask

How do I import npm packages into Meteor?

In Meteor, it is also simple and straightforward to use the import syntax to load npm packages on the client or server and access the package’s exported symbols as you would with any other module. You can also import from Meteor Atmosphere packages, but the import path must be prefixed with meteor/ to avoid conflict with the npm package namespace.

How are JavaScript files loaded in a Meteor project?

By default, any JavaScript files in your Meteor application folder are bundled and loaded on both the client and the server. However, the names of the files and directories inside your project can affect their load order, where they are loaded, and some other characteristics.

How do I Share my code with another node project?

The first step across all the following options is to move your code into a separate Node.js project. This project will have its own package.json file. Once you've moved your shared code into a separate project, link the project as a dependency using npm link.

Where should I put my code in Meteor?

Any sensitive code that you don’t want served to the client, such as code containing passwords or authentication mechanisms, should be kept in the server/ directory. Meteor gathers all your JavaScript files, excluding anything under the client, public, and private subdirectories, and loads them into a Node.js server instance.


1 Answers

You need to be aware of how Meteor handles package scanning when confronted with meteor add package :

  • searching for it inside the local packages/ folder of your app.
  • searching for it inside every folder specified in the PACKAGE_DIRS environment variable.
  • searching for it on Atmosphere.

Not sure about the specific order but I'm assuming the one that makes most sense.

So your question is basically where to store the package for an optimal workflow.

Using the fist scenario, you would store your private packages inside the app root folder under packages/, you'll just have to git pull from the repo to get the latest versions of the packages. Then you would have to make sure to define correctly the PACKAGE_DIRS env variable, something like this :

export PACKAGE_DIRS=$PACKAGE_DIRS:$HOME/meteor/my-repo/packages

Using the second scenario, you would store each private package on its own git repo, then pull them into a local $HOME/meteor/packages of yours and don't forget to set PACKAGE_DIRS appropriately.

export PACKAGE_DIRS=$PACKAGE_DIRS:$HOME/meteor/packages

I would tend to go with the second scenario if there's a chance that these private packages may be reused for other projects, if you are sure they only make sense in a particular project, then storing them along in the repo is OK.

like image 107
saimeunt Avatar answered Sep 22 '22 15:09

saimeunt