How to detect a package's dependents?


Suppose packages B, C, and D depend on package A, but only packages B and D are installed in an app. How can we in package A determine that the current dependents of package A are B and D?

I can imagine walking up until I find .meteor, looking in there at the packages file, then based on the names in there go look at each package either in the app’s packages folder, or in ~/.meteor/package to see which ones call api.use on package A. That’s a bad idea though since there could be tons of packages to look through.

Is there an official way?


I have an alternative:

Expose a method in package A that every dependent must call.

Package B would call this for example: PackageA.registerDependent('package-b')


@sanjo That’s a great idea for runtime code! The thing is I need to do this in a build plugin that I’ve registered with Package.registerBuildPlugin. The code for the plugin runs during the build phase, before runtime. Any ideas?


If you have a fixed set of packages that you know that they depend on package A, you can just have this list of packages in package A and see if they are in .meteor/packages. Would make it easier.

Two packages that could be helpful for you:


That’s true in that case. In my case the set of packages that depend on Package A will be unpredictable from app to app.

Thanks for the links! I was planning to do similar like that, detecting .meteor to find the app path, etc. The downside is it’s not official and could break when/if Meteor changes things.


Ah, well, the findAppDir comes from velocity, so their method is fairly official. I’ll just scan the packages listed in .meteor/packages after finding the app dir.


The findAppDir is originally from the Meteor command line tool code (Meteor core). Both packages are used in Velocity and I will keep them up to date for new Meteor releases. sanjo:meteor-files-helpers also has tests for all functions.