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): Include all files inside dist/ instead of only entry.mjs #5175

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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/nine-roses-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Edge adapter includes all the generated files (all files inside `dist/`) instead of only `entry.mjs`
14 changes: 9 additions & 5 deletions packages/integrations/vercel/src/edge/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro';
import { relative as relativePath } from 'node:path';
import { fileURLToPath } from 'node:url';

import { copyFilesToFunction, getVercelOutput, removeDir, writeJson } from '../lib/fs.js';
import {
copyFilesToFunction,
getFilesFromFolder,
getVercelOutput,
removeDir,
writeJson,
} from '../lib/fs.js';
import { getRedirects } from '../lib/redirects.js';

const PACKAGE_NAME = '@astrojs/vercel/edge';
Expand Down Expand Up @@ -88,13 +94,11 @@ export default function vercelEdge({ includeFiles = [] }: VercelEdgeConfig = {})
},
'astro:build:done': async ({ routes }) => {
const entry = new URL(serverEntry, buildTempFolder);
const generatedFiles = await getFilesFromFolder(buildTempFolder);

// Copy entry and other server files
const commonAncestor = await copyFilesToFunction(
[
new URL(serverEntry, buildTempFolder),
...includeFiles.map((file) => new URL(file, _config.root)),
],
[...generatedFiles, ...includeFiles.map((file) => new URL(file, _config.root))],
functionFolder
);

Expand Down
14 changes: 14 additions & 0 deletions packages/integrations/vercel/src/lib/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ export async function emptyDir(dir: PathLike): Promise<void> {
await fs.mkdir(dir, { recursive: true });
}

export async function getFilesFromFolder(dir: URL) {
const data = await fs.readdir(dir, { withFileTypes: true });
let files: URL[] = [];
for (const item of data) {
if (item.isDirectory()) {
const moreFiles = await getFilesFromFolder(new URL(`./${item.name}/`, dir));
files = files.concat(moreFiles);
} else {
files.push(new URL(`./${item.name}`, dir));
}
}
return files;
}

export const getVercelOutput = (root: URL) => new URL('./.vercel/output/', root);

/**
Expand Down