cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm link doesn't create an entry in

Open BartlomiejLewandowski opened this issue 4 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

I'm trying to configure a simple CLI tool using oclif. The generated code comes with the following package json contents

 "bin": {
    "quizily": "./bin/run"
  },
"main": "dist/index.js",
  "files": [
    "/bin",
    "/dist",
    "/oclif.manifest.json"
  ],  "scripts": {
    "build": "shx rm -rf dist && tsc -b",
    "lint": "eslint . --ext .ts",
    "postpack": "shx rm -f oclif.manifest.json",
    "posttest": "npm run lint",
    "prepack": "oclif manifest && oclif readme",
    "test": "mocha --forbid-only \"test/**/*.test.ts\"",
    "version": "oclif readme && git add README.md"
  },
  "engines": {
    "node": ">=18.0.0"
  },

I've read somewhere that I can use npm link to have the resulting bin command available on my machine. It didn't work at first so I started debugging.

Running npm link with --verbose didn't show any additional information.

npm link --verbose
npm verbose cli /Users/blewandowski/.nvm/versions/node/v22.9.0/bin/node /Users/blewandowski/.nvm/versions/node/v22.9.0/bin/npm
npm info using [email protected]
npm info using [email protected]
npm verbose title npm link
npm verbose argv "link" "--loglevel" "verbose"
npm verbose logfile logs-max:10 dir:/Users/blewandowski/.npm/_logs/2024-10-20T12_08_50_697Z-
npm verbose logfile /Users/blewandowski/.npm/_logs/2024-10-20T12_08_50_697Z-debug-0.log
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 361ms

changed 1 package, and audited 3 packages in 1s

found 0 vulnerabilities
npm verbose cwd /Users/blewandowski/repositories/quizzy/quizily-cli
npm verbose os Darwin 23.2.0
npm verbose node v22.9.0
npm verbose npm  v10.9.0
npm verbose exit 0
npm info ok

After running the command I check the directories that should have changed

/Users/blewandowski/.nvm/versions/node/v22.9.0
 npm --version     
10.9.0
ls /Users/blewandowski/.nvm/versions/node/v22.9.0/bin
corepack node     npm      npx
ls /Users/blewandowski/.nvm/versions/node/v22.9.0/lib/node_modules 
corepack    npm         quizily-cli

As you can see the package was correctly symlinked, but the bin wasn't.

Expected Behavior

From the help of npm link

First, npm link in a package folder with no arguments will create a symlink in the global folder {prefix}/lib/node_modules/<package> that links to the package where
       the npm link command was executed. It will also link any bins in the package to {prefix}/bin/{name}. Note that npm link uses the global prefix (see npm prefix -g for
       its value).

I was expecting the {prefix}/bin to contain a symlink to the bin command that is defined in package.json

Steps To Reproduce

Not tested in isolation

  1. Create a new package json with bin set to some file in dist.
  2. Run npm link
  3. Verify bin directory in npm prefix -g doesn't contain the bin command defined in package.json

Environment

  • npm: 10.9.0
  • Node.js: v22.9.0
  • OS Name: Mac OS 14.2.1 (23C71)
  • System Model Name:
  • npm config:
; node bin location = /Users/blewandowski/.nvm/versions/node/v22.9.0/bin/node
; node version = v22.9.0
; npm local prefix = /Users/blewandowski/repositories/quizzy/quizily-cli
; npm version = 10.9.0
; cwd = /Users/blewandowski/repositories/quizzy/quizily-cli
; HOME = /Users/blewandowski

BartlomiejLewandowski avatar Oct 20 '24 12:10 BartlomiejLewandowski