summaryrefslogtreecommitdiff
path: root/benchmark/packages/timer/src/index.ts
blob: 49edcb5e86a5e3de70db7645e9b1b28512594521 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { AstroAdapter, AstroIntegration } from 'astro';

export function getAdapter(): AstroAdapter {
	return {
		name: '@benchmark/timer',
		serverEntrypoint: '@benchmark/timer/server.js',
		previewEntrypoint: '@benchmark/timer/preview.js',
		exports: ['handler'],
	};
}

export default function createIntegration(): AstroIntegration {
	return {
		name: '@benchmark/timer',
		hooks: {
			'astro:config:setup': ({ updateConfig }) => {
				updateConfig({
					vite: {
						ssr: {
							noExternal: ['@benchmark/timer'],
						},
					},
				});
			},
			'astro:config:done': ({ setAdapter, config }) => {
				setAdapter(getAdapter());

				if (config.output === 'static') {
					// eslint-disable-next-line no-console
					console.warn(`[@benchmark/timer] \`output: "server"\` is required to use this adapter.`);
				}
			},
		},
	};
}