1

I am working on creating an NPM link utility.

I have a package which depends on about 7 or 8 locally developed packages as well. I link them together using NPM link. This is currently manually and has become tedious, would like to automate it with a utility. I believe the best thing to do is to start linking the packages with no dependencies, and then work my way up to the packages with the most dependencies.

It looks something like this:

     A (my main NPM project)

       /     \       \
      /       \       \
     B         C       H __
    / \              /  \  \
   /   \            /    \  \
  D     E          I     J   K
         \       /
          \     /
           \   / 
             F 

Assumption - I should start from the bottoms of the tree and work my way upwards.

What data structures/algorithm can I use to easily implement this?

With the above tree in mind, the effective code would look like:

# start with F and work upwards
cd F && npm link .
cd E && npm link F && npm link .
cd D && npm link .
cd B && npm link D && npm link E && npm link .
# etc etc

So I think the algorithm should be something like:

  1. Create a unique list L of locally developed projects (versus remote only).
  2. Starting with main project, drill down into the tree (using package.json to find declared dependencies) until you find the set of dependencies that are in the list L but which have no other dependencies in the List L.

After that I am not sure.

halfer
  • 19,824
  • 17
  • 99
  • 186
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

2 Answers2

1

Try http://aka.ms/rush -- it is an industrial strength solution to your problem.

pgonzal
  • 11
  • 1
0

I asked NPM, and someone said there might not be such a utility in existence yet, so I started working on it:

https://github.com/ORESoftware/npm-link-up

Feel free to give feedback or contribute.

Besides Rush, there is also Lerna, which is used by Babel. But I think "npm-link-up" might be significantly simpler and leaner.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817