Socket
Socket
Sign inDemoInstall

link

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

link

A better npm link


Version published
Weekly downloads
11K
increased by13.97%
Maintainers
1
Weekly downloads
 
Created
Source

A safer version of npm link.

Why is npm link unsafe? Read the blog post.

Features

  • 🔗 Link dependencies without removing previous links
  • 🛡 Only resolves to local paths
  • 🔥 Config file quickly linking multiple packages
  • 💫 Deep linking for quickling linking multilple packages

Usage

npx link simply symlinks the target package as a dependency in the current project.

Unlike npm link, it doesn't install the target package globally or re-install project dependencies.

From the project you want to link a package to:

npx link <package-path>

Configuration file

Create a link.config.json configuration file at the root of your npm project to automatically setup links to multiple packages.

Example link.config.json:

{
    "packages": [
        "/path/to/package-path-a",
        "../package-path-b"
    ]
}

The configuration has the following type schema:

type LinkConfig = {

    // Whether to run link on linked packages with link.config.json
    deepLink?: boolean

    // List of packages to link
    packages?: string[]
}

Note: It's not recommended to commit this file to source control since this is for local development with local paths.

To link the dependencies defined in link.config.json, run:

npx link

Deep linking

By default, npx link only links packages in the current project. However, there are cases where the linked packages also needs linking setup.

Deep linking recursively runs link on every linked package that has a link.config.json file.

Enable with the --deep flag or deepLink property in link.config.json.

npx link --deep

FAQ

Because npm link has footguns that make it dangerous to use.

You must use npx v7 or higher. Check the version with npx -v.

In the obsolete npx v6, local binaries take precedence over npm modules so npx link can point to the native link/ln command:

$ npx link
usage: ln [-s [-F] | -L | -P] [-f | -i] [-hnv] source_file [target_file]
       ln [-s [-F] | -L | -P] [-f | -i] [-hnv] source_file ... target_dir
       link source_file target_file

To work around this, install link globally first:

$ npm i -g link
$ npx link

Keywords

FAQs

Package last updated on 05 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc