npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

absolutize-links

v0.1.0

Published

A bash script to convert relative node_modules symlinks to absolute ones, so we can use with docker volumes.

Downloads

5

Readme

absolutize-links

A bash script to convert relative node_modules symlinks to absolute ones, so we can use with docker volumes.

This repo was created in tandem with this issue comment: https://github.com/npm/npm/issues/14325#issuecomment-285566020

installation

npm install -g absolutize-links

purpose

When you run npm link, what it's doing under the hood is creating a symlink from . to /usr/local/lib/node_modules. On the other side, when you npm link package-name, it creates a link from node_modules/package-name to /usr/local/lib/node_modules/package-name.

If you were to run docker run --rm -it your-image-name:latest ls -al node_modules | grep -e "->", you'll likely see something like this:

package-name -> ../../../../../../usr/local/lib/node_modules/package-name

It's very unlikely that there's anything at all in your docker container at that path, which is why npm is telling you that file doesn't exist - it's right, it doesn't!

the problem

Unfortunately AFAIK npm doesn't allow you to create non-relative symlinks with npm link, which is problematic in that the directory structure of your docker container is pretty much never going to be the same as the directory structure of your local laptop.

In addition, since nothing is copied from /usr/local to the image, even if your directory structure were to match, the file still wouldn't exist.

a complex workaround, aka how to use this lib

Because npm link makes relative symlinks, and because docker doesn't allow using volumes outside of $HOME by default, I can't think of a solution that doesn't require modifying your local fs and docker settings.

However, here's one way:

  1. Update Docker for Mac settings to include /usr/local/lib/node_modules in the shared folders so you can use it as a volume:

image

  1. Update any local symlinks to be absolute. Link them using npm link package-name, then run this script (absolutize-links)

  2. Add a volume to your docker config:

To run a docker command, add a -v /usr/local/lib/node_modules:/usr/local/lib/node_modules - this will mount your local npm node_modules on your docker container, which will make them available. You'll unfortunately also need to add a -v flag referencing the local linked modules' folder.

If you're using docker-compose, you can add these entries as volumes keys in your docker-compose.yml, so they'll always be there when you restart your container.

There's quite a lot of nuance when it comes to setting up docker volumes, so I'll leave it at the above for now, but the idea here is that you'll need both /usr/local/lib/node_modules and /path/to/the/linked/module defined as volumes when you run your docker image.

usage

absolutize-links [node_modules_dir]

node_modules_dir defaults to node_modules, so if you're in the same directory as package.json, you should be fine running just absolutize-links.