From 54555dbcf64d69fe3c0958158d4dc1a00f7a5bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Tue, 27 May 2025 09:36:41 +0200 Subject: [PATCH] Makes the path more specific --- sources/commands/Disable.ts | 2 +- sources/commands/Enable.ts | 2 +- tests/Disable.test.ts | 6 +++--- tests/Enable.test.ts | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sources/commands/Disable.ts b/sources/commands/Disable.ts index 15557b9..ea76f65 100644 --- a/sources/commands/Disable.ts +++ b/sources/commands/Disable.ts @@ -72,7 +72,7 @@ export class DisableCommand extends Command { try { const currentTarget = await fs.promises.realpath(file); - if (binName.includes(`yarn`) && currentTarget.match(/[/\\]switch[/\\]/)) { + if (binName.includes(`yarn`) && currentTarget.match(/[/\\]switch[/\\]bin[/\\]/)) { console.warn(`${binName} is already installed in ${file} and points to a Yarn Switch install - skipping`); return; } diff --git a/sources/commands/Enable.ts b/sources/commands/Enable.ts index 0b35e70..5fc6adc 100644 --- a/sources/commands/Enable.ts +++ b/sources/commands/Enable.ts @@ -85,7 +85,7 @@ export class EnableCommand extends Command { const currentSymlink = await fs.promises.readlink(file); const currentTarget = await fs.promises.realpath(file); - if (binName.includes(`yarn`) && currentTarget.match(/[/\\]switch[/\\]/)) { + if (binName.includes(`yarn`) && currentTarget.match(/[/\\]switch[/\\]bin[/\\]/)) { console.warn(`${binName} is already installed in ${file} and points to a Yarn Switch install - skipping`); return; } diff --git a/tests/Disable.test.ts b/tests/Disable.test.ts index 83b7076..fcea6a6 100644 --- a/tests/Disable.test.ts +++ b/tests/Disable.test.ts @@ -100,11 +100,11 @@ describe(`DisableCommand`, () => { it(`shouldn't remove Yarn binaries if they are in a /switch/ folder`, async () => { await xfs.mktempPromise(async cwd => { - await xfs.mkdirPromise(ppath.join(cwd, `switch`)); - await xfs.writeFilePromise(ppath.join(cwd, `switch/yarn`), `hello`); + await xfs.mkdirPromise(ppath.join(cwd, `switch/bin`), {recursive: true}); + await xfs.writeFilePromise(ppath.join(cwd, `switch/bin/yarn`), `hello`); await xfs.linkPromise( - ppath.join(cwd, `switch/yarn`), + ppath.join(cwd, `switch/bin/yarn`), ppath.join(cwd, `yarn`), ); diff --git a/tests/Enable.test.ts b/tests/Enable.test.ts index 265cfeb..822b238 100644 --- a/tests/Enable.test.ts +++ b/tests/Enable.test.ts @@ -110,11 +110,11 @@ describe(`EnableCommand`, () => { testNotWindows(`shouldn't overwrite Yarn files if they are in a /switch/ folder`, async () => { await xfs.mktempPromise(async cwd => { - await xfs.mkdirPromise(ppath.join(cwd, `switch`)); - await xfs.writeFilePromise(ppath.join(cwd, `switch/yarn`), `hello`); + await xfs.mkdirPromise(ppath.join(cwd, `switch/bin`), {recursive: true}); + await xfs.writeFilePromise(ppath.join(cwd, `switch/bin/yarn`), `hello`); await xfs.linkPromise( - ppath.join(cwd, `switch/yarn`), + ppath.join(cwd, `switch/bin/yarn`), ppath.join(cwd, `yarn`), );