onilabs / stratifiedjs

Oni StratifiedJS (previously Apollo)
http://onilabs.com/stratifiedjs
Other
231 stars 22 forks source link

cannot launch apollo repl under windows #11

Closed caizongchao closed 12 years ago

caizongchao commented 12 years ago

First thanks for your great work on apollo.

While launching apollo under windows with command "node.exe apollo", the following error appears:

Uncaught: Error: Cannot load module 'apollo:nodejs/repl'. (Underlying exception: Error: ENOENT, open 'K:\apollo\apollo\modules\nodejs\repl.sjs' and then Error: ENOENT, open 'K:\apollo\apollo\modules\nodejs\repl' (in apollo-sys-nodejs.sjs:310)) (in apollo-sys-common.sjs:702)

The root directory of apollo is k:\apollo, so the correct path of repl.sjs should be k:\apollo\modules\nodejs\repl.sjs, but it resolves to K:\apollo\apollo\modules\nodejs\repl.sjs'

I have tried node 0.6.18 and 0.7.9 and get the same error.

afri commented 12 years ago

Thanks a lot for the bug report!

The path mapping is fixed on the master branch now. You should be able to run 'node apollo' or, if node is on your path, you can just run './apollo' from a bash shell (such as Git Bash).

Note that there appear to be some things that still aren't working under Windows though. E.g. the 'rocket' webserver script executes fine, but it doesn't seem to actually open any port on Windows :-/

caizongchao commented 12 years ago

I did some research on this issue, below is my fix:

https://github.com/caizongchao/apollo/commit/c8ca26830dfe916396e8429a6920283e8aeddc37

Both apollo and rocket works under windows now. This fix is just for your reference and you should have better solution for this issue.

I added two files apollo.cmd and rocket.cmd for windows users who do not have bash installed.

I was also curious why the code below did not work in "src / sys / apollo-sys-nodejs.sjs":

var file_url_encode = (function() { if( process.platform === "win32" ) { return function(path) { return ("file:///" + path.replace(/\/g, "/")); }; } else { return function(path) { return ("file://" + path); } } })();

After built and run ./apollo, it reports that file_url_encode is undefined. It seems that the function is not evaluated. To make it work I have to write in a less effecient way:

function file_url_encode(path) { if( process.platform === 'win32' ) { return ('file:///' + path.replace(/\/g, '/')); } else { return ('file://' + path); }; }

afri commented 12 years ago

Awesome, thanks a lot! I'll feed your fix into the master branch soon.

To answer your question, the reason why your dynamic "var file_url_encode=..." code didn't work is because of the way apollo-sys-common.sjs and apollo-sys-nodejs.sjs get appended together at compile time: Together they form the 'sys' module (and in the browser it would be -common + -xbrowser). Now, apollo-sys-common.sjs makes a call to 'getTopReqParent_hostenv' which in turn calls your function file_url_encode. Your dynamic definition 'var file_url_encode=...' will not have executed by that time. Conversely, if you define it as a function, JS automatically hoists the definition to the beginning of the script, which is why your second code works.

afri commented 12 years ago

apollo & rocket are working for windows now. I've also added your apollo.cmd & rocket.cmd to the master branch.

Thanks again!

caizongchao commented 12 years ago

Great, thanks!