Fix types for the edge function integration
This commit is contained in:
parent
0c3a85f2e3
commit
4e4ff19fe0
3 changed files with 24 additions and 13 deletions
|
@ -36,6 +36,7 @@
|
|||
"devDependencies": {
|
||||
"@netlify/edge-handler-types": "^0.34.1",
|
||||
"@netlify/functions": "^1.0.0",
|
||||
"@types/node": "^14.18.20",
|
||||
"astro": "workspace:*",
|
||||
"astro-scripts": "workspace:*"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import type { AstroAdapter, AstroConfig, AstroIntegration, BuildConfig, RouteData } from 'astro';
|
||||
import type { Plugin as VitePlugin } from 'vite';
|
||||
import esbuild from 'esbuild';
|
||||
import * as fs from 'fs';
|
||||
import * as npath from 'path';
|
||||
|
@ -97,12 +98,31 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
|
|||
return {
|
||||
name: '@astrojs/netlify/edge-functions',
|
||||
hooks: {
|
||||
'astro:config:setup': ({ config }) => {
|
||||
'astro:config:setup': ({ config, updateConfig }) => {
|
||||
if (dist) {
|
||||
config.outDir = dist;
|
||||
} else {
|
||||
config.outDir = new URL('./dist/', config.root);
|
||||
}
|
||||
|
||||
// Add a plugin that shims the global environment.
|
||||
const injectPlugin: VitePlugin = {
|
||||
name: '@astrojs/netlify/plugin-inject',
|
||||
generateBundle(_options, bundle) {
|
||||
if(_buildConfig.serverEntry in bundle) {
|
||||
const chunk = bundle[_buildConfig.serverEntry];
|
||||
if(chunk && chunk.type === 'chunk') {
|
||||
chunk.code = `globalThis.process = { argv: [], env: {}, };${chunk.code}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
updateConfig({
|
||||
vite: {
|
||||
plugins: [injectPlugin]
|
||||
}
|
||||
});
|
||||
},
|
||||
'astro:config:done': ({ config, setAdapter }) => {
|
||||
setAdapter(getAdapter());
|
||||
|
@ -131,18 +151,6 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
|
|||
}
|
||||
}
|
||||
|
||||
// Add a plugin that shims the global environment.
|
||||
vite.plugins.unshift({
|
||||
name: '@astrojs/netlify/plugin-inject',
|
||||
generateBundle(options, bundle) {
|
||||
if(_buildConfig.serverEntry in bundle) {
|
||||
const chunk = bundle[_buildConfig.serverEntry];
|
||||
chunk.code = `globalThis.process = { argv: [], env: {}, };` +
|
||||
chunk.code;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
vite.ssr = {
|
||||
noExternal: true,
|
||||
};
|
||||
|
|
|
@ -1732,6 +1732,7 @@ importers:
|
|||
'@astrojs/webapi': ^0.12.0
|
||||
'@netlify/edge-handler-types': ^0.34.1
|
||||
'@netlify/functions': ^1.0.0
|
||||
'@types/node': ^14.18.20
|
||||
astro: workspace:*
|
||||
astro-scripts: workspace:*
|
||||
esbuild: ^0.14.42
|
||||
|
@ -1741,6 +1742,7 @@ importers:
|
|||
devDependencies:
|
||||
'@netlify/edge-handler-types': 0.34.1
|
||||
'@netlify/functions': 1.0.0
|
||||
'@types/node': 14.18.21
|
||||
astro: link:../../astro
|
||||
astro-scripts: link:../../../scripts
|
||||
|
||||
|
|
Loading…
Reference in a new issue