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

Fix vercel build error when passing includeFiles #7677

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-baboons-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Fix build error when passing `includeFiles`
10 changes: 6 additions & 4 deletions packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export default function vercelServerless({
let buildTempFolder: URL;
let serverEntry: string;
let _entryPoints: Map<RouteData, URL>;
// Extra files to be merged with `includeFiles` during build
const extraFilesToInclude: URL[] = [];

async function createFunctionFolder(funcName: string, entry: URL, inc: URL[]) {
const functionFolder = new URL(`./functions/${funcName}.func/`, _config.outDir);
Expand Down Expand Up @@ -74,8 +76,6 @@ export default function vercelServerless({
});
}

const filesToInclude = includeFiles?.map((file) => new URL(file, _config.root)) || [];

return {
name: PACKAGE_NAME,
hooks: {
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function vercelServerless({
vercelEdgeMiddlewareHandlerPath
);
// let's tell the adapter that we need to save this file
filesToInclude.push(bundledMiddlewarePath);
extraFilesToInclude.push(bundledMiddlewarePath);
}
},

Expand All @@ -140,7 +140,7 @@ export default function vercelServerless({
const mergeGlobbedIncludes = (globPattern: unknown) => {
if (typeof globPattern === 'string') {
const entries = glob.sync(globPattern).map((p) => pathToFileURL(p));
filesToInclude.push(...entries);
extraFilesToInclude.push(...entries);
} else if (Array.isArray(globPattern)) {
for (const pattern of globPattern) {
mergeGlobbedIncludes(pattern);
Expand All @@ -152,6 +152,8 @@ export default function vercelServerless({
}

const routeDefinitions: { src: string; dest: string }[] = [];
const filesToInclude = includeFiles?.map((file) => new URL(file, _config.root)) || [];
filesToInclude.push(...extraFilesToInclude);

// Multiple entrypoint support
if (_entryPoints.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';

export default defineConfig({
adapter: vercel(),
adapter: vercel({
// Pass some value to make sure it doesn't error out
includeFiles: ['package.json']
}),
bluwy marked this conversation as resolved.
Show resolved Hide resolved
output: 'server'
});