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(pages): wrangler pages dev should prioritize _worker.js #1950

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

CarmenPopoviciu
Copy link
Contributor

When using a _worker.js file, the entire /functions directory should be ignored – this includes its routing and middleware characteristics. Currently wrangler pages dev does the reverse, by prioritizing /functions over _worker.js. This commit fixes that.

@changeset-bot
Copy link

changeset-bot bot commented Sep 28, 2022

🦋 Changeset detected

Latest commit: 3c0efbf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
pages-workerjs-and-functions-app Patch
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Sep 28, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/3181524686/npm-package-wrangler-1950

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/1950/npm-package-wrangler-1950

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/3181524686/npm-package-wrangler-1950 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.developers.workers.dev/runs/3181524686/npm-package-cloudflare-pages-shared-1950

@codecov
Copy link

codecov bot commented Sep 28, 2022

Codecov Report

Merging #1950 (3c0efbf) into main (c172217) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1950      +/-   ##
==========================================
- Coverage   72.72%   72.70%   -0.02%     
==========================================
  Files         118      118              
  Lines        8230     8229       -1     
  Branches     2160     2160              
==========================================
- Hits         5985     5983       -2     
- Misses       2245     2246       +1     
Impacted Files Coverage Δ
packages/wrangler/src/pages/dev.tsx 19.90% <0.00%> (-1.27%) ⬇️
...ackages/wrangler/src/__tests__/helpers/mock-bin.ts 100.00% <0.00%> (+5.26%) ⬆️

@CarmenPopoviciu CarmenPopoviciu force-pushed the pages-dev-prioritize-worker-over-fns branch 2 times, most recently from 637cd3d to 23a294e Compare September 28, 2022 16:48
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM


if (url.pathname.startsWith("/date")) {
return new Response(
"Yesterday is history, tomorrow is a mystery, but today is a gift. That’s why it is called the present."
Copy link
Contributor

Choose a reason for hiding this comment

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

🙇

};

await runBuild();
watch([scriptPath], {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this watch only get cancelled if you kill the process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@petebacondarwin that is correct. In fact that is true for all our watchers. I am rather new to watch and esbuild so my reasoning might be wrong, but the way I see it is that we want to keep watching these files (_worker.js, /functions/* and _routes.json) for changes for as long as the process is running, so we can serve the right assets.
Is there a use case you had in mind that would require us to close the watcher? Or what was the underlying concern of your question?

Copy link
Contributor

Choose a reason for hiding this comment

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

My only thought was whether esbuild kicks off a child process that might somehow get orphaned if we closed down the process in some other way than killing it? But I think that is probably not the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

according to evanw/esbuild#643 this 👉 https://github.com/evanw/esbuild/blob/master/cmd/esbuild/service.go#L124-L137 should prevent something like that from happening. So I think we should be OK

When using a _worker.js file, the entire /functions directory should be
ignored – this includes its routing and middleware characteristics.
Currently `wrangler pages dev` does the reverse, by prioritizing
`/functions` over `_worker.js`. This commit fixes that.
@CarmenPopoviciu CarmenPopoviciu force-pushed the pages-dev-prioritize-worker-over-fns branch from 23a294e to 3c0efbf Compare October 4, 2022 10:54
@CarmenPopoviciu CarmenPopoviciu merged commit daf73fb into main Oct 4, 2022
@CarmenPopoviciu CarmenPopoviciu deleted the pages-dev-prioritize-worker-over-fns branch October 4, 2022 11:31
@github-actions github-actions bot mentioned this pull request Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants