Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path resolution in Pages esbuild #773

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-turtles-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: the pathing for the template was resolving using `__dirname` into the esbuild file which then used a relative path back from pages. When ran inside a test would get a resolved absolute path to the template from "pages/pages/functions/template-workers.ts
4 changes: 1 addition & 3 deletions packages/wrangler/pages/functions/buildWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export function buildWorker({
onEnd = () => {},
}: Options) {
return build({
entryPoints: [
path.resolve(__dirname, "../pages/functions/template-worker.ts"),
],
entryPoints: [path.resolve(__dirname, "./template-worker.ts")],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if __dirname returns a different result once this file is bundled?

In other words, the __dirname at runtime is packages/wrangler/wrangler-dist rather than the source path of packages/wrangler/pages/functions.

I note that this only came up when we were trying to run Pages in a Wrangler unit test, which is not bundled...

inject: [routesModule],
bundle: true,
format: "esm",
Expand Down