Clarify documentation on Cloudflare Pages Functions file structure

Hi!

We’re currently setting up a CF Pages Function, and in the processing of that were struck because it wasn’t being picked up (neither by the wrangler pages dev nor by the wrangler pages deploy command).
I have now realized what has gone wrong. I have roughly the following folder structure:

.
└── cf_pages_project/
    ├── src/
    │   └── some_build_script.js
    └── dist/
        ├── functions/
        │   └── helloworld.js
        └── some_static_asset.html

Now, while I was in the directory cf_pages_project, I ran npx wrangler pages dev dist.
That picked up the static assets inside dist, but didn’t pick up the functions folder contained in dist.
When I instead run cd dist && npx wrangler pages dev ., all works as expected and the functions are actually being picked up.

However, I did not find any mention of this in the Cloudflare Functions docs.
It’s also a bit baffling because from what I can tell, this is the only feature in wrangler that can only be controlled using the current working directory.

There are several ways how this could be improved:

  • Mention this in the documentation!
  • Print a warning when a functions directory has been found in the “wrong” directory, and let the user know that it won’t be picked up.
  • Discover functions directories in both the cwd and in the target folder.
  • Add an option to wrangler for the path to the functions directory.

Thank you for the consideration,
Marcel

The documentation says

To get started with generating a Pages Function, create a /functions directory at the root of your Pages project.
source

In other words

.
└── cf_pages_project/
    ├── functions/
    │   └── helloworld.js
    ├── src/
    │   └── some_build_script.js
    └── dist/
        └── some_static_asset.html

Might also want to put the build script in the root of the project not inside a subdirectory.