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

Add an experimental "hugo npm install" command #7644

Closed
bep opened this issue Sep 9, 2020 · 5 comments · Fixed by #7664
Closed

Add an experimental "hugo npm install" command #7644

bep opened this issue Sep 9, 2020 · 5 comments · Fixed by #7664
Assignees
Milestone

Comments

@bep
Copy link
Member

bep commented Sep 9, 2020

I have been struggling with some npm (e.g. node_modules) dependency setup with Hugo Modules, and I suspect I'm not alone.

I have been avoiding this issue for some time now, but I think I'm going to try out something simple. I'll call this "experimental" in the sense that as a Hugo feature it may be changed or possibly even removed (if it doesn't really work) in a future version without too much notice.

The premise here is that 1) It's not really practically possible to specify "path to package.json" etc. when running "npm install" and 2) While there is a defined lookup order for node_modules folders, that order is strictly file system hierarchical -- which doesn't really match how Hugo works in this area.

So, my current idea is that:

  • A Hugo module can have a package.json in its module root (which can be different from the Git repo root)
  • In Hugo, we have a well defined import order for all of these

So, if we

  1. Loop these modules in reverse order
  2. Write their package.json file to a (common) temp folder and run npm install
  3. When done, move the node_modules folder to the main project.

/cc @regisphilibert @budparr does this sound wild enough?

@bep bep added the Proposal label Sep 9, 2020
@bep bep added this to the v0.75 milestone Sep 9, 2020
@bep bep self-assigned this Sep 9, 2020
@regisphilibert
Copy link
Member

So this would mean all the imported Module's package.jsons, merge their dep and devDep entries into one big list and install them all?

I can see it as a way for Hugo Modules to specify their won npm packages and so would avoid having to ask the user to install x or x npm package (PostCSS, Tailwind etc...).

I'd love to play with that!

@bep
Copy link
Member Author

bep commented Sep 9, 2020

So this would mean all the imported Module's package.jsons, merge their dep and devDep entries into one big list and install them all?

Well, the end result will be like that, but I'm certainly not implementing that logic. My thinking is that a simple loop and then creating this "node_modules" overlay.

But I kind of don't know how this would work until I/we tried it out, hence the "experimental label".

@bep
Copy link
Member Author

bep commented Sep 9, 2020

... maybe a merge of the dependency sections would be simpler/faster -- I will experiment.

@bep
Copy link
Member Author

bep commented Sep 9, 2020

OK, I have thought a little more about this, and I think a good middle ground for this would be to:

  • When running hugo npm install I will look for a package.hugo.json (and only that) -- meaning I could probably call the command something else ...
  • The full dependency list will be written to package.json
  • This way it will be really transparent what the final "thing" is -- and you can commit it to Git and it will build right out of the box on Netlify etc. And it would be easy to implement.

Also, I've had a fair amount of Tailwind "minor version" breakage lately, so if I get time I will probably implement this using minimal version selection:

https://about.sourcegraph.com/blog/the-pain-that-minimal-version-selection-solves/

bep added a commit to bep/hugo that referenced this issue Sep 11, 2020
bep added a commit to bep/hugo that referenced this issue Sep 11, 2020
bep added a commit to bep/hugo that referenced this issue Sep 11, 2020
bep added a commit to bep/hugo that referenced this issue Sep 12, 2020
bep added a commit to bep/hugo that referenced this issue Sep 12, 2020
bep added a commit to bep/hugo that referenced this issue Sep 12, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

Fixes gohugoio#7644
Fixes gohugoio#7656
bep added a commit to bep/hugo that referenced this issue Sep 12, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

Fixes gohugoio#7644
Fixes gohugoio#7656
bep added a commit to bep/hugo that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

Fixes gohugoio#7644
Fixes gohugoio#7656
bep added a commit to bep/hugo that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

This commit also adds adds `workDir/node_modules` to NODE_PATH if it exists and `HUGO_WORKDIR` to the env when running the JS tools above.

Fixes gohugoio#7644
Fixes gohugoio#7656
Fixes gohugoio#7675
bep added a commit to bep/hugo that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above.

Fixes gohugoio#7644
Fixes gohugoio#7656
Fixes gohugoio#7675
bep added a commit to bep/hugo that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above.

Fixes gohugoio#7644
Fixes gohugoio#7656
Fixes gohugoio#7675
bep added a commit to bep/hugo that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above.

Fixes gohugoio#7644
Fixes gohugoio#7656
Fixes gohugoio#7675
bep added a commit to bep/hugo that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above.

Fixes gohugoio#7644
Fixes gohugoio#7656
Fixes gohugoio#7675
bep added a commit to bep/hugo that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above.

Fixes gohugoio#7644
Fixes gohugoio#7656
Fixes gohugoio#7675
bep added a commit to bep/hugo that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above.

Fixes gohugoio#7644
Fixes gohugoio#7656
Fixes gohugoio#7675
@bep bep closed this as completed in #7664 Sep 13, 2020
bep added a commit that referenced this issue Sep 13, 2020
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:

```
assets/_jsconfig
´``

These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.

But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.

This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above.

Fixes #7644
Fixes #7656
Fixes #7675
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants