Updated some types + added webapi
This commit is contained in:
parent
f946687bea
commit
a878a5cb77
4 changed files with 17 additions and 58 deletions
|
@ -23,7 +23,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@astrojs/webapi": "^0.11.0",
|
||||
"@vercel/node": "^1.14.0",
|
||||
"esbuild": "0.14.25",
|
||||
"globby": "^12.2.0"
|
||||
},
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
import type { AstroIntegration, AstroConfig } from 'astro';
|
||||
import fs from 'fs/promises';
|
||||
import type { IncomingMessage, ServerResponse } from 'http';
|
||||
import type { PathLike } from 'fs';
|
||||
|
||||
import fs from 'fs/promises';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { globby } from 'globby';
|
||||
import esbuild from 'esbuild';
|
||||
|
||||
export type { VercelApiHandler, VercelRequest, VercelRequestBody, VercelRequestCookies, VercelRequestQuery, VercelResponse } from '@vercel/node';
|
||||
export type VercelRequest = IncomingMessage;
|
||||
export type VercelResponse = ServerResponse;
|
||||
export type VercelHandler = (request: VercelRequest, response: VercelResponse) => void | Promise<void>;
|
||||
|
||||
const writeJson = (path: PathLike, data: any) => fs.writeFile(path, JSON.stringify(data), { encoding: 'utf-8' });
|
||||
|
||||
const ENDPOINT_GLOB = 'api/**/*.{js,ts,tsx}';
|
||||
|
||||
export function vercelFunctions(): AstroIntegration {
|
||||
function vercelFunctions(): AstroIntegration {
|
||||
let _config: AstroConfig;
|
||||
let output: URL;
|
||||
|
||||
|
@ -59,11 +63,14 @@ export function vercelFunctions(): AstroIntegration {
|
|||
entryPoints: endpoints.map((endpoint) => new URL(endpoint, _config.pages)).map(fileURLToPath),
|
||||
outdir: fileURLToPath(new URL('./server/pages/api/', output)),
|
||||
outbase: fileURLToPath(new URL('./api/', _config.pages)),
|
||||
inject: [fileURLToPath(new URL('./shims.js', import.meta.url))],
|
||||
bundle: true,
|
||||
target: 'node14',
|
||||
platform: 'node',
|
||||
format: 'cjs',
|
||||
});
|
||||
|
||||
await writeJson(new URL(`./package.json`, output), { type: 'commonjs' });
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
5
packages/integrations/vercel/src/shims.ts
Normal file
5
packages/integrations/vercel/src/shims.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { polyfill } from '@astrojs/webapi';
|
||||
|
||||
polyfill(globalThis, {
|
||||
exclude: 'window document',
|
||||
});
|
|
@ -1344,14 +1344,12 @@ importers:
|
|||
packages/integrations/vercel:
|
||||
specifiers:
|
||||
'@astrojs/webapi': ^0.11.0
|
||||
'@vercel/node': ^1.14.0
|
||||
astro: workspace:*
|
||||
astro-scripts: workspace:*
|
||||
esbuild: 0.14.25
|
||||
globby: ^12.2.0
|
||||
dependencies:
|
||||
'@astrojs/webapi': link:../../webapi
|
||||
'@vercel/node': 1.14.0
|
||||
esbuild: 0.14.25
|
||||
globby: 12.2.0
|
||||
devDependencies:
|
||||
|
@ -4308,19 +4306,6 @@ packages:
|
|||
'@unocss/scope': 0.15.6
|
||||
dev: true
|
||||
|
||||
/@vercel/node-bridge/2.2.0:
|
||||
resolution: {integrity: sha512-ydYlZyIQfsuriF6qTt/F4vaAt+nb4ZKhLEl2o5AQFa5ED7LoPS5w01Xbujy+25pqS1ODu8/bsqOCUSX8y/+tSQ==}
|
||||
dev: false
|
||||
|
||||
/@vercel/node/1.14.0:
|
||||
resolution: {integrity: sha512-UAb1qQMeTkSXz95yljJpz0MyTzcj++B/1XR0vKFZOs2CEfSkBO1DjzX6BkaKriaihBdbGM/X9UoMJfWfUBBn8Q==}
|
||||
dependencies:
|
||||
'@types/node': 17.0.23
|
||||
'@vercel/node-bridge': 2.2.0
|
||||
ts-node: 8.9.1_typescript@4.3.4
|
||||
typescript: 4.3.4
|
||||
dev: false
|
||||
|
||||
/@vitejs/plugin-vue/2.2.4_vite@2.8.6+vue@3.2.31:
|
||||
resolution: {integrity: sha512-ev9AOlp0ljCaDkFZF3JwC/pD2N4Hh+r5srl5JHM6BKg5+99jiiK0rE/XaRs3pVm1wzyKkjUy/StBSoXX5fFzcw==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
@ -4605,10 +4590,6 @@ packages:
|
|||
readable-stream: 2.3.7
|
||||
dev: true
|
||||
|
||||
/arg/4.1.3:
|
||||
resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==}
|
||||
dev: false
|
||||
|
||||
/arg/5.0.1:
|
||||
resolution: {integrity: sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==}
|
||||
|
||||
|
@ -4858,6 +4839,7 @@ packages:
|
|||
|
||||
/buffer-from/1.1.2:
|
||||
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
|
||||
dev: true
|
||||
|
||||
/buffer/5.7.1:
|
||||
resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==}
|
||||
|
@ -5458,11 +5440,6 @@ packages:
|
|||
/didyoumean/1.2.2:
|
||||
resolution: {integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==}
|
||||
|
||||
/diff/4.0.2:
|
||||
resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==}
|
||||
engines: {node: '>=0.3.1'}
|
||||
dev: false
|
||||
|
||||
/diff/5.0.0:
|
||||
resolution: {integrity: sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==}
|
||||
engines: {node: '>=0.3.1'}
|
||||
|
@ -7510,10 +7487,6 @@ packages:
|
|||
sourcemap-codec: 1.4.8
|
||||
dev: false
|
||||
|
||||
/make-error/1.3.6:
|
||||
resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==}
|
||||
dev: false
|
||||
|
||||
/map-obj/1.0.1:
|
||||
resolution: {integrity: sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
@ -9406,6 +9379,7 @@ packages:
|
|||
dependencies:
|
||||
buffer-from: 1.1.2
|
||||
source-map: 0.6.1
|
||||
dev: true
|
||||
|
||||
/source-map/0.5.7:
|
||||
resolution: {integrity: sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=}
|
||||
|
@ -9957,21 +9931,6 @@ packages:
|
|||
/trough/2.1.0:
|
||||
resolution: {integrity: sha512-AqTiAOLcj85xS7vQ8QkAV41hPDIJ71XJB4RCUrzo/1GM2CQwhkJGaf9Hgr7BOugMRpgGUrqRg/DrBDl4H40+8g==}
|
||||
|
||||
/ts-node/8.9.1_typescript@4.3.4:
|
||||
resolution: {integrity: sha512-yrq6ODsxEFTLz0R3BX2myf0WBCSQh9A+py8PBo1dCzWIOcvisbyH6akNKqDHMgXePF2kir5mm5JXJTH3OUJYOQ==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
typescript: '>=2.7'
|
||||
dependencies:
|
||||
arg: 4.1.3
|
||||
diff: 4.0.2
|
||||
make-error: 1.3.6
|
||||
source-map-support: 0.5.21
|
||||
typescript: 4.3.4
|
||||
yn: 3.1.1
|
||||
dev: false
|
||||
|
||||
/tsconfig-resolver/3.0.1:
|
||||
resolution: {integrity: sha512-ZHqlstlQF449v8glscGRXzL6l2dZvASPCdXJRWG4gHEZlUVx2Jtmr+a2zeVG4LCsKhDXKRj5R3h0C/98UcVAQg==}
|
||||
dependencies:
|
||||
|
@ -10193,12 +10152,6 @@ packages:
|
|||
resolution: {integrity: sha512-AiknQSEqKVGDDjtZqeKrUoTlcj7FKhupmnVUgz6KoOKtvMwRGE6hUNJ/nVear+h7fnUPO1q/htSkYKb1pyntkQ==}
|
||||
engines: {node: '>=12.20'}
|
||||
|
||||
/typescript/4.3.4:
|
||||
resolution: {integrity: sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==}
|
||||
engines: {node: '>=4.2.0'}
|
||||
hasBin: true
|
||||
dev: false
|
||||
|
||||
/typescript/4.6.3:
|
||||
resolution: {integrity: sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==}
|
||||
engines: {node: '>=4.2.0'}
|
||||
|
@ -10995,11 +10948,6 @@ packages:
|
|||
yargs-parser: 20.2.4
|
||||
dev: true
|
||||
|
||||
/yn/3.1.1:
|
||||
resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==}
|
||||
engines: {node: '>=6'}
|
||||
dev: false
|
||||
|
||||
/yocto-queue/0.1.0:
|
||||
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
||||
engines: {node: '>=10'}
|
||||
|
|
Loading…
Reference in a new issue