tlrobinson / narwhal

[DEPRECATED] A JavaScript standard library, package manager, and more.
http://narwhaljs.org/
372 stars 16 forks source link

Module.id in Windows Includes file extension (.js) Which Disrupts Directory Structure #71

Open pnewhook opened 14 years ago

pnewhook commented 14 years ago

I was trying to run

tusk.cmd help 

but i get the following error:

C:\Gited\280North\narwhal>tusk.cmd help Usage: help [OPTIONS] COMMAND A Narwhal project package manager. require error: couldn't find "C:\Gited\280North\narwhal\lib\narwhal\tusk.js\list"

I looked at tusk.js and found

parser.command('list', module.id + '/list');

if i replace this with

parser.command('list', C:/Gited/280North/narwhal/lib/narwhal/tusk' + '/list');

The example works. Obviously you can't hard code the file path, but I couldn't find where module.id was set to override the windows behaviour.

I'm running Windows XP SP3

kriskowal commented 14 years ago

module.id ultimately gets set in lib/sandbox.js (look for module.id = id). I'm not sure how it's keeping the extension. It might be a bug in the module search algorithm, but more likely one of the file system routines. Would you be able to isolate this?

pnewhook commented 14 years ago

I'd like to try to isolate this but I'm not sure where to start. IN sandbox.js i don't see module.id=id. the closest thig i have is

if !Object.prototype.hasOwnProperty.call(modules, id) || reload)
            modules[id] = {};

one line 228 or

        var module = {
            'id': id,
            'path': factory.path
        };

on line 246.

How would you recommend isolating it? Is this something the Rhino debugger may help with?

kriskowal commented 14 years ago

Yeah, the Rhino debugger will give you a stack trace; you can put probes (hahah, euphemism for print(data)) into all the active functions and evaluate whether they're doing what they're supposed to, namely, not putting .js in the module identifier.

pnewhook commented 14 years ago

I dropped this into sandbox.js

        var module = {
            'id': id,
            'path': factory.path
        };
        print(module.id);
        factory(require, exports, module, subsystem, subprint);

And this is what I got on the Rhino console:

global array object string regexp date binary binary-engine function json system io io-engine file file-bootstrap file-engine os os-engine logger narwhal args util term packages packages-engine C:\Gited\narwhal\lib\narwhal\tusk.js http http-engine Usage: help [OPTIONS] COMMAND A Narwhal project package manager.

so something is definitely wrong with the way the Tusk module is loaded. What's your recommendation to look into this?

kriskowal commented 14 years ago

Oh! This is very helpful. It seems that the narwhal/tusk module is being loaded as a script instead of as a module, which is very possible depending on the tusk shell script. I'll look into this.

kriskowal commented 14 years ago

Please let me know if this fixes the problem: http://github.com/kriskowal/narwhal/commit/14821bbe823fd550ce19a0b6aac6f568efd055f5

pnewhook commented 14 years ago

I tried your fix and I think it may have worked, but I can't tell 100% because there appears to be another problem. I tried both applying your patch to the 280 North fork and your repository and got the same results. I ran tusk.cmd help still with that line in sandbox.js to print module.id and got this C:\Gited\narwhal>tusk.cmd help global array object string regexp date binary binary-engine function json system io io-engine file file-bootstrap file-engine os os-engine logger narwhal args util term packages packages-engine narwhal\tusk http http-engine

so it looks like it's finding tusk properly. I ran this again in the debugger and the application just stalled at http-engine.js

function(require,exports,module,system,print){ var IO = require('./io').IO;

exports.IO = function (url) { return new IO( new java.net.URL(url).openStream(), null ); };

// */ }

I tried commenting out the require(http) like in tusk.js but then it stalls at narwhal/tusk

Should I close this ticket and open a new one or is this related?

ps Thanks for all your help.