Skip to content

Commit

Permalink
Asynchronous rc library
Browse files Browse the repository at this point in the history
  • Loading branch information
vladtsf committed Feb 4, 2013
1 parent 00bc0d4 commit 438c6fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
33 changes: 17 additions & 16 deletions lib/package.coffee
Expand Up @@ -3,7 +3,7 @@
class Package class Package


fs = require "fs" fs = require "fs"
rc = require "rc" rc = require "runtime-configuration"
url = require "url" url = require "url"
util = require "util" util = require "util"
glob = require "glob" glob = require "glob"
Expand Down Expand Up @@ -154,24 +154,25 @@ class Package
return callback.call( @, err ) if err return callback.call( @, err ) if err


# load npmrc configuration # load npmrc configuration
@rc = rc "npm", registry: "https://registry.npmjs.org/" rc "npm", registry: "https://registry.npmjs.org/", ( err, config ) =>
@rc = config


try try
# try to load info from package.json # try to load info from package.json
@pkg = @require @path @pkg = @require @path


# fill dependencies # fill dependencies
@dependencies = @pkg.dependencies @dependencies = @pkg.dependencies
@devDependencies = @pkg.devDependencies @devDependencies = @pkg.devDependencies


callback.call @ callback.call @
catch e catch e
if e.code is "ENOENT" if e.code is "ENOENT"
# if package.json not exists, should initialize dependencies # if package.json not exists, should initialize dependencies
@create callback @create callback
else else
# if package.json is broken # if package.json is broken
callback.call @, e callback.call @, e


@ @


Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"request": "2.12.0", "request": "2.12.0",
"wrench": "1.4.4", "wrench": "1.4.4",
"colors": "0.6.0-1", "colors": "0.6.0-1",
"rc": "0.0.6" "runtime-configuration": "0.1.1"
}, },
"devDependencies": { "devDependencies": {
"mocha": "1.8.1", "mocha": "1.8.1",
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js
@@ -1,7 +1,7 @@
global.fs = require( "fs" ) global.fs = require( "fs" )
global.path = require( "path" ) global.path = require( "path" )
global.wrench = require( "wrench" ) global.wrench = require( "wrench" )
global.rc = require( "rc" ) global.rc = require( "runtime-configuration" )
global.sinon = require( "sinon" ) global.sinon = require( "sinon" )
global.request = require( "request" ) global.request = require( "request" )
global.exec = require('child_process').exec global.exec = require('child_process').exec
Expand Down
7 changes: 4 additions & 3 deletions test/specs/programmatic/package.coffee
@@ -1,8 +1,9 @@
describe "Package", -> describe "Package", ->


before -> before ( done ) ->
@npmrc = rc "npm", registry: "https://registry.npmjs.org/" rc "npm", registry: "https://registry.npmjs.org/", ( err, @npmrc ) =>

done()

describe "@lookup()", -> describe "@lookup()", ->


it "should lookup package.json in specified directory", ( done ) -> it "should lookup package.json in specified directory", ( done ) ->
Expand Down

0 comments on commit 438c6fa

Please sign in to comment.