Skip to content
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 sources/commands/Enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export class EnableCommand extends Command<Context> {
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;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Enable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
});
});

Expand All @@ -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,
});

Expand Down