Feature: allowing include to accept directories #81

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants

lorensr commented Sep 17, 2011

I'm currently getting a strange error and am hoping you might know what it is?

$ cat test.coffee
require('zappa/src/zappa') ->  
  include 'db'
$ ls db
model.coffee 
setup.coffee
$ coffee test.coffee
Express server listening on port 3000 in development mode
Zappa 0.2.0edge orchestrating the show

undefined:2
 if (this[i] === item) return i;  } return -1; };return (undefined).apply(cont
                                                                    ^
TypeError: Cannot call method 'apply' of undefined
    at anonymous (eval at <anonymous> (/Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:35:12))
    at Object.include_file (/Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:457:14)
    at /Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:473:30

@timshadel timshadel commented on the diff Sep 27, 2011

src/zappa.coffee
@@ -303,6 +313,14 @@ zappa.app = ->
rewritten_sub(root_context, include_locals)
+ root_locals.include = (name) ->
+ fs.stat name, (err, stats) ->
@timshadel

timshadel Sep 27, 2011

Contributor

Does this call have to by synchronous to make sure that all the pieces are loaded in a predictable order? I'm curious about potential race conditions that may result from the unpredictable callback execution order.

lorensr commented Oct 1, 2011

I changed it to

  root_locals.include = (name) ->
    if fs.statSync(name)?.isDirectory()
      for file in fs.readdirSync(name) when not is_tempfile file
        root_locals.include name + '/' + file
    else
      root_locals.include_file name

and the slightly different output I'm getting is

   info  - socket.io started
TypeError: Cannot call method 'apply' of undefined
    at anonymous (eval at <anonymous> (/Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:35:12))
    at Object.include_file (/Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:457:14)
    at Object.include (/Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:472:28)
    at /Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:467:39
    at Object.<anonymous> (eval at <anonymous> (/Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:35:12))
    at anonymous (eval at <anonymous> (/Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:35:12))
    at Object.app (/Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:480:5)
    at /Users/me/code/orgist/node_modules/zappa/src/zappa.coffee:782:18
    at Object.<anonymous> (/Users/me/code/orgist/test.coffee:2:63)
    at Object.<anonymous> (/Users/me/code/orgist/test.coffee:5:4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment