Skip to content

Commit

Permalink
yarn plugins might be built-in (#147)
Browse files Browse the repository at this point in the history
in yarn 4, all first-party plugins are installed by default. trying to
install workspace-tools again fails.

ref: yarnpkg/berry#4253
  • Loading branch information
nigelzor authored Sep 2, 2023
1 parent e754eb5 commit 391d043
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/yarn-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export async function getYarnPlugins({ cwd }: { cwd: CommonContext["cwd"] }) {

return stdout.split("\n").reduce((acc, line) => {
try {
const { name, builtin } = JSON.parse(line);
const { name } = JSON.parse(line);

if (!builtin && name !== "@@core") {
if (name !== "@@core") {
return [...acc, name.replace("@yarnpkg/plugin-", "")];
}
} catch {
Expand Down
18 changes: 17 additions & 1 deletion test/yarn-plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ test.serial("getYarnPlugins", async (t) => {

const plugins = await getYarnPlugins(context);

t.deepEqual(plugins, ["interactive-tools", "typescript", "version"]);
t.deepEqual(plugins, [
"essentials",
"compat",
"pnp",
"pnpm",
"interactive-tools",
"typescript",
"version",
]);
});

test.serial("installYarnPluginIfNeeded when needed", async (t) => {
Expand All @@ -40,3 +48,11 @@ test.serial("installYarnPluginIfNeeded when not needed", async (t) => {

t.false(await installYarnPluginIfNeeded("version", context));
});

test.serial("installYarnPluginIfNeeded when builtin", async (t) => {
const context = createContext();

mockExeca({ stdout: '{"name":"@yarnpkg/plugin-version","builtin":true}' });

t.false(await installYarnPluginIfNeeded("version", context));
});

0 comments on commit 391d043

Please sign in to comment.