Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Finding plugins breaks when the package manager doesn't use node_modules #170

Closed
TPHRyan opened this issue Aug 30, 2020 · 1 comment · Fixed by #171
Closed

Finding plugins breaks when the package manager doesn't use node_modules #170

TPHRyan opened this issue Aug 30, 2020 · 1 comment · Fixed by #171

Comments

@TPHRyan
Copy link
Contributor

TPHRyan commented Aug 30, 2020

When trying to use oclif with a package manager such as Yarn 2, the following error message occurs:

(node:621147) Error Plugin: @maintainer/package: could not find package.json with {
  type: 'core',
  root: '/path/to/project/root',
  name: '@oclif/plugin-help'
}
module: @oclif/config@1.17.0
task: loadPlugins
plugin: @maintainer/package
root: /path/to/project/root
See more details with DEBUG=*

Digging into the code, it seems pretty obvious that this is because of the fact that this package looks for plugins in node_modules, but Yarn 2 doesn't use node_modules.

config/src/plugin.ts

Lines 109 to 135 in 07a0670

async function findRoot(name: string | undefined, root: string) {
// essentially just "cd .."
function * up(from: string) {
while (path.dirname(from) !== from) {
yield from
from = path.dirname(from)
}
yield from
}
for (const next of up(root)) {
let cur
if (name) {
cur = path.join(next, 'node_modules', name, 'package.json')
// eslint-disable-next-line no-await-in-loop
if (await exists(cur)) return path.dirname(cur)
try {
// eslint-disable-next-line no-await-in-loop
const pkg = await loadJSON(path.join(next, 'package.json'))
if (pkg.name === name) return next
} catch { }
} else {
cur = path.join(next, 'package.json')
// eslint-disable-next-line no-await-in-loop
if (await exists(cur)) return path.dirname(cur)
}
}
}

As per the Yarn 2 documentation, this is somewhat easily solved with a change to utilize resolve@>=1.9. Any pitfalls or caveats existing contributors/maintainers can think of?

Yes, Yarn 2 is in RC stage but it will not be so eventually and this issue will need to be resolved. (Heh.)

I'm most probably going to try to fix this myself so I can obstinately use the new modules system, but tracking issues is important so I'm doing this first.

@adamovittorio
Copy link

Hi, any news on this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants