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

exact-deps

v1.2.1

Published

Update all dependency versions in package.json to be exact version currently installed.

Downloads

4

Readme

exact-deps

Update package.json to use exact versions for dependencies

NOTE: this does not replace the best practice of adding a .npmrc file with save-exact=true attribute to a project

yarn add -D exact-deps

Getting started

For a variety of reasons, I have often wanted to convert all the versions of dependencies in a package.json file to the exact versions that have been installed.

exact-deps solves this problem by

  • looping through each dependency in the main package.json file
  • for each dependency:
    • finding the locally installed dependency's package.json file
    • updating the entry in the main package.json with the version attribute from the dependency's package.json file

Requirements

  • node: >=8

Command Line

This module provides a simple CLI:

./node_modules/.bin/exact-deps

If combined with Yarn, it can be run as:

yarn exact-deps package.json

It can also be used as part of an npm script:

{
  "scripts": {
    "deps:exact": "exact-deps"
  },
  "devDependencies": {
    "exact-deps": "latest"
  }
}
yarn deps:exact

Options

| Option | Alias | Description | Default | | -----------| --------- | -------------- | ----------- | | prefix | p | Prefix to put before each version | '' | | help | h | Print help menu | |

Module

The module exports a function that takes the directory of package.json and a prefix.

It returns a new object with path and contents properties

const fs = require('fs');
const exactDeps = require('exact-deps');

const { path, contents } = exactDeps(process.cwd(), '^');
fs.writeFileSync(path, JSON.stringify(contents, null, 2));

Integrating

An effective integration of this plugin could look like this:

{
  "scripts": {
    "deps:exact": "exact-deps",
    "precommit": "lint-staged",
    "prepublish": "deps:exact"
  },
  "lint-staged": {
    "package.json": [
      "exact-deps -p ^",
      "git add"
    ]
  },
  "devDependencies": {
    "lint-staged": "latest",
    "exact-deps": "latest"
  },
  "optionalDependencies": {
    "husky": "latest"
  }
}

This configuration combines:

  • lint-staged for automatically running tasks on staged files
  • husky for githook integrations
  • exact-deps to make sure package.json is always exact

Together, these modules ensure the package.json file is automatically updated if it changes and provides an easy package.json script for manual use:

yarn deps:exact