Makes the path more specific

This commit is contained in:
Maël Nison 2025-05-27 09:36:41 +02:00 committed by GitHub
parent 55b86aca65
commit 54555dbcf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 8 deletions

View File

@ -72,7 +72,7 @@ export class DisableCommand extends Command<Context> {
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;
}

View File

@ -85,7 +85,7 @@ export class EnableCommand extends Command<Context> {
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;
}

View File

@ -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`),
);

View File

@ -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`),
);