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

[Bug?]: yarn workspace version apply removes deferred versions for other packages #4926

Closed
1 task done
hiddenist opened this issue Oct 1, 2022 · 8 comments
Closed
1 task done
Labels
bug Something isn't working stale Issues that didn't get attention unreproducible This issue cannot be reproduced on master

Comments

@hiddenist
Copy link

hiddenist commented Oct 1, 2022

Self-service

  • I'd be willing to implement a fix

Describe the bug

I have a workspace that has two packages which do not share a release cycle.

I'm using deferred versioning on the packages with yarn workspace <workspaceName> version <strategy> --deferred, which creates .yarn/versions/<hash>.yml files defining the strategy just for my target workspace, as I would expect.

When I run yarn workspace <workspaceName> version apply, the package.json file for the specified workspace is updated. As expected, the package.json for the other workspaces has not changed. However, the .yarn/versions files have removed the other deferred changes.

To reproduce

Here's a sherlock script with the reproduction case:

const {promises: {readFile}} = require(`fs`);
const {execSync} = require(`child_process`);

const {resolve} = require(`path`);

const createWorkspacePackage = async (packageName, version = "1.0.0") => {
    await packageJson(
        {
            name: packageName,
            version
        },
        { cwd: `./packages/${packageName}` }
    )
}
const readPackageJson = async (packageName = null) => {
    const path = resolve(
        packageName
            ? `./packages/${packageName}/package.json`
            : "./package.json"
    );
    const body = await readFile(path);
    return body ? JSON.parse(body.toString()) : null;
}

await yarn(`init`, `-w`);

// apparently this is already installed:
// await yarn(`plugin`, `import`, `version`);

await createWorkspacePackage(`unicorn`);
await createWorkspacePackage(`dragon`);
await yarn(`install`);

await expect(readPackageJson("unicorn")).resolves.toMatchObject({
    name: "unicorn",
    version: "1.0.0",
});
expect(await readPackageJson("dragon")).toMatchObject({
    name: "dragon",
    version: "1.0.0",
});

execSync(`git add .`);
// git complains if this isn't set
execSync(`git config user.email "sherlock@test"`);
execSync(`git config user.name "sherlock"`);
execSync(`git commit -m "initial commit"`);

// have to use a different branch for the version plugin to work
execSync(`git checkout -b feature`);

await yarn(`workspace`, `unicorn`, `version`, `minor`, `-d`);
await yarn(`workspace`, `dragon`, `version`, `patch`, `-d`);


await yarn(`workspace`, `unicorn`, `version`, `apply`);

expect(await readPackageJson("unicorn")).toMatchObject({
    name: "unicorn",
    version: "1.1.0",
});
expect(await readPackageJson("dragon")).toMatchObject({
    name: "dragon",
    version: "1.0.0",
});

await yarn(`workspace`, `dragon`, `version`, `apply`);

expect(await readPackageJson("unicorn")).toMatchObject({
    name: "unicorn",
    version: "1.1.0",
});
expect(await readPackageJson("dragon")).toMatchObject({
    name: "dragon",
    version: "1.0.1",
});

// this was fixed in the yarn v4 version plugin so this test is only valid for v3.x
// await expect(yarn(`-v`)).resolves.toMatch(/^3\./);

Environment

System:
    OS: macOS 12.5.1
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 16.15.1 - /private/var/folders/kc/rkdxxgzx4q1b4cq6mpm343100000gn/T/xfs-80d59fb3/node
    Yarn: 3.2.3 - /private/var/folders/kc/rkdxxgzx4q1b4cq6mpm343100000gn/T/xfs-80d59fb3/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
@hiddenist hiddenist added the bug Something isn't working label Oct 1, 2022
@hiddenist
Copy link
Author

hiddenist commented Oct 1, 2022

Ah, I was digging through the source code to see how this could be fixed and it looks like it's been addressed by #4336. Is there any easy way for me to incorporate this change in my own repo now?


Edit: I built a patched version of the @yarnpkg/plugin-version plugin that cherry picks 5ae7b8a.

I tested this out in my reproduction repository and it seems to work fine.

@hiddenist
Copy link
Author

Would be great if the fix that was already merged in the version plugin could be released in yarn v3 - I see that the change is included in v4 rc tags.

@jj811208
Copy link
Contributor

jj811208 commented Oct 4, 2022

I read in this discussion that v4 is now quite stable #4895

Maybe you can try upgrading to v4 using the yarn set version canary command to see if your project breaks, If not, then use it😆.

@hiddenist
Copy link
Author

Fair enough! I think for the moment I'm content using v3 with the patched version plugin that I built, but I'll consider using v4 for my project if I run into any other v4 features that I wish I had.

@yarnbot

This comment has been minimized.

@yarnbot yarnbot added the stale Issues that didn't get attention label Nov 4, 2022
@yarnbot yarnbot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2022
@yarnbot yarnbot added the reproducible This issue can be successfully reproduced label Mar 16, 2023
@yarnbot

This comment has been minimized.

@hiddenist
Copy link
Author

Is there a way to even have Sherlock run on yarn v3?

@yarnbot yarnbot added unreproducible This issue cannot be reproduced on master and removed reproducible This issue can be successfully reproduced labels Mar 16, 2023
@yarnbot
Copy link
Collaborator

yarnbot commented Mar 16, 2023

We couldn't reproduce your issue (all the assertions passed on master).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale Issues that didn't get attention unreproducible This issue cannot be reproduced on master
Projects
None yet
Development

No branches or pull requests

3 participants