From 5b01112bf72dcf7534fc63546caef9a3372f3b1c Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 14 Jun 2024 12:14:21 -0400 Subject: [PATCH] Fix backwards compat with Astro <= 4.9 --- .changeset/serious-humans-obey.md | 6 ++++++ packages/integrations/node/src/server.ts | 7 +++++-- packages/integrations/vercel/src/serverless/entrypoint.ts | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .changeset/serious-humans-obey.md diff --git a/.changeset/serious-humans-obey.md b/.changeset/serious-humans-obey.md new file mode 100644 index 000000000000..4cd6e4d69ab6 --- /dev/null +++ b/.changeset/serious-humans-obey.md @@ -0,0 +1,6 @@ +--- +'@astrojs/vercel': patch +'@astrojs/node': patch +--- + +Fix backwards compat with Astro <= 4.9 diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts index e5b503292d40..e79c0761a445 100644 --- a/packages/integrations/node/src/server.ts +++ b/packages/integrations/node/src/server.ts @@ -5,10 +5,13 @@ 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 -await import('astro/env/setup') - .then((mod) => mod.setGetEnv((key) => process.env[key])) +const setupModule = 'astro/env/setup'; +await import(/* @vite-ignore */setupModule) + .then((mod: EnvSetupModule) => mod.setGetEnv((key) => process.env[key])) .catch(() => {}); applyPolyfills(); diff --git a/packages/integrations/vercel/src/serverless/entrypoint.ts b/packages/integrations/vercel/src/serverless/entrypoint.ts index 11d3c3a91e1d..ee1e1bc99b73 100644 --- a/packages/integrations/vercel/src/serverless/entrypoint.ts +++ b/packages/integrations/vercel/src/serverless/entrypoint.ts @@ -8,10 +8,13 @@ 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 -await import('astro/env/setup') - .then((mod) => mod.setGetEnv((key) => process.env[key])) +const setupModule = 'astro/env/setup'; +await import(/* @vite-ignore */setupModule) + .then((mod: EnvSetupModule) => mod.setGetEnv((key) => process.env[key])) .catch(() => {}); applyPolyfills();