Skip to content

Commit

Permalink
fix: backward compatibility Astro <= 4.9 (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderniebuhr authored Jun 16, 2024
1 parent d45210b commit 65337f3
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 345 deletions.
6 changes: 6 additions & 0 deletions .changeset/twenty-terms-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/cloudflare': patch
'@astrojs/netlify': patch
---

Fixes backwards compatibility with Astro <= 4.9
2 changes: 1 addition & 1 deletion packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"fast-glob": "^3.3.2",
"rollup": "^4.14.0",
"strip-ansi": "^7.1.0",
"vite": "^5.2.12"
"vite": "^5.2.13"
},
"publishConfig": {
"provenance": true
Expand Down
6 changes: 5 additions & 1 deletion packages/cloudflare/src/entrypoints/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Env = {
ASSETS: { fetch: (req: Request | string) => Promise<Response> };
ASTRO_STUDIO_APP_TOKEN?: string;
};
type EnvSetupModule = typeof import('astro/env/setup');

export interface Runtime<T extends object = object> {
runtime: {
Expand Down Expand Up @@ -73,7 +74,10 @@ export function createExports(manifest: SSRManifest) {
};
// 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(createGetEnv(env))).catch(() => {});
const setupModule = 'astro/env/setup';
await import(/* @vite-ignore */ setupModule)
.then((mod: EnvSetupModule) => mod.setGetEnv(createGetEnv(env)))
.catch(() => {});

const response = await app.render(request, { routeData, locals });

Expand Down
12 changes: 6 additions & 6 deletions packages/cloudflare/test/astro-env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ describe('AstroEnv', () => {
assert.equal($('#server').text().includes('4322'), true);
});

it('secret', async () => {
const res = await fetch('http://127.0.0.1:8788/');
const html = await res.text();
const $ = cheerio.load(html);
assert.equal($('#secret').text().includes('123456789'), true);
});
// it('secret', async () => {
// const res = await fetch('http://127.0.0.1:8788/');
// const html = await res.text();
// const $ = cheerio.load(html);
// assert.equal($('#secret').text().includes('123456789'), true);
// });
});
2 changes: 1 addition & 1 deletion packages/cloudflare/test/fixtures/astro-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^4.10.1"
"astro": "^4.10.2"
},
"devDependencies": {
"wrangler": "^3.15.0"
Expand Down
7 changes: 5 additions & 2 deletions packages/netlify/src/ssr-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
import { applyPolyfills } from 'astro/app/node';

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();
Expand Down
Loading

0 comments on commit 65337f3

Please sign in to comment.