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 1, 2024
2 parents 7d83f60 + dd6a7c9 commit 9730bbf
Show file tree
Hide file tree
Showing 32 changed files with 792 additions and 707 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.8.3/schema.json",
"$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
"files": {
"ignore": [
"**/dist",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@
},
"devDependencies": {
"@astrojs/check": "^0.9.3",
"@biomejs/biome": "1.8.3",
"@biomejs/biome": "1.9.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.8",
"@types/node": "^20.16.5",
"@types/node": "^20.16.10",
"esbuild": "^0.21.5",
"eslint": "^9.10.0",
"eslint": "^9.11.1",
"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.1",
"typescript": "^5.5.4",
"typescript-eslint": "^8.4.0"
"turbo": "^2.1.3",
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.0"
}
}
12 changes: 12 additions & 0 deletions packages/cloudflare/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@

- [#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.1.0

### Minor Changes

- [#394](https://github.com/withastro/adapters/pull/394) [`44dfa99`](https://github.com/withastro/adapters/commit/44dfa9935e22edab16490d625a88aaa0f1942a19) Thanks [@veitbjarsch](https://github.com/veitbjarsch)! - Added functionality to compare include and exclude rules to reduce the amount of cloudflare rules

## 11.0.5

### Patch Changes

- [#387](https://github.com/withastro/adapters/pull/387) [`04e5c38`](https://github.com/withastro/adapters/commit/04e5c389f251efa02fe7b973ed95cdc61fad3389) Thanks [@veitbjarsch](https://github.com/veitbjarsch)! - Fixes a bug which was caused on windows when splitting static file paths

## 11.0.4

### Patch Changes
Expand Down
12 changes: 6 additions & 6 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.20240903.0",
"@cloudflare/workers-types": "^4.20240925.0",
"esbuild": "^0.23.1",
"estree-walker": "^3.0.3",
"magic-string": "^0.30.11",
"miniflare": "^3.20240821.1",
"miniflare": "^3.20240925.0",
"tiny-glob": "^0.2.9",
"wrangler": "^3.75.0",
"@inox-tools/astro-when": "^0.2.2"
"wrangler": "^3.78.12",
"@inox-tools/astro-when": "^0.2.3"
},
"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.21.2",
"rollup": "^4.22.5",
"strip-ansi": "^7.1.0",
"vite": "^5.4.3"
"vite": "^5.4.8"
},
"publishConfig": {
"provenance": true
Expand Down
41 changes: 36 additions & 5 deletions packages/cloudflare/src/utils/generate-routes-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AstroConfig, AstroIntegrationLogger, IntegrationRouteData, RoutePa

import { existsSync } from 'node:fs';
import { writeFile } from 'node:fs/promises';
import { posix } from 'node:path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import {
prependForwardSlash,
Expand Down Expand Up @@ -128,6 +128,31 @@ class PathTrie {
}
}

/**
* The reduce function is used to remove unnecessary paths from the trie.
* It receives a trie node to compare with the current node.
*/
private reduce(compNode: TrieNode, node: TrieNode): void {
if (node.hasWildcardChild || compNode.hasWildcardChild) return;

for (const [segment, childNode] of node.children) {
if (childNode.children.size === 0) continue;

const compChildNode = compNode.children.get(segment);
if (compChildNode === undefined) {
childNode.hasWildcardChild = true;
continue;
}

this.reduce(compChildNode, childNode);
}
}

reduceAllPaths(compTrie: PathTrie): this {
this.reduce(compTrie.root, this.root);
return this;
}

getAllPaths(): [string[][], boolean] {
const allPaths: string[][] = [];
this.dfs(this.root, [], allPaths);
Expand Down Expand Up @@ -186,7 +211,7 @@ export async function createRoutesFile(
const staticPath = staticFile;

const segments = removeLeadingForwardSlash(staticPath)
.split(posix.sep)
.split(path.sep)
.filter(Boolean)
.map((s: string) => {
return getParts(s);
Expand Down Expand Up @@ -232,7 +257,7 @@ export async function createRoutesFile(
for (const page of pages) {
if (page.pathname === '404') hasPrerendered404 = true;
const pageSegments = removeLeadingForwardSlash(page.pathname)
.split(posix.sep)
.split(path.posix.sep)
.filter(Boolean)
.map((s) => {
return getParts(s);
Expand All @@ -244,7 +269,6 @@ export async function createRoutesFile(
for (const includePath of includePaths) {
includeTrie.insert(includePath);
}
const [deduplicatedIncludePaths, includedPathsHaveWildcard] = includeTrie.getAllPaths();

const excludeTrie = new PathTrie();
for (const excludePath of excludePaths) {
Expand All @@ -256,7 +280,14 @@ export async function createRoutesFile(
if (excludePath[0] === '*') continue;
excludeTrie.insert(excludePath);
}
const [deduplicatedExcludePaths, _excludedPathsHaveWildcard] = excludeTrie.getAllPaths();

const [deduplicatedIncludePaths, includedPathsHaveWildcard] = includeTrie
.reduceAllPaths(excludeTrie)
.getAllPaths();

const [deduplicatedExcludePaths, _excludedPathsHaveWildcard] = excludeTrie
.reduceAllPaths(includeTrie)
.getAllPaths();

/**
* Cloudflare allows no more than 100 include/exclude rules combined
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.75.0"
"wrangler": "^3.78.12"
}
}
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.75.0"
"wrangler": "^3.78.12"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="../../.astro/types.d.ts" />
/// <reference types="astro/client" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
export const prerender = true;
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender=false;
---

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

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

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

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

ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender=true;
---

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

ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender=true;
---

ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender=true;
---

ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender=true;
---

ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender=true;
---

ok
4 changes: 2 additions & 2 deletions packages/cloudflare/test/fixtures/with-solid-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"@astrojs/solid-js": "^4.4.1",
"@astrojs/solid-js": "^4.4.2",
"astro": "^5.0.0-alpha.8",
"solid-js": "^1.8.21"
"solid-js": "^1.9.1"
}
}
41 changes: 40 additions & 1 deletion packages/cloudflare/test/routes-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('_routes.json generation', () => {
assert.deepEqual(routes, {
version: 1,
include: ['/*'],
exclude: ['/_astro/*', '/redirectme', '/public.txt', '/a/redirect'],
exclude: ['/_astro/*', '/redirectme', '/public.txt', '/a/*'],
});
});
});
Expand Down Expand Up @@ -146,4 +146,43 @@ describe('_routes.json generation', () => {
});
});
});

describe('with nested on demand and prerendered routes', () => {
let fixture;

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

it('reduces the amount of include and exclude entries by applying wildcards wherever possible', async () => {
const _routesJson = await fixture.readFile('/_routes.json');
const routes = JSON.parse(_routesJson);

assert.deepEqual(routes, {
version: 1,
include: [
'/',
'/dynamicPages/*',
'/mixedPages/dynamic',
'/mixedPages/subfolder/dynamic',
'/_image',
],
exclude: [
'/_astro/*',
'/redirectme',
'/public.txt',
'/a/*',
'/404',
'/mixedPages/static',
'/mixedPages/subfolder/static',
'/staticPages/*',
],
});
});
});
});
8 changes: 4 additions & 4 deletions packages/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@
"@netlify/functions": "^2.8.0",
"@vercel/nft": "^0.27.4",
"esbuild": "^0.21.5",
"vite": "^5.4.2"
"vite": "^5.4.8"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.8"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"@netlify/edge-functions": "^2.10.0",
"@netlify/edge-functions": "^2.11.0",
"@netlify/edge-handler-types": "^0.34.1",
"@types/node": "^20.16.1",
"@types/node": "^20.16.10",
"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.5.4"
"typescript": "^5.6.2"
},
"astro": {
"external": true
Expand Down
2 changes: 1 addition & 1 deletion packages/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export default function netlifyIntegration(
ip:
typeof req.headers['x-nf-client-connection-ip'] === 'string'
? req.headers['x-nf-client-connection-ip']
: req.socket.remoteAddress ?? '127.0.0.1',
: (req.socket.remoteAddress ?? '127.0.0.1'),
server: {
region: 'local-dev',
},
Expand Down
12 changes: 12 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
- Updated dependencies [[`b6fbdaa`](https://github.com/withastro/astro/commit/b6fbdaa94a9ecec706a99e1938fbf5cd028c72e0), [`89bab1e`](https://github.com/withastro/astro/commit/89bab1e70786123fbe933a9d7a1b80c9334dcc5f), [`d74617c`](https://github.com/withastro/astro/commit/d74617cbd3278feba05909ec83db2d73d57a153e), [`e90f559`](https://github.com/withastro/astro/commit/e90f5593d23043579611452a84b9e18ad2407ef9), [`2df49a6`](https://github.com/withastro/astro/commit/2df49a6fb4f6d92fe45f7429430abe63defeacd6), [`8a53517`](https://github.com/withastro/astro/commit/8a5351737d6a14fc55f1dafad8f3b04079e81af6)]:
- astro@5.0.0-alpha.0

## 8.3.4

### Patch Changes

- [#398](https://github.com/withastro/adapters/pull/398) [`0cf7e91`](https://github.com/withastro/adapters/commit/0cf7e912607fcd76072bf710b8f857dc8cc07a33) Thanks [@bluwy](https://github.com/bluwy)! - Updates `send` dependency to 0.19.0

## 8.3.4

### Patch Changes

- [#398](https://github.com/withastro/adapters/pull/398) [`0cf7e91`](https://github.com/withastro/adapters/commit/0cf7e912607fcd76072bf710b8f857dc8cc07a33) Thanks [@bluwy](https://github.com/bluwy)! - Updates `send` dependency to 0.19.0

## 8.3.3

### Patch Changes
Expand Down
Loading

0 comments on commit 9730bbf

Please sign in to comment.