2

Situation

I'm working on a project "main" and in order to split the code and make parts of it reusable, I created 2 npm projects/packages: "A" and "B". "main" requires "A" and "B", "B" requires "A"

main
 +-- A
 `-- B
     `-- A

While developing in project main, A and B might require some improvements, But in order to have changes inside A and B take effect inside main I would need to publish a new version of them for every little change

npm link, yalc, workspaces

The common approach is npm link or npm workspaces but it has a few downsides, symlinks tend to behave differently depending on the environment and setup, also the symlinks tend to get messed up by running other npm commands, there are also some issues with webpack etc. etc.

yalc attempts to solve this by copying files around and putting file: / link: dependencies into the package.json

All of these "local" approaches have a few problems:

  • If I push the code of "main" to git, I can't run CI/CD pipelines that rely on the newest A/B being present because in the pipeline, those packages are not symlinked or the file: / link: dependencies point to folders that do not exist
  • When working in a small team, the improvements only exist on my machine, even if I push them into the repositories of A and B, others in my team would need to constantly need to update their repositories
  • others in my team would need the same folder/link structure on their machines like me

git repositories

I added A and B as git dependencies inside main:

main/package.json

"devDependencies": {
  "A": "git+https://<link of my git repo>/A.git",
  "B": "git+https://<link of my git repo>/B.git",


B/package.json

"devDependencies": {
  "A": "git+https://<link of my git repo>/A.git"

Thats great because I can simply push a change in A or B and everybody can receive the newest version of A and B via npm update

The problem here is, that npm sadly but justifiably does not recursively resolve git dependencies, A and B inside main get resolved but A inside B does not get resolved, this means that when running webpack for example, "A" does not exist inside "B"

what now?

There has to be a better solution than this. But using real packages, even if its a private repository like verdaccio, means every little change requires me to create and publish a new version of the package, spamming the repository with package versions.

CodingKiwi
  • 676
  • 8
  • 22

0 Answers0