Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: astro:env getSecret #11296

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/small-sloths-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/vercel': patch
'@astrojs/node': patch
---

Fixes `astro:env` getSecret compatibility
17 changes: 16 additions & 1 deletion packages/integrations/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
}
}

export default function createIntegration(userOptions: UserOptions): AstroIntegration {
if (!userOptions?.mode) {
throw new AstroError(`Setting the 'mode' option is required.`);
Expand All @@ -33,14 +43,19 @@ 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',
},
vite: {
ssr: {
noExternal: ['@astrojs/node'],
...((await shouldExternalizeAstroEnvSetup())
? {
external: ['astro/env/setup'],
}
: {}),
},
},
});
Expand Down
7 changes: 2 additions & 5 deletions packages/integrations/node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 14 additions & 1 deletion packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = {};

Expand Down
7 changes: 2 additions & 5 deletions packages/integrations/vercel/src/serverless/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading