Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: allowing include to accept directories #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lorensr
Copy link

@lorensr 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

@@ -303,6 +313,14 @@ zappa.app = ->

rewritten_sub(root_context, include_locals)

root_locals.include = (name) ->
fs.stat name, (err, stats) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants