Open stephtr opened 4 years ago
Hmm, can you whip up a demo that we could use to debug?
I have created a quick repro: hashfordep-yarn-pnp.zip (probably needs Yarn 1.22+).
It basically consists of a default yarn PNP setup and the following test file (which can be run via yarn test
):
const hashForDep = require('hash-for-dep');
hashForDep('hash-for-dep'); // resolves to .yarn\cache\hash-for-dep-npm-1.5.1-cd643a5817-e1c64acc43.zip\node_modules\hash-for-dep\...
According to a quick debug the issue is that for hashForDep
the dir
parameter is optional, but for resolve-package-path
or at least for running pnp.resolveToUnqualified
it is required.
Hmm. OK, I wonder if there is a reasonable default value for dir
that we can use 🤔
Either process.cwd()
(even though there are a few scenarios where this wouldn't work, for example yarn workspaces) or using __dirname
and traversing up until one reaches the .yarn
or node_modules
parent folder, which also doesn't feel great 🤔.
I'm currently using this package via Broccoli. However it fails in my case by calling
hashForDep('.yarn\cache\broccoli-babel-transpiler-npm-7.6.0-0caf4090d4-715d71cfe7.zip\node_modules\broccoli-babel-transpiler')
:(It fails at
pnp.resolveToUnqualified(target + '/package.json', basedir)
). Is this command supposed to work for this argument, is this a bug of Yarn, this package or the broccoli plugin?