node.jsnpmnpm-installpackage.jsonnpm-link

How to execute 'npm link' directly on install


I have an internal project where I want to link a command to a file with bin. Like expect this package.json:

{
  "name": "my-project",
  "bin": {
    "cli-name": "./bin/my-executable.js"
  },
  "dependencies": {
    "node-red": "^1.0.0"
  }
}

When executing npm install, all dependencies will be installed, and the bin configuration of node-red will be created too.

But my own bin will be completely ignored. It's not possible to use cli-name in cmd. It's necessary to execute npm link too, in a second step. Then cli-name will be available as command in console. I've even tried to use a postinstall script of npm with npm link in it, but then I got a loop ...

Is there a way to do this in one step on npm install?


Solution

  • There seems actually no build-in way to execute this tasks togeter automatically. So I've created an request for this feature directly to npm. It seems that a new command like npm il could be implemented.

    I will updates this here when this or another way is available.

    https://github.com/npm/npm/issues/15999