@liris-tech/meteor-private-package-linker

0.1.0 • Public • Published

[WIP - not usable yet] meteor-private-package-linker

Creates the symlink structure for interdependent private Meteor packages.

Problem statement

The way to encapsulate Meteor dependent code in Meteor projects is by using Meteor packages and publishing them to Atmosphere.

Sometimes, however, you need to keep business critical code in Meteor private packages. This can be done by putting those into the packages/ directory (by default) of the Meteor project.

The problem arises when those private packages depend on each other. Dependent packages need to be recursively symlinked into a packages/ directory inside the parent package as shown below.

Example: Meteor project containing 3 private packages A, B and C. A depends on both B and C. And B depends on C.

your/meteor/project
 ├── .meteor
 ├── package.json
 ├── [...]
 └── packages
      └── A
      │   ├── [...]
      │   ├── package.js
      │   └── packages
      │        ├── B # ---------------------- symlink to packages/B
      │        │   ├── [...]
      │        │   ├── package.js
      │        │   └── packages
      │        │        └── C # ------------- symlink to packages/C
      │        │            ├── [...]
      │        │            └── package.js
      │        └── C # ---------------------- symlink to packages/C
      │            ├── [...]
      │            └── package.js
      ├── B # ------------------------------- symlink to packages/B
      │   ├── [...]
      │   ├── package.js
      │   └── packages
      │        └── C # ---------------------- symlink to packages/C
      │            ├── [...]
      │            └── package.js
      └── C
          ├── [...]
          └── package.js

Doing this manually is error prone and cumbersome.

meteor-private-package-linker solves this problem.

Usage

cd /your/meteor/project
meteor npm install meteor-private-package-linker

In package.json add the following:

{
  ...
  "scripts": {
    ...
    "meteorlink": "node node_modules/meteor-private-package-linker/index.js --watch && meteor"
    "meteorlink-no-watch": "node node_modules/meteor-private-package-linker/index.js && meteor"
  }
}

The purpose of meteorlink is to watch for relevant file changes and update the symlinks on the go.

As such, for building the Meteor project, instead of simply meteor, you should now use:

# in development (with file-watch, so that symlinks are updated seemlessly)
npm run meteorlink

# in production (without file-watch)
npm run meteorlink-no-watch

# notice that the usual command-line arguments passed to meteor also work here
npm run meteorlink-no-watch --production

Advanced

The part below is useful but not mandatory.

Meteor forces private packages to be at the top-level of the project's packages/ directory.

With meteor-private-package-linker, you have the freedom to organize your packages as you see fit by setting the METEOR_PRIVATE_PACKAGE_DIRS env variable. For example, with the following structure:

your/meteor/project
 ├── .meteor
 ├── package.json
 ├── [...]
 └── my-private-packages
      ├── invoicing
      │    ├── A
      │    │   └── [...]
      │    └── B
      │        └── [...]  
      └── clients
           └── C
               └── [...]

you would set METEOR_PRIVATE_PACKAGE_DIRS to your/meteor/project/my-private-packages.

Executing meteorlink will then generate the following output:

your/meteor/project
 ├── .meteor
 ├── package.json
 ├── [...]
 └── my-private-packages
 │    ├── invoicing
 │    │    ├── A
 │    │    │   └── [...]
 │    │    └── B
 │    │        └── [...]  
 │    └── clients
 │         └── C
 │             └── [...]
 └── packages # ----------------------------- This is generated by meteorlink and used by meteor's build process
      └── A # ------------------------------- symlink to my-private-packages/invoicing/A
      │   ├── [...]
      │   └── packages
      │        ├── B # ---------------------- symlink to my-private-packages/invoicing/B
      │        │   ├── [...]
      │        │   └── packages
      │        │        └── C # ------------- symlink to my-private-packages/clients/C
      │        │            └── [...]
      │        └── C # ---------------------- symlink to my-private-packages/clients/C
      │            └── [...]
      ├── B # ------------------------------- symlink to my-private-packages/invoicing/B
      │   ├── [...]
      │   └── packages
      │        └── C # ---------------------- symlink to my-private-packages/clients/C
      │            └── [...]
      └── C # ------------------------------- symlink to my-private-packages/clients/C
          └── [...] 

💡 You can share private packages among several meteor projects:

your/meteor/project
 ├── .meteor
 ├── package.json
 └── [...]
your/other/meteor/project
 ├── .meteor
 ├── package.json
 └── [...]
my-private-packages-shared-among-several-projects
 ├── invoicing
 │    ├── A
 │    │   └── [...]
 │    └── B
 │        └── [...]  
 └── clients
      └── C
          └── [...]

💡 You can add /packages to the .gitignore of your meteor project.

Package Sidebar

Install

npm i @liris-tech/meteor-private-package-linker

Weekly Downloads

2

Version

0.1.0

License

ISC

Unpacked Size

126 kB

Total Files

17

Last publish

Collaborators

  • zforro