Skip to content

Commit 614272b

Browse files
authored
fix: preserve trailing slashes in nested dep URLs (#42) (#43)
filepath.Join strips trailing slashes, so expandDepURL lost them for nested dependencies. Re-append the slash after computing the relative path when the original filePath ended with "/" or was empty. Closes #42 Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 298c77d commit 614272b

13 files changed

Lines changed: 101 additions & 1 deletion

File tree

resolve/local/local.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,11 @@ func (r *Resolver) expandDepURL(depName, filePath string, nested bool, depPath,
907907
if err != nil {
908908
return r.template.Expand(depName, "", filePath)
909909
}
910-
return "/" + filepath.ToSlash(rel)
910+
result := "/" + filepath.ToSlash(rel)
911+
if strings.HasSuffix(filePath, "/") || filePath == "" {
912+
result += "/"
913+
}
914+
return result
911915
}
912916

913917
// parsePackageName extracts the package name from a package spec.

resolve/local/local_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func TestResolver(t *testing.T) {
6464
{"circular dependencies", "circular-deps"},
6565
{"nested node_modules", "nested-node-modules"},
6666
{"peer dependencies in scopes", "with-peer-deps"},
67+
{"nested dep trailing-slash exports", "nested-trailing-slash"},
68+
{"mixed nested and hoisted with wildcards", "nested-mixed-hoisted"},
6769
}
6870

6971
for _, tt := range tests {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"imports": {
3+
"alpha": "/node_modules/alpha/index.js",
4+
"beta": "/node_modules/beta/index.js",
5+
"shared-lib": "/node_modules/shared-lib/index.js",
6+
"shared-lib/": "/node_modules/shared-lib/src/"
7+
},
8+
"scopes": {
9+
"/node_modules/alpha/": {
10+
"shared-lib": "/node_modules/alpha/node_modules/shared-lib/v1.js",
11+
"shared-lib/": "/node_modules/alpha/node_modules/shared-lib/lib/"
12+
},
13+
"/node_modules/beta/": {
14+
"shared-lib": "/node_modules/shared-lib/index.js",
15+
"shared-lib/": "/node_modules/shared-lib/src/"
16+
}
17+
}
18+
}

testdata/resolve/nested-mixed-hoisted/node_modules/alpha/node_modules/shared-lib/package.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testdata/resolve/nested-mixed-hoisted/node_modules/alpha/package.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testdata/resolve/nested-mixed-hoisted/node_modules/beta/package.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testdata/resolve/nested-mixed-hoisted/node_modules/shared-lib/package.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "mixed-test",
3+
"dependencies": {
4+
"alpha": "^1.0.0",
5+
"beta": "^1.0.0",
6+
"shared-lib": "^2.0.0"
7+
}
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"imports": {
3+
"parent-pkg": "/node_modules/parent-pkg/index.js"
4+
},
5+
"scopes": {
6+
"/node_modules/parent-pkg/": {
7+
"@nested/lib": "/node_modules/parent-pkg/node_modules/@nested/lib/index.js",
8+
"@nested/lib/": "/node_modules/parent-pkg/node_modules/@nested/lib/src/",
9+
"@nested/lib/controllers/": "/node_modules/parent-pkg/node_modules/@nested/lib/controllers/",
10+
"no-exports-dep": "/node_modules/parent-pkg/node_modules/no-exports-dep/index.js",
11+
"no-exports-dep/": "/node_modules/parent-pkg/node_modules/no-exports-dep/"
12+
}
13+
}
14+
}

testdata/resolve/nested-trailing-slash/node_modules/parent-pkg/node_modules/@nested/lib/package.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)