mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
* fix: include route prefix in vercel func names * chore: add changeset * chore: update pnpm lockfile * refactor: simplify logic that generates vercel func names * fix: properly remove entryFile prefix from func name * refactor: change how vercel function names are generated --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
parent
61ad70fdc5
commit
9ffa1a84e8
10 changed files with 104 additions and 6 deletions
5
.changeset/modern-guests-float.md
Normal file
5
.changeset/modern-guests-float.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/vercel': patch
|
||||
---
|
||||
|
||||
Fix serverless function naming conflicts for routes with identical filenames but different directory structures
|
|
@ -207,14 +207,25 @@ You can set functionPerRoute: false to prevent surpassing the limit.`
|
|||
|
||||
// Multiple entrypoint support
|
||||
if (_entryPoints.size) {
|
||||
for (const [route, entryFile] of _entryPoints) {
|
||||
const func = basename(entryFile.toString()).replace(/\.mjs$/, '');
|
||||
const getRouteFuncName = (route: RouteData) =>
|
||||
route.component.replace('src/pages/', '')
|
||||
|
||||
const getFallbackFuncName = (entryFile: URL) =>
|
||||
basename(entryFile.toString())
|
||||
.replace('entry.', '')
|
||||
.replace(/\.mjs$/, '');
|
||||
|
||||
for (const [route, entryFile] of _entryPoints) {
|
||||
const func = route.component.startsWith('src/pages/')
|
||||
? getRouteFuncName(route)
|
||||
: getFallbackFuncName(entryFile)
|
||||
|
||||
await createFunctionFolder(func, entryFile, filesToInclude, logger);
|
||||
routeDefinitions.push({
|
||||
src: route.pattern.source,
|
||||
dest: func,
|
||||
});
|
||||
}
|
||||
src: route.pattern.source,
|
||||
dest: func,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await createFunctionFolder(
|
||||
'render',
|
||||
|
|
10
packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs
vendored
Normal file
10
packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import vercel from '@astrojs/vercel/serverless';
|
||||
|
||||
export default defineConfig({
|
||||
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-with-dynamic-routes/included.js
vendored
Normal file
1
packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/included.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
'works'
|
9
packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/package.json
vendored
Normal file
9
packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/astro-vercel-serverless-with-dynamic-routes",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/vercel": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
export const prerender = false;
|
||||
---
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>testing {Astro.params.id}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>testing {Astro.params.id}</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,7 @@
|
|||
export const prerender = false;
|
||||
|
||||
export async function GET({ params }) {
|
||||
return Response.json({
|
||||
id: params.id
|
||||
});
|
||||
}
|
12
packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/index.astro
vendored
Normal file
12
packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
export const prerender = import.meta.env.PRERENDER;
|
||||
---
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>testing</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,22 @@
|
|||
import { expect } from 'chai';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
describe('Serverless with dynamic routes', () => {
|
||||
/** @type {import('./test-utils.js').Fixture} */
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
process.env.PRERENDER = true;
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/serverless-with-dynamic-routes/',
|
||||
output: 'hybrid',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('build successful', async () => {
|
||||
expect(await fixture.readFile('../.vercel/output/static/index.html')).to.be.ok;
|
||||
expect(await fixture.readFile('../.vercel/output/functions/[id]/index.astro.func/.vc-config.json')).to.be.ok;
|
||||
expect(await fixture.readFile('../.vercel/output/functions/api/[id].js.func/.vc-config.json')).to.be.ok;
|
||||
});
|
||||
});
|
|
@ -4812,6 +4812,15 @@ importers:
|
|||
specifier: workspace:*
|
||||
version: link:../../../../../astro
|
||||
|
||||
packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes:
|
||||
dependencies:
|
||||
'@astrojs/vercel':
|
||||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
astro:
|
||||
specifier: workspace:*
|
||||
version: link:../../../../../astro
|
||||
|
||||
packages/integrations/vercel/test/fixtures/static-assets:
|
||||
dependencies:
|
||||
'@astrojs/vercel':
|
||||
|
|
Loading…
Reference in a new issue