-
-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple globally installed presets and plugins don’t work #165
Comments
Could you rub with This problem can occur if |
I create a gist with the logs and the In this example I was trying to disable
I think this situation can happen very frequently as So when Wouldn't it be better to depend on module/rule name rather than Object identity? |
The configuration you posted in the gist in different from what you posted above. Which one is this issue about? Red flattening: that's what enables duping on object equality, otherwise it wouldn't be possible at all! |
Where is your configuration file compared to the readme file you are processing? The logs show that it isn't found? What are you using to run remark? |
I deleted the reproduction env I created yesterday and I posted a similar case instead. Sorry for the confusion. Here is the gist with the case initially mentioned: https://gist.github.com/pvdlg/1ad2570fa203a1270f1b9e66d1930bff The file structure is:
I use the CLI |
Hmm, how weird! What are the versions of node, npm, remark-lint, the preset, and the rule? |
The new gist I posted also has the error Even though |
Yeah, the configuration is read, I misread the logs as saying otherwise as well, but a later line shows its reading the configuration file anyway! |
$ npm ls -g remark-lint 23ms
/Users/vanduynslager/.npm-packages/lib
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected] $ npm ls -g remark 8s 672ms
/Users/vanduynslager/.npm-packages/lib
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└─┬ [email protected]
└── [email protected] $ npm ls -g remark-preset-lint-recommended 7s 958ms
/Users/vanduynslager/.npm-packages/lib
└── [email protected] $ npm ls -g remark-lint-list-item-indent 8s 118ms
/Users/vanduynslager/.npm-packages/lib
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected] |
I could try. But I might loose the reproduction env. Plus I'd rather not have to delete my global |
Ohhh, I thought stuff was local. I’m guessing global mode interferes with the normal state of things. Why are all things global? |
Why are all things global? Because I'd like to lint any markdown files including:
|
That said, even in a local install you can't predict that you won't have two version of the same package coexisting. This is why I proposed to rely on module/rule name rather than on object identity to dedupe. |
There’s no good way of doing this, I think, but you’re the first to raise an issue about it after it existing for a while. And probably because of global installs! Why not create a |
This is more or less my config. Everything is installed globally and I put Are you suggesting to have a |
Yes, or even point from your config file to plugins in some other directory: // ~/.remarkrc
{
"plugins": [
"./some/place/node_modules/remark-preset-lint-recommended",
["./some/place/node_modules/remark-lint-list-item-indent", false] // a
["./some/place/node_modules/remark-preset-lint-recommended/node_modules/remark-lint-list-item-indent", false] // or b
]
} |
I just tried that:
It doesn't work, and still report |
Hmm. 🤔 Does |
With:
I get the error: $ ls ~/.npm-packages/lib/node_modules/remark-preset-lint-markdown-style-guide 400ms → 1
index.js node_modules package.json readme.md |
To make it works I have to configure:
|
Interestingly So it doesn't seems to be related to duplicate packages in the tree with different versions. |
No, it’s exactly because global mode doesn’t dedupe! You can use global mode, but in that case, when reconfiguring plugins, you need to point to the deeper plugin! Global mode doesn’t flatten the tree, which is why it’s not suitable for this. npm installs stuff differently in |
I'm not sure it's a dedupe issue as I have only one time the package Also does that mean to works locally you need to run |
So here’s what’s going on:
When I’m talking about deduping I mean the flatting that npm and yarn do automatically. A clean I suggest using |
I understand. But as you develop and add new modules this deduped state will not be guaranteed. you would have to delete
It's a working workaround indeed. I'm not sure it's the ideal approach though. It makes it really really hard to lint markdown that is not in a node project. All other linters (eslint, stylelint) do not rely on plugin/rule identity but on names, so this problem doesn't happen. So they can be used globally with globally installed configs and plugin. |
I also have a frustratingly hard time to override a rule. I also use remark-cli globally, with a .remarkrc.yaml file in ~.
My input file is
and this is the output.
So, the rule list-item-indent is not suppressed.
then I get an error: Error: Could not find module
So there is a serious problem here. I am at a loss how to get a preset to work and then changing one of its rules! |
There is a difference between installing rules and activating, using them. So my proposal would be:
which switches on all the rules of mentioned presets, which can be individually overridden by subsequent declarations. An other thing: it would be nice if remark-stringify would look at the same options as the parser. |
Any update with this issue? I was trying configure stuff with I would suggest editing the title of this issue to make it more obvious the problem is related to globally installed plugins. Also, I understand the proposed workaround of installing plugins locally in
@wooorm, would that be too difficult to implement in the current codebase? Would you be against PRs in that direction? |
Done, thanks for suggesting!
Not really, globally installed plugins is an anti-pattern, as global stuff is meant to be a top-level thing, not to be resolved and used.
This would mean that about ±200 plugins, often from the community, would need to be updated, that we can’t rely on node’s module caching (because we load different plugins, but pick one of them because they share an identifier), and that those identifiers also need to change when a new version is published. |
Relying on module/rule name is the better solution, to not have conflicts with versions of the rule. Eslint does this too, and rules are named according to I'm currently trying to use some presets together, and the one overwrites some rule of the other, and that's fine. It's only very strange how remark-lint is setup, as each preset needs to include |
Yes, exactly, and it's better to not mix them. Presets should just turn rules on/off, and define their plugin peer-dependencies. |
Imho, instead of doing this, it might be better to work towards a new major release where installing plugins and turning on/off rules are separated, which will make it easier to use and understand, and probably will also make it easier to implement, no? It will solve the problem mentioned in this thread, and probably a lot of other problems too. (Also, this library is not the only one that needs certain instances to be unique, which is a real pain, like mongoose etc....) I would be interested to do some work on this. Is there any roadmap to a new major release? |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
These new comments seem off topic, as they are not about global presets/plugins, so I’ll hide them. Please do not post off-topic comments and please use the designated support channels.
Looks like you found a solution. That’s also the solution I would recommend. |
@wooorm I apologize if these seemed off topic but I am referring to the original poster's initial issue The reason I posted here and why I thought it was on topic is that I was pointing out that using
@wooorm I apologize if I wasn't clear. I did not view this as a solution as I believe if you individually "re"-install each of the individual rules, that has worked all along and you can modify/disable them. But the issue (in my opinion) is that these individual rules are already installed as dependencies when you install a preset like My multiple comments above were iterating as I learned and found other related datapoints throughout my research. I wanted to bring full context of what I was attempting, researching and learning along the way. Does that make sense? Essentially the TLDR of what I still consider a problem and why my proposed "workaround" of manually adding each rule to the package.json is not a solution is because these rules are already installed as dependencies and should be able to be modified / disabled without needing to also add them each to the package.json. I believe that it is because the checking for installed individual rules is assuming Hopefully that helps clarify. Does that make sense? Any questions? Thanks! |
That’s how pnpm chooses to work. If they and you want that. That’s a choice. npm doesn’t work like that. Except when installing globally (which is an anti-pattern because it doesn’t version and could easily break). You use JSON for your config file. JSON is a shorthand for JS. Your JSON: "plugins": [
"preset-lint-recommended",
[
"remark-lint-list-item-indent",
"space",
]
] Is equivalent to the JS: import remarkPresetLintRecommended from 'remark-preset-lint-recommended'
import remarkLintListItemIndent from 'remark-lint-list-item-indent'
plugins: [
remarkPresetLintRecommended,
[
remarkLintListItemIndent,
'space'
]
] Which explains why you need to explicitly install them in pnpm. Presumably you could do: TLDR: we depend on how Node can resolve things. Because we run in Node. Sometimes without wrappers. So it’s simplest to work exactly like Node does always, otherwise it’d be inconsistent. The solution to configuring many rules is: make your own preset! |
Thank you for showing me the alternative method with JS imports. That should work. For anyone else that stumbles across a similar issue as me with pnpm, another option is to use |
Following the example in the README.md.
$ remark .
The
list-item-indent
rule should have been disabled, but it's still active.The text was updated successfully, but these errors were encountered: