Skip to content

Commit 48d76b9

Browse files
authored
Remove unused legacyGetBuildTargetByUA function (esm-dev#1361)
1 parent 310a6d8 commit 48d76b9

5 files changed

Lines changed: 8 additions & 291 deletions

File tree

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/ije/esbuild-internal v0.28.0
1010
github.com/ije/gox v0.10.4
1111
github.com/ije/rex v1.15.6
12-
github.com/mssola/useragent v1.0.0
1312
go.etcd.io/bbolt v1.4.3
1413
golang.org/x/net v0.53.0
1514
golang.org/x/term v0.42.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ github.com/ije/gox v0.10.4 h1:c8QpPl6cCdUOm0FrheF4icNstsTImaRRrJv4l8BQmw8=
1414
github.com/ije/gox v0.10.4/go.mod h1:3GTaK8WXf6oxRbrViLqKNLTNcMR871Dz0zoujFNmG48=
1515
github.com/ije/rex v1.15.6 h1:wJwVjk1LcHgeQ456dTAHntNL9+aW1xwFjXneDB7bJAw=
1616
github.com/ije/rex v1.15.6/go.mod h1:F/nHnBvOhbnnkccthddcPW/BcmVUSeJBQLPQBdGQTFM=
17-
github.com/mssola/useragent v1.0.0 h1:WRlDpXyxHDNfvZaPEut5Biveq86Ze4o4EMffyMxmH5o=
18-
github.com/mssola/useragent v1.0.0/go.mod h1:hz9Cqz4RXusgg1EdI4Al0INR62kP7aPSRNHnpU+b85Y=
1917
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2018
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2119
github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA=

server/legacy_compat.go

Lines changed: 0 additions & 212 deletions
This file was deleted.

server/legacy_router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func esmLegacyRouter(fs storage.Storage) rex.Handle {
9292

9393
// packages created by the `/build` API
9494
if len(pathname) == 42 && strings.HasPrefix(pathname, "/~") && valid.IsHexString(pathname[2:]) {
95-
return redirect(ctx, fmt.Sprintf("/v135%s@0.0.0/%s/mod.mjs", pathname, legacyGetBuildTargetByUA(ctx.UserAgent())), true)
95+
return redirect(ctx, fmt.Sprintf("/v135%s@0.0.0/%s/mod.mjs", pathname, getBuildTargetByUA(ctx.UserAgent())), true)
9696
}
9797

9898
return ctx.Next()
@@ -220,7 +220,7 @@ func legacyESM(ctx *rex.Context, fs storage.Storage, buildVersionPrefix string)
220220
if query != "" {
221221
if !ctx.R.URL.Query().Has("target") {
222222
varyUA = true
223-
savePath += "." + legacyGetBuildTargetByUA(ctx.UserAgent())
223+
savePath += "." + getBuildTargetByUA(ctx.UserAgent())
224224
}
225225
h := xxhash.New()
226226
h.Write([]byte(query))

test/pkg.pr.new/test.ts

Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,22 @@ import { assert, assertEquals, assertStringIncludes } from "jsr:@std/assert";
22

33
Deno.test("routing", async () => {
44
{
5-
const { Bench } = await import("http://localhost:8080/pr/tinybench@a832a55");
6-
assertEquals(typeof Bench, "function");
5+
const {mount}= await import("http://localhost:8080/pkg.pr.new/sveltejs/svelte@main");
6+
assertEquals(typeof mount, "function");
77
}
88
{
9-
const { Bench } = await import("http://localhost:8080/pr/tinylibs/tinybench@a832a55");
10-
assertEquals(typeof Bench, "function");
9+
const { mount } = await import("http://localhost:8080/pr/sveltejs/svelte@main");
10+
assertEquals(typeof mount, "function");
1111
}
12-
{
13-
const { Bench } = await import("http://localhost:8080/pr/tinylibs/tinybench/tinybench@a832a55");
14-
assertEquals(typeof Bench, "function");
15-
}
16-
{
17-
const { Bench } = await import("http://localhost:8080/pkg.pr.new/tinybench@a832a55");
18-
assertEquals(typeof Bench, "function");
19-
}
20-
{
21-
const { proxy } = await import("http://localhost:8080/pr/valtio@main");
22-
assertEquals(typeof proxy, "function");
23-
}
24-
// {
25-
// const { proxy } = await import("http://localhost:8080/pr/valtio@e21edb3");
26-
// assertEquals(typeof proxy, "function");
27-
// }
28-
// {
29-
// const { proxy } = await import("http://localhost:8080/pr/pmndrs/valtio@e21edb3");
30-
// assertEquals(typeof proxy, "function");
31-
// }
32-
// {
33-
// const { proxy } = await import("http://localhost:8080/pr/pmndrs/valtio/valtio@e21edb3");
34-
// assertEquals(typeof proxy, "function");
35-
// }
36-
{
37-
const { defineComponent } = await import("http://localhost:8080/pr/vuejs/vue-vapor/@vue/runtime-dom@3f6ce96");
38-
assertEquals(typeof defineComponent, "function");
39-
}
40-
});
41-
42-
Deno.test("module", async () => {
43-
const res = await fetch("http://localhost:8080/pr/tinybench@a832a55", { headers: { "user-agent": "i'm a browser" } });
44-
assertEquals(res.status, 200);
45-
assertEquals(res.headers.get("content-type"), "application/javascript; charset=utf-8");
46-
assertEquals(res.headers.get("cache-control"), "public, max-age=31536000, immutable");
47-
assertEquals(res.headers.get("x-typescript-types"), "http://localhost:8080/pr/tinybench@a832a55/dist/index.d.ts");
48-
const text = await res.text();
49-
assertStringIncludes(text, "/es2022/tinybench.mjs");
50-
});
51-
52-
Deno.test("dts", async () => {
53-
const res = await fetch("http://localhost:8080/pr/tinybench@a832a55/dist/index.d.ts");
54-
assertEquals(res.status, 200);
55-
assertEquals(res.headers.get("content-type"), "application/typescript; charset=utf-8");
56-
assertEquals(res.headers.get("cache-control"), "public, max-age=31536000, immutable");
57-
const text = await res.text();
58-
assertStringIncludes(text, "declare class Bench extends EventTarget {");
59-
});
60-
61-
Deno.test("raw files", async () => {
62-
const { name } = await fetch("http://localhost:8080/pr/tinylibs/tinybench/tinybench@a832a55/package.json").then((res) => res.json());
63-
assertEquals(name, "tinybench");
64-
65-
const res = await fetch("http://localhost:8080/pr/@rolldown/browser@main?raw", { headers: { "user-agent": "i'm a browser" } });
66-
assert(res.redirected);
67-
assertEquals(res.status, 200);
68-
assertEquals(res.headers.get("content-type"), "application/javascript; charset=utf-8");
69-
assertEquals(res.headers.get("cache-control"), "public, max-age=31536000, immutable");
70-
const code = await res.text();
71-
assertStringIncludes(code, "build");
7212
});
7313

7414
Deno.test("resolve branch to commit hash", async () => {
75-
const res = await fetch("http://localhost:8080/pr/@rolldown/browser@main", { headers: { "user-agent": "i'm a browser" } });
15+
const res = await fetch("http://localhost:8080/pr/sveltejs/svelte@main", { headers: { "user-agent": "i'm a browser" } });
7616
assert(!res.redirected);
7717
assertEquals(res.status, 200);
7818
assertEquals(res.headers.get("content-type"), "application/javascript; charset=utf-8");
7919
assertEquals(res.headers.get("cache-control"), "public, max-age=600");
8020
const code = await res.text();
81-
assert(/@rolldown\/browser@[\da-f]{7}/.test(code));
21+
assert(/sveltejs\/svelte@[\da-f]{7}/.test(code));
8222
});
8323

84-
Deno.test("as a dependency", async () => {
85-
const res = await fetch("http://localhost:8080/pr/vuejs/vue-vapor/vue@3f6ce96", { headers: { "user-agent": "i'm a browser" } });
86-
assertEquals(res.status, 200);
87-
assertEquals(res.headers.get("content-type"), "application/javascript; charset=utf-8");
88-
assertEquals(res.headers.get("cache-control"), "public, max-age=31536000, immutable");
89-
const code = await res.text();
90-
assertStringIncludes(code, 'import "/pr/vuejs/vue-vapor/@vue/runtime-dom@3f6ce96/es2022/runtime-dom.mjs"');
91-
});

0 commit comments

Comments
 (0)