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

Fix plugins not being found when no node_modules exists #171

Merged
merged 3 commits into from
Nov 29, 2021

Conversation

TPHRyan
Copy link
Contributor

@TPHRyan TPHRyan commented Aug 30, 2020

Fixes #170.

As I mentioned in the issue, Yarn 2 uses a different package system that does not have node_modules. As such, relying on node_modules should be discouraged.

Yarn suggests using the resolve package, and this is the approach I have taken.

Please let me know if any further changes are required. I tried to conform to idioms of the code, but for testing in particular I wasn't sure what the guidelines were.

This test should pass when it has been updated to use resolve
Assume resolve returns an entry file not a directory
@salesforce-cla
Copy link

Thanks for the contribution! Before we can merge this, we need @TPHRyan to sign the Salesforce.com Contributor License Agreement.

@codecov
Copy link

codecov bot commented Aug 30, 2020

Codecov Report

Merging #171 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #171   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files           2       2           
  Lines          12      12           
  Branches        3       3           
======================================
  Misses         12      12           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 07a0670...7925d35. Read the comment docs.

@tobilen
Copy link

tobilen commented Mar 14, 2021

@jdxcode anything missing here? this issue is preventing apollo tooling from running under yarn 2

@AaronBuxbaum
Copy link

Any movement on this PR? It's been a long while, and this would help quite a few packages that depend on it to move to Yarn 2.

@amphro
Copy link
Contributor

amphro commented Apr 12, 2021

I don't see any problem with this, but I want to try it out. @AaronBuxbaum have you also been able to try this PR to confirm that it works and doesn't break any existing functionality?

I hope you have also seen the announcement about oclif/core. I'm assuming that library will also have that problem? @TPHRyan could we also do a PR there as well?

@AaronBuxbaum
Copy link

I don't see any problem with this, but I want to try it out. @AaronBuxbaum have you also been able to try this PR to confirm that it works and doesn't break any existing functionality?

Yes, I'm using it now and as far as I'm concerned there are no issues at all with this. It's a dependency of a different library, so it's a limited test case, but it looks solid to me.

Copy link
Contributor

@amphro amphro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I link this with https://github.com/salesforcecli/sfdx-cli/ it blows up. Passing in basedir as mentioned in the comments fixes some errors, but it still doesn't resolve everything. I don't have the time right now to try to see why it is still failing. Unless we can see why resolve isn't finding the packages, we may have to add in the old code as a backup if resolve can't find it.

if (name) {
let pkgPath
try {
pkgPath = await resolvePackage(name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to pass in { basedir: root } because it may need to look outside of the current path. i.e. where user plugins are stored.

With that said, the resolve library isn't working how I thought it would. If I add the basedir above, it will still sometimes throw MODULE_NOT_FOUND even though it seems to be in the resolution path.

For example, I modified resolvePackage to take in the same options object that resolve takes and pass that to resolve.

// name = '@salesforce/plugin-evergreen-build'
// root = '/Users/t.dvornik/.local/share/sfdx/node_modules/@salesforce/plugin-evergreen'
...
// The root may not always be a dir, so ensure it is before passing it into resolve
if (path.extname(root)) {
  root = path.dirname(root)
}
try {
  pkgPath = await util_2.resolvePackage(name, { basedir: root });
}
...

That package is in /Users/t.dvornik/.local/share/sfdx/node_modules/@salesforce/plugin-evergreen-build which should be in node module resolution but resolve isn't resolving it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this - this issue flew under the radar for me for a minute, but I'll have a look to see if I can fix it sometime soon. It's not high priority for me but evidently there's a few others others also waiting on a fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we don't just use the native require.resolve over the resolve package? it doesn't appear that we really need it to resolve asynchronously for our use case.

@AaronBuxbaum
Copy link

Any progress on this? @TPHRyan

I'm hoping to use workspaces in my Yarn 2 repo, but that throws errors from @oclif/config even with the existing patch that previously worked:

module: @oclif/[email protected]
task: runHook init
plugin: @percy/cli
root: /Users/aaron/Work/web/.yarn/cache/@percy-cli-npm-1.0.0-beta.59-cc1949c1e6-3ebc2fb960.zip/node_modules/@percy/cli
See more details with DEBUG=*
Error: can't resolve reference /snapshot#/properties/name from id /config/static
    at Object.code (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/vocabularies/core/ref.js:21:19)
    at keywordCode (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/validate/index.js:454:13)
    at /Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/validate/index.js:185:25
    at CodeGen.code (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/codegen/index.js:439:13)
    at CodeGen.block (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/codegen/index.js:568:18)
    at schemaKeywords (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/validate/index.js:185:13)
    at typeAndKeywords (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/validate/index.js:128:5)
    at subSchemaObjCode (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/validate/index.js:115:5)
    at subschemaCode (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/validate/index.js:91:13)
    at KeywordCxt.subschema (/Users/aaron/Work/web/.yarn/cache/ajv-npm-8.6.2-712407c2bc-9969d6c0e6.zip/node_modules/ajv/dist/compile/validate/index.js:428:9)

this is effectively the same setup as previously worked, except with a workspace that now owns the percy and oclif packages, instead of directly on root

@QWp6t
Copy link

QWp6t commented Jul 20, 2021

As a workaround, you can tell Yarn 2 to use node-modules instead of pnp.

.yarnrc.yml

nodeLinker: node-modules

Reference: https://yarnpkg.com/configuration/yarnrc/#nodeLinker

@AaronBuxbaum
Copy link

nodeLinker: node-modules

For me at least, that doesn't do it, though it could be that it's not actually oclif here, I haven't dug into it

(node:17050) Error Plugin: @percy/cli: can't resolve reference /config/snapshot#/properties/widths from id /config/static
module: @oclif/[email protected]
task: runHook init
plugin: @percy/cli
root: /Users/aaron/Work/web/node_modules/@percy/cli
See more details with DEBUG=*
    Error: can't resolve reference /config/snapshot#/properties/widths 
    from id /config/static

It's also not a greaaat solution even if it did work because the node_modules linker defeats a lot of the purpose of Yarn 2

@timini
Copy link

timini commented Sep 3, 2021

can we get this merged already??

@dangreenisrael
Copy link

@peternhale. Would you mind taking a look at this? It seems to be blocking a lot of people. 🙏

@mdonnalley
Copy link
Contributor

@TPHRyan Sorry for the delays on this PR!

I'll merge this PR once we're done testing on our end. I'd strongly suggest that you open a PR with the same changes against oclif/core since this project will be going into maintenance mode in the next 1-2 weeks once core is officially released

@mdonnalley mdonnalley merged commit e5739c4 into oclif:master Nov 29, 2021
mdonnalley added a commit that referenced this pull request Nov 29, 2021
@mdonnalley
Copy link
Contributor

@TPHRyan Despite our internal testing, we encountered a bug with this change in the sfdx cli after it was published: forcedotcom/cli#1300

I decided to revert the commit for now. I'm happy to merge your changes again once you come up with a fix

@benatshippabo
Copy link
Contributor

I decided to revert the commit for now. I'm happy to merge your changes again once you come up with a fix

@mdonnalley I have forked and updated this pr in #289 let me know if that fixes the issues

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

Successfully merging this pull request may close these issues.

Finding plugins breaks when the package manager doesn't use node_modules
9 participants