diff --git a/lib/Package.js b/lib/Package.js index df201e1..c7ab4c7 100644 --- a/lib/Package.js +++ b/lib/Package.js @@ -270,10 +270,11 @@ Package.prototype.resolveDependencies = function(callback) { * @return {Array} An array representing a list of NPM package dependencies */ Package.prototype.generateDependencyAST = function() { + var self = this; var dependencies = []; - for(var dependencyName in this.providedDependencies) { - var dependency = this.providedDependencies[dependencyName]; + Object.keys(self.providedDependencies).sort().forEach(function(dependencyName) { + var dependency = self.providedDependencies[dependencyName]; // For each dependency, refer to the source attribute set that defines it var ref = new nijs.NixAttrReference({ @@ -297,7 +298,7 @@ Package.prototype.generateDependencyAST = function() { } dependencies.push(dependencyExpr); - } + }); if(dependencies.length == 0) { return undefined; // If no dependencies are required, simply compose no parameter. Though not mandatory, it improves readability of the generated expression diff --git a/lib/SourcesCache.js b/lib/SourcesCache.js index 5a75231..09bf538 100644 --- a/lib/SourcesCache.js +++ b/lib/SourcesCache.js @@ -33,12 +33,13 @@ SourcesCache.prototype.addSource = function(source) { * @see NixASTNode#toNixAST */ SourcesCache.prototype.toNixAST = function() { + var self = this; var ast = {}; - for(var identifier in this.sources) { - var source = this.sources[identifier]; + Object.keys(self.sources).sort().forEach(function(identifier) { + var source = self.sources[identifier]; ast[identifier] = source.toNixAST(); - } + }); return ast; };