Skip to content

Commit

Permalink
Merge branch 'next' into feat/new-basics
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored Nov 22, 2024
2 parents 27da146 + 82d89a7 commit 4effcbf
Show file tree
Hide file tree
Showing 150 changed files with 1,523 additions and 605 deletions.
50 changes: 50 additions & 0 deletions .changeset/giant-ravens-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
'astro': minor
---

Adds a new `astro:routes:resolved` hook to the Integration API. Also update the `astro:build:done` hook by deprecating `routes` and adding a new `assets` map.

When building an integration, you can now get access to routes inside the `astro:routes:resolved` hook:

```js
const integration = () => {
return {
name: 'my-integration',
hooks: {
'astro:routes:resolved': ({ routes }) => {
console.log(routes)
}
}
}
}
```

This hook runs before `astro:config:done`, and whenever a route changes in development.

The `routes` array from `astro:build:done` is now deprecated, and exposed properties are now available on `astro:routes:resolved`, except for `distURL`. For this, you can use the newly exposed `assets` map:

```diff
const integration = () => {
+ let routes
return {
name: 'my-integration',
hooks: {
+ 'astro:routes:resolved': (params) => {
+ routes = params.routes
+ },
'astro:build:done': ({
- routes
+ assets
}) => {
+ for (const route of routes) {
+ const distURL = assets.get(route.pattern)
+ if (distURL) {
+ Object.assign(route, { distURL })
+ }
+ }
console.log(routes)
}
}
}
}
```
7 changes: 7 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
"afraid-apricots-buy",
"blue-boats-relax",
"blue-sloths-stare",
"blue-socks-doubt",
"brave-elephants-fly",
"breezy-colts-promise",
"brown-bulldogs-share",
"chatty-teachers-sit",
"chilly-terms-know",
"clean-camels-drive",
"clean-donuts-walk",
"clean-moles-rest",
"cold-bananas-hear",
"cool-mangos-shop",
"cuddly-shoes-press",
Expand All @@ -61,6 +64,7 @@
"funny-wolves-dream",
"fuzzy-pugs-live",
"gentle-scissors-bow",
"giant-ravens-look",
"giant-rocks-thank",
"gorgeous-foxes-divide",
"healthy-ads-scream",
Expand Down Expand Up @@ -95,8 +99,10 @@
"poor-seals-clap",
"pretty-walls-camp",
"proud-games-repair",
"proud-terms-swim",
"quick-ads-exercise",
"quick-onions-leave",
"rotten-dodos-judge",
"rotten-phones-scream",
"selfish-cats-crash",
"selfish-impalas-grin",
Expand All @@ -116,6 +122,7 @@
"tame-rats-cross",
"ten-students-repair",
"ten-walls-tap",
"thirty-clocks-jump",
"three-days-cough",
"three-olives-reflect",
"tough-planets-dress",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/rotten-dodos-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Call server island early so it can set headers
7 changes: 7 additions & 0 deletions .changeset/thirty-clocks-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'astro': minor
---

Changes the default content config location from `src/content/config.*` to `src/content.config.*`.

The previous location is still supported, and is required if the `legacy.collections` flag is enabled.
5 changes: 5 additions & 0 deletions .changeset/unlucky-kids-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a regression where Astro was trying to access `Request.headers`
68 changes: 34 additions & 34 deletions .github/scripts/announce.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { globby as glob } from 'globby';
import { fileURLToPath } from 'node:url';
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { globby as glob } from 'globby';
import { setOutput } from './utils.mjs';

const { GITHUB_REF = 'main' } = process.env;
Expand All @@ -18,34 +18,34 @@ const descriptors = [
'updates',
];
const verbs = [
"just went out!",
"just launched!",
"now available!",
"in the wild!",
"now live!",
"hit the registry!",
"to share!",
"for you!",
"for y’all! 🤠",
"comin’ your way!",
"comin’ atcha!",
"comin’ in hot!",
"freshly minted on the blockchain! (jk)",
"[is] out (now with 100% more reticulated splines!)",
"(as seen on TV!)",
"just dropped!",
"– artisanally hand-crafted just for you.",
"– oh happy day!",
"– enjoy!",
"now out. Be the first on your block to download!",
"made with love 💕",
"[is] out! Our best [version] yet!",
"[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!",
"... HUZZAH!",
"[has] landed!",
"landed! The internet just got a little more fun.",
"– from our family to yours.",
"– go forth and build!"
'just went out!',
'just launched!',
'now available!',
'in the wild!',
'now live!',
'hit the registry!',
'to share!',
'for you!',
'for y’all! 🤠',
'comin’ your way!',
'comin’ atcha!',
'comin’ in hot!',
'freshly minted on the blockchain! (jk)',
'[is] out (now with 100% more reticulated splines!)',
'(as seen on TV!)',
'just dropped!',
'– artisanally hand-crafted just for you.',
'– oh happy day!',
'– enjoy!',
'now out. Be the first on your block to download!',
'made with love 💕',
'[is] out! Our best [version] yet!',
'[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!',
'... HUZZAH!',
'[has] landed!',
'landed! The internet just got a little more fun.',
'– from our family to yours.',
'– go forth and build!',
];
const extraVerbs = [
'new',
Expand All @@ -72,7 +72,7 @@ const plurals = new Map([

function pluralize(text) {
return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) =>
plurals.has(match) ? plurals.get(match) : `${match}s`
plurals.has(match) ? plurals.get(match) : `${match}s`,
);
}

Expand All @@ -91,7 +91,7 @@ async function generatePackageMap() {
const pkgFile = fileURLToPath(new URL(pkg, packageRoot));
const content = await readFile(pkgFile).then((res) => JSON.parse(res.toString()));
packageMap.set(content.name, `./packages/${pkg.replace('/package.json', '')}`);
})
}),
);
}

Expand All @@ -110,7 +110,7 @@ async function generateMessage() {
version,
url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString(),
};
})
}),
);

const emoji = item(emojis);
Expand All @@ -122,7 +122,7 @@ async function generateMessage() {
if (packages.length === 1) {
const { name, version, url } = packages[0];
message += `${emoji} \`${name}@${version}\` ${singularlize(
verb
verb,
)}\nRead the [release notes →](<${url}>)\n`;
} else {
message += `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`;
Expand Down
54 changes: 35 additions & 19 deletions .github/scripts/bundle-size.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { build } from 'esbuild';
import { existsSync } from 'node:fs';
import { build } from 'esbuild';

const CLIENT_RUNTIME_PATH = 'packages/astro/src/runtime/client/';

function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 B';
if (bytes === 0) return '0 B';

const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

const i = Math.floor(Math.log(bytes) / Math.log(k));
const i = Math.floor(Math.log(bytes) / Math.log(k));

return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}

export default async function checkBundleSize({ github, context }) {
Expand All @@ -24,7 +24,7 @@ export default async function checkBundleSize({ github, context }) {
pull_number: PR_NUM,
});
const clientRuntimeFiles = files.filter((file) => {
return file.filename.startsWith(CLIENT_RUNTIME_PATH) && file.status !== 'removed'
return file.filename.startsWith(CLIENT_RUNTIME_PATH) && file.status !== 'removed';
});
if (clientRuntimeFiles.length === 0) return;

Expand All @@ -35,17 +35,24 @@ export default async function checkBundleSize({ github, context }) {
const output = await bundle(clientRuntimeFiles);

for (let [filename, { oldSize, newSize, sourceFile }] of Object.entries(output)) {
filename = ['idle', 'load', 'media', 'only', 'visible'].includes(filename) ? `client:${filename}` : filename;
const prefix = (newSize - oldSize) === 0 ? '' : (newSize - oldSize) > 0 ? '+ ' : '- ';
filename = ['idle', 'load', 'media', 'only', 'visible'].includes(filename)
? `client:${filename}`
: filename;
const prefix = newSize - oldSize === 0 ? '' : newSize - oldSize > 0 ? '+ ' : '- ';
const change = `${prefix}${formatBytes(newSize - oldSize)}`;
table.push(`| [\`${filename}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/${context.payload.pull_request.head.ref}/${sourceFile}) | ${formatBytes(oldSize)} | ${formatBytes(newSize)} | ${change} |`);
table.push(
`| [\`${filename}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/${context.payload.pull_request.head.ref}/${sourceFile}) | ${formatBytes(oldSize)} | ${formatBytes(newSize)} | ${change} |`,
);
}

const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number: PR_NUM
})
const comment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('Bundle Size Check'));
issue_number: PR_NUM,
});
const comment = comments.find(
(comment) =>
comment.user.login === 'github-actions[bot]' && comment.body.includes('Bundle Size Check'),
);
const method = comment ? 'updateComment' : 'createComment';
const payload = comment ? { comment_id: comment.id } : { issue_number: PR_NUM };
await github.rest.issues[method]({
Expand All @@ -60,27 +67,36 @@ ${table.join('\n')}`,
}

async function bundle(files) {

const { metafile } = await build({
entryPoints: [...files.map(({ filename }) => filename), ...files.map(({ filename }) => `main/${filename}`).filter(f => existsSync(f))],
entryPoints: [
...files.map(({ filename }) => filename),
...files.map(({ filename }) => `main/${filename}`).filter((f) => existsSync(f)),
],
bundle: true,
minify: true,
sourcemap: false,
target: ['es2018'],
outdir: 'out',
external: ['astro:*', 'aria-query', 'axobject-query'],
metafile: true,
})
});

return Object.entries(metafile.outputs).reduce((acc, [filename, info]) => {
filename = filename.slice('out/'.length);
if (filename.startsWith('main/')) {
filename = filename.slice('main/'.length).replace(CLIENT_RUNTIME_PATH, '').replace('.js', '');
const oldSize = info.bytes;
return Object.assign(acc, { [filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, { oldSize }) });
return Object.assign(acc, {
[filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, { oldSize }),
});
}
filename = filename.replace(CLIENT_RUNTIME_PATH, '').replace('.js', '');
const newSize = info.bytes;
return Object.assign(acc, { [filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, { newSize, sourceFile: Object.keys(info.inputs).find(src => src.endsWith('.ts')) }) });
return Object.assign(acc, {
[filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, {
newSize,
sourceFile: Object.keys(info.inputs).find((src) => src.endsWith('.ts')),
}),
});
}, {});
}
Loading

0 comments on commit 4effcbf

Please sign in to comment.