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

install-from

v3.0.0

Published

Reliably installs a local package into another, for testing.

Downloads

15

Readme

install-from

npm version CI status

Reliably installs a local package into another, for testing.

It’s very similar to installing a published package; npm pack is used to generate a tarball that only includes published files, which are extracted into node_modules for a similar result to a regular npm install --no-save.

npm link is a notoriously unreliable way to locally test a package in another package, as it uses symlinks:

  • It will not reveal if the package.json files field or .npmignore is correct, as npm link doesn’t use npm pack like npm publish does.
  • As the package being tested is not actually installed inside the node_modules of the package it’s being tested in, peer dependencies installed in the host package can’t be reached. For example, this makes it difficult to test a package that has a react peer dependency inside a Next.js project.
  • How it works is not intuitive. It messes with the global node_modules and bin directories, and you have to remember to use npm unlink to tidy up, which inconveniently strips the dependency from your package.json.

Setup

Installation isn’t required to use the CLI command install-from with npx.

To install with npm, run:

npm install install-from --save-dev

Then, use either the CLI command install-from or the JS API function installFrom.

CLI

Command install-from

Reliably installs a local package into another at the CWD, for testing.

Arguments

| Argument | Description | | :-- | :-- | | 1 | Absolute or CWD relative filesystem path to the package to install from. |

Examples

Installing a local package into another using npx.

In a terminal, change to the directory of the package you want to test another package in:

cd ~/Repos/foo

Then, install the desired local package:

npx install-from ~/Repos/bar

API

function installFrom

Reliably installs a local package into another, for testing.

| Parameter | Type | Description | | :-- | :-- | :-- | | pathPackageFrom | string | Absolute or CWD relative filesystem path to the package to install from. | | pathPackageTo | string? | Absolute or CWD relative filesystem path to the package to install to, defaulting to process.cwd(). |

Returns: Promise<void> — Resolves once installation is complete.

Examples

How to import.

import installFrom from 'install-from';

Installing a local package into another.

installFrom(
  './packages/package-to-install-from',
  './packages/package-to-install-to'
)
  .then(() => {
    // …
  })
  .catch(() => {
    // …
  });