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

fix: correct yarn detection #140

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ export const packageManagers: PackageManager[] = [
{
name: "yarn",
command: "yarn",
majorVersion: "1.0.0",
majorVersion: "1",
lockFile: "yarn.lock",
},
{
name: "yarn",
command: "yarn",
majorVersion: "3.0.0",
majorVersion: "3",
Comment on lines 59 to +61
Copy link
Contributor Author

@LekoArts LekoArts Jul 5, 2024

Choose a reason for hiding this comment

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

It would probably be a breaking change, but from a usability standpoint this here would be better:

name: "yarn-berry"
majorVersion: ["3", "4"]

Because right now on any new yarn berry project (the current major is 4) this whole detection system won't work. And there is no real differentiation between yarn classic and yarn berry.

So in my own code I need to write this at the moment:

if (pm.name === 'yarn' && (pm.majorVersion === "3" || pm.majorVersion === "4")) {}

Would be cool to be able to write this instead:

if (pm.name === 'yarn-berry') {}

lockFile: "yarn.lock",
files: [".yarnrc.yml"],
},
Expand Down
3 changes: 3 additions & 0 deletions test/_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type Fixture = {
packageManager: PackageManagerName;
majorVersion?: string;
workspace: boolean;
files?: string[];
};

export const fixtures = (
Expand Down Expand Up @@ -48,11 +49,13 @@ export const fixtures = (
name: "yarn-berry",
packageManager: "yarn",
majorVersion: "3",
files: [".yarnrc.yml"],
},
{
name: "yarn-berry-workspace",
packageManager: "yarn",
majorVersion: "3",
files: [".yarnrc.yml"],
},
] satisfies Partial<Fixture>[]
)
Expand Down
3 changes: 3 additions & 0 deletions test/detect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ describe("detectPackageManager", () => {
if (fixture.majorVersion) {
expect(detected?.majorVersion).toBe(fixture.majorVersion);
}
if (fixture.files) {
expect(detected?.files).toEqual(fixture.files);
}
});

it.skipIf(fixture.name.includes("berry") /* TODO */)(
Expand Down