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

[Feature Request] Resolver for NPM Modules #1175

Closed
penx opened this issue Dec 13, 2018 · 1 comment · Fixed by #1197 · May be fixed by dubscratch/MagicMirror#16 or Matthelonianxl/create-an-issue#3
Closed

[Feature Request] Resolver for NPM Modules #1175

penx opened this issue Dec 13, 2018 · 1 comment · Fixed by #1197 · May be fixed by dubscratch/MagicMirror#16 or Matthelonianxl/create-an-issue#3

Comments

@penx
Copy link

penx commented Dec 13, 2018

This has previously been raised as #1136 but is still an issue.

As previously raised:

Suppose we have a package installed like this:

`npm i -S @example/cards`

Now want to import from it like this within a template:

`{% import "@example/templates/birthday.html" as birthday %}`

Could the nunjucks resolver implement NPMs resolv alogrithm?

A potential solution has previously been suggested:

nunjucks.configure('node_modules');
#1136 (comment)

However, as far as I know, this doesn't use standard node_modules resolution and so would not work under several conditions:

  • using npm link
  • having templates in peerDependencies, as the node_modules path could not be calculated relative to the current file
  • where a project has module1 as a dependency, module1 uses nunjucks, which in turn has a dependency on module2 that contains templates. Depending on the dependency tree, the templates may live in project/node_modules/module2, or project/node_modules/module1/node_modules/module2
  • when using yarn pnp, node_modules does not exist at a known location on disk
  • when using npm tink
  • in a monorepo (e.g. using lerna or yarn workspaces), which introduces several other patterns such as linking between modules
@penx
Copy link
Author

penx commented Dec 13, 2018

A possible solution would be to use the same convention as in some scss projects, in that starting a path with ~ infers using node_modules resolution:

{% import "~@example/templates/birthday.html" as birthday %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment