[feat] use Netlify internal functions directory for generated functions#2113
[feat] use Netlify internal functions directory for generated functions#2113benmccann merged 8 commits intosveltejs:masterfrom
Conversation
🦋 Changeset detectedLatest commit: 12e3766 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
5785580 to
7ecb000
Compare
| [build] | ||
| command = "npm run build" | ||
| publish = "build/publish/" | ||
| functions = "build/functions/" |
There was a problem hiding this comment.
I don't know if we can just remove this. Where will it put functions then? We put this here on purpose so that all output would show up under build and be automatically gitignored without the user having to edit their .gitignore at all. It would be nice if that continued to work for people who are not using the Netlify CLI
There was a problem hiding this comment.
Or at least if we're going to remove this line, should we also remove the publish line so that ends up under .netlify/publish or something? It seems weird to treat these inconsistently.
Perhaps what we could do is maintain the old behavior and use the directories in these files if they are present and if they are not then we use the directory you're specifying as a default
There was a problem hiding this comment.
The functions will be in .netlify/functions-internal. The functions directory isn't needed anymore, because we're using the internal functions directory instead, which is hard-coded. The idea is that the functions value is for user functions, while .netlify/functions-internal is for auto-generated functions. If we remove the publish dir it will default to static because that's the value specified for SvelteKit. Should that be changed?
There was a problem hiding this comment.
If they user isn't using the Netlify CLI then presumably this won't be an issue anyway, as it wouldn't be using the Netlify preset when building locally as the auto-detection won't trigger it.
There was a problem hiding this comment.
Though I suppose the user could have manually specified the preset.
There was a problem hiding this comment.
Ok, thanks for clarifying and being patient as I come up-to-speed on Netlify stuff. I'm on board with your plan. Lets always output to .netlify/functions-internal
There was a problem hiding this comment.
OK, so skip the CLI detection entirely?
There was a problem hiding this comment.
What would be the benefit of CLI detection? If we're not using the Netlify CLI, I'm assuming that any code .netlify/functions-internal will still be used?
There was a problem hiding this comment.
Correct. I'll update the PR.
There was a problem hiding this comment.
OK, I've updated the PR as follows:
- Always write out the generated functions to
.netlify/functions-internal - Read
"publish"fromnetlify.toml, but if it's missing then default to"build" - Add more warnings and checks, such as ensuring that publish isn't set to the site root (that would delete the site!)
- Updated the README
One thing I'd like to suggest for a follow-up PR is that cwd is passed to adapter functions here. That would allow us to ensure that we resolve all the paths correctly inside adapters. I may be misunderstanding it as I've not tested it, but as it stands I'm not sure if these will all work if cwd isn't process.cwd() This would likely apply to most adapters, as they all seem to assume paths are relative to process.cwd().
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
35688e2 to
a8863d0
Compare
a8863d0 to
b10fcb9
Compare
|
The build is failing because the netlify.toml in the template has been updated to the new format, but the package hasn't. |
|
Thanks for this! Appreciate your knowledge of the Netlify internals and explaining it all to me |
Description
This changes the location of generated Netlify render function to the internal functions directory (
.netlify/functions-internal), rather than using the user functions directory. This means the user can use the normal functions directory for their own Netlify functions without them being deleted at build time.Fixes #1249
Before submitting the PR, please make sure you do the following
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpx changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0