npm / node-which

Like which(1) unix command. Find the first instance of an executable in the PATH.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relative paths stopped working

satazor opened this issue · comments

I got a bug report in cross-spawn-async related to relative paths not working correctly. After investigation, which changed handling of relative paths in 1.2.5. The same test when using which@1.2.4 passes. As a workaround, if I do path.resolve before calling which it works correctly.

I will add a test case if necessary.

Well that's weird, because 1.2.5 was supposed to fix handling of relative paths. I'll dig in soon.

Feel free to send a PR (or just paste an example) with a failing test case.

@satazor Can you try npm i npm/node-which#fix-relative-more and see if that fixes the issue?

@isaacs when I arrive home I will try it out!

@isaacs I confirm that fix-relative-more branch is working correctly!

@satazor \o/ Awesome. I'll add a test and try to get this shipped soon.

Not sure if this is related issue, but I see some inconsistency in how which and this modules works:

 ...Projects/OSS/sort-staged-example    master ✘ ✹ ✚   $ which ./front/postcss/sort         
./front/postcss/sort

 ...Projects/OSS/sort-staged-example    master ✘ ✹ ✚   $ node bin/which ./front/postcss/sort 
module.js:457
    throw err;
    ^

Error: Cannot find module '/Users/okonet/Projects/OSS/sort-staged-example/bin/which'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.runMain (module.js:590:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

@okonet That's not a problem with this code, it's a problem when the way you're trying to invoke it. Observe:

$ cat ./front/postcss/sort
echo ok

$ ls -laF ./front/postcss/sort
-rwxr-xr-x  1 isaacs  staff  8 Dec 19 15:16 ./front/postcss/sort*

$ ./front/postcss/sort
ok

$ which ./front/postcss/sort
./front/postcss/sort

$ npm i which -S
x@3.0.0 /Users/isaacs/dev/js/x
└── which@1.2.12

$ node node_modules/.bin/which ./front/postcss/sort
./front/postcss/sort