Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
add name normalization, change install receipt to list of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
amccollum committed Nov 16, 2013
1 parent 5c5650b commit 2e60c5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
22 changes: 12 additions & 10 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@
* SOFTWARE.
*/

const npm = require('npm')
const npm = require('npm')
, path = require('path')
, util = require('./util')

, RepositorySetupError = require('./errors').RepositorySetupError
, RepositoryCommandError = require('./errors').RepositoryCommandError

// simple wraper around npm.commands.install()
var install = function (packages, callback) {
if (!this._isSetup) throw new RepositorySetupError('repository.setup() has not been called')

npm.commands.install(packages, function (err, installed, tree, pretty) {
npm.commands.install(packages, function (err, receipts) {
if (err) return callback(new RepositoryCommandError(err))

var ids = [], roots = []
installed.forEach(function (r) {
ids.push(r[0])
roots.push(r[1])
})

callback(null, ids, roots)
callback(null, receipts.map(function (r) {
return {
id: r[0]
, root: path.resolve(r[1])
, source: util.normalizeName(r[4])
}
}))
})
}

Expand Down
12 changes: 11 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ var getName = function (id) { return id.split('@')[0] }
: 'package'
)
}

, normalizeName = function (name) {
switch (getNameType(name)) {
case 'path' : return path.resolve(name)
case 'github' : return 'git://github.com/' + name
default : return name
}
}

, getChildRoot = function (name, parentRoot) {
return path.resolve(path.join(parentRoot || '.', 'node_modules', name))
Expand All @@ -60,11 +68,13 @@ var getName = function (id) { return id.split('@')[0] }
, getPackageDescriptor = function (root) {
return path.join(root, 'package.json')
}



module.exports = {
getName : getName
, getVersion : getVersion
, getNameType : getNameType
, normalizeName : normalizeName
, getChildRoot : getChildRoot
, getPackageDescriptor : getPackageDescriptor
}
Expand Down

0 comments on commit 2e60c5d

Please sign in to comment.