Skip to content

Commit

Permalink
Fix encodeBuildArgsPrefix function
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Sep 1, 2024
1 parent 075b029 commit 23a1b77
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
9 changes: 6 additions & 3 deletions server/build_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ func encodeBuildArgsPrefix(args BuildArgs, pkg Pkg, isDts bool) string {
for name := range info.PeerDependencies {
pkgDeps.Add(name)
}
if pkg.SubPath != "" {
pkgDeps.Add(pkg.Name)
}
}
}
if len(args.alias) > 0 && pkgDeps.Len() > 0 {
var ss sort.StringSlice
for from, to := range args.alias {
if from != pkg.Name {
if from != pkg.Name || pkg.SubPath != "" {
ss = append(ss, fmt.Sprintf("%s:%s", from, to))
}
}
Expand All @@ -111,7 +114,7 @@ func encodeBuildArgsPrefix(args BuildArgs, pkg Pkg, isDts bool) string {
if len(args.deps) > 0 && pkgDeps.Len() > 0 {
var ss sort.StringSlice
for _, p := range args.deps {
if p.Name != pkg.Name {
if p.Name != pkg.Name || pkg.SubPath != "" {
ss = append(ss, fmt.Sprintf("%s@%s", p.Name, p.Version))
}
}
Expand All @@ -123,7 +126,7 @@ func encodeBuildArgsPrefix(args BuildArgs, pkg Pkg, isDts bool) string {
if args.external.Len() > 0 && (args.external.Has("*") || pkgDeps.Len() > 0) {
var ss sort.StringSlice
for _, name := range args.external.Values() {
if name != pkg.Name {
if name != pkg.Name || pkg.SubPath != "" {
ss = append(ss, name)
}
}
Expand Down
5 changes: 4 additions & 1 deletion test/external-all/preact.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ Deno.test("external all", () => {
Deno.test("external all 2", async () => {
const res = await fetch("http://localhost:8080/*[email protected]/jsx-runtime");
const code = await res.text();
assertStringIncludes(code, "[email protected]/X-ZS8q/");
assertStringIncludes(code, "[email protected]/X-ZS8q/denonext/");
const res2 = await fetch("http://localhost:8080/*[email protected]");
const code2 = await res2.text();
assertStringIncludes(code2, "[email protected]/denonext/preact.mjs");
});
12 changes: 11 additions & 1 deletion test/external/preact.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assert, assertStringIncludes } from "https://deno.land/[email protected]/testing/asserts.ts";

import { h } from "preact";
import render from "preact-render-to-string";
Expand Down Expand Up @@ -26,3 +26,13 @@ Deno.test("external", () => {
const html = render(<App />);
assert(html == "<main><p>just now</p></main>");
});

Deno.test("external 2", async () => {
const res = await fetch("http://localhost:8080/[email protected]/hooks?external=preact");
const code = await res.text();
assertStringIncludes(code, "[email protected]/X-ZS9wcmVhY3Q/");

const res2 = await fetch("http://localhost:8080/[email protected]?external=preact&target=es2022");
const code2 = await res2.text();
assertStringIncludes(code2, "[email protected]/es2022/preact.mjs");
});

0 comments on commit 23a1b77

Please sign in to comment.