dominictarr / npmd

MIT License
450 stars 37 forks source link

strange --global behavior #73

Open duralog opened 10 years ago

duralog commented 10 years ago

it gets mixed up with locals and globals for resolution... actually, this could be a npmd-resolve issue now that I think about it, but either way, it can be reproduced like this:

  1. npmd install npmd-config --greedy to install locally
  2. npmd install -g npmd-config --greedy to install globally
  3. give npmd-config a try now on the terminal, and it will tell you that it can't find optimist

right, so if you go to any other directory now and re-run the npmd install -g npmd-config, the --global option will install the missing deps

I don't think the greedy option makes any difference (didn't actually try it ... and come to think of it, why isn't greedy on by default?)

love npmd man :) it's great keep it real

dominictarr commented 10 years ago

I have not been able to reproduce this - are you using the latest version on npmd?

dominictarr commented 10 years ago

can you post output of npmd-config ?

duralog commented 10 years ago

sure

{
  "0": "npmd-config",
  "dbPath": "/Users/duralog/.npmd",
  "debug": false,
  "sync": false,
  "registry": "https://registry.npmjs.org",
  "cache": "/Users/duralog/.npm",
  "user-agent": "node/v0.10.28 darwin x64",
  "prefix": "/usr/local",
  "port": 5656,
  "_": [],
  "global": null,
  "g": null,
  "greedy": null,
  "dedupe": null,
  "online": null,
  "offline": null,
  "save-dev": null,
  "D": null,
  "saveDev": null,
  "save": null,
  "S": null,
  "$0": "npmd-config",
  "bin": "/tmp/npmd-config-bug/node_modules/.bin",
  "userAgent": "node/v0.10.28 darwin x64",
  "": [],
  "d": null,
  "s": null
}

lemme look a bit more into this a second... aha! I found the bug. you can reproduce perfectly like this:

mkdir -p /tmp/npmd-bug
cd /tmp/npmd-bug
cat  > package.json << EOL
{
    "name": "npmd-test",
    "dependencies": {
        "optimist": "x"
    }
}
EOL
npmd install
npmd install npmd-config --greedy --global

now try it :)

notes:

  1. if you rm -rf node_modules/optimist (even though it's in package.json dependencies) it will now install properly.
  2. the greedy tag is indeed the culprit. appears that it makes npmd greedy locally as well globally (insert multinational corporation joke here)
dominictarr commented 10 years ago

aha, so it's probably rchecking for already available modules in the ./node_modules etc, but it should look for that starting from where it will be installed (or just skip that step for global modules)