fix(vercel): Include all files inside dist/
instead of only entry.mjs
(#5175)
This commit is contained in:
parent
7e430a3dc9
commit
abf41da774
3 changed files with 28 additions and 5 deletions
5
.changeset/nine-roses-explain.md
Normal file
5
.changeset/nine-roses-explain.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/vercel': patch
|
||||
---
|
||||
|
||||
Edge adapter includes all the generated files (all files inside `dist/`) instead of only `entry.mjs`
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue