Skip to content
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

Module resolution npm: alias mapping assumes node_modules and eleventy config exist in same directory #211

Open
filmaj opened this issue Jul 7, 2024 · 3 comments

Comments

@filmaj
Copy link

filmaj commented Jul 7, 2024

First of all: you rock! Love the projects, excellent work, very grateful ❤️

I described my issue in a comment in some more detail over in the eleventy-plugin-webc repo.

I have an issue loading the is-land plugin in an 11ty webc project. I have a large, complicated webapp codebase, where eleventy is but a small part of a larger system. The eleventy bits are located in a subdirectory of this project, ./public, while the package.json for this project exists one directory up, in the root of the project. Thus, node_modules exists one parent directory above where the eleventy project exists.

My particular problem boils down to two issues, I think, which are related:

  1. The fsCache module seems (to me) unnecessarily restrictive re: requiring components to be subdirectories of the "working directory"
  2. npm: component loading aliasing assumes npm: maps to ./node_modules

Issue (1) effectively prevents setting webc component loading to any directory that is not an immediate subdirectory within the eleventy project. For a monorepo style setup, this seems like an unnecessarily restrictive constraint. As mentioned, since in my setup, node_modules is one level up above the eleventy project, that exception is troublesome. Could we consider dropping the code I linked to in (1)?

Issue (2) is related to the same problem: the npm: component loading alias assumes something about the location of the node_modules directory. There is a TODO here, tantalizingly hinting at perhaps the author foreseeing an issue similar to what I'm describing here. I was thinking one way to improve this would be to search up the file tree to find the npm project root first (by looking for the presence of a package.json file), and then joining that found project root with ./node_modules. I think that would solve this issue? What do you think?

I am happy to give a PR a go to try to fix this! I wanted first to check if my thinking is correct / is a PR worth it / would the project be responsive to the issue / provide guidance on how to go about improving the situation.

Thanks for any discussion and thank you once more for an amazing open source project!

@Ryuno-Ki
Copy link

Issue (1) was introduced to fix #10.
Limiting the scope to subdirectories is a good security measure.

I would expect the monorepo tool (lerna and friends) to handle the dependencies properly. Are you allowed to share how you manage the repo?

@filmaj
Copy link
Author

filmaj commented Dec 3, 2024

Apologies, I have since moved to a different solution and have stopped using webc as a result. Unfortunately, I did not save the project state from that time 😢

@Ryuno-Ki
Copy link

Ryuno-Ki commented Dec 6, 2024

That's fine. Do you mind to close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants