-
-
Notifications
You must be signed in to change notification settings - Fork 52
Update netlify adapter to integrate includeFiles and excludeFiles options #515
Conversation
🦋 Changeset detectedLatest commit: 5557cc0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
It doesn't seem you added new assertions, and you didn't test the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a new changeset?
I have an old PR that does the same, but it also included changing the cwd at runtime, which in retropect should have been separate – and proved to be controversial – which is why I never merged it. Mine has now become outdated and conflicted, so having a new PR like this makes sense to me, but you might want to look at my PR to get some tests and changeset ideas. |
Thanks @ascorbic for the PR was very useful ✨ After taking a look to #325 I have made the following changes:
|
.changeset/beige-insects-hang.md
Outdated
|
||
The `includedFiles` and `excludedFiles` options allow you specify these inclusions and exclusions as an array of file paths relative to the site root. Both options support glob patterns, so you can include/exclude multiple files at once. | ||
|
||
If you are specifying files using filesystem functions, resolve the path using `path.resolve()` or `process.cwd()`, which will give you the site root. At runtime, compiled source files will be in a different location and you cannot rely on relative file paths. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will work in this PR, because it doesn't do chdir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't speak to the tech, but will note:
- this feels a bit too detailed for a changelog
- if someone needs an explanation like this to use the feature, it must be in docs itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelogs update -> 5557cc0
|
||
export default defineConfig({ | ||
vite: { | ||
assetsInclude: process.env.VITE_ASSETS_INCLUDE?.split(',') || [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than juggling env vars you can pass the actual config to loadFixture
in each test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍🏽 -> 63ce3bb
process.env.VITE_ASSETS_INCLUDE = expectedAssetsInclude.join(); | ||
fixture = await loadFixture({ root }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the config to loadFixture
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some tiny comments on the changeset, and info that seems to be in this PR that did not make it into docs!
.changeset/beige-insects-hang.md
Outdated
|
||
Adds `includedFiles` and `excludedFiles` configuration options. These allow extra files to be deployed in the SSR function bundle. | ||
|
||
When an Astro site using `server` or `hybrid` rendering is deployed to Netlify, the generated functions trace the server dependencies and include any that may be needed in SSR. However, sometimes you may want to include extra files that are not detected as dependencies, such as files that are loaded using `fs` functions. Also, you may sometimes want to specifically exclude dependencies that are bundled automatically. For example, you may have a Node module that includes a large binary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an Astro site using `server` or `hybrid` rendering is deployed to Netlify, the generated functions trace the server dependencies and include any that may be needed in SSR. However, sometimes you may want to include extra files that are not detected as dependencies, such as files that are loaded using `fs` functions. Also, you may sometimes want to specifically exclude dependencies that are bundled automatically. For example, you may have a Node module that includes a large binary. | |
When an Astro site using on-demand rendering is deployed to Netlify, the generated functions trace the server dependencies and include any that may be needed in SSR. However, sometimes you may want to include extra files that are not detected as dependencies, such as files that are loaded using `fs` functions. Also, you may sometimes want to specifically exclude dependencies that are bundled automatically. For example, you may have a Node module that includes a large binary. |
Noting that hybrid
does not exist as a "code" word anymore (and, I'm not sure we use it casually?)
.changeset/beige-insects-hang.md
Outdated
|
||
When an Astro site using `server` or `hybrid` rendering is deployed to Netlify, the generated functions trace the server dependencies and include any that may be needed in SSR. However, sometimes you may want to include extra files that are not detected as dependencies, such as files that are loaded using `fs` functions. Also, you may sometimes want to specifically exclude dependencies that are bundled automatically. For example, you may have a Node module that includes a large binary. | ||
|
||
The `includedFiles` and `excludedFiles` options allow you specify these inclusions and exclusions as an array of file paths relative to the site root. Both options support glob patterns, so you can include/exclude multiple files at once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a note (in the Docs PR) that this content did not make it into the docs PR, but should!
.changeset/beige-insects-hang.md
Outdated
|
||
The `includedFiles` and `excludedFiles` options allow you specify these inclusions and exclusions as an array of file paths relative to the site root. Both options support glob patterns, so you can include/exclude multiple files at once. | ||
|
||
If you are specifying files using filesystem functions, resolve the path using `path.resolve()` or `process.cwd()`, which will give you the site root. At runtime, compiled source files will be in a different location and you cannot rely on relative file paths. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't speak to the tech, but will note:
- this feels a bit too detailed for a changelog
- if someone needs an explanation like this to use the feature, it must be in docs itself
@ascorbic I've made the requested changes to the tests, and as @sarah11918 requested, I've updated the changelog and made some updates to the docs as well. 👍🏽 Let me know if you need anything else! Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not really confident about this feature because I don't know the code. I let @ascorbic doing th review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changeset is good! It could merge exactly like this, but I could even see adding a code example that shows both new properties configured (I'd maybe include one file, to show that it's still an array even if you only have one item, and then exclude two or three files, and/or a glob pattern?), but I'd usually make final recommendations when the feature is ready to be merged and the docs are done.
I can see that this feature still needs a code review/approval, so I won't super edit the corresponding docs just yet, but can confirm they're in good draft shape and I should have all that I need to whip those up if this feature is being accepted! (I do like to wait until it's pretty clear nothing more will change before doing a final polish to the documentation, just in case!)
So please ping me when this is close to being released, and I'll come in for a final swoop on both this and docs then! It won't take much! 🫡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Once this is in, you might want to think about your proposal for exposing the fucntion root dir at runtime. If we were to do it, it would make sense to do the same for Vercel.
Hi, we moved the netlify adapter in a new repository: https://github.com/withastro/astro/tree/main/packages/integrations/netlify We will achieve this repository soon, so if you wish to land this PR, you'll have to create a new one. |
@dfdez sorry we didn't get this in before the move. It should be fine to redo it as-is on the main repo, aside from the slightly changed base path |
No worries! I'll redo it on the main repo 👍🏽 |
Changes
When trying Netlify SSR with Astro, I wasn't able to get the
included_files
option to work. After investigating, I realized that theincludeFiles
andexcludeFiles
functionalities, similar to what Vercel provides, were necessary to include additional files during the build process.In this PR, I have implemented the integration to add these options:
includeFiles
andexcludeFiles
options to the integration, mirroring Vercel's functionality.includeFiles
: Allows users to explicitly specify files or directories to be bundled with their function. Useful for avoiding missing files in production.excludeFiles
: Enables users to specify files or directories to be excluded from the deployment. Helps minimize bundle size.Testing
includeFiles
andexcludeFiles
with various configurations to ensure:includeFiles
are bundled correctly.excludeFiles
are omitted as expected.Docs
includeFiles
andexcludeFiles
on netlify adapter.