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

Update netlify adapter to integrate includeFiles and excludeFiles options #13194

Merged
merged 9 commits into from
Feb 12, 2025

Conversation

dfdez
Copy link
Contributor

@dfdez dfdez commented Feb 7, 2025

This PR implements the changes previously proposed in withastro/adapters#515, migrated to work within this repository's structure. The core functionality remains the same, with adjustments made to align with this repository.

Changes

When trying Netlify SSR with Astro, I wasn't able to get the included_files option to work. After investigating, I realized that the includeFiles and excludeFiles 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:

  • Added includeFiles and excludeFiles 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.
  • All code for these features has been adapted directly from Vercel's integration for consistency and reliability.

Testing

  • Manually tested includeFiles and excludeFiles with various configurations to ensure:
    • Files specified in includeFiles are bundled correctly.
    • Files and directories specified in excludeFiles are omitted as expected.
  • Automated tests added to validate edge cases and typical usage scenarios.
  • Confirmed the implementation behaves identically to Vercel's integration.

Docs

  • Updated astro docs with documentation for includeFiles and excludeFiles on netlify adapter.
  • Added links to Vercel's documentation for further reference:

Copy link

changeset-bot bot commented Feb 7, 2025

🦋 Changeset detected

Latest commit: 194a27b

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

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 github-actions bot added the pkg: integration Related to any renderer integration (scope) label Feb 7, 2025
@dfdez dfdez force-pushed the feat/netlify-include-files branch from 7d6936e to a1bcac7 Compare February 8, 2025 16:48
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you! I left some questions, and also we should make the docs a bit more explicit because there's some important information that we should expose to users.

packages/integrations/netlify/src/index.ts Outdated Show resolved Hide resolved
packages/integrations/netlify/src/index.ts Outdated Show resolved Hide resolved
packages/integrations/netlify/src/index.ts Outdated Show resolved Hide resolved
if (_config.vite.assetsInclude) {
const mergeGlobbedIncludes = (globPattern: unknown) => {
if (typeof globPattern === 'string') {
const entries = glob.sync(globPattern).map((p) => pathToFileURL(p));
Copy link
Member

Choose a reason for hiding this comment

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

Two questions:

  • Why aren't these assets resolved from the same cwd of line 263?
  • Why don't we ignore exclude?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Why aren't these assets resolved from the same cwd of line 263?

That is a good question; this code were taken from the vercel integration not sure why that difference does currently exists...

Maybe it does have sense to update this and use the getFilesByGlob function to have the same behavior on either includeFiles and vite.assetsInclude.

  • Why don't we ignore exclude?

Similar to previous response; this code were taken from the vercel integration but I think there isn't any specific reason to don't exclude the files therefore we can add it.

I just wanted to keep the most consistency between integration, for those reasons I decided to keep this code as is. Let me know if any modifications are needed, and I'll gladly update it 👌

Copy link
Member

Choose a reason for hiding this comment

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

It looks like the code is been there for a long time, let's keep it as is. Thank you for taking time for investigating and providing me with a proper response!

Copy link
Contributor

Choose a reason for hiding this comment

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

While the Vercel code has been there for a long time, this is new code for Netlify, so I think it would make sense to make it consistent with the cwd at least

includeFiles?: string[];

/** Exclude any files from the bundling process that would otherwise be included. */
excludeFiles?: string[];
Copy link
Member

@ematipico ematipico Feb 10, 2025

Choose a reason for hiding this comment

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

There's an important piece of information that is missing from the inline JS docs. The code resolves the files from the rootDir. This information must be shared with the docs. This information is also missing from the docs PR (I checked).

What does that mean? If a user adds an absolute path, this might fail. We should provide this information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a note on the JS Docs 93c2acf#diff-c395613459736f27ff2bafd942481c8713261bd79538e1234994f9d3d4d0be5bR148

Also I will make sure to update the docs to add this important information 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add it to the excludeFiles block too

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Looks good to me!

packages/integrations/netlify/src/index.ts Outdated Show resolved Hide resolved
if (_config.vite.assetsInclude) {
const mergeGlobbedIncludes = (globPattern: unknown) => {
if (typeof globPattern === 'string') {
const entries = glob.sync(globPattern).map((p) => pathToFileURL(p));
Copy link
Member

Choose a reason for hiding this comment

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

It looks like the code is been there for a long time, let's keep it as is. Thank you for taking time for investigating and providing me with a proper response!

@ematipico ematipico added this to the 5.3.0 milestone Feb 11, 2025
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Just left an idea of a sample changeset, for your consideration!

.changeset/ninety-clouds-judge.md Outdated Show resolved Hide resolved
@ematipico ematipico merged commit 1b5037b into withastro:main Feb 12, 2025
15 checks passed
This was referenced Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants