-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update netlify adapter to integrate includeFiles and excludeFiles opt…
…ions (#13194) * feat: integrated includeFiles and excludeFiles on netlify adapter * feat: added netlify include and exclude files tests * feat: changelogs added * fix: avoid problems with glob file url on windows * feat: improved JS Docs to include examples and important information * feat: removed non necessary root path as glob is already absolute * Apply suggestions from code review * Update packages/integrations/netlify/src/index.ts Co-authored-by: Matt Kane <[email protected]> * Update .changeset/ninety-clouds-judge.md Co-authored-by: Sarah Rainsberger <[email protected]> --------- Co-authored-by: Emanuele Stoppa <[email protected]> Co-authored-by: Matt Kane <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]>
- Loading branch information
1 parent
b019150
commit 1b5037b
Showing
15 changed files
with
487 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
'@astrojs/netlify': minor | ||
--- | ||
|
||
Adds `includedFiles` and `excludedFiles` configuration options to customize SSR function bundle contents. | ||
|
||
|
||
The `includeFiles` property allows you to explicitly specify additional files that should be bundled with your function. This is useful for files that aren't automatically detected as dependencies, such as: | ||
- Data files loaded using `fs` operations | ||
- Configuration files | ||
- Template files | ||
|
||
Similarly, you can use the `excludeFiles` property to prevent specific files from being bundled that would otherwise be included. This is helpful for: | ||
- Reducing bundle size | ||
- Excluding large binaries | ||
- Preventing unwanted files from being deployed | ||
|
||
```js | ||
import { defineConfig } from 'astro/config'; | ||
import netlify from '@astrojs/netlify'; | ||
|
||
export default defineConfig({ | ||
// ... | ||
output: 'server', | ||
adapter: netlify({ | ||
includeFiles: ['./my-data.json'], | ||
excludeFiles: [ | ||
'./node_modules/package/**/*', | ||
'./src/**/*.test.js' | ||
], | ||
}), | ||
}); | ||
``` | ||
|
||
See the [Netlify adapter documentation](https://docs.astro.build/en/guides/integrations-guide/netlify/#including-or-excluding-files) for detailed usage instructions and examples. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/integrations/netlify/test/functions/fixtures/includes/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import netlify from '@astrojs/netlify'; | ||
import { defineConfig } from 'astro/config'; | ||
|
||
export default defineConfig({ | ||
output: 'server', | ||
adapter: netlify(), | ||
site: "http://example.com", | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/integrations/netlify/test/functions/fixtures/includes/files/also-this.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1,2,3 |
1 change: 1 addition & 0 deletions
1
packages/integrations/netlify/test/functions/fixtures/includes/files/exclude-asset.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
packages/integrations/netlify/test/functions/fixtures/includes/files/include-asset.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
packages/integrations/netlify/test/functions/fixtures/includes/files/include-this.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello |
1 change: 1 addition & 0 deletions
1
...ges/integrations/netlify/test/functions/fixtures/includes/files/subdirectory/and-this.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1,2,3 |
1 change: 1 addition & 0 deletions
1
...ges/integrations/netlify/test/functions/fixtures/includes/files/subdirectory/not-this.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1,2,3 |
1 change: 1 addition & 0 deletions
1
...ages/integrations/netlify/test/functions/fixtures/includes/files/subdirectory/or-this.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello |
9 changes: 9 additions & 0 deletions
9
packages/integrations/netlify/test/functions/fixtures/includes/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/netlify-includes", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/netlify": "workspace:", | ||
"cowsay": "1.6.0" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/integrations/netlify/test/functions/fixtures/includes/src/pages/404.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
export const prerender = false | ||
const header = Astro.request.headers.get("x-test") | ||
--- | ||
|
||
<p>This is my custom 404 page</p> | ||
<p>x-test: {header}</p> |
27 changes: 27 additions & 0 deletions
27
packages/integrations/netlify/test/functions/fixtures/includes/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
import { promises as fs } from 'fs'; | ||
import { fileURLToPath } from 'url'; | ||
import { dirname, join } from 'path'; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
const loadFile = Astro.url.searchParams.get('file'); | ||
const file = await fs.readFile(join(__dirname, `../../../files/${loadFile}`), 'utf-8'); | ||
async function moo() { | ||
const cow = await import('cowsay'); | ||
return cow.say({ text: 'Moo!' }); | ||
} | ||
if (Astro.url.searchParams.get('moo')) { | ||
await moo(); | ||
} | ||
--- | ||
<html> | ||
<head><title>Testing</title></head> | ||
<body> | ||
{loadFile && <h1>{file}</h1>} | ||
</body> | ||
</html> |
Oops, something went wrong.