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) {
|
||||
// drop 1 to remove leading `/`
|
||||
var assetPath = packageAssetUri.getAssetPath().substring(1);
|
||||
var resolvedPath = path.resolve(assetPath);
|
||||
// copy how remote dependencies work; the `..` segment at the root just normalizes to the
|
||||
// root.
|
||||
var assetPath = Path.of(packageAssetUri.getAssetPath()).normalize();
|
||||
var relativePath = Path.of("/").relativize(assetPath);
|
||||
var resolvedPath = path.resolve(relativePath);
|
||||
var normalized = IoUtils.toNormalizedPathString(resolvedPath);
|
||||
try {
|
||||
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