0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

fix: astro:env getSecret (#11296)

This commit is contained in:
Florian Lefebvre 2024-06-20 15:54:54 +02:00 committed by GitHub
parent e67d7e66a9
commit 5848d97867
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 40 additions and 12 deletions

View file

@ -0,0 +1,6 @@
---
'@astrojs/vercel': patch
'@astrojs/node': patch
---
Fixes `astro:env` getSecret compatibility

View file

@ -24,6 +24,16 @@ export function getAdapter(options: Options): AstroAdapter {
};
}
// TODO: remove once we don't use a TLA anymore
async function shouldExternalizeAstroEnvSetup() {
try {
await import('astro/env/setup');
return false;
} catch {
return true;
}
}
export default function createIntegration(userOptions: UserOptions): AstroIntegration {
if (!userOptions?.mode) {
throw new AstroError(`Setting the 'mode' option is required.`);
@ -33,7 +43,7 @@ export default function createIntegration(userOptions: UserOptions): AstroIntegr
return {
name: '@astrojs/node',
hooks: {
'astro:config:setup': ({ updateConfig, config }) => {
'astro:config:setup': async ({ updateConfig, config }) => {
updateConfig({
image: {
endpoint: config.image.endpoint ?? 'astro/assets/endpoint/node',
@ -41,6 +51,11 @@ export default function createIntegration(userOptions: UserOptions): AstroIntegr
vite: {
ssr: {
noExternal: ['@astrojs/node'],
...((await shouldExternalizeAstroEnvSetup())
? {
external: ['astro/env/setup'],
}
: {}),
},
},
});

View file

@ -5,13 +5,10 @@ import { createStandaloneHandler } from './standalone.js';
import startServer from './standalone.js';
import type { Options } from './types.js';
type EnvSetupModule = typeof import('astro/env/setup');
// Won't throw if the virtual module is not available because it's not supported in
// the users's astro version or if astro:env is not enabled in the project
const setupModule = 'astro/env/setup';
await import(/* @vite-ignore */ setupModule)
.then((mod: EnvSetupModule) => mod.setGetEnv((key) => process.env[key]))
await import('astro/env/setup')
.then((mod) => mod.setGetEnv((key) => process.env[key]))
.catch(() => {});
applyPolyfills();

View file

@ -263,7 +263,10 @@ export default function vercelServerless({
vite: {
...getSpeedInsightsViteConfig(speedInsights?.enabled),
ssr: {
external: ['@vercel/nft'],
external: [
'@vercel/nft',
...((await shouldExternalizeAstroEnvSetup()) ? ['astro/env/setup'] : []),
],
},
},
...getAstroImageConfig(
@ -442,6 +445,16 @@ export default function vercelServerless({
type Runtime = `nodejs${string}.x`;
// TODO: remove once we don't use a TLA anymore
async function shouldExternalizeAstroEnvSetup() {
try {
await import('astro/env/setup');
return false;
} catch {
return true;
}
}
class VercelBuilder {
readonly NTF_CACHE = {};

View file

@ -8,13 +8,10 @@ import {
ASTRO_PATH_PARAM,
} from './adapter.js';
type EnvSetupModule = typeof import('astro/env/setup');
// Won't throw if the virtual module is not available because it's not supported in
// the users's astro version or if astro:env is not enabled in the project
const setupModule = 'astro/env/setup';
await import(/* @vite-ignore */ setupModule)
.then((mod: EnvSetupModule) => mod.setGetEnv((key) => process.env[key]))
await import('astro/env/setup')
.then((mod) => mod.setGetEnv((key) => process.env[key]))
.catch(() => {});
applyPolyfills();