-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fix import path for plugins #3198
Conversation
This way it won't work of course (you're modified the |
Have a look at the paths var! Maybe it should not effect the plugin loading, but it does! And adding process.cwd()/node_modules to paths doesn't make any sense either, because it assumes that your current terminal location is always in a npm installation root dir. |
Well, I understand that it makes it accidentally to work for your particular setup and directory structures (I can read it in the corresponding thread), it just does not fix the problem at all. It's no way even a quick-and-dirty fix because "quick-and-dirty" is assumed to not break anything else (at least major) while your change simply breaks the whole "import" facility. It's not hard to guess why |
I guess I'll reopen the PR just marking it "consider closing" instead assuming you'll try to find a proper method (you'll update the PR by making new commits to your branch). Closing it instantly was just too harsh maybe. |
It's your good right to close the PR since it was an ugly and not useful attempt 😄 I just saw a comparable approach to get the right folder in the plugin-loader of less 2.7 (require("../../../" + name)). My brain is currently melted from programming in groovy. Sorry! |
@seven-phases-max Technically, @Franziskus1988 is right. There was a hard-coded value that was removed in the plugin refactor. Unfortunately, we had no test that tested that scenario, so things continued to work without it. See: https://github.com/less/less.js/blob/v2.7.3/lib/less-node/plugin-loader.js#L58 The thing about the pathing in 2.x is that it was kind of magic to plugins, and specifically to What happens now is that the Node environment adds lookup paths to the less default options. See: https://github.com/less/less.js/blob/master/lib/less-node/index.js#L20 By the looks of it, that means that this approach that @Franziskus1988 is largely correct, although I wouldn't delete and replace BUT: @Franziskus1988 if you want a proper PR to be considered, that would mean you need to then do the following:
I'm fine with a "magic value" if it can be PROVEN via documentation that the magic value is legitimately correct. I don't see that yet. I just see, "This makes this work now for me," which isn't quite good enough to be merged. If you can do that, a fix would be great! |
@seven-phases-max It's more the reverse. Imports were using the local environment settings, which mapped to the local file manager, which with 2.xlessc plugins
3.xlessc plugins
I think I have that documented correctly, but it's been a little while. In 3.x, there is no special file manager layer for plugins with But other than that, any file requests to the |
Just as an FYI, Less "default options" were also normalized for the Node environment across the API and |
Honestly for me https://github.com/less/less.js/blob/master/lib/less-node/index.js#L20
The Well, I guess it would be easier for one of us just to fix it the way we see it right rather than trying to explain how it supposed to be (honestly for me all this "less-node import resolver -> less-node plugin file resolver -> less-node file manager -> custom plugin evaluator" is like a Chinese - I usually think of things by documented options and concrete use-case examples (how it's implemented behind the scenes is not that really important)). |
The file manager resolves file lookups for the environment. In Node, file lookups are local to the file, then use Node's file resolution mechanism. You seem to be arguing that this shouldn't be the case, but it has been the case since As far as being valid directories, if you're in your
It doesn't pollute the It's possible you could do a different approach which merged hidden paths in the The documentation you refer to is still accurate; it's just that it was never updated to also refer to
True, all I was trying to say was:
There are trade-offs to But anyway, hope that clarifies things.
You're not going to offend me if you change things. As far as I'm concerned, in open source, decisions are made by those who show up. Whoever has the time to do the work should do the work. If you have a better way, do a PR and I'll probably give it 1,000 thumbs up. As you know, I'm trying to reduce my time on projects like Less, so whomever wants to do the work, go for it. |
But I am not (Why should I be?). That's the point. The cwd is allowed to be anywhere and this should not affect any path resolution (neither imports nor plugins) in either of The cwd directory is the directory only to resolve the command line file paths, e.g. as in For the rest, yes, I remember |
I don't have the braining today to fully dissect that philosophy, but in general, scripts looking for NPM modules from the root of where you invoked running the script is not really unusual at all. Actually not that unusual in the history of computing and running scripts. 🤷♂️ I guess maybe what you're saying is the path should be relative from something more like a path joined with And I'd also point out again that this isn't code I wrote, but basically code I moved, so that path resolution wasn't happening outside of the file manager, and that plugin resolution wasn't happening outside the core API. The paths chosen were originally here: https://github.com/less/less.js/blob/v2.7.3/lib/less-node/plugin-loader.js#L57-L81 So, philosophically, it sounds like you would argue against one of those path lookups, but you're debating the wrong person. If there's a valid use case where the right answer is derived, then that path should be looked up. At the least, we should support path lookups that were broken with this change, do you agree?
Umm... god no. These aren't hacks, in fact the hacks are gone. It's just a list of paths to resolve imports, which includes plugins. It probably just needs one more path to solve this problem. Literally the answer is exactly as I documented it to @Franziskus1988. That is: 1) edit the paths, 2) update tests, 3) document change, 4) submit PR. It's not difficult or complicated at all. It's basically a one-line change + some text edits to error statements + documentation. A few changes to this PR and it would be done. |
+100! (I may sound harsh - it's just my "always" because of being the freaking perfectionist, which is not good thing considering the efforts I put into Less recently. So please always consider my comments/remarks as of "A plain Less user" and not a contributor of any kind. @Franziskus1988 notice this please). So my only requirement for a fix to be a real fix is: |
@seven-phases-max Based on some more data about the history, does it seem reasonable then that this path would just change to remove Tryna think what the best option is here. It seems like a simple fix. |
I mean to go back to the original point:
How do you expect the Node environment to resolve that if you're running the binary from another non-relative folder? This is what I'm trying to understand. It's a non-trivial problem. Applications could be any layers of folders each with a 🤔 hmm.... |
I may have a way to fix this.... |
Please look at #3200. |
#3181 Less shouldn't search for plugins in process.cwd(), but in same node_modules folder like less is installed.