sindresorhus / global-directory

Get the directory of globally installed packages and binaries
MIT License
75 stars 10 forks source link

Wrong paths with homebrew formula node@12 #17

Open matz3 opened 4 years ago

matz3 commented 4 years ago

Detected via https://github.com/SAP/ui5-cli/issues/374

This breaks the is-installed-globally module, which is used within update-notifier.

It can be reproduced within docker but also on WSL Ubuntu 18.04, so it seems to be a common problem with the node@12 formula.

Global packages are installed into /home/linuxbrew/.linuxbrew/lib/node_modules but npm.packages points to /home/linuxbrew/.linuxbrew/Cellar/node@12/12.18.4/lib/node_modules (where npm is installed).

I'm not sure whether this can/should be solved in this module or within the homebrew formula for node@12.

node@12 ❌

FROM homebrew/brew:2.4.11
USER linuxbrew
RUN brew install node@12
ENV PATH=/home/linuxbrew/.linuxbrew/opt/node@12/bin:$PATH
RUN npm i -g global-dirs
RUN node -e "console.log(require('/home/linuxbrew/.linuxbrew/lib/node_modules/global-dirs'))"
Step 6/6 : RUN node -e "console.log(require('/home/linuxbrew/.linuxbrew/lib/node_modules/global-dirs'))"
 ---> Running in 3041eed7dba6
{
  npm: {
    prefix: '/home/linuxbrew/.linuxbrew/Cellar/node@12/12.18.4',
    packages: '/home/linuxbrew/.linuxbrew/Cellar/node@12/12.18.4/lib/node_modules',
    binaries: '/home/linuxbrew/.linuxbrew/Cellar/node@12/12.18.4/bin'
  },
  yarn: {
    prefix: '/home/linuxbrew/.linuxbrew/Cellar/node@12/12.18.4',
    packages: '/home/linuxbrew/.linuxbrew/Cellar/node@12/12.18.4/global/node_modules',
    binaries: '/home/linuxbrew/.linuxbrew/Cellar/node@12/12.18.4/global/node_modules/.bin'
  }
}

node@14 ✅

FROM homebrew/brew:2.4.11
USER linuxbrew
RUN brew install node@14
RUN npm i -g global-dirs
RUN node -e "console.log(require('/home/linuxbrew/.linuxbrew/lib/node_modules/global-dirs'))"
Step 5/5 : RUN node -e "console.log(require('/home/linuxbrew/.linuxbrew/lib/node_modules/global-dirs'))"
 ---> Running in f93fd0092011
{
  npm: {
    prefix: '/home/linuxbrew/.linuxbrew',
    packages: '/home/linuxbrew/.linuxbrew/lib/node_modules',
    binaries: '/home/linuxbrew/.linuxbrew/bin'
  },
  yarn: {
    prefix: '/home/linuxbrew/.linuxbrew',
    packages: '/home/linuxbrew/.linuxbrew/global/node_modules',
    binaries: '/home/linuxbrew/.linuxbrew/global/node_modules/.bin'
  }
}

node ✅

FROM homebrew/brew:2.4.11
USER linuxbrew
RUN brew install node
RUN npm i -g global-dirs
RUN node -e "console.log(require('/home/linuxbrew/.linuxbrew/lib/node_modules/global-dirs'))"
Step 5/5 : RUN node -e "console.log(require('/home/linuxbrew/.linuxbrew/lib/node_modules/global-dirs'))"
 ---> Running in 40b41954c0c4
{
  npm: {
    prefix: '/home/linuxbrew/.linuxbrew',
    packages: '/home/linuxbrew/.linuxbrew/lib/node_modules',
    binaries: '/home/linuxbrew/.linuxbrew/bin'
  },
  yarn: {
    prefix: '/home/linuxbrew/.linuxbrew',
    packages: '/home/linuxbrew/.linuxbrew/global/node_modules',
    binaries: '/home/linuxbrew/.linuxbrew/global/node_modules/.bin'
  }
}