From 6abb9a960fe4f3ef68d6a629102840b7d9e9ea27 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Thu, 6 Jun 2024 21:34:26 +0200 Subject: [PATCH 1/3] feat: add support for astro:env to node and vercel --- .changeset/wet-chefs-develop.md | 6 ++++++ packages/integrations/node/src/env.d.ts | 1 + packages/integrations/node/src/index.ts | 6 ++++++ packages/integrations/node/src/server.ts | 6 ++++++ packages/integrations/vercel/src/serverless/adapter.ts | 6 ++++++ packages/integrations/vercel/src/serverless/entrypoint.ts | 6 ++++++ packages/integrations/vercel/src/static/adapter.ts | 1 + packages/integrations/vercel/src/types.d.ts | 2 ++ 8 files changed, 34 insertions(+) create mode 100644 .changeset/wet-chefs-develop.md create mode 100644 packages/integrations/node/src/env.d.ts diff --git a/.changeset/wet-chefs-develop.md b/.changeset/wet-chefs-develop.md new file mode 100644 index 000000000000..d215b69fb71a --- /dev/null +++ b/.changeset/wet-chefs-develop.md @@ -0,0 +1,6 @@ +--- +'@astrojs/vercel': patch +'@astrojs/node': patch +--- + +Adds support for experimental `astro:env` released in Astro 4.10 diff --git a/packages/integrations/node/src/env.d.ts b/packages/integrations/node/src/env.d.ts new file mode 100644 index 000000000000..8c34fb45e7cf --- /dev/null +++ b/packages/integrations/node/src/env.d.ts @@ -0,0 +1 @@ +/// \ No newline at end of file diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts index 2108ec5ca82c..a7a017b618e5 100644 --- a/packages/integrations/node/src/index.ts +++ b/packages/integrations/node/src/index.ts @@ -19,6 +19,7 @@ export function getAdapter(options: Options): AstroAdapter { isSquooshCompatible: true, }, i18nDomains: 'experimental', + envGetSecret: 'experimental', }, }; } @@ -41,6 +42,11 @@ export default function createIntegration(userOptions: UserOptions): AstroIntegr ssr: { noExternal: ['@astrojs/node'], }, + build: { + rollupOptions: { + external: ['astro:env/setup'], + }, + }, }, }); }, diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts index 1fb9d93e503d..6c710a68ae43 100644 --- a/packages/integrations/node/src/server.ts +++ b/packages/integrations/node/src/server.ts @@ -5,6 +5,12 @@ import { createStandaloneHandler } from './standalone.js'; import startServer from './standalone.js'; import type { Options } from './types.js'; +// 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])) + .catch(() => {}); + applyPolyfills(); export function createExports(manifest: SSRManifest, options: Options) { const app = new NodeApp(manifest); diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index 1090555cc350..fe48d21b1677 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -98,6 +98,7 @@ function getAdapter({ isSquooshCompatible: true, }, i18nDomains: 'experimental', + envGetSecret: 'experimental', }, }; } @@ -264,6 +265,11 @@ export default function vercelServerless({ ssr: { external: ['@vercel/nft'], }, + build: { + rollupOptions: { + external: ['astro:env/setup'], + }, + }, }, ...getAstroImageConfig( imageService, diff --git a/packages/integrations/vercel/src/serverless/entrypoint.ts b/packages/integrations/vercel/src/serverless/entrypoint.ts index a8e8ebc41c9f..645b4120c81c 100644 --- a/packages/integrations/vercel/src/serverless/entrypoint.ts +++ b/packages/integrations/vercel/src/serverless/entrypoint.ts @@ -8,6 +8,12 @@ import { ASTRO_PATH_PARAM, } from './adapter.js'; +// 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])) + .catch(() => {}); + applyPolyfills(); export const createExports = ( diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index d7fd57fd5379..4a66c558ef69 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -32,6 +32,7 @@ function getAdapter(): AstroAdapter { staticOutput: 'stable', serverOutput: 'unsupported', hybridOutput: 'unsupported', + envGetSecret: 'unsupported', }, adapterFeatures: { edgeMiddleware: false, diff --git a/packages/integrations/vercel/src/types.d.ts b/packages/integrations/vercel/src/types.d.ts index 1c5b8d2db11f..06080e83b522 100644 --- a/packages/integrations/vercel/src/types.d.ts +++ b/packages/integrations/vercel/src/types.d.ts @@ -1,3 +1,5 @@ +/// + import type { AnalyticsProps } from '@vercel/analytics'; export type VercelWebAnalyticsBeforeSend = AnalyticsProps['beforeSend']; From c830445527e83239fd06bbcdb7907407b0091d6a Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Fri, 7 Jun 2024 12:35:03 +0200 Subject: [PATCH 2/3] Update wet-chefs-develop.md --- .changeset/wet-chefs-develop.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/wet-chefs-develop.md b/.changeset/wet-chefs-develop.md index d215b69fb71a..e2a29702bc02 100644 --- a/.changeset/wet-chefs-develop.md +++ b/.changeset/wet-chefs-develop.md @@ -1,6 +1,6 @@ --- -'@astrojs/vercel': patch -'@astrojs/node': patch +'@astrojs/vercel': minor +'@astrojs/node': minor --- Adds support for experimental `astro:env` released in Astro 4.10 From 0eba30cc52d1ef5d3592a14442510ce533995352 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Sat, 8 Jun 2024 11:39:38 +0200 Subject: [PATCH 3/3] feat: update --- packages/integrations/node/src/env.d.ts | 1 - packages/integrations/node/src/index.ts | 5 ----- packages/integrations/node/src/server.ts | 2 +- packages/integrations/vercel/src/serverless/adapter.ts | 5 ----- packages/integrations/vercel/src/serverless/entrypoint.ts | 2 +- packages/integrations/vercel/src/types.d.ts | 2 -- 6 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 packages/integrations/node/src/env.d.ts diff --git a/packages/integrations/node/src/env.d.ts b/packages/integrations/node/src/env.d.ts deleted file mode 100644 index 8c34fb45e7cf..000000000000 --- a/packages/integrations/node/src/env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// \ No newline at end of file diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts index a7a017b618e5..5fec3850c79f 100644 --- a/packages/integrations/node/src/index.ts +++ b/packages/integrations/node/src/index.ts @@ -42,11 +42,6 @@ export default function createIntegration(userOptions: UserOptions): AstroIntegr ssr: { noExternal: ['@astrojs/node'], }, - build: { - rollupOptions: { - external: ['astro:env/setup'], - }, - }, }, }); }, diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts index 6c710a68ae43..e5b503292d40 100644 --- a/packages/integrations/node/src/server.ts +++ b/packages/integrations/node/src/server.ts @@ -7,7 +7,7 @@ import type { Options } from './types.js'; // 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') +await import('astro/env/setup') .then((mod) => mod.setGetEnv((key) => process.env[key])) .catch(() => {}); diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index fe48d21b1677..65f5fafd798f 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -265,11 +265,6 @@ export default function vercelServerless({ ssr: { external: ['@vercel/nft'], }, - build: { - rollupOptions: { - external: ['astro:env/setup'], - }, - }, }, ...getAstroImageConfig( imageService, diff --git a/packages/integrations/vercel/src/serverless/entrypoint.ts b/packages/integrations/vercel/src/serverless/entrypoint.ts index 645b4120c81c..11d3c3a91e1d 100644 --- a/packages/integrations/vercel/src/serverless/entrypoint.ts +++ b/packages/integrations/vercel/src/serverless/entrypoint.ts @@ -10,7 +10,7 @@ import { // 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') +await import('astro/env/setup') .then((mod) => mod.setGetEnv((key) => process.env[key])) .catch(() => {}); diff --git a/packages/integrations/vercel/src/types.d.ts b/packages/integrations/vercel/src/types.d.ts index 06080e83b522..1c5b8d2db11f 100644 --- a/packages/integrations/vercel/src/types.d.ts +++ b/packages/integrations/vercel/src/types.d.ts @@ -1,5 +1,3 @@ -/// - import type { AnalyticsProps } from '@vercel/analytics'; export type VercelWebAnalyticsBeforeSend = AnalyticsProps['beforeSend'];