Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 31, 2024
2 parents 3351348 + 5391c02 commit e30c046
Show file tree
Hide file tree
Showing 28 changed files with 1,096 additions and 1,395 deletions.
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"files": {
"ignore": [
"**/dist",
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@
}
},
"devDependencies": {
"@astrojs/check": "^0.9.3",
"@biomejs/biome": "1.9.2",
"@astrojs/check": "^0.9.4",
"@biomejs/biome": "1.9.4",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.8",
"@types/node": "^20.16.10",
"@changesets/cli": "^2.27.9",
"@types/node": "^20.17.4",
"esbuild": "^0.21.5",
"eslint": "^9.11.1",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-no-only-tests": "^3.3.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-regexp": "^2.6.0",
"only-allow": "^1.2.1",
"prettier": "^3.3.3",
"prettier-plugin-astro": "^0.14.1",
"turbo": "^2.1.3",
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.0"
"turbo": "^2.2.3",
"typescript": "^5.6.3",
"typescript-eslint": "^8.12.2"
}
}
10 changes: 10 additions & 0 deletions packages/cloudflare/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@

- [#392](https://github.com/withastro/adapters/pull/392) [`3a49eb7`](https://github.com/withastro/adapters/commit/3a49eb7802c44212ccfab06034b7dc5f2b060e94) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Updates internal code for Astro 5 changes. No changes is required to your project, apart from using Astro 5

## 11.2.0

### Minor Changes

- [#423](https://github.com/withastro/adapters/pull/423) [`169ac24`](https://github.com/withastro/adapters/commit/169ac24451d8ac0e47dda27f7148d2ddad66e3dc) Thanks [@schummar](https://github.com/schummar)! - Changes the logic which generates the `_routes.json` file to improve generation for projects with many static pages, while still making sure all routes work as expected.

### Patch Changes

- [#409](https://github.com/withastro/adapters/pull/409) [`d63bed8`](https://github.com/withastro/adapters/commit/d63bed81afe549f98d705573d365de5204cab134) Thanks [@alexanderniebuhr](https://github.com/alexanderniebuhr)! - Fixes an issue where `cloudflare:` scoped imports made the build fail. We externalize all imports with the `cloudflare:` scope by default now.

## 11.1.0

### Minor Changes
Expand Down
14 changes: 7 additions & 7 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
"dependencies": {
"@astrojs/internal-helpers": "0.4.1",
"@astrojs/underscore-redirects": "^0.4.0-alpha.0",
"@cloudflare/workers-types": "^4.20240925.0",
"@cloudflare/workers-types": "^4.20241022.0",
"esbuild": "^0.23.1",
"estree-walker": "^3.0.3",
"magic-string": "^0.30.11",
"miniflare": "^3.20240925.0",
"magic-string": "^0.30.12",
"miniflare": "^3.20241022.0",
"tiny-glob": "^0.2.9",
"wrangler": "^3.78.12",
"@inox-tools/astro-when": "^0.2.3"
"wrangler": "^3.84.0",
"@inox-tools/astro-when": "^0.2.4"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.8"
Expand All @@ -49,9 +49,9 @@
"cheerio": "1.0.0",
"execa": "^8.0.1",
"fast-glob": "^3.3.2",
"rollup": "^4.22.5",
"rollup": "^4.24.3",
"strip-ansi": "^7.1.0",
"vite": "^5.4.8"
"vite": "^5.4.10"
},
"publishConfig": {
"provenance": true
Expand Down
10 changes: 10 additions & 0 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ export default function createIntegration(args?: Options): AstroIntegration {
// https://developers.cloudflare.com/pages/functions/module-support/
// Allows imports of '.wasm', '.bin', and '.txt' file types
cloudflareModulePlugin,
{
name: 'vite:cf-imports',
enforce: 'pre',
resolveId(source) {
if (source.startsWith('cloudflare:')) {
return { id: source, external: true };
}
return null;
},
},
],
},
integrations: [astroWhen()],
Expand Down
10 changes: 5 additions & 5 deletions packages/cloudflare/src/utils/generate-routes-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export async function createRoutesFile(
const convertedPath = segmentsToCfSyntax(route.segments, _config);
if (route.pathname === '/404' && route.prerender === true) hasPrerendered404 = true;

// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (route.type) {
case 'page':
if (route.prerender === false) includePaths.push(convertedPath);
Expand Down Expand Up @@ -307,11 +308,10 @@ export async function createRoutesFile(
const EXTENDED_EXCLUDE_RULES_COUNT = excludeExtends?.length ?? 0;
const EXCLUDE_RULES_COUNT = AUTOMATIC_EXCLUDE_RULES_COUNT + EXTENDED_EXCLUDE_RULES_COUNT;

if (
!hasPrerendered404 ||
INCLUDE_RULES_COUNT > CLOUDFLARE_COMBINED_LIMIT ||
EXCLUDE_RULES_COUNT > CLOUDFLARE_COMBINED_LIMIT
) {
const OPTION2_TOTAL_COUNT =
INCLUDE_RULES_COUNT + (includedPathsHaveWildcard ? EXCLUDE_RULES_COUNT : 0);

if (!hasPrerendered404 || OPTION2_TOTAL_COUNT > CLOUDFLARE_COMBINED_LIMIT) {
await writeRoutesFileToOutDir(
_config,
logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"astro": "^5.0.0-alpha.8"
},
"devDependencies": {
"wrangler": "^3.78.12"
"wrangler": "^3.84.0"
}
}
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 @@ -7,6 +7,6 @@
"astro": "^5.0.0-alpha.8"
},
"devDependencies": {
"wrangler": "^3.78.12"
"wrangler": "^3.84.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../../.astro/types.d.ts" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
import type { GetStaticPaths } from "astro";
export const getStaticPaths = (() => {
return Array.from({length:100}).map((_, i) => ({
params: {
id: i.toString()
}
}));
}) satisfies GetStaticPaths;
const { id } = Astro.params;
---

id={id}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender = false;
---

dynamic
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../../.astro/types.d.ts" />
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
import type { GetStaticPaths } from "astro";
export const getStaticPaths = (() => {
return Array.from({length:100}).map((_, i) => ({
params: {
id: i.toString()
}
}));
}) satisfies GetStaticPaths;
const { id } = Astro.params;
---

id={id}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender = false;
---

dynamic
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"@astrojs/cloudflare": "workspace:*",
"@astrojs/solid-js": "^4.4.2",
"astro": "^5.0.0-alpha.8",
"solid-js": "^1.9.1"
"solid-js": "^1.9.3"
}
}
54 changes: 54 additions & 0 deletions packages/cloudflare/test/routes-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,58 @@ describe('_routes.json generation', () => {
});
});
});

describe('with many static files', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/routes-json/', import.meta.url).toString(),
srcDir: './src/manyStatic',
adapter: cloudflare({}),
});
await fixture.build();
});

it('creates a wildcard `include` and `exclude` for as many static assets and redirects as possible, truncating after 100 rules', async () => {
const _routesJson = await fixture.readFile('/_routes.json');
const routes = JSON.parse(_routesJson);

assert.deepEqual(routes, {
version: 1,
include: ['/*'],
exclude: [
'/_astro/*',
'/redirectme',
'/public.txt',
'/a/*',
...Array.from({ length: 95 }, (_, i) => `/${i}`),
],
});
});
});

describe('with many static files when a static 404 is present', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/routes-json/', import.meta.url).toString(),
srcDir: './src/manyStaticWith404',
adapter: cloudflare({}),
});
await fixture.build();
});

it('creates `include` for on-demand and `exclude` that are supposed to match nothin', async () => {
const _routesJson = await fixture.readFile('/_routes.json');
const routes = JSON.parse(_routesJson);

assert.deepEqual(routes, {
version: 1,
include: ['/_image', '/dynamic'],
exclude: [],
});
});
});
});
6 changes: 6 additions & 0 deletions packages/netlify/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@

- [#385](https://github.com/withastro/adapters/pull/385) [`bb725b7`](https://github.com/withastro/adapters/commit/bb725b7a430a01a3cd197e3e84381be4fa0c945c) Thanks [@florian-lefebvre](https://github.com/florian-lefebvre)! - Cleans up `astro:env` support

## 5.5.4

### Patch Changes

- [#413](https://github.com/withastro/adapters/pull/413) [`1b18e67`](https://github.com/withastro/adapters/commit/1b18e671a689b67bde20fdc7fb8cf1d6283e4ec9) Thanks [@ascorbic](https://github.com/ascorbic)! - Fixes `context.rewrite` in edge middleware

## 5.5.3

### Patch Changes
Expand Down
8 changes: 4 additions & 4 deletions packages/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"@astrojs/internal-helpers": "0.4.1",
"@astrojs/underscore-redirects": "^0.4.0-alpha.0",
"@netlify/functions": "^2.8.0",
"@vercel/nft": "^0.27.4",
"@vercel/nft": "^0.27.5",
"esbuild": "^0.21.5",
"vite": "^5.4.8"
"vite": "^5.4.10"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.8"
Expand All @@ -45,14 +45,14 @@
"@astrojs/test-utils": "workspace:*",
"@netlify/edge-functions": "^2.11.0",
"@netlify/edge-handler-types": "^0.34.1",
"@types/node": "^20.16.10",
"@types/node": "^20.17.4",
"astro": "^5.0.0-alpha.8",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"execa": "^8.0.1",
"fast-glob": "^3.3.2",
"strip-ansi": "^7.1.0",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"astro": {
"external": true
Expand Down
19 changes: 19 additions & 0 deletions packages/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,25 @@ export default function netlifyIntegration(
params: {}
});
ctx.locals = { netlify: { context } }
// https://docs.netlify.com/edge-functions/api/#return-a-rewrite
ctx.rewrite = (target) => {
if(target instanceof Request) {
// We can only mutate headers, so if anything else is different, we need to fetch
// the target URL instead.
if(target.method !== request.method || target.body || target.url.origin !== request.url.origin) {
return fetch(target);
}
// We can't replace the headers object, so we need to delete all headers and set them again
request.headers.forEach((_value, key) => {
request.headers.delete(key);
});
target.headers.forEach((value, key) => {
request.headers.set(key, value);
});
return new URL(target.url);
}
return new URL(target, request.url);
};
const next = () => {
const { netlify, ...otherLocals } = ctx.locals;
request.headers.set("x-astro-locals", trySerializeLocals(otherLocals));
Expand Down
8 changes: 4 additions & 4 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
"test": "astro-scripts test \"test/**/*.test.js\""
},
"dependencies": {
"send": "^0.19.0",
"send": "^0.19.1",
"server-destroy": "^1.0.1"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.8"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"@types/node": "^18.19.54",
"@types/node": "^18.19.62",
"@types/send": "^0.17.4",
"@types/server-destroy": "^1.0.4",
"astro": "^5.0.0-alpha.8",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"express": "^4.21.0",
"node-mocks-http": "^1.16.0"
"express": "^4.21.1",
"node-mocks-http": "^1.16.1"
},
"publishConfig": {
"provenance": true
Expand Down
6 changes: 6 additions & 0 deletions packages/vercel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

- [#385](https://github.com/withastro/adapters/pull/385) [`bb725b7`](https://github.com/withastro/adapters/commit/bb725b7a430a01a3cd197e3e84381be4fa0c945c) Thanks [@florian-lefebvre](https://github.com/florian-lefebvre)! - Cleans up `astro:env` support

## 7.8.2

### Patch Changes

- [#373](https://github.com/withastro/adapters/pull/373) [`5b802a4`](https://github.com/withastro/adapters/commit/5b802a4099743c86418747872171bbe224caaa6d) Thanks [@hrabiel](https://github.com/hrabiel)! - Fix excluding routes with rest parameters from ISR

## 7.8.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
},
"dependencies": {
"@astrojs/internal-helpers": "^0.4.1",
"@vercel/analytics": "^1.3.1",
"@vercel/analytics": "^1.3.2",
"@vercel/edge": "^1.1.2",
"@vercel/nft": "^0.27.4",
"@vercel/nft": "^0.27.5",
"esbuild": "^0.21.5",
"fast-glob": "^3.3.2"
},
Expand Down
Loading

0 comments on commit e30c046

Please sign in to comment.