Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit bb725b7

Browse files
chore(next): astro:env cleanup (#385)
1 parent e7881f7 commit bb725b7

File tree

10 files changed

+30
-58
lines changed

10 files changed

+30
-58
lines changed

.changeset/sixty-trainers-shout.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astrojs/netlify': minor
3+
'@astrojs/vercel': minor
4+
'@astrojs/node': minor
5+
---
6+
7+
Cleans up `astro:env` support

packages/netlify/src/index.ts

-15
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ async function writeNetlifyFrameworkConfig(config: AstroConfig, logger: AstroInt
141141
);
142142
}
143143

144-
// TODO: remove once we don't use a TLA anymore
145-
async function shouldExternalizeAstroEnvSetup() {
146-
try {
147-
await import('astro/env/setup');
148-
return false;
149-
} catch {
150-
return true;
151-
}
152-
}
153-
154144
export interface NetlifyIntegrationConfig {
155145
/**
156146
* If enabled, On-Demand-Rendered pages are cached for up to a year.
@@ -435,11 +425,6 @@ export default function netlifyIntegration(
435425
ignored: [fileURLToPath(new URL('./.netlify/**', rootDir))],
436426
},
437427
},
438-
...((await shouldExternalizeAstroEnvSetup())
439-
? {
440-
ssr: { external: ['astro/env/setup'] },
441-
}
442-
: {}),
443428
},
444429
image: {
445430
service: {

packages/netlify/src/polyfill.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { applyPolyfills } from 'astro/app/node';
2+
3+
applyPolyfills();

packages/netlify/src/ssr-function.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1+
// Keep at the top
2+
import './polyfill.js';
3+
14
import type { Context } from '@netlify/functions';
25
import type { SSRManifest } from 'astro';
36
import { App } from 'astro/app';
4-
import { applyPolyfills } from 'astro/app/node';
5-
6-
applyPolyfills();
7+
import { setGetEnv } from 'astro/env/setup';
78

8-
// Won't throw if the virtual module is not available because it's not supported in
9-
// the users's astro version or if astro:env is not enabled in the project
10-
await import('astro/env/setup')
11-
.then((mod) => mod.setGetEnv((key) => process.env[key]))
12-
.catch(() => {});
9+
setGetEnv((key) => process.env[key]);
1310

1411
export interface Args {
1512
middlewareSecret: string;

packages/node/src/index.ts

-15
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ export function getAdapter(options: Options): AstroAdapter {
2727
};
2828
}
2929

30-
// TODO: remove once we don't use a TLA anymore
31-
async function shouldExternalizeAstroEnvSetup() {
32-
try {
33-
await import('astro/env/setup');
34-
return false;
35-
} catch {
36-
return true;
37-
}
38-
}
39-
4030
export default function createIntegration(userOptions: UserOptions): AstroIntegration {
4131
if (!userOptions?.mode) {
4232
throw new AstroError(`Setting the 'mode' option is required.`);
@@ -54,11 +44,6 @@ export default function createIntegration(userOptions: UserOptions): AstroIntegr
5444
vite: {
5545
ssr: {
5646
noExternal: ['@astrojs/node'],
57-
...((await shouldExternalizeAstroEnvSetup())
58-
? {
59-
external: ['astro/env/setup'],
60-
}
61-
: {}),
6247
},
6348
},
6449
});

packages/node/src/polyfill.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { applyPolyfills } from 'astro/app/node';
2+
3+
applyPolyfills();

packages/node/src/server.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
// Keep at the top
2+
import './polyfill.js';
3+
14
import type { SSRManifest } from 'astro';
2-
import { NodeApp, applyPolyfills } from 'astro/app/node';
5+
import { NodeApp } from 'astro/app/node';
36
import { setGetEnv } from 'astro/env/setup';
47
import createMiddleware from './middleware.js';
58
import { createStandaloneHandler } from './standalone.js';
69
import startServer from './standalone.js';
710
import type { Options } from './types.js';
811

9-
// This needs to run first because some internals depend on `crypto`
10-
applyPolyfills();
1112
setGetEnv((key) => process.env[key]);
1213

1314
export function createExports(manifest: SSRManifest, options: Options) {

packages/vercel/src/serverless/adapter.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,7 @@ export default function vercelServerless({
260260
vite: {
261261
...getSpeedInsightsViteConfig(speedInsights?.enabled),
262262
ssr: {
263-
external: [
264-
'@vercel/nft',
265-
...((await shouldExternalizeAstroEnvSetup()) ? ['astro/env/setup'] : []),
266-
],
263+
external: ['@vercel/nft'],
267264
},
268265
},
269266
...getAstroImageConfig(
@@ -426,16 +423,6 @@ export default function vercelServerless({
426423

427424
type Runtime = `nodejs${string}.x`;
428425

429-
// TODO: remove once we don't use a TLA anymore
430-
async function shouldExternalizeAstroEnvSetup() {
431-
try {
432-
await import('astro/env/setup');
433-
return false;
434-
} catch {
435-
return true;
436-
}
437-
}
438-
439426
class VercelBuilder {
440427
readonly NTF_CACHE = {};
441428

packages/vercel/src/serverless/entrypoint.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Keep at the top
2+
import './polyfill.js';
3+
14
import type { IncomingMessage, ServerResponse } from 'node:http';
25
import type { SSRManifest } from 'astro';
3-
import { NodeApp, applyPolyfills } from 'astro/app/node';
6+
import { NodeApp } from 'astro/app/node';
47
import { setGetEnv } from 'astro/env/setup';
58
import {
69
ASTRO_LOCALS_HEADER,
@@ -9,8 +12,6 @@ import {
912
ASTRO_PATH_PARAM,
1013
} from './adapter.js';
1114

12-
// Run polyfills immediately so any dependent code can use the globals
13-
applyPolyfills();
1415
setGetEnv((key) => process.env[key]);
1516

1617
export const createExports = (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { applyPolyfills } from 'astro/app/node';
2+
3+
applyPolyfills();

0 commit comments

Comments
 (0)