Skip to content

Commit

Permalink
fix(vercel): Include all files inside dist/ instead of only `entry.…
Browse files Browse the repository at this point in the history
…mjs`
  • Loading branch information
JuanM04 committed Oct 23, 2022
1 parent bf5ad72 commit 8c3b235
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
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

0 comments on commit 8c3b235

Please sign in to comment.