Wanted: concrete install from monorepo with file: dependencies


(Garth Kidd) #1

G’day! Given:

  • pkg/a/package.json, and
  • pkg/b/package.json with dependencies: { "a": "file:../a" }

… I’d like to get a global install of b and its production dependencies, including a, with no symlinks.

Unfortunately:

  • npm install --global --prefix=$PREFIX gives me $PREFIX/lib/node_modules/b symlinked to the source directory, and I can’t copy that without ending up with a Docker image full of devDependencies and unrelated source code

  • npm pack to get tarballs, then npm install * in another directory, fails with npm complaining about not being able to follow the symlink to the package:

    Could not install from “a” as it does not contain a package.json file.

  • npm install from a directory with a package.json with dependencies: { "a": "file:a-x.x.x.tgz", "b": "file:b-x.x.x.tgz" } does the same

  • If I make the versions concrete, npm install * with tarballs or npm install with a package.json linking to tar balls errors out if any of the package versions weren’t published

I’m not open to solutions involving npm publish or yarn.


(Daniel Stockman) #2

I played around with bundledDependencies recently in a monorepo with relative file: specifiers (the lerna source), and it definitely did not like node_modules living in an ancestor directory, among other things.

I honestly don’t see how your Docker requirements are possible to achieve without publishing the packages first (lerna replaces the file: specifiers with the target semver range before packing) and then installing them at the root of the Docker image target thingy (don’t use Docker, sorry I don’t know the lingo).