managed-bower

Motivation

The unix philosophy Do one thing and do it well guides the node ecosystem, it is not surprising that web developers are starting to adopt this approach as well. One of the downsides to the unix philosophy is the amount of dependencies you need in order to create a complex application.

In contrast to the battle harden npm that rule the land of commonjs packages, managing web dependencies is less straightforward. The current heavyweight champion for web dependencies package manager is bower, it has many problems, but aligning with the unix philosophy we aim to address only one.

#Goal

Our Goal is to managed web dependencies without the use of the bower.json, personally I prefer no to use configuration files, more specifically I think that web dependencies should be resolve in one of the stages of the build process, giving us the ability to manage the project web dependencies according to the run environment - local/test/dev/prod etc’.

#Methodology

As mentioned earlier we follow the unix philosophy which emphasise strings stream inputs and outputs, meaning our program inputs and outputs strings stream, this also fits well to the gulp ecosystem which give us access to large number of plugins we for future use. Following the KISS principle we choose to pipe the stream as is, without any modification (at least in this early stage).

The obvious problem we needed to solve was where to place the bower meta data needed for resolving the dependencies, basically where to place the package names. There were two solutions for that, assigning it as a configuration or embedding it within the input streams as parameters. Choosing the configuration solution would be like placing bandaid on the problem we were trying to solve, most likely it would lead to generating bower.json file via javascript code. Placing the needed data in the context in which it is required, meaning the HTML files, seems like the better solution, HTML is a well defined standard that can easily be expended, in addition, adding the bower meta data to it would turn it from imperative to declarative (at lease at the build stage).

#Solution

Our current solution is simple:

  1. Add managed-bower attribute to the script tag.
  2. Add name="my-package" attribute to the script tag, my-package is the bower package name.
  3. Stream the HTML files to managed-bower, directly or with gulp, consult the readme for usage examples.

#Roadmap

No particular order:

  • Use other tags, <link> the first one.
  • Package versions.
  • Namespaces (for archiving modularity).
  • Cleaning HTML file.
  • Inlining the required files (this would most likely would be in a different project).
  • Add configuration to return the required files.
  • Well, whatever you suggest.


Share this article: