mirror of
https://github.com/morluto/rea.git
synced 2026-11-11 17:28:08 +00:00
fix(reference): preserve directory intent through portable target rebasing
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
1 parent
8e11a430cf
commit
1f2a869e5b
3 files changed
+35
-1
No files matched your search
@@ -640,3 +640,27 @@ it("prefers a later exact filename over an earlier unique canonical candidate",
|
||||
expect.objectContaining({ to: `${composed}.js`, resolution: "internal" }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("retains a missing target's directory requirement when rebasing from the inventory root", () => {
|
||||
const read: ReferenceSourceRead = {
|
||||
root: "/selected",
|
||||
entries: [
|
||||
{
|
||||
status: "read",
|
||||
kind: "symlink",
|
||||
path: "nested/link",
|
||||
target: "sub/missing/",
|
||||
targetState: "missing",
|
||||
},
|
||||
],
|
||||
bytesRead: 0,
|
||||
limitations: [],
|
||||
};
|
||||
expect(parseReferenceSourceEntries(read, []).entries).toContainEqual(
|
||||
expect.objectContaining({
|
||||
path: "nested/link",
|
||||
target: "../sub/missing/",
|
||||
target_state: "missing",
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -6,6 +6,7 @@ import type { JavaScriptPackageType } from "../domain/javascript/javascriptSourc
|
||||
import { logicalPathEscapesRoot } from "../domain/artifactIdentity.js";
|
||||
import {
|
||||
createReferenceSourcePathLookup,
|
||||
rebaseReferenceSourceTarget,
|
||||
decodeReferenceSourceModuleUrlPath,
|
||||
isPortableAbsoluteReferenceTarget,
|
||||
type ReferenceSourcePathLookup,
|
||||
@@ -630,7 +631,7 @@ const appendReadEntry = (
|
||||
entry.targetState === "internal" ||
|
||||
(entry.targetState === "missing" &&
|
||||
!isPortableAbsoluteReferenceTarget(entry.target))
|
||||
? posix.relative(posix.dirname(entry.path), entry.target) || "."
|
||||
? rebaseReferenceSourceTarget(entry.path, entry.target)
|
||||
: entry.target,
|
||||
target_state: entry.targetState,
|
||||
classifications,
|
||||
|
||||
@@ -75,3 +75,12 @@ export const decodeReferenceSourceModuleUrlPath = (
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/** Rebase a portable target without discarding its directory-required suffix. */
|
||||
export const rebaseReferenceSourceTarget = (
|
||||
linkPath: string,
|
||||
target: string,
|
||||
): string => {
|
||||
const relative = posix.relative(posix.dirname(linkPath), target) || ".";
|
||||
return target.endsWith("/") ? `${relative}/` : relative;
|
||||
};
|
||||
Reference in new issue
Block a user