diff options
author | 2024-06-20 15:54:54 +0200 | |
---|---|---|
committer | 2024-06-20 15:54:54 +0200 | |
commit | 2a0181f9959f63684e2daaa44da0d825bafc3868 (patch) | |
tree | 149dea59393a7e7c0b6953fbcd20c4fe4b33b110 /packages/integrations/node/src | |
parent | cce24e1a22e35b8cb28e481994847d1dc8f93616 (diff) | |
download | astro-2a0181f9959f63684e2daaa44da0d825bafc3868.tar.gz astro-2a0181f9959f63684e2daaa44da0d825bafc3868.tar.zst astro-2a0181f9959f63684e2daaa44da0d825bafc3868.zip |
fix: astro:env getSecret (#11296)
Diffstat (limited to 'packages/integrations/node/src')
-rw-r--r-- | packages/integrations/node/src/index.ts | 17 | ||||
-rw-r--r-- | packages/integrations/node/src/server.ts | 7 |
2 files changed, 18 insertions, 6 deletions
diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts index e11576990..eb3c98a9b 100644 --- a/packages/integrations/node/src/index.ts +++ b/packages/integrations/node/src/index.ts @@ -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'], + } + : {}), }, }, }); diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts index febace938..e5b503292 100644 --- a/packages/integrations/node/src/server.ts +++ b/packages/integrations/node/src/server.ts @@ -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(); |