mirror of
https://github.com/apple/pkl.git
synced 2026-07-09 06:25:16 +02:00
Normalize asset paths in local dependencies (#1737)
This changes local asset path resolution so that `..` segments at the dependency root just resolves to the dependency root. This makes import resolution work the same between local and remote dependencies.
This commit is contained in:
@@ -53,9 +53,11 @@ public abstract class Dependency {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public URI resolveAssetUri(URI projectBaseUri, PackageAssetUri packageAssetUri) {
|
public URI resolveAssetUri(URI projectBaseUri, PackageAssetUri packageAssetUri) {
|
||||||
// drop 1 to remove leading `/`
|
// copy how remote dependencies work; the `..` segment at the root just normalizes to the
|
||||||
var assetPath = packageAssetUri.getAssetPath().substring(1);
|
// root.
|
||||||
var resolvedPath = path.resolve(assetPath);
|
var assetPath = Path.of(packageAssetUri.getAssetPath()).normalize();
|
||||||
|
var relativePath = Path.of("/").relativize(assetPath);
|
||||||
|
var resolvedPath = path.resolve(relativePath);
|
||||||
var normalized = IoUtils.toNormalizedPathString(resolvedPath);
|
var normalized = IoUtils.toNormalizedPathString(resolvedPath);
|
||||||
try {
|
try {
|
||||||
var relativeUri = new URI(null, null, normalized, null);
|
var relativeUri = new URI(null, null, normalized, null);
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
// `..` at the package root stays in the package root
|
||||||
|
res1 = import("@project2/../penguin.pkl")
|
||||||
|
res2 = import("@project2/foo/../../penguin.pkl")
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
res1 = read*("@project2/../*").keys
|
||||||
|
res2 = read*("@project2/../../*").keys
|
||||||
|
res3 = read("@project2/../../").text
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
res1 {
|
||||||
|
bird {
|
||||||
|
name = "Penguin"
|
||||||
|
favoriteFruit {
|
||||||
|
name = "Ice Fruit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res2 {
|
||||||
|
bird {
|
||||||
|
name = "Penguin"
|
||||||
|
favoriteFruit {
|
||||||
|
name = "Ice Fruit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
res1 = Set("@project2/../PklProject", "@project2/../PklProject.deps.json", "@project2/../penguin.pkl")
|
||||||
|
res2 = Set("@project2/../../PklProject", "@project2/../../PklProject.deps.json", "@project2/../../penguin.pkl")
|
||||||
|
res3 = """
|
||||||
|
penguin.pkl
|
||||||
|
PklProject
|
||||||
|
PklProject.deps.json
|
||||||
|
|
||||||
|
"""
|
||||||
Reference in New Issue
Block a user