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

chore(next): astro:env cleanup #385

Merged
merged 3 commits into from
Sep 12, 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
7 changes: 7 additions & 0 deletions .changeset/sixty-trainers-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astrojs/netlify': minor
'@astrojs/vercel': minor
'@astrojs/node': minor
---

Cleans up `astro:env` support
15 changes: 0 additions & 15 deletions packages/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ async function writeNetlifyFrameworkConfig(config: AstroConfig, logger: AstroInt
);
}

// 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 interface NetlifyIntegrationConfig {
/**
* If enabled, On-Demand-Rendered pages are cached for up to a year.
Expand Down Expand Up @@ -435,11 +425,6 @@ export default function netlifyIntegration(
ignored: [fileURLToPath(new URL('./.netlify/**', rootDir))],
},
},
...((await shouldExternalizeAstroEnvSetup())
? {
ssr: { external: ['astro/env/setup'] },
}
: {}),
},
image: {
service: {
Expand Down
3 changes: 3 additions & 0 deletions packages/netlify/src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { applyPolyfills } from 'astro/app/node';

applyPolyfills();
13 changes: 5 additions & 8 deletions packages/netlify/src/ssr-function.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// Keep at the top
import './polyfill.js';

import type { Context } from '@netlify/functions';
import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
import { applyPolyfills } from 'astro/app/node';

applyPolyfills();
import { setGetEnv } from 'astro/env/setup';
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

// 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(() => {});
setGetEnv((key) => process.env[key]);

export interface Args {
middlewareSecret: string;
Expand Down
15 changes: 0 additions & 15 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ 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.`);
Expand All @@ -54,11 +44,6 @@ export default function createIntegration(userOptions: UserOptions): AstroIntegr
vite: {
ssr: {
noExternal: ['@astrojs/node'],
...((await shouldExternalizeAstroEnvSetup())
? {
external: ['astro/env/setup'],
}
: {}),
},
},
});
Expand Down
3 changes: 3 additions & 0 deletions packages/node/src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { applyPolyfills } from 'astro/app/node';

applyPolyfills();
7 changes: 4 additions & 3 deletions packages/node/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Keep at the top
import './polyfill.js';

import type { SSRManifest } from 'astro';
import { NodeApp, applyPolyfills } from 'astro/app/node';
import { NodeApp } from 'astro/app/node';
import { setGetEnv } from 'astro/env/setup';
import createMiddleware from './middleware.js';
import { createStandaloneHandler } from './standalone.js';
import startServer from './standalone.js';
import type { Options } from './types.js';

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

export function createExports(manifest: SSRManifest, options: Options) {
Expand Down
15 changes: 1 addition & 14 deletions packages/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,7 @@ export default function vercelServerless({
vite: {
...getSpeedInsightsViteConfig(speedInsights?.enabled),
ssr: {
external: [
'@vercel/nft',
...((await shouldExternalizeAstroEnvSetup()) ? ['astro/env/setup'] : []),
],
external: ['@vercel/nft'],
},
},
...getAstroImageConfig(
Expand Down Expand Up @@ -426,16 +423,6 @@ 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: 4 additions & 3 deletions packages/vercel/src/serverless/entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Keep at the top
import './polyfill.js';

import type { IncomingMessage, ServerResponse } from 'node:http';
import type { SSRManifest } from 'astro';
import { NodeApp, applyPolyfills } from 'astro/app/node';
import { NodeApp } from 'astro/app/node';
import { setGetEnv } from 'astro/env/setup';
import {
ASTRO_LOCALS_HEADER,
Expand All @@ -9,8 +12,6 @@ import {
ASTRO_PATH_PARAM,
} from './adapter.js';

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

export const createExports = (
Expand Down
3 changes: 3 additions & 0 deletions packages/vercel/src/serverless/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { applyPolyfills } from 'astro/app/node';

applyPolyfills();