IonicaBizau / promptify

An easy-to-use prompt for Node.js.
MIT License
1 stars 1 forks source link

Path-checking fails on windows #2

Closed MichaelPaulukonis closed 9 years ago

MichaelPaulukonis commented 10 years ago

Running node node-demo.js throws an error:

Error: ENOENT, open 'd:\font\doh.flf'

Brief poking about shows that asciimo.js branched onto the else path of the following:

// Remark : not a very good env check
var fontPath;
if(typeof __dirname == 'undefined'){
  fontPath = './fonts/';
}
else{
  fontPath = __dirname.substring(0, __dirname.lastIndexOf("/")) + '/fonts/';
}

The windows path-separator is "\\", which works in a dumb-windows-only-replacement.

The following is a better patch:

// Remark : not a very good env check
var fontPath;
if(typeof __dirname == 'undefined'){
  fontPath = './fonts/';
}
else{
  fontPath = __dirname.substring(0, __dirname.lastIndexOf(require('path').sep)) + '/fonts/';
}

Although I'm itchy about the use of require for just one thing.

Is there a better fix? Are there other places in the code that should be fixed?

I plan on putting a pull-request through for this.

MichaelPaulukonis commented 10 years ago

That's a lousy fix -- since it won't work in the browser.

It needs to be something that works in node.js (os-agnostic) AND the browser....

IonicaBizau commented 9 years ago

https://github.com/IonicaBizau/jasciimo#deprecation-notice