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

Request: add main property, or empty index.js #5

Open
lennym opened this issue Feb 6, 2015 · 6 comments
Open

Request: add main property, or empty index.js #5

lennym opened this issue Feb 6, 2015 · 6 comments

Comments

@lennym
Copy link

lennym commented Feb 6, 2015

I'm trying to build some modules which depend on this, but since it can't be found with require.resolve() as it has no canonical file it's proving quite difficult to reliably resolve the install location to do fs.readFile etc on it. Looking in ./node_modules works in most cases, but not if the parent project already has this as a dependency.

Either adding a main property in the package.json to point to the template file (ideal scenario for me), or adding a blank (or maybe log a usage warning) index.js file in the root will allow require.resolve('govuk_template_mustache'); to successfully resolve the install location, and so make it easier to build other modules which sit on top of this without needing additional caveats.

@lennym
Copy link
Author

lennym commented Feb 6, 2015

Having hacked away at a few things for a while I managed to discover that

require.resolve('govuk_template_mustache/views/layouts/govuk_template.html');

worked ok.

However, it would be nice if the location of the template was defiend in the "main" property in package.json anyway just to make it a little easier to find, and more robust of the file structure were liable to change in future.

Thanks.

@tombye
Copy link

tombye commented Feb 10, 2015

@alexmuller @easternbloc could you feed into this? It sounds like Lenny's request is associated with conventions around usage of package.json so be good to hear your opinions on this change (my experience of this is limited).

@lennym
Copy link
Author

lennym commented Feb 10, 2015

Thanks @tombye

I had a few discussions on this topic on #nodejs irc channel, and general consensus was that "this is weird because it's not a node module and you'd never require it", so I'm not sure there's a lot of best practice.

Generally speaking though, the "main" property in the package.json should point to "the thing" for the module, so in this case, I don't think it's inappropriate for that to point to the template.

@easternbloc
Copy link

@lennym IMHO I think it should point at the "main" property. If you put in a pull request for it we can merge that for you. The npm module is generated here so you'll need to edit the main property on that project. https://github.com/alphagov/govuk_frontend_toolkit_npm

@lennym
Copy link
Author

lennym commented Feb 10, 2015

@easternbloc - I think you mean https://github.com/alphagov/govuk_template, but sure...

@easternbloc
Copy link

^^ that

lennym pushed a commit to lennym/govuk_template that referenced this issue Feb 10, 2015
It is useful when building modules which depend on the templates to be able to programmatically obtain the location of the template, especially so when installing as an npm package, as the install location may be dependent on other factors. Setting the "main" property of the package.json allows the full path of the tempalte to be ascertained using `require.resolve('govuk_template_*')` in a node environment.

See alphagov/govuk_template_mustache#5
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

3 participants