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

Improve support for node library/application package management #3817

Closed
gioragutt opened this issue Sep 27, 2020 · 5 comments
Closed

Improve support for node library/application package management #3817

gioragutt opened this issue Sep 27, 2020 · 5 comments
Labels
outdated scope: node Issues related to Node, Express, NestJS support for Nx stale type: feature

Comments

@gioragutt
Copy link
Contributor

Description

Also described in this reddit comment.

Recently I migrated some of my company's code to an NX repo. It consists of:

  • several front-end angular projects, more to be migrated in the future.
  • a production node microservice, and several other node-based projects.

Bundling and dockerizing a front-end application is a piece of cake - bundle and you're done.
On the other hand, bundling and dockerizing a node app is a pain.

Since an NX repo only has a single package.json, you need a different mechanism for bundling your dependencies, an example for such is described in this issue, and in issues linked to it.

In the reddit post, I described a problem I had which made me do an even uglier workaround, to do get a node_modules directory in my code, since a library I used (jaeger-client) relied to reading an asset from there.

What I ended up doing was save a list of all dependencies that are specific to node libraries and apps (which is still more than you need, but much less than you would get otherwise) and generate a package.json using this list.

Motivation

I think that there should be a more standard way to bundle/build node applications, such that supports node_modules cleanly. Running the applications locally could work the same as it does now, but another option to bundle it with a proper node_modules should be available.

Suggested Implementation

One thing I thought of would be to generate a package.json as part of the bundling.
In order to generate the package.json, you'd have each node library and application specify its distinct dependencies in a configuration file. It would be just the names of the dependencies, since the versions are specified in the repo-level package.json.

In the build process, since dependencies are known, you could collect all the dependencies from all libraries used, and the built application, and combine it into a package.json.

This package.json is then easily used by a Dockerfile that would copy the package.json, then npm install (or npm ci if we can generate a lock file as well), and then copy the dist files themselves.

Alternate Implementations

I can't think of any non-hacky solutions, but it would revolve around libraries specifying their dependencies, and later a more compact node_modules is created.

If you could take the actual node_modules of the repo, copy it, and curate it to contain only the needed dependencies.

I don't know how the curation process would work, but I also don't know if this would work well with docker layer caching 🤷🏻‍♂️

@gioragutt gioragutt changed the title Improve support for node library package management Improve support for node library/application package management Sep 27, 2020
@FrozenPandaz FrozenPandaz added the scope: node Issues related to Node, Express, NestJS support for Nx label Oct 2, 2020
@reajuria
Copy link

reajuria commented Nov 28, 2020

Please refer to This link

@gioragutt
Copy link
Contributor Author

Hey @reajuria, thanks for the tip!

I'm currently not able to test this, so I'm gonna ask instead. When I use this method, do I have to populate the package.json dependencies array(s) myself, or does nx handle this?

Because if it doesn't, it'd mean that I'd still have to manage package.json dependencies separately for this app.
Also, how would mono-repo level dependencies work?

@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Mar 29, 2021
@github-actions github-actions bot removed the stale label Apr 8, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: node Issues related to Node, Express, NestJS support for Nx stale type: feature
Projects
None yet
Development

No branches or pull requests

3 participants