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
2 changes: 1 addition & 1 deletion src/cache/targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const applyTargetDir = async (params: TargetParams) => {
const linkTarget =
process.platform === "win32"
? sourceDir
: path.relative(parentDir, sourceDir);
: path.relative(parentDir, sourceDir) || ".";
await deps.symlink(linkTarget, params.targetDir, type);
} catch (error) {
const code = getErrnoCode(error);
Expand Down
25 changes: 25 additions & 0 deletions tests/targets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,28 @@ test("applyTargetDir uses relative symlink targets on non-Windows", {
const linkTarget = await readlink(targetDir);
assert.equal(linkTarget, path.relative(parentDir, sourceDir));
});

test("applyTargetDir creates usable symlink when source equals target parent", {
skip: process.platform === "win32",
}, async () => {
const tmpRoot = path.join(
tmpdir(),
`docs-cache-target-self-parent-${Date.now().toString(36)}`,
);
const sourceDir = path.join(tmpRoot, "source");
const targetDir = path.join(sourceDir, "linked");

await mkdir(sourceDir, { recursive: true });
await writeFile(path.join(sourceDir, "README.md"), "hello", "utf8");

await applyTargetDir({
sourceDir,
targetDir,
mode: "symlink",
});

const data = await readFile(path.join(targetDir, "README.md"), "utf8");
assert.equal(data, "hello");
const linkTarget = await readlink(targetDir);
assert.equal(linkTarget, ".");
});
Loading