From 29b29fe5ff79749da1ecd680cd816493ca568841 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 6 Nov 2025 22:39:38 +0100 Subject: [PATCH] fix: Yarn switch install support and tests --- sources/commands/Enable.ts | 4 ++-- tests/Enable.test.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sources/commands/Enable.ts b/sources/commands/Enable.ts index 6a2a58413..978059072 100644 --- a/sources/commands/Enable.ts +++ b/sources/commands/Enable.ts @@ -83,9 +83,9 @@ export class EnableCommand extends Command { const symlink = path.relative(installDirectory, path.join(distFolder, `${binName}.js`)); if (fs.existsSync(file)) { - const currentSymlink = await fs.promises.readlink(file); + const currentSymlink = await fs.promises.realpath(file); - if (binName.includes(`yarn`) && corepackUtils.isYarnSwitchPath(await fs.promises.realpath(file))) { + if (binName.includes(`yarn`) && corepackUtils.isYarnSwitchPath(currentSymlink)) { console.warn(`${binName} is already installed in ${file} and points to a Yarn Switch install - skipping`); return; } diff --git a/tests/Enable.test.ts b/tests/Enable.test.ts index a72b5b480..7ca77cbee 100644 --- a/tests/Enable.test.ts +++ b/tests/Enable.test.ts @@ -93,14 +93,14 @@ describe(`EnableCommand`, () => { await xfs.writeFilePromise(ppath.join(cwd, `yarn`), `hello`); process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`; - await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({ + await expect(runCli(cwd, [`enable`, `--install-directory`, npath.fromPortablePath(cwd)])).resolves.toMatchObject({ stdout: ``, stderr: ``, exitCode: 0, }); const file = await xfs.readFilePromise(ppath.join(cwd, `yarn`), `utf8`); - expect(file).toBe(`hello`); + expect(file).not.toBe(`hello`); }); }); @@ -109,15 +109,15 @@ describe(`EnableCommand`, () => { await xfs.mkdirPromise(ppath.join(cwd, `switch/bin`), {recursive: true}); await xfs.writeFilePromise(ppath.join(cwd, `switch/bin/yarn`), `hello`); - await xfs.linkPromise( + await xfs.symlinkPromise( ppath.join(cwd, `switch/bin/yarn`), ppath.join(cwd, `yarn`), ); process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`; - await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({ + await expect(runCli(cwd, [`enable`, `--install-directory`, npath.fromPortablePath(cwd)])).resolves.toMatchObject({ stdout: ``, - stderr: ``, + stderr: expect.stringMatching(/^yarn is already installed in .+ and points to a Yarn Switch install - skipping\n$/), exitCode: 0, });