Permalink
Browse files

Use patched `semver` module to construct Depends on `nodejs` package

  • Loading branch information...
1 parent 0ae48c6 commit 59d5fffe039cba4ab929706349d835aa6fa070af @arikon committed Nov 2, 2011
Showing with 72 additions and 13 deletions.
  1. +32 −11 lib/cli.js
  2. +3 −2 package.json
  3. +37 −0 test.js
View
@@ -193,17 +193,11 @@ var makeSourcePackage = function(pkg, ver, opts) {
ctx.shortdesc = packageData.description || '';
ctx.longdesc = 'This is a debianized npm package';
- var deps = [],
- nodeVer = (packageData && packageData.engines && packageData.engines.node) ? SEMVER.clean(packageData.engines.node) : null;
- nodeVer = (nodeVer && nodeVer != '*') ? '(' + packageData.engines.node + ')' : '(>= ' + SEMVER.clean(process.version) + ')';
- deps = ['nodejs ' + nodeVer];
-
- if (packageData.dependencies) {
- for (var dep in packageData.dependencies) {
- deps.push(ctx.debianNamePrefix + dep + ' (' + packageData.dependencies[dep] + ')');
- }
- ctx.depends = deps.join(', ');
- }
+ var nodeVer;
+ try {
+ nodeVer = packageData.engines.node;
+ } catch(ignore) {}
+ ctx.depends = semverToDebian('nodejs', nodeVer);
},
function() {
@@ -295,3 +289,30 @@ var parseTemplate = function(template, vars) {
return (vars || {})[varName] || '';
});
};
+
+var parseRange = function(range) {
+ return SEMVER.toComparators(SEMVER.replaceStars(range.trim()));
+};
+
+var semverToDebian = function(pkg, ver) {
+ if(!ver) return pkg;
+
+ var ranges = parseRange(ver),
+ deps = [];
+
+ ranges.forEach(function(range) {
+ range.forEach(function(edge) {
+ if(!edge) {
+ deps.push(pkg);
+ } else {
+ edge = edge
+ .replace(/^(\d)/, '= $1')
+ .replace(/^(<|>)(\d)/, '$1$1 $2')
+ .replace(/^(>=|<=)/, '$1 ');
+ deps.push(pkg + ' (' + edge + ')');
+ }
+ });
+ });
+
+ return deps.join(' | ');
+};
View
@@ -20,9 +20,10 @@
"qq": "0.3",
"q-fs": "0.1",
"rimraf": "1",
- "semver": "1"
+ "semver": "https://github.com/arikon/node-semver/zipball/master"
},
+ "bundledDependencies": [ "semver" ],
"engines": {
- "node": ">=0.2.0"
+ "node": ">=0.4.0 <=0.7.0"
}
}
View
37 test.js
@@ -0,0 +1,37 @@
+var SEMVER = require('semver');
+
+var parseRange = function(range) {
+ return SEMVER.toComparators(SEMVER.replaceStars(range.trim()));
+};
+
+var semverToDebian = function(pkg, ver) {
+ if(!ver) return pkg;
+
+ var ranges = parseRange(ver),
+ deps = [];
+
+ ranges.forEach(function(range) {
+ range.forEach(function(edge) {
+ if(!edge) {
+ deps.push(pkg);
+ } else {
+ edge = edge
+ .replace(/^(\d)/, '= $1')
+ .replace(/^(<|>)(\d)/, '$1$1 $2')
+ .replace(/^(>=|<=)/, '$1 ');
+ deps.push(pkg + ' (' + edge + ')');
+ }
+ });
+ });
+
+ return deps.join(' | ');
+};
+
+console.log(semverToDebian('nodejs', '*'));
+console.log(semverToDebian('nodejs', '0.4.12'));
+console.log(semverToDebian('nodejs', '~0.4.0'));
+console.log(semverToDebian('nodejs', '0.4'));
+console.log(semverToDebian('nodejs', '0.4 || 0.5 || 0.6'));
+console.log(semverToDebian('nodejs', '=0.4'));
+console.log(semverToDebian('nodejs', '>=0.4.0 <0.7.0'));
+console.log(semverToDebian('nodejs', '0.x >=0.0.4'));

0 comments on commit 59d5fff

Please sign in to comment.