A snap that can install dependencies—where to put them?

So we have the node snap up and running (only --edge or --channel 6|8|9) but I’ve run into a dilemma.

npm install --global ... is supposed to let you pull a package from the npm registry and install it globally on your computer. It’s not great practice and people are encouraged to avoid global where possible but is in common enough use for command line utilities (as executables) that you may want to have available globally. There’s also npm link which will link a local package that you may be developing to the global space where its executables can be used globally but you can also link it from that global space back down into another package that requires it as a dependency. Just a common pattern that Node developers use.

This global space is generally in $prefix/lib/node_modules with executables symlinked in $prefix/bin. So if you have node installed in /usr/local/bin/node then that’s where your global utils will go. Likewise if you have it going into /usr/bin/node as it is from most Linux distros (and our very heavily used repos https://github.com/nodesource/distributions) then you’re using /usr/lib/node_modules/ and symlinking executables into /usr/bin/.

Now, with a Node snap it’s a different matter because your $prefix is something like /snap/node/152/ and is not writable so an npm install --global ... will fail. I can change that with a global config option, but I need to decide on what it should be.

On developer machines, particularly macOS, a common practice (amongst Node developers at least) is to chown me -R /usr/local so you don’t need to sudo and everything is done in there and you’re likely the only user anyway. The Node snap is likely to fall into the developer-machine category too, we’re probably not going to recommend it for production deployments for various reasons.

I’m inclined to set $prefix to be /usr/local for the Node snap. Do we have much prior art on this kind of thing? Is there some kind of parallel to /snap for persistent components that a snap might create?