Giter Club home page Giter Club logo

Comments (16)

wooorm avatar wooorm commented on May 18, 2024

Are both mdast and mdast-html global in your example case? I agree that it should work, and it worked before, so this is indeed a bug.

from remark.

eush77 avatar eush77 commented on May 18, 2024

Are both mdast and mdast-html global in your example case?

Yes, they are.

from remark.

eush77 avatar eush77 commented on May 18, 2024

Just noticed that in my case mdast was npmlinked. After removing the link and doing npm i mdast -g global plugins are working again.

Perhaps mdast should also consult npm prefix as a last step if none of other patterns match. What do you think?

from remark.

wooorm avatar wooorm commented on May 18, 2024

Seems to not be very simple: https://github.com/h2non/requireg#differences-with-require

from remark.

wooorm avatar wooorm commented on May 18, 2024

Also: I don’t think many people will link mdast into global, so if for this to work 5+ paths need to be checked, I’d rather decline...

from remark.

eush77 avatar eush77 commented on May 18, 2024

if for this to work 5+ paths need to be checked, I’d rather decline

In reality, there are not so many of them.

From Node docs:

If the NODE_PATH environment variable is set to a colon-delimited list of absolute paths, then io.js will search those paths for modules if they are not found elsewhere.
[…]

Additionally, io.js will search in the following locations:
1: $HOME/.node_modules
2: $HOME/.node_libraries
3: $PREFIX/lib/node

Where $HOME is the user's home directory, and $PREFIX is io.js's configured node_prefix.

These are mostly for historic reasons.

Note that (1) these paths are practically deprecated, (2) none of them is where npm puts modules upon global install, and (3) they are part of the Node core, so default require() algorithm works just fine!

$ echo 'module.exports=function(){return function(ast){ast.children.push({"type":"text","value":"hi there"})}}' >~/.node_libraries/hello.js
$ echo '# hello' |mdast -u hello
# hello

hi there

<stdin>: no issues found

So this is not what this issue is about. It really is about paths used by npm but not native to the Node. From npm docs:

Global installs on Unix systems go to {prefix}/lib/node_modules. Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)

And so there are only two paths currently missing: {prefix}/lib/node_modules and {prefix}/node_modules.

from remark.

wooorm avatar wooorm commented on May 18, 2024

That makes things better. Know if it's easy to access that prefix reliably, sync?

from remark.

eush77 avatar eush77 commented on May 18, 2024

First of all, npmrc needs to be taken into account, you can use rc for that.

In the past, this one-liner worked for me pretty well:

rc('npm', null, []).prefix || path.resolve(process.execPath, '../..')

Upd: On Windows default prefix should be path.resolve(process.execPath, '..') according to the docs.

from remark.

wooorm avatar wooorm commented on May 18, 2024

Cool! Any reason why the windows case is not handled by your module?

from remark.

eush77 avatar eush77 commented on May 18, 2024

It is handled in 1.0.1 :)

from remark.

wooorm avatar wooorm commented on May 18, 2024

One last Q: I'd like to only load global plug-ins when mdast is global too. That prevents a local mdast from loading a global plugin (by throwing a helpful error). Any idea if and how that would be possible? I have no clue, maybe you do, but this looks important.

from remark.

eush77 avatar eush77 commented on May 18, 2024

One idea is to check if process.argv[1] is {prefix}/bin/mdast ({prefix}/mdast on Windows). That is not very pretty though.

Alternatively, if __dirname is under {prefix}, then mdast is definitely global (but in this case it could be not installed directly by the user, and this test also fails if mdast is linked).

from remark.

wooorm avatar wooorm commented on May 18, 2024

I haven’t checked this on Windows. Are you able to test there?
I opted for checking if process.argv[1] is inside $prefix, which seemed like the simplest check for this.
I tested in npm-run scripts, and with using a linked mdast(1).
I think this should work 😄

from remark.

eush77 avatar eush77 commented on May 18, 2024

I haven’t checked this on Windows. Are you able to test there?

Nope, sorry.

from remark.

wooorm avatar wooorm commented on May 18, 2024

Darn, well, I think this should work. So let’s leave it at that!

from remark.

eush77 avatar eush77 commented on May 18, 2024

👍

from remark.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.