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

feat: support yarnpkg as an alias for yarn #1670

Merged
merged 8 commits into from
Mar 14, 2024

Conversation

rytmis
Copy link
Contributor

@rytmis rytmis commented Jan 28, 2024

My attempt at implementing #1391. This is my first Rust code aside from a helloworld example, so you know, it mightn't be perfect yet.

I tested (and wrote) this on macOS Sonoma 14.3 by switching between the 1.1.1 release and this dev build, and it seems to work, but I'm not 100% sure on how to reliably verify it. I bumped the version to 1.1.2 so that the dev install script would let me switch, not sure if I was supposed to do that. :)

Copy link
Contributor

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

This seems totally on the right path! Thanks for working on it!!

I think there are a few things we'd still need to do:

  • Ensure we create the yarnpkg shim (will require changes in the installer I think?)

ln -s "${INSTALL_DIR}"/shim "${INSTALL_DIR}"/bin/yarn

local main_shims=( node npm npx yarn )

volta/wix/main.wxs

Lines 157 to 172 in 889ff97

<Component Id='yarnBinary' Guid='*' Win64='$(var.Win64)'>
<File
Id='yarnEXE'
Name='yarn.exe'
DiskId='1'
Source='target\release\volta-shim.exe'
KeyPath='yes'/>
</Component>
<Component Id='yarnScript' Guid='*' Win64='$(var.Win64)'>
<File
Id='yarnCMD'
Name='yarn.cmd'
DiskId='1'
Source='wix\shim.cmd'
KeyPath='yes'/>
</Component>

  • Add some tests so we don't accidentally break this new feature. I'm not 100% sure where to add the tests. Maybe @chriskrycho or @charlespierce have an idea...

Cargo.toml Outdated
@@ -1,6 +1,6 @@
[package]
name = "volta"
version = "1.1.1"
version = "1.1.2"
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, we only bump the version when we do releases.

Copy link
Contributor

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Also need to make sure volta run knows how to handle this correctly. I think that means adding another match arm here:

Some("yarn") => yarn::command(args, session),

Some tests are here (you could probably add a couple that call volta run --yarn=1.7.71 yarnpkg --version or something):

#[test]
fn command_line_yarn_1() {
let s = sandbox()
.node_available_versions(NODE_VERSION_INFO)
.distro_mocks::<NodeFixture>(&NODE_VERSION_FIXTURES)
.yarn_1_available_versions(YARN_1_VERSION_INFO)
.distro_mocks::<Yarn1Fixture>(&YARN_1_VERSION_FIXTURES)
.env(VOLTA_LOGLEVEL, "debug")
.build();
assert_that!(
s.volta("run --node 10.99.1040 --yarn 1.7.71 yarn --version"),
execs()
.with_status(ExitCode::Success as i32)
.with_stderr_contains("[..]Yarn: 1.7.71 from command-line configuration")
);
}
#[test]
fn command_line_yarn_3() {
let s = sandbox()
.node_available_versions(NODE_VERSION_INFO)
.distro_mocks::<NodeFixture>(&NODE_VERSION_FIXTURES)
.yarn_1_available_versions(YARN_1_VERSION_INFO)
.yarn_berry_available_versions(YARN_BERRY_VERSION_INFO)
.distro_mocks::<Yarn1Fixture>(&YARN_1_VERSION_FIXTURES)
.distro_mocks::<YarnBerryFixture>(&YARN_BERRY_VERSION_FIXTURES)
.env(VOLTA_LOGLEVEL, "debug")
.build();
assert_that!(
s.volta("run --node 10.99.1040 --yarn 3.7.71 yarn --version"),
execs()
.with_status(ExitCode::Success as i32)
.with_stderr_contains("[..]Yarn: 3.7.71 from command-line configuration")
);
}
#[test]
fn inherited_yarn_1() {
let s = sandbox()
.node_available_versions(NODE_VERSION_INFO)
.distro_mocks::<NodeFixture>(&NODE_VERSION_FIXTURES)
.yarn_1_available_versions(YARN_1_VERSION_INFO)
.distro_mocks::<Yarn1Fixture>(&YARN_1_VERSION_FIXTURES)
.package_json(&package_json_with_pinned_node_yarn("10.99.1040", "1.2.42"))
.env(VOLTA_LOGLEVEL, "debug")
.build();
assert_that!(
s.volta("run --node 10.99.1040 yarn --version"),
execs()
.with_status(ExitCode::Success as i32)
.with_stderr_contains("[..]Yarn: 1.2.42 from project configuration")
);
}
#[test]
fn inherited_yarn_3() {
let s = sandbox()
.node_available_versions(NODE_VERSION_INFO)
.distro_mocks::<NodeFixture>(&NODE_VERSION_FIXTURES)
.yarn_1_available_versions(YARN_1_VERSION_INFO)
.yarn_berry_available_versions(YARN_BERRY_VERSION_INFO)
.distro_mocks::<Yarn1Fixture>(&YARN_1_VERSION_FIXTURES)
.distro_mocks::<YarnBerryFixture>(&YARN_BERRY_VERSION_FIXTURES)
.package_json(&package_json_with_pinned_node_yarn("10.99.1040", "3.2.42"))
.env(VOLTA_LOGLEVEL, "debug")
.build();
assert_that!(
s.volta("run --node 10.99.1040 yarn --version"),
execs()
.with_status(ExitCode::Success as i32)
.with_stderr_contains("[..]Yarn: 3.2.42 from project configuration")
);
}

@rytmis
Copy link
Contributor Author

rytmis commented Jan 28, 2024

Interesting! Something gave me a yarnpkg symlink under .volta/bin--but I'll take a look at your links a bit later and see if I can figure what's what.

@rwjblue
Copy link
Contributor

rwjblue commented Jan 28, 2024

Something gave me a yarnpkg symlink under .volta/bin--but I'll take a look at your links a bit later and see if I can figure what's what.

Most likely that was done by volta setup (which your changes to get_shim_list_deduped in volta/crates/volta-core/src/shim.rs do).

@rytmis
Copy link
Contributor Author

rytmis commented Jan 28, 2024

Also need to make sure volta run knows how to handle this correctly. I think that means adding another match arm here:

Did I mess something up in the PR? I thought I handled it here:

Some("yarn") => yarn::command(args, session, "yarn"),
Some("yarnpkg") => yarn::command(args, session, "yarnpkg"),

And here:

yarn_executable: &str,

Ok(ToolCommand::new(yarn_executable, args, platform, ToolKind::Yarn).into())

As for the tests--do you prefer a separate test that duplicates the setup, or would a second assertion in the test do?

And finally: yarn 3 doesn't seem to ship the yarnpkg command. That results in a NoPlatform error, which is reported as a missing node installation. The NoPlatform error should probably include the name of the missing component? Should I try to handle the yarn 3 case gracefully, or would the error suffice, if the message was correct?

@rwjblue
Copy link
Contributor

rwjblue commented Jan 28, 2024

Did I mess something up in the PR? I thought I handled it here:

Nope, you didn't miss anything. I did! 😸 I was jumping between main and your PR, and must have gotten confused about which branch I was on. 🤦

As for the tests--do you prefer a separate test that duplicates the setup, or would a second assertion in the test do?

I think additional assertions are fine (though I'll defer to @chriskrycho / @charlespierce if they have a strong preference).

And finally: yarn 3 doesn't seem to ship the yarnpkg command.

Oof. That makes things a bit rough. I do worry about the situation where someone might check (e.g. in a script do which yarnpkg as a way to switch or something), but IMHO that's not a great way to test anyways so probably not a giant issue for us here.

That results in a NoPlatform error, which is reported as a missing node installation. The NoPlatform error should probably include the name of the missing component? Should I try to handle the yarn 3 case gracefully, or would the error suffice, if the message was correct?

Yeah, I think we'll need to tweak this. I'd prefer to have a custom error specifically for this scenario (usage of yarnpkg with yarn@3+) (and we can throw another specific test for that (here).

@charlespierce
Copy link
Contributor

Regarding the Yarn 3 / yarnpkg missing issues: It looks like the Yarn 1 version of yarnpkg was only ever a pure passthrough to yarn—would it make sense for Volta to treat it the same way? That is, we don't actually change the yarn::command function to take in the executable, but continue to always execute yarn, regardless of whether it was actually called using yarn or yarnpkg?

That would mean that yarnpkg continues to work on Yarn 3, even though it isn't actually shipped with it, but it would simplify the code a little and remove the issues with the specific version.

@rytmis
Copy link
Contributor Author

rytmis commented Feb 4, 2024

That makes more sense than any other alternative I can think of, yes. I reverted the yarn::command change and combined the yarn and yarnpkg arms of the match into one.

@rytmis
Copy link
Contributor Author

rytmis commented Feb 5, 2024

Anything else I should do to get this finalized?

I just verified that this works on Windows--I went down this rabbit hole because I noticed that the lack of a yarnpkg shim to Volta was causing issues with caniuse-lite's update command, and lo and behold, that use case works now. :D

Copy link
Contributor

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Seems good to me!

@charlespierce / @chriskrycho - Any other changes needed from y'alls perspective?

Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

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

Nope, seems excellent, let's do it! (And sorry for the delay!)

@chriskrycho chriskrycho linked an issue Mar 14, 2024 that may be closed by this pull request
@chriskrycho chriskrycho merged commit ddfdda9 into volta-cli:main Mar 14, 2024
10 checks passed
@rytmis rytmis deleted the feature/yarnpkg-shim branch March 14, 2024 11:35
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.

Volta should create a shim for yarnpkg
4 participants