d.r.y. technique for multiple dependencies with same version?

353 views
Skip to first unread message

Anthony Kerz

unread,
Oct 30, 2013, 7:20:56 PM10/30/13
to twitte...@googlegroups.com
i'm relatively new to the js space, so bear with me:

for this bower.json file:

{
  "name": "ng-boilerplate",
  "version": "0.3.1",
  "devDependencies": {
    "angular": "~1.2.0-rc.3",
    "angular-mocks": "~1.2.0-rc.3",
    "bootstrap": "~3.0.1",
    "angular-bootstrap": "~0.3.0",
    "angular-ui-router": "~0.0.1",
    "angular-ui-utils": "~0.0.3"
  },
  "dependencies": {}
}

angular and angular-mocks should be at the same version,
if this was a maven pom.xml file or grails build-config.groovy file which serve similar purposes,
i would be able to set a single variable to say "~1.2.0-rc.3' in the example above and refer to 
it in both the angular and angular-mocks dependencies.

is the issue here that dot-json files don't support variables like that so we are forced to repeat "~1.2.0-rc.3"
twice, or is there some trick to specify the version once and refer to it twice...?

if bower.json was more of a bower.js file, then we could use variables...?

regards,
tony. 

Sindre Sorhus

unread,
Nov 1, 2013, 1:51:25 PM11/1/13
to twitte...@googlegroups.com
Nope. JSON can't have variables, and Bower will always use JSON as a package format. It's not that hard to update two lines once in a while.

Anthony Kerz

unread,
Nov 25, 2013, 10:48:16 AM11/25/13
to twitte...@googlegroups.com
thanks sindre,

works for me.

to edify the uninitiated, can you very briefly summarize your rationale around preferring JSON over javascript for this configuration?

as a noob, i'm just curious about the thought process around why grunt uses script for config and others like bower and npm use json...

regards,
tony.

Sindre Sorhus

unread,
Nov 26, 2013, 6:55:55 AM11/26/13
to twitte...@googlegroups.com
We want bower.json to be readable even in non-JS environments and tools. Eg. Ruby tools that reads the dependencies in bower.json. It's also heavily inspired by npm which does the same.

Frédéric Camblor

unread,
Jul 17, 2014, 6:24:32 AM7/17/14
to twitte...@googlegroups.com
Hi,

Couldn't we think about something keeping the JSON format, but needing some processing after the parsing ?

Something like this :
{
  "name": "ng-boilerplate",
  "version": "0.3.1",
  "properties": { 
    "angular.version":"~1.2.0-rc.3" 
  },
  "devDependencies": {
    "angular": "${angular.version}",
    "angular-mocks": "${angular.version}",
    "bootstrap": "~3.0.1",
    "angular-bootstrap": "~0.3.0",
    "angular-ui-router": "~0.0.1",
    "angular-ui-utils": "~0.0.3"
  },
  "dependencies": {}
}

where `${..}` strings would be interpolated in json leaf values.

It would need some processing after parsing, but this is already the case with "dependencies" and "devDependencies" : different meanings for each notion.

To my POV, variabilizing versions have a greater meaning than just being lazy.
It really means "I want to use same version for both of this libs"
Typically, I might use different version names for same version values in some cases.
Reply all
Reply to author
Forward
0 new messages