Fix the detection of invalid version

Modify the condition checking whether a dependency version satisfies the range required in package.json, so that 'latest' is always considered as valid.

Fixes npm/npm#3860.