Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Yarn 2+ support to pack #1071

Closed
wants to merge 2 commits into from

Conversation

mattwebbio
Copy link
Contributor

Fixes #759

Closed #989 and updated this branch to support the deprecation of qq introduced in #1035.

@strophy
Copy link

strophy commented Dec 31, 2022

Interesting, this one fails for me with:

oclif: gathering workspace for dashmate to /home/strophy/Code/dashpay/platform/packages/dashmate/tmp/dashmate
    Error: Command failed: yarn workspaces focus --production

    Code: 1

But I think you are on the right track again here, I'll close #1060 in favour of this. I see your point on the other PR that c.workspace() returns a workspace temp dir, this is not what I wanted. Something like c.config.name might be more appropriate? I'm trying to run the command in the monorepo root while specifying the focus package like this:

await exec(`yarn workspaces focus ${c.config.name} --production`, { cwd: yarnRoot })

But I'm not sure if this is standard yarn usage or something different in our monorepo, and also not sure if yarn.lock still needs to be copied first.

@mattwebbio
Copy link
Contributor Author

If you were to run yarn workspaces focus --production by hand in /home/strophy/Code/dashpay/platform/packages/dashmate/tmp/dashmate, what's the output? Are you using Yarn 2 or Yarn 3? 🤔

@strophy
Copy link

strophy commented Jan 2, 2023

Interesting, this reveals the underlying error:

dashmate/tmp/dashmate on  chore/update-chain-id [$] ❯ yarn workspaces focus --production
➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: @dashevo/dashpay-contract@workspace:*: Workspace not found (@dashevo/dashpay-contract@workspace:*)
    at ze.getWorkspaceByDescriptor (/home/strophy/.cache/node/corepack/yarn/3.2.2/yarn.js:439:3273)
    at md.getCandidates (/home/strophy/.cache/node/corepack/yarn/3.2.2/yarn.js:390:29963)
    at wd.getCandidates (/home/strophy/.cache/node/corepack/yarn/3.2.2/yarn.js:391:1281)
    at wd.getCandidates (/home/strophy/.cache/node/corepack/yarn/3.2.2/yarn.js:391:1281)
    at /home/strophy/.cache/node/corepack/yarn/3.2.2/yarn.js:439:7764
    at Lg (/home/strophy/.cache/node/corepack/yarn/3.2.2/yarn.js:390:11154)
    at ce (/home/strophy/.cache/node/corepack/yarn/3.2.2/yarn.js:439:7744)
➤ YN0000: └ Completed in 0s 414ms
➤ YN0000: Failed with errors in 0s 420ms

Same error with both yarn 3.2.2 and 3.3.0. Maybe a problem with the workspace?

@peniqliotuv
Copy link
Contributor

Is this still in-progress?

@mattwebbio
Copy link
Contributor Author

@peniqliotuv

Is this still in-progress?

This is working in an oclif CLI monorepo at @appfolio, but I've not had an opportunity to figure out why it isn't working for @strophy. On a previous PR also trying to fix this same issue, an engineer at Salesforce made it pretty clear that this is not a priority for them to test, review, and merge. As a result, it seems like it may be a waste of my time to continue pushing this forward.

@peniqliotuv
Copy link
Contributor

@peniqliotuv

Is this still in-progress?

This is working in an oclif CLI monorepo at @appfolio, but I've not had an opportunity to figure out why it isn't working for @strophy. On a previous PR also trying to fix this same issue, an engineer at Salesforce made it pretty clear that this is not a priority for them to test, review, and merge. As a result, it seems like it may be a waste of my time to continue pushing this forward.

Got it - I'd hate to have to fork over oclif just to get support for this. We are using a monorepo with yarn berry - the only solution now is to create a nested .yarnrc and run yarn set version classic. This also restricts us from using our first-party libraries within our CLI. I'm surprised there aren't more use cases of this... but also Yarn berry isn't quite popular

@strophy
Copy link

strophy commented Jan 21, 2023

Yep, sounds like you are experiencing the same problem as us @peniqliotuv

@mattwebbio I discussed this with our lead engineer last week and he determined that the error I pasted above is due to oclif needing to gather some more things from the workspace into the tmp directory, either as copies or symlinks. We will continue trying to figure out a fix based on this PR.

@strophy
Copy link

strophy commented Jan 28, 2023

@mattwebbio we traced the problem above to quirks in the way our specific monorepo is set up. With additional steps on our side this PR is now tested working for us. @RodEsp Can we please get it merged?

@shumkov
Copy link

shumkov commented Feb 4, 2023

Yeah, it works for me as well. Please merge.

@peniqliotuv
Copy link
Contributor

Any update on this?

@peniqliotuv
Copy link
Contributor

Also I do believe for this to work, you'll need workspace-tools installed. (see: https://yarnpkg.com/cli/workspaces/focus)

src/tarballs/build.ts Outdated Show resolved Hide resolved
Co-authored-by: Jerry Tsui <tiger.tsui@gmail.com>
@peniqliotuv
Copy link
Contributor

@WillieRuemmele / @mdonnalley sorry for the direct ping, saw you were active maintainers

@strophy
Copy link

strophy commented Mar 15, 2023

Or @peternhale can you help maybe?

(@peniqliotuv for background info I was getting good feedback from him when I first raised this issue way back in 2021)

@peniqliotuv
Copy link
Contributor

peniqliotuv commented Mar 20, 2023

I really appreciate this wonderful library but I'm really disappointed by the level of responsiveness for outstanding issues, especially when it was communicated that from the release of @oclif/core v2, the maintainers would be more active in the community. I wish there was a discord or something of sorts where community contributors could collaborate and ask/answer questions.

@peniqliotuv
Copy link
Contributor

peniqliotuv commented Apr 5, 2023

Hi, any update on this? @peternhale

@@ -66,7 +66,21 @@ export async function build(c: BuildConfig, options: {
const yarnRoot = findYarnWorkspaceRoot(c.root) || c.root
if (fs.existsSync(path.join(yarnRoot, 'yarn.lock'))) {
await fs.copy(path.join(yarnRoot, 'yarn.lock'), path.join(c.workspace(), 'yarn.lock'))
await exec('yarn --no-progress --production --non-interactive', {cwd: c.workspace()})

const yarnVersion = (await exec('yarn -v')).stdout.charAt(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @mattwebbio - sorry for lack of comms is yarn guaranteed to be installed? This would throw a command not found error if not

Copy link
Contributor

Choose a reason for hiding this comment

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

The same issue would happen today on the production version of oclif today. I agree that we should add a check, but if possible, that should be another PR

@WillieRuemmele
Copy link
Contributor

Hey @mattwebbio -

I'm trying to verify these changes today but can't get it working.

I've done the following:

  1. check out your fork/branch
  2. yarn set version berry
  3. yarn --version => 3.5.1
  4. yarn && yarn build
./bin/run pack:tarballs
oclif: gathering workspace for oclif to /Users/william.ruemmele/projects/oclif/oclif-fork/tmp/oclif
Error: Command failed: yarn workspaces focus --production

    at ChildProcess.exithandler (node:child_process:419:12)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1091:16)
    at Socket.<anonymous> (node:internal/child_process:449:11)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at Pipe.<anonymous> (node:net:322:12)

using yarn 2.4.3 fails with the same error
using yarn 1.22.19 works

we should be able to run the ./bin/dev pack:tarballs command on the oclif/oclif repo, did I miss a step, or do something wrong? I don't think anyone on the team has adopted yarn 1+ (clearly 😜) so could be a user error too

Copy link

@amccarthy1 amccarthy1 left a comment

Choose a reason for hiding this comment

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

I was able to reproduce @WillieRuemmele 's issue with the steps provided, and confirmed that this is because of a missingworkspace-tools plugin. There's a catch block that's supposed to identify this and print a clearer message, but it looks like it's matching on the wrong pattern. Added a comment for a guard that works for me. Another alternative would be to print this error message for any "Command failed" errors, but that would likely catch more than just missing plugins.

Comment on lines +77 to +79
if (error instanceof Error && error.message.includes('Command not found')) {
throw new Error('Missing workspace tools. Run `yarn plugin import workspace-tools`.')
}

Choose a reason for hiding this comment

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

I wasn't able to get this conditional to correctly identify Command not found errors; it seems like the resulting error's message is just Command failed, but it has an extra property stdout which includes the "Command not found" substring.

This is consistent with the NodeJS docs on this usage:

In case of an error (including any error resulting in an exit code other than 0), a rejected promise is returned, with the same error object given in the callback, but with two additional properties stdout and stderr.

It's a bit verbose, but this does catch it for me:

  const isCommandNotFoundError = (error: unknown): boolean => {
    type ErrorWithStdout = Error & {
      stdout: string;
    }
    const typedError = error as ErrorWithStdout
    if (typedError instanceof Error && typeof typedError.stdout === 'string') {
      return typedError.stdout.includes('Command not found')
    }

    return false
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @amccarthy1 - I tried adding a simplified version of your check

  const isCommandNotFoundError = (error: unknown): boolean => {
    type ErrorWithStdout = Error & {
      stdout: string;
    }
    const typedError = error as ErrorWithStdout
    return typedError.stdout.includes('Command not found')
  }

this worked for yarn1 and yarn3 🎉

when I was testing with yarn2, and was told to yarn plugin import workspace-tools that command failed. I did quite a bit of researching but wasn't able to find a command or version that would install that plugin... if you can figure out a way to install workspace-tools in yarn 2 we could add that to the error message... otherwise I think it'd be ok to continue as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @mattwebbio -

I'm trying to verify these changes today but can't get it working.

I've done the following:

  1. check out your fork/branch
  2. yarn set version berry
  3. yarn --version => 3.5.1
  4. yarn && yarn build
./bin/run pack:tarballs
oclif: gathering workspace for oclif to /Users/william.ruemmele/projects/oclif/oclif-fork/tmp/oclif
Error: Command failed: yarn workspaces focus --production

    at ChildProcess.exithandler (node:child_process:419:12)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1091:16)
    at Socket.<anonymous> (node:internal/child_process:449:11)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at Pipe.<anonymous> (node:net:322:12)

using yarn 2.4.3 fails with the same error using yarn 1.22.19 works

we should be able to run the ./bin/dev pack:tarballs command on the oclif/oclif repo, did I miss a step, or do something wrong? I don't think anyone on the team has adopted yarn 1+ (clearly 😜) so could be a user error too

Hi @WillieRuemmele - so I don't think that the oclif repository will actually work with Yarn 2.
I tried the steps above and couldn't even run yarn install (got this issue installing Typescript).
However, there does seem to be an issue with yarn >=2 <=3 when running plugin import workspace-tools. I've opened an issue here.

Something we could do is explicitly not support yarn 2, which seems reasonable considering that yarn >= 2 doesn't work at all today, and this issue is blocking other folks.

@WillieRuemmele
Copy link
Contributor

Hey everyone and @mattwebbio , @peniqliotuv @amccarthy1 - I created my own PR with those changes we talked about - just merged it and should be publishing as I type this

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

Successfully merging this pull request may close these issues.

Bug: Oclif pack does not work on Yarn v3
6 participants