Skip to content

Commit

Permalink
fix(wrangler): Fix pages dev watch mode [Functions]
Browse files Browse the repository at this point in the history
The watch mode in `pages dev` for Pages Functions
projects is currently partially broken, as it only
watches for file system changes in the "/functions"
directory, but not for changes in any of the Functions'
dependencies. This means that given a Pages Function
"math-is-fun.ts", defined as follows:

```
import { ADD } from "../math/add";

export async function onRequest() {
  return new Response(`${ADD} is fun!`);
}
```

`pages dev` will reload for any changes in
"math-is-fun.ts" itself, but not for any changes in
"math/add.ts", which is its dependency.

Similarly, `pages dev` will not reload for any changes
in non-JS module imports, such as wasm/html/binary module
imports.

This commit fixes all these things, plus adds some extra
polish to the `pages dev` watch mode experience.

Fixes #3840
  • Loading branch information
CarmenPopoviciu committed Jun 25, 2024
1 parent 7d02856 commit 238ecca
Show file tree
Hide file tree
Showing 18 changed files with 465 additions and 145 deletions.
22 changes: 22 additions & 0 deletions .changeset/gorgeous-oranges-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"wrangler": patch
---

fix: Fix `pages dev` watch mode [Functions]

The watch mode in `pages dev` for Pages Functions projects is currently partially broken, as it only watches for file system changes in the
"/functions" directory, but not for changes in any of the Functions' dependencies. This means that given a Pages Function `math-is-fun.ts`, defined as follows:

```
import { ADD } from "../math/add";
export async function onRequest() {
return new Response(`${ADD} is fun!`);
}
```

`pages dev` will reload for any changes in `math-is-fun.ts` itself, but not for any changes in `math/add.ts`, which is its dependency.

Similarly, `pages dev` will not reload for any changes in non-JS module imports, such as wasm/html/binary module imports.

This commit fixes all these things, plus adds some extra polish to the `pages dev` watch mode experience.
1 change: 1 addition & 0 deletions fixtures/pages-functions-with-routes-app/JSMY/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hi</h1>
2 changes: 2 additions & 0 deletions fixtures/pages-functions-with-routes-app/JSMY/js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const x = 6;
export default x;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Cersei = "😽😽😽😽😽😽😽😽😽😽😽😽😽😽😽😽😽";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Gracie = "😽😽😽😽😽";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Bear = "🐻";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Graham = "😽";
10 changes: 10 additions & 0 deletions fixtures/pages-functions-with-routes-app/functions/[foo].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import j from "../JSMY/js.js";
// import h2 from "../my/html copy.html";
import h from "../my/html.html";

export const onRequest = () => {
console.log({ j });
return new Response(h, {
headers: { "Content-Type": "text/html" },
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const onRequest = () => new Response("bz");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ADD } from "../../utils/math/add";
import { MUL } from "../../utils/math/mul";

export async function onRequest() {
return new Response(`${ADD} and ${MUL} are fun!!`);
}
1 change: 1 addition & 0 deletions fixtures/pages-functions-with-routes-app/my/html copy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hi copy</h1>
1 change: 1 addition & 0 deletions fixtures/pages-functions-with-routes-app/my/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hi!</h1>
1 change: 1 addition & 0 deletions fixtures/pages-functions-with-routes-app/utils/math/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ADD = "Addition!";
1 change: 1 addition & 0 deletions fixtures/pages-functions-with-routes-app/utils/math/mul.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const MUL = "multiplication";
Loading

0 comments on commit 238ecca

Please sign in to comment.