Skip to content

Share common modules between extensions #8477

Closed
dnbard opened this Issue Jul 21, 2014 · 1 comment

3 participants

@dnbard
dnbard commented Jul 21, 2014

Hello. I have an idea on how to share same modules between extensions and don't load them multiple times. Brackets could use Bower.

  • Author define dependencies of his extension in bower.json config file:
{
"dependencies": {
    "lodash": "latest",
  }
}
  • Brackets search for bower.json in root folder of extension when it is installed
  • Brackets install all dependencies (using Bower) if bower.json is found
  • Then extension's author loading the module using:
//in Production
var lodash = brackets.getModule('bower/lodash');

//in Development (where no such module is available in Brackets module cache)
var lodash = brackets.getModule('bower/lodash') || require('./bower_modules/lodash/lodash.min');

This way common modules can be shared between all extensions and not being loaded in the memory more than an once.

@dangoor
dangoor commented Jul 29, 2014

My view on this is that sharing library code between extensions is not desirable. One of npm's greatest successes is the fact that dependencies of libraries that you include in your program are isolated from one another so that you don't get into dependency hell. Libraries can always count on having compatible versions of their dependencies.

Similarly, extensions should be able to count on having compatible versions of the libraries that they use.

What I do think is valuable (and I'm proposing that we lay the groundwork for this soon) is for extensions to share "services". The difference between a service and a library is that a service has data that is being shared. Consider, for example, a service that parses the current file into a JavaScript AST that other extensions could then use to further transform the code. This is quite different from the npm way of doing things where require("foo") gets you a copy of the library that is unique to your module... require("jsast/ast") or something like that would give you access to a singleton shared by the whole of Brackets.

If multiple extensions want to use lodash, there's not much harm in them each having their own copy. They could use the one built in to Brackets, but they risk Brackets core upgrading it to an incompatible version.

"Services" would need to maintain some level of API stability, in much the same way that web-based service APIs do.

@dangoor dangoor closed this Jul 29, 2014
@dnbard dnbard referenced this issue in dnbard/brackets-documents-toolbar Sep 24, 2014
Closed

Nice but ... You should get together with #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.