Fix vercel build error when passing includeFiles
(#7677)
This commit is contained in:
parent
1a6f833c40
commit
1f0d0b5863
5 changed files with 26 additions and 7 deletions
5
.changeset/six-baboons-allow.md
Normal file
5
.changeset/six-baboons-allow.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/vercel': patch
|
||||
---
|
||||
|
||||
Fix build error when passing `includeFiles`
|
|
@ -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);
|
||||
|
@ -74,8 +76,6 @@ export default function vercelServerless({
|
|||
});
|
||||
}
|
||||
|
||||
const filesToInclude = includeFiles?.map((file) => new URL(file, _config.root)) || [];
|
||||
|
||||
return {
|
||||
name: PACKAGE_NAME,
|
||||
hooks: {
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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: ['included.js']
|
||||
}),
|
||||
output: 'server'
|
||||
});
|
||||
|
|
1
packages/integrations/vercel/test/fixtures/serverless-prerender/included.js
vendored
Normal file
1
packages/integrations/vercel/test/fixtures/serverless-prerender/included.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
'works'
|
|
@ -10,12 +10,20 @@ describe('Serverless prerender', () => {
|
|||
fixture = await loadFixture({
|
||||
root: './fixtures/serverless-prerender/',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('build successful', async () => {
|
||||
await fixture.build();
|
||||
expect(await fixture.readFile('../.vercel/output/static/index.html')).to.be.ok;
|
||||
});
|
||||
|
||||
it('includeFiles work', async () => {
|
||||
expect(
|
||||
await fixture.readFile(
|
||||
'../.vercel/output/functions/render.func/packages/integrations/vercel/test/fixtures/serverless-prerender/included.js'
|
||||
)
|
||||
).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Serverless hybrid rendering', () => {
|
||||
|
@ -28,10 +36,10 @@ describe('Serverless hybrid rendering', () => {
|
|||
root: './fixtures/serverless-prerender/',
|
||||
output: 'hybrid',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('build successful', async () => {
|
||||
await fixture.build();
|
||||
expect(await fixture.readFile('../.vercel/output/static/index.html')).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue