Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored and astrobot-houston committed Oct 23, 2023
1 parent b209e53 commit e4ba501
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/integrations/vercel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export default defineConfig({
**Type:** `number`<br>
**Available for:** Serverless
Use this property to extend or limit the maximum duration (in seconds) that Serverless Functions can run before timing out. See the [Vercel documentation](https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration) for the default and maximum limit for your account plan.
Use this property to extend or limit the maximum duration (in seconds) that Serverless Functions can run before timing out. See the [Vercel documentation](https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration) for the default and maximum limit for your account plan.
```diff lang="js"
// astro.config.mjs
Expand Down
32 changes: 17 additions & 15 deletions packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface VercelServerlessConfig {

/** Whether to create the Vercel Edge middleware from an Astro middleware in your code base. */
edgeMiddleware?: boolean;

/** Whether to split builds into a separate function for each route. */
functionPerRoute?: boolean;

Expand All @@ -120,7 +120,6 @@ export default function vercelServerless({
edgeMiddleware = false,
maxDuration,
}: VercelServerlessConfig = {}): AstroIntegration {

if (maxDuration) {
if (typeof maxDuration !== 'number') {
throw new TypeError(`maxDuration must be a number`, { cause: maxDuration });
Expand All @@ -143,10 +142,13 @@ export default function vercelServerless({
name: PACKAGE_NAME,
hooks: {
'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => {

if (maxDuration && maxDuration > 900) {
logger.warn(`maxDuration is set to ${maxDuration} seconds, which is longer than the maximum allowed duration of 900 seconds.`)
logger.warn(`Please make sure that your plan allows for this duration. See https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration for more information.`)
logger.warn(
`maxDuration is set to ${maxDuration} seconds, which is longer than the maximum allowed duration of 900 seconds.`
);
logger.warn(
`Please make sure that your plan allows for this duration. See https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration for more information.`
);
}

if (webAnalytics?.enabled || analytics) {
Expand Down Expand Up @@ -272,7 +274,7 @@ You can set functionPerRoute: false to prevent surpassing the limit.`
NTF_CACHE,
includeFiles: filesToInclude,
excludeFiles,
maxDuration
maxDuration,
});
routeDefinitions.push({
src: route.pattern.source,
Expand All @@ -288,7 +290,7 @@ You can set functionPerRoute: false to prevent surpassing the limit.`
NTF_CACHE,
includeFiles: filesToInclude,
excludeFiles,
maxDuration
maxDuration,
});
routeDefinitions.push({ src: '/.*', dest: 'render' });
}
Expand Down Expand Up @@ -331,14 +333,14 @@ You can set functionPerRoute: false to prevent surpassing the limit.`
}

interface CreateFunctionFolderArgs {
functionName: string
entry: URL
config: AstroConfig
logger: AstroIntegrationLogger
NTF_CACHE: any
includeFiles: URL[]
excludeFiles?: string[]
maxDuration?: number
functionName: string;
entry: URL;
config: AstroConfig;
logger: AstroIntegrationLogger;
NTF_CACHE: any;
includeFiles: URL[];
excludeFiles?: string[];
maxDuration?: number;
}

async function createFunctionFolder({
Expand Down
26 changes: 14 additions & 12 deletions packages/integrations/vercel/test/max-duration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import { loadFixture } from './test-utils.js';
import { expect } from 'chai';

describe('maxDuration', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
/** @type {import('./test-utils.js').Fixture} */
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/max-duration/',
});
await fixture.build();
});
before(async () => {
fixture = await loadFixture({
root: './fixtures/max-duration/',
});
await fixture.build();
});

it('makes it to vercel function configuration', async () => {
const vcConfig = JSON.parse(await fixture.readFile('../.vercel/output/functions/render.func/.vc-config.json'));
expect(vcConfig).to.deep.include({ maxDuration: 60 });
});
it('makes it to vercel function configuration', async () => {
const vcConfig = JSON.parse(
await fixture.readFile('../.vercel/output/functions/render.func/.vc-config.json')
);
expect(vcConfig).to.deep.include({ maxDuration: 60 });
});
});

0 comments on commit e4ba501

Please sign in to comment.