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

@flossbank/registry-resolver

v2.2.2

Published

Resolve list of packages into weighted map of dependencies

Downloads

3

Readme

registry-resolver

A packages resolver library intended to assign weights to all the packages in the dependency tree of a given package or packages.

The algorithm currently in use is:

  1. Begin with weight 1
  2. Divide weight between input packages (top level packages)
  3. For each package, query registry for immediate dependencies
  4. Split the package's weight with its immediate dependencies.
  5. Repeat from step 2 until there are no more dependencies or remaining weight is less than the configured epsilon

Usage

const RegistryResolver = require('@flossbank/registry-resolver')

const resolver = new RegistryResolver({
  log: logger, // defaults to console
  epsilon: 0.01 // the smallest weight that will be assigned to a package before exiting
})

const packageWeightMap = await resolver.computePackageWeight({
  language: 'javascript',
  registry: 'npm',
  topLevelPackages: ['standard', 'react', 'webpack'],
  noCompList: new Set(['react'])
})

/* example output
{
  packageWeightMap: Map {
    'standard' => 0.037037037037037035,
    'webpack' => 0.013333333333333332,
    '@types/estree' => 0.013333333333333332,
    '@webassemblyjs/ast' => 0.013333333333333332,
    '@types/eslint-scope' => 0.013333333333333332,
    'glob-to-regexp' => 0.013333333333333332,
    '@webassemblyjs/helper-module-context' => 0.013333333333333332,
    'graceful-fs' => 0.013333333333333332,
    'json-parse-better-errors' => 0.013333333333333332,
    'loader-runner' => 0.013333333333333332,
    'mime-types' => 0.013333333333333332,
    'pkg-dir' => 0.013333333333333332,
    'neo-async' => 0.013333333333333332,
    '@webassemblyjs/wasm-edit' => 0.013333333333333332,
    '@webassemblyjs/wasm-parser' => 0.013333333333333332,
    'tapable' => 0.013333333333333332,
    'chrome-trace-event' => 0.013333333333333332,
    'acorn' => 0.013333333333333332,
    'terser-webpack-plugin' => 0.013333333333333332,
    'schema-utils' => 0.013333333333333332,
    'watchpack' => 0.013333333333333332,
    'eslint-scope' => 0.013333333333333332,
    'enhanced-resolve' => 0.013333333333333332,
    'webpack-sources' => 0.013333333333333332,
    'browserslist' => 0.013333333333333332,
    'events' => 0.013333333333333332,
    'loose-envify' => 0.08333333333333333,
    'object-assign' => 0.16666666666666666,
    'js-tokens' => 0.08333333333333333,
    'eslint-config-standard' => 0.037037037037037035,
    'eslint-plugin-node' => 0.037037037037037035,
    'eslint-plugin-react' => 0.037037037037037035,
    'eslint-plugin-promise' => 0.037037037037037035,
    'standard-engine' => 0.037037037037037035,
    'eslint-config-standard-jsx' => 0.037037037037037035,
    'eslint' => 0.037037037037037035,
    'eslint-plugin-import' => 0.037037037037037035
  }
}
*/

API

new RegistryResolver({ log, epsilon })

Constructor. Log defaults to console. Epsilon is the smallest weight allowed for a specific package.

.getSupportedManifestPatterns()

Returns filenames of package manifest files supported by the resolver in the format:

[
  {
    registry: String,
    language: String,
    patterns: []String
  }
]

.extractDependenciesFromManifests(manifests)

Returns top-level dependencies extracted from a list of supported manifest files.

manifests

A list of manifest objects:

[
  {
    registry: String,
    language: String,
    manifest: String
  }
]

.extractDependenciesFromManifest(manifest)

Returns top-level dependencies extracted from a single manifest file.

manifest

{
  registry: String,
  language: String,
  manifest: String
}

.getSupportedRegistry({ language: String, registry: String })

Returns a package registry wrapper used to resolve dependencies, or false if the combination is unsupported. Used internally.

.computePackageWeight({ topLevelPackages, language, registry, noCompList? })

Returns a Promise that resolves to a Map of packageName => packageWeight.

topLevelPackages

A list of packages/specs extracted from package manifest files, e.g. ['standard@^12.0.1', '[email protected]'].

language

String; the language the packages are written in (e.g. javascript). Currently only JavaScript is supported.

registry

String; the registry identifier (e.g. npm). Currently only NPM is supported.

noCompList

Set; a set of packages that should be given 0 weight in the dependency tree.

.resolveToSpec({ packages, language, registry })

Returns a Promise that resolves a list of package specs (e.g. standard@^12.0.1) to a static package identifier (e.g. [email protected]).

packages

List of strings, e.g. ['standard@^12.0.1', '[email protected]'].

language

String; the language the packages are written in (e.g. javascript). Currently only JavaScript is supported.

registry

String; the registry identifier (e.g. npm). Currently only NPM is supported.

License

GPL-3.0