fix(vercel): Include all files inside dist/ instead of only entry.mjs (#5175)

This commit is contained in:
Juan Martín Seery 2022-10-24 11:24:52 -03:00 committed by GitHub
parent 7e430a3dc9
commit abf41da774
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---
Edge adapter includes all the generated files (all files inside `dist/`) instead of only `entry.mjs`

View file

@ -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';
@ -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
);

View file

@ -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);
/**