πŸ”— A better npm link

Overview

npx link

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

Why should I use this over npm link?

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

Why does npx link point to ln?

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

Related

Comments
  • "Failed to symlink" a scoped package's bin executable

    I am pleased with this package thus far. It has solved npm link linked package dependency problems for me.

    But I think this package does not successfully link bin executables for scoped package. If I am incorrect, I welcome any direction to solve my problem.

    Short Version

    I truncate my actual directory structure as /Users/.../repos/.

    A. ⚠️ When I run npx link to install a directory with a scoped packages, a symlink can not be created for any bin executable.

    {
      "name": "@tacc/core-styles",
      "bin": "src/cli.js",
      // ...
    }
    
    > pwd
    /Users/.../repos/core-cms
    > npx link ../core-styles
    βœ– Failed to symlink /Users/.../repos/core-styles with error: ENOENT: no such file or directory, symlink '/Users/.../repos/core-styles/src/cli.js' -> 'node_modules/.bin/@tacc/core-styles'
    

    B. βœ… When I run npx link to install a directory with a not-scoped package, a symlink is created for any bin executable.

    {
      "name": "core-styles",
      "bin": "src/cli.js",
      // ...
    }
    
    > pwd
    /Users/.../repos/core-cms
    > npx link ../core-styles
    βœ” Symlinked core-styles: /Users/.../repos/core-cms/node_modules/core-styles β†’ ../../core-styles
    

    Long Version

    I truncate my actual directory structure as /Users/.../repos/.

    A. ⚠️ Scoped Package (click to toggle details)
    1. Given a package with a scope @tacc/core-styles:
    {
      "name": "@tacc/core-styles",
      "version": "0.7.0",
      // ...
      "main": "src/main.js",
      "bin": "src/cli.js",
      // ...
    }
    
    1. I link the core-styles package into core-cms.
    > pwd
    /Users/.../repos/core-cms
    > npx link ../core-styles
    βœ– Failed to symlink /Users/.../repos/core-styles with error: ENOENT: no such file or directory, symlink '/Users/.../repos/core-styles/src/cli.js' -> 'node_modules/.bin/@tacc/core-styles'
    
    1. The scoped directory for the bin executable (as link package expects) in core-cms does not exist.
    > pwd
    /Users/.../repos/core-cms
    > ls -la node_modules/.bin/@tacc
    ls: node_modules/.bin/@tacc: No such file or directory
    
    1. I think NPM does not install there by design (old info). Indeed, NPM (v8.12.1) puts the bin executable for a scoped package @frctl/fractal (dependency of core-cms) directly in .bin:
    > pwd
    /Users/.../repos/core-cms
    > ls -la node_modules/.bin/fractal
    lrwxr-xr-x  1 ...  staff  32 Jul 18 11:22 node_modules/.bin/fractal -> ../@frctl/fractal/bin/fractal.js
    
    1. The bin executable (as NPM creates for scoped packages) in core-cms does not exist.
    > pwd
    /Users/.../repos/core-cms
    > ls -la node_modules/.bin/core-styles
    ls: node_modules/.bin/core-styles: No such file or directory
    
    B. βœ… Not-Scoped Package (click to toggle details)
    1. Given a package with no scope, core-styles:
    {
      "name": "core-styles",
      "version": "0.7.0",
      // ...
      "main": "src/main.js",
      "bin": "src/cli.js",
      // ...
    }
    
    1. I link the core-styles package into core-cms.
    > pwd
    /Users/.../repos/core-cms
    > npx link ../core-styles
    βœ” Symlinked core-styles: /Users/.../repos/core-cms/node_modules/core-styles β†’ ../../core-styles
    
    1. The bin executable (as NPM creates for scoped packages) in core-cms does exist.
    > pwd
    /Users/.../repos/core-cms
    > ls -la node_modules/.bin/core-styles
    lrwxr-xr-x  1 ...  staff  78 Jul 18 12:30 node_modules/.bin/core-styles -> /Users/.../repos/core-styles/src/cli.js
    
    opened by wesleyboar 3
  • blog post linked in the README is 404

    blog post linked in the README is 404

    404 url: https://hirok.io/posts/avoid-npm-link

    wayback machine: https://web.archive.org/web/20220422234748/https://hirok.io/posts/avoid-npm-link

    Suggestion: put the blog post as a Markdown file in this repo and link to it in the README, OR include the whole blog post in the README

    opened by shazron 2
  • feat: support JS config file

    feat: support JS config file

    the config file loader will hunt for a js file is a json file is missing.

    Nothing changed for the dynamic creation of the json file... i supposed they could technically be augmented but no point here.

    added a unit test for load-config

    released 
    opened by gillyspy 2
  • Feature request: .env support or `.js` config

    Feature request: .env support or `.js` config

    I would like to check in the config file to source control and use a .env file to supply the private portions.

    Alternatively I would like the config option to support .js file (so that I can export a value that was generated dynamically).

    p.s. thanks for creating this!

    enhancement 
    opened by gillyspy 2
  • feat: publish emulation mode

    feat: publish emulation mode

    Feature

    Specifically, to only link publish files and dependencies from the dependencies object. This would likely result in a watcher.

    Motivation

    Only publish files

    In a development environment, it's possible files that are not published are present and accessible, leading to an inconsistent/inaccurate package.

    Removes dev dependencies

    When linking a development package, the linked package's node_modules directory usually contains devDependencies.

    If the package's dev dependency is also a peer dependency, it's usually provided by the consuming app. However, when linked, Node will resolve the closest dependency, which is unexpected.

    opened by privatenumber 0
Releases(v1.5.1)
Owner
hiroki osame
I'm on a mission to open source my solutions πŸš€
hiroki osame
A file sharing service, where you can upload files and provide a download link for anyone on the internet by sharing the link πŸ”— or via mail βœ‰οΈ which remains active for 24hours πŸ•™.

eShare | File Sharing App A file sharing service, where you can upload files and provide a download link for anyone on the internet by sharing the lin

Akhil Bhalerao 7 Nov 20, 2022
Welcome contributersβ€οΈπŸŽ‰. Just add your name, Github profile link and Linkedin linkπŸ”— Look at Readme for more.πŸ“–

Hello Welcome Developers! Step - 1 Create a GitHub account, if you don't already have one. Step - 2 Register for Hacktoberfest: Navigate to the Hackto

Prineth Fernando 28 Oct 31, 2022
Generate link preview using our app, API or our NPM package.

get-link-preview ?? View the link preview using our App. Use the API to generate link preview in your app or use the NPM package to use the custom hoo

Siddhi Gate 25 Dec 21, 2022
➀_ A better way to organize your npm scripts

➀_ Better Scripts A better way to organize your npm scripts See better-scripts.vercel.app β†’ Installation Usage Basic setup Add script description Scri

Yoki 49 Dec 29, 2022
This tool fetches my BrewFather inventory and publishes it at the link below.

?? BrewFather Inventory ?? How to get your own BrewFather public inventory list Fork this repo Setup GitHub Pages Navigate to Settings > Pages Select

Joost Slijkoort 4 Feb 24, 2022
A web panel to manage TP-Link/Kasa smart home devices.

TP-Link Web Panel A web panel to manage TP-Link/Kasa smart home devices. Prerequisites Node.js v16.13.1 or higher Yarn Installation Run git clone http

Milan M 3 Apr 1, 2022
Hexo-backlink - This plugin is for transfer Obsidian-type backlink to standard hexo in-site post link.

Hexo-Backlink A plugin to convert backlink in .md file to in-site link. Install npm install hexo-backlink configuration Add backlink:true in _config.y

null 8 Sep 27, 2022
Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Ellis 2 Feb 16, 2021
A plugin for Strapi Headless CMS that provides ability to sign-in/sign-up to an application by link had sent to email.

Strapi PasswordLess Plugin A plugin for Strapi Headless CMS that provides ability to sign-in/sign-up to an application by link had sent to email. A pl

Andrey Kucherenko 51 Dec 12, 2022
Automatic arxiv->ar5iv link replacement in Chrome.

Automatic arxiv->ar5iv link replacement in Chrome. This chrome extension will automatically replace arxiv.org/pdf/* links with ar5iv links for more we

yobi byte 44 Oct 29, 2022
(πŸ”—, 🌲) Web3 Link Tree is a free & open-source alternative to Linktree built with React.js, Next.js, Tailwind and Web3-React

Getting Started Read the detailed guide here Customize Add your name, wallet address, social media links and more in config.ts Images Save images to t

Naut 35 Sep 20, 2022
Link your documentation to the relevant code files

Link your documentation to the relevant code files

Mintlify 13 Jul 19, 2022
Chain Link External Inititator Template

Chain Link External Inititator Template AWS Lambda Ready Pre-Deployment 1) Install the Serverless Framework globally npm install serverless -g 2) In

0xD1x0n 4 May 6, 2022
Obsidian.md plugin that allows you to link multiple bible verses easily

Obsidian Bible Linker Plugin for easier linking of multiple bible verses in Obsdian.md note taking app. Usage Use command "Add biblical link" or click

null 31 Dec 27, 2022
A simple firefox/chrome extension adds Sci-Hub direct link access on publishing websites

Sci-Hub injector extension Supported sites PubMed Nature Science Direct Taylor & Francis Springer Link (article, book, chapter, protocol, reference wo

Dany 15 May 7, 2022
GitHub starter project link: https://github.com/buildspace/waveportal-starter-project

Running React on Repl.it React is a popular JavaScript library for building user interfaces. Vite is a blazing fast frontend build tool that includes

MD Rafi Uddin 0 Jun 5, 2022
MagπŸ”₯Lit - A super fast and easy-to-use free and open source private encrypted Magnet/HTTP(s) Link Shortener

Mag ?? Lit Mag ?? Lit - A super fast and easy-to-use free and open source private encrypted Magnet/HTTP(s) Link Shortener https://maglit.ml Features βœ…

null 280 Jan 8, 2023
A tool for collecting data and access camera, microphone and location and clipboard via link.

Snow Build malicious links. A tool for collecting data and access camera, microphone and location and clipboard via link.

Msf 14 Dec 12, 2022
⚑ Self-hostable branded link shortener built with Next.js & Notion API

Notiolink ⚑ Self-hostable branded link shortener built with Next.js & Notion API Made by Theodorus Clarence Installation Guide Please read the full gu

Theodorus Clarence 144 Dec 27, 2022