From 67e06f9db1b0492ccfb4b053762dc91d69a53ecb Mon Sep 17 00:00:00 2001 From: Canaris Date: Tue, 2 Jan 2024 22:52:22 +0800 Subject: [PATCH 01/19] `yarn add` should be used to install packages instead of `yarn install` (#9562) Co-authored-by: Bjorn Lu Co-authored-by: Florian Lefebvre --- .changeset/poor-cars-battle.md | 5 +++++ packages/upgrade/src/actions/install.ts | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/poor-cars-battle.md diff --git a/.changeset/poor-cars-battle.md b/.changeset/poor-cars-battle.md new file mode 100644 index 000000000000..5832e363cadd --- /dev/null +++ b/.changeset/poor-cars-battle.md @@ -0,0 +1,5 @@ +--- +"@astrojs/upgrade": patch +--- + +Updates the command used for installing packages with pnpm and yarn diff --git a/packages/upgrade/src/actions/install.ts b/packages/upgrade/src/actions/install.ts index 3f343463fadf..14011a07ee7d 100644 --- a/packages/upgrade/src/actions/install.ts +++ b/packages/upgrade/src/actions/install.ts @@ -123,6 +123,8 @@ async function runInstallCommand( const cwd = fileURLToPath(ctx.cwd); if (ctx.packageManager === 'yarn') await ensureYarnLock({ cwd }); + const installCmd = ctx.packageManager === 'yarn' || ctx.packageManager === 'pnpm' ? 'add' : 'install'; + await spinner({ start: `Installing dependencies with ${ctx.packageManager}...`, end: `Installed dependencies!`, @@ -132,7 +134,7 @@ async function runInstallCommand( await shell( ctx.packageManager, [ - 'install', + installCmd, ...dependencies.map( ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, '')}` ), @@ -144,7 +146,7 @@ async function runInstallCommand( await shell( ctx.packageManager, [ - 'install', + installCmd, '--save-dev', ...devDependencies.map( ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, '')}` @@ -161,7 +163,7 @@ async function runInstallCommand( error( 'error', `Dependencies failed to install, please run the following command manually:\n${color.bold( - `${ctx.packageManager} install ${packages}` + `${ctx.packageManager} ${installCmd} ${packages}` )}` ); return ctx.exit(1); From f192fc3a35872cb187cf631c62fa5b44f004242b Mon Sep 17 00:00:00 2001 From: Canaris Date: Tue, 2 Jan 2024 14:53:17 +0000 Subject: [PATCH 02/19] [ci] format --- packages/upgrade/src/actions/install.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/upgrade/src/actions/install.ts b/packages/upgrade/src/actions/install.ts index 14011a07ee7d..3c294a8ee2a5 100644 --- a/packages/upgrade/src/actions/install.ts +++ b/packages/upgrade/src/actions/install.ts @@ -123,7 +123,8 @@ async function runInstallCommand( const cwd = fileURLToPath(ctx.cwd); if (ctx.packageManager === 'yarn') await ensureYarnLock({ cwd }); - const installCmd = ctx.packageManager === 'yarn' || ctx.packageManager === 'pnpm' ? 'add' : 'install'; + const installCmd = + ctx.packageManager === 'yarn' || ctx.packageManager === 'pnpm' ? 'add' : 'install'; await spinner({ start: `Installing dependencies with ${ctx.packageManager}...`, From ec71f03cfd9b8195fb21c92dfda0eff63b6ebeed Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Tue, 2 Jan 2024 22:14:09 +0700 Subject: [PATCH 03/19] Remove telemetry for unhandled errors (#9571) --- .changeset/few-days-relate.md | 5 +++++ packages/astro/src/vite-plugin-astro-server/error.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/few-days-relate.md diff --git a/.changeset/few-days-relate.md b/.changeset/few-days-relate.md new file mode 100644 index 000000000000..836e033e3451 --- /dev/null +++ b/.changeset/few-days-relate.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Removes telemetry for unhandled errors in the dev server diff --git a/packages/astro/src/vite-plugin-astro-server/error.ts b/packages/astro/src/vite-plugin-astro-server/error.ts index cbab6e7be090..7c478fc6eb68 100644 --- a/packages/astro/src/vite-plugin-astro-server/error.ts +++ b/packages/astro/src/vite-plugin-astro-server/error.ts @@ -3,7 +3,7 @@ import type { AstroConfig } from '../@types/astro.js'; import type DevPipeline from './devPipeline.js'; import { collectErrorMetadata } from '../core/errors/dev/index.js'; -import { createSafeError } from '../core/errors/index.js'; +import { createSafeError, AstroErrorData } from '../core/errors/index.js'; import { formatErrorMessage } from '../core/messages.js'; import { eventError, telemetry } from '../events/index.js'; @@ -24,7 +24,10 @@ export function recordServerError( // Our error should already be complete, but let's try to add a bit more through some guesswork const errorWithMetadata = collectErrorMetadata(err, config.root); - telemetry.record(eventError({ cmd: 'dev', err: errorWithMetadata, isFatal: false })); + // Ignore unhandled rejection errors as they appear A LOT and we cannot record the amount to telemetry + if (errorWithMetadata.name !== AstroErrorData.UnhandledRejection.name) { + telemetry.record(eventError({ cmd: 'dev', err: errorWithMetadata, isFatal: false })); + } pipeline.logger.error( null, From d85433057189ed6dc599be007125c225face763e Mon Sep 17 00:00:00 2001 From: "Houston (Bot)" <108291165+astrobot-houston@users.noreply.github.com> Date: Tue, 2 Jan 2024 07:26:33 -0800 Subject: [PATCH 04/19] [ci] release (#9541) Co-authored-by: github-actions[bot] --- .changeset/few-days-relate.md | 5 -- .changeset/great-beans-check.md | 5 -- .changeset/ninety-buses-occur.md | 5 -- .changeset/olive-sloths-brush.md | 5 -- .changeset/plenty-dingos-relax.md | 5 -- .changeset/poor-cars-battle.md | 5 -- .changeset/quiet-weeks-teach.md | 5 -- .changeset/silent-wasps-learn.md | 5 -- .changeset/sixty-bugs-unite.md | 5 -- .changeset/small-snakes-build.md | 5 -- .changeset/tall-mayflies-deliver.md | 5 -- .changeset/weak-oranges-relate.md | 5 -- .changeset/yellow-yaks-promise.md | 5 -- examples/basics/package.json | 2 +- examples/blog/package.json | 2 +- examples/component/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 2 +- examples/framework-multiple/package.json | 4 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 2 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 2 +- examples/framework-vue/package.json | 4 +- examples/hackernews/package.json | 4 +- examples/integration/package.json | 2 +- examples/middleware/package.json | 4 +- examples/minimal/package.json | 2 +- examples/non-html-pages/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 4 +- examples/starlog/package.json | 2 +- examples/view-transitions/package.json | 4 +- examples/with-markdoc/package.json | 2 +- examples/with-markdown-plugins/package.json | 2 +- examples/with-markdown-shiki/package.json | 2 +- examples/with-mdx/package.json | 2 +- examples/with-nanostores/package.json | 2 +- examples/with-tailwindcss/package.json | 2 +- examples/with-vitest/package.json | 2 +- packages/astro/CHANGELOG.md | 22 +++++++ packages/astro/package.json | 2 +- packages/integrations/node/CHANGELOG.md | 6 ++ packages/integrations/node/package.json | 2 +- packages/integrations/vercel/CHANGELOG.md | 6 ++ packages/integrations/vercel/package.json | 2 +- packages/integrations/vue/CHANGELOG.md | 6 ++ packages/integrations/vue/package.json | 2 +- packages/upgrade/CHANGELOG.md | 6 ++ packages/upgrade/package.json | 2 +- pnpm-lock.yaml | 66 ++++++++++----------- 51 files changed, 117 insertions(+), 136 deletions(-) delete mode 100644 .changeset/few-days-relate.md delete mode 100644 .changeset/great-beans-check.md delete mode 100644 .changeset/ninety-buses-occur.md delete mode 100644 .changeset/olive-sloths-brush.md delete mode 100644 .changeset/plenty-dingos-relax.md delete mode 100644 .changeset/poor-cars-battle.md delete mode 100644 .changeset/quiet-weeks-teach.md delete mode 100644 .changeset/silent-wasps-learn.md delete mode 100644 .changeset/sixty-bugs-unite.md delete mode 100644 .changeset/small-snakes-build.md delete mode 100644 .changeset/tall-mayflies-deliver.md delete mode 100644 .changeset/weak-oranges-relate.md delete mode 100644 .changeset/yellow-yaks-promise.md diff --git a/.changeset/few-days-relate.md b/.changeset/few-days-relate.md deleted file mode 100644 index 836e033e3451..000000000000 --- a/.changeset/few-days-relate.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Removes telemetry for unhandled errors in the dev server diff --git a/.changeset/great-beans-check.md b/.changeset/great-beans-check.md deleted file mode 100644 index 69e188bd0a79..000000000000 --- a/.changeset/great-beans-check.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fixes error overlay display on URI malformed error diff --git a/.changeset/ninety-buses-occur.md b/.changeset/ninety-buses-occur.md deleted file mode 100644 index 52265a036129..000000000000 --- a/.changeset/ninety-buses-occur.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@astrojs/vue": patch ---- - -Fixes support for async `appEntrypoint` diff --git a/.changeset/olive-sloths-brush.md b/.changeset/olive-sloths-brush.md deleted file mode 100644 index 574af00902b0..000000000000 --- a/.changeset/olive-sloths-brush.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@astrojs/node': patch ---- - -Fixes a bug where an error while serving response stopped the server. diff --git a/.changeset/plenty-dingos-relax.md b/.changeset/plenty-dingos-relax.md deleted file mode 100644 index 4bb328ee1cf6..000000000000 --- a/.changeset/plenty-dingos-relax.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Implement i18n's `getLocaleByPath` function diff --git a/.changeset/poor-cars-battle.md b/.changeset/poor-cars-battle.md deleted file mode 100644 index 5832e363cadd..000000000000 --- a/.changeset/poor-cars-battle.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@astrojs/upgrade": patch ---- - -Updates the command used for installing packages with pnpm and yarn diff --git a/.changeset/quiet-weeks-teach.md b/.changeset/quiet-weeks-teach.md deleted file mode 100644 index bfbbb737c168..000000000000 --- a/.changeset/quiet-weeks-teach.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Prevents ANSI codes from rendering in the error overlay diff --git a/.changeset/silent-wasps-learn.md b/.changeset/silent-wasps-learn.md deleted file mode 100644 index 60f8d4c0efc9..000000000000 --- a/.changeset/silent-wasps-learn.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Toggle dev toolbar hitbox height when toolbar is visible diff --git a/.changeset/sixty-bugs-unite.md b/.changeset/sixty-bugs-unite.md deleted file mode 100644 index 167cc4aa7543..000000000000 --- a/.changeset/sixty-bugs-unite.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Documents supported `--host` and `--port` flags in `astro preview --help` diff --git a/.changeset/small-snakes-build.md b/.changeset/small-snakes-build.md deleted file mode 100644 index 9f1c9f8ac0ec..000000000000 --- a/.changeset/small-snakes-build.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fixes remote images with encoded characters diff --git a/.changeset/tall-mayflies-deliver.md b/.changeset/tall-mayflies-deliver.md deleted file mode 100644 index 736aeb0d03b4..000000000000 --- a/.changeset/tall-mayflies-deliver.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Adds 'starlight' to the displayed options for `astro add` diff --git a/.changeset/weak-oranges-relate.md b/.changeset/weak-oranges-relate.md deleted file mode 100644 index c61c4b7e05e8..000000000000 --- a/.changeset/weak-oranges-relate.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -`` srcset now parses encoded paths correctly diff --git a/.changeset/yellow-yaks-promise.md b/.changeset/yellow-yaks-promise.md deleted file mode 100644 index 2b9aa21ff90c..000000000000 --- a/.changeset/yellow-yaks-promise.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@astrojs/vercel": patch ---- - -Fixes an issue where a build could not complete on Node 21. diff --git a/examples/basics/package.json b/examples/basics/package.json index ff55e0d315af..8ed1da076d0a 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.0.8" + "astro": "^4.0.9" } } diff --git a/examples/blog/package.json b/examples/blog/package.json index 6e0bd7a2cf9e..cd925738056a 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -14,6 +14,6 @@ "@astrojs/mdx": "^2.0.3", "@astrojs/rss": "^4.0.1", "@astrojs/sitemap": "^3.0.4", - "astro": "^4.0.8" + "astro": "^4.0.9" } } diff --git a/examples/component/package.json b/examples/component/package.json index 67ec5a3a801d..728c58c0d824 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^4.0.8" + "astro": "^4.0.9" }, "peerDependencies": { "astro": "^3.0.0" diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index da02b10cec53..2651136e3052 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -14,6 +14,6 @@ "@astrojs/alpinejs": "^0.3.2", "@types/alpinejs": "^3.13.5", "alpinejs": "^3.13.3", - "astro": "^4.0.8" + "astro": "^4.0.9" } } diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index a12879c13052..212c4b7f2788 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/lit": "^4.0.1", "@webcomponents/template-shadowroot": "^0.2.1", - "astro": "^4.0.8", + "astro": "^4.0.9", "lit": "^2.8.0" } } diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index 235c0015ef11..c6bdb4fd9cd0 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -15,8 +15,8 @@ "@astrojs/react": "^3.0.9", "@astrojs/solid-js": "^3.0.3", "@astrojs/svelte": "^5.0.3", - "@astrojs/vue": "^4.0.6", - "astro": "^4.0.8", + "@astrojs/vue": "^4.0.7", + "astro": "^4.0.9", "preact": "^10.19.2", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 182488e94ae6..1d15b0b91fa8 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/preact": "^3.0.2", "@preact/signals": "^1.2.1", - "astro": "^4.0.8", + "astro": "^4.0.9", "preact": "^10.19.2" } } diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index c82665504727..6876397bd2c1 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -14,7 +14,7 @@ "@astrojs/react": "^3.0.9", "@types/react": "^18.2.37", "@types/react-dom": "^18.2.15", - "astro": "^4.0.8", + "astro": "^4.0.9", "react": "^18.2.0", "react-dom": "^18.2.0" } diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index a872508abefa..1ac1ac9af5be 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/solid-js": "^3.0.3", - "astro": "^4.0.8", + "astro": "^4.0.9", "solid-js": "^1.8.5" } } diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 86e67d122441..d7f859642fca 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/svelte": "^5.0.3", - "astro": "^4.0.8", + "astro": "^4.0.9", "svelte": "^4.2.5" } } diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 29ad35c9275e..b8f46c7d53cc 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -11,8 +11,8 @@ "astro": "astro" }, "dependencies": { - "@astrojs/vue": "^4.0.6", - "astro": "^4.0.8", + "@astrojs/vue": "^4.0.7", + "astro": "^4.0.9", "vue": "^3.3.8" } } diff --git a/examples/hackernews/package.json b/examples/hackernews/package.json index b10f2aaeba20..10e2cef66f85 100644 --- a/examples/hackernews/package.json +++ b/examples/hackernews/package.json @@ -11,7 +11,7 @@ "astro": "astro" }, "dependencies": { - "@astrojs/node": "^7.0.3", - "astro": "^4.0.8" + "@astrojs/node": "^7.0.4", + "astro": "^4.0.9" } } diff --git a/examples/integration/package.json b/examples/integration/package.json index cac406ddca81..914397e0ce9a 100644 --- a/examples/integration/package.json +++ b/examples/integration/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^4.0.8" + "astro": "^4.0.9" }, "peerDependencies": { "astro": "^3.0.0" diff --git a/examples/middleware/package.json b/examples/middleware/package.json index 69424f74c935..ea19c7a8732c 100644 --- a/examples/middleware/package.json +++ b/examples/middleware/package.json @@ -12,8 +12,8 @@ "server": "node dist/server/entry.mjs" }, "dependencies": { - "@astrojs/node": "^7.0.3", - "astro": "^4.0.8", + "@astrojs/node": "^7.0.4", + "astro": "^4.0.9", "html-minifier": "^4.0.0" }, "devDependencies": { diff --git a/examples/minimal/package.json b/examples/minimal/package.json index 860897d1bf8b..233f0474fa87 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.0.8" + "astro": "^4.0.9" } } diff --git a/examples/non-html-pages/package.json b/examples/non-html-pages/package.json index 2a1c4d61a8e4..d86fb3091afa 100644 --- a/examples/non-html-pages/package.json +++ b/examples/non-html-pages/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.0.8" + "astro": "^4.0.9" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 3332fc3a332e..e3afa006c0ae 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.0.8" + "astro": "^4.0.9" } } diff --git a/examples/ssr/package.json b/examples/ssr/package.json index 7ed70e2bf89d..5167af81f990 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -12,9 +12,9 @@ "server": "node dist/server/entry.mjs" }, "dependencies": { - "@astrojs/node": "^7.0.3", + "@astrojs/node": "^7.0.4", "@astrojs/svelte": "^5.0.3", - "astro": "^4.0.8", + "astro": "^4.0.9", "svelte": "^4.2.5" } } diff --git a/examples/starlog/package.json b/examples/starlog/package.json index 8975eaa5cd03..97ddbf059f72 100644 --- a/examples/starlog/package.json +++ b/examples/starlog/package.json @@ -10,7 +10,7 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.0.5", + "astro": "^4.0.9", "sass": "^1.69.5", "sharp": "^0.32.5" } diff --git a/examples/view-transitions/package.json b/examples/view-transitions/package.json index 51069d03d0a6..42cdc61788a4 100644 --- a/examples/view-transitions/package.json +++ b/examples/view-transitions/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@astrojs/tailwind": "^5.1.0", - "@astrojs/node": "^7.0.3", - "astro": "^4.0.8" + "@astrojs/node": "^7.0.4", + "astro": "^4.0.9" } } diff --git a/examples/with-markdoc/package.json b/examples/with-markdoc/package.json index 3a256c74cb5c..714bf0c5463c 100644 --- a/examples/with-markdoc/package.json +++ b/examples/with-markdoc/package.json @@ -12,6 +12,6 @@ }, "dependencies": { "@astrojs/markdoc": "^0.8.2", - "astro": "^4.0.8" + "astro": "^4.0.9" } } diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json index 070443067aa9..bdcee218cfec 100644 --- a/examples/with-markdown-plugins/package.json +++ b/examples/with-markdown-plugins/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/markdown-remark": "^4.0.1", - "astro": "^4.0.8", + "astro": "^4.0.9", "hast-util-select": "^6.0.2", "rehype-autolink-headings": "^7.1.0", "rehype-slug": "^6.0.0", diff --git a/examples/with-markdown-shiki/package.json b/examples/with-markdown-shiki/package.json index 562d476ee881..d0b6da252f4b 100644 --- a/examples/with-markdown-shiki/package.json +++ b/examples/with-markdown-shiki/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.0.8" + "astro": "^4.0.9" } } diff --git a/examples/with-mdx/package.json b/examples/with-mdx/package.json index 016370f40d0a..4a53e0b2224c 100644 --- a/examples/with-mdx/package.json +++ b/examples/with-mdx/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/mdx": "^2.0.3", "@astrojs/preact": "^3.0.2", - "astro": "^4.0.8", + "astro": "^4.0.9", "preact": "^10.19.2" } } diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index 86a6305f4d88..1d143b844e69 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/preact": "^3.0.2", "@nanostores/preact": "^0.5.0", - "astro": "^4.0.8", + "astro": "^4.0.9", "nanostores": "^0.9.5", "preact": "^10.19.2" } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index c497f3f8a3f0..61f7bf8f30d3 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -14,7 +14,7 @@ "@astrojs/mdx": "^2.0.3", "@astrojs/tailwind": "^5.1.0", "@types/canvas-confetti": "^1.6.3", - "astro": "^4.0.8", + "astro": "^4.0.9", "autoprefixer": "^10.4.15", "canvas-confetti": "^1.9.1", "postcss": "^8.4.28", diff --git a/examples/with-vitest/package.json b/examples/with-vitest/package.json index ff523da7d7cb..ccc9e6004966 100644 --- a/examples/with-vitest/package.json +++ b/examples/with-vitest/package.json @@ -12,7 +12,7 @@ "test": "vitest" }, "dependencies": { - "astro": "^4.0.8", + "astro": "^4.0.9", "vitest": "^0.34.2" } } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 86a1df59a10c..5afff3ce0421 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,27 @@ # astro +## 4.0.9 + +### Patch Changes + +- [#9571](https://github.com/withastro/astro/pull/9571) [`ec71f03cfd9b8195fb21c92dfda0eff63b6ebeed`](https://github.com/withastro/astro/commit/ec71f03cfd9b8195fb21c92dfda0eff63b6ebeed) Thanks [@bluwy](https://github.com/bluwy)! - Removes telemetry for unhandled errors in the dev server + +- [#9548](https://github.com/withastro/astro/pull/9548) [`8049f0cd91b239c52e37d571e3ba3e703cf0e4cf`](https://github.com/withastro/astro/commit/8049f0cd91b239c52e37d571e3ba3e703cf0e4cf) Thanks [@bluwy](https://github.com/bluwy)! - Fixes error overlay display on URI malformed error + +- [#9504](https://github.com/withastro/astro/pull/9504) [`8cc3d6aa46f438d668516539c34b48ad748ade39`](https://github.com/withastro/astro/commit/8cc3d6aa46f438d668516539c34b48ad748ade39) Thanks [@matiboux](https://github.com/matiboux)! - Implement i18n's `getLocaleByPath` function + +- [#9547](https://github.com/withastro/astro/pull/9547) [`22f42d11a4fd2e154a0c5873c4f516584e383b70`](https://github.com/withastro/astro/commit/22f42d11a4fd2e154a0c5873c4f516584e383b70) Thanks [@bluwy](https://github.com/bluwy)! - Prevents ANSI codes from rendering in the error overlay + +- [#9446](https://github.com/withastro/astro/pull/9446) [`ede3f7fef6b43a08c9371f7a2531e2eef858b94d`](https://github.com/withastro/astro/commit/ede3f7fef6b43a08c9371f7a2531e2eef858b94d) Thanks [@alexnguyennz](https://github.com/alexnguyennz)! - Toggle dev toolbar hitbox height when toolbar is visible + +- [#9572](https://github.com/withastro/astro/pull/9572) [`9f6453cf4972ac28eec4f07a1373feaa295c8864`](https://github.com/withastro/astro/commit/9f6453cf4972ac28eec4f07a1373feaa295c8864) Thanks [@bluwy](https://github.com/bluwy)! - Documents supported `--host` and `--port` flags in `astro preview --help` + +- [#9540](https://github.com/withastro/astro/pull/9540) [`7f212f0831d8cd899a86fb94899a7cad8ec280db`](https://github.com/withastro/astro/commit/7f212f0831d8cd899a86fb94899a7cad8ec280db) Thanks [@matthewp](https://github.com/matthewp)! - Fixes remote images with encoded characters + +- [#9559](https://github.com/withastro/astro/pull/9559) [`8b873bf1f343efc1f486d8ef53c38380e2373c08`](https://github.com/withastro/astro/commit/8b873bf1f343efc1f486d8ef53c38380e2373c08) Thanks [@sygint](https://github.com/sygint)! - Adds 'starlight' to the displayed options for `astro add` + +- [#9537](https://github.com/withastro/astro/pull/9537) [`16e61fcacb98e6bd948ac240bc082659d70193a4`](https://github.com/withastro/astro/commit/16e61fcacb98e6bd948ac240bc082659d70193a4) Thanks [@walter9388](https://github.com/walter9388)! - `` srcset now parses encoded paths correctly + ## 4.0.8 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index 370c5f829cda..771289fe6df8 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "4.0.8", + "version": "4.0.9", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/packages/integrations/node/CHANGELOG.md b/packages/integrations/node/CHANGELOG.md index 2a37ae6f8bdc..6710489242a4 100644 --- a/packages/integrations/node/CHANGELOG.md +++ b/packages/integrations/node/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/node +## 7.0.4 + +### Patch Changes + +- [#9533](https://github.com/withastro/astro/pull/9533) [`48f47b50a0f8bc0fa51760215def36640f79050d`](https://github.com/withastro/astro/commit/48f47b50a0f8bc0fa51760215def36640f79050d) Thanks [@lilnasy](https://github.com/lilnasy)! - Fixes a bug where an error while serving response stopped the server. + ## 7.0.3 ### Patch Changes diff --git a/packages/integrations/node/package.json b/packages/integrations/node/package.json index f2ed4f2e5658..c3d952840ad2 100644 --- a/packages/integrations/node/package.json +++ b/packages/integrations/node/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/node", "description": "Deploy your site to a Node.js server", - "version": "7.0.3", + "version": "7.0.4", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/packages/integrations/vercel/CHANGELOG.md b/packages/integrations/vercel/CHANGELOG.md index d2aec2e35efc..ab0008526742 100644 --- a/packages/integrations/vercel/CHANGELOG.md +++ b/packages/integrations/vercel/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/vercel +## 6.1.2 + +### Patch Changes + +- [#9550](https://github.com/withastro/astro/pull/9550) [`7b586a6e23e25653814db9adea9674ec3a9bd535`](https://github.com/withastro/astro/commit/7b586a6e23e25653814db9adea9674ec3a9bd535) Thanks [@lilnasy](https://github.com/lilnasy)! - Fixes an issue where a build could not complete on Node 21. + ## 6.1.1 ### Patch Changes diff --git a/packages/integrations/vercel/package.json b/packages/integrations/vercel/package.json index bf779881c90c..3c48a6039aad 100644 --- a/packages/integrations/vercel/package.json +++ b/packages/integrations/vercel/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/vercel", "description": "Deploy your site to Vercel", - "version": "6.1.1", + "version": "6.1.2", "type": "module", "author": "withastro", "license": "MIT", diff --git a/packages/integrations/vue/CHANGELOG.md b/packages/integrations/vue/CHANGELOG.md index 40d3bb15c70f..5eff4621140a 100644 --- a/packages/integrations/vue/CHANGELOG.md +++ b/packages/integrations/vue/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/vue +## 4.0.7 + +### Patch Changes + +- [#9558](https://github.com/withastro/astro/pull/9558) [`e496b2e3b84b673b81c872dad9a6b3f9dd32396a`](https://github.com/withastro/astro/commit/e496b2e3b84b673b81c872dad9a6b3f9dd32396a) Thanks [@michaelhthomas](https://github.com/michaelhthomas)! - Fixes support for async `appEntrypoint` + ## 4.0.6 ### Patch Changes diff --git a/packages/integrations/vue/package.json b/packages/integrations/vue/package.json index 1f59c3e9a237..73cd606a5594 100644 --- a/packages/integrations/vue/package.json +++ b/packages/integrations/vue/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/vue", - "version": "4.0.6", + "version": "4.0.7", "description": "Use Vue components within Astro", "type": "module", "types": "./dist/index.d.ts", diff --git a/packages/upgrade/CHANGELOG.md b/packages/upgrade/CHANGELOG.md index e39000145f31..e4a21db5e096 100644 --- a/packages/upgrade/CHANGELOG.md +++ b/packages/upgrade/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/upgrade +## 0.2.2 + +### Patch Changes + +- [#9562](https://github.com/withastro/astro/pull/9562) [`67e06f9db1b0492ccfb4b053762dc91d69a53ecb`](https://github.com/withastro/astro/commit/67e06f9db1b0492ccfb4b053762dc91d69a53ecb) Thanks [@DET171](https://github.com/DET171)! - Updates the command used for installing packages with pnpm and yarn + ## 0.2.1 ### Patch Changes diff --git a/packages/upgrade/package.json b/packages/upgrade/package.json index fb765e47b37f..802b180157ec 100644 --- a/packages/upgrade/package.json +++ b/packages/upgrade/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/upgrade", - "version": "0.2.1", + "version": "0.2.2", "type": "module", "author": "withastro", "license": "MIT", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4fe84084be43..b995a2002c3e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -125,7 +125,7 @@ importers: examples/basics: dependencies: astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/blog: @@ -140,13 +140,13 @@ importers: specifier: ^3.0.4 version: link:../../packages/integrations/sitemap astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/component: devDependencies: astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/framework-alpine: @@ -161,7 +161,7 @@ importers: specifier: ^3.13.3 version: 3.13.3 astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/framework-lit: @@ -173,7 +173,7 @@ importers: specifier: ^0.2.1 version: 0.2.1 astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro lit: specifier: ^2.8.0 @@ -194,10 +194,10 @@ importers: specifier: ^5.0.3 version: link:../../packages/integrations/svelte '@astrojs/vue': - specifier: ^4.0.6 + specifier: ^4.0.7 version: link:../../packages/integrations/vue astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -227,7 +227,7 @@ importers: specifier: ^1.2.1 version: 1.2.1(preact@10.19.3) astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -245,7 +245,7 @@ importers: specifier: ^18.2.15 version: 18.2.18 astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro react: specifier: ^18.2.0 @@ -260,7 +260,7 @@ importers: specifier: ^3.0.3 version: link:../../packages/integrations/solid astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro solid-js: specifier: ^1.8.5 @@ -272,7 +272,7 @@ importers: specifier: ^5.0.3 version: link:../../packages/integrations/svelte astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro svelte: specifier: ^4.2.5 @@ -281,10 +281,10 @@ importers: examples/framework-vue: dependencies: '@astrojs/vue': - specifier: ^4.0.6 + specifier: ^4.0.7 version: link:../../packages/integrations/vue astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro vue: specifier: ^3.3.8 @@ -293,25 +293,25 @@ importers: examples/hackernews: dependencies: '@astrojs/node': - specifier: ^7.0.3 + specifier: ^7.0.4 version: link:../../packages/integrations/node astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/integration: devDependencies: astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/middleware: dependencies: '@astrojs/node': - specifier: ^7.0.3 + specifier: ^7.0.4 version: link:../../packages/integrations/node astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro html-minifier: specifier: ^4.0.0 @@ -324,31 +324,31 @@ importers: examples/minimal: dependencies: astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/non-html-pages: dependencies: astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/portfolio: dependencies: astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/ssr: dependencies: '@astrojs/node': - specifier: ^7.0.3 + specifier: ^7.0.4 version: link:../../packages/integrations/node '@astrojs/svelte': specifier: ^5.0.3 version: link:../../packages/integrations/svelte astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro svelte: specifier: ^4.2.5 @@ -357,7 +357,7 @@ importers: examples/starlog: dependencies: astro: - specifier: ^4.0.5 + specifier: ^4.0.9 version: link:../../packages/astro sass: specifier: ^1.69.5 @@ -369,13 +369,13 @@ importers: examples/view-transitions: devDependencies: '@astrojs/node': - specifier: ^7.0.3 + specifier: ^7.0.4 version: link:../../packages/integrations/node '@astrojs/tailwind': specifier: ^5.1.0 version: link:../../packages/integrations/tailwind astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/with-markdoc: @@ -384,7 +384,7 @@ importers: specifier: ^0.8.2 version: link:../../packages/integrations/markdoc astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/with-markdown-plugins: @@ -393,7 +393,7 @@ importers: specifier: ^4.0.1 version: link:../../packages/markdown/remark astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro hast-util-select: specifier: ^6.0.2 @@ -414,7 +414,7 @@ importers: examples/with-markdown-shiki: dependencies: astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro examples/with-mdx: @@ -426,7 +426,7 @@ importers: specifier: ^3.0.2 version: link:../../packages/integrations/preact astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -441,7 +441,7 @@ importers: specifier: ^0.5.0 version: 0.5.0(nanostores@0.9.5)(preact@10.19.3) astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro nanostores: specifier: ^0.9.5 @@ -462,7 +462,7 @@ importers: specifier: ^1.6.3 version: 1.6.4 astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro autoprefixer: specifier: ^10.4.15 @@ -480,7 +480,7 @@ importers: examples/with-vitest: dependencies: astro: - specifier: ^4.0.8 + specifier: ^4.0.9 version: link:../../packages/astro vitest: specifier: ^0.34.2 From d48ab90fb41fbc0589cd2df711682a41382c03aa Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Tue, 2 Jan 2024 22:18:52 +0100 Subject: [PATCH 05/19] Fix history navigation to hash fragment on Firefox when using view transitions (#9563) * Fix history navigation to hash fragment on Firefox when using view transitions * Edit changeset * Improve changeset, add co-authors --- .changeset/breezy-eyes-teach.md | 8 ++++++++ packages/astro/src/transitions/router.ts | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/breezy-eyes-teach.md diff --git a/.changeset/breezy-eyes-teach.md b/.changeset/breezy-eyes-teach.md new file mode 100644 index 000000000000..6ab45e666e26 --- /dev/null +++ b/.changeset/breezy-eyes-teach.md @@ -0,0 +1,8 @@ +--- +"astro": patch +--- + +Fixes back navigation to fragment links (e.g. `#about`) in Firefox when using view transitions + +Co-authored-by: Florian Lefebvre <69633530+florian-lefebvre@users.noreply.github.com> +Co-authored-by: Sarah Rainsberger diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index d77842f4da3c..848fa38bb4db 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -213,7 +213,9 @@ const moveToLocation = (to: URL, from: URL, options: Options, historyState?: Sta // ... what comes next is a intra-page navigation // that won't reload the page but instead scroll to the fragment history.scrollRestoration = 'auto'; - location.href = to.href; + const savedState = history.state; + location.href = to.href; // this kills the history state on Firefox + history.state || history.replaceState(savedState, ''); // this restores the history state } else { if (!scrolledToTop) { scrollTo({ left: 0, top: 0, behavior: 'instant' }); From 98c69b89cc27a35bc3665eef6b3a10988b0d414c Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Tue, 2 Jan 2024 22:43:09 +0100 Subject: [PATCH 06/19] Fix history usage of PR 9563 (#9581) --- packages/astro/src/transitions/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index 848fa38bb4db..5d07287b6f00 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -215,7 +215,7 @@ const moveToLocation = (to: URL, from: URL, options: Options, historyState?: Sta history.scrollRestoration = 'auto'; const savedState = history.state; location.href = to.href; // this kills the history state on Firefox - history.state || history.replaceState(savedState, ''); // this restores the history state + history.state || replaceState(savedState, ''); // this restores the history state } else { if (!scrolledToTop) { scrollTo({ left: 0, top: 0, behavior: 'instant' }); From 1099c6412b87749fe08ffcb86783f73b4f76f995 Mon Sep 17 00:00:00 2001 From: Mati Date: Wed, 3 Jan 2024 07:20:38 +0100 Subject: [PATCH 07/19] Patch `set-output` deprecation in workflows (#9543) --- .github/workflows/check-merge.yml | 4 ++-- .github/workflows/main.yml | 4 ++-- .github/workflows/release.yml | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-merge.yml b/.github/workflows/check-merge.yml index 378c595274f5..167879b628ba 100644 --- a/.github/workflows/check-merge.yml +++ b/.github/workflows/check-merge.yml @@ -50,10 +50,10 @@ jobs: if: steps.blocked.outputs.result != 'true' run: | echo "Checking for changesets marked as minor" - echo '::set-output name=found::false' + echo "found=false" >> $GITHUB_OUTPUT for file in ${{ steps.changed-files.outputs.all_changed_files }}; do if grep -q "'astro': minor" "$file"; then - echo '::set-output name=found::true' + echo "found=true" >> $GITHUB_OUTPUT echo "$file has a minor release tag" fi done diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 961f4d9977be..8e2fd8af4b0d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,10 +54,10 @@ jobs: if [[ $output = '{ "changesets": [], "releases": [] }' ]] then echo 'No changeset found' - echo "::set-output name=run_job::true" + echo "run_job=true" >> $GITHUB_OUTPUT else echo 'changes found, push to latest skipped' - echo "::set-output name=run_job::false" + echo "run_job=false" >> $GITHUB_OUTPUT fi update: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 30fd8867bcba..8696c85a04ec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,7 +62,9 @@ jobs: - name: Generate Notification id: notification if: steps.changesets.outputs.published == 'true' - run: message=$(node scripts/notify/index.js '${{ steps.changesets.outputs.publishedPackages }}') && echo ::set-output name=message::${message//$'\n'/'%0A'} + run: | + message=$(node scripts/notify/index.js '${{ steps.changesets.outputs.publishedPackages }}') + echo "message=${message//$'\n'/'%0A'}" >> $GITHUB_OUTPUT - name: Discord Notification if: steps.changesets.outputs.published == 'true' From ab6049bd58e4d02f47d500f9db08a865bc7f09b8 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 3 Jan 2024 14:54:30 +0700 Subject: [PATCH 08/19] Set default NODE_ENV for JS API (#9575) --- .changeset/six-bottles-mix.md | 5 +++++ packages/astro/src/cli/add/index.ts | 3 ++- packages/astro/src/cli/check/index.ts | 2 ++ packages/astro/src/cli/index.ts | 5 ----- packages/astro/src/core/build/index.ts | 2 ++ packages/astro/src/core/dev/dev.ts | 2 ++ packages/astro/src/core/preview/index.ts | 2 ++ packages/astro/src/core/sync/index.ts | 2 ++ packages/astro/src/core/util.ts | 9 +++++++++ 9 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 .changeset/six-bottles-mix.md diff --git a/.changeset/six-bottles-mix.md b/.changeset/six-bottles-mix.md new file mode 100644 index 000000000000..d010104a698f --- /dev/null +++ b/.changeset/six-bottles-mix.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Sets correct `process.env.NODE_ENV` default when using the JS API diff --git a/packages/astro/src/cli/add/index.ts b/packages/astro/src/cli/add/index.ts index 5b65106cca86..1240e67deed0 100644 --- a/packages/astro/src/cli/add/index.ts +++ b/packages/astro/src/cli/add/index.ts @@ -27,7 +27,7 @@ import * as msg from '../../core/messages.js'; import { printHelp } from '../../core/messages.js'; import { appendForwardSlash } from '../../core/path.js'; import { apply as applyPolyfill } from '../../core/polyfill.js'; -import { parseNpmName } from '../../core/util.js'; +import { ensureProcessNodeEnv, parseNpmName } from '../../core/util.js'; import { eventCliSession, telemetry } from '../../events/index.js'; import { createLoggerFromFlags, flagsToAstroInlineConfig } from '../flags.js'; import { generate, parse, t, visit } from './babel.js'; @@ -92,6 +92,7 @@ async function getRegistry(): Promise { } export async function add(names: string[], { flags }: AddOptions) { + ensureProcessNodeEnv('production'); const inlineConfig = flagsToAstroInlineConfig(flags); const { userConfig } = await resolveConfig(inlineConfig, 'add'); telemetry.record(eventCliSession('add', userConfig)); diff --git a/packages/astro/src/cli/check/index.ts b/packages/astro/src/cli/check/index.ts index 6ce3bf71ecb6..faf07b776b9f 100644 --- a/packages/astro/src/cli/check/index.ts +++ b/packages/astro/src/cli/check/index.ts @@ -2,8 +2,10 @@ import path from 'node:path'; import type { Arguments } from 'yargs-parser'; import { createLoggerFromFlags, flagsToAstroInlineConfig } from '../flags.js'; import { getPackage } from '../install-package.js'; +import { ensureProcessNodeEnv } from '../../core/util.js'; export async function check(flags: Arguments) { + ensureProcessNodeEnv('production'); const logger = createLoggerFromFlags(flags); const getPackageOpts = { skipAsk: flags.yes || flags.y, cwd: flags.root }; const checkPackage = await getPackage( diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 7ca4d21a9a7b..19347ebecd16 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -131,11 +131,6 @@ async function runCommand(cmd: string, flags: yargs.Arguments) { enableVerboseLogging(); } - // Start with a default NODE_ENV so Vite doesn't set an incorrect default when loading the Astro config - if (!process.env.NODE_ENV) { - process.env.NODE_ENV = cmd === 'dev' ? 'development' : 'production'; - } - const { notify } = await import('./telemetry/index.js'); await notify(); diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 8cb53f3c7c3a..553497bc5b40 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -33,6 +33,7 @@ import { collectPagesData } from './page-data.js'; import { staticBuild, viteBuild } from './static-build.js'; import type { StaticBuildOptions } from './types.js'; import { getTimeStat } from './util.js'; +import { ensureProcessNodeEnv } from '../util.js'; export interface BuildOptions { /** @@ -63,6 +64,7 @@ export default async function build( inlineConfig: AstroInlineConfig, options: BuildOptions = {} ): Promise { + ensureProcessNodeEnv('production'); applyPolyfill(); const logger = createNodeLogger(inlineConfig); const { userConfig, astroConfig } = await resolveConfig(inlineConfig, 'build'); diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index c0c1b9b8ea64..d345c1db6145 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -10,6 +10,7 @@ import { telemetry } from '../../events/index.js'; import * as msg from '../messages.js'; import { startContainer } from './container.js'; import { createContainerWithAutomaticRestart } from './restart.js'; +import { ensureProcessNodeEnv } from '../util.js'; export interface DevServer { address: AddressInfo; @@ -25,6 +26,7 @@ export interface DevServer { * @experimental The JavaScript API is experimental */ export default async function dev(inlineConfig: AstroInlineConfig): Promise { + ensureProcessNodeEnv('development'); const devStart = performance.now(); await telemetry.record([]); diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index 0f65c0c858b7..d5faf8cf27f3 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -10,6 +10,7 @@ import { createNodeLogger } from '../config/logging.js'; import { createSettings } from '../config/settings.js'; import createStaticPreviewServer from './static-preview-server.js'; import { getResolvedHostForHttpServer } from './util.js'; +import { ensureProcessNodeEnv } from '../util.js'; /** * Starts a local server to serve your static dist/ directory. This command is useful for previewing @@ -18,6 +19,7 @@ import { getResolvedHostForHttpServer } from './util.js'; * @experimental The JavaScript API is experimental */ export default async function preview(inlineConfig: AstroInlineConfig): Promise { + ensureProcessNodeEnv('production'); const logger = createNodeLogger(inlineConfig); const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, 'preview'); telemetry.record(eventCliSession('preview', userConfig)); diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 966454845b30..bfaed6c2f9fd 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -17,6 +17,7 @@ import { createSettings } from '../config/settings.js'; import { createVite } from '../create-vite.js'; import { AstroError, AstroErrorData, createSafeError, isAstroError } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; +import { ensureProcessNodeEnv } from '../util.js'; export type ProcessExit = 0 | 1; @@ -41,6 +42,7 @@ export default async function sync( inlineConfig: AstroInlineConfig, options?: SyncOptions ): Promise { + ensureProcessNodeEnv('production'); const logger = createNodeLogger(inlineConfig); const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, 'sync'); telemetry.record(eventCliSession('sync', userConfig)); diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index bcfa9a511bbb..4db3549a2a6d 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -231,3 +231,12 @@ export function resolvePath(specifier: string, importer: string) { return specifier; } } + +/** + * Set a default NODE_ENV so Vite doesn't set an incorrect default when loading the Astro config + */ +export function ensureProcessNodeEnv(defaultNodeEnv: string) { + if (!process.env.NODE_ENV) { + process.env.NODE_ENV = defaultNodeEnv; + } +} From b8a6fa8917ff7babd35dafb3d3dcd9a58cee836d Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 3 Jan 2024 21:05:51 +0800 Subject: [PATCH 09/19] Error on preview if outDir missing (#9544) * Error on preview if outDir missing * Update .changeset/four-moles-burn.md Co-authored-by: Sarah Rainsberger --------- Co-authored-by: Emanuele Stoppa Co-authored-by: Sarah Rainsberger --- .changeset/four-moles-burn.md | 5 +++++ packages/astro/src/core/preview/index.ts | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/four-moles-burn.md diff --git a/.changeset/four-moles-burn.md b/.changeset/four-moles-burn.md new file mode 100644 index 000000000000..3f45f452d914 --- /dev/null +++ b/.changeset/four-moles-burn.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Adds a helpful error for static sites when you use the `astro preview` command if you have not previously run `astro build`. diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index d5faf8cf27f3..5d6adc0c64bb 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -1,3 +1,4 @@ +import fs from 'node:fs'; import { createRequire } from 'node:module'; import { fileURLToPath, pathToFileURL } from 'node:url'; import type { AstroInlineConfig, PreviewModule, PreviewServer } from '../../@types/astro.js'; @@ -34,6 +35,12 @@ export default async function preview(inlineConfig: AstroInlineConfig): Promise< await runHookConfigDone({ settings: settings, logger: logger }); if (settings.config.output === 'static') { + if (!fs.existsSync(settings.config.outDir)) { + const outDirPath = fileURLToPath(settings.config.outDir); + throw new Error( + `[preview] The output directory ${outDirPath} does not exist. Did you run \`astro build\`?` + ); + } const server = await createStaticPreviewServer(settings, logger); return server; } From 607303be198931825dac9f3bc97867b4886feaf3 Mon Sep 17 00:00:00 2001 From: Austin Merrick Date: Wed, 3 Jan 2024 05:06:57 -0800 Subject: [PATCH 10/19] Move create-astro async tasks to end (#9470) * Upgrade @astrojs/cli-kit * Add tasks to context * Change steps to use tasks * Do tasks at end * Add changeset * Make labels more consistent Co-authored-by: Nate Moore * Update .changeset/chatty-penguins-sin.md Co-authored-by: Sarah Rainsberger --------- Co-authored-by: Nate Moore Co-authored-by: Sarah Rainsberger --- .changeset/chatty-penguins-sin.md | 5 +++++ packages/create-astro/package.json | 2 +- packages/create-astro/src/actions/context.ts | 4 +++- packages/create-astro/src/actions/dependencies.ts | 9 +++++---- packages/create-astro/src/actions/git.ts | 9 ++++++--- packages/create-astro/src/actions/template.ts | 7 ++++--- packages/create-astro/src/actions/typescript.ts | 15 ++++++++++++--- packages/create-astro/src/index.ts | 14 +++++++++++++- pnpm-lock.yaml | 8 ++++---- 9 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 .changeset/chatty-penguins-sin.md diff --git a/.changeset/chatty-penguins-sin.md b/.changeset/chatty-penguins-sin.md new file mode 100644 index 000000000000..5c6a1bdf0d72 --- /dev/null +++ b/.changeset/chatty-penguins-sin.md @@ -0,0 +1,5 @@ +--- +'create-astro': minor +--- + +Improves the `create astro` CLI experience by asking all the questions upfront, then creating your new Astro project based on your responses. diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index 417ebc08447a..9a62aca78b63 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -31,7 +31,7 @@ "//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.", "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES", "dependencies": { - "@astrojs/cli-kit": "^0.3.1", + "@astrojs/cli-kit": "^0.4.0", "giget": "1.1.3" }, "devDependencies": { diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index a7f2e6d8c71d..7a401162544d 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -1,4 +1,4 @@ -import { prompt } from '@astrojs/cli-kit'; +import { prompt, type Task } from '@astrojs/cli-kit'; import { random } from '@astrojs/cli-kit/utils'; import arg from 'arg'; import os from 'node:os'; @@ -26,6 +26,7 @@ export interface Context { stdout?: typeof process.stdout; exit(code: number): never; hat?: string; + tasks: Task[]; } export async function getContext(argv: string[]): Promise { @@ -103,6 +104,7 @@ export async function getContext(argv: string[]): Promise { exit(code) { process.exit(code); }, + tasks: [], }; return context; } diff --git a/packages/create-astro/src/actions/dependencies.ts b/packages/create-astro/src/actions/dependencies.ts index 26557d5a2f1d..e420fcb716e3 100644 --- a/packages/create-astro/src/actions/dependencies.ts +++ b/packages/create-astro/src/actions/dependencies.ts @@ -1,12 +1,12 @@ import { color } from '@astrojs/cli-kit'; import fs from 'node:fs'; import path from 'node:path'; -import { error, info, spinner, title } from '../messages.js'; +import { error, info, title } from '../messages.js'; import { shell } from '../shell.js'; import type { Context } from './context.js'; export async function dependencies( - ctx: Pick + ctx: Pick ) { let deps = ctx.install ?? ctx.yes; if (deps === undefined) { @@ -24,8 +24,9 @@ export async function dependencies( if (ctx.dryRun) { await info('--dry-run', `Skipping dependency installation`); } else if (deps) { - await spinner({ - start: `Installing dependencies with ${ctx.packageManager}...`, + ctx.tasks.push({ + pending: 'Dependencies', + start: `Dependencies installing with ${ctx.packageManager}...`, end: 'Dependencies installed', onError: (e) => { error('error', e); diff --git a/packages/create-astro/src/actions/git.ts b/packages/create-astro/src/actions/git.ts index dd703b1f559c..bd038f3f5236 100644 --- a/packages/create-astro/src/actions/git.ts +++ b/packages/create-astro/src/actions/git.ts @@ -3,10 +3,12 @@ import path from 'node:path'; import type { Context } from './context.js'; import { color } from '@astrojs/cli-kit'; -import { error, info, spinner, title } from '../messages.js'; +import { error, info, title } from '../messages.js'; import { shell } from '../shell.js'; -export async function git(ctx: Pick) { +export async function git( + ctx: Pick +) { if (fs.existsSync(path.join(ctx.cwd, '.git'))) { await info('Nice!', `Git has already been initialized`); return; @@ -26,7 +28,8 @@ export async function git(ctx: Pick diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index bdb32607692b..fa88fd503044 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -4,10 +4,10 @@ import { color } from '@astrojs/cli-kit'; import { downloadTemplate } from 'giget'; import fs from 'node:fs'; import path from 'node:path'; -import { error, info, spinner, title } from '../messages.js'; +import { error, info, title } from '../messages.js'; export async function template( - ctx: Pick + ctx: Pick ) { if (!ctx.template && ctx.yes) ctx.template = 'basics'; @@ -32,7 +32,8 @@ export async function template( if (ctx.dryRun) { await info('--dry-run', `Skipping template copying`); } else if (ctx.template) { - await spinner({ + ctx.tasks.push({ + pending: 'Template', start: 'Template copying...', end: 'Template copied', while: () => diff --git a/packages/create-astro/src/actions/typescript.ts b/packages/create-astro/src/actions/typescript.ts index 2c0d21e89bcb..0ac1c753d50c 100644 --- a/packages/create-astro/src/actions/typescript.ts +++ b/packages/create-astro/src/actions/typescript.ts @@ -4,12 +4,20 @@ import { color } from '@astrojs/cli-kit'; import { readFile, rm, writeFile } from 'node:fs/promises'; import path from 'node:path'; import stripJsonComments from 'strip-json-comments'; -import { error, info, spinner, title, typescriptByDefault } from '../messages.js'; +import { error, info, title, typescriptByDefault } from '../messages.js'; import { shell } from '../shell.js'; type PickedTypeScriptContext = Pick< Context, - 'typescript' | 'yes' | 'prompt' | 'dryRun' | 'cwd' | 'exit' | 'packageManager' | 'install' + | 'typescript' + | 'yes' + | 'prompt' + | 'dryRun' + | 'cwd' + | 'exit' + | 'packageManager' + | 'install' + | 'tasks' >; export async function typescript(ctx: PickedTypeScriptContext) { @@ -61,7 +69,8 @@ export async function typescript(ctx: PickedTypeScriptContext) { if (ts === 'relaxed' || ts === 'default') { ts = 'base'; } - await spinner({ + ctx.tasks.push({ + pending: 'TypeScript', start: 'TypeScript customizing...', end: 'TypeScript customized', while: () => diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index f641e876e414..2ffdd00b7dd3 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -10,6 +10,7 @@ import { template } from './actions/template.js'; import { setupTypeScript, typescript } from './actions/typescript.js'; import { verify } from './actions/verify.js'; import { setStdout } from './messages.js'; +import { tasks } from '@astrojs/cli-kit'; const exit = () => process.exit(0); process.on('SIGINT', exit); @@ -43,12 +44,23 @@ export async function main() { // Steps which write to files need to go above git git, - next, ]; for (const step of steps) { await step(ctx); } + + // eslint-disable-next-line no-console + console.log(''); + + const labels = { + start: 'Project initializing...', + end: 'Project initialized!', + }; + await tasks(labels, ctx.tasks); + + await next(ctx); + process.exit(0); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b995a2002c3e..ea42a5abe7ce 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3713,8 +3713,8 @@ importers: packages/create-astro: dependencies: '@astrojs/cli-kit': - specifier: ^0.3.1 - version: 0.3.1 + specifier: ^0.4.0 + version: 0.4.0 giget: specifier: 1.1.3 version: 1.1.3 @@ -5235,8 +5235,8 @@ packages: sisteransi: 1.0.5 dev: false - /@astrojs/cli-kit@0.3.1: - resolution: {integrity: sha512-BEzf3gudr4XrrrInJKD+GSS5O+GXRTukLUpOfgqdTSq6d48EWVhigNHobmlQGbpa9FEAw+sZmvmHmhS29QhnwA==} + /@astrojs/cli-kit@0.4.0: + resolution: {integrity: sha512-M7R2Af/Gh13pwZ2zjTkTPt87x4IjRw/bSRCmjJGWEGeW3nLNzuEeRY8tleeIGbbfUsm3DJg+UF5rCrQGoviHgQ==} engines: {node: '>=18.14.1'} dependencies: chalk: 5.3.0 From 2a8b9c56b9c6918531c57ec38b89474571331aee Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 3 Jan 2024 21:07:31 +0800 Subject: [PATCH 11/19] Support --open with url string (#9573) * Support --open with url string * Update jsdoc * Fix typo * Document server.open * Apply suggestions from code review Co-authored-by: Sarah Rainsberger --------- Co-authored-by: Sarah Rainsberger --- .changeset/cyan-seals-bathe.md | 5 +++++ packages/astro/src/@types/astro.ts | 21 +++++++++++++-------- packages/astro/src/cli/flags.ts | 3 ++- packages/astro/src/core/config/config.ts | 3 ++- packages/astro/src/core/config/schema.ts | 10 ++++++++-- packages/astro/src/core/dev/container.ts | 7 ++++--- 6 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 .changeset/cyan-seals-bathe.md diff --git a/.changeset/cyan-seals-bathe.md b/.changeset/cyan-seals-bathe.md new file mode 100644 index 000000000000..0e2f69f597b1 --- /dev/null +++ b/.changeset/cyan-seals-bathe.md @@ -0,0 +1,5 @@ +--- +"astro": minor +--- + +Allows passing a string to `--open` and `server.open` to open a specific URL on startup in development diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 6a255c5734b7..dc47d3a63592 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -153,7 +153,7 @@ export interface CLIFlags { host?: string | boolean; port?: number; config?: string; - open?: boolean; + open?: string | boolean; } /** @@ -371,19 +371,21 @@ type ServerConfig = { /** * @name server.open - * @type {boolean} + * @type {string | boolean} * @default `false` * @version 2.1.8 * @description - * Control whether the dev server should open in your browser window on startup. + * Controls whether the dev server should open in your browser window on startup. + * + * Pass a full URL string (e.g. "http://example.com") or a pathname (e.g. "/about") to specify the URL to open. * * ```js * { - * server: { open: true } + * server: { open: "/about" } * } * ``` */ - open?: boolean; + open?: string | boolean; }; export interface ViteUserConfig extends vite.UserConfig { @@ -1020,16 +1022,19 @@ export interface AstroUserConfig { */ /** + * @docs * @name server.open - * @type {boolean} + * @type {string | boolean} * @default `false` * @version 2.1.8 * @description - * Control whether the dev server should open in your browser window on startup. + * Controls whether the dev server should open in your browser window on startup. + * + * Pass a full URL string (e.g. "http://example.com") or a pathname (e.g. "/about") to specify the URL to open. * * ```js * { - * server: { open: true } + * server: { open: "/about" } * } * ``` */ diff --git a/packages/astro/src/cli/flags.ts b/packages/astro/src/cli/flags.ts index c384d98671b8..d61f1e66d7df 100644 --- a/packages/astro/src/cli/flags.ts +++ b/packages/astro/src/cli/flags.ts @@ -19,7 +19,8 @@ export function flagsToAstroInlineConfig(flags: Flags): AstroInlineConfig { port: typeof flags.port === 'number' ? flags.port : undefined, host: typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined, - open: typeof flags.open === 'boolean' ? flags.open : undefined, + open: + typeof flags.open === 'string' || typeof flags.open === 'boolean' ? flags.open : undefined, }, }; } diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts index 82bb872b1593..5284af1631a7 100644 --- a/packages/astro/src/core/config/config.ts +++ b/packages/astro/src/core/config/config.ts @@ -63,10 +63,11 @@ export function resolveFlags(flags: Partial): CLIFlags { site: typeof flags.site === 'string' ? flags.site : undefined, base: typeof flags.base === 'string' ? flags.base : undefined, port: typeof flags.port === 'number' ? flags.port : undefined, - open: typeof flags.open === 'boolean' ? flags.open : undefined, config: typeof flags.config === 'string' ? flags.config : undefined, host: typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined, + open: + typeof flags.open === 'string' || typeof flags.open === 'boolean' ? flags.open : undefined, }; } diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 08910720a13e..0ea2d368a182 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -147,7 +147,10 @@ export const AstroConfigSchema = z.object({ // validate z .object({ - open: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.server.open), + open: z + .union([z.string(), z.boolean()]) + .optional() + .default(ASTRO_CONFIG_DEFAULTS.server.open), host: z .union([z.string(), z.boolean()]) .optional() @@ -464,12 +467,15 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: string) { // validate z .object({ + open: z + .union([z.string(), z.boolean()]) + .optional() + .default(ASTRO_CONFIG_DEFAULTS.server.open), host: z .union([z.string(), z.boolean()]) .optional() .default(ASTRO_CONFIG_DEFAULTS.server.host), port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port), - open: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.server.open), headers: z.custom().optional(), streaming: z.boolean().optional().default(true), }) diff --git a/packages/astro/src/core/dev/container.ts b/packages/astro/src/core/dev/container.ts index 4f2b5d4f2fd5..d252e2eea534 100644 --- a/packages/astro/src/core/dev/container.ts +++ b/packages/astro/src/core/dev/container.ts @@ -54,10 +54,11 @@ export async function createContainer({ const { base, - server: { host, headers, open: shouldOpen }, + server: { host, headers, open: serverOpen }, } = settings.config; - // Open server to the correct path - const open = shouldOpen ? base : false; + // Open server to the correct path. We pass the `base` here as we didn't pass the + // base to the initial Vite config + const open = typeof serverOpen == 'string' ? serverOpen : serverOpen ? base : false; // The client entrypoint for renderers. Since these are imported dynamically // we need to tell Vite to preoptimize them. From e44f6acf99195a3f29b8390fd9b2c06410551b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=80=E9=9D=99=E5=87=A1?= Date: Wed, 3 Jan 2024 21:07:58 +0800 Subject: [PATCH 12/19] enhance(prefetch): Adds a `'load'` prefetch strategy, and ignores `3g` in slow connection detection (#9513) * [enhance:prefetch] add global ignoreSlowConnection and add none to defaultStrategy enum * changeset * change defaultStrategy enum 'none' to 'all', and fix e2e test * test:e2e prefetch * update changeset * rename defaultStrategy.all to defaultStrategy.load * fix: remove global ignoreSlowConnection config and ignore 3g in slow connection detection * fix: Revert variable name changes * Split changeset --------- Co-authored-by: bluwy Co-authored-by: Emanuele Stoppa Co-authored-by: Sarah Rainsberger --- .changeset/bright-feet-flash.md | 5 + .changeset/two-hats-arrive.md | 5 + .../fixtures/prefetch/src/pages/index.astro | 4 +- .../prefetch/src/pages/prefetch-all.astro | 1 + packages/astro/e2e/prefetch.test.js | 101 ++++++++++++++++++ packages/astro/src/@types/astro.ts | 5 +- packages/astro/src/core/config/schema.ts | 2 +- packages/astro/src/prefetch/index.ts | 17 ++- 8 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 .changeset/bright-feet-flash.md create mode 100644 .changeset/two-hats-arrive.md create mode 100644 packages/astro/e2e/fixtures/prefetch/src/pages/prefetch-all.astro diff --git a/.changeset/bright-feet-flash.md b/.changeset/bright-feet-flash.md new file mode 100644 index 000000000000..d88d2aecea32 --- /dev/null +++ b/.changeset/bright-feet-flash.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Adds a `'load'` prefetch strategy to prefetch links on page load diff --git a/.changeset/two-hats-arrive.md b/.changeset/two-hats-arrive.md new file mode 100644 index 000000000000..6796462b0a0f --- /dev/null +++ b/.changeset/two-hats-arrive.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Ignores `3g` in slow connection detection. Only `2g` and `slow-2g` are considered slow connections. diff --git a/packages/astro/e2e/fixtures/prefetch/src/pages/index.astro b/packages/astro/e2e/fixtures/prefetch/src/pages/index.astro index 88ce196ae22f..63a30031ea8a 100644 --- a/packages/astro/e2e/fixtures/prefetch/src/pages/index.astro +++ b/packages/astro/e2e/fixtures/prefetch/src/pages/index.astro @@ -20,6 +20,8 @@ Scroll down to trigger viewport prefetch
+ load +
viewport - \ No newline at end of file + diff --git a/packages/astro/e2e/fixtures/prefetch/src/pages/prefetch-all.astro b/packages/astro/e2e/fixtures/prefetch/src/pages/prefetch-all.astro new file mode 100644 index 000000000000..8e2c799bbdfb --- /dev/null +++ b/packages/astro/e2e/fixtures/prefetch/src/pages/prefetch-all.astro @@ -0,0 +1 @@ +

Prefetch load

diff --git a/packages/astro/e2e/prefetch.test.js b/packages/astro/e2e/prefetch.test.js index a19c87680eca..12aa770029c2 100644 --- a/packages/astro/e2e/prefetch.test.js +++ b/packages/astro/e2e/prefetch.test.js @@ -95,6 +95,12 @@ test.describe('Prefetch (default)', () => { await page.locator('#prefetch-manual').click(); expect(reqUrls.filter((u) => u.includes('/prefetch-manual')).length).toEqual(1); }); + + test('data-astro-prefetch="load" should prefetch', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).toContainEqual('/prefetch-load'); + expect(page.locator('link[rel="prefetch"][href$="/prefetch-load"]')).toBeDefined(); + }); }); test.describe("Prefetch (prefetchAll: true, defaultStrategy: 'tap')", () => { @@ -182,4 +188,99 @@ test.describe("Prefetch (prefetchAll: true, defaultStrategy: 'tap')", () => { expect(reqUrls).toContainEqual('/prefetch-viewport'); expect(page.locator('link[rel="prefetch"][href$="/prefetch-viewport"]')).toBeDefined(); }); + + test('data-astro-prefetch="load" should prefetch', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).toContainEqual('/prefetch-load'); + expect(page.locator('link[rel="prefetch"][href$="/prefetch-load"]')).toBeDefined(); + }); +}); + +test.describe("Prefetch (prefetchAll: true, defaultStrategy: 'load')", () => { + let devServer; + /** @type {string[]} */ + const reqUrls = []; + + test.beforeAll(async ({ astro }) => { + devServer = await astro.startDevServer({ + prefetch: { + prefetchAll: true, + defaultStrategy: 'load', + }, + }); + }); + + test.beforeEach(async ({ page }) => { + page.on('request', (req) => { + const urlObj = new URL(req.url()); + reqUrls.push(urlObj.pathname + urlObj.search); + }); + }); + + test.afterEach(() => { + reqUrls.length = 0; + }); + + test.afterAll(async () => { + await devServer.stop(); + }); + + test('Link without data-astro-prefetch should prefetch', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).toContainEqual('/prefetch-default'); + expect(page.locator('link[rel="prefetch"][href$="/prefetch-default"]')).toBeDefined(); + }); + + test('data-astro-prefetch="false" should not prefetch', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).not.toContainEqual('/prefetch-false'); + }); + + test('Link with search param should prefetch', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).not.toContainEqual('/?search-param=true'); + await Promise.all([ + page.waitForEvent('request'), // wait prefetch request + page.locator('#prefetch-search-param').hover(), + ]); + expect(reqUrls).toContainEqual('/?search-param=true'); + }); + + test('data-astro-prefetch="tap" should prefetch on tap', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).not.toContainEqual('/prefetch-tap'); + await Promise.all([ + page.waitForEvent('request'), // wait prefetch request + page.locator('#prefetch-tap').click(), + ]); + expect(reqUrls).toContainEqual('/prefetch-tap'); + }); + + test('data-astro-prefetch="hover" should prefetch on hover', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).not.toContainEqual('/prefetch-hover'); + await Promise.all([ + page.waitForEvent('request'), // wait prefetch request + page.locator('#prefetch-hover').hover(), + ]); + expect(reqUrls).toContainEqual('/prefetch-hover'); + }); + + test('data-astro-prefetch="viewport" should prefetch on viewport', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).not.toContainEqual('/prefetch-viewport'); + // Scroll down to show the element + await Promise.all([ + page.waitForEvent('request'), // wait prefetch request + page.locator('#prefetch-viewport').scrollIntoViewIfNeeded(), + ]); + expect(reqUrls).toContainEqual('/prefetch-viewport'); + expect(page.locator('link[rel="prefetch"][href$="/prefetch-viewport"]')).toBeDefined(); + }); + + test('data-astro-prefetch="load" should prefetch', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/')); + expect(reqUrls).toContainEqual('/prefetch-load'); + expect(page.locator('link[rel="prefetch"][href$="/prefetch-load"]')).toBeDefined(); + }); }); diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index dc47d3a63592..7c18af4602d4 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -949,7 +949,7 @@ export interface AstroUserConfig { /** * @docs * @name prefetch.defaultStrategy - * @type {'tap' | 'hover' | 'viewport'} + * @type {'tap' | 'hover' | 'viewport' | 'load'} * @default `'hover'` * @description * The default prefetch strategy to use when the `data-astro-prefetch` attribute is set on a link with no value. @@ -957,6 +957,7 @@ export interface AstroUserConfig { * - `'tap'`: Prefetch just before you click on the link. * - `'hover'`: Prefetch when you hover over or focus on the link. (default) * - `'viewport'`: Prefetch as the links enter the viewport. + * - `'load'`: Prefetch the link without any restrictions. * * You can override this default value and select a different strategy for any individual link by setting a value on the attribute. * @@ -964,7 +965,7 @@ export interface AstroUserConfig { * About * ``` */ - defaultStrategy?: 'tap' | 'hover' | 'viewport'; + defaultStrategy?: 'tap' | 'hover' | 'viewport' | 'load'; }; /** diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 0ea2d368a182..5d30d1b5305c 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -185,7 +185,7 @@ export const AstroConfigSchema = z.object({ z.boolean(), z.object({ prefetchAll: z.boolean().optional(), - defaultStrategy: z.enum(['tap', 'hover', 'viewport']).optional(), + defaultStrategy: z.enum(['tap', 'hover', 'viewport', 'load']).optional(), }), ]) .optional(), diff --git a/packages/astro/src/prefetch/index.ts b/packages/astro/src/prefetch/index.ts index 15f4ef0ccd95..99cf3627af8e 100644 --- a/packages/astro/src/prefetch/index.ts +++ b/packages/astro/src/prefetch/index.ts @@ -45,6 +45,7 @@ export function init(defaultOpts?: InitOptions) { initTapStrategy(); initHoverStrategy(); initViewportStrategy(); + initLoadStrategy(); } /** @@ -169,6 +170,20 @@ function createViewportIntersectionObserver() { }); } +/** + * Prefetch links with lower priority when page load + */ +function initLoadStrategy() { + onPageLoad(() => { + for (const anchor of document.getElementsByTagName('a')) { + if (elMatchesStrategy(anchor, 'load')) { + // Prefetch every link in this page + prefetch(anchor.href, { with: 'link' }); + } + } + }); +} + export interface PrefetchOptions { /** * How the prefetch should prioritize the URL. (default `'link'`) @@ -265,7 +280,7 @@ function isSlowConnection() { if ('connection' in navigator) { // Untyped Chrome-only feature: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection const conn = navigator.connection as any; - return conn.saveData || /(2|3)g/.test(conn.effectiveType); + return conn.saveData || /2g/.test(conn.effectiveType); } return false; } From d239e2cd7c100e4898884c4cc253ed10df25afef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=80=E9=9D=99=E5=87=A1?= Date: Wed, 3 Jan 2024 13:10:02 +0000 Subject: [PATCH 13/19] [ci] format --- packages/astro/src/@types/astro.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 7c18af4602d4..5af1a7417e7d 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -376,7 +376,7 @@ type ServerConfig = { * @version 2.1.8 * @description * Controls whether the dev server should open in your browser window on startup. - * + * * Pass a full URL string (e.g. "http://example.com") or a pathname (e.g. "/about") to specify the URL to open. * * ```js @@ -1030,7 +1030,7 @@ export interface AstroUserConfig { * @version 2.1.8 * @description * Controls whether the dev server should open in your browser window on startup. - * + * * Pass a full URL string (e.g. "http://example.com") or a pathname (e.g. "/about") to specify the URL to open. * * ```js From 08402ad5846c73b6887e74ed4575fd71a3e3c73d Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 3 Jan 2024 21:19:04 +0800 Subject: [PATCH 14/19] Add limitInputPixels option for sharp image service (#9546) * Add limitInputPixels option for sharp image service * Fix types * Update docs Co-authored-by: sarah11918 --------- Co-authored-by: Emanuele Stoppa Co-authored-by: sarah11918 --- .changeset/poor-apes-cheat.md | 21 +++++++++++++++++++++ packages/astro/config.d.ts | 3 ++- packages/astro/config.mjs | 4 ++-- packages/astro/src/@types/astro.ts | 9 +++++++-- packages/astro/src/assets/services/sharp.ts | 17 ++++++++++++++--- 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 .changeset/poor-apes-cheat.md diff --git a/.changeset/poor-apes-cheat.md b/.changeset/poor-apes-cheat.md new file mode 100644 index 000000000000..1d8c380d0b86 --- /dev/null +++ b/.changeset/poor-apes-cheat.md @@ -0,0 +1,21 @@ +--- +'astro': minor +--- + +Adds an option for the Sharp image service to allow large images to be processed. Set `limitInputPixels: false` to bypass the default image size limit: + +```js +// astro.config.mjs +import { defineConfig } from 'astro/config'; + +export default defineConfig({ + image: { + service: { + entrypoint: 'astro/assets/services/sharp', + config: { + limitInputPixels: false, + }, + }, + }, +}); +``` diff --git a/packages/astro/config.d.ts b/packages/astro/config.d.ts index a12f862d651b..b859f0b055fc 100644 --- a/packages/astro/config.d.ts +++ b/packages/astro/config.d.ts @@ -2,6 +2,7 @@ type ViteUserConfig = import('vite').UserConfig; type ViteUserConfigFn = import('vite').UserConfigFn; type AstroUserConfig = import('./dist/@types/astro.js').AstroUserConfig; type ImageServiceConfig = import('./dist/@types/astro.js').ImageServiceConfig; +type SharpImageServiceConfig = import('./dist/assets/services/sharp.js').SharpImageServiceConfig; /** * See the full Astro Configuration API Documentation @@ -17,7 +18,7 @@ export function getViteConfig(config: ViteUserConfig): ViteUserConfigFn; /** * Return the configuration needed to use the Sharp-based image service */ -export function sharpImageService(): ImageServiceConfig; +export function sharpImageService(config?: SharpImageServiceConfig): ImageServiceConfig; /** * Return the configuration needed to use the Squoosh-based image service diff --git a/packages/astro/config.mjs b/packages/astro/config.mjs index 208313287817..389387bddf02 100644 --- a/packages/astro/config.mjs +++ b/packages/astro/config.mjs @@ -1,9 +1,9 @@ export { defineConfig, getViteConfig } from './dist/config/index.js'; -export function sharpImageService() { +export function sharpImageService(config = {}) { return { entrypoint: 'astro/assets/services/sharp', - config: {}, + config, }; } diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 5af1a7417e7d..cadc704cd68e 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1096,8 +1096,13 @@ export interface AstroUserConfig { * ```js * { * image: { - * // Example: Enable the Sharp-based image service - * service: { entrypoint: 'astro/assets/services/sharp' }, + * // Example: Enable the Sharp-based image service with a custom config + * service: { + * entrypoint: 'astro/assets/services/sharp', + * config: { + * limitInputPixels: false, + * }, + * }, * }, * } * ``` diff --git a/packages/astro/src/assets/services/sharp.ts b/packages/astro/src/assets/services/sharp.ts index 21529913892c..74bf921d9ce2 100644 --- a/packages/astro/src/assets/services/sharp.ts +++ b/packages/astro/src/assets/services/sharp.ts @@ -8,6 +8,13 @@ import { type LocalImageService, } from './service.js'; +export interface SharpImageServiceConfig { + /** + * The `limitInputPixels` option passed to Sharp. See https://sharp.pixelplumbing.com/api-constructor for more information + */ + limitInputPixels?: number; +} + let sharp: typeof import('sharp'); const qualityTable: Record = { @@ -28,13 +35,13 @@ async function loadSharp() { return sharpImport; } -const sharpService: LocalImageService = { +const sharpService: LocalImageService = { validateOptions: baseService.validateOptions, getURL: baseService.getURL, parseURL: baseService.parseURL, getHTMLAttributes: baseService.getHTMLAttributes, getSrcSet: baseService.getSrcSet, - async transform(inputBuffer, transformOptions) { + async transform(inputBuffer, transformOptions, config) { if (!sharp) sharp = await loadSharp(); const transform: BaseServiceTransform = transformOptions as BaseServiceTransform; @@ -43,7 +50,11 @@ const sharpService: LocalImageService = { // TODO: Sharp has some support for SVGs, we could probably support this once Sharp is the default and only service. if (transform.format === 'svg') return { data: inputBuffer, format: 'svg' }; - let result = sharp(inputBuffer, { failOnError: false, pages: -1 }); + const result = sharp(inputBuffer, { + failOnError: false, + pages: -1, + limitInputPixels: config.service.config.limitInputPixels, + }); // always call rotate to adjust for EXIF data orientation result.rotate(); From f33fe3190b482a42ebc68cc5275fd7f2c49102e6 Mon Sep 17 00:00:00 2001 From: Alex Sherwin Date: Wed, 3 Jan 2024 08:19:41 -0500 Subject: [PATCH 15/19] Allow setting all cookie package serialize/parse options (#9063) * #9062: allow setting all cookie package serialize/parse options * 9062: fix scripts to original arrangement * feat: only add specific properties * Update tiny-days-dance.md * Add examples to the changeset * Update .changeset/tiny-days-dance.md Co-authored-by: Sarah Rainsberger * Update .changeset/tiny-days-dance.md Co-authored-by: Sarah Rainsberger * Update .changeset/tiny-days-dance.md Co-authored-by: Emanuele Stoppa * Update .changeset/tiny-days-dance.md Co-authored-by: Emanuele Stoppa --------- Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com> Co-authored-by: Florian Lefebvre Co-authored-by: Matthew Phillips Co-authored-by: Matthew Phillips Co-authored-by: Sarah Rainsberger Co-authored-by: Emanuele Stoppa --- .changeset/tiny-days-dance.md | 28 +++++++++++++++++++ packages/astro/src/@types/astro.ts | 2 +- packages/astro/src/core/cookies/cookies.ts | 23 +++++++++------ packages/astro/src/core/cookies/index.ts | 1 + packages/astro/test/units/cookies/get.test.js | 24 ++++++++++++++++ packages/astro/test/units/cookies/set.test.js | 23 +++++++++++++++ 6 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 .changeset/tiny-days-dance.md diff --git a/.changeset/tiny-days-dance.md b/.changeset/tiny-days-dance.md new file mode 100644 index 000000000000..ae62b609f485 --- /dev/null +++ b/.changeset/tiny-days-dance.md @@ -0,0 +1,28 @@ +--- +'astro': minor +--- + +Cookie encoding / decoding can now be customized + +Adds new `encode` and `decode` functions to allow customizing how cookies are encoded and decoded. For example, you can bypass the default encoding via `encodeURIComponent` when adding a URL as part of a cookie: + +```astro +--- +import { encodeCookieValue } from "./cookies"; +Astro.cookies.set('url', Astro.url.toString(), { + // Override the default encoding so that URI components are not encoded + encode: value => encodeCookieValue(value) +}); +--- +``` + +Later, you can decode the URL in the same way: + +```astro +--- +import { decodeCookieValue } from "./cookies"; +const url = Astro.cookies.get('url', { + decode: value => decodeCookieValue(value) +}); +--- +``` diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index cadc704cd68e..e9c73fc90f3a 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -64,7 +64,7 @@ export type { } from '../assets/types.js'; export type { RemotePattern } from '../assets/utils/remotePattern.js'; export type { SSRManifest } from '../core/app/types.js'; -export type { AstroCookies } from '../core/cookies/index.js'; +export type { AstroCookies, AstroCookieSetOptions, AstroCookieGetOptions } from '../core/cookies/index.js'; export interface AstroBuiltinProps { 'client:load'?: boolean; diff --git a/packages/astro/src/core/cookies/cookies.ts b/packages/astro/src/core/cookies/cookies.ts index 604f30e63b92..7ed87b3ca91e 100644 --- a/packages/astro/src/core/cookies/cookies.ts +++ b/packages/astro/src/core/cookies/cookies.ts @@ -2,7 +2,7 @@ import type { CookieSerializeOptions } from 'cookie'; import { parse, serialize } from 'cookie'; import { AstroError, AstroErrorData } from '../errors/index.js'; -interface AstroCookieSetOptions { +export interface AstroCookieSetOptions { domain?: string; expires?: Date; httpOnly?: boolean; @@ -10,8 +10,13 @@ interface AstroCookieSetOptions { path?: string; sameSite?: boolean | 'lax' | 'none' | 'strict'; secure?: boolean; + encode?: (value: string) => string; } +export interface AstroCookieGetOptions { + decode?: (value: string) => string; +}; + type AstroCookieDeleteOptions = Pick; interface AstroCookieInterface { @@ -97,7 +102,7 @@ class AstroCookies implements AstroCookiesInterface { * @param key The cookie to get. * @returns An object containing the cookie value as well as convenience methods for converting its value. */ - get(key: string): AstroCookie | undefined { + get(key: string, options: AstroCookieGetOptions | undefined = undefined): AstroCookie | undefined { // Check for outgoing Set-Cookie values first if (this.#outgoing?.has(key)) { let [serializedValue, , isSetValue] = this.#outgoing.get(key)!; @@ -108,7 +113,7 @@ class AstroCookies implements AstroCookiesInterface { } } - const values = this.#ensureParsed(); + const values = this.#ensureParsed(options); if (key in values) { const value = values[key]; return new AstroCookie(value); @@ -121,12 +126,12 @@ class AstroCookies implements AstroCookiesInterface { * @param key The cookie to check for. * @returns */ - has(key: string): boolean { + has(key: string, options: AstroCookieGetOptions | undefined = undefined): boolean { if (this.#outgoing?.has(key)) { let [, , isSetValue] = this.#outgoing.get(key)!; return isSetValue; } - const values = this.#ensureParsed(); + const values = this.#ensureParsed(options); return !!values[key]; } @@ -185,9 +190,9 @@ class AstroCookies implements AstroCookiesInterface { } } - #ensureParsed(): Record { + #ensureParsed(options: AstroCookieGetOptions | undefined = undefined): Record { if (!this.#requestValues) { - this.#parse(); + this.#parse(options); } if (!this.#requestValues) { this.#requestValues = {}; @@ -202,13 +207,13 @@ class AstroCookies implements AstroCookiesInterface { return this.#outgoing; } - #parse() { + #parse(options: AstroCookieGetOptions | undefined = undefined) { const raw = this.#request.headers.get('cookie'); if (!raw) { return; } - this.#requestValues = parse(raw); + this.#requestValues = parse(raw, options); } } diff --git a/packages/astro/src/core/cookies/index.ts b/packages/astro/src/core/cookies/index.ts index c8869f9ae236..912fd2721e19 100644 --- a/packages/astro/src/core/cookies/index.ts +++ b/packages/astro/src/core/cookies/index.ts @@ -4,3 +4,4 @@ export { getSetCookiesFromResponse, responseHasCookies, } from './response.js'; +export type { AstroCookieSetOptions, AstroCookieGetOptions } from "./cookies.js"; \ No newline at end of file diff --git a/packages/astro/test/units/cookies/get.test.js b/packages/astro/test/units/cookies/get.test.js index 216128907543..104ff1f759bb 100644 --- a/packages/astro/test/units/cookies/get.test.js +++ b/packages/astro/test/units/cookies/get.test.js @@ -16,6 +16,30 @@ describe('astro/src/core/cookies', () => { expect(cookies.get('foo').value).to.equal('bar'); }); + it('gets the cookie value with default decode', () => { + const url = 'http://localhost'; + const req = new Request('http://example.com/', { + headers: { + cookie: `url=${encodeURIComponent(url)}`, + }, + }); + const cookies = new AstroCookies(req); + // by default decodeURIComponent is used on the value + expect(cookies.get('url').value).to.equal(url); + }); + + it('gets the cookie value with custom decode', () => { + const url = 'http://localhost'; + const req = new Request('http://example.com/', { + headers: { + cookie: `url=${encodeURIComponent(url)}`, + }, + }); + const cookies = new AstroCookies(req); + // set decode to the identity function to prevent decodeURIComponent on the value + expect(cookies.get('url', { decode: o => o }).value).to.equal(encodeURIComponent(url)); + }); + it("Returns undefined is the value doesn't exist", () => { const req = new Request('http://example.com/'); let cookies = new AstroCookies(req); diff --git a/packages/astro/test/units/cookies/set.test.js b/packages/astro/test/units/cookies/set.test.js index 0913bcc7da1c..16c0d2e874ac 100644 --- a/packages/astro/test/units/cookies/set.test.js +++ b/packages/astro/test/units/cookies/set.test.js @@ -15,6 +15,29 @@ describe('astro/src/core/cookies', () => { expect(headers[0]).to.equal('foo=bar'); }); + it('Sets a cookie value that can be serialized w/ defaultencodeURIComponent behavior', () => { + let req = new Request('http://example.com/'); + let cookies = new AstroCookies(req); + const url = 'http://localhost/path'; + cookies.set('url', url); + let headers = Array.from(cookies.headers()); + expect(headers).to.have.a.lengthOf(1); + // by default cookie value is URI encoded + expect(headers[0]).to.equal(`url=${encodeURIComponent(url)}`); + }); + + it('Sets a cookie value that can be serialized w/ custom encode behavior', () => { + let req = new Request('http://example.com/'); + let cookies = new AstroCookies(req); + const url = 'http://localhost/path'; + // set encode option to the identity function + cookies.set('url', url, { encode: o => o }); + let headers = Array.from(cookies.headers()); + expect(headers).to.have.a.lengthOf(1); + // no longer URI encoded + expect(headers[0]).to.equal(`url=${url}`); + }); + it('Can set cookie options', () => { let req = new Request('http://example.com/'); let cookies = new AstroCookies(req); From 769826edbd9ee2144e9272656dfbe6155b24d67d Mon Sep 17 00:00:00 2001 From: Mads Erik Forberg Date: Wed, 3 Jan 2024 14:20:07 +0100 Subject: [PATCH 16/19] feat: support setting rootMargin for `client:visible` (#9363) * feat: support setting rootMargin for `client:visible` This support adding optional `rootMargin` to the `IntersectionObserver` options. This gives the developer the optional choice to hydrate a bit before the astro-island enters the viewport. * chore: update type for client:visible * chore: added changeset * chore: update types * fix: check if value is string * Update stupid-peas-juggle.md * fix: update .changeset/stupid-peas-juggle.md Co-authored-by: Sarah Rainsberger --------- Co-authored-by: Florian Lefebvre Co-authored-by: Bjorn Lu Co-authored-by: Sarah Rainsberger --- .changeset/stupid-peas-juggle.md | 10 ++++++++++ packages/astro/src/@types/astro.ts | 2 +- packages/astro/src/runtime/client/visible.ts | 8 ++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/stupid-peas-juggle.md diff --git a/.changeset/stupid-peas-juggle.md b/.changeset/stupid-peas-juggle.md new file mode 100644 index 000000000000..1e01c0996636 --- /dev/null +++ b/.changeset/stupid-peas-juggle.md @@ -0,0 +1,10 @@ +--- +'astro': minor +--- + +Extends the `client:visible` directive by adding an optional `rootMargin` property. This allows a component to be hydrated when it is close to the viewport instead of waiting for it to become visible. + +```html + + +``` diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index e9c73fc90f3a..ed6015757cc9 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -70,7 +70,7 @@ export interface AstroBuiltinProps { 'client:load'?: boolean; 'client:idle'?: boolean; 'client:media'?: string; - 'client:visible'?: boolean; + 'client:visible'?: string|boolean; 'client:only'?: boolean | string; } diff --git a/packages/astro/src/runtime/client/visible.ts b/packages/astro/src/runtime/client/visible.ts index de36b29098a5..9e625ca23df9 100644 --- a/packages/astro/src/runtime/client/visible.ts +++ b/packages/astro/src/runtime/client/visible.ts @@ -5,12 +5,16 @@ import type { ClientDirective } from '../../@types/astro.js'; * We target the children because `astro-island` is set to `display: contents` * which doesn't work with IntersectionObserver */ -const visibleDirective: ClientDirective = (load, _options, el) => { +const visibleDirective: ClientDirective = (load, options, el) => { const cb = async () => { const hydrate = await load(); await hydrate(); }; + const ioOptions = { + rootMargin: typeof options.value === 'string' ? options.value : undefined, + }; + const io = new IntersectionObserver((entries) => { for (const entry of entries) { if (!entry.isIntersecting) continue; @@ -19,7 +23,7 @@ const visibleDirective: ClientDirective = (load, _options, el) => { cb(); break; // break loop on first match } - }); + }, ioOptions); for (const child of el.children) { io.observe(child); From f85cb1fab63dfaf926ff4aa1b301810e9250547e Mon Sep 17 00:00:00 2001 From: Mads Erik Forberg Date: Wed, 3 Jan 2024 13:21:03 +0000 Subject: [PATCH 17/19] [ci] format --- packages/astro/src/@types/astro.ts | 8 ++++++-- packages/astro/src/core/cookies/cookies.ts | 7 +++++-- packages/astro/src/core/cookies/index.ts | 2 +- packages/astro/test/units/cookies/get.test.js | 12 ++++++------ packages/astro/test/units/cookies/set.test.js | 12 ++++++------ 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index ed6015757cc9..74cbb4694d9d 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -64,13 +64,17 @@ export type { } from '../assets/types.js'; export type { RemotePattern } from '../assets/utils/remotePattern.js'; export type { SSRManifest } from '../core/app/types.js'; -export type { AstroCookies, AstroCookieSetOptions, AstroCookieGetOptions } from '../core/cookies/index.js'; +export type { + AstroCookies, + AstroCookieSetOptions, + AstroCookieGetOptions, +} from '../core/cookies/index.js'; export interface AstroBuiltinProps { 'client:load'?: boolean; 'client:idle'?: boolean; 'client:media'?: string; - 'client:visible'?: string|boolean; + 'client:visible'?: string | boolean; 'client:only'?: boolean | string; } diff --git a/packages/astro/src/core/cookies/cookies.ts b/packages/astro/src/core/cookies/cookies.ts index 7ed87b3ca91e..f9214c48345f 100644 --- a/packages/astro/src/core/cookies/cookies.ts +++ b/packages/astro/src/core/cookies/cookies.ts @@ -15,7 +15,7 @@ export interface AstroCookieSetOptions { export interface AstroCookieGetOptions { decode?: (value: string) => string; -}; +} type AstroCookieDeleteOptions = Pick; @@ -102,7 +102,10 @@ class AstroCookies implements AstroCookiesInterface { * @param key The cookie to get. * @returns An object containing the cookie value as well as convenience methods for converting its value. */ - get(key: string, options: AstroCookieGetOptions | undefined = undefined): AstroCookie | undefined { + get( + key: string, + options: AstroCookieGetOptions | undefined = undefined + ): AstroCookie | undefined { // Check for outgoing Set-Cookie values first if (this.#outgoing?.has(key)) { let [serializedValue, , isSetValue] = this.#outgoing.get(key)!; diff --git a/packages/astro/src/core/cookies/index.ts b/packages/astro/src/core/cookies/index.ts index 912fd2721e19..1ac732f1b1fb 100644 --- a/packages/astro/src/core/cookies/index.ts +++ b/packages/astro/src/core/cookies/index.ts @@ -4,4 +4,4 @@ export { getSetCookiesFromResponse, responseHasCookies, } from './response.js'; -export type { AstroCookieSetOptions, AstroCookieGetOptions } from "./cookies.js"; \ No newline at end of file +export type { AstroCookieSetOptions, AstroCookieGetOptions } from './cookies.js'; diff --git a/packages/astro/test/units/cookies/get.test.js b/packages/astro/test/units/cookies/get.test.js index 104ff1f759bb..a8bc0d4b5217 100644 --- a/packages/astro/test/units/cookies/get.test.js +++ b/packages/astro/test/units/cookies/get.test.js @@ -17,27 +17,27 @@ describe('astro/src/core/cookies', () => { }); it('gets the cookie value with default decode', () => { - const url = 'http://localhost'; + const url = 'http://localhost'; const req = new Request('http://example.com/', { headers: { cookie: `url=${encodeURIComponent(url)}`, }, }); const cookies = new AstroCookies(req); - // by default decodeURIComponent is used on the value + // by default decodeURIComponent is used on the value expect(cookies.get('url').value).to.equal(url); }); - + it('gets the cookie value with custom decode', () => { - const url = 'http://localhost'; + const url = 'http://localhost'; const req = new Request('http://example.com/', { headers: { cookie: `url=${encodeURIComponent(url)}`, }, }); const cookies = new AstroCookies(req); - // set decode to the identity function to prevent decodeURIComponent on the value - expect(cookies.get('url', { decode: o => o }).value).to.equal(encodeURIComponent(url)); + // set decode to the identity function to prevent decodeURIComponent on the value + expect(cookies.get('url', { decode: (o) => o }).value).to.equal(encodeURIComponent(url)); }); it("Returns undefined is the value doesn't exist", () => { diff --git a/packages/astro/test/units/cookies/set.test.js b/packages/astro/test/units/cookies/set.test.js index 16c0d2e874ac..a583aa1ca34d 100644 --- a/packages/astro/test/units/cookies/set.test.js +++ b/packages/astro/test/units/cookies/set.test.js @@ -18,23 +18,23 @@ describe('astro/src/core/cookies', () => { it('Sets a cookie value that can be serialized w/ defaultencodeURIComponent behavior', () => { let req = new Request('http://example.com/'); let cookies = new AstroCookies(req); - const url = 'http://localhost/path'; + const url = 'http://localhost/path'; cookies.set('url', url); let headers = Array.from(cookies.headers()); expect(headers).to.have.a.lengthOf(1); - // by default cookie value is URI encoded + // by default cookie value is URI encoded expect(headers[0]).to.equal(`url=${encodeURIComponent(url)}`); }); it('Sets a cookie value that can be serialized w/ custom encode behavior', () => { let req = new Request('http://example.com/'); let cookies = new AstroCookies(req); - const url = 'http://localhost/path'; - // set encode option to the identity function - cookies.set('url', url, { encode: o => o }); + const url = 'http://localhost/path'; + // set encode option to the identity function + cookies.set('url', url, { encode: (o) => o }); let headers = Array.from(cookies.headers()); expect(headers).to.have.a.lengthOf(1); - // no longer URI encoded + // no longer URI encoded expect(headers[0]).to.equal(`url=${url}`); }); From fe719e27a84c09e46b515252690678c174a25759 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 3 Jan 2024 21:34:21 +0800 Subject: [PATCH 18/19] Add reverted aria audit rules for dev toolbar (#9377) Co-authored-by: Emanuele Stoppa --- .changeset/chilly-students-glow.md | 5 + packages/astro/package.json | 3 + .../client/dev-overlay/plugins/audit/a11y.ts | 152 ++++++++++++++++++ .../vite-plugin-dev-overlay.ts | 8 + pnpm-lock.yaml | 19 +++ 5 files changed, 187 insertions(+) create mode 100644 .changeset/chilly-students-glow.md diff --git a/.changeset/chilly-students-glow.md b/.changeset/chilly-students-glow.md new file mode 100644 index 000000000000..b7f5ca4e896c --- /dev/null +++ b/.changeset/chilly-students-glow.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Adds "Missing ARIA roles check" and "Unsupported ARIA roles check" audit rules for the dev toolbar diff --git a/packages/astro/package.json b/packages/astro/package.json index 771289fe6df8..aa585b45ea3b 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -126,6 +126,8 @@ "@babel/types": "^7.23.3", "@types/babel__core": "^7.20.4", "acorn": "^8.11.2", + "aria-query": "^5.3.0", + "axobject-query": "^4.0.0", "boxen": "^7.1.1", "chokidar": "^3.5.3", "ci-info": "^4.0.0", @@ -182,6 +184,7 @@ "devDependencies": { "@astrojs/check": "^0.3.1", "@playwright/test": "1.40.0", + "@types/aria-query": "^5.0.4", "@types/babel__generator": "^7.6.7", "@types/babel__traverse": "^7.20.4", "@types/chai": "^4.3.10", diff --git a/packages/astro/src/runtime/client/dev-overlay/plugins/audit/a11y.ts b/packages/astro/src/runtime/client/dev-overlay/plugins/audit/a11y.ts index 15432e910538..5a1fd4693893 100644 --- a/packages/astro/src/runtime/client/dev-overlay/plugins/audit/a11y.ts +++ b/packages/astro/src/runtime/client/dev-overlay/plugins/audit/a11y.ts @@ -23,6 +23,10 @@ * SOFTWARE. */ +import type { ARIARoleDefinitionKey } from 'aria-query'; +import { aria, roles } from 'aria-query'; +// @ts-expect-error package does not provide types +import { AXObjectRoles, elementAXObjects } from 'axobject-query'; import type { AuditRuleWithSelector } from './index.js'; const a11y_required_attributes = { @@ -125,6 +129,8 @@ const a11y_required_content = [ const a11y_distracting_elements = ['blink', 'marquee']; +// Unused for now +// eslint-disable-next-line @typescript-eslint/no-unused-vars const a11y_nested_implicit_semantics = new Map([ ['header', 'banner'], ['footer', 'contentinfo'], @@ -443,6 +449,61 @@ export const a11y: AuditRuleWithSelector[] = [ 'This will move elements out of the expected tab order, creating a confusing experience for keyboard users.', selector: '[tabindex]:not([tabindex="-1"]):not([tabindex="0"])', }, + { + code: 'a11y-role-has-required-aria-props', + title: 'Missing attributes required for ARIA role', + message: (element) => { + const { __astro_role: role, __astro_missing_attributes: required } = element as any; + return `${ + element.localName + } element is missing required attributes for its role (${role}): ${required.join(', ')}`; + }, + selector: '*', + match(element) { + const role = getRole(element); + if (!role) return false; + if (is_semantic_role_element(role, element.localName, getAttributeObject(element))) { + return; + } + const { requiredProps } = roles.get(role)!; + const required_role_props = Object.keys(requiredProps); + const missingProps = required_role_props.filter((prop) => !element.hasAttribute(prop)); + if (missingProps.length > 0) { + (element as any).__astro_role = role; + (element as any).__astro_missing_attributes = missingProps; + return true; + } + }, + }, + + { + code: 'a11y-role-supports-aria-props', + title: 'Unsupported ARIA attribute', + message: (element) => { + const { __astro_role: role, __astro_unsupported_attributes: unsupported } = element as any; + return `${ + element.localName + } element has ARIA attributes that are not supported by its role (${role}): ${unsupported.join( + ', ' + )}`; + }, + selector: '*', + match(element) { + const role = getRole(element); + if (!role) return false; + const { props } = roles.get(role)!; + const attributes = getAttributeObject(element); + const unsupportedAttributes = aria.keys().filter((attribute) => !(attribute in props)); + const invalidAttributes: string[] = Object.keys(attributes).filter( + (key) => key.startsWith('aria-') && unsupportedAttributes.includes(key as any) + ); + if (invalidAttributes.length > 0) { + (element as any).__astro_role = role; + (element as any).__astro_unsupported_attributes = invalidAttributes; + return true; + } + }, + }, { code: 'a11y-structure', title: 'Invalid DOM structure', @@ -476,6 +537,19 @@ export const a11y: AuditRuleWithSelector[] = [ }, ]; +// Unused for now +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const a11y_labelable = [ + 'button', + 'input', + 'keygen', + 'meter', + 'output', + 'progress', + 'select', + 'textarea', +]; + /** * Exceptions to the rule which follows common A11y conventions * TODO make this configurable by the user @@ -489,3 +563,81 @@ const a11y_non_interactive_element_to_interactive_role_exceptions = { td: ['gridcell'], fieldset: ['radiogroup', 'presentation'], }; + +const combobox_if_list = ['email', 'search', 'tel', 'text', 'url']; +function input_implicit_role(attributes: Record) { + if (!('type' in attributes)) return; + const { type, list } = attributes; + if (!type) return; + if (list && combobox_if_list.includes(type)) { + return 'combobox'; + } + return input_type_to_implicit_role.get(type); +} + +/** @param {Map} attribute_map */ +function menuitem_implicit_role(attributes: Record) { + if (!('type' in attributes)) return; + const { type } = attributes; + if (!type) return; + return menuitem_type_to_implicit_role.get(type); +} + +function getRole(element: Element): ARIARoleDefinitionKey | undefined { + if (element.hasAttribute('role')) { + return element.getAttribute('role')! as ARIARoleDefinitionKey; + } + return getImplicitRole(element) as ARIARoleDefinitionKey; +} + +function getImplicitRole(element: Element) { + const name = element.localName; + const attrs = getAttributeObject(element); + if (name === 'menuitem') { + return menuitem_implicit_role(attrs); + } else if (name === 'input') { + return input_implicit_role(attrs); + } else { + return a11y_implicit_semantics.get(name); + } +} + +function getAttributeObject(element: Element): Record { + let obj: Record = {}; + for (let i = 0; i < element.attributes.length; i++) { + const attribute = element.attributes.item(i)!; + obj[attribute.name] = attribute.value; + } + return obj; +} + +/** + * @param {import('aria-query').ARIARoleDefinitionKey} role + * @param {string} tag_name + * @param {Map} attribute_map + */ +function is_semantic_role_element( + role: string, + tag_name: string, + attributes: Record +) { + for (const [schema, ax_object] of elementAXObjects.entries()) { + if ( + schema.name === tag_name && + (!schema.attributes || + schema.attributes.every((attr: any) => attributes[attr.name] === attr.value)) + ) { + for (const name of ax_object) { + const axRoles = AXObjectRoles.get(name); + if (axRoles) { + for (const { name: _name } of axRoles) { + if (_name === role) { + return true; + } + } + } + } + } + } + return false; +} diff --git a/packages/astro/src/vite-plugin-dev-overlay/vite-plugin-dev-overlay.ts b/packages/astro/src/vite-plugin-dev-overlay/vite-plugin-dev-overlay.ts index 31cdb8f71ac0..d8227a8af082 100644 --- a/packages/astro/src/vite-plugin-dev-overlay/vite-plugin-dev-overlay.ts +++ b/packages/astro/src/vite-plugin-dev-overlay/vite-plugin-dev-overlay.ts @@ -7,6 +7,14 @@ const resolvedVirtualModuleId = '\0' + VIRTUAL_MODULE_ID; export default function astroDevOverlay({ settings }: AstroPluginOptions): vite.Plugin { return { name: 'astro:dev-overlay', + config() { + return { + optimizeDeps: { + // Optimize CJS dependencies used by the dev toolbar + include: ['astro > aria-query', 'astro > axobject-query'], + }, + }; + }, resolveId(id) { if (id === VIRTUAL_MODULE_ID) { return resolvedVirtualModuleId; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ea42a5abe7ce..7902ad244ac2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -524,6 +524,12 @@ importers: acorn: specifier: ^8.11.2 version: 8.11.3 + aria-query: + specifier: ^5.3.0 + version: 5.3.0 + axobject-query: + specifier: ^4.0.0 + version: 4.0.0 boxen: specifier: ^7.1.1 version: 7.1.1 @@ -682,6 +688,9 @@ importers: '@playwright/test': specifier: 1.40.0 version: 1.40.0 + '@types/aria-query': + specifier: ^5.0.4 + version: 5.0.4 '@types/babel__generator': specifier: ^7.6.7 version: 7.6.8 @@ -7341,6 +7350,10 @@ packages: resolution: {integrity: sha512-BSNTroRhmBkNiyd7ELK/5Boja92hnQMST6H4z1BqXKeMVzHjp9o1j5poqd5Tyhjd8oMFwxYC4I00eghfg2xrTA==} dev: false + /@types/aria-query@5.0.4: + resolution: {integrity: sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==} + dev: true + /@types/babel__core@7.20.5: resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} dependencies: @@ -8444,6 +8457,12 @@ packages: dependencies: dequal: 2.0.3 + /axobject-query@4.0.0: + resolution: {integrity: sha512-+60uv1hiVFhHZeO+Lz0RYzsVHy5Wr1ayX0mwda9KPDVLNJgZ1T9Ny7VmFbLDzxsH0D87I86vgj3gFrjTJUYznw==} + dependencies: + dequal: 2.0.3 + dev: false + /b4a@1.6.4: resolution: {integrity: sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==} dev: false From da307e4a080483f8763f1919a05fa2194bb14e22 Mon Sep 17 00:00:00 2001 From: Jenna Smith <175330+jjenzz@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:39:17 +0000 Subject: [PATCH 19/19] feat: add extendable `CSSProperties` interface (#9587) * feat: add extendable `CSSProperties` interface * Update .changeset/slow-kiwis-own.md Co-authored-by: Florian Lefebvre --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> Co-authored-by: Florian Lefebvre --- .changeset/slow-kiwis-own.md | 5 +++++ packages/astro/astro-jsx.d.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/slow-kiwis-own.md diff --git a/.changeset/slow-kiwis-own.md b/.changeset/slow-kiwis-own.md new file mode 100644 index 000000000000..8e22e97d9ff8 --- /dev/null +++ b/.changeset/slow-kiwis-own.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Adds a `CSSProperties` interface that allows extending the style attribute diff --git a/packages/astro/astro-jsx.d.ts b/packages/astro/astro-jsx.d.ts index fd4632eaedc1..f79c5a36544a 100644 --- a/packages/astro/astro-jsx.d.ts +++ b/packages/astro/astro-jsx.d.ts @@ -499,6 +499,15 @@ declare namespace astroHTML.JSX { KebabCSSDOMProperties & DOMCSSProperties & AllCSSProperties >; + interface CSSProperties extends StyleObject { + /** + * Extend namespace to add properties or an index signature of your own. + * + * For more information, visit: + * https://docs.astro.build/en/guides/typescript/#built-in-html-attributes + */ + } + interface HTMLAttributes extends AriaAttributes, DOMAttributes, AstroBuiltinAttributes { // Standard HTML Attributes accesskey?: string | undefined | null; @@ -547,7 +556,7 @@ declare namespace astroHTML.JSX { popover?: boolean | string | undefined | null; slot?: string | undefined | null; spellcheck?: 'true' | 'false' | boolean | undefined | null; - style?: string | StyleObject | undefined | null; + style?: string | CSSProperties | undefined | null; tabindex?: number | string | undefined | null; title?: string | undefined | null; translate?: 'yes' | 'no' | '' | undefined | null;