get-alex / alex

Catch insensitive, inconsiderate writing
https://alexjs.com
MIT License
4.81k stars 208 forks source link

Can't resolve paths in /tmp directory on macOS #290

Closed kaoru closed 4 years ago

kaoru commented 4 years ago

Can't resolve paths in /tmp directory on macOS

I think this is related to https://github.com/get-alex/alex/issues/266

Your environment

Steps to reproduce

  1. Create a file in /tmp
  2. Attempt to run alex on the file from your home directory

Works fine if the file is in my home directory:

alex@orihime:~$ alex job-ad.md 
job-ad.md: no issues found

But breaks if the file is in /tmp:

alex@orihime:~$ alex /tmp/job-ad.md 
/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:366
  throw new Ctor(message)
  ^

RangeError: path should be a `path.relative()`d string, but got "../../tmp/job-ad.md"
    at throwError (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:366:9)
    at checkPath (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:385:12)
    at Ignore._test (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:502:5)
    at Ignore.ignores (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:541:17)
    at one (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/finder.js:255:51)
    at handleIgnore (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/finder.js:243:5)
    at done (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/ignore.js:41:7)
    at apply (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/find-up.js:190:7)
    at applyAll (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/find-up.js:180:7)
    at found (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/find-up.js:172:7)

It might be caused by /tmp being a symlink?

alex@orihime:~$ ls -l /tmp 
lrwxr-xr-x@ 1 root  admin  11 22 Oct  2019 /tmp@ -> private/tmp

Although actually it's still broken if I use the non-symlink path:

alex@orihime:~$ alex /private/tmp/job-ad.md 
/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:366
  throw new Ctor(message)
  ^

RangeError: path should be a `path.relative()`d string, but got "../../private/tmp/job-ad.md"
    at throwError (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:366:9)
    at checkPath (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:385:12)
    at Ignore._test (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:502:5)
    at Ignore.ignores (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/ignore/index.js:541:17)
    at one (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/finder.js:255:51)
    at handleIgnore (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/finder.js:243:5)
    at done (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/ignore.js:41:7)
    at apply (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/find-up.js:190:7)
    at applyAll (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/find-up.js:180:7)
    at found (/Users/alex/.nvm/versions/node/v12.13.1/lib/node_modules/alex/node_modules/unified-engine/lib/find-up.js:172:7)

It works if my current working directory is inside /tmp:

alex@orihime:/tmp$ alex job-ad.md 
job-ad.md: no issues found

Expected behaviour

It should be able to process the file when given an absolute path into /tmp

Actual behaviour

It crashes with a RangeError trying to convert the absolute path into a relative path.

wooorm commented 4 years ago

Hi there!

Did you also see how #266 was solved?

kaoru commented 4 years ago

Hi there!

Did you also see how #266 was solved?

I saw that #266 was broken in 8.0.1 and solved in 8.1.0 but I didn't see how, there wasn't a link to a PR or anything.

wooorm commented 4 years ago

There was indeed no fix necessary, I think it was reinstalling dependencies that fixed it!

kaoru commented 4 years ago

There was indeed no fix necessary, I think it was reinstalling dependencies that fixed it!

Huh, ok... I don't know how to do that. Searching for "npm update dependencies" is finding me a lot of pages that are assuming I'm using a package.json but I'm installing alex globally so that doesn't seem relevant.

Shouldn't npm install alex --global always install the right versions of the dependencies?

The error message stack trace implies the problem is with something called "ignore" or "unified-engine"? I tried uninstalling and reinstalling those packages:

$ npm uninstall -g ignore unified-engine

$ npm install -g ignore unified-engine  
+ unified-engine@8.0.0
+ ignore@5.1.8
added 77 packages from 50 contributors in 2.644s

But I'm still getting the same error.

wooorm commented 4 years ago

Thanks. I was able to reproduce your issue on unified-engine@7.0.0, which is still used in alex. It is solved (by these lines probably) in unified-engine@8.0.0.

The update to unified-engine will come somewhere these months, when alex receives a new major version.

wooorm commented 4 years ago

This should be fixed in 9.0.0!