why-jay / remark-lint-sentence-newline

Enforce a newline after an end of sentence in Markdown
7 stars 0 forks source link

Global CLI usage breaks? #19

Closed why-jay closed 8 years ago

why-jay commented 8 years ago

Hey @wooorm, could you help!

If I run the following inside this repo,

npm install -g remark
npm install -g remark-lint
npm install -g remark-lint-sentence-newline # global install!
remark --no-stdout -u remark-lint="external:[\"remark-lint-sentence-newline\"]" README.md

I get this error:

README.md
        1:1  error    Error: Cannot find module 'vfile-sort'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Users/chcokr/code/mdast-lint-sentence-newline/node_modules/remark-lint/lib/index.js:19:12)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)

✖ 1 error

Do you happen to know what this is about?

wooorm commented 8 years ago

Maybe because you’re still linked from the mdast- prefix?

# from mdast-lint-sentence-newline
npm unlink
cd ..
mv mdast-lint-sentence-newline remark-lint-sentence-newline
cd remark-lint-sentence-newline
rm -rf node_modules && npm install # just to be sure new module come along properly
npm link

...and try again.

Maybe it’s something else though? If this doesn’t work, please ping again!

why-jay commented 8 years ago

Ah, I know what the problem is now.

By external:[\"remark-lint-sentence-newline\"], remark looks up the local scope, not the global score (as in npm install vs npm install -g).

How could I address this?

wooorm commented 8 years ago

This is the list remark-lint supports, whereas this is what remark supports.

And this code ensures to only depend on globally installed plug-ins when remarkis also in global mode.

If you’re interested, you can do a PR :wink:

why-jay commented 8 years ago

So, in the case of this issue, the global remark-lint-sentence-newline rule is not being found because remark-lint only supports the following:

Am I correct?

wooorm commented 8 years ago

Yup!

wooorm commented 8 years ago

Also: the reason for not always loading global dependencies is in fact so that people get some error. When you package a .remarkrc file, you should add said rule to your dependencies and not depend on a global package.

why-jay commented 8 years ago

Right. I actually think the current behavior is good. I guess I need to change external:[\"remark-lint-sentence-newline\"] to refer to the global directory, but am not sure how to do this. Is there some sort of a Node.js way of referring to the global npm cache..?

Or do you think this is a better alternative: If a .remarkrc is being used, don't look up globally. Otherwise, do look up globally. Something like this.

wooorm commented 8 years ago

The only way to detect that is here in remark, but that’s in JS and not in a .remarkrc. Maybe you could specify an absolute path though?

Anyway, I think I prefer loading global plugins/rules when in global mode (so just like remark itself) over treating CLI flags different from .remarkrc.

why-jay commented 8 years ago

Ah, I see. That makes sense. So it comes down to: If remark is global, remark-lint should look up globally too. If this is correct, I'll work on a PR over the next couple of days.

wooorm commented 8 years ago

Yes, it is! When remark is global, it looks up a local remark-lint and if that isn’t found, it looks for a global remark-lint. So what we’re adding now is that remark-lint will load external rules normally but when it cannot find them in global mode, tries the global npm directory.

:+1:

why-jay commented 8 years ago

Now being tracked at https://github.com/wooorm/remark-lint/issues/38