17

From the Meteor docs:

Give users of this package access to another package (by passing in the string packagename) or a collection of packages (by passing in an array of strings [packagename1, packagename2]).

I have no idea what it means.
From this question I know that imply can be employed with use.

What does api.imply do?
What's exactly the difference between api.use and api.imply?

2 Answers 2

18

api.use gives a package access to other packages exported symbols.

For example you need to api.use("random") (see how it's done in the accounts-base package) if you want to use the Random symbol in a package code (see how the random package.js is api.exporting Random).

However, meteor adding accounts-base wouldn't give your whole application access to its used packages (random in this case). If your app needs random, you'd still need to meteor add it.


api.imply on the other hand, gives the whole application access to that package exported symbols.

For example, see how accounts-google is api.implying accounts-base.

accounts-base is responsible for exporting the Accounts symbol, when you meteor add accounts-google, not only does accounts-base is also added in your application dependencies, but accounts-base symbols are also made available in your app, specifically because it was implied.


accounts-base is both using Accounts in its own code (api.use) and exporting its dependencies symbols to the whole app (api.imply).

api.imply can be used to make "shadow packages" that are just pulling in some other packages.

For example, at some point MDG renamed the showdown package to markdown, they could just have stated to meteor remove showdown && meteor add markdown, but it would have required some actions on end users.

What they did instead is keeping the showdown package and just make it implying the new markdown package.

3
  • 4
    I assumed api.export always exported to the full project! Actually, it's used to export objects which can then be imported in multiple ways: To the whole project (meteor add), to the scope of a package (api.use) or both (api.imply). Thanks for the insights!
    – Kyll
    Apr 30, 2015 at 15:01
  • This concept is basically the same as re-exporting in NPM packages, for example, in ES6: export {Foo} from 'other-package' or in CommonJS: exports.Foo = require('other-package').Foo. Meteor 1.3 supports NPM modules out-of-the-box now, just npm install in your app's root directory, then require() or import whatever you need in your app code (or write packages that re-export things, and optionally publish them on NPM instead of Atmosphere).
    – trusktr
    Jan 26, 2016 at 0:12
  • Perhaps I'm misunderstanding this but I don't really understand the difference between meteor add'ing a package, which makes it explicitly listed/defined, and api.imply'ing it.It seems like they essentially do the same thing, but that api.imply means now you potentially have a bunch of packages available that are hard to find/maintain because they're littered throughout an assortment of package definitions. Am I right about that, and if so, what's the strength in it over meteor add?
    – dudewad
    Mar 22, 2016 at 18:04
0

If you have something in your app that consumes api from package:name and you install just package package:dependant which has a package:name as a dependency, but you don't use imply here, your api from package:name will not work in the app. It will work only in package:dependant package. You need use imply if you want to use something from package:name outside your package:dependant

I don't know if this is clear ;)

2
  • I still don't get it. I have to use imply to have the API of the first package working in the whole app? And if I use imply it will export this API everywhere?
    – Kyll
    Apr 28, 2015 at 19:54
  • It will install package:name and you will be able to use it everywhere in the app. Just like it is when you run meteor add package:name Apr 28, 2015 at 20:02

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.