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

require-semver

v0.1.0

Published

Alternative node_modules layout supporting version slotting.

Downloads

4

Readme

An alternative way of organizing node_modules and searching for dependencies which respects a package’s version requests with support for slotting.

The Problem

You want to use different software packages which require different major API versions of npm packages and share the library storage. Reasons you might want to share library storage:

  1. So that all packages using a particular npm package can benefit from bugfixes including security patches.

  2. To save disk space without needing to use FS-level file deduplication.

The current node_modules directory structure does not support this at all. It has a weird recursion where each module in node_modules can contain yet other node_modules, enabling further duplication. Also, if you need to use two different packages which demand different major API versions of the same package, these different major API version packages cannot exist in the same node_modules repository because modules are stored directly by name.

Possible Solution

Instead of storing packages like node_modules/«moduleId», store them like node_modules/«moduleId»/«version». This enables the list of available versions to be collected by listing the node_modules/«moduleId» directory, logic to choose a version compatible with the package calling require, and then actual loading.

There are two steps to using require-semver.

  1. Ensure your node_modules contains require-semver:

     $ npm install require-semver

    This is necessary because the changed repository format’s shims rely on require_semver.

  2. Fix your node_modules directory to use the changed repository format and place shims. This package provides the tool require-semver-fixdir to do that for you. Simply run it in the directory containing node_modules.

     user@hostname ~/my-app $ require-semver-fixdir

    The altered repository will store original packages at node_modules/«moduleId»/«version». It will also insert a stub package at node_modules/«moduleId» which delegates to require-semver (which you installed in the first step) which resolves and require()s the real module.

Expected Incompatibilities

A lot of npm packages in the wild treat the node_modules structure as if it were part of node’s public API. In fact, require-semver-fixder assumes a particular implementation when rearranging things, though hopefully this is just a temporary hack and a real solution will be provided by npm itself in the future. But there are packages such as grunt which make broken assumptions which cannot be made compatible with a changed directory structure, another discussion.