Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Jun 29, 2023
1 parent 154af8f commit 7ae6e89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/integrations/vercel/README.md
Expand Up @@ -228,8 +228,8 @@ export default defineConfig({
output: 'server',
adapter: vercel(),
build: {
split: true
}
split: true,
},
});
```

Expand Down
14 changes: 5 additions & 9 deletions packages/integrations/vercel/src/serverless/adapter.ts
@@ -1,6 +1,7 @@
import type { AstroAdapter, AstroConfig, AstroIntegration, RouteData } from 'astro';

import glob from 'fast-glob';
import { basename } from 'node:path';
import { pathToFileURL } from 'url';
import {
defaultImageConfig,
Expand All @@ -12,7 +13,6 @@ import { exposeEnv } from '../lib/env.js';
import { getVercelOutput, removeDir, writeJson } from '../lib/fs.js';
import { copyDependenciesToFunction } from '../lib/nft.js';
import { getRedirects } from '../lib/redirects.js';
import { basename } from 'node:path';

const PACKAGE_NAME = '@astrojs/vercel/serverless';

Expand Down Expand Up @@ -130,13 +130,13 @@ export default function vercelServerless({
const routeDefinitions: { src: string; dest: string }[] = [];

// Multiple entrypoint support
if(_entryPoints.size) {
for(const [route, entryFile] of _entryPoints) {
if (_entryPoints.size) {
for (const [route, entryFile] of _entryPoints) {
const func = basename(entryFile.toString()).replace(/\.mjs$/, '');
await createFunctionFolder(func, entryFile, inc);
routeDefinitions.push({
src: route.pattern.source,
dest: func
dest: func,
});
}
} else {
Expand All @@ -148,11 +148,7 @@ export default function vercelServerless({
// https://vercel.com/docs/build-output-api/v3#build-output-configuration
await writeJson(new URL(`./config.json`, _config.outDir), {
version: 3,
routes: [
...getRedirects(routes, _config),
{ handle: 'filesystem' },
...routeDefinitions
],
routes: [...getRedirects(routes, _config), { handle: 'filesystem' }, ...routeDefinitions],
...(imageService || imagesConfig
? { images: imagesConfig ? imagesConfig : defaultImageConfig }
: {}),
Expand Down
6 changes: 3 additions & 3 deletions packages/integrations/vercel/test/split.test.js
Expand Up @@ -11,19 +11,19 @@ describe('build: split', () => {
output: 'server',
build: {
split: true,
}
},
});
await fixture.build();
});

it('creates separate functions for each page', async () => {
const files = await fixture.readdir('../.vercel/output/functions/')
const files = await fixture.readdir('../.vercel/output/functions/');
expect(files.length).to.equal(2);
});

it('creates the route definitions in the config.json', async () => {
const json = await fixture.readFile('../.vercel/output/config.json');
const config = JSON.parse(json);
expect(config.routes).to.have.a.lengthOf(3);
})
});
});

0 comments on commit 7ae6e89

Please sign in to comment.