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

(include "module") doesn't seem to work as described. #96

Open
riatzukiza opened this issue Oct 21, 2016 · 5 comments
Open

(include "module") doesn't seem to work as described. #96

riatzukiza opened this issue Oct 21, 2016 · 5 comments

Comments

@riatzukiza
Copy link

I attempted the example in the documentation for "sibilant-react", and on macro libs I'd written my self, and it does not seem to resolve.

@riatzukiza
Copy link
Author

I think this may have to do with:

(def create-context ()
     (var context (vm.create-context))
     (set module 'filename (pipe (process.cwd) (concat "/exec")))
     (set context
          '*sibilant sibilant
          'module  module
          'require require)
     (each-key key global (set context key (get global key)))
     context)

this is from the repl file, but it causes a similar kind of issue as what I see with inclusion for the require statement, in that it cannot find modules. It is looking from them from the directory that sibilant is installed, not from where it is run.

I have fixed problems like this before in custom module systems I've build for http servers, I'll be seeing what I can do with this.

@riatzukiza
Copy link
Author

(def create-context ()
  (var context (vm.create-context)
       cwd (process.cwd))

  (set module 'filename (pipe cwd (concat "/exec")))

  (var p "/")
  (assign module.paths [
          ...module.paths
          ...(.map (.split cwd path.sep)
                   (lambda (el)
                     (var r (path.join p "node_modules"))
                     (assign p (path.join p el)) r))
          cwd
          (path.join cwd "node_modules")
          ])
  (set context
       '*sibilant sibilant
       'module  module
       'require (modded-require (process.cwd)))
  (each-key key global (set context key (get global key)))
  context)

I have made the following modifications to the create context function, it can find the modules properly inside of a repl context. Much better! now the repls actually useful.

@riatzukiza
Copy link
Author

The above example is not what was used in the fork to fix this, I'd originally thought I could fix it like I had fixed another similar problem with requiring in dynamic contexts, and temporarily borrowed it.

(macro add-to-module-lookup (path)
       `(scoped (require! 'path)
                (var p "/"
                     inc @(or path (process.cwd)))
                (assign module.paths [
                        ...module.paths
                        ...(.map (.split inc path.sep)
                                 (lambda (el)
                                   (var r (path.join p "node_modules"))
                                   (assign p (path.join p el)) r))
                        (path.join inc "node_modules")
                        ])))

there is now a macro that can be used any where to add a new path to the require look up.

@riatzukiza
Copy link
Author

I thought this would have fixed the inclusion issue as well, but its a no go.

sibilant> (include "sibilant-react")
(include "sibilant-react")

/home/aaron/devel/by-lang/js/sibilant/maps/src/repl.sibilant:96
(readline.on 'line handle-line)
                   ^
TypeError: Cannot read property 'match' of undefined
    at Interface.<anonymous> (/home/aaron/devel/by-lang/js/sibilant/maps/src/repl.sibilant:96:20)
    at Interface.<anonymous> (/home/aaron/devel/by-lang/js/sibilant/lib/repl.js:128:10)
    at Interface.handleLine$ (/home/aaron/devel/by-lang/js/sibilant/lib/repl.js:130:6)
    at emitOne (events.js:96:13)
    at Interface.emit (events.js:188:7)
    at Interface._onLine (readline.js:239:10)
    at Interface._line (readline.js:585:8)
    at Interface._ttyWrite (readline.js:869:16)
    at ReadStream.onkeypress (readline.js:126:10)
    at emitTwo (events.js:106:13)

@riatzukiza
Copy link
Author

Not sure why the above was happening... maybe I've now changed somthing else that magically fixed it, not sure.

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

No branches or pull requests

1 participant