Skip to content

Commit

Permalink
fix: fix link/unlink pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Mialon committed Dec 12, 2024
1 parent 484f2db commit dee40c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/commands/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default new Command()
.action(async ({ verbose, force }, requestedPkg) => {
const configuration = await config.get();

const pkgs = await packages.list(configuration.repo);
const pkgs = await packages.list(configuration.repo)
.catch(() => [])

const filteredPkgs = pkgs
.filter((pkg) => {
Expand Down
24 changes: 5 additions & 19 deletions src/tools/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,10 @@ export const linkPackage = async (
file.directory,
file.name,
);

const linkRealPath = await getTargetLink(targetLinkPath);
const isValid = linkRealPath === file.fullPath;

if (!linkRealPath) {
await Deno.remove(targetLinkPath);
await Deno.mkdir(dirname(targetLinkPath), { recursive: true });
await Deno.symlink(file.fullPath, targetLinkPath);
}

if (!isValid) {
await Deno.remove(targetLinkPath);
await Deno.symlink(file.fullPath, targetLinkPath);
}
// Avoid throw if it's a symlink that doesn't point to valid file
await Deno.remove(targetLinkPath).catch(() => {})
await Deno.mkdir(dirname(targetLinkPath), { recursive: true });
await Deno.symlink(file.fullPath, targetLinkPath);
}
};

Expand All @@ -128,10 +118,6 @@ export const unlinkPackage = async (
file.name,
);

const linkRealPath = await getTargetLink(targetLinkPath);

if (linkRealPath) {
await Deno.remove(targetLinkPath);
}
await Deno.remove(targetLinkPath).catch(() => {});
}
};

0 comments on commit dee40c2

Please sign in to comment.