Permalink
Browse files

Fixed issue with require caching

  • Loading branch information...
1 parent 9df7f79 commit 33c42dc5609c51b0596421789626c89325e47f6e @vtsvang committed Jan 24, 2013
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/package.coffee
View
@@ -26,6 +26,14 @@ class Package
# Registry override
@registry = null
+ # Load and parse json file.
+ #
+ # @param [String] fPath path to json file
+ # @return [Object] parsed json
+ #
+ require: ( fPath ) ->
+ JSON.parse fs.readFileSync fPath
+
# Log message.
#
# @example Just log.
@@ -150,15 +158,15 @@ class Package
try
# try to load info from package.json
- @pkg = require @path
+ @pkg = @require @path
# fill dependencies
@dependencies = @pkg.dependencies
@devDependencies = @pkg.devDependencies
callback.call @
catch e
- if e.code is "MODULE_NOT_FOUND"
+ if e.code is "ENOENT"
# if package.json not exists, should initialize dependencies
@create callback
else
@@ -366,7 +374,7 @@ class Package
for own file in files
try
- { name, version } = require file
+ { name, version } = @require file
# if this package not listed in dependencies, add it
unless ( name in Object.keys ( @dependencies ? {} ) ) or ( name in Object.keys ( @devDependencies ? {} ) )
@@ -402,7 +410,7 @@ class Package
if ( not forceRemote ) and fs.existsSync( depPath = path.join ( path.dirname @path ), "node_modules", packageName, "package.json" )
# try to determine version according from node_modules containment at first
try
- callback.call @, null, require( depPath ).version
+ callback.call @, null, @require( depPath ).version
catch e
@fetch packageName, on, callback
else

0 comments on commit 33c42dc

Please sign in to comment.