Skip to content

Commit

Permalink
Small refactorings + addition of some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
svanderburg committed Sep 12, 2016
1 parent 7e0221b commit 59dfd0b
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 86 deletions.
6 changes: 5 additions & 1 deletion lib/packagefetcher/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {

delete parsedUrl.hash;

/* Compose a Git URL out of the parsed object */
var gitURL = parsedUrl.format();

/* Compose a metadata object out of the git repository */
Expand Down Expand Up @@ -110,6 +111,7 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {
},

function(callback) {
/* When no commitIsh has been provide, parse the revision of HEAD */
var branch;

if(commitIsh === null) {
Expand Down Expand Up @@ -141,6 +143,7 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {

function(callback) {
if(commitIsh !== null && rev == "") {
/* If we were still unable to parse a revision, we try to parse the revision of the origin's branch */
process.stderr.write("Parsing the revision of commitish: origin/"+commitIsh+"\n");

/* Resolve the hash of the branch/tag */
Expand Down Expand Up @@ -169,6 +172,7 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {
if(rev == "") {
callback(null);
} else {
/* When we have resolved a revision, do a checkout of it */
rev = rev.substr(0, rev.length - 1);

process.stderr.write("Checking out revision: "+rev+"\n");
Expand Down Expand Up @@ -196,7 +200,7 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {
function(callback, packageJSON) {
packageObj = JSON.parse(packageJSON);

/* Search for .git files to prune out of the checkout */
/* Search for .git directories to prune out of the checkout */
var finder = findit(repositoryDir);

finder.on("directory", function(dir, stat) {
Expand Down
30 changes: 19 additions & 11 deletions lib/packagefetcher/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ var path = require('path');
var slasp = require('slasp');
var nijs = require('nijs');

function composeSourcePath(outputDir, versionSpec, resolvedPath) {
var first = versionSpec.substr(0, 1);

if(first === '~' || first === '/') { // Path is absolute
return versionSpec;
} else {
// Compose path relative to the output directory
var srcPath = path.relative(outputDir, resolvedPath);

if(srcPath.substr(0, 1) !== ".") {
srcPath = "./"+srcPath; // If a path starts with a . prefix it, so that it is a valid path in the Nix language
}

return srcPath;
}
}

/**
* @member packagefetcher.local
*
Expand All @@ -20,17 +37,8 @@ function fetchMetaDataFromLocalDirectory(baseDir, outputDir, versionSpec, callba
process.stderr.write("fetching local directory: "+versionSpec+" from "+baseDir+"\n");

var resolvedPath = path.resolve(baseDir, versionSpec);
var first = versionSpec.substr(0, 1);
if ( first === '~' || first === '/') {
var srcPath = versionSpec;
} else {
var srcPath = path.relative(outputDir, resolvedPath);

if(srcPath.substr(0, 1) !== ".") {
srcPath = "./"+srcPath;
}
}

var srcPath = composeSourcePath(outputDir, versionSpec, resolvedPath);

slasp.sequence([
function(callback) {
fs.readFile(path.join(resolvedPath, "package.json"), callback);
Expand Down
30 changes: 15 additions & 15 deletions node-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ let
sha1 = "2d46fa874337af9498a2f12bb43d8d0be4a36873";
};
};
"inherits-2.0.2" = {
"inherits-2.0.3" = {
name = "inherits";
packageName = "inherits";
version = "2.0.2";
version = "2.0.3";
src = fetchurl {
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.2.tgz";
sha1 = "7880e686ae72d327c3e7cdb406c3b71ad12b36b8";
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz";
sha1 = "633c2c83e3da42a502f52466022480f4208261de";
};
};
"typedarray-0.0.6" = {
Expand Down Expand Up @@ -1093,13 +1093,13 @@ let
sha1 = "7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0";
};
};
"signal-exit-3.0.0" = {
"signal-exit-3.0.1" = {
name = "signal-exit";
packageName = "signal-exit";
version = "3.0.0";
version = "3.0.1";
src = fetchurl {
url = "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.0.tgz";
sha1 = "3c0543b65d7b4fbc60b6cd94593d9bf436739be8";
url = "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.1.tgz";
sha1 = "5a4c884992b63a7acd9badb7894c3ee9cfccad81";
};
};
"string-width-1.0.2" = {
Expand Down Expand Up @@ -1350,7 +1350,7 @@ let
sources."chownr-1.0.1"
(sources."concat-stream-1.5.2" // {
dependencies = [
sources."inherits-2.0.2"
sources."inherits-2.0.3"
sources."typedarray-0.0.6"
(sources."readable-stream-2.0.6" // {
dependencies = [
Expand Down Expand Up @@ -1409,7 +1409,7 @@ let
(sources."readable-stream-2.0.6" // {
dependencies = [
sources."core-util-is-1.0.2"
sources."inherits-2.0.2"
sources."inherits-2.0.3"
sources."isarray-1.0.0"
sources."process-nextick-args-1.0.7"
sources."string_decoder-0.10.31"
Expand Down Expand Up @@ -1542,7 +1542,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.2"
sources."inherits-2.0.3"
(sources."minimatch-3.0.3" // {
dependencies = [
(sources."brace-expansion-1.1.6" // {
Expand All @@ -1568,7 +1568,7 @@ let
dependencies = [
sources."buffer-shims-1.0.0"
sources."core-util-is-1.0.2"
sources."inherits-2.0.2"
sources."inherits-2.0.3"
sources."isarray-1.0.0"
sources."process-nextick-args-1.0.7"
sources."string_decoder-0.10.31"
Expand All @@ -1584,7 +1584,7 @@ let
sources."has-color-0.1.7"
sources."has-unicode-2.0.1"
sources."object-assign-4.1.0"
sources."signal-exit-3.0.0"
sources."signal-exit-3.0.1"
(sources."string-width-1.0.2" // {
dependencies = [
(sources."code-point-at-1.0.0" // {
Expand Down Expand Up @@ -1619,7 +1619,7 @@ let
sources."proto-list-1.2.4"
];
})
sources."inherits-2.0.2"
sources."inherits-2.0.3"
sources."ini-1.3.4"
(sources."mkdirp-0.5.1" // {
dependencies = [
Expand Down Expand Up @@ -1689,7 +1689,7 @@ let
})
];
})
sources."inherits-2.0.2"
sources."inherits-2.0.3"
];
})
(sources."temp-0.8.3" // {
Expand Down
30 changes: 15 additions & 15 deletions tests/grunt/node-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ let
sha1 = "988df33feab191ef799a61369dd76c17adf957ea";
};
};
"signal-exit-3.0.0" = {
"signal-exit-3.0.1" = {
name = "signal-exit";
packageName = "signal-exit";
version = "3.0.0";
version = "3.0.1";
src = fetchurl {
url = "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.0.tgz";
sha1 = "3c0543b65d7b4fbc60b6cd94593d9bf436739be8";
url = "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.1.tgz";
sha1 = "5a4c884992b63a7acd9badb7894c3ee9cfccad81";
};
};
"array-find-index-1.0.1" = {
Expand Down Expand Up @@ -580,13 +580,13 @@ let
sha1 = "db3204cd5a9de2e6cd890b85c6e2f66bcf4f620a";
};
};
"inherits-2.0.2" = {
"inherits-2.0.3" = {
name = "inherits";
packageName = "inherits";
version = "2.0.2";
version = "2.0.3";
src = fetchurl {
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.2.tgz";
sha1 = "7880e686ae72d327c3e7cdb406c3b71ad12b36b8";
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz";
sha1 = "633c2c83e3da42a502f52466022480f4208261de";
};
};
"once-1.4.0" = {
Expand Down Expand Up @@ -1292,7 +1292,7 @@ let
sources."array-find-index-1.0.1"
];
})
sources."signal-exit-3.0.0"
sources."signal-exit-3.0.1"
];
})
sources."map-obj-1.0.1"
Expand Down Expand Up @@ -1407,7 +1407,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.2"
sources."inherits-2.0.3"
(sources."once-1.4.0" // {
dependencies = [
sources."wrappy-1.0.2"
Expand All @@ -1425,7 +1425,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.2"
sources."inherits-2.0.3"
(sources."once-1.4.0" // {
dependencies = [
sources."wrappy-1.0.2"
Expand Down Expand Up @@ -1545,7 +1545,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.2"
sources."inherits-2.0.3"
(sources."once-1.4.0" // {
dependencies = [
sources."wrappy-1.0.2"
Expand Down Expand Up @@ -1581,7 +1581,7 @@ let
sources."core-util-is-1.0.2"
sources."isarray-0.0.1"
sources."string_decoder-0.10.31"
sources."inherits-2.0.2"
sources."inherits-2.0.3"
];
})
sources."entities-1.0.0"
Expand Down Expand Up @@ -1619,7 +1619,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.2"
sources."inherits-2.0.3"
(sources."once-1.4.0" // {
dependencies = [
sources."wrappy-1.0.2"
Expand Down Expand Up @@ -1653,7 +1653,7 @@ let
sources."depd-1.1.0"
(sources."http-errors-1.3.1" // {
dependencies = [
sources."inherits-2.0.2"
sources."inherits-2.0.3"
sources."statuses-1.3.0"
];
})
Expand Down
18 changes: 9 additions & 9 deletions tests/grunt/supplement.nix
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ let
sha1 = "988df33feab191ef799a61369dd76c17adf957ea";
};
};
"signal-exit-3.0.0" = {
"signal-exit-3.0.1" = {
name = "signal-exit";
packageName = "signal-exit";
version = "3.0.0";
version = "3.0.1";
src = fetchurl {
url = "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.0.tgz";
sha1 = "3c0543b65d7b4fbc60b6cd94593d9bf436739be8";
url = "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.1.tgz";
sha1 = "5a4c884992b63a7acd9badb7894c3ee9cfccad81";
};
};
"array-find-index-1.0.1" = {
Expand Down Expand Up @@ -580,13 +580,13 @@ let
sha1 = "db3204cd5a9de2e6cd890b85c6e2f66bcf4f620a";
};
};
"inherits-2.0.2" = {
"inherits-2.0.3" = {
name = "inherits";
packageName = "inherits";
version = "2.0.2";
version = "2.0.3";
src = fetchurl {
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.2.tgz";
sha1 = "7880e686ae72d327c3e7cdb406c3b71ad12b36b8";
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz";
sha1 = "633c2c83e3da42a502f52466022480f4208261de";
};
};
"once-1.4.0" = {
Expand Down Expand Up @@ -1285,7 +1285,7 @@ in
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.2"
sources."inherits-2.0.3"
(sources."minimatch-3.0.3" // {
dependencies = [
(sources."brace-expansion-1.1.6" // {
Expand Down
Loading

0 comments on commit 59dfd0b

Please sign in to comment.