Local module regression was introduced sometime around 5.0

What I Wanted to Do

I would like to install a local module as though it was one off the internet, in an attempt to emulate what the postinstall script would do. I expected it to act exactly the same, copying the files into node_modules, running any scripts.

What Happened Instead

It created a symlink, and ran the postinstall script from the wrong location.

Reproduction Steps

  1. Create any local module
    mkdir ~/tmp/foo && cd ~/tmp/foo && npm init
  2. Create a second module
    mkdir ~/tmp/bar && cd ~/tmp/bar && npm init
  3. Install the first module in the second
    cd ~/tmp/bar && npm i "../foo"
  4. Navigate into bar/node_modules and observe that foo is a symlink

Details

I recognize that for many situations symlinks work just fine, and are perhaps even more useful. But given that creating a symlink is completely unexpected behavior, and it breaks use cases dependent on what an average user would assume the function does, I would categorize this as a regression. Unless there’s some flag I’m missing to enable/disable this feature, it may have added something, but it also removed something.

Platform Info

$ npm --versions
{ bolierplate: '1.0.0',
  npm: '6.7.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  llhttp: '1.1.1',
  modules: '67',
  napi: '4',
  nghttp2: '1.34.0',
  node: '11.12.0',
  openssl: '1.1.1b',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.26.0',
  v8: '7.0.276.38-node.18',
  zlib: '1.2.11' }

$ node -p process.platform
darwin

Noting it is the documented behaviour:

npm install <folder>
Install the package in the directory as a symlink in the current project. Its dependencies will be installed before it’s linked.

https://docs.npmjs.com/cli/install