Skip to content

Commit d04d483

Browse files
authored
fix: Yarn switch install support and tests (#761)
1 parent 172a630 commit d04d483

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

sources/commands/Enable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ export class EnableCommand extends Command<Context> {
8383
const symlink = path.relative(installDirectory, path.join(distFolder, `${binName}.js`));
8484

8585
if (fs.existsSync(file)) {
86-
const currentSymlink = await fs.promises.readlink(file);
86+
const currentSymlink = await fs.promises.realpath(file);
8787

88-
if (binName.includes(`yarn`) && corepackUtils.isYarnSwitchPath(await fs.promises.realpath(file))) {
88+
if (binName.includes(`yarn`) && corepackUtils.isYarnSwitchPath(currentSymlink)) {
8989
console.warn(`${binName} is already installed in ${file} and points to a Yarn Switch install - skipping`);
9090
return;
9191
}

tests/Enable.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ describe(`EnableCommand`, () => {
9393
await xfs.writeFilePromise(ppath.join(cwd, `yarn`), `hello`);
9494

9595
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`;
96-
await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({
96+
await expect(runCli(cwd, [`enable`, `--install-directory`, npath.fromPortablePath(cwd)])).resolves.toMatchObject({
9797
stdout: ``,
9898
stderr: ``,
9999
exitCode: 0,
100100
});
101101

102102
const file = await xfs.readFilePromise(ppath.join(cwd, `yarn`), `utf8`);
103-
expect(file).toBe(`hello`);
103+
expect(file).not.toBe(`hello`);
104104
});
105105
});
106106

@@ -109,15 +109,15 @@ describe(`EnableCommand`, () => {
109109
await xfs.mkdirPromise(ppath.join(cwd, `switch/bin`), {recursive: true});
110110
await xfs.writeFilePromise(ppath.join(cwd, `switch/bin/yarn`), `hello`);
111111

112-
await xfs.linkPromise(
112+
await xfs.symlinkPromise(
113113
ppath.join(cwd, `switch/bin/yarn`),
114114
ppath.join(cwd, `yarn`),
115115
);
116116

117117
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`;
118-
await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({
118+
await expect(runCli(cwd, [`enable`, `--install-directory`, npath.fromPortablePath(cwd)])).resolves.toMatchObject({
119119
stdout: ``,
120-
stderr: ``,
120+
stderr: expect.stringMatching(/^yarn is already installed in .+ and points to a Yarn Switch install - skipping\n$/),
121121
exitCode: 0,
122122
});
123123

0 commit comments

Comments
 (0)