Skip to content

Commit 780817d

Browse files
committed
Refactor some of the shared no bundle logic and address misc PR comments
1 parent da29860 commit 780817d

File tree

15 files changed

+198
-717
lines changed

15 files changed

+198
-717
lines changed

.changeset/cuddly-rules-rest.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"wrangler": patch
2+
"wrangler": minor
33
---
44

55
feat: Add support for the undocumented `_worker.js/` directory in Pages

fixtures/pages-workerjs-directory/public/_worker.js/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import staticMod from "./static.js";
2+
13
export default {
24
async fetch(request, env) {
35
const { pathname } = new URL(request.url);
6+
7+
if (pathname === "/static") {
8+
return new Response(staticMod);
9+
}
10+
411
if (pathname !== "/") {
512
return new Response((await import(`./${pathname.slice(1)}`)).default);
613
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "static";

fixtures/pages-workerjs-directory/tests/index.test.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { resolve } from "node:path";
1+
import { execSync } from "node:child_process";
2+
import { readFileSync } from "node:fs";
3+
import { tmpdir } from "node:os";
4+
import path, { join, resolve } from "node:path";
25
import { fetch } from "undici";
36
import { describe, it } from "vitest";
47
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
@@ -13,9 +16,27 @@ describe.concurrent("Pages _worker.js/ directory", () => {
1316
await expect(
1417
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
1518
).resolves.toContain("Hello, world!");
19+
await expect(
20+
fetch(`http://${ip}:${port}/static`).then((resp) => resp.text())
21+
).resolves.toContain("static");
1622
await expect(
1723
fetch(`http://${ip}:${port}/other-script`).then((resp) => resp.text())
1824
).resolves.toContain("test");
1925
await stop();
2026
});
27+
28+
it("should bundle", async ({ expect }) => {
29+
const dir = tmpdir();
30+
const file = join(dir, "./_worker.bundle");
31+
32+
execSync(
33+
`npx wrangler pages functions build --build-output-directory public --outfile ${file} --bindings="{\\"d1_databases\\":{\\"FOO\\":{}}}"`,
34+
{
35+
cwd: path.resolve(__dirname, ".."),
36+
}
37+
);
38+
39+
expect(readFileSync(file, "utf-8")).toContain("D1_ERROR");
40+
expect(readFileSync(file, "utf-8")).toContain('"static"');
41+
});
2142
});

0 commit comments

Comments
 (0)