jspm / nodelibs-path

MIT License
0 stars 3 forks source link

path not working as expected #2

Open CxRes opened 9 years ago

CxRes commented 9 years ago

Given a string 'foo/bar', I am getting the following outputs:

console.log(path.dirname('foo\\bar')); //outputs "."
console.log(path.basename('foo\\bar')); //outputs "foo\\bar"

As you can guess I am on windows. The bug occurs when I use jspm version of path but not when I use node version.

guybedford commented 9 years ago

Can you share a larger example here how you are loading path? If you do jspm install path and then import path from 'path' it will use the Node native path implementation.

CxRes commented 9 years ago

Hmmm... I am loading path in a nwjs/node-webkit app in the browser context.

Normally, in nwjs, I would just require('path') and it will load the path from nodejs version that it contain internally. But when I use JSPM, JSPM hijacks the require statement (as it is supposed to) - require will work according to Systemjs config and not nwjs. It was in this context that I did jspm install path, which is when the above problem occurs, and thats why I am pretty sure that the issue is with the browserify version. (For some reason I could not get _nodeRequire to work which was why I went this route).

Also, I ran my code on the command line with node and there was no problem in processing the string.

guybedford commented 9 years ago

@CxRes are you saying that your paths are running in the browser, but they have a Windows-style format? What browser are you using to get that behaviour?

CxRes commented 9 years ago

I am not sure what you mean here, specifically by paths "running" in the browser? nwjs uses v8 engine, so its effectively chrome.

What I am doing is setting up a watcher on filesystem (using node on Server or nwjs acting as a pseudo Server) and grabbing events in the client. I use path then to process the paths on the browser and display information to the user - think of it like a file-explorer/finder running in the browser which is looking a filesystem somewhere. That is why I need path in the client - not executing paths but manipulating path strings.

Its not a conventional use case but that is the beauty of nodejs - allowing same javascript code to run on both server and client :) .

guybedford commented 9 years ago

@CxRes the problem then is that System._nodeRequire is not being defined I think? SystemJS will need to have a handle to the environment Node core require to load the NodeJS core paths implementation.

CxRes commented 9 years ago

@guybedford Honestly, I wouldn't know how SystemJS identifies node in the environment - for me as an end user SystemJS is mostly magic!

All I know is some other version of path different from the NodeJS core path is being loaded after I do jspm install path which is buggy.

guybedford commented 9 years ago

@CxRes you can check exactly if System._nodeRequire is set, and if not that would be the reason here.

CxRes commented 9 years ago

Sorry for taking my time on getting back... been busy with other things. You are right, no System._nodeRequire is defined on the System object.

So should I file the feature request for environment node identification in node-webkit? Or should this be a concern of node-webkit developers?

guybedford commented 9 years ago

@CxRes yes please file an issue for node-webkit support here. It would be about ensuring we populate the _nodeRequire correctly for node-webkit in https://github.com/systemjs/systemjs/blob/master/lib/core.js#L52.