diff --git a/.changeset/afraid-sloths-shake.md b/.changeset/afraid-sloths-shake.md new file mode 100644 index 000000000000..98c8efb37206 --- /dev/null +++ b/.changeset/afraid-sloths-shake.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improves warning logs for invalid content collection configuration diff --git a/.changeset/config.json b/.changeset/config.json index 8292fbe07858..030941db2347 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,10 +1,12 @@ { - "$schema": "https://unpkg.com/@changesets/config@1.7.0/schema.json", + "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", "changelog": ["@changesets/changelog-github", { "repo": "withastro/astro" }], "commit": false, "linked": [], "access": "public", "baseBranch": "main", "updateInternalDependencies": "patch", - "ignore": ["@example/*", "@test/*"] + "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { + "onlyUpdatePeerDependentsWhenOutOfRange": true + } } diff --git a/.changeset/pretty-pumpkins-work.md b/.changeset/pretty-pumpkins-work.md deleted file mode 100644 index 40d19f5cd65d..000000000000 --- a/.changeset/pretty-pumpkins-work.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fixes an issue that was breaking asset and stylesheet URLs when building for a subpath diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000000..49a76b9a5b3c --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,13 @@ +FROM mcr.microsoft.com/devcontainers/javascript-node:1-18 + +# Install playwright +RUN npm install -g @playwright/test + +# Install latest pnpm +RUN npm install -g pnpm + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && curl -sSL https://dl.google.com/linux/direct/google-chrome-stable_current_$(dpkg --print-architecture).deb -o /tmp/chrome.deb \ + && apt-get -y install /tmp/chrome.deb + +COPY welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt \ No newline at end of file diff --git a/.devcontainer/basics/devcontainer.json b/.devcontainer/basics/devcontainer.json new file mode 100644 index 000000000000..bb1707ff063b --- /dev/null +++ b/.devcontainer/basics/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Basics", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/basics", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/blog/devcontainer.json b/.devcontainer/blog/devcontainer.json new file mode 100644 index 000000000000..d587fead507d --- /dev/null +++ b/.devcontainer/blog/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Blog", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/blog", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/component/devcontainer.json b/.devcontainer/component/devcontainer.json new file mode 100644 index 000000000000..c2d3e50c3545 --- /dev/null +++ b/.devcontainer/component/devcontainer.json @@ -0,0 +1,21 @@ +{ + "name": "Component Template", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/component", + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "customizations": { + "codespaces": { + "openFiles": ["src/MyComponent.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000000..6b8edf60573c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +{ + "name": "Contribute to Astro", + "build": { + "dockerfile": "Dockerfile" + }, + + "features": { + "ghcr.io/devcontainers/features/desktop-lite:1": {} + }, + + "postCreateCommand": "pnpm install && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Astro tests": "pnpm run test" + }, + + "customizations": { + "codespaces": { + "openFiles": ["README.md", "CONTRIBUTING.md"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/docs/devcontainer.json b/.devcontainer/docs/devcontainer.json new file mode 100644 index 000000000000..a26ff9d8c751 --- /dev/null +++ b/.devcontainer/docs/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Docs Site", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/docs", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/example-welcome-message.txt b/.devcontainer/example-welcome-message.txt new file mode 100644 index 000000000000..72ef4734f5c5 --- /dev/null +++ b/.devcontainer/example-welcome-message.txt @@ -0,0 +1,5 @@ +👋 Welcome to "Astro" in GitHub Codespaces! + +🛠️ Your environment is fully setup with all the required software. + +🚀 The example app should automatically start soon in a new terminal tab. \ No newline at end of file diff --git a/.devcontainer/examples.Dockerfile b/.devcontainer/examples.Dockerfile new file mode 100644 index 000000000000..6ab758c823fd --- /dev/null +++ b/.devcontainer/examples.Dockerfile @@ -0,0 +1,6 @@ +FROM mcr.microsoft.com/devcontainers/javascript-node:1-18 + +# Install latest pnpm +RUN npm install -g pnpm + +COPY example-welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt \ No newline at end of file diff --git a/.devcontainer/framework-alpine/devcontainer.json b/.devcontainer/framework-alpine/devcontainer.json new file mode 100644 index 000000000000..1b8f26503d69 --- /dev/null +++ b/.devcontainer/framework-alpine/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Alpine", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/framework-alpine", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/framework-lit/devcontainer.json b/.devcontainer/framework-lit/devcontainer.json new file mode 100644 index 000000000000..4eb1d59791d0 --- /dev/null +++ b/.devcontainer/framework-lit/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Lit", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/framework-lit", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/framework-multiple/devcontainer.json b/.devcontainer/framework-multiple/devcontainer.json new file mode 100644 index 000000000000..660df3e32411 --- /dev/null +++ b/.devcontainer/framework-multiple/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Kitchen Sink (Multiple Frameworks)", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/framework-multiple", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/framework-preact/devcontainer.json b/.devcontainer/framework-preact/devcontainer.json new file mode 100644 index 000000000000..5c71cb6f2d0d --- /dev/null +++ b/.devcontainer/framework-preact/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Preact", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/framework-preact", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/framework-react/devcontainer.json b/.devcontainer/framework-react/devcontainer.json new file mode 100644 index 000000000000..f130c26ff3a4 --- /dev/null +++ b/.devcontainer/framework-react/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "React", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/framework-react", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/framework-solid/devcontainer.json b/.devcontainer/framework-solid/devcontainer.json new file mode 100644 index 000000000000..4a3e65ec855a --- /dev/null +++ b/.devcontainer/framework-solid/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Solid", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/framework-solid", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/framework-svelte/devcontainer.json b/.devcontainer/framework-svelte/devcontainer.json new file mode 100644 index 000000000000..d8db14287d87 --- /dev/null +++ b/.devcontainer/framework-svelte/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Svelte", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/framework-svelte", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/framework-vue/devcontainer.json b/.devcontainer/framework-vue/devcontainer.json new file mode 100644 index 000000000000..db9a6287834c --- /dev/null +++ b/.devcontainer/framework-vue/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Vue", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/framework-vue", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/hackernews/devcontainer.json b/.devcontainer/hackernews/devcontainer.json new file mode 100644 index 000000000000..dc113624d6c1 --- /dev/null +++ b/.devcontainer/hackernews/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Hackernews", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/hackernews", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/[...stories].astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/integration/devcontainer.json b/.devcontainer/integration/devcontainer.json new file mode 100644 index 000000000000..8e6a4df8d852 --- /dev/null +++ b/.devcontainer/integration/devcontainer.json @@ -0,0 +1,21 @@ +{ + "name": "Integration Package", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/integration", + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "customizations": { + "codespaces": { + "openFiles": ["index.ts"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/minimal/devcontainer.json b/.devcontainer/minimal/devcontainer.json new file mode 100644 index 000000000000..1756ffd8baaf --- /dev/null +++ b/.devcontainer/minimal/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Minimal", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/minimal", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/non-html-pages/devcontainer.json b/.devcontainer/non-html-pages/devcontainer.json new file mode 100644 index 000000000000..b47fae4e9186 --- /dev/null +++ b/.devcontainer/non-html-pages/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Non-HTML Pages", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/non-html-pages", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/portfolio/devcontainer.json b/.devcontainer/portfolio/devcontainer.json new file mode 100644 index 000000000000..39e283d83b5d --- /dev/null +++ b/.devcontainer/portfolio/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Portfolio", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/portfolio", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/ssr/devcontainer.json b/.devcontainer/ssr/devcontainer.json new file mode 100644 index 000000000000..2ace9a1dd012 --- /dev/null +++ b/.devcontainer/ssr/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "SSR", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/ssr", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/welcome-message.txt b/.devcontainer/welcome-message.txt new file mode 100644 index 000000000000..f2ca4bf31085 --- /dev/null +++ b/.devcontainer/welcome-message.txt @@ -0,0 +1,4 @@ +👋 Welcome to Astro! + +🛠️ Your environment is fully setup with all required software installed. Tests will + be running shortly in a separate terminal tab. diff --git a/.devcontainer/with-markdown-plugins/devcontainer.json b/.devcontainer/with-markdown-plugins/devcontainer.json new file mode 100644 index 000000000000..21894a77c42b --- /dev/null +++ b/.devcontainer/with-markdown-plugins/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Markdown with Plugins", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/with-markdown-plugins", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.md"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/with-markdown-shiki/devcontainer.json b/.devcontainer/with-markdown-shiki/devcontainer.json new file mode 100644 index 000000000000..a3f51750adbf --- /dev/null +++ b/.devcontainer/with-markdown-shiki/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Markdown with Shiki", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/with-markdown-shiki", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.md"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/with-mdx/devcontainer.json b/.devcontainer/with-mdx/devcontainer.json new file mode 100644 index 000000000000..13ff67464285 --- /dev/null +++ b/.devcontainer/with-mdx/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "MDX", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/with-mdx", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.mdx"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/with-nanostores/devcontainer.json b/.devcontainer/with-nanostores/devcontainer.json new file mode 100644 index 000000000000..656776b2a049 --- /dev/null +++ b/.devcontainer/with-nanostores/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Nanostores", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/with-nanostores", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/with-tailwindcss/devcontainer.json b/.devcontainer/with-tailwindcss/devcontainer.json new file mode 100644 index 000000000000..6e7298a6f994 --- /dev/null +++ b/.devcontainer/with-tailwindcss/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Tailwind", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/with-tailwindcss", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.devcontainer/with-vitest/devcontainer.json b/.devcontainer/with-vitest/devcontainer.json new file mode 100644 index 000000000000..7931089395da --- /dev/null +++ b/.devcontainer/with-vitest/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Vitest", + "build": { + "dockerfile": "../examples.Dockerfile" + }, + + "workspaceFolder": "/workspaces/astro/examples/with-vitest", + + "portsAttributes": { + "4321": { + "label": "Application", + "onAutoForward": "openPreview" + } + }, + + "forwardPorts": [4321], + + "postCreateCommand": "pnpm install && cd /workspaces/astro && pnpm run build", + + "waitFor": "postCreateCommand", + + "postAttachCommand": { + "Server": "pnpm start --host" + }, + + "customizations": { + "codespaces": { + "openFiles": ["src/pages/index.astro"] + }, + "vscode": { + "extensions": ["astro-build.astro-vscode", "esbenp.prettier-vscode"] + } + } +} diff --git a/.editorconfig b/.editorconfig index 0bb4ad6ecde1..6c6c428353bd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,5 +11,5 @@ indent_style = tab insert_final_newline = true trim_trailing_whitespace = false -[{.*,*.md,*.json,*.toml,*.yml,}] +[{.*,*.md,*.json,*.toml,*.yml,*.json5}] indent_style = space diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index c2d3e84009d9..000000000000 --- a/.eslintignore +++ /dev/null @@ -1,8 +0,0 @@ -**/*.js -**/*.ts -!packages/astro/**/*.js -!packages/astro/**/*.ts -packages/astro/test/**/*.js -packages/astro/vendor/vite/**/* -.github -.changeset diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index d2d00d0816d6..000000000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - parser: '@typescript-eslint/parser', - extends: ['plugin:@typescript-eslint/recommended', 'prettier'], - plugins: ['@typescript-eslint', 'prettier'], - rules: { - '@typescript-eslint/ban-ts-comment': 'off', - '@typescript-eslint/camelcase': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-unused-vars': 'off', - '@typescript-eslint/no-use-before-define': 'off', - '@typescript-eslint/no-var-requires': 'off', - '@typescript-eslint/no-this-alias': 'off', - 'no-console': 'warn', - 'prefer-const': 'off', - 'no-shadow': 'off', - '@typescript-eslint/no-shadow': ['error'], - }, -}; diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 495a5ff2ee36..6c950a14e8ac 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,4 +1,10 @@ # Switch to tabs (Use Accessible Indentation #2253) 6ddd7678ffb6598ae6e263706813cb5e94535f02 # prettier config update -1335797903a57716e9a02b0ffd8ca636b3883c62 \ No newline at end of file +1335797903a57716e9a02b0ffd8ca636b3883c62 +# Manually format .astro files in example projects (#3862) +59e8c71786fd1c154904b3fefa7d26d88f4d92d2 +# Change formatting (#10180) +062623438b5dfd66682a967edc7b7c91bd29e888 +# Update to trailingComma: 'all' (#11640) +72c7ae9901de927ae8d9d5be63cbaef4f976422c diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index d801514c3569..000000000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @snowpackjs/maintainers diff --git a/.github/ISSUE_TEMPLATE/---01-bug-report.yml b/.github/ISSUE_TEMPLATE/---01-bug-report.yml index 1b241039a384..9f9bb166dea5 100644 --- a/.github/ISSUE_TEMPLATE/---01-bug-report.yml +++ b/.github/ISSUE_TEMPLATE/---01-bug-report.yml @@ -1,6 +1,5 @@ name: "\U0001F41B Bug Report" description: Report an issue or possible bug -title: "\U0001F41B BUG:" labels: [] assignees: [] body: @@ -11,45 +10,44 @@ body: Thank you for taking the time to file a bug report! Please fill out this form as completely as possible. ✅ I am using the **latest version of Astro** and all plugins. - ✅ I am using a version of Node that supports ESM (`v14.15.0+`, or `v16.0.0+`) - - type: input - attributes: - label: What version of `astro` are you using? - placeholder: 0.0.0 - validations: - required: true - - type: input + ✅ I am using a version of Node that Astro supports (`v18.17.1` or `v20.3.0` or higher.) + - type: textarea + id: astro-info attributes: - label: Are you using an SSR adapter? If so, which one? - placeholder: None, or Netlify, Vercel, Cloudflare, etc. + label: Astro Info + description: Run the command `astro info` in your terminal and paste the output here. Please review the data before submitting in case there is any sensitive information you don't want to share. + render: block validations: required: true - type: input + id: browser attributes: - label: What package manager are you using? - placeholder: npm, yarn, pnpm - validations: - required: true - - type: input + label: If this issue only occurs in one browser, which browser is a problem? + placeholder: Chrome, Firefox, Safari + - type: textarea + id: bug-description attributes: - label: What operating system are you using? - placeholder: Mac, Windows, Linux + label: Describe the Bug + description: A clear and concise description of what the bug is. validations: required: true - type: textarea + id: bug-expectation attributes: - label: Describe the Bug - description: A clear and concise description of what the bug is. + label: What's the expected result? + description: Describe what you expect to happen. validations: required: true - type: input + id: bug-reproduction attributes: label: Link to Minimal Reproducible Example - description: 'Use [astro.new](https://astro.new) to create a minimal reproduction of the problem. **A minimal reproduction is required** so that others can help debug your issue. If a report is vague (e.g. just a generic error message) and has no reproduction, it may be auto-closed.' + description: 'Use [StackBlitz](https://astro.new/repro) to create a minimal reproduction of the problem. **A minimal reproduction is required** so that others can help debug your issue. If a report is vague (e.g. just a generic error message) and has no reproduction, it may be auto-closed. Not sure how to create a minimal example? [Read our guide](https://docs.astro.build/en/guides/troubleshooting/#creating-minimal-reproductions)' placeholder: 'https://stackblitz.com/abcd1234' validations: required: true - type: checkboxes + id: will-pr attributes: label: Participation options: diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index e896bd2f2275..5c5f4e11b8ef 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,14 +1,14 @@ blank_issues_enabled: false contact_links: + - name: 💁 Support + url: https://astro.build/chat + about: 'This issue tracker is not for support questions. Join us on Discord for assistance!' - name: 📘 Documentation url: https://github.com/withastro/docs about: File an issue or make an improvement to the docs website. - name: 💡 Ideas for New Features, Improvements and RFCs - url: https://github.com/withastro/rfcs/discussions + url: https://github.com/withastro/roadmap/discussions about: Propose and discuss future improvements to Astro - name: 👾 Chat url: https://astro.build/chat about: Our Discord server is active, come join us! - - name: 💁 Support - url: https://astro.build/chat - about: 'This issue tracker is not for support questions. Join us on Discord for assistance!' diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index edec77376cb0..59e8413b602e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -12,6 +12,9 @@ ## Docs - + + + + - \ No newline at end of file + diff --git a/.github/assets/banner.jpg b/.github/assets/banner.jpg new file mode 100644 index 000000000000..e88438780364 Binary files /dev/null and b/.github/assets/banner.jpg differ diff --git a/.github/assets/banner.png b/.github/assets/banner.png new file mode 100644 index 000000000000..7696fafb75c0 Binary files /dev/null and b/.github/assets/banner.png differ diff --git a/.github/assets/deepgram-dark.svg b/.github/assets/deepgram-dark.svg new file mode 100644 index 000000000000..9b66066ff35b --- /dev/null +++ b/.github/assets/deepgram-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/deepgram.svg b/.github/assets/deepgram.svg new file mode 100644 index 000000000000..ec55ad3fa41d --- /dev/null +++ b/.github/assets/deepgram.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/monogram-dark.svg b/.github/assets/monogram-dark.svg new file mode 100644 index 000000000000..feccf6fe840a --- /dev/null +++ b/.github/assets/monogram-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/monogram.svg b/.github/assets/monogram.svg new file mode 100644 index 000000000000..e60aa428e6e6 --- /dev/null +++ b/.github/assets/monogram.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/netlify-dark.svg b/.github/assets/netlify-dark.svg index d974206de75e..2fcff1dde7cf 100644 --- a/.github/assets/netlify-dark.svg +++ b/.github/assets/netlify-dark.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/.github/assets/netlify.svg b/.github/assets/netlify.svg index 7a068f2445a4..aa07cbcabb4f 100644 --- a/.github/assets/netlify.svg +++ b/.github/assets/netlify.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/.github/assets/qoddi-dark.png b/.github/assets/qoddi-dark.png new file mode 100644 index 000000000000..b666799d99d9 Binary files /dev/null and b/.github/assets/qoddi-dark.png differ diff --git a/.github/assets/qoddi.png b/.github/assets/qoddi.png new file mode 100644 index 000000000000..e7a1c3c43790 Binary files /dev/null and b/.github/assets/qoddi.png differ diff --git a/.github/assets/sentry-dark.svg b/.github/assets/sentry-dark.svg new file mode 100644 index 000000000000..1e09e141b268 --- /dev/null +++ b/.github/assets/sentry-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/sentry.svg b/.github/assets/sentry.svg index a4470b601ecb..56e122e04a3f 100644 --- a/.github/assets/sentry.svg +++ b/.github/assets/sentry.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/.github/assets/shipshape-dark.svg b/.github/assets/shipshape-dark.svg new file mode 100644 index 000000000000..038534ec9e37 --- /dev/null +++ b/.github/assets/shipshape-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/shipshape.svg b/.github/assets/shipshape.svg new file mode 100644 index 000000000000..6c2e2ee70f11 --- /dev/null +++ b/.github/assets/shipshape.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/stackup-dark.svg b/.github/assets/stackup-dark.svg index 3b8ed2746b8c..b7a45841051c 100644 --- a/.github/assets/stackup-dark.svg +++ b/.github/assets/stackup-dark.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/.github/assets/stackup.svg b/.github/assets/stackup.svg index 207f28b2a52f..6faa178f55a3 100644 --- a/.github/assets/stackup.svg +++ b/.github/assets/stackup.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/.github/assets/storyblok-dark.svg b/.github/assets/storyblok-dark.svg new file mode 100644 index 000000000000..9df58c4bbb4b --- /dev/null +++ b/.github/assets/storyblok-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/storyblok.svg b/.github/assets/storyblok.svg new file mode 100644 index 000000000000..ec77593560e3 --- /dev/null +++ b/.github/assets/storyblok.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/assets/vercel-dark.svg b/.github/assets/vercel-dark.svg index 31c2d5b88249..1fbf0317d0f1 100644 --- a/.github/assets/vercel-dark.svg +++ b/.github/assets/vercel-dark.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/.github/assets/vercel.svg b/.github/assets/vercel.svg index d2b7685c5c09..6711aa56f9a2 100644 --- a/.github/assets/vercel.svg +++ b/.github/assets/vercel.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/.github/extract-artifacts.sh b/.github/extract-artifacts.sh deleted file mode 100755 index 03f0d19a1ac8..000000000000 --- a/.github/extract-artifacts.sh +++ /dev/null @@ -1,11 +0,0 @@ -cd artifacts -mkdir -p ../tmp/packages -mv * ../tmp/packages -cd ../tmp -tar -cvzpf artifacts.tar.gz * -mv artifacts.tar.gz ../artifacts.tar.gz -cd .. -tar -xvzpf artifacts.tar.gz -rm -rf artifacts -rm -rf tmp -rm -f artifacts.tar.gz diff --git a/.github/labeler.yml b/.github/labeler.yml index e6ec99206025..b0d27800ba97 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,40 +1,44 @@ # See https://github.com/actions/labeler -example: +'pkg: example': - examples/**/* '🚨 action': - .github/workflows/** -test: -- packages/**/*.test.js - -core: +'pkg: astro': - packages/astro/** -create-astro: +'pkg: create-astro': - packages/create-astro/** -markdown: +'pkg: db': +- packages/integrations/db/** + +'feat: markdown': - packages/markdown/** -renderer: +'pkg: integration': - packages/integrations/** -framework-lit: +'pkg: lit': - packages/integrations/lit/** -framework-preact: +'pkg: preact': - packages/integrations/preact/** -framework-react: +'pkg: react': - packages/integrations/react/** -framework-solid: +'pkg: solid': - packages/integrations/solid/** -framework-svelte: +'pkg: svelte': - packages/integrations/svelte/** -framework-vue: +'pkg: vue': - packages/integrations/vue/** + +'docs pr': +- packages/astro/src/types/public/** +- packages/astro/src/core/errors/errors-data.ts diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 000000000000..ead596c39574 --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,35 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended", + "schedule:weekly", + "group:allNonMajor", + ":disablePeerDependencies", + "regexManagers:biomeVersions", + ], + "labels": ["dependencies"], + "rangeStrategy": "bump", + "postUpdateOptions": ["pnpmDedupe"], + "ignorePaths": ["**/node_modules/**"], + "ignoreDeps": [ + // manually bumping deps + "@biomejs/biome", + "@types/node", + "@preact/preset-vite", // v2.8.3 starts to use Vite's esbuild for perf, but this conflicts with the react plugin + "astro-embed", // TODO: investigate upgrade (zod import issues with atproto) + "drizzle-orm", // TODO: investigate upgrade (has type issues) + "sharp", + + // manually bumping workflow actions + "actions/labeler", + + // ignore "engines" update + "node", + "npm", + "pnpm", + + // follow vite deps version + "postcss-load-config", + "esbuild", + ], +} diff --git a/.github/scripts/announce.mjs b/.github/scripts/announce.mjs new file mode 100755 index 000000000000..df73040372eb --- /dev/null +++ b/.github/scripts/announce.mjs @@ -0,0 +1,166 @@ +import { readFile } from 'node:fs/promises'; +import { fileURLToPath } from 'node:url'; +import { globby as glob } from 'globby'; +import { setOutput } from './utils.mjs'; + +const { GITHUB_REF = 'main' } = process.env; +const baseUrl = new URL(`https://github.com/withastro/astro/blob/${GITHUB_REF}/`); + +const emojis = ['🎉', '🥳', '🚀', '🧑', '🎊', '🏆', '✅', '🤩', '🤖', '🙌']; +const descriptors = [ + 'new releases', + 'hot and fresh updates', + 'shiny updates', + 'exciting changes', + 'package updates', + 'awesome updates', + 'bug fixes and features', + 'updates', +]; +const verbs = [ + 'just went out!', + 'just launched!', + 'now available!', + 'in the wild!', + 'now live!', + 'hit the registry!', + 'to share!', + 'for you!', + 'for y’all! 🤠', + 'comin’ your way!', + 'comin’ atcha!', + 'comin’ in hot!', + 'freshly minted on the blockchain! (jk)', + '[is] out (now with 100% more reticulated splines!)', + '(as seen on TV!)', + 'just dropped!', + '– artisanally hand-crafted just for you.', + '– oh happy day!', + '– enjoy!', + 'now out. Be the first on your block to download!', + 'made with love 💕', + '[is] out! Our best [version] yet!', + '[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!', + '... HUZZAH!', + '[has] landed!', + 'landed! The internet just got a little more fun.', + '– from our family to yours.', + '– go forth and build!', +]; +const extraVerbs = [ + 'new', + 'here', + 'released', + 'freshly made', + 'going out', + 'hitting the registry', + 'available', + 'live now', + 'hot and fresh', + 'for you', + "comin' atcha", +]; + +function item(items) { + return items[Math.floor(Math.random() * items.length)]; +} + +const plurals = new Map([ + ['is', 'are'], + ['has', 'have'], +]); + +function pluralize(text) { + return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => + plurals.has(match) ? plurals.get(match) : `${match}s`, + ); +} + +function singularlize(text) { + return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => `${match}`); +} + +const packageMap = new Map(); +async function generatePackageMap() { + const packageRoot = new URL('../../packages/', import.meta.url); + const packages = await glob(['*/package.json', '*/*/package.json'], { + cwd: fileURLToPath(packageRoot), + }); + await Promise.all( + packages.map(async (pkg) => { + const pkgFile = fileURLToPath(new URL(pkg, packageRoot)); + const content = await readFile(pkgFile).then((res) => JSON.parse(res.toString())); + packageMap.set(content.name, `./packages/${pkg.replace('/package.json', '')}`); + }), + ); +} + +async function generateMessage() { + await generatePackageMap(); + const releases = process.argv.slice(2)[0]; + const data = JSON.parse(releases); + const packages = await Promise.all( + data.map(({ name, version }) => { + const p = packageMap.get(name); + if (!p) { + throw new Error(`Unable to find entrypoint for "${name}"!`); + } + return { + name, + version, + url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString(), + }; + }), + ); + + const emoji = item(emojis); + const descriptor = item(descriptors); + const verb = item(verbs); + + let message = ''; + + if (packages.length === 1) { + const { name, version, url } = packages[0]; + message += `${emoji} \`${name}@${version}\` ${singularlize( + verb, + )}\nRead the [release notes →](<${url}>)\n`; + } else { + message += `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`; + for (const { name, version, url } of packages) { + message += `• \`${name}@${version}\` Read the [release notes →](<${url}>)\n`; + } + } + + if (message.length < 2000) { + return message; + } else { + const { name, version, url } = packages.find((pkg) => pkg.name === 'astro') ?? packages[0]; + message = `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`; + message += `• \`${name}@${version}\` Read the [release notes →](<${url}>)\n`; + + message += `\nAlso ${item(extraVerbs)}:`; + + const remainingPackages = packages.filter((p) => p.name !== name); + for (const { name, version, _url } of remainingPackages) { + message += `\n• \`${name}@${version}\``; + } + + if (message.length < 2000) { + return message; + } else { + message = `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`; + message += `• \`${name}@${version}\` Read the [release notes →](<${url}>)\n`; + + message += `\n\nAlso ${item(extraVerbs)}: ${remainingPackages.length} other packages!`; + return message; + } + } +} + +async function run() { + const content = await generateMessage(); + console.info(content); + setOutput('DISCORD_MESSAGE', content); +} + +run(); diff --git a/.github/scripts/bundle-size.mjs b/.github/scripts/bundle-size.mjs new file mode 100644 index 000000000000..76d6b3f29724 --- /dev/null +++ b/.github/scripts/bundle-size.mjs @@ -0,0 +1,102 @@ +import { existsSync } from 'node:fs'; +import { build } from 'esbuild'; + +const CLIENT_RUNTIME_PATH = 'packages/astro/src/runtime/client/'; + +function formatBytes(bytes, decimals = 2) { + if (bytes === 0) return '0 B'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} + +export default async function checkBundleSize({ github, context }) { + const PR_NUM = context.payload.pull_request.number; + const SHA = context.payload.pull_request.head.sha; + + const { data: files } = await github.rest.pulls.listFiles({ + ...context.repo, + pull_number: PR_NUM, + }); + const clientRuntimeFiles = files.filter((file) => { + return file.filename.startsWith(CLIENT_RUNTIME_PATH) && file.status !== 'removed'; + }); + if (clientRuntimeFiles.length === 0) return; + + const table = [ + '| File | Old Size | New Size | Change |', + '| ---- | -------- | -------- | ------ |', + ]; + const output = await bundle(clientRuntimeFiles); + + for (let [filename, { oldSize, newSize, sourceFile }] of Object.entries(output)) { + filename = ['idle', 'load', 'media', 'only', 'visible'].includes(filename) + ? `client:${filename}` + : filename; + const prefix = newSize - oldSize === 0 ? '' : newSize - oldSize > 0 ? '+ ' : '- '; + const change = `${prefix}${formatBytes(newSize - oldSize)}`; + table.push( + `| [\`${filename}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/${context.payload.pull_request.head.ref}/${sourceFile}) | ${formatBytes(oldSize)} | ${formatBytes(newSize)} | ${change} |`, + ); + } + + const { data: comments } = await github.rest.issues.listComments({ + ...context.repo, + issue_number: PR_NUM, + }); + const comment = comments.find( + (comment) => + comment.user.login === 'github-actions[bot]' && comment.body.includes('Bundle Size Check'), + ); + const method = comment ? 'updateComment' : 'createComment'; + const payload = comment ? { comment_id: comment.id } : { issue_number: PR_NUM }; + await github.rest.issues[method]({ + ...context.repo, + ...payload, + body: `### ⚖️ Bundle Size Check + +Latest commit: ${SHA} + +${table.join('\n')}`, + }); +} + +async function bundle(files) { + const { metafile } = await build({ + entryPoints: [ + ...files.map(({ filename }) => filename), + ...files.map(({ filename }) => `main/${filename}`).filter((f) => existsSync(f)), + ], + bundle: true, + minify: true, + sourcemap: false, + target: ['es2018'], + outdir: 'out', + external: ['astro:*', 'aria-query', 'axobject-query'], + metafile: true, + }); + + return Object.entries(metafile.outputs).reduce((acc, [filename, info]) => { + filename = filename.slice('out/'.length); + if (filename.startsWith('main/')) { + filename = filename.slice('main/'.length).replace(CLIENT_RUNTIME_PATH, '').replace('.js', ''); + const oldSize = info.bytes; + return Object.assign(acc, { + [filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, { oldSize }), + }); + } + filename = filename.replace(CLIENT_RUNTIME_PATH, '').replace('.js', ''); + const newSize = info.bytes; + return Object.assign(acc, { + [filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, { + newSize, + sourceFile: Object.keys(info.inputs).find((src) => src.endsWith('.ts')), + }), + }); + }, {}); +} diff --git a/.github/scripts/utils.mjs b/.github/scripts/utils.mjs new file mode 100644 index 000000000000..768302230150 --- /dev/null +++ b/.github/scripts/utils.mjs @@ -0,0 +1,53 @@ +import * as crypto from 'node:crypto'; +import * as fs from 'node:fs'; +import * as os from 'node:os'; + +/** Based on https://github.com/actions/toolkit/blob/4e3b068ce116d28cb840033c02f912100b4592b0/packages/core/src/file-command.ts */ +export function setOutput(key, value) { + const filePath = process.env['GITHUB_OUTPUT'] || ''; + if (filePath) { + return issueFileCommand('OUTPUT', prepareKeyValueMessage(key, value)); + } + process.stdout.write(os.EOL); +} + +function issueFileCommand(command, message) { + const filePath = process.env[`GITHUB_${command}`]; + if (!filePath) { + throw new Error(`Unable to find environment variable for file command ${command}`); + } + if (!fs.existsSync(filePath)) { + throw new Error(`Missing file at path: ${filePath}`); + } + + fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, { + encoding: 'utf8', + }); +} + +function prepareKeyValueMessage(key, value) { + const delimiter = `gh-delimiter-${crypto.randomUUID()}`; + const convertedValue = toCommandValue(value); + + // These should realistically never happen, but just in case someone finds a + // way to exploit uuid generation let's not allow keys or values that contain + // the delimiter. + if (key.includes(delimiter)) { + throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`); + } + + if (convertedValue.includes(delimiter)) { + throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`); + } + + return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`; +} + +function toCommandValue(input) { + if (input === null || input === undefined) { + return ''; + } else if (typeof input === 'string' || input instanceof String) { + return input; + } + return JSON.stringify(input); +} diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 000000000000..85dbb1c948f0 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,112 @@ +name: Benchmark + +on: + issue_comment: + types: [created] + workflow_dispatch: + +env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + FORCE_COLOR: true + +jobs: + benchmark: + if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench') }} + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + PR-BENCH: ${{ steps.benchmark-pr.outputs.BENCH_RESULT }} + MAIN-BENCH: ${{ steps.benchmark-main.outputs.BENCH_RESULT }} + steps: + - name: Check if user has write access + uses: lannonbr/repo-permission-check-action@2.0.2 + with: + permission: write + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # https://github.com/actions/checkout/issues/331#issuecomment-1438220926 + - uses: actions/checkout@v4 + with: + persist-credentials: false + ref: refs/pull/${{ github.event.issue.number }}/head + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Build Packages + run: pnpm run build + + - name: Get bench command + id: bench-command + env: + # protects from untrusted user input and command injection + COMMENT: ${{ github.event.comment.body }} + run: | + benchcmd=$(echo "$COMMENT" | grep '!bench' | awk -F ' ' '{print $2}') + echo "bench=$benchcmd" >> $GITHUB_OUTPUT + shell: bash + + - name: Run benchmark + id: benchmark-pr + run: | + result=$(pnpm run --silent benchmark ${{ steps.bench-command.outputs.bench }}) + processed=$(node ./benchmark/ci-helper.js "$result") + echo "BENCH_RESULT<> $GITHUB_OUTPUT + echo "### PR Benchmark" >> $GITHUB_OUTPUT + echo "$processed" >> $GITHUB_OUTPUT + echo "BENCHEOF" >> $GITHUB_OUTPUT + shell: bash + + # main benchmark + - uses: actions/checkout@v4 + with: + persist-credentials: false + ref: "main" + + - name: Install + run: | + pnpm install + + - name: Build Packages + run: pnpm run build + + - name: Run benchmark + id: benchmark-main + run: | + result=$(pnpm run --silent benchmark ${{ steps.bench-command.outputs.bench }}) + processed=$(node ./benchmark/ci-helper.js "$result") + echo "BENCH_RESULT<> $GITHUB_OUTPUT + echo "### Main Benchmark" >> $GITHUB_OUTPUT + echo "$processed" >> $GITHUB_OUTPUT + echo "BENCHEOF" >> $GITHUB_OUTPUT + shell: bash + + output-benchmark: + if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench') }} + needs: [benchmark] + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Comment PR + uses: peter-evans/create-or-update-comment@v4 + continue-on-error: true + with: + issue-number: ${{ github.event.issue.number }} + body: | + ${{ needs.benchmark.outputs.PR-BENCH }} + + ${{ needs.benchmark.outputs.MAIN-BENCH }} + edit-mode: replace diff --git a/.github/workflows/check-merge.yml b/.github/workflows/check-merge.yml new file mode 100644 index 000000000000..a4b4ddb99e5a --- /dev/null +++ b/.github/workflows/check-merge.yml @@ -0,0 +1,96 @@ +name: Check mergeability + +on: pull_request_target + +permissions: + pull-requests: write + checks: write + statuses: write + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Check if there is already a block on this PR + id: blocked + uses: actions/github-script@v7 + env: + issue_number: ${{ github.event.number }} + with: + script: | + const { data: reviews } = await github.rest.pulls.listReviews({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: process.env.issue_number, + }); + + for (const review of reviews) { + if (review.user.login === 'github-actions[bot]' && review.state === 'CHANGES_REQUESTED') { + return 'true' + } + } + return 'false' + result-encoding: string + + - uses: actions/checkout@v4 + if: steps.blocked.outputs.result != 'true' + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: Get changed files in the .changeset folder + id: changed-files + uses: tj-actions/changed-files@v45 + if: steps.blocked.outputs.result != 'true' + with: + files: | + .changeset/**/*.md + + - name: Check if any changesets contain minor or major changes + id: check + if: steps.blocked.outputs.result != 'true' + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + echo "Checking for changesets marked as minor or major" + echo "found=false" >> $GITHUB_OUTPUT + + regex="[\"']astro[\"']: (minor|major)" + for file in ${ALL_CHANGED_FILES}; do + if [[ $(cat $file) =~ $regex ]]; then + version="${BASH_REMATCH[1]}" + echo "version=$version" >> $GITHUB_OUTPUT + echo "found=true" >> $GITHUB_OUTPUT + echo "$file has a $version release tag" + fi + done + + - name: Add label + uses: actions/github-script@v7 + if: steps.check.outputs.found == 'true' + env: + issue_number: ${{ github.event.number }} + with: + script: | + github.rest.issues.addLabels({ + issue_number: process.env.issue_number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['semver: ${{ steps.check.outputs.version }}'] + }); + + - name: Change PR Status + uses: actions/github-script@v7 + if: steps.check.outputs.found == 'true' + env: + issue_number: ${{ github.event.number }} + with: + script: | + github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: process.env.issue_number, + event: 'REQUEST_CHANGES', + body: 'This PR is blocked because it contains a `${{ steps.check.outputs.version }}` changeset. A reviewer will merge this at the next release if approved.' + }); diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 000000000000..f8c7ceb49d04 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,52 @@ +name: Examples astro check + +on: + workflow_dispatch: + push: + branches: + - main + merge_group: + pull_request: + paths: + - "examples/**" + - ".github/workflows/check.yml" + - "scripts/smoke/check.js" + - "packages/astro/src/types/public/**" + - "pnpm-lock.yaml" + - "packages/astro/types.d.ts" + +env: + ASTRO_TELEMETRY_DISABLED: true + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + FORCE_COLOR: true + +jobs: + check: + name: astro check + runs-on: ubuntu-latest + timeout-minutes: 7 + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm run build + + - name: Status + run: git status + + - name: astro check + run: pnpm run test:check-examples diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb9d6cbd864c..e7bb0eb7b1a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,92 +1,92 @@ name: CI on: + workflow_dispatch: push: branches: - main + merge_group: pull_request: paths-ignore: - - '.vscode/**' + - ".vscode/**" + - "**/*.md" + - ".github/ISSUE_TEMPLATE/**" -# Automatically cancel in-progress actions on the same branch +# Automatically cancel older in-progress jobs on the same branch concurrency: group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} cancel-in-progress: true - defaults: run: shell: bash +env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + FORCE_COLOR: true + ASTRO_TELEMETRY_DISABLED: true + # 7 GiB by default on GitHub, setting to 6 GiB + # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + NODE_OPTIONS: --max-old-space-size=6144 + jobs: - # Lint can run in parallel with Build. - lint: - name: Lint - runs-on: ubuntu-latest + # Build primes out Turbo build cache and pnpm cache + build: + name: "Build: ${{ matrix.os }}" + runs-on: ${{ matrix.os }} + timeout-minutes: 3 + strategy: + matrix: + OS: [ubuntu-latest, windows-latest] + NODE_VERSION: [22] + fail-fast: true steps: - - name: Check out repository - uses: actions/checkout@v3 + # Disable crlf so all OS can share the same Turbo cache + # https://github.com/actions/checkout/issues/135 + - name: Disable git crlf + run: git config --global core.autocrlf false + + - name: Checkout + uses: actions/checkout@v4 - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 + uses: pnpm/action-setup@v3 - - name: Setup Node - uses: actions/setup-node@v3 + - name: Setup node@${{ matrix.NODE_VERSION }} + uses: actions/setup-node@v4 with: - node-version: 16 - cache: 'pnpm' + node-version: ${{ matrix.NODE_VERSION }} + cache: "pnpm" - name: Install dependencies run: pnpm install - - name: Status - run: git status - - # Lint autofix cannot run on forks, so just skip those! See https://github.com/wearerequired/lint-action/issues/13 - - name: Lint (External) - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.owner.login != github.repository_owner }} - run: pnpm run lint + # Only build in ubuntu as windows can share the build cache. + # Also only build in core repo as forks don't have access to the Turbo cache. + - name: Build Packages + if: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'withastro' }} + run: pnpm run build - # Otherwise, run lint autofixer - - name: Lint - if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.repository_owner }} - uses: wearerequired/lint-action@v1.11.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - eslint: true - eslint_args: --ignore-pattern test --ignore-pattern vendor - eslint_dir: packages/astro - eslint_extensions: ts - prettier: false - auto_fix: true - git_name: github-actions[bot] - git_email: github-actions[bot]@users.noreply.github.com - commit_message: 'chore(lint): ${linter} fix' - github_token: ${{ secrets.GITHUB_TOKEN }} - neutral_check_on_warning: true - - # Checks that the formatter runs successfully on all files - # In the future, we may have this fail PRs on unformatted code - - name: Format Check - run: yarn format --list - - # Build installs all devDependencies and runs our full build pipeline. - # We upload all `dist/` artifacts to GitHub, which can be shared by all dependent jobs. - build: - name: Build Packages + lint: + name: Lint runs-on: ubuntu-latest + timeout-minutes: 5 + needs: build steps: + - name: Disable git crlf + run: git config --global core.autocrlf false + - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 + uses: pnpm/action-setup@v3 - name: Setup Node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 16 - cache: 'pnpm' + node-version: 22 + cache: "pnpm" - name: Install dependencies run: pnpm install @@ -94,162 +94,162 @@ jobs: - name: Build Packages run: pnpm run build - - name: Upload Package Artifacts - uses: actions/upload-artifact@v3 - with: - name: artifacts - path: | - packages/*/dist/** - packages/*/*/dist/** - packages/webapi/mod.js - packages/webapi/mod.js.map - if-no-files-found: error - - # Test depends on Build's output, which allows us to skip any build process! + - name: Lint source code + run: pnpm run lint:ci + + - name: Lint publish code + run: pnpm run publint + test: - name: 'Test: ${{ matrix.os }} (node@${{ matrix.node_version }})' + name: "Test: ${{ matrix.os }} (node@${{ matrix.NODE_VERSION }})" runs-on: ${{ matrix.os }} - env: - ASTRO_TELEMETRY_DISABLED: true + timeout-minutes: 25 + needs: build strategy: matrix: - os: [ubuntu-latest] - node_version: [14, 16] + OS: [ubuntu-latest] + NODE_VERSION: [18, 20, 22] include: + - os: macos-14 + NODE_VERSION: 22 - os: windows-latest - node_version: 16 - - os: macos-latest - node_version: 16 + NODE_VERSION: 22 fail-fast: false - needs: - - build + env: + NODE_VERSION: ${{ matrix.NODE_VERSION }} steps: + - name: Disable git crlf + run: git config --global core.autocrlf false + - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 + uses: pnpm/action-setup@v3 - - name: Setup node@${{ matrix.node_version }} - uses: actions/setup-node@v3 + - name: Setup node@${{ matrix.NODE_VERSION }} + uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node_version }} - cache: 'pnpm' - - - name: Use Deno - uses: denoland/setup-deno@v1 - with: - deno-version: v1.19.3 - - - name: Download Build Artifacts - uses: actions/download-artifact@v3 - - - name: Extract Artifacts - run: ./.github/extract-artifacts.sh + node-version: ${{ matrix.NODE_VERSION }} + cache: "pnpm" - name: Install dependencies run: pnpm install + - name: Build Packages + run: pnpm run build + - name: Test run: pnpm run test - smoke: - name: 'Test (Smoke) ${{ matrix.os }}' + e2e: + name: "Test (E2E): ${{ matrix.os }} (node@${{ matrix.NODE_VERSION }})" runs-on: ${{ matrix.os }} + timeout-minutes: 25 + needs: build strategy: matrix: - os: [windows-latest, ubuntu-latest] - needs: - - build + OS: [ubuntu-latest, windows-latest] + NODE_VERSION: [22] + fail-fast: false + env: + NODE_VERSION: ${{ matrix.NODE_VERSION }} steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: 'recursive' + - name: Disable git crlf + run: git config --global core.autocrlf false - - name: Update submodules - run: git submodule update --remote + - name: Checkout + uses: actions/checkout@v4 - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 + uses: pnpm/action-setup@v3 - - name: Setup Node - uses: actions/setup-node@v3 + - name: Setup node@${{ matrix.NODE_VERSION }} + uses: actions/setup-node@v4 with: - node-version: 14 - cache: 'pnpm' - - - name: Download Build Artifacts - uses: actions/download-artifact@v3 - - - name: Extract Artifacts - run: ./.github/extract-artifacts.sh + node-version: ${{ matrix.NODE_VERSION }} + cache: "pnpm" - name: Install dependencies - run: pnpm install --no-frozen-lockfile - - - name: Test - run: pnpm run test:smoke + run: pnpm install - - name: Memory Leak Test - run: | - node ./scripts/memory/mk.js - node --expose-gc ./scripts/memory/index.js --ci + - name: Build Packages + run: pnpm run build + - name: Test + run: pnpm run test:e2e - # Changelog can only run _after_ build. - # We download all `dist/` artifacts from GitHub to skip the build process. - changelog: - name: Changelog PR or Release - if: ${{ (github.ref_name == 'main' || github.head_ref == 'next') && github.repository_owner == 'withastro' }} - needs: [build] - runs-on: ubuntu-latest + smoke: + name: "Test (Smoke): ${{ matrix.os }} (node@${{ matrix.NODE_VERSION }})" + runs-on: ${{ matrix.os }} + timeout-minutes: 25 + needs: build + strategy: + matrix: + OS: [ubuntu-latest, windows-latest] + NODE_VERSION: [22] + env: + NODE_VERSION: ${{ matrix.NODE_VERSION }} steps: - - uses: actions/checkout@v3 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Disable git crlf + run: git config --global core.autocrlf false + + - name: Checkout + uses: actions/checkout@v4 - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 + uses: pnpm/action-setup@v3 - - name: Setup Node - uses: actions/setup-node@v3 + - name: Setup node@${{ matrix.NODE_VERSION }} + uses: actions/setup-node@v4 with: - node-version: 16 - cache: 'pnpm' - - - name: Download Build Artifacts - uses: actions/download-artifact@v3 + node-version: ${{ matrix.NODE_VERSION }} + cache: "pnpm" - - name: Extract Artifacts - run: ./.github/extract-artifacts.sh + - name: Checkout docs + uses: actions/checkout@v4 + with: + repository: withastro/docs + path: smoke/docs + # For a commit event on the `next` branch (`ref_name`), use the `5.0.0-beta` branch. + # For a pull_request event merging into the `next` branch (`base_ref`), use the `5.0.0-beta` branch. + # NOTE: For a pull_request event, the `ref_name` is something like `/merge` than the branch name. + # NOTE: Perhaps docs repo should use a consistent `next` branch in the future. + ref: ${{ (github.ref_name == 'next' || github.base_ref == 'next') && '5.0.0-beta' || 'main' }} - name: Install dependencies - run: pnpm install + run: pnpm install --no-frozen-lockfile - - name: Create Release Pull Request or Publish - id: changesets - uses: changesets/action@v1 + # Reset lockfile changes so that Turbo can reuse the old build cache + - name: Reset lockfile changes + run: git reset --hard + + - name: Build Packages + run: pnpm run build + + - name: Remove docs translations except for English and Korean + run: find smoke/docs/src/content/docs ! -name 'en' ! -name 'ko' -type d -mindepth 1 -maxdepth 1 -exec rm -rf {} + + + - name: Check if docs changed + id: changes + uses: dorny/paths-filter@v3 with: - # Note: pnpm install after versioning is necessary to refresh lockfile - version: pnpm run version - publish: pnpm exec changeset publish - commit: '[ci] release' - title: '[ci] release' + filters: | + docs: + - 'packages/integrations/*/README.md' + - "packages/astro/src/types/public/**" + - 'packages/astro/src/core/errors/errors-data.ts' + + - name: Build autogenerated docs pages from current astro branch + if: ${{ steps.changes.outputs.docs == 'true' }} + run: cd smoke/docs && pnpm docgen && pnpm docgen:errors env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + SOURCE_REPO: ${{ github.event.pull_request.head.repo.full_name || github.event.repository.full_name }} + SOURCE_BRANCH: ${{ github.head_ref || github.ref_name }} - - 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'} - - - name: Discord Notification - if: steps.changesets.outputs.published == 'true' - id: discord-notification + - name: Test + run: pnpm run test:smoke env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - uses: Ilshidur/action-discord@0.3.2 - with: - args: ${{ steps.notification.outputs.message }} + SKIP_OG: true + PUBLIC_TWO_LANG: true diff --git a/.github/workflows/cleanup-cache.yml b/.github/workflows/cleanup-cache.yml new file mode 100644 index 000000000000..9d8205cc5390 --- /dev/null +++ b/.github/workflows/cleanup-cache.yml @@ -0,0 +1,44 @@ +name: Cleanup cache + +on: + schedule: + - cron: "0 11 * * *" + pull_request: + types: + - closed + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Cleanup caches older than 5 days + if: github.event_name == 'schedule' + uses: MyAlbum/purge-cache@v2 + with: + max-age: 432000 + + # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries + - name: Cleanup on PR close + if: github.event_name == 'pull_request' + run: | + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge" + + echo "Fetching list of cache key" + cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 ) + + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + for cacheKey in $cacheKeysForPR + do + gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm + done + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/congrats.yml b/.github/workflows/congrats.yml new file mode 100644 index 000000000000..4052bdac8776 --- /dev/null +++ b/.github/workflows/congrats.yml @@ -0,0 +1,16 @@ +name: Congratsbot + +on: + push: + branches: + - main + +jobs: + congrats: + name: congratsbot + if: ${{ github.repository_owner == 'withastro' && github.event.head_commit.message != '[ci] format' }} + uses: withastro/automation/.github/workflows/congratsbot.yml@main + with: + EMOJIS: '🎉,🎊,🧑‍🚀,🥳,🙌,🚀,👏,<:houston_golden:1068575433647456447>,<:astrocoin:894990669515489301>,<:astro_pride:1130501345326157854>' + secrets: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_CONGRATS }} diff --git a/.github/workflows/continuous_benchmark.yml b/.github/workflows/continuous_benchmark.yml new file mode 100644 index 000000000000..1b382f8dc6fc --- /dev/null +++ b/.github/workflows/continuous_benchmark.yml @@ -0,0 +1,56 @@ +name: Continuous benchmark + +on: + workflow_dispatch: + pull_request: + branches: + - main + paths: + - 'packages/astro/src/**/*.ts' + - 'benchmark/**' + push: + branches: + - main + paths: + - 'packages/astro/src/**/*.ts' + - 'benchmark/**' + +env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + FORCE_COLOR: true + CODSPEED: true + +jobs: + codspeed: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm run build + + - name: Run the benchmarks + uses: CodSpeedHQ/action@513a19673a831f139e8717bf45ead67e47f00044 # v3.2.0 + timeout-minutes: 30 + with: + working-directory: ./benchmark + run: pnpm bench + token: ${{ secrets.CODSPEED_TOKEN }} + diff --git a/.github/workflows/dispatch-event.yml b/.github/workflows/dispatch-event.yml new file mode 100644 index 000000000000..0bca088e3d37 --- /dev/null +++ b/.github/workflows/dispatch-event.yml @@ -0,0 +1,62 @@ +name: Dispatch event + +on: + workflow_dispatch: + push: + branches: + - main + tags: + - '!**' + +permissions: + contents: read + actions: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + ASTRO_ADAPTERS_REPO: withastro/adapters + ASTRO_STARLIGHT_REPO: withastro/starlight + ASTRO_PUSH_MAIN_EVENT: astro-push-main-event + +jobs: + repository-dispatch: + name: Repository dispatch + if: github.repository_owner == 'withastro' + runs-on: ubuntu-latest + steps: + - name: Dispatch event on push - adapters + if: ${{ github.event_name == 'push' }} + uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3 + with: + token: ${{ secrets.ASTRO_REPOSITORY_DISPATCH }} + repository: ${{ env.ASTRO_ADAPTERS_REPO }} + event-type: ${{ env.ASTRO_PUSH_MAIN_EVENT }} + client-payload: '{"event": ${{ toJson(github.event) }}}' + - name: Dispatch event on push - starlight + if: ${{ github.event_name == 'push' }} + uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3 + with: + token: ${{ secrets.ASTRO_REPOSITORY_DISPATCH }} + repository: ${{ env.ASTRO_STARLIGHT_REPO }} + event-type: ${{ env.ASTRO_PUSH_MAIN_EVENT }} + client-payload: '{"event": ${{ toJson(github.event) }}}' + # For testing only, the payload is mocked + - name: Dispatch event on workflow dispatch - adapters + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3 + with: + token: ${{ secrets.ASTRO_REPOSITORY_DISPATCH }} + repository: ${{ env.ASTRO_ADAPTERS_REPO }} + event-type: ${{ env.ASTRO_PUSH_MAIN_EVENT }} + client-payload: '{"event": {"head_commit": {"id": "${{ env.GITHUB_SHA }}"}}}' + - name: Dispatch event on workflow dispatch - starlight + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3 + with: + token: ${{ secrets.ASTRO_REPOSITORY_DISPATCH }} + repository: ${{ env.ASTRO_STARLIGHT_REPO }} + event-type: ${{ env.ASTRO_PUSH_MAIN_EVENT }} + client-payload: '{"event": {"head_commit": {"id": "${{ env.GITHUB_SHA }}"}}}' diff --git a/.github/workflows/examples-deploy.yml b/.github/workflows/examples-deploy.yml new file mode 100644 index 000000000000..91ef304f01e6 --- /dev/null +++ b/.github/workflows/examples-deploy.yml @@ -0,0 +1,22 @@ +# This workflow runs when changes to examples are pushed to main. +# It calls a build hook on Netlify that will redeploy preview.astro.new with the latest changes. + +name: Redeploy preview.astro.new + +on: + push: + branches: + - main + paths: + - 'examples/**' + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Send a POST request to Netlify to rebuild preview.astro.new + run: 'curl -X POST -d {} ${{ env.BUILD_HOOK }}' + env: + BUILD_HOOK: ${{ secrets.NETLIFY_PREVIEWS_BUILD_HOOK }} diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 4db389d24e34..9faaa1886608 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,31 +1,15 @@ -name: 'Format Code' +name: Format on: + workflow_dispatch: push: branches: - main jobs: - format: - runs-on: ubuntu-latest - steps: - - name: Check out code using Git - uses: actions/checkout@v3 - with: - ref: ${{ github.head_ref }} - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - name: Install dependencies - run: pnpm install - - name: Format code - run: pnpm run format - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: '[ci] format' - branch: ${{ github.head_ref }} + prettier: + if: github.repository_owner == 'withastro' + uses: withastro/automation/.github/workflows/format.yml@main + with: + command: "format" + secrets: inherit diff --git a/.github/workflows/issue-labeled.yml b/.github/workflows/issue-labeled.yml new file mode 100644 index 000000000000..b0a0e80c7767 --- /dev/null +++ b/.github/workflows/issue-labeled.yml @@ -0,0 +1,30 @@ +name: Issue Labeled + +on: + issues: + types: [labeled] + +jobs: + reply-labeled: + if: github.repository == 'withastro/astro' + runs-on: ubuntu-latest + steps: + - name: remove triage + if: contains(github.event.label.description, '(priority)') && contains(github.event.issue.labels.*.name, 'needs triage') + uses: actions-cool/issues-helper@v3 + with: + actions: "remove-labels" + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.issue.number }} + labels: "needs triage" + + - name: needs repro + if: github.event.label.name == 'needs repro' + uses: actions-cool/issues-helper@v3 + with: + actions: "create-comment, remove-labels" + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.issue.number }} + body: | + Hello @${{ github.event.issue.user.login }}. Please provide a [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) using a GitHub repository or [StackBlitz](https://astro.new/repro). Issues marked with `needs repro` will be closed if they have no activity within 3 days. + labels: "needs triage" diff --git a/.github/workflows/issue-needs-repro.yml b/.github/workflows/issue-needs-repro.yml new file mode 100644 index 000000000000..a859d85ad7ed --- /dev/null +++ b/.github/workflows/issue-needs-repro.yml @@ -0,0 +1,18 @@ +name: Close Issues (needs repro) + +on: + schedule: + - cron: "0 0 * * *" + +jobs: + close-issues: + if: github.repository == 'withastro/astro' + runs-on: ubuntu-latest + steps: + - name: needs repro + uses: actions-cool/issues-helper@v3 + with: + actions: "close-issues" + token: ${{ secrets.GITHUB_TOKEN }} + labels: "needs repro" + inactive-day: 3 diff --git a/.github/workflows/issue-opened.yml b/.github/workflows/issue-opened.yml new file mode 100644 index 000000000000..7171a1b9b7bc --- /dev/null +++ b/.github/workflows/issue-opened.yml @@ -0,0 +1,23 @@ +name: Label issues +on: + issues: + types: + - reopened + - opened + +jobs: + label_issues: + runs-on: ubuntu-latest + if: github.repository == 'withastro/astro' + permissions: + issues: write + steps: + - uses: actions/github-script@v7 + with: + script: | + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ["needs triage"] + }) diff --git a/.github/workflows/issue.yml b/.github/workflows/issue.yml deleted file mode 100644 index cc370ea07ebf..000000000000 --- a/.github/workflows/issue.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Auto Assign Issues to Project - -on: - issues: - types: [opened] - -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -jobs: - auto_assign_issues: - runs-on: ubuntu-latest - name: Auto-assign new issues to projects - steps: - - name: Assign Bugs to the Bug Tracker - uses: srggrs/assign-one-project-github-action@1.3.1 - if: github.event.action == 'opened' && startsWith(github.event.issue.title, '🐛 BUG:') - with: - project: 'https://github.com/withastro/astro/projects/2' - column_name: 'Needs Triage' - - - name: Assign RFCs to the RFC Tracker - uses: srggrs/assign-one-project-github-action@1.3.1 - if: github.event.action == 'opened' && startsWith(github.event.issue.title, '💡 RFC:') - with: - project: 'https://github.com/withastro/astro/projects/3' - column_name: 'Discussing' - - - name: Assign RFCs to the Docs Tracker - uses: srggrs/assign-one-project-github-action@1.3.1 - if: github.event.action == 'opened' && startsWith(github.event.issue.title, '📘 DOC:') - with: - project: 'https://github.com/withastro/astro/projects/5' - column_name: 'TODO' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 02344ecdbb93..000000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: Main Checks - -on: - push: - branches: - - main - -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -# Automatically cancel in-progress actions on the same branch -concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} - cancel-in-progress: true - -jobs: - congrats: - name: congratsbot - if: ${{ github.repository_owner == 'withastro' }} - runs-on: ubuntu-latest - steps: - - id: setup - env: - MESSAGE: ${{ github.event.commits[0].message }} - run: | - TRIMMED=$(echo "$MESSAGE" | sed '1!d;q') - echo "::set-output name=COMMIT_MSG::${TRIMMED}" - - name: Send a Discord notification when a PR is merged - env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_CONGRATS }} - # DISCORD_AVATAR: ${{ github.event.pull_request.user.avatar_url }} - uses: Ilshidur/action-discord@0.3.2 - with: - args: "**Merged!** ${{ github.event.commits[0].author.name }}: [`${{ steps.setup.outputs.COMMIT_MSG }}`]()" - - check_for_update: - name: Check for Updates - runs-on: ubuntu-latest - outputs: - run_job: ${{ steps.check_files.outputs.run_job }} - steps: - - uses: actions/checkout@v3 - - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install - - - name: Check Modified - run: pnpm exec changeset status --output ./status.json - - - name: Check Output - id: check_files - run: | - output=`echo $(cat status.json)` - if [[ $output = '{ "changesets": [], "releases": [] }' ]] - then - echo 'No changeset found' - echo "::set-output name=run_job::true" - else - echo 'changes found, push to latest skipped' - echo "::set-output name=run_job::false" - fi - - update: - name: Update the latest branch - needs: check_for_update - if: needs.check_for_update.outputs.run_job == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Push - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: latest diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml deleted file mode 100644 index 251f5517e58b..000000000000 --- a/.github/workflows/nightly.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: 'Nightly' - -on: - schedule: - # * is a special character in YAML so you have to quote this string - - cron: '0 12 * * *' - workflow_dispatch: - -jobs: - stat: - if: github.repository_owner == 'withastro' - runs-on: ubuntu-latest - steps: - - name: Check out code using Git - uses: actions/checkout@v3 - - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install - - - name: Collect stats - run: node scripts/stats/index.js - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: '[ci] collect stats' - branch: ${{ github.head_ref }} - - lockfile: - if: github.repository_owner == 'withastro' - runs-on: ubuntu-latest - steps: - - - name: Check out code using Git - uses: actions/checkout@v3 - - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Upgrade recursive - run: pnpm upgrade --recursive - - - name: Create Pull Request - id: createpr - uses: peter-evans/create-pull-request@v3 - with: - branch: ci/lockfile - token: ${{ secrets.NIGHTLY_PERSONAL_GITHUB_TOKEN }} - commit-message: '[ci] update lockfile' - title: '[ci] update lockfile' - body: > - This PR is auto-generated by a nightly GitHub action. - It should automatically be merged if tests pass. diff --git a/.github/workflows/preview-comment.yml b/.github/workflows/preview-comment.yml new file mode 100644 index 000000000000..9fb0f48c3983 --- /dev/null +++ b/.github/workflows/preview-comment.yml @@ -0,0 +1,26 @@ +name: Add continuous release label + +on: + issue_comment: + types: [created] + +permissions: + pull-requests: write + +jobs: + label: + if: ${{ github.repository_owner == 'withastro' && startsWith(github.event.comment.body, '!preview') }} + runs-on: ubuntu-latest + + steps: + - name: Check if user has write access + uses: lannonbr/repo-permission-check-action@2.0.2 + with: + permission: write + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - run: | + gh issue edit ${{ github.event.issue.number }} --add-label "pr: preview" --repo ${{ github.repository }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/preview-release.yml b/.github/workflows/preview-release.yml new file mode 100644 index 000000000000..bba55c028eaa --- /dev/null +++ b/.github/workflows/preview-release.yml @@ -0,0 +1,60 @@ +name: Preview release + +on: + pull_request: + branches: [main] + types: [opened, synchronize, labeled, ready_for_review] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.number }} + cancel-in-progress: true + +permissions: + contents: read + actions: write + +env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + FORCE_COLOR: true + ASTRO_TELEMETRY_DISABLED: true + # 7 GiB by default on GitHub, setting to 6 GiB + # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + NODE_OPTIONS: --max-old-space-size=6144 + +jobs: + preview: + if: | + ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && contains(github.event.pull_request.labels.*.name, 'pr: preview') }} + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + issues: write + pull-requests: write + name: Publish preview release + timeout-minutes: 5 + steps: + - name: Disable git crlf + run: git config --global core.autocrlf false + + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Build Packages + run: pnpm run build + + - name: Publish packages + run: pnpx pkg-pr-new publish --pnpm './packages/*' './packages/integrations/*' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000000..738028a744f9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,75 @@ +name: Release + +on: + push: + branches: + - main + - "1-legacy" + - "2-legacy" + - "3-legacy" + - "4-legacy" + +defaults: + run: + shell: bash + +env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + FORCE_COLOR: true + +jobs: + changelog: + name: Changelog PR or Release + if: ${{ github.repository_owner == 'withastro' }} + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + steps: + - uses: actions/checkout@v4 + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Build Packages + run: pnpm run build + + - name: Create Release Pull Request or Publish + id: changesets + uses: changesets/action@v1 + with: + # Note: pnpm install after versioning is necessary to refresh lockfile + version: pnpm run version + publish: pnpm exec changeset publish + commit: "[ci] release" + title: "[ci] release" + env: + # Needs access to push to main + GITHUB_TOKEN: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} + # Needs access to publish to npm + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Generate Announcement + id: message + if: steps.changesets.outputs.published == 'true' + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + run: node .github/scripts/announce.mjs '${{ steps.changesets.outputs.publishedPackages }}' + + - name: Send message on Discord + if: steps.changesets.outputs.published == 'true' + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + uses: Ilshidur/action-discord@0.3.2 + with: + args: "${{ steps.message.outputs.DISCORD_MESSAGE }}" diff --git a/.github/workflows/scripts.yml b/.github/workflows/scripts.yml new file mode 100644 index 000000000000..542f943ac34a --- /dev/null +++ b/.github/workflows/scripts.yml @@ -0,0 +1,52 @@ +name: Scripts + +on: + workflow_dispatch: + pull_request: + branches: + - "main" + paths: + - "packages/astro/src/runtime/client/**/*" + - "!packages/astro/src/runtime/client/dev-toolbar/**/*" + +# Automatically cancel in-progress actions on the same branch +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash + +jobs: + bundle: + name: Bundle Size + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Checkout Main into tmp + uses: actions/checkout@v4 + with: + ref: main + path: main + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Check Bundle Size + uses: actions/github-script@v7 + with: + script: | + const { default: script } = await import('${{ github.workspace }}/.github/scripts/bundle-size.mjs') + await script({ github, context }) diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml new file mode 100644 index 000000000000..c12834264cc4 --- /dev/null +++ b/.github/workflows/snapshot-release.yml @@ -0,0 +1,169 @@ +name: Create a Snapshot Release + +on: + workflow_dispatch: + issue_comment: + types: [created] + +defaults: + run: + shell: bash + +env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + FORCE_COLOR: 1 + +jobs: + snapshot-release: + name: Create a snapshot release of a pull request + if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && (contains(github.event.comment.body, '!preview') || contains(github.event.comment.body, '/preview') || contains(github.event.comment.body, '!snapshot') || contains(github.event.comment.body, '/snapshot')) }} + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + issues: write + pull-requests: write + steps: + - name: Check if user has write access + uses: lannonbr/repo-permission-check-action@2.0.2 + with: + permission: write + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract the snapshot name from comment body + id: getSnapshotName + uses: actions/github-script@v7 + with: + script: | + const { body } = context.payload.comment; + const PREVIEW_RE = /^[!\/](?:preview|snapshot)\s+(\S*)\s*$/gim; + const [_, name] = PREVIEW_RE.exec(body) ?? []; + if (name) return name; + + const error = 'Invalid command. Expected: "/preview "' + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: error, + }) + core.setFailed(error) + result-encoding: string + + - name: resolve pr refs + id: refs + uses: eficode/resolve-pr-refs@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@v4 + with: + ref: ${{ steps.refs.outputs.head_ref }} + fetch-depth: 0 + + - name: Extract base branch from .changeset/config.json + id: getBaseBranch + run: | + baseBranch=$(jq -r '.baseBranch' .changeset/config.json) + echo "baseBranch=${baseBranch}" >> $GITHUB_OUTPUT + + - run: git fetch origin ${{ steps.getBaseBranch.outputs.baseBranch }}:${{ steps.getBaseBranch.outputs.baseBranch }} + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: "https://registry.npmjs.org" + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Build Packages + run: pnpm run build + + - name: Bump Package Versions + id: changesets + run: | + pnpm exec changeset status --output status.output.json 2>&1 + # Snapshots don't work in pre mode. See https://github.com/changesets/changesets/issues/1195 + pnpm exec changeset pre exit || true + pnpm exec changeset version --snapshot ${{ steps.getSnapshotName.outputs.result }} + + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "status<<$EOF" >> $GITHUB_OUTPUT + echo "$(cat status.output.json)" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + env: + # Needs access to run the script + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Disable color + FORCE_COLOR: 0 + NO_COLOR: 1 + + - name: Publish Release + id: publish + run: | + GITHUB_ACTIONS=0 pnpm run build > build.output.txt 2>&1 + pnpm exec changeset publish --tag experimental--${{ steps.getSnapshotName.outputs.result }} > publish.output.txt 2>&1 + + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + + echo "build<<$EOF" >> $GITHUB_OUTPUT + echo "$(cat build.output.txt)" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + cat build.output.txt + + echo "publish<<$EOF" >> $GITHUB_OUTPUT + echo "$(cat publish.output.txt)" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + cat publish.output.txt + env: + # Needs access to publish to npm + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + # Disable color + FORCE_COLOR: 0 + NO_COLOR: 1 + + - name: Pull Request Notification + uses: actions/github-script@v7 + env: + TAG: ${{ steps.getSnapshotName.outputs.result }} + STATUS_DATA: ${{ steps.changesets.outputs.status }} + BUILD_LOG: ${{ steps.publish.outputs.build }} + PUBLISH_LOG: ${{ steps.publish.outputs.publish }} + with: + script: | + let changeset = { releases: [] }; + try { + changeset = JSON.parse(process.env.STATUS_DATA); + } catch (e) {} + let message = 'Snapshots have been released for the following packages:' + for (const release of changeset.releases) { + if (release.type === 'none') continue; + message += `\n- \`${release.name}@experimental--${process.env.TAG}\``; + } + + function details(title, body) { + message += '\n'; + message += `
${title}` + message += '\n\n```\n'; + message += body; + message += '\n```\n\n
'; + } + + details('Publish Log', process.env.PUBLISH_LOG); + details('Build Log', process.env.BUILD_LOG); + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: message, + }) diff --git a/.github/workflows/sync-examples.yml b/.github/workflows/sync-examples.yml new file mode 100644 index 000000000000..8603a951e8a9 --- /dev/null +++ b/.github/workflows/sync-examples.yml @@ -0,0 +1,88 @@ +name: Sync examples + +on: + workflow_dispatch: + inputs: + skip-unchanged-check: + type: boolean + default: false + dry-run: + type: boolean + default: false + push: + branches: + - main + +# Automatically cancel in-progress actions on the same branch +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} + cancel-in-progress: true + +permissions: + # Allow auto-branch-sync-action to git push + contents: write + +jobs: + sync: + name: Sync branches + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 2 # fetch 2 to compare with previous commit for changes + + - name: Detect changesets + uses: bluwy/detect-changesets-action@v1 + id: detect + + # We only do sync if there are no changesets, so we don't accidentally allow users + # to clone examples that may rely on unreleased code + + - name: Sync from main branch to latest and examples/* branches + if: steps.detect.outputs.has-changesets == 'false' && github.ref == 'refs/heads/main' + uses: bluwy/auto-branch-sync-action@v1 + with: + map: | + / -> latest + /examples/* -> examples/* + skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }} + dry-run: ${{ inputs.dry-run == true }} + + - name: Check .changeset/pre.json for matching tag + if: steps.detect.outputs.has-changesets == 'false' && github.ref == 'refs/heads/next' + id: check-pre-mode + run: | + if [ -f ./.changeset/pre.json ]; then + if grep -q '"tag": "alpha"' ./.changeset/pre.json; then + echo "alpha=true" >> $GITHUB_OUTPUT + elif grep -q '"tag": "beta"' ./.changeset/pre.json; then + echo "beta=true" >> $GITHUB_OUTPUT + elif grep -q '"tag": "rc"' ./.changeset/pre.json; then + echo "rc=true" >> $GITHUB_OUTPUT + fi + fi + + - name: Sync from next branch to alpha branch + if: steps.detect.outputs.has-changesets == 'false' && steps.check-pre-mode.outputs.alpha == 'true' + uses: bluwy/auto-branch-sync-action@v1 + with: + map: / -> alpha + skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }} + dry-run: ${{ inputs.dry-run == true }} + + - name: Sync from next branch to beta branch + if: steps.detect.outputs.has-changesets == 'false' && steps.check-pre-mode.outputs.beta == 'true' + uses: bluwy/auto-branch-sync-action@v1 + with: + map: / -> beta + skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }} + dry-run: ${{ inputs.dry-run == true }} + + - name: Sync from next branch to rc branch + if: steps.detect.outputs.has-changesets == 'false' && steps.check-pre-mode.outputs.rc == 'true' + uses: bluwy/auto-branch-sync-action@v1 + with: + map: / -> rc + skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }} + dry-run: ${{ inputs.dry-run == true }} diff --git a/.github/workflows/test-hosts.yml b/.github/workflows/test-hosts.yml new file mode 100644 index 000000000000..546d82e07a4b --- /dev/null +++ b/.github/workflows/test-hosts.yml @@ -0,0 +1,48 @@ +name: Hosted tests + +on: + schedule: + - cron: '0 0 * * 0' + +env: + ASTRO_TELEMETRY_DISABLED: true + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_TEST_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_TEST_PROJECT_ID }} + VERCEL_TOKEN: ${{ secrets.VERCEL_TEST_TOKEN }} + FORCE_COLOR: true + +jobs: + test: + name: Run tests + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Build Astro + run: pnpm turbo build --filter astro --filter @astrojs/vercel + + - name: Build test project + working-directory: ./packages/integrations/vercel/test/hosted/hosted-astro-project + run: pnpm run build + + - name: Deploy to Vercel + working-directory: ./packages/integrations/vercel/test/hosted/hosted-astro-project + run: pnpm dlx vercel --prod --prebuilt + + - name: Test + run: pnpm run test:e2e:hosts diff --git a/.gitignore b/.gitignore index 30c24d1e9698..d6a28ec1b19a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,42 @@ node_modules/ dist/ -.output/ *.tsbuildinfo .DS_Store .vercel +.netlify _site/ scripts/smoke/*-main/ scripts/memory/project/src/pages/ +benchmark/projects/ +benchmark/results/ +test-results/ *.log package-lock.json .turbo/ - -# ignore top-level vscode settings -/.vscode/settings.json +.eslintcache +.pnpm-store # do not commit .env files or any files that end with `.env` *.env -!packages/astro/vendor/vite/dist +packages/astro/src/**/*.prebuilt.ts +packages/astro/src/**/*.prebuilt-dev.ts +packages/astro/test/units/_temp-fixtures/* +!packages/astro/test/units/_temp-fixtures/package.json packages/integrations/**/.netlify/ + +# exclude IntelliJ/WebStorm stuff +.idea + +# ignore content collection generated files +packages/**/test/**/fixtures/**/.astro/ +packages/**/test/**/fixtures/**/env.d.ts +packages/**/e2e/**/fixtures/**/.astro/ +packages/**/e2e/**/fixtures/**/env.d.ts +examples/**/.astro/ +examples/**/env.d.ts + +# make it easy for people to add project-specific Astro settings that they don't +# want to share with others (see +# https://github.com/withastro/astro/pull/11759#discussion_r1721444711) +*.code-workspace diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 28a12af2dd2f..000000000000 --- a/.gitmodules +++ /dev/null @@ -1,8 +0,0 @@ -[submodule "smoke/docs"] - path = smoke/docs - url = git@github.com:withastro/docs.git - branch = main -[submodule "smoke/astro.build"] - path = smoke/astro.build - url = git@github.com:withastro/astro.build.git - branch = main diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile deleted file mode 100644 index e6dbb0118361..000000000000 --- a/.gitpod.Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM gitpod/workspace-node - -# Install latest pnpm -RUN pnpm i -g pnpm - -# Install deno in gitpod -RUN curl -fsSL https://deno.land/x/install/install.sh | sh -RUN /home/gitpod/.deno/bin/deno completions bash > /home/gitpod/.bashrc.d/90-deno && echo 'export DENO_INSTALL="/home/gitpod/.deno"' >> /home/gitpod/.bashrc.d/90-deno && echo 'export PATH="$DENO_INSTALL/bin:$PATH"' >> /home/gitpod/.bashrc.d/90-deno diff --git a/.gitpod.yml b/.gitpod.yml index 97ce81997b5e..367ddf4feee3 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,9 +1,11 @@ --- -image: - file: .gitpod.Dockerfile # Commands to start on workspace startup tasks: - - init: | + - before: | + # Get latest pnpm version, in case the custom docker image was not updated + # Until this issue gets resolved - https://github.com/gitpod-io/gitpod/issues/12551 + curl -fsSL https://get.pnpm.io/install.sh | SHELL=`which bash` bash - + init: | pnpm install pnpm run build command: | @@ -14,7 +16,7 @@ vscode: - esbenp.prettier-vscode - dbaeumer.vscode-eslint ports: - - port: 3000 + - port: 4321 onOpen: open-preview github: prebuilds: diff --git a/.gitpod/gitpod-setup.sh b/.gitpod/gitpod-setup.sh index 883b3b1c97f7..b1ba15d2d84c 100755 --- a/.gitpod/gitpod-setup.sh +++ b/.gitpod/gitpod-setup.sh @@ -3,6 +3,9 @@ # Convert context URL to an array mapfile -t CONTEXT_URL_ITEMS < <(echo "$GITPOD_WORKSPACE_CONTEXT_URL" | tr '/' '\n') +# Install latest pnpm +curl -fsSL https://get.pnpm.io/install.sh | SHELL=`which bash` bash - + # Check if Gitpod started from a specific example directory in the repository if [ "${CONTEXT_URL_ITEMS[7]}" = "examples" ]; then EXAMPLE_PROJECT=${CONTEXT_URL_ITEMS[8]} @@ -15,9 +18,9 @@ else fi # Wait for VSCode to be ready (port 23000) -gp await-port 23000 > /dev/null 2>&1 +gp ports await 23000 > /dev/null 2>&1 -echo "Loading example project:" $EXAMPLE_PROJECT +echo "Loading example project: $EXAMPLE_PROJECT" # Go to the requested example project cd "$GITPOD_REPO_ROOT"/examples/"$EXAMPLE_PROJECT" || exit diff --git a/.npmrc b/.npmrc index 492d2035781f..4912828b6bdd 100644 --- a/.npmrc +++ b/.npmrc @@ -2,20 +2,13 @@ prefer-workspace-packages=true link-workspace-packages=true save-workspace-protocol=false # This prevents the examples to have the `workspace:` prefix +auto-install-peers=false -shamefully-hoist=true -# TODO: We would like to move to individual opt-in hoisting, but Astro was not originally -# written with this in mind. In the future, it would be good to hoist individual packages only. -# public-hoist-pattern[]=autoprefixer -# public-hoist-pattern[]=astro -# public-hoist-pattern[]=remark-* -# public-hoist-pattern[]=rehype-* -# public-hoist-pattern[]=react -# public-hoist-pattern[]=react-dom -# public-hoist-pattern[]=preact -# public-hoist-pattern[]=preact-render-to-string -# public-hoist-pattern[]=vue -# public-hoist-pattern[]=svelte -# public-hoist-pattern[]=solid-js -# public-hoist-pattern[]=lit -# public-hoist-pattern[]=@webcomponents/template-shadowroot +# Vite's esbuild optimizer has trouble optimizing `@astrojs/lit/client-shim.js` +# which imports this dependency. +public-hoist-pattern[]=@webcomponents/template-shadowroot +# There's a lit dependency duplication somewhere causing multiple Lit versions error. +public-hoist-pattern[]=*lit* +# `astro sync` could try to import `@astrojs/db` but could fail due to linked dependencies in the monorepo. +# We hoist it here so that it can easily resolve `@astrojs/db` without hardcoded handling. +public-hoist-pattern[]=@astrojs/db diff --git a/.nvmrc b/.nvmrc index 31102b28de6a..4a1f488b6c3b 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14.18.1 +18.17.1 diff --git a/.prettierignore b/.prettierignore index 7c89fbaf5aef..64e94860fa24 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,23 +1,30 @@ -# To be removed with ".astro" parsing is ready -# Also, be sure to remove "pluginSearchDirs" from config -**/*.astro +# Benchmark artifacts +benchmark/projects/ +benchmark/results/ # Deep Directories **/dist -**/.output **/smoke **/node_modules **/fixtures **/vendor **/.vercel -examples/docs/**/*.md -examples/blog/**/*.md + +# Short-term need to format +!packages/db/test/fixtures # Directories .github .changeset # Files -README.md -packages/webapi/mod.d.ts pnpm-lock.yaml + +# Formatted by Biome +**/*.json +**/*.js +**/*.ts +**/*.tsx +**/*.jsx +**/*.mjs +**/*.cjs diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index b0a1a2a0757f..000000000000 --- a/.prettierrc.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "printWidth": 100, - "semi": true, - "singleQuote": true, - "tabWidth": 2, - "trailingComma": "es5", - "useTabs": true, - "overrides": [ - { - "files": [".*", "*.json", "*.md", "*.toml", "*.yml"], - "options": { - "useTabs": false - } - } - ], - "pluginSearchDirs": ["./assets"] -} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index d8411afe0257..ea69b5c70466 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,7 +3,8 @@ "astro-build.astro-vscode", "esbenp.prettier-vscode", "editorconfig.editorconfig", - "dbaeumer.vscode-eslint" + "dbaeumer.vscode-eslint", + "biomejs.biome" ], "unwantedRecommendations": [] } diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000000..97aeabec0f36 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,21 @@ +{ + "[json]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[javascript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[typescript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[javascriptreact]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[typescriptreact]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "editor.codeActionsOnSave": { + "quickFix.biome": "explicit", + "source.fixAll.biome": "explicit" + } +} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 63266fdec162..000000000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, sex characteristics, gender identity and expression, -level of experience, education, socio-economic status, nationality, personal -appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -- Using welcoming and inclusive language -- Being respectful of differing viewpoints and experiences -- Gracefully accepting constructive criticism -- Focusing on what is best for the community -- Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -- The use of sexualized language or imagery and unwelcome sexual attention or - advances -- Trolling, insulting/derogatory comments, and personal or political attacks -- Public or private harassment -- Publishing others' private information, such as a physical or electronic - address, without explicit permission -- Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -All complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -See [GOVERNANCE.md](GOVERNANCE.md#Moderation) for instructions on reporting a Code of Conduct violation and a full description of the review process. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html - -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9ff3bae3a120..d44be03b8ce3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,22 +2,25 @@ We welcome contributions of any size and skill level. As an open source project, we believe in giving back to our contributors and are happy to help with guidance on PRs, technical writing, and turning any feature idea into a reality. -> **Tip for new contributors:** -> Take a look at [https://github.com/firstcontributions/first-contributions](https://github.com/firstcontributions/first-contributions) for helpful information on contributing +> [!Tip] +> +> **For new contributors:** Take a look at [https://github.com/firstcontributions/first-contributions](https://github.com/firstcontributions/first-contributions) for helpful information on contributing ## Quick Guide -### Prerequisite +### Prerequisites ```shell -node: "^14.15.0 || >=16.0.0" -pnpm: "^7.0.0" +node: "^>=18.17.1" +pnpm: "^9.12.1" # otherwise, your build will fail ``` +We recommend using Corepack, [read PNPM docs](https://pnpm.io/installation#using-corepack). + ### Setting up your local repo -Astro uses pnpm workspaces, so you should **always run `pnpm install` from the top-level project directory.** running `pnpm install` in the top-level project root will install dependencies for `astro`, and every package in the repo. +Astro uses pnpm workspaces, so you should **always run `pnpm install` from the top-level project directory**. Running `pnpm install` in the top-level project root will install dependencies for `astro`, and every package in the repo. ```shell git clone && cd ... @@ -31,6 +34,24 @@ In [#2254](https://github.com/withastro/astro/pull/2254) a `.git-blame-ignore-re git config --local blame.ignoreRevsFile .git-blame-ignore-revs ``` +To automatically handle merge conflicts in `pnpm-lock.yaml`, you should run the following commands locally. + +```shell +pnpm add -g @pnpm/merge-driver +pnpm dlx npm-merge-driver install --driver-name pnpm-merge-driver --driver "pnpm-merge-driver %A %O %B %P" --files pnpm-lock.yaml +``` + +### Using GitHub Codespaces for development + +To get started, create a codespace for this repository by clicking this 👇 + +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro) + +Your new codespace will open in a web-based version of Visual Studio Code. All development dependencies will be preinstalled, and the tests will run automatically ensuring you've got a green base from which to start working. + +> [!Note] +> Dev containers is now an open spec which is supported by [GitHub Codespaces](https://github.com/codespaces) and [other supporting tools](https://containers.dev/supporting). + ### Development ```shell @@ -40,11 +61,27 @@ pnpm run dev pnpm run build ``` +**How can I test my changes while contributing to the repository?** + +During the development process, you may want to test your changes to ensure they are working as expected. Here are a few ways to do it: + +1. Run any of the examples in the `/examples` folder. They are linked to use the local Astro source code, so you can see the effects of your changes. + + ```shell + pnpm --filter @example/minimal run dev + ``` + +2. Write a test and run it. This is useful if you're making a specific fix and want to see if your changes are working as expected. + +3. Create a separate project and use your local Astro through [`pnpm link`](https://pnpm.io/cli/link). This is helpful if you're making bigger changes and want to test them in a separate project. + +Overall, it's up to personal preference which method to use. For smaller changes, using the examples folder may be sufficient. For larger changes, using a separate project may be more appropriate. + #### Debugging Vite You can debug vite by prefixing any command with `DEBUG` like so: -``` +```shell DEBUG=vite:* astro dev # debug everything in Vite DEBUG=vite:[name] astro dev # debug specific process, e.g. "vite:deps" or "vite:transform" ``` @@ -54,11 +91,97 @@ DEBUG=vite:[name] astro dev # debug specific process, e.g. "vite:deps" or "vit ```shell # run this in the top-level project root to run all tests pnpm run test -# run only a few tests, great for working on a single feature -# (example - `pnpm run test:match "RSS"` runs `astro-rss.test.js`) +# run only a few tests in the `astro` package, great for working on a single feature +# (example - `pnpm run test:match "cli"` runs tests with "cli" in the name) pnpm run test:match "$STRING_MATCH" +# run tests on another package +# (example - `pnpm --filter @astrojs/rss run test` runs `packages/astro-rss/test/rss.test.js`) +pnpm --filter $STRING_MATCH run test +``` + +Most tests use [`mocha`](https://mochajs.org) as the test runner. We're slowly migrating to use [`node:test`](https://nodejs.org/api/test.html) instead through the custom [`astro-scripts test`](./scripts/cmd/test.js) command. For packages that use `node:test`, you can run these commands in their directories: + +```shell +# run all of the package's tests +pnpm run test +# run only a few tests in the package +# (example - `pnpm run test -m "cli"` runs tests with "cli" in the name) +pnpm run test -m "$STRING_MATCH" +# run a single test file, you can use `node --test` directly +node --test ./test/foo.test.js +``` + +#### Running a single test + +Sometimes you want to run a single test case (`it` or `describe`) or a single test file. You can do so by using Node.js. + +To run a single test file, for example `test/astro-basic.test.js`: + +```shell +node --test test/astro-basic.test.js +``` + +If you wish to run a single test case, you have to postfix `it` and `describe` functions with `.only`: + +```diff +// test/astro-basic.test.js +- describe("description", () => { ++ describe.only("description", () => { +- it("description", () => { ++ it.only("description", () => {}) +}) +``` + +Then, you have to pass the `--test-only` option to the Node.js: + +```shell +node --test --test-only test/astro-basic.test.js +``` + +> [!WARNING] +> +> 1. If you have nested `describe`, all of them must postfix with `.only` +> 2. `--test-only` and `--test` must be placed **before** declaring the path to the file. Failing to do so will test all files + +#### Debugging tests in CI + +There might be occasions where some tests fail in certain CI runs due to some timeout issue. If this happens, it will be very difficult to understand which file cause the timeout. That's caused by come quirks of the Node.js test runner combined with our architecture. + +To understand which file causes the issue, you can modify the `test` script inside the `package.json` by adding the `--parallel` option: + +```diff +{ +- "test": "astro-scripts test \"test/**/*.test.js\"", ++ "test": "astro-scripts test --parallel \"test/**/*.test.js\"", +} ``` +Save the change and **push it** to your PR. This change will make the test CI slower, but it will allow to see which files causes the timeout. Once you fixed the issue **revert the change and push it**. + +#### E2E tests + +Certain features, like HMR and client hydration, need end-to-end tests to verify functionality in the dev server. [Playwright](https://playwright.dev/) is used to test against the dev server. + +```shell +# run this in the top-level project root to run all E2E tests +pnpm run test:e2e +# run only a few tests, great for working on a single feature +# (example - `pnpm run test:e2e:match "Tailwind CSS" runs `tailwindcss.test.js`) +pnpm run test:e2e:match "$STRING_MATCH" +``` + +**When should you add E2E tests?** + +Any tests for `astro build` output should use the main `mocha` tests rather than E2E - these tests will run faster than having Playwright start the `astro preview` server. + +If a test needs to validate what happens on the page after it's loading in the browser, that's a perfect use for E2E dev server tests, i.e. to verify that hot-module reloading works in `astro dev` or that components were client hydrated and are interactive. + +#### Creating tests + +When creating new tests, it's best to reference other existing test files and replicate the same setup. Some other tips include: + +- When re-using a fixture multiple times with different configurations, you should also configure unique `outDir`, `build.client`, and `build.server` values so the build output runtime isn't cached and shared by ESM between test runs. + ### Other useful commands ```shell @@ -83,22 +206,82 @@ pnpm exec changeset ### Running benchmarks -We have benchmarks to keep performance under control. You can run these by running (from the project root): +We have benchmarks to keep performance under control. They are located in the `benchmarks` directory, and it exposes a CLI you can use to run them. + +You can run all available benchmarks sequentially by running (from the project root): ```shell -pnpm run benchmark --filter astro +pnpm run benchmark ``` -Which will fail if the performance has regressed by **10%** or more. - -To update the times cd into the `packages/astro` folder and run the following: +To run a specific benchmark only, you can add the name of the benchmark after the command: ```shell -node test/benchmark/build.bench.js --save -node test/benchmark/dev.bench.js --save +pnpm run benchmark memory +``` + +Use `pnpm run benchmark --help` to see all available options. + +To run these benchmarks in a PR on GitHub instead of using the CLI, you can comment `!bench`. The benchmarks will run on both the PR branch and the `main` branch, and the results will be posted as a new comment. + +To run only a specific benchmark on CI, add its name after the command in your comment, for example, `!bench memory`. + +## For maintainers + +This paragraph provides some guidance to the maintainers of the monorepo. The guidelines explained here aren't necessarily followed by other repositories of the same GitHub organisation. + +### Issue triaging workflow + +```mermaid +graph TD; + start{Followed issue\ntemplate?} + start --NO--> close1[Close and ask to\nfollow template] + start --YES--> dupe{Is duplicate?} + dupe --YES--> close2[Close and point\nto duplicate] + dupe --NO--> repro{Has proper\nreproduction?} + repro --NO--> close3[Label: 'needs reproduction'\nbot will auto close if no update\nhas been made in 3 days] + repro --YES--> real{Is actually a bug?} + real --NO--> maybefeat{Is it a feature request?} + maybefeat -- YES --> roadmap[Close the issue.\n Point user to the roadmap.] + maybefeat -- NO --> intended{Is the intended\nbehaviour?} + intended --YES--> explain[Explain and close\npoint to docs if needed] + intended --NO--> open[Add label 'needs discussion'\nRemove 'needs triage' label] + real --YES--> real2["1. Remove 'needs triage' label\n2. Add related feature label if\napplicable (e.g. 'feat: ssr')\n3. Add priority and meta labels (see below)"] + real2 --> tolabel[Use the framework below to decide the priority of the issue,\nand choose the correct label] + ``` -Which will update the build and dev benchmarks. +### Assign priority to bugs + +The Astro project has five levels of priority to issues, where `p5` is the highest in priority, and `p1` is the lowest in priority. + +- `p5`: the bug impacts the majority of Astro projects, it doesn't have a workaround and makes Astro unusable/unstable. + + Some examples: + + - the dev server crashes; + - the build breaks and doesn't complete; + - huge regressions in terms of performance; + + Bugs violate the documentation/intended behaviour of the feature, although sometimes the documentation might not cover possible edge cases. + + Usually we **don't** assign this priority to packages that **aren't** `astro`, but that can change. + +- `p4`: the bug impacts _many_ Astro projects, it doesn't have a workaround but Astro is still stable/usable. +- `p3`: any bug that doesn't fall in the `p4` or `p5` category. If the documentation doesn't cover + the case reported by the user, it's useful to initiate a discussion via the `"needs discussion"` label. Seek opinions from OP and other maintainers. +- `p2`: all the bugs that have workarounds. +- `p1`: very minor bug, that impacts a small amount of users. Sometimes it's an edge case and it's easy to fix. Very useful if you want to assign the fix to a first-time contributor. + +> [!IMPORTANT] +> The priority of a bug isn't set on stone. It can change based on different factors. + +Assigning labels isn't always easy and many times the distinction between the different levels of priority is blurry, hence try to follow these guidelines: + +- When assigning a `p2`, **always** add a comment that explains the workaround. If a workaround isn't provided, ping the person that assigned the label and ask them to provide one. +- Astro has **many** features, but there are some that have a larger impact than others: development server, build command, HMR (TBD, we don't have a page that explains expectations of HMR in Astro), **evident** regressions in performance. +- In case the number of reactions of an issue grows, the number of users affected grows, or a discussion uncovers some insights that weren't clear before, it's OK to change the priority of the issue. The maintainer **should** provide an explanation when assigning a different label. + As with any other contribution, triaging is voluntary and best-efforts. We welcome and appreciate all the help you're happy to give (including reading this!) and nothing more. If you are not confident about an issue, you are welcome to leave an issue untriaged for someone who would have more context, or to bring it to their attention. ## Code Structure @@ -106,12 +289,12 @@ Server-side rendering (SSR) can be complicated. The Astro package (`packages/ast - `components/`: Built-in components to use in your project (e.g. `import Code from 'astro/components/Code.astro'`) - `src/`: Astro source - - `@types/`: TypeScript types. These are centralized to cut down on circular dependencies + - `types/`: TypeScript types. These are centralized to cut down on circular dependencies - `cli/`: Code that powers the `astro` CLI command - `core/`: Code that executes **in the top-level scope** (in Node). Within, you’ll find code that powers the `astro build` and `astro dev` commands, as well as top-level SSR code. - `runtime/`: Code that executes **in different scopes** (i.e. not in a pure Node context). You’ll have to think about code differently here. - `client/`: Code that executes **in the browser.** Astro’s partial hydration code lives here, and only browser-compatible code can be used. - - `server/`: Code that executes **inside Vite’s SSR.** Though this is a Node environment inside, this will be executed independently from `core/` and may have to be structured differently. + - `server/`: Code that executes **inside Vite’s SSR.** Though this is a Node environment inside, this will be executed independently of `core/` and may have to be structured differently. - `vite-plugin-*/`: Any Vite plugins that Astro needs to run. For the most part, these also execute within Vite similar to `src/runtime/server/`, but it’s also helpful to think about them as independent modules. _Note: at the moment these are internal while they’re in development_ ### Thinking about SSR @@ -124,9 +307,25 @@ There are 3 contexts in which code executes: Understanding in which environment code runs, and at which stage in the process, can help clarify thinking about what Astro is doing. It also helps with debugging, for instance, if you’re working within `src/core/`, you know that your code isn’t executing within Vite, so you don’t have to debug Vite’s setup. But you will have to debug vite inside `runtime/server/`. +## Branches + +### `main` + +Active Astro development happens on the [`main`](https://github.com/withastro/astro/tree/main) branch. `main` always reflects the latest code. + +> [!Note] +> During certain periods, we put `main` into a [**prerelease**](https://github.com/changesets/changesets/blob/main/docs/prereleases.md#prereleases) state. Read more about [Releasing Astro](#releasing-astro). + +### `latest` + +The **stable** release of Astro can always be found on the [`latest`](https://github.com/withastro/astro/tree/latest) branch. `latest` is automatically updated every time we publish a stable (not prerelease) version of Astro. + +By default, `create-astro` and [astro.new](https://astro.new) point to this branch. + ## Releasing Astro -_Note: Only [core maintainers (L3+)](https://github.com/withastro/astro/blob/main/GOVERNANCE.md#level-3-l3---core-maintainer) can release new versions of Astro._ +> [!Note] +> Only [core maintainers (L3+)](https://github.com/withastro/.github/blob/main/GOVERNANCE.md#level-3-l3---core) can release new versions of Astro. The repo is set up with automatic releases, using the changeset GitHub action & bot. @@ -136,48 +335,57 @@ To release a new version of Astro, find the `Version Packages` PR, read it over, Our release tool `changeset` has a feature for releasing "snapshot" releases from a PR or custom branch. These are npm package publishes that live temporarily, so that you can give users a way to test a PR before merging. This can be a great way to get early user feedback while still in the PR review process. +To run `changeset version` locally, you'll need to create a GitHub [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) and set it as a `GITHUB_TOKEN` environment variable. + To release a snapshot, run the following locally: ```shell -# Note: XXX should be a keyword to identify this release. Ex: `--snapshot routing` & `--tag next--routing` - -# 1: -pnpm exec changeset version --snapshot XXX -# 2: (Manual) review the diff, and make sure that you're not releasing more than you need to. +# Notes: +# - YYY should be a keyword to identify this release. Ex: `--snapshot routing` & `--tag next--routing` +# - Use npm/npx instead of pnpm, since npm handles registry login, authentication and publishing. +# - Adding GITHUB_TOKEN in the command adds that token to your bash history. Set a short expiration! + +# 1: Tag the new release versions +GITHUB_TOKEN=XXX npx changeset version --snapshot YYY +# 2: Review the diff, and make sure that you're not releasing more than you need to. git checkout -- examples/ -# 3: -pnpm run release --tag next--XXX -# 4: (Manual) review the publish, and if you're happy then you can throw out all local changes +# 3: Release +npm run release --tag next--YYY +# 4: If you're satisfied, you can now throw out all local changes git reset --hard ``` -Full documentation: https://github.com/atlassian/changesets/blob/main/docs/snapshot-releases.md +By default, every package with a changeset will be released. If you only want to target a smaller subset of packages for release, you can consider clearing out the `.changesets` directory to replace all existing changesets with a single changeset of only the packages that you want to release. Just be sure not to commit or push this to `main`, since it will destroy existing changesets that you will still want to eventually release. + +Full documentation: https://github.com/changesets/changesets/blob/main/docs/snapshot-releases.md ### Releasing `astro@next` (aka "prerelease mode") Sometimes, the repo will enter into "prerelease mode". In prerelease mode, our normal release process will publish npm versions under the `next` dist-tag, instead of the default `latest` tag. We do this from time-to-time to test large features before sharing them with the larger Astro audience. -While in prerelease mode, follow the normal release process to release `astro@next` instead of `astro@latest`. To release `astro@latest` instead, see [Releasing `astro@latest` while in prerelease mode](#user-content-releasing-astrolatest-while-in-prerelease-mode). +While in prerelease mode, follow the normal release process to release `astro@next` instead of `astro@latest`. To release `astro@latest` instead, see [Releasing `astro@latest` while in prerelease mode](#releasing-astrolatest-while-in-prerelease-mode). -Full documentation: https://github.com/atlassian/changesets/blob/main/docs/prereleases.md +Full documentation: https://github.com/changesets/changesets/blob/main/docs/prereleases.md ### Entering prerelease mode -If you have gotten permission from the core contributors, you can enter into prerelease mode by following the following steps: +If you have gotten permission from the core contributors, you can enter into prerelease mode with the following steps: - Run: `pnpm exec changeset pre enter next` in the project root +- Update `.changeset/config.json` with `"baseBranch": "next"` (for easier changesets creation) - Create a new PR from the changes created by this command -- Review, approve, and more the PR to enter prerelease mode. -- If successful, The "Version Packages" PR (if one exists) will now say "Version Packages (next)". +- Review, approve, and merge the PR to enter prerelease mode. +- If successful, The "[ci] release" PR (if one exists) will now say "[ci] release (next)". ### Exiting prerelease mode -Exiting prerelease mode should happen once an experimental release is ready to go from `npm install astro@next` to `npm install astro`. Only a core contributor run these steps. These steps should be run before +Exiting prerelease mode should happen once an experimental release is ready to go from `npm install astro@next` to `npm install astro`. Only a core contributor can run these steps: - Run: `pnpm exec changeset pre exit` in the project root +- Update `.changeset/config.json` with `"baseBranch": "main"` - Create a new PR from the changes created by this command. -- Review, approve, and more the PR to enter prerelease mode. -- If successful, The "Version Packages (next)" PR (if one exists) will now say "Version Packages". +- Review, approve, and merge the PR to enter prerelease mode. +- If successful, The "[ci] release (next)" PR (if one exists) will now say "[ci] release". ### Releasing `astro@latest` while in prerelease mode diff --git a/FUNDING.md b/FUNDING.md deleted file mode 100644 index 8a29c9011617..000000000000 --- a/FUNDING.md +++ /dev/null @@ -1,40 +0,0 @@ -# Astro Project Funding - -_Last Updated: 02-09-2022_ - -## Raising Funds - -Astro is an MIT licensed open source project and completely free to use. However, the amount of effort needed to maintain and develop new features for Astro is not sustainable without proper financial backing. We need your help to achieve this. - -Learn more about sponsorship on our [Open Collective.](https://opencollective.com/astrodotbuild). - -### Why Open Collective? - -- **Full Transparency.** Everyone gets to see where money is coming from and where it's going. -- **Individual and Corporate Sponsors.** Open Collective makes it easy for both individuals and companies to sponsor open source projects. -- **Potential Tax Benefits.** Because funds are paid to the Open Source Collective, a 501(c)(6) organization in the U.S., there may be tax benefits for some donors (please check with your accountant). -- **Automatic Invoicing.** For corporate sponsors, Open Collective automatically generates and sends invoices for tracking purposes. -- **Open Participation.** Anyone can request reimbursement for funds spent helping the Astro project and Astro can pay out to anyone. - -_List borrowed from [ESLint: "Funding ESLint's Future."](https://eslint.org/blog/2019/02/funding-eslint-future)_ - -## Distributing Funds - -100% of money raised is invested back into the community. Every dollar spent **must** support and/or improve Astro in some way. - -See all past expenses on our [Open Collective.](https://opencollective.com/astrodotbuild) - -Below is a (non-exhaustive) list of how we plan to distribute raised funds: - -- **Swag!** Creating stickers, t-shirts, etc. for sponsors and community members. -- **Improve documentation.** -- **Improve translations.** -- **Improve website.** -- **User research.** -- **Sponsoring conferences.** -- **Sponsoring community members to represent Astro at meetups, conferences, etc.** -- **Dedicated support for GitHub, Discord, Stack Overflow, etc.** - -## Eligibility - -**Employees of The Astro Technology Company are not eligible to receive funds from Open Collective.** These funds exist solely to serve the larger Astro community. diff --git a/FUNDING.yml b/FUNDING.yml deleted file mode 100644 index 7ace19ae2d3a..000000000000 --- a/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # Replace with a single Patreon username -open_collective: astrodotbuild -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/GOVERNANCE.md b/GOVERNANCE.md deleted file mode 100644 index 0ed5237650a7..000000000000 --- a/GOVERNANCE.md +++ /dev/null @@ -1,379 +0,0 @@ -# Governance - -This document outlines the governance model for Astro. This includes detailed descriptions of the contributor levels, nomination process, code review process, pull request merge process, and the consequences of Code of Conduct violations. - -👉 **All community members must follow the [Code of Conduct (CoC)](CODE_OF_CONDUCT.md).** -Consequences for CoC violations are detailed in [Moderation](#moderation). - -👉 **Want to trigger a vote, nomination, or perform some other action?** -Scroll down to [Playbook](#governance-playbook). - -## Get Involved - -**Anything that supports the Astro community is a valuable contribution.** All types of contribution are meaningful, from code to documentation to blog posts. Anyone can become an Astro Contributor (yes, even you!). Our goal is to recognize all contributors to Astro regardless of skill, experience or background. - -## Contributor Levels - -We recognize different degrees of contribution as **levels**, and most levels can be reached regardless of coding skill or years of experience. The two most important things that we look for in contributors are: - -- **Being here** - Everyone's time is valuable, and the fact that you're here and contributing to Astro is amazing! Thank you for being a part of this journey with us. -- **Being a positive member of our community** - Go above and beyond our Code of Conduct, and commit to healthy communication in pull requests, issue discussions, Discord conversations, and interactions outside of our community (ex: no Twitter bullies allowed :) - -Each level unlocks new privileges and responsibilities on Discord and GitHub. Below is a summary of each contributor level: - -### Level 1 - Contributor - -Have you done something (big or small) to contribute to the health, success, or growth of Astro? Congratulations, you're officially recognized as a contributor to the project! - -#### Examples of recognized contributions - -- **GitHub:** Submitting a merged pull request -- **GitHub:** Filing a detailed bug report or RFC -- **GitHub:** Updating documentation! -- Helping people on GitHub, Discord, etc. -- Answering questions on Stack Overflow, Twitter, etc. -- Blogging, Vlogging, Podcasting, and Livestreaming about Astro -- This list is incomplete! Similar contributions are also recognized. - -#### Privileges - -- New role on [Discord](https://astro.build/chat): `@contributor` -- New name color on Discord: **light blue**. -- Invitations to contributor-only events, sticker drops, and the occasional swag drop. - -#### Responsibilities - -This role does not require any extra responsibilities or time commitment. We hope you stick around and keep participating! - -If you're interested in reaching the next level and becoming a Maintainer, you can begin to explore some of those responsibilities in the next section. - -#### Nomination Process - -If you contributed to Astro outside of Discord, you may self-nominate by sending `!contribute` in any Discord channel, accompanied by a link or description of your contribution. You may also gain this role if you are active and helpful on Discord. - -### Level 2 (L2) - Maintainer - -The **Maintainer** role is available to any contributor who wants to join the team and take part in the long-term maintenance of Astro. - -The Maintainer role is critical to the long-term health of Astro. Maintainers act as the first line of defense when it comes to new issues, pull requests and Discord activity. Maintainers are most likely the first people that a user will interact with on Discord or GitHub. - -**A Maintainer is not required to write code!** Some Maintainers spend most of their time inside of Discord, maintaining a healthy community there. - -**A Maintainer has moderation privileges!** All maintainers are trusted with the ability to help moderate our Discord and GitHub communities for things like spam. There is also a special (optional, opt-in) `@mods` role open to maintainers who are also interested in helping out when a community member reaches out for moderation help. - -#### Recognized Contributions - -There is no strict minimum number of contributions needed to reach this level, as long as you can show **sustained** involvement over some amount of time (at least a couple of weeks). - -- **GitHub:** Submitting non-trivial pull requests and RFCs -- **GitHub:** Reviewing non-trivial pull requests and RFCs -- **Discord:** Supporting users in Discord, especially in the #support channel -- **Discord:** Active participation in RFC calls and other events -- **GitHub + Discord:** Triaging and confirming user issues -- This list is incomplete! Similar contributions are also recognized. - -#### Privileges - -- All privileges of the [Contributor role](#level-1---contributor), plus... -- Invitation to the `@maintainer` role on [Discord](https://astro.build/chat) -- Invitation to the `@maintainers` team on GitHub. -- New name color on Discord: **blue**. -- Invitation to the private #maintainers channel on Discord. -- Ability to moderate Discord to remove spam, harmful speech, etc. -- Ability to join the `@mods` role on Discord (optional, opt-in). -- Ability to push branches to the repo (No more personal fork needed). -- Ability to review GitHub PRs. -- Ability to merge _some_ GitHub PRs. -- Ability to vote on _some_ initiatives (see [Voting](#voting) below). - -#### Responsibilities - -- Participate in the project as a team player. -- Bring a friendly, welcoming voice to the Astro community. -- Be active on Discord, especially in the #support channel. -- Triage new issues. -- Review pull requests. -- Merge some, non-trivial community pull requests. -- Merge your own pull requests (once reviewed and approved). - -#### Nomination - -To be nominated, a nominee is expected to already be performing some of the responsibilities of a Maintainer over the course of at least a couple of weeks. - -In some rare cases, this role may be revoked by a project Steward. However, under normal circumstances this role is granted for as long as the contributor wishes to engage with the project. - -#### Nomination Process - -- You can be nominated by any existing Maintainer (L2 or above). -- Once nominated, there will be a vote by existing Maintainers (L2 and above). -- See [vote rules & requirements](#voting) for info on how the vote works. - -### Level 3 (L3) - Core Maintainer - -**Core Maintainers** are community members who have contributed a significant amount of time and energy to the project through issues, bug fixes, implementing enhancements/features, and engagement with the community. A Core Maintainer is considered a trusted leader within the community. - -A Core Maintainer has significant sway in software design decisions. For this reason, coding experience is critical for this role. Core Maintainer is the only level of contributor that does require a significant contribution history on GitHub. - -Core maintainers are watchdogs over the code, ensuring code quality, correctness and security. A Core Maintainer helps to set the direction of the project and ensure a healthy future for Astro. - -Some contributors will not reach this level, and that's okay! L2 Maintainers still have significant responsibility and privileges in our community. - -#### Privileges - -- All privileges of the [Maintainer role](#level-2---maintainer), plus... -- `@core` role on [Discord](https://astro.build/chat) -- New name color on Discord: **yellow**. -- Invitation to the private #core channel on Discord. -- Invitation to the `core` team on GitHub. -- Ability to merge all GitHub PRs. -- Ability to vote on all initiatives (see [Voting](#voting) below). - -#### Responsibilities - -- All of the responsibilities of L2, including... -- Ownership over specific parts of the project. -- Maintaining and improving overall architecture. -- Tracking and ensuring progress of open pull requests. -- Reviewing and merging larger, non-trivial PRs. - -#### Nomination - -To be nominated, a nominee is expected to already be performing some of the responsibilities of a Core Maintainer. This could include showing expertise over some larger section of the codebase, championing RFCs through ideation and implementation, reviewing non-trivial PRs and providing critical feedback, or some combination of those responsibilities listed above. - -If a Core Maintainer steps away from the project for a significant amount of time, they may be removed as a Core Maintainer (L3 -> L2) until they choose to return. - -In some rare cases, this role may be revoked by a project Steward. However, under normal circumstances this role is granted for as long as the contributor wishes to engage with the project. - -#### Nomination Process - -- You can be nominated by any existing Core Maintainer (L3 or above). -- Once nominated, there will be a vote by existing Core Maintainers (L3 and above). -- See [vote rules & requirements](#voting) for info on how the vote works. - -### Steward - -Steward is an additional privilege bestowed to 1 (or more) Core Maintainers. The role of Steward is mainly an administrative one. Stewards control and maintain sensitive project assets, and act as tiebreakers in the event of disagreements. - -In extremely rare cases, a Steward can act unilaterally when they believe it is in the project's best interest and can prove that the issue cannot be resolved through normal governance procedure. The steward must publicly state their reason for unilateral action before taking it. - -The project Steward is currently: **@FredKSchott** - -#### Responsibilities - -- Access to the [@astrodotbuild Twitter account](https://twitter.com/astrodotbuild) -- Administration privileges on the [astro GitHub org](https://github.com/snowpackjs) -- Administration privileges on the [astro Discord server](https://astro.build/chat) -- Publish access to the [`astro` npm package](https://www.npmjs.com/package/astro) -- Domain registrar and DNS access to `astro.build` and all other domains -- Administration access to the `astro.build` Vercel account -- Ability to initiate a [vote](GOVERNANCE.md#voting) -- Ability to veto [votes](GOVERNANCE.md#voting) and resolve voting deadlocks -- Define project direction and planning -- Ability to decide on moderation decisions -- Access to the `*@astro.build` email address - -#### Nomination - -- Stewards cannot be self-nominated. -- Only Core Maintainers are eligible. -- New stewards will be added based on a unanimous vote by the existing Steward(s). -- In the event that someone is unreachable then the decision will be deferred. - -## Other Roles - -### Staff - -Staff is a special designation for employees of [The Astro Technology Company](https://astro.build/company) that lives outside of our Governance model. The staff role was designed to help those of us working full-time on Astro to work productively without "skipping the line" and circumventing our governance model entirely. - -The staff role was designed to offer instant **visibility** and **trust**, but not instant **authority.** - -#### Privileges - -All privileges of the [Core Maintainer role](#level-3---core-mainainer), except... - -- Instead of gaining Discord contributor roles (`@contributor`, `@maintainer`, `@core`) you will receive a special `@staff` role in Discord and GitHub that grants equivalent visibility and permissions as `@core`. -- No voting abilities for the first 3 months of staff membership. Then, the role grants equivalent voting permissions as `@core` (see [Voting](#voting) below). -- Not eligible for additional contributor levels while acting as `@staff`. You can retain all current contributor levels and can request a new nomination upon leaving `@staff` (See [Leaving Staff](#leaving-staff) below). This rule is designed to prevent a team of contributors/maintainers that is overwhelmingly ex-staff members. - -#### Responsibilities - -Responsibilities will vary. Most often, a staff member will regularly meet the responsibilites of either the [Maintainer (L2)](#level-2---maintainer) or [Core Maintainer (L3)](#level-3---core-mainainer) role. - -#### Nomination - -There is no nomination process for this role. The project steward is responsible for granting and revoking the `@staff` role. - -#### Leaving Staff - -When someone leaves the Astro Technology Company, they lose staff privileges and return to their original membership level in our governance structure (whatever level they were at before joining staff). - -If that person wishes to continue working on Astro after leaving, they may request a nomination to become an official L2 or L3 contributor. This nomination would follow the normal voting rules & procedure for that role (see [Voting](#voting) below). - -# Governance Playbook - -## Voting - -Certain project decisions (like governance changes and membership nominations) require a vote. Below are the changes that require a vote, and the rules that govern that vote. - -The project Steward may initiate a vote for any unlisted project decision. [General Rules](#general-rules) will apply, along with any addition rules provided at the steward's discretion. If this unlisted project decision is expected to be repeated in the future, voting rules should be agreed on and then added to this document. - -### General Voting Rules - -- Members may abstain from any vote. -- Members who do not vote within 3 days will automatically abstain. -- Stewards may reduce the 3 day automatic abstain for urgent decisions. -- Stewards reserve the right to veto approval with a publicly disclosed reason. - -## Voting: Maintainer (L2) Nomination - -This process kicks off once a valid nomination has been made. See ["Maintainer - Nomination Process"](#nomination-process) above for more details on nomination. - -**Who can vote:** All Maintainers (L2 and above). - -1. A vote thread should be created in Discord #maintainers channel (the private channel for all maintainers). -2. A vote thread can be created by any maintainer, core maintainer, or the Steward. -3. Once a vote thread is created, existing Maintainers can discuss the nomination in private. -4. The normal 3 day voting & discussion window begins with the thread creation. -5. Voting can be done in the thread (visible to other voters) or in a private DM to the project Steward. -6. Once the vote is complete, the thread is deleted. -7. The vote must receive an overwhelming majority (70%+) to pass. -8. **If the vote passes:** the nominee will be made a Maintainer and all privileges will be made available to them. -9. **If the vote fails:** the project Steward is responsible for informing the nominee with constructive, actionable feedback. (Note: this is not required if the nomination was made in the #core channel, or if the nominee was otherwise not made aware of their nomination). - -#### Draft message to send to accepted maintainer, informing them of the decision: - -``` -Hey ${NAME}! - -**I have some exciting news — you've been given the role of L2 Contributor (aka Maintainer/Moderator) in the Astro community!** - -Some background: I nominated you for the role in the (private) #maintainers channel, and the consensus was overwhelmingly positive. Some quotes from the nomination thread that sum up the impact you've already had on the project so far: - -- ... -- ... -- ... - -Thank you for ${1 SENTENCE DESCRIPTION OF CONTRIBUTIONS}. Your impact has definitely been felt and we would be thrilled to have your help building a healthy future for Astro! There is no required time commitment: you can continue to contribute as often or as little as you'd like. This is mainly a chance to recognize your contributions and give you more privileges in Discord and GitHub. - -Please let me know if you’re interested in accepting this invitation. If so, we’ll start getting your roles up to date. And if you have any questions, feel free to let me know. - -Best, -${MY_NAME} - -*PS: As a reminder, our Governance document describes the following privileges and responsibilities for the **L2 - Maintainer** role: https://github.com/withastro/astro/blob/main/GOVERNANCE.md* -``` - -## Voting: Core Maintainer (L3) Nomination - -This process kicks off once a valid nomination has been made. See ["Core Maintainer - Nomination Process"](#nomination-process) above for more details on nomination. - -**Who can vote:** All Core Maintainers (L3 and above). - -1. A vote thread should be created in Discord #core channel (the private channel for core maintainers). -2. A vote thread can be created by any core maintainer, or the Steward. -3. Once a vote thread is created, existing Core Maintainers can discuss the nomination in private. -4. The normal 3 day voting & discussion window begins with the thread creation. -5. Voting can be done in the thread (visible to other voters) or in a private DM to the project Steward. -6. Once the vote is complete, the thread is deleted. -7. The vote must receive an overwhelming majority (70%+) to pass. -8. **If the vote passes:** the nominee will be made a Core Maintainer and all privileges will be made available to them. -9. **If the vote fails:** the project Steward is responsible for informing the nominee with constructive, actionable feedback. (Note: this is not required if the nomination was made in the #core channel, or if the nominee was otherwise not made aware of their nomination). - -#### Draft message to send to accepted maintainer, informing them of the decision: - -``` -Hey $NAME! - -I have some exciting news—you’ve been nominated and accepted as a core maintainer of Astro! The core maintainer group held a vote and overwhelmingly agree that you would be a great addition to the team. Congratulations! Thanks for all of your significant contributions to Astro to date and your continued dedication to this project and our community. We would be thrilled to have your help ensuring a healthy future for Astro! - -Please let me know if you’re interested in accepting this invitation. If so, we’ll start getting your roles and permissions up to date. - -As a reminder, our Governance document describes the following privileges and responsibilities for a **Core Maintainer**: - -#### Privileges - -$COPY_AND_PASTE_FROM_ABOVE - -#### Responsibilities - -$COPY_AND_PASTE_FROM_ABOVE -``` - -## Voting: Governance Change - -A vote is initiated once a pull request to the GOVERNANCE.md file is submitted by a Core Maintainer. - -If the pull request submitter is not a Core Maintainer, the PR can be closed by any Maintainer without a vote. However, any Core Maintainer may request a vote on that PR, in which case a vote is initiated. - -**Who can vote:** Core Maintainers (L3 and above). All Maintainers are encouraged to discuss and voice their opinion in the pull request discussion. Core Maintainers should take the opinions of others into consideration when voting. - -1. The pull request discussion thread is used to discuss the governance change. -2. The normal 3 day voting & discussion window begins with either the PR creation or the removal of `WIP:` from the PR title if the PR was created as a draft. -3. Voting can be done in the pull request via a review of either **Approve (For)** or **Change Requested (Against)**. -4. The vote must receive a simple majority (50%+) to pass. -5. **If the vote passes:** the PR is merged and the changes take effect immediately. -6. **If the vote fails:** the PR is closed and no change occurs. - -## Voting: RFC Proposals - -Astro features are discussed using a model called [Consensus-seeking decision-making](https://en.wikipedia.org/wiki/Consensus-seeking_decision-making). This model attempts to achieve consensus on all significant changes to Astro, but has a fallback voting procedure in place if consensus appears unattainable. - -**Who can vote:** All Maintainers (L2 and above). - -1. Anyone can submit an RFC to suggest changes to Astro. -2. A trivial change can be discussed and approved entirely within the RFC GitHub issue, as long as there are no objections from Maintainers or Core Maintainers. This is not considered a formal vote. -3. A non-trivial, significant change should be discussed within the RFC GitHub issue and approved during an RFC meeting call. -4. During an RFC meeting, the moderator will attempt to achieve consensus on the RFC proposal. -5. **If consensus is reached:** the RFC is approved. -6. **If consensus is not reached:** Maintainers must make all reasonable attempts to resolve issues and reach consensus in GitHub or a follow-up RFC meeting. The process of reaching consensus can take time, and should not be rushed as long as all participants are making a reasonable effort to respond. -7. **If consensus still cannot be reached:** The project Steward may initiate the first fallback mechanism by limiting the vote to Core Maintainers. -8. **If consensus still cannot be reached:** The project Steward may initiate a final fallback vote of Core Maintainers, of which an overwhelming majority (80%+) is required to pass. -9. **If consensus still cannot be reached:** The RFC is closed without approval. - -## Moderation - -Outlined below is the process for Code of Conduct violation reviews. - -### Reporting - -Anyone may report a violation. Violations can be reported in the following ways: - -- In private, via email to one or more stewards. -- In private, via direct message to a project steward on Discord. -- In public, via a GitHub comment (mentioning `@snowpackjs/maintainers`). -- In public, via the project Discord server (mentioning `staff`). - -### Who gets involved? - -Each report will be assigned reviewers. These will initially be all project [stewards](#stewards). - -In the event of any conflict of interest - ie. stewards who are personally connected to a situation, they must immediately recuse themselves. - -At request of the reporter and if deemed appropriate by the reviewers, another neutral third-party may be involved in the review and decision process. - -### Review - -If a report doesn’t contain enough information, the reviewers will strive to obtain all relevant data before acting. - -The reviewers will then review the incident and determine, to the best of their ability: - -- What happened. -- Whether this event constitutes a Code of Conduct violation. -- Who, if anyone, was involved in the violation. -- Whether this is an ongoing situation. - -The reviewers should aim to have a resolution agreed very rapidly; if not agreed within a week, they will inform the parties of the planned date. - -### Resolution - -Responses will be determined by the reviewers on the basis of the information gathered and of the potential consequences. It may include: - -- taking no further action -- issuing a reprimand (private or public) -- asking for an apology (private or public) -- permanent ban from the GitHub org and Discord server -- revoked contributor status - ---- - -Inspired by [ESLint](https://eslint.org/docs/6.0.0/maintainer-guide/governance), [Rome](https://github.com/rome/tools/blob/main/GOVERNANCE.md) and [Blitz](https://blitzjs.com/docs/maintainers). diff --git a/LICENSE b/LICENSE index 1f0bcaa7dcef..b3cd0c0f0e01 100644 --- a/LICENSE +++ b/LICENSE @@ -20,7 +20,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - """ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository: @@ -33,7 +32,6 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ - """ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository: diff --git a/README.md b/README.md index db7591703b2e..f42323a863a4 100644 --- a/README.md +++ b/README.md @@ -1,125 +1,107 @@ +![Build the web you want](.github/assets/banner.jpg 'Build the web you want') +

- Astro logo -

+
Astro is a website build tool for the modern web —
powerful developer experience meets lightweight output.

+
+ +[![main](https://github.com/withastro/astro/actions/workflows/ci.yml/badge.svg)](https://github.com/withastro/astro/actions/workflows/ci.yml) +[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/withastro/astro/blob/main/LICENSE) +[![npm version](https://badge.fury.io/js/astro.svg)](https://badge.fury.io/js/astro) + +
+ ## Install +The **recommended** way to install the latest version of Astro is by running the command below: ```bash -# Recommended! npm create astro@latest +``` -# Manual: +You can also install Astro **manually** by running this command instead: + +```bash npm install --save-dev astro ``` -Looking for help? Start with our [Getting Started](https://docs.astro.build/en/getting-started/) guide. +Looking for help? Start with our [Getting Started](https://docs.astro.build/en/getting-started/) guide. Looking for quick examples? [Open a starter project](https://astro.new/) right in your browser. + ## Documentation -Visit our [offical documentation](https://docs.astro.build/). +Visit our [official documentation](https://docs.astro.build/). ## Support Having trouble? Get help in the official [Astro Discord](https://astro.build/chat). + ## Contributing -**New contributors welcome!** Check out our [Contributors Guide](CONTRIBUTING.md) for help getting started. +**New contributors welcome!** Check out our [Contributors Guide](CONTRIBUTING.md) for help getting started. Join us on [Discord](https://astro.build/chat) to meet other maintainers. We'll help you get your first contribution in no time! ## Directory -| Package | Release Notes | -| ------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | -| [astro](packages/astro) | [![astro version](https://img.shields.io/npm/v/astro.svg?label=%20)](packages/astro/CHANGELOG.md) | -| [create-astro](packages/create-astro) | [![create-astro version](https://img.shields.io/npm/v/create-astro.svg?label=%20)](packages/create-astro/CHANGELOG.md) | -| [@astrojs/react](packages/integrations/react) | [![astro version](https://img.shields.io/npm/v/@astrojs/react.svg?label=%20)](packages/integrations/react/CHANGELOG.md) | -| [@astrojs/preact](packages/integrations/preact) | [![astro version](https://img.shields.io/npm/v/@astrojs/preact.svg?label=%20)](packages/integrations/preact/CHANGELOG.md) | -| [@astrojs/solid-js](packages/integrations/solid-js) | [![astro version](https://img.shields.io/npm/v/@astrojs/solid-js.svg?label=%20)](packages/integrations/solid-js/CHANGELOG.md) | -| [@astrojs/svelte](packages/integrations/svelte) | [![astro version](https://img.shields.io/npm/v/@astrojs/svelte.svg?label=%20)](packages/integrations/svelte/CHANGELOG.md) | -| [@astrojs/vue](packages/integrations/vue) | [![astro version](https://img.shields.io/npm/v/@astrojs/vue.svg?label=%20)](packages/integrations/vue/CHANGELOG.md) | -| [@astrojs/lit](packages/integrations/lit) | [![astro version](https://img.shields.io/npm/v/@astrojs/lit.svg?label=%20)](packages/integrations/lit/CHANGELOG.md) | -| [@astrojs/deno](packages/integrations/deno) | [![astro version](https://img.shields.io/npm/v/@astrojs/deno.svg?label=%20)](packages/integrations/deno/CHANGELOG.md) | -| [@astrojs/netlify](packages/integrations/netlify) | [![astro version](https://img.shields.io/npm/v/@astrojs/netlify.svg?label=%20)](packages/integrations/netlify/CHANGELOG.md) | -| [@astrojs/vercel](packages/integrations/vercel) | [![astro version](https://img.shields.io/npm/v/@astrojs/vercel.svg?label=%20)](packages/integrations/vercel/CHANGELOG.md) | -| [@astrojs/partytown](packages/integrations/partytown) | [![astro version](https://img.shields.io/npm/v/@astrojs/partytown.svg?label=%20)](packages/integrations/partytown/CHANGELOG.md) | -| [@astrojs/sitemap](packages/integrations/sitemap) | [![astro version](https://img.shields.io/npm/v/@astrojs/sitemap.svg?label=%20)](packages/integrations/sitemap/CHANGELOG.md) | -| [@astrojs/tailwind](packages/integrations/tailwind) | [![astro version](https://img.shields.io/npm/v/@astrojs/tailwind.svg?label=%20)](packages/integrations/tailwind/CHANGELOG.md) | -| [@astrojs/turbolinks](packages/integrations/turbolinks) | [![astro version](https://img.shields.io/npm/v/@astrojs/turbolinks.svg?label=%20)](packages/integrations/turbolinks/CHANGELOG.md) | +| Package | Release Notes | +| ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [astro](packages/astro) | [![astro version](https://img.shields.io/npm/v/astro.svg?label=%20)](packages/astro/CHANGELOG.md) | +| [create-astro](packages/create-astro) | [![create-astro version](https://img.shields.io/npm/v/create-astro.svg?label=%20)](packages/create-astro/CHANGELOG.md) | +| [@astrojs/react](packages/integrations/react) | [![@astrojs/react version](https://img.shields.io/npm/v/@astrojs/react.svg?label=%20)](packages/integrations/react/CHANGELOG.md) | +| [@astrojs/preact](packages/integrations/preact) | [![@astrojs/preact version](https://img.shields.io/npm/v/@astrojs/preact.svg?label=%20)](packages/integrations/preact/CHANGELOG.md) | +| [@astrojs/solid-js](packages/integrations/solid) | [![@astrojs/solid version](https://img.shields.io/npm/v/@astrojs/solid-js.svg?label=%20)](packages/integrations/solid/CHANGELOG.md) | +| [@astrojs/svelte](packages/integrations/svelte) | [![@astrojs/svelte version](https://img.shields.io/npm/v/@astrojs/svelte.svg?label=%20)](packages/integrations/svelte/CHANGELOG.md) | +| [@astrojs/vue](packages/integrations/vue) | [![@astrojs/vue version](https://img.shields.io/npm/v/@astrojs/vue.svg?label=%20)](packages/integrations/vue/CHANGELOG.md) | +| [@astrojs/lit](packages/integrations/lit) | [![@astrojs/lit version](https://img.shields.io/npm/v/@astrojs/lit.svg?label=%20)](packages/integrations/lit/CHANGELOG.md) | +| [@astrojs/node](packages/integrations/node) | [![@astrojs/node version](https://img.shields.io/npm/v/@astrojs/node.svg?label=%20)](packages/integrations/node/CHANGELOG.md) | +| [@astrojs/vercel](packages/integrations/vercel) | [![@astrojs/vercel version](https://img.shields.io/npm/v/@astrojs/vercel.svg?label=%20)](packages/integrations/vercel/CHANGELOG.md) | +| [@astrojs/cloudflare](https://github.com/withastro/adapters/blob/main/packages/cloudflare) | [![@astrojs/cloudflare version](https://img.shields.io/npm/v/@astrojs/cloudflare.svg?label=%20)](https://github.com/withastro/adapters/blob/main/packages/cloudflare/CHANGELOG.md) | +| [@astrojs/partytown](packages/integrations/partytown) | [![@astrojs/partytown version](https://img.shields.io/npm/v/@astrojs/partytown.svg?label=%20)](packages/integrations/partytown/CHANGELOG.md) | +| [@astrojs/sitemap](packages/integrations/sitemap) | [![@astrojs/sitemap version](https://img.shields.io/npm/v/@astrojs/sitemap.svg?label=%20)](packages/integrations/sitemap/CHANGELOG.md) | +| [@astrojs/tailwind](packages/integrations/tailwind) | [![@astrojs/tailwind version](https://img.shields.io/npm/v/@astrojs/tailwind.svg?label=%20)](packages/integrations/tailwind/CHANGELOG.md) | +| [@astrojs/alpinejs](packages/integrations/alpinejs) | [![@astrojs/alpinejs version](https://img.shields.io/npm/v/@astrojs/alpinejs.svg?label=%20)](packages/integrations/alpinejs/CHANGELOG.md) | +| [@astrojs/mdx](packages/integrations/mdx) | [![@astrojs/mdx version](https://img.shields.io/npm/v/@astrojs/mdx.svg?label=%20)](packages/integrations/mdx/CHANGELOG.md) | +| [@astrojs/db](packages/db) | [![@astrojs/db version](https://img.shields.io/npm/v/@astrojs/db.svg?label=%20)](packages/db/CHANGELOG.md) | +| [@astrojs/rss](packages/astro-rss) | [![@astrojs/rss version](https://img.shields.io/npm/v/@astrojs/rss.svg?label=%20)](packages/astro-rss/CHANGELOG.md) | +| [@astrojs/netlify](https://github.com/withastro/adapters/blob/main/packages/netlify) | [![@astrojs/netlify version](https://img.shields.io/npm/v/@astrojs/netlify.svg?label=%20)](https://github.com/withastro/adapters/blob/main/packages/netlify/CHANGELOG.md) | + +[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6178/badge)](https://bestpractices.coreinfrastructure.org/projects/6178) Several official projects are maintained outside of this repo: | Project | Repository | | ------------------------------------------------------------------- | ----------------------------------------------------------------------- | -| [@astrojs/compiler](packages/integrations/compiler) | [withastro/compiler](https://github.com/withastro/compiler) | +| [@astrojs/compiler](https://github.com/withastro/compiler) | [withastro/compiler](https://github.com/withastro/compiler) | | [Astro Language Tools](https://github.com/withastro/language-tools) | [withastro/language-tools](https://github.com/withastro/language-tools) | - ## Links - [License (MIT)](LICENSE) -- [Code of Conduct](CODE_OF_CONDUCT.md) -- [Open Governance & Voting](GOVERNANCE.md) -- [Project Funding](FUNDING.md) +- [Code of Conduct](https://github.com/withastro/.github/blob/main/CODE_OF_CONDUCT.md) +- [Open Governance & Voting](https://github.com/withastro/.github/blob/main/GOVERNANCE.md) +- [Project Funding](https://github.com/withastro/.github/blob/main/FUNDING.md) - [Website](https://astro.build/) ## Sponsors -Astro is generously supported by Netlify, Vercel, and several other amazing organizations. - -[❤️ Sponsor Astro! ❤️](FUNDING.md) - -### Platinum Sponsors - - - - - - - - -
NetlifyNetlify - VercelVercel -
- -### Gold Sponsors - - - - - - - - -
- - ‹div›RIOTS - - - ‹div›RIOTS - - - - StackUp Digital - - - StackUp Digital - -
- -### Sponsors - - - - - - - -
SentryQoddi App Platform
+Astro is free, open source software made possible by these wonderful sponsors. + +[❤️ Sponsor Astro! ❤️](https://github.com/withastro/.github/blob/main/FUNDING.md) + +

+ + +[![Astro's sponsors.](https://astro.build/sponsors.png "Astro's sponsors. +Platinum sponsors: Vercel, storyblok, Netlify, Ship Shape, Google Chrome +Gold sponsors: ‹div›RIOTS, DEEPGRAM, Transloadit, CloudCannon +Sponsors: Monogram, Qoddi, Dimension")](https://github.com/sponsors/withastro) + + +

diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000000..b49a60c1ad2e --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,25 @@ +# Astro Security + +## Reporting a Vulnerability + +To report a security issue, please [open a security advisory](https://github.com/withastro/astro/security/advisories/new) on GitHub with a detailed description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. + +Please remember to include everything required for us to reproduce the issue, including but not limited to a publicly accessible git repository and/or StackBlitz repository. All code samples shared with our Security team will only be used to verify and diagnose the issue and will not be publicly shared with anyone outside of Astro's teams. Astro's Security Team members may share information only within the Astro teams on a need-to-know basis to fix the related issue in Astro. + +Our Security team will respond to the security advisory within 3 working days. + +**If you think you've found a security issue, please DO NOT report, discuss, or describe it on Discord, GitHub, or any other public forum; without prior contact and acknowledgment of Astro's Security team.** + +This project follows a 90 day disclosure timeline. + +**_This is detrimental to the safety of all Astro users. No exceptions._** + +## Embargo Policy + +The information members and others receive through participation in this group must not be made public, shared, or even hinted otherwise, except with prior explicit approval (which shall be handled on a case-by-case basis). This holds true until the agreed-upon public disclosure date/time is satisfied. + +As a clarifying example, this policy forbids Astro Security members from sharing list information with their employers; unless prior arrangements have been made directly with an employer. + +In the unfortunate event that you share the information beyond what is allowed by this policy, you must urgently inform the Astro Security Team of exactly what information leaked and to whom, as well as the steps that will be taken to prevent future leaks. + +**Repeated offenses may lead to the removal from the Security or Astro team.** diff --git a/SECURITY_CONTACTS b/SECURITY_CONTACTS new file mode 100644 index 000000000000..ccc68f7f0e60 --- /dev/null +++ b/SECURITY_CONTACTS @@ -0,0 +1,16 @@ +# Defined below are the security contacts for this repo. +# +# They are the contact point for triaging and handling of incoming +# Security issues. +# +# The below names agree to abide by the +# [Embargo Policy](https://github.com/withastro/astro/blob/master/SECURITY.md) +# and will be removed and replaced if they violate that agreement. +# +# DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE +# INSTRUCTIONS AT https://github.com/withastro/astro/blob/master/SECURITY.md + +Fred K. Schott (@fks) +Matthew Phillips (@matthewp) +Nate Moore (@natemoo-re) + diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md index 52501fa38327..0c7239cfc127 100644 --- a/STYLE_GUIDE.md +++ b/STYLE_GUIDE.md @@ -16,8 +16,8 @@ Anything enforced by linting and formatting is considered a **style rule.** It i These style rules are maintained in configuration files, and therefore not documented in this document. Read any of the following configuration files to learn more about the style rules that we strictly enforced across the codebase: -- [ESLint](https://github.com/withastro/astro/blob/main/.eslintrc.cjs) (Linting) -- [Prettier](https://github.com/withastro/astro/blob/main/.prettierrc.json) (Formatting) +- [ESLint](https://github.com/withastro/astro/blob/main/eslint.config.js) (Linting) +- [Prettier](https://github.com/withastro/astro/blob/main/prettier.config.js) (Formatting) Alternatively, don't worry too much about style rules and trust that our tools will catch these issues for you and offer inline suggestions as you work. diff --git a/assets/brand/file-icon.svg b/assets/brand/file-icon.svg deleted file mode 100644 index a9e08b2a3437..000000000000 --- a/assets/brand/file-icon.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/assets/brand/icon-32.svg b/assets/brand/icon-32.svg deleted file mode 100644 index 59bec2a8fbf0..000000000000 --- a/assets/brand/icon-32.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/assets/brand/logo-square-black.png b/assets/brand/logo-square-black.png deleted file mode 100644 index 64ada36c6f1d..000000000000 Binary files a/assets/brand/logo-square-black.png and /dev/null differ diff --git a/assets/brand/logo-square-white.png b/assets/brand/logo-square-white.png deleted file mode 100644 index 5db4ddfc1c1c..000000000000 Binary files a/assets/brand/logo-square-white.png and /dev/null differ diff --git a/assets/brand/logo-white.svg b/assets/brand/logo-white.svg deleted file mode 100644 index 19da1cee11b6..000000000000 --- a/assets/brand/logo-white.svg +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/assets/brand/logo.svg b/assets/brand/logo.svg deleted file mode 100644 index a1388d9317f3..000000000000 --- a/assets/brand/logo.svg +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/assets/social/avatar.png b/assets/social/avatar.png deleted file mode 100644 index 6992dde91cbb..000000000000 Binary files a/assets/social/avatar.png and /dev/null differ diff --git a/assets/social/banner-minimal.png b/assets/social/banner-minimal.png deleted file mode 100644 index afca6967f18f..000000000000 Binary files a/assets/social/banner-minimal.png and /dev/null differ diff --git a/assets/social/banner.svg b/assets/social/banner.svg deleted file mode 100644 index 5e4b2a4b0b21..000000000000 --- a/assets/social/banner.svg +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 000000000000..79d63f4da26c --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,5 @@ +# benchmark + +Astro's main benchmark suite. It exposes the `astro-benchmark` CLI command. Run `astro-benchmark --help` to see all available commands! + +If you'd like to understand how the benchmark works, check out the other READMEs in the subfolders. diff --git a/benchmark/bench/README.md b/benchmark/bench/README.md new file mode 100644 index 000000000000..9d3312880bb0 --- /dev/null +++ b/benchmark/bench/README.md @@ -0,0 +1,7 @@ +# bench + +This `bench` folder contains different benchmarking files that you can run via `astro-benchmark `, e.g. `astro-benchmark memory`. Files that start with an underscore are not benchmarking files. + +Benchmarking files will run against a project to measure its performance, and write the results down as JSON in the `results` folder. The `results` folder is gitignored and its result files can be safely deleted if you're not using them. + +You can duplicate `_template.js` to start a new benchmark test. All shared utilities are kept in `_util.js`. diff --git a/benchmark/bench/_template.js b/benchmark/bench/_template.js new file mode 100644 index 000000000000..ae96d72ad522 --- /dev/null +++ b/benchmark/bench/_template.js @@ -0,0 +1,12 @@ +/** Default project to run for this benchmark if not specified */ +export const defaultProject = 'project-name'; + +/** + * Run benchmark on `projectDir` and write results to `outputFile`. + * Use `console.log` to report the results too. Logs that start with 10 `=` + * and end with 10 `=` will be extracted by CI to display in the PR comment. + * Usually after the first 10 `=` you'll want to add a title like `#### Test`. + * @param {URL} _projectDir + * @param {URL} _outputFile + */ +export async function run(_projectDir, _outputFile) {} diff --git a/benchmark/bench/_util.js b/benchmark/bench/_util.js new file mode 100644 index 000000000000..d9dfe5b19076 --- /dev/null +++ b/benchmark/bench/_util.js @@ -0,0 +1,32 @@ +import { createRequire } from 'node:module'; +import path from 'node:path'; + +const astroPkgPath = createRequire(import.meta.url).resolve('astro/package.json'); + +export const astroBin = path.resolve(astroPkgPath, '../astro.js'); + +/** @typedef {{ avg: number, stdev: number, max: number }} Stat */ + +/** + * @param {number[]} numbers + * @returns {Stat} + */ +export function calculateStat(numbers) { + const avg = numbers.reduce((a, b) => a + b, 0) / numbers.length; + const stdev = Math.sqrt( + numbers.map((x) => Math.pow(x - avg, 2)).reduce((a, b) => a + b, 0) / numbers.length, + ); + const max = Math.max(...numbers); + return { avg, stdev, max }; +} + +export async function makeProject(name) { + console.log('Making project:', name); + const projectDir = new URL(`../projects/${name}/`, import.meta.url); + + const makeProjectMod = await import(`../make-project/${name}.js`); + await makeProjectMod.run(projectDir); + + console.log('Finished making project:', name); + return projectDir; +} diff --git a/benchmark/bench/cli-startup.js b/benchmark/bench/cli-startup.js new file mode 100644 index 000000000000..9144797d7547 --- /dev/null +++ b/benchmark/bench/cli-startup.js @@ -0,0 +1,73 @@ +import { fileURLToPath } from 'node:url'; +import { markdownTable } from 'markdown-table'; +import { exec } from 'tinyexec'; +import { astroBin, calculateStat } from './_util.js'; + +/** Default project to run for this benchmark if not specified */ +export const defaultProject = 'render-default'; + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + const root = fileURLToPath(projectDir); + + console.log('Benchmarking `astro --help`...'); + const helpStat = await benchmarkCommand('node', [astroBin, '--help'], root); + console.log('Done'); + + console.log('Benchmarking `astro preferences list`...'); + const infoStat = await benchmarkCommand('node', [astroBin, 'preferences', 'list'], root); + console.log('Done'); + + console.log('Result preview:'); + console.log('='.repeat(10)); + console.log(`#### CLI Startup\n\n`); + console.log( + printResult({ + 'astro --help': helpStat, + 'astro info': infoStat, + }), + ); + console.log('='.repeat(10)); +} + +/** + * @param {string} command + * @param {string[]} args + * @param {string} root + * @returns {Promise} + */ +async function benchmarkCommand(command, args, root) { + /** @type {number[]} */ + const durations = []; + + for (let i = 0; i < 10; i++) { + const start = performance.now(); + await exec(command, args, { nodeOptions: { cwd: root }, throwOnError: true }); + durations.push(performance.now() - start); + } + + // From the 10 durations, calculate average, standard deviation, and max value + return calculateStat(durations); +} + +/** + * @param {Record} result + */ +function printResult(result) { + return markdownTable( + [ + ['Command', 'Avg (ms)', 'Stdev (ms)', 'Max (ms)'], + ...Object.entries(result).map(([command, { avg, stdev, max }]) => [ + command, + avg.toFixed(2), + stdev.toFixed(2), + max.toFixed(2), + ]), + ], + { + align: ['l', 'r', 'r', 'r'], + }, + ); +} diff --git a/benchmark/bench/codspeed.bench.js b/benchmark/bench/codspeed.bench.js new file mode 100644 index 000000000000..4073ebed856a --- /dev/null +++ b/benchmark/bench/codspeed.bench.js @@ -0,0 +1,48 @@ +import { fileURLToPath } from 'node:url'; +import { exec } from 'tinyexec'; +import { beforeAll, bench, describe } from 'vitest'; +import { astroBin, makeProject } from './_util.js'; +let streamingApp; +let nonStreamingApp; +beforeAll(async () => { + const render = await makeProject('render-bench'); + const root = fileURLToPath(render); + await exec(astroBin, ['build'], { + nodeOptions: { + cwd: root, + stdio: 'inherit', + }, + }); + const entry = new URL('./dist/server/entry.mjs', `file://${root}`); + const { manifest, createApp } = await import(entry); + streamingApp = createApp(manifest, true); + nonStreamingApp = createApp(manifest, false); +}, 900000); + +describe('Bench rendering', () => { + bench('Rendering: streaming [true], .astro file', async () => { + const request = new Request(new URL('http://exmpale.com/astro')); + await streamingApp.render(request); + }); + bench('Rendering: streaming [true], .md file', async () => { + const request = new Request(new URL('http://exmpale.com/md')); + await streamingApp.render(request); + }); + bench('Rendering: streaming [true], .mdx file', async () => { + const request = new Request(new URL('http://exmpale.com/mdx')); + await streamingApp.render(request); + }); + + bench('Rendering: streaming [false], .astro file', async () => { + const request = new Request(new URL('http://exmpale.com/astro')); + await nonStreamingApp.render(request); + }); + bench('Rendering: streaming [false], .md file', async () => { + const request = new Request(new URL('http://exmpale.com/md')); + await nonStreamingApp.render(request); + }); + bench('Rendering: streaming [false], .mdx file', async () => { + const request = new Request(new URL('http://exmpale.com/mdx')); + await nonStreamingApp.render(request); + }); +}); diff --git a/benchmark/bench/memory.js b/benchmark/bench/memory.js new file mode 100644 index 000000000000..4f9153cc0c67 --- /dev/null +++ b/benchmark/bench/memory.js @@ -0,0 +1,61 @@ +import fs from 'node:fs/promises'; +import { fileURLToPath } from 'node:url'; +import { markdownTable } from 'markdown-table'; +import { exec } from 'tinyexec'; +import { astroBin } from './_util.js'; + +/** @typedef {Record} AstroTimerStat */ + +/** Default project to run for this benchmark if not specified */ +export const defaultProject = 'memory-default'; + +/** + * @param {URL} projectDir + * @param {URL} outputFile + */ +export async function run(projectDir, outputFile) { + const root = fileURLToPath(projectDir); + const outputFilePath = fileURLToPath(outputFile); + + console.log('Building and benchmarking...'); + await exec('node', ['--expose-gc', '--max_old_space_size=10000', astroBin, 'build'], { + nodeOptions: { + cwd: root, + stdio: 'inherit', + env: { + ASTRO_TIMER_PATH: outputFilePath, + }, + }, + throwOnError: true, + }); + + console.log('Raw results written to', outputFilePath); + + console.log('Result preview:'); + console.log('='.repeat(10)); + console.log(`#### Memory\n\n`); + console.log(printResult(JSON.parse(await fs.readFile(outputFilePath, 'utf-8')))); + console.log('='.repeat(10)); + + console.log('Done!'); +} + +/** + * @param {AstroTimerStat} output + */ +function printResult(output) { + return markdownTable( + [ + ['', 'Elapsed time (s)', 'Memory used (MB)', 'Final memory (MB)'], + ...Object.entries(output).map(([name, stat]) => [ + name, + (stat.elapsedTime / 1000).toFixed(2), + (stat.heapUsedChange / 1024 / 1024).toFixed(2), + (stat.heapUsedTotal / 1024 / 1024).toFixed(2), + ]), + ], + { + align: ['l', 'r', 'r', 'r'], + }, + ); +} diff --git a/benchmark/bench/render.js b/benchmark/bench/render.js new file mode 100644 index 000000000000..02f75a73b270 --- /dev/null +++ b/benchmark/bench/render.js @@ -0,0 +1,121 @@ +import fs from 'node:fs/promises'; +import http from 'node:http'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { markdownTable } from 'markdown-table'; +import { waitUntilBusy } from 'port-authority'; +import { exec } from 'tinyexec'; +import { renderPages } from '../make-project/render-default.js'; +import { astroBin, calculateStat } from './_util.js'; + +const port = 4322; + +export const defaultProject = 'render-default'; + +/** + * @param {URL} projectDir + * @param {URL} outputFile + */ +export async function run(projectDir, outputFile) { + const root = fileURLToPath(projectDir); + + console.log('Building...'); + await exec(astroBin, ['build'], { + nodeOptions: { + cwd: root, + stdio: 'inherit', + }, + throwOnError: true, + }); + + console.log('Previewing...'); + const previewProcess = exec(astroBin, ['preview', '--port', port], { + nodeOptions: { + cwd: root, + stdio: 'inherit', + }, + throwOnError: true, + }); + + console.log('Waiting for server ready...'); + await waitUntilBusy(port, { timeout: 5000 }); + + console.log('Running benchmark...'); + const result = await benchmarkRenderTime(); + + console.log('Killing server...'); + if (!previewProcess.kill('SIGTERM')) { + console.warn('Failed to kill server process id:', previewProcess.pid); + } + + console.log('Writing results to', fileURLToPath(outputFile)); + await fs.writeFile(outputFile, JSON.stringify(result, null, 2)); + + console.log('Result preview:'); + console.log('='.repeat(10)); + console.log(`#### Render\n\n`); + console.log(printResult(result)); + console.log('='.repeat(10)); + + console.log('Done!'); +} + +export async function benchmarkRenderTime(portToListen = port) { + /** @type {Record} */ + const result = {}; + for (const fileName of renderPages) { + // Render each file 100 times and push to an array + for (let i = 0; i < 100; i++) { + const pathname = '/' + fileName.slice(0, -path.extname(fileName).length); + const renderTime = await fetchRenderTime(`http://localhost:${portToListen}${pathname}`); + if (!result[pathname]) result[pathname] = []; + result[pathname].push(renderTime); + } + } + /** @type {Record} */ + const processedResult = {}; + for (const [pathname, times] of Object.entries(result)) { + // From the 100 results, calculate average, standard deviation, and max value + processedResult[pathname] = calculateStat(times); + } + return processedResult; +} + +/** + * @param {Record} result + */ +function printResult(result) { + return markdownTable( + [ + ['Page', 'Avg (ms)', 'Stdev (ms)', 'Max (ms)'], + ...Object.entries(result).map(([pathname, { avg, stdev, max }]) => [ + pathname, + avg.toFixed(2), + stdev.toFixed(2), + max.toFixed(2), + ]), + ], + { + align: ['l', 'r', 'r', 'r'], + }, + ); +} + +/** + * Simple fetch utility to get the render time sent by `@benchmark/timer` in plain text + * @param {string} url + * @returns {Promise} + */ +function fetchRenderTime(url) { + return new Promise((resolve, reject) => { + const req = http.request(url, (res) => { + res.setEncoding('utf8'); + let data = ''; + res.on('data', (chunk) => (data += chunk)); + res.on('error', (e) => reject(e)); + res.on('end', () => resolve(+data)); + }); + req.on('error', (e) => reject(e)); + req.end(); + }); +} diff --git a/benchmark/bench/server-stress.js b/benchmark/bench/server-stress.js new file mode 100644 index 000000000000..5bcaa6963438 --- /dev/null +++ b/benchmark/bench/server-stress.js @@ -0,0 +1,115 @@ +import fs from 'node:fs/promises'; +import { fileURLToPath } from 'node:url'; +import autocannon from 'autocannon'; +import { markdownTable } from 'markdown-table'; +import { waitUntilBusy } from 'port-authority'; +import pb from 'pretty-bytes'; +import { exec } from 'tinyexec'; +import { astroBin } from './_util.js'; + +const port = 4321; + +export const defaultProject = 'server-stress-default'; + +/** + * @param {URL} projectDir + * @param {URL} outputFile + */ +export async function run(projectDir, outputFile) { + const root = fileURLToPath(projectDir); + + console.log('Building...'); + await exec(astroBin, ['build'], { + nodeOptions: { + cwd: root, + stdio: 'inherit', + }, + throwOnError: true, + }); + + console.log('Previewing...'); + const previewProcess = await exec(astroBin, ['preview', '--port', port], { + nodeOptions: { + cwd: root, + stdio: 'inherit', + }, + }); + + console.log('Waiting for server ready...'); + await waitUntilBusy(port, { timeout: 5000 }); + + console.log('Running benchmark...'); + const result = await benchmarkCannon(); + + console.log('Killing server...'); + if (!previewProcess.kill('SIGTERM')) { + console.warn('Failed to kill server process id:', previewProcess.pid); + } + + console.log('Writing results to', fileURLToPath(outputFile)); + await fs.writeFile(outputFile, JSON.stringify(result, null, 2)); + + console.log('Result preview:'); + console.log('='.repeat(10)); + console.log(`#### Server stress\n\n`); + console.log(printResult(result)); + console.log('='.repeat(10)); + + console.log('Done!'); +} + +/** + * @returns {Promise} + */ +export async function benchmarkCannon() { + return new Promise((resolve, reject) => { + const instance = autocannon( + { + url: `http://localhost:${port}`, + connections: 100, + duration: 30, + pipelining: 10, + }, + (err, result) => { + if (err) { + reject(err); + } else { + // @ts-expect-error untyped but documented + instance.stop(); + resolve(result); + } + }, + ); + autocannon.track(instance, { renderResultsTable: false }); + }); +} + +/** + * @param {import('autocannon').Result} output + */ +function printResult(output) { + const { latency: l, requests: r, throughput: t } = output; + + const latencyTable = markdownTable( + [ + ['', 'Avg', 'Stdev', 'Max'], + ['Latency', `${l.average} ms`, `${l.stddev} ms`, `${l.max} ms`], + ], + { + align: ['l', 'r', 'r', 'r'], + }, + ); + + const reqAndBytesTable = markdownTable( + [ + ['', 'Avg', 'Stdev', 'Min', 'Total in 30s'], + ['Req/Sec', r.average, r.stddev, r.min, `${(r.total / 1000).toFixed(1)}k requests`], + ['Bytes/Sec', pb(t.average), pb(t.stddev), pb(t.min), `${pb(t.total)} read`], + ], + { + align: ['l', 'r', 'r', 'r', 'r'], + }, + ); + + return `${latencyTable}\n\n${reqAndBytesTable}`; +} diff --git a/benchmark/ci-helper.js b/benchmark/ci-helper.js new file mode 100644 index 000000000000..2dbdf5acf195 --- /dev/null +++ b/benchmark/ci-helper.js @@ -0,0 +1,13 @@ +// This script helps extract the benchmark logs that are between the `==========` lines. +// They are a convention defined in the `./bench/_template.js` file, which are used to log +// out with the `!bench` command. See `/.github/workflows/benchmark.yml` to see how it's used. +const benchLogs = process.argv[2]; +const resultRegex = /==========(.*?)==========/gs; + +let processedLog = ''; +let m; +while ((m = resultRegex.exec(benchLogs))) { + processedLog += m[1] + '\n'; +} + +console.log(processedLog); diff --git a/benchmark/index.js b/benchmark/index.js new file mode 100755 index 000000000000..0c62036d98d3 --- /dev/null +++ b/benchmark/index.js @@ -0,0 +1,72 @@ +import fs from 'node:fs/promises'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import mri from 'mri'; +import { makeProject } from './bench/_util.js'; + +const args = mri(process.argv.slice(2)); + +if (args.help || args.h) { + console.log(`\ +astro-benchmark [options] + +Command + [empty] Run all benchmarks + memory Run build memory and speed test + render Run rendering speed test + server-stress Run server stress test + cli-startup Run CLI startup speed test + +Options + --project Project to use for benchmark, see benchmark/make-project/ for available names + --output Output file to write results to +`); + process.exit(0); +} + +const commandName = args._[0]; +const benchmarks = { + memory: () => import('./bench/memory.js'), + render: () => import('./bench/render.js'), + 'server-stress': () => import('./bench/server-stress.js'), + 'cli-startup': () => import('./bench/cli-startup.js'), +}; + +if (commandName && !(commandName in benchmarks)) { + console.error(`Invalid benchmark name: ${commandName}`); + process.exit(1); +} + +if (commandName) { + // Run single benchmark + const bench = benchmarks[commandName]; + const benchMod = await bench(); + const projectDir = await makeProject(args.project || benchMod.defaultProject); + const outputFile = await getOutputFile(commandName); + await benchMod.run(projectDir, outputFile); +} else { + // Run all benchmarks + for (const name in benchmarks) { + const bench = benchmarks[name]; + const benchMod = await bench(); + const projectDir = await makeProject(args.project || benchMod.defaultProject); + const outputFile = await getOutputFile(name); + await benchMod.run(projectDir, outputFile); + } +} + +/** + * @param {string} benchmarkName + */ +export async function getOutputFile(benchmarkName) { + let file; + if (args.output) { + file = pathToFileURL(path.resolve(args.output)); + } else { + file = new URL(`./results/${benchmarkName}-bench-${Date.now()}.json`, import.meta.url); + } + + // Prepare output file directory + await fs.mkdir(new URL('./', file), { recursive: true }); + return file; +} diff --git a/benchmark/make-project/README.md b/benchmark/make-project/README.md new file mode 100644 index 000000000000..9d1a421c9b6e --- /dev/null +++ b/benchmark/make-project/README.md @@ -0,0 +1,7 @@ +# make-project + +This `make-project` folder contains different files to programmatically create a new Astro project. They are created inside the `projects` folder and are gitignored. These projects are used by benchmarks for testing. + +Each benchmark can specify the default project to run in its `defaultProject` export, but it can be overridden if `--project ` is passed through the CLI. + +You can duplicate `_template.js` to start a new project script. All shared utilities are kept in `_util.js`. diff --git a/benchmark/make-project/_template.js b/benchmark/make-project/_template.js new file mode 100644 index 000000000000..00ebdc4737b7 --- /dev/null +++ b/benchmark/make-project/_template.js @@ -0,0 +1,6 @@ +/** + * Create a new project in the `projectDir` directory. Make sure to clean up the + * previous artifacts here before generating files. + * @param {URL} projectDir + */ +export async function run(projectDir) {} diff --git a/benchmark/make-project/_util.js b/benchmark/make-project/_util.js new file mode 100644 index 000000000000..65c91dbf3f51 --- /dev/null +++ b/benchmark/make-project/_util.js @@ -0,0 +1,12 @@ +export const loremIpsum = + "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; + +export const loremIpsumHtml = loremIpsum + .replace(/Lorem/g, 'Lorem') + .replace(/Ipsum/g, 'Ipsum') + .replace(/dummy/g, 'dummy'); + +export const loremIpsumMd = loremIpsum + .replace(/Lorem/g, '**Lorem**') + .replace(/Ipsum/g, '_Ipsum_') + .replace(/dummy/g, '`dummy`'); diff --git a/benchmark/make-project/image.jpg b/benchmark/make-project/image.jpg new file mode 100644 index 000000000000..80b8ea67b8e4 Binary files /dev/null and b/benchmark/make-project/image.jpg differ diff --git a/benchmark/make-project/markdown-cc1.js b/benchmark/make-project/markdown-cc1.js new file mode 100644 index 000000000000..1e3aaa51779b --- /dev/null +++ b/benchmark/make-project/markdown-cc1.js @@ -0,0 +1,64 @@ +import fs from 'node:fs/promises'; +import { loremIpsumMd } from './_util.js'; + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + await fs.rm(projectDir, { recursive: true, force: true }); + await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/content/blog', projectDir), { recursive: true }); + await fs.copyFile( + new URL('./image.jpg', import.meta.url), + new URL('./src/image.jpg', projectDir), + ); + + const promises = []; + + for (let i = 0; i < 10000; i++) { + const content = `\ +# Article ${i} + +${loremIpsumMd} + +![image ${i}](../../image.jpg) + + +`; + promises.push( + fs.writeFile(new URL(`./src/content/blog/article-${i}.md`, projectDir), content, 'utf-8'), + ); + } + + await fs.writeFile( + new URL(`./src/pages/blog/[...slug].astro`, projectDir), + `\ +--- +import { getCollection } from 'astro:content'; +export async function getStaticPaths() { + const blogEntries = await getCollection('blog'); + return blogEntries.map(entry => ({ + params: { slug: entry.slug }, props: { entry }, + })); +} +const { entry } = Astro.props; +const { Content } = await entry.render(); +--- +

{entry.data.title}

+ +`, + 'utf-8', + ); + + await Promise.all(promises); + + await fs.writeFile( + new URL('./astro.config.js', projectDir), + `\ +import { defineConfig } from 'astro/config'; + +export default defineConfig({ +});`, + 'utf-8', + ); +} diff --git a/benchmark/make-project/markdown-cc2.js b/benchmark/make-project/markdown-cc2.js new file mode 100644 index 000000000000..ba60813c0d4a --- /dev/null +++ b/benchmark/make-project/markdown-cc2.js @@ -0,0 +1,76 @@ +import fs from 'node:fs/promises'; +import { loremIpsumMd } from './_util.js'; + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + await fs.rm(projectDir, { recursive: true, force: true }); + await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); + await fs.mkdir(new URL('./data/blog', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/content', projectDir), { recursive: true }); + await fs.copyFile(new URL('./image.jpg', import.meta.url), new URL('./image.jpg', projectDir)); + + const promises = []; + + for (let i = 0; i < 10000; i++) { + const content = `\ +# Article ${i} + +${loremIpsumMd} + +![image ${i}](../../image.jpg) + +`; + promises.push( + fs.writeFile(new URL(`./data/blog/article-${i}.md`, projectDir), content, 'utf-8'), + ); + } + + await fs.writeFile( + new URL(`./src/content/config.ts`, projectDir), + /*ts */ ` + import { defineCollection, z } from 'astro:content'; + import { glob } from 'astro/loaders'; + + const blog = defineCollection({ + loader: glob({ pattern: '*', base: './data/blog' }), + }); + + export const collections = { blog } + + `, + ); + + await fs.writeFile( + new URL(`./src/pages/blog/[...slug].astro`, projectDir), + `\ +--- +import { getCollection, render } from 'astro:content'; +export async function getStaticPaths() { + const blogEntries = await getCollection('blog'); + return blogEntries.map(entry => ({ + params: { slug: entry.id }, props: { entry }, + })); +} +const { entry } = Astro.props; +const { Content } = await render(entry); + +--- +

{entry.data.title}

+ +`, + 'utf-8', + ); + + await Promise.all(promises); + + await fs.writeFile( + new URL('./astro.config.js', projectDir), + `\ +import { defineConfig } from 'astro/config'; + +export default defineConfig({});`, + 'utf-8', + ); +} diff --git a/benchmark/make-project/mdx-cc1.js b/benchmark/make-project/mdx-cc1.js new file mode 100644 index 000000000000..a948ce194008 --- /dev/null +++ b/benchmark/make-project/mdx-cc1.js @@ -0,0 +1,67 @@ +import fs from 'node:fs/promises'; +import { loremIpsumMd } from './_util.js'; + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + await fs.rm(projectDir, { recursive: true, force: true }); + await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/content/blog', projectDir), { recursive: true }); + await fs.copyFile( + new URL('./image.jpg', import.meta.url), + new URL('./src/image.jpg', projectDir), + ); + + const promises = []; + + for (let i = 0; i < 10000; i++) { + const content = `\ +# Article ${i} + +${loremIpsumMd} + +![image ${i}](../../image.jpg) + + +`; + promises.push( + fs.writeFile(new URL(`./src/content/blog/article-${i}.mdx`, projectDir), content, 'utf-8'), + ); + } + + await fs.writeFile( + new URL(`./src/pages/blog/[...slug].astro`, projectDir), + `\ +--- +import { getCollection } from 'astro:content'; +export async function getStaticPaths() { + const blogEntries = await getCollection('blog'); + return blogEntries.map(entry => ({ + params: { slug: entry.slug }, props: { entry }, + })); +} +const { entry } = Astro.props; +const { Content } = await entry.render(); +--- +

{entry.data.title}

+ +`, + 'utf-8', + ); + + await Promise.all(promises); + + await fs.writeFile( + new URL('./astro.config.js', projectDir), + `\ +import { defineConfig } from 'astro/config'; + +import mdx from '@astrojs/mdx'; + +export default defineConfig({ + integrations: [mdx()], +});`, + 'utf-8', + ); +} diff --git a/benchmark/make-project/mdx-cc2.js b/benchmark/make-project/mdx-cc2.js new file mode 100644 index 000000000000..f50b63c9ee38 --- /dev/null +++ b/benchmark/make-project/mdx-cc2.js @@ -0,0 +1,80 @@ +import fs from 'node:fs/promises'; +import { loremIpsumMd } from './_util.js'; + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + await fs.rm(projectDir, { recursive: true, force: true }); + await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); + await fs.mkdir(new URL('./data/blog', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/content', projectDir), { recursive: true }); + await fs.copyFile(new URL('./image.jpg', import.meta.url), new URL('./image.jpg', projectDir)); + + const promises = []; + + for (let i = 0; i < 10000; i++) { + const content = `\ +# Article ${i} + +${loremIpsumMd} + +![image ${i}](../../image.jpg) + +`; + promises.push( + fs.writeFile(new URL(`./data/blog/article-${i}.mdx`, projectDir), content, 'utf-8'), + ); + } + + await fs.writeFile( + new URL(`./src/content/config.ts`, projectDir), + /*ts */ ` + import { defineCollection, z } from 'astro:content'; + import { glob } from 'astro/loaders'; + + const blog = defineCollection({ + loader: glob({ pattern: '*', base: './data/blog' }), + }); + + export const collections = { blog } + + `, + ); + + await fs.writeFile( + new URL(`./src/pages/blog/[...slug].astro`, projectDir), + `\ +--- +import { getCollection, render } from 'astro:content'; +export async function getStaticPaths() { + const blogEntries = await getCollection('blog'); + return blogEntries.map(entry => ({ + params: { slug: entry.id }, props: { entry }, + })); +} +const { entry } = Astro.props; +const { Content } = await render(entry); + +--- +

{entry.data.title}

+ +`, + 'utf-8', + ); + + await Promise.all(promises); + + await fs.writeFile( + new URL('./astro.config.js', projectDir), + `\ +import { defineConfig } from 'astro/config'; + +import mdx from '@astrojs/mdx'; + +export default defineConfig({ + integrations: [mdx()], +});`, + 'utf-8', + ); +} diff --git a/benchmark/make-project/memory-default.js b/benchmark/make-project/memory-default.js new file mode 100644 index 000000000000..1087c3d4aa84 --- /dev/null +++ b/benchmark/make-project/memory-default.js @@ -0,0 +1,82 @@ +import fs from 'node:fs/promises'; +import { loremIpsum } from './_util.js'; + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + await fs.rm(projectDir, { recursive: true, force: true }); + await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/content/blog', projectDir), { recursive: true }); + + const promises = []; + + for (let i = 0; i < 100; i++) { + const content = `\ +--- +const i = ${i}; +--- + +{i} +`; + promises.push( + fs.writeFile(new URL(`./src/pages/page-${i}.astro`, projectDir), content, 'utf-8'), + ); + } + + for (let i = 0; i < 100; i++) { + const content = `\ +# Article ${i} + +${loremIpsum} +`; + promises.push( + fs.writeFile(new URL(`./src/content/blog/article-${i}.md`, projectDir), content, 'utf-8'), + ); + } + + for (let i = 0; i < 100; i++) { + const content = `\ +# Post ${i} + +${loremIpsum} +`; + promises.push( + fs.writeFile(new URL(`./src/content/blog/post-${i}.mdx`, projectDir), content, 'utf-8'), + ); + } + + await fs.writeFile( + new URL(`./src/pages/blog/[...slug].astro`, projectDir), + `\ +--- +import { getCollection } from 'astro:content'; +export async function getStaticPaths() { + const blogEntries = await getCollection('blog'); + return blogEntries.map(entry => ({ + params: { slug: entry.slug }, props: { entry }, + })); +} +const { entry } = Astro.props; +const { Content } = await entry.render(); +--- +

{entry.data.title}

+ +`, + 'utf-8', + ); + + await Promise.all(promises); + + await fs.writeFile( + new URL('./astro.config.js', projectDir), + `\ +import { defineConfig } from 'astro/config'; +import mdx from '@astrojs/mdx'; + +export default defineConfig({ + integrations: [mdx()], +});`, + 'utf-8', + ); +} diff --git a/benchmark/make-project/render-bench.js b/benchmark/make-project/render-bench.js new file mode 100644 index 000000000000..e2964fbd232d --- /dev/null +++ b/benchmark/make-project/render-bench.js @@ -0,0 +1,132 @@ +import fs from 'node:fs/promises'; +import { loremIpsumHtml, loremIpsumMd } from './_util.js'; + +// Map of files to be generated and tested for rendering. +// Ideally each content should be similar for comparison. +const renderFiles = { + 'components/ListItem.astro': `\ +--- +const { className, item, attrs } = Astro.props; +const nested = item !== 0; +--- +
  • + + {item} + +
  • + `, + 'components/Sublist.astro': `\ +--- +import ListItem from '../components/ListItem.astro'; +const { items } = Astro.props; +const className = "text-red-500"; +const style = { color: "red" }; +--- +
      +{items.map((item) => ( + +))} +
    + `, + 'pages/astro.astro': `\ +--- +const className = "text-red-500"; +const style = { color: "red" }; +const items = Array.from({ length: 10000 }, (_, i) => ({i})); +--- + + + My Site + + +

    List

    + + ${Array.from({ length: 1000 }) + .map(() => `

    ${loremIpsumHtml}

    `) + .join('\n')} + +`, + 'pages/md.md': `\ +# List + +${Array.from({ length: 1000 }, (_, i) => i) + .map((v) => `- ${v}`) + .join('\n')} + +${Array.from({ length: 1000 }) + .map(() => loremIpsumMd) + .join('\n\n')} +`, + 'pages/mdx.mdx': `\ +export const className = "text-red-500"; +export const style = { color: "red" }; +export const items = Array.from({ length: 1000 }, (_, i) => i); + +# List + +
      + {items.map((item) => ( +
    • {item}
    • + ))} +
    + +${Array.from({ length: 1000 }) + .map(() => loremIpsumMd) + .join('\n\n')} +`, +}; + +export const renderPages = []; +for (const file of Object.keys(renderFiles)) { + if (file.startsWith('pages/')) { + renderPages.push(file.replace('pages/', '')); + } +} + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + await fs.rm(projectDir, { recursive: true, force: true }); + await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/components', projectDir), { recursive: true }); + + await Promise.all( + Object.entries(renderFiles).map(([name, content]) => { + return fs.writeFile(new URL(`./src/${name}`, projectDir), content, 'utf-8'); + }), + ); + + await fs.writeFile( + new URL('./astro.config.js', projectDir), + `\ +import { defineConfig } from 'astro/config'; +import adapter from '@benchmark/adapter'; +import mdx from '@astrojs/mdx'; + +export default defineConfig({ + integrations: [mdx()], + output: 'server', + adapter: adapter(), +});`, + 'utf-8', + ); +} diff --git a/benchmark/make-project/render-default.js b/benchmark/make-project/render-default.js new file mode 100644 index 000000000000..7ea54b936ed3 --- /dev/null +++ b/benchmark/make-project/render-default.js @@ -0,0 +1,132 @@ +import fs from 'node:fs/promises'; +import { loremIpsumHtml, loremIpsumMd } from './_util.js'; + +// Map of files to be generated and tested for rendering. +// Ideally each content should be similar for comparison. +const renderFiles = { + 'components/ListItem.astro': `\ +--- +const { className, item, attrs } = Astro.props; +const nested = item !== 0; +--- +
  • + + {item} + +
  • + `, + 'components/Sublist.astro': `\ +--- +import ListItem from '../components/ListItem.astro'; +const { items } = Astro.props; +const className = "text-red-500"; +const style = { color: "red" }; +--- +
      +{items.map((item) => ( + +))} +
    + `, + 'pages/astro.astro': `\ +--- +const className = "text-red-500"; +const style = { color: "red" }; +const items = Array.from({ length: 10000 }, (_, i) => ({i})); +--- + + + My Site + + +

    List

    + + ${Array.from({ length: 1000 }) + .map(() => `

    ${loremIpsumHtml}

    `) + .join('\n')} + +`, + 'pages/md.md': `\ +# List + +${Array.from({ length: 1000 }, (_, i) => i) + .map((v) => `- ${v}`) + .join('\n')} + +${Array.from({ length: 1000 }) + .map(() => loremIpsumMd) + .join('\n\n')} +`, + 'pages/mdx.mdx': `\ +export const className = "text-red-500"; +export const style = { color: "red" }; +export const items = Array.from({ length: 1000 }, (_, i) => i); + +# List + +
      + {items.map((item) => ( +
    • {item}
    • + ))} +
    + +${Array.from({ length: 1000 }) + .map(() => loremIpsumMd) + .join('\n\n')} +`, +}; + +export const renderPages = []; +for (const file of Object.keys(renderFiles)) { + if (file.startsWith('pages/')) { + renderPages.push(file.replace('pages/', '')); + } +} + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + await fs.rm(projectDir, { recursive: true, force: true }); + await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/components', projectDir), { recursive: true }); + + await Promise.all( + Object.entries(renderFiles).map(([name, content]) => { + return fs.writeFile(new URL(`./src/${name}`, projectDir), content, 'utf-8'); + }), + ); + + await fs.writeFile( + new URL('./astro.config.js', projectDir), + `\ +import { defineConfig } from 'astro/config'; +import timer from '@benchmark/timer'; +import mdx from '@astrojs/mdx'; + +export default defineConfig({ + integrations: [mdx()], + output: 'server', + adapter: timer(), +});`, + 'utf-8', + ); +} diff --git a/benchmark/make-project/server-stress-default.js b/benchmark/make-project/server-stress-default.js new file mode 100644 index 000000000000..1724f8f82593 --- /dev/null +++ b/benchmark/make-project/server-stress-default.js @@ -0,0 +1,62 @@ +import fs from 'node:fs/promises'; +import { loremIpsum } from './_util.js'; + +/** + * @param {URL} projectDir + */ +export async function run(projectDir) { + await fs.rm(projectDir, { recursive: true, force: true }); + await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/components', projectDir), { recursive: true }); + + await fs.writeFile( + new URL('./src/pages/index.astro', projectDir), + `\ +--- +import Paragraph from '../components/Paragraph.astro' +const content = "${loremIpsum}" +--- + + + + + + + Astro + + +

    Astro

    +
    + ${Array.from({ length: 100 }) + .map(() => '

    {content}

    ') + .join('\n')} +
    +
    + ${Array.from({ length: 50 }) + .map((_, i) => '') + .join('\n')} +
    + +`, + 'utf-8', + ); + + await fs.writeFile( + new URL('./src/components/Paragraph.astro', projectDir), + `
    {Astro.props.num} {Astro.props.str}
    `, + 'utf-8', + ); + + await fs.writeFile( + new URL('./astro.config.js', projectDir), + `\ +import { defineConfig } from 'astro/config'; +import nodejs from '@astrojs/node'; + +export default defineConfig({ + output: 'server', + adapter: nodejs({ mode: 'standalone' }), +});`, + 'utf-8', + ); +} diff --git a/benchmark/package.json b/benchmark/package.json new file mode 100644 index 000000000000..708ee14d12dc --- /dev/null +++ b/benchmark/package.json @@ -0,0 +1,30 @@ +{ + "name": "astro-benchmark", + "private": true, + "type": "module", + "version": "0.0.0", + "bin": { + "astro-benchmark": "./index.js" + }, + "scripts": { + "bench": "pnpm vitest bench --run" + }, + "dependencies": { + "@astrojs/mdx": "workspace:*", + "@astrojs/node": "^8.3.4", + "@benchmark/timer": "workspace:*", + "@benchmark/adapter": "workspace:*", + "astro": "workspace:*", + "autocannon": "^7.15.0", + "markdown-table": "^3.0.4", + "mri": "^1.2.0", + "port-authority": "^2.0.1", + "pretty-bytes": "^6.1.1", + "sharp": "^0.33.3", + "tinyexec": "^0.3.1" + }, + "devDependencies": { + "@codspeed/vitest-plugin": "3.1.1", + "vitest": "2.1.8" + } +} diff --git a/benchmark/packages/adapter/README.md b/benchmark/packages/adapter/README.md new file mode 100644 index 000000000000..5b8e33ed4e59 --- /dev/null +++ b/benchmark/packages/adapter/README.md @@ -0,0 +1,3 @@ +# @benchmark/timer + +Like `@astrojs/node`, but returns the rendered time in milliseconds for the page instead of the page content itself. This is used for internal benchmarks only. diff --git a/benchmark/packages/adapter/package.json b/benchmark/packages/adapter/package.json new file mode 100644 index 000000000000..2bdb73ce9bd8 --- /dev/null +++ b/benchmark/packages/adapter/package.json @@ -0,0 +1,35 @@ +{ + "name": "@benchmark/adapter", + "description": "Bench adapter", + "private": true, + "version": "0.0.0", + "type": "module", + "types": "./dist/index.d.ts", + "author": "withastro", + "license": "MIT", + "keywords": [ + "withastro", + "astro-adapter" + ], + "exports": { + ".": "./dist/index.js", + "./server.js": "./dist/server.js", + "./package.json": "./package.json" + }, + "scripts": { + "build": "astro-scripts build \"src/**/*.ts\" && tsc", + "build:ci": "astro-scripts build \"src/**/*.ts\"", + "dev": "astro-scripts dev \"src/**/*.ts\"" + }, + "dependencies": { + "server-destroy": "^1.0.1" + }, + "peerDependencies": { + "astro": "workspace:*" + }, + "devDependencies": { + "@types/server-destroy": "^1.0.4", + "astro": "workspace:*", + "astro-scripts": "workspace:*" + } +} diff --git a/benchmark/packages/adapter/src/index.ts b/benchmark/packages/adapter/src/index.ts new file mode 100644 index 000000000000..0fc6d67f99c2 --- /dev/null +++ b/benchmark/packages/adapter/src/index.ts @@ -0,0 +1,32 @@ +import type { AstroIntegration } from 'astro'; + +export default function createIntegration(): AstroIntegration { + return { + name: '@benchmark/timer', + hooks: { + 'astro:config:setup': ({ updateConfig }) => { + updateConfig({ + vite: { + ssr: { + noExternal: ['@benchmark/timer'], + }, + }, + }); + }, + 'astro:config:done': ({ setAdapter }) => { + setAdapter({ + name: '@benchmark/adapter', + serverEntrypoint: '@benchmark/adapter/server.js', + exports: ['manifest', 'createApp'], + supportedAstroFeatures: { + serverOutput: 'stable', + envGetSecret: 'experimental', + staticOutput: 'stable', + hybridOutput: 'stable', + i18nDomains: 'stable', + }, + }); + }, + }, + }; +} diff --git a/benchmark/packages/adapter/src/server.ts b/benchmark/packages/adapter/src/server.ts new file mode 100644 index 000000000000..10e212adbedd --- /dev/null +++ b/benchmark/packages/adapter/src/server.ts @@ -0,0 +1,32 @@ +import * as fs from 'node:fs'; +import type { SSRManifest } from 'astro'; +import { App } from 'astro/app'; +import { applyPolyfills } from 'astro/app/node'; + +applyPolyfills(); + +class MyApp extends App { + #manifest: SSRManifest | undefined; + constructor(manifest: SSRManifest, streaming = false) { + super(manifest, streaming); + this.#manifest = manifest; + } + + async render(request: Request) { + const url = new URL(request.url); + if (this.#manifest?.assets.has(url.pathname)) { + const filePath = new URL('../../client/' + this.removeBase(url.pathname), import.meta.url); + const data = await fs.promises.readFile(filePath); + return new Response(data); + } + + return super.render(request); + } +} + +export function createExports(manifest: SSRManifest) { + return { + manifest, + createApp: (streaming: boolean) => new MyApp(manifest, streaming), + }; +} diff --git a/benchmark/packages/adapter/tsconfig.json b/benchmark/packages/adapter/tsconfig.json new file mode 100644 index 000000000000..1504b4b6dfa4 --- /dev/null +++ b/benchmark/packages/adapter/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../tsconfig.base.json", + "include": ["src"], + "compilerOptions": { + "outDir": "./dist" + } +} diff --git a/benchmark/packages/timer/README.md b/benchmark/packages/timer/README.md new file mode 100644 index 000000000000..5b8e33ed4e59 --- /dev/null +++ b/benchmark/packages/timer/README.md @@ -0,0 +1,3 @@ +# @benchmark/timer + +Like `@astrojs/node`, but returns the rendered time in milliseconds for the page instead of the page content itself. This is used for internal benchmarks only. diff --git a/benchmark/packages/timer/package.json b/benchmark/packages/timer/package.json new file mode 100644 index 000000000000..7e3e2065bc04 --- /dev/null +++ b/benchmark/packages/timer/package.json @@ -0,0 +1,36 @@ +{ + "name": "@benchmark/timer", + "description": "Preview server for benchmark", + "private": true, + "version": "0.0.0", + "type": "module", + "types": "./dist/index.d.ts", + "author": "withastro", + "license": "MIT", + "keywords": [ + "withastro", + "astro-adapter" + ], + "exports": { + ".": "./dist/index.js", + "./server.js": "./dist/server.js", + "./preview.js": "./dist/preview.js", + "./package.json": "./package.json" + }, + "scripts": { + "build": "astro-scripts build \"src/**/*.ts\" && tsc", + "build:ci": "astro-scripts build \"src/**/*.ts\"", + "dev": "astro-scripts dev \"src/**/*.ts\"" + }, + "dependencies": { + "server-destroy": "^1.0.1" + }, + "peerDependencies": { + "astro": "workspace:*" + }, + "devDependencies": { + "@types/server-destroy": "^1.0.4", + "astro": "workspace:*", + "astro-scripts": "workspace:*" + } +} diff --git a/benchmark/packages/timer/src/index.ts b/benchmark/packages/timer/src/index.ts new file mode 100644 index 000000000000..f83a61c36cb5 --- /dev/null +++ b/benchmark/packages/timer/src/index.ts @@ -0,0 +1,37 @@ +import type { AstroAdapter, AstroIntegration } from 'astro'; + +export function getAdapter(): AstroAdapter { + return { + name: '@benchmark/timer', + serverEntrypoint: '@benchmark/timer/server.js', + previewEntrypoint: '@benchmark/timer/preview.js', + exports: ['handler'], + supportedAstroFeatures: { + serverOutput: 'stable', + }, + }; +} + +export default function createIntegration(): AstroIntegration { + return { + name: '@benchmark/timer', + hooks: { + 'astro:config:setup': ({ updateConfig }) => { + updateConfig({ + vite: { + ssr: { + noExternal: ['@benchmark/timer'], + }, + }, + }); + }, + 'astro:config:done': ({ setAdapter, config }) => { + setAdapter(getAdapter()); + + if (config.output === 'static') { + console.warn(`[@benchmark/timer] \`output: "server"\` is required to use this adapter.`); + } + }, + }, + }; +} diff --git a/benchmark/packages/timer/src/preview.ts b/benchmark/packages/timer/src/preview.ts new file mode 100644 index 000000000000..9659a26beaa5 --- /dev/null +++ b/benchmark/packages/timer/src/preview.ts @@ -0,0 +1,36 @@ +import { createServer } from 'node:http'; +import type { CreatePreviewServer } from 'astro'; +import enableDestroy from 'server-destroy'; + +const preview: CreatePreviewServer = async function ({ serverEntrypoint, host, port }) { + const ssrModule = await import(serverEntrypoint.toString()); + const ssrHandler = ssrModule.handler; + const server = createServer(ssrHandler); + server.listen(port, host); + enableDestroy(server); + + // biome-ignore lint/suspicious/noConsoleLog: allowed + console.log(`Preview server listening on http://${host}:${port}`); + + // Resolves once the server is closed + const closed = new Promise((resolve, reject) => { + server.addListener('close', resolve); + server.addListener('error', reject); + }); + + return { + host, + port, + closed() { + return closed; + }, + server, + stop: async () => { + await new Promise((resolve, reject) => { + server.destroy((err) => (err ? reject(err) : resolve(undefined))); + }); + }, + }; +}; + +export { preview as default }; diff --git a/benchmark/packages/timer/src/server.ts b/benchmark/packages/timer/src/server.ts new file mode 100644 index 000000000000..9905a627b755 --- /dev/null +++ b/benchmark/packages/timer/src/server.ts @@ -0,0 +1,18 @@ +import type { IncomingMessage, ServerResponse } from 'node:http'; +import type { SSRManifest } from 'astro'; +import { NodeApp, applyPolyfills } from 'astro/app/node'; + +applyPolyfills(); + +export function createExports(manifest: SSRManifest) { + const app = new NodeApp(manifest); + return { + handler: async (req: IncomingMessage, res: ServerResponse) => { + const start = performance.now(); + await app.render(req); + const end = performance.now(); + res.write(end - start + ''); + res.end(); + }, + }; +} diff --git a/benchmark/packages/timer/tsconfig.json b/benchmark/packages/timer/tsconfig.json new file mode 100644 index 000000000000..1504b4b6dfa4 --- /dev/null +++ b/benchmark/packages/timer/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../tsconfig.base.json", + "include": ["src"], + "compilerOptions": { + "outDir": "./dist" + } +} diff --git a/benchmark/vitest.config.js b/benchmark/vitest.config.js new file mode 100644 index 000000000000..b8b6e5e52a28 --- /dev/null +++ b/benchmark/vitest.config.js @@ -0,0 +1,7 @@ +import codspeedPlugin from '@codspeed/vitest-plugin'; +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + plugins: process.env.CODSPEED ? [codspeedPlugin()] : [], + include: ['./bench/codspeed.bench.js'], +}); diff --git a/biome.jsonc b/biome.jsonc new file mode 100644 index 000000000000..a1000760a743 --- /dev/null +++ b/biome.jsonc @@ -0,0 +1,133 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.3/schema.json", + "files": { + "ignore": ["**/smoke/**", "**/fixtures/**", "**/_temp-fixtures/**", "**/vendor/**"], + "include": ["test/**", "e2e/**", "packages/**", "scripts/**", "benchmark"], + }, + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true, + }, + "formatter": { + "indentStyle": "tab", + "indentWidth": 2, + "lineWidth": 100, + "ignore": [".changeset", "pnpm-lock.yaml", "*.astro"], + }, + "organizeImports": { + "enabled": true, + }, + "linter": { + "enabled": true, + "rules": { + "recommended": false, + "style": { + "useNodejsImportProtocol": "error", + // Enforce separate type imports for type-only imports to avoid bundling unneeded code + "useImportType": "error", + }, + "suspicious": { + // This one is specific to catch `console.log`. The rest of logs are permitted + "noConsoleLog": "warn", + }, + "correctness": { + "noUnusedVariables": "info", + "noUnusedFunctionParameters": "info", + "noUnusedImports": "warn", + }, + }, + }, + "javascript": { + "formatter": { + "trailingCommas": "all", + "quoteStyle": "single", + "semicolons": "always", + }, + }, + "json": { + "parser": { + "allowComments": true, + "allowTrailingCommas": true, + }, + "formatter": { + "indentStyle": "space", + "trailingCommas": "none", + }, + }, + "overrides": [ + { + // Workaround to format files like npm does + "include": ["package.json"], + "json": { + "formatter": { + "lineWidth": 1, + }, + }, + }, + { + // We don"t want to have node modules in code that should be runtime agnostic + "include": ["packages/astro/src/runtime/**/*.ts"], + "linter": { + "rules": { + "correctness": { + "noNodejsModules": "error", + }, + }, + }, + }, + { + "include": ["*.test.js"], + "linter": { + "rules": { + "suspicious": { + "noFocusedTests": "error", + "noConsole": "off", + }, + }, + }, + }, + { + "include": ["*.astro", "client.d.ts", "jsx-runtime.d.ts"], + "linter": { + "rules": { + "correctness": { + "noUnusedVariables": "off", + "noUnusedImports": "off", + }, + }, + }, + }, + { + "include": ["packages/integrations/**/*.ts"], + "linter": { + "rules": { + "suspicious": { + "noConsole": { + "level": "error", + "options": { + "allow": ["warn", "error", "info", "debug"], + }, + }, + }, + }, + }, + }, + { + "include": [ + "packages/db/**/cli/**/*.ts", + "benchmark/**/*.js", + "packages/astro/src/cli/**/*.ts", + "packages/astro/astro.js", + ], + "linter": { + "rules": { + "suspicious": { + "noConsole": "off", + "noConsoleLog": "off", + }, + }, + }, + }, + ], +} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 000000000000..c5fbf3fbc37c --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,135 @@ +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import tseslint from 'typescript-eslint'; + +// plugins +import regexpEslint from 'eslint-plugin-regexp'; +const typescriptEslint = tseslint.plugin; + +// parsers +const typescriptParser = tseslint.parser; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +export default [ + // If ignores is used without any other keys in the configuration object, then the patterns act as global ignores. + // ref: https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores + { + ignores: [ + '**/.*', + '**/*.d.ts', + 'packages/**/*.min.js', + 'packages/**/dist/', + 'packages/**/fixtures/', + 'packages/astro/vendor/vite/', + 'benchmark/**/dist/', + 'examples/', + 'scripts/', + '.github/', + '.changeset/', + ], + }, + + ...tseslint.configs.recommendedTypeChecked, + ...tseslint.configs.stylisticTypeChecked, + regexpEslint.configs['flat/recommended'], + { + languageOptions: { + parser: typescriptParser, + parserOptions: { + project: ['./packages/*/tsconfig.json', './tsconfig.eslint.json'], + tsconfigRootDir: __dirname, + }, + }, + plugins: { + '@typescript-eslint': typescriptEslint, + regexp: regexpEslint, + }, + rules: { + // These off/configured-differently-by-default rules fit well for us + '@typescript-eslint/switch-exhaustiveness-check': 'error', + '@typescript-eslint/no-shadow': 'error', + 'no-console': 'off', + + // Todo: do we want these? + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/class-literal-property-style': 'off', + '@typescript-eslint/consistent-indexed-object-style': 'off', + '@typescript-eslint/consistent-type-definitions': 'off', + '@typescript-eslint/dot-notation': 'off', + '@typescript-eslint/no-base-to-string': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-floating-promises': 'off', + '@typescript-eslint/no-misused-promises': 'off', + '@typescript-eslint/no-redundant-type-constituents': 'off', + '@typescript-eslint/no-this-alias': 'off', + '@typescript-eslint/no-unsafe-argument': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unused-expressions': 'off', + '@typescript-eslint/only-throw-error': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/no-unnecessary-type-assertion': 'off', + '@typescript-eslint/prefer-nullish-coalescing': 'off', + '@typescript-eslint/prefer-optional-chain': 'off', + '@typescript-eslint/prefer-promise-reject-errors': 'off', + '@typescript-eslint/prefer-string-starts-ends-with': 'off', + '@typescript-eslint/require-await': 'off', + '@typescript-eslint/restrict-plus-operands': 'off', + '@typescript-eslint/restrict-template-expressions': 'off', + '@typescript-eslint/sort-type-constituents': 'off', + '@typescript-eslint/unbound-method': 'off', + '@typescript-eslint/no-explicit-any': 'off', + + // Used by Biome + '@typescript-eslint/consistent-type-imports': 'off', + // These rules enabled by the preset configs don't work well for us + '@typescript-eslint/await-thenable': 'off', + 'prefer-const': 'off', + + // In some cases, using explicit letter-casing is more performant than the `i` flag + 'regexp/use-ignore-case': 'off', + 'regexp/prefer-regexp-exec': 'warn', + 'regexp/prefer-regexp-test': 'warn', + }, + }, + { + files: ['packages/astro/src/runtime/client/**/*.ts'], + languageOptions: { + globals: { + browser: true, + }, + }, + }, + { + files: ['packages/astro/src/core/errors/errors-data.ts'], + rules: { + // This file is used for docs generation, as such the code need to be in a certain format, we can somewhat ensure this with these rules + 'object-shorthand': ['error', 'methods', { avoidExplicitReturnArrows: true }], + 'arrow-body-style': ['error', 'never'], + }, + }, + + { + files: ['packages/db/src/runtime/**/*.ts'], + rules: { + 'no-restricted-imports': 'off', + '@typescript-eslint/no-restricted-imports': [ + 'error', + { + patterns: [ + { + group: ['../core/*'], + allowTypeImports: true, + }, + ], + }, + ], + }, + }, +]; diff --git a/examples/README.md b/examples/README.md index e3e295b6d71c..1482084d42df 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,22 +1,21 @@ # Astro Examples Library - The easiest way to check out one of these examples on your machine is by running this command in an empty directory: -``` -npm init astro -- --template [EXAMPLE_NAME] +```sh +npm create astro@latest -- --template [EXAMPLE_NAME] ``` ## Community Examples -Visit [awesome-astro](https://github.com/one-aalam/awesome-astro) for a full list of community examples. You can use `npm init astro` to check out any community examples: +Visit [awesome-astro](https://github.com/one-aalam/awesome-astro) for a full list of community examples. You can use `npm create astro@latest` to check out any community examples: -``` -npm init astro -- --template [GITHUB_USER]/[REPO_NAME] +```sh +npm create astro@latest -- --template [GITHUB_USER]/[REPO_NAME] ``` Paths to examples nested inside of a repo are also supported: -``` -npm init astro -- --template [GITHUB_USER]/[REPO_NAME]/path/to/example +```sh +npm create astro@latest -- --template [GITHUB_USER]/[REPO_NAME]/path/to/example ``` diff --git a/examples/basics/.codesandbox/Dockerfile b/examples/basics/.codesandbox/Dockerfile new file mode 100644 index 000000000000..c3b5c81a121d --- /dev/null +++ b/examples/basics/.codesandbox/Dockerfile @@ -0,0 +1 @@ +FROM node:18-bullseye diff --git a/examples/basics/.gitignore b/examples/basics/.gitignore index 7329a851d0ac..016b59ea143d 100644 --- a/examples/basics/.gitignore +++ b/examples/basics/.gitignore @@ -1,6 +1,8 @@ # build output dist/ -.output/ + +# generated types +.astro/ # dependencies node_modules/ @@ -11,10 +13,12 @@ yarn-debug.log* yarn-error.log* pnpm-debug.log* - # environment variables .env .env.production # macOS-specific files .DS_Store + +# jetbrains setting folder +.idea/ diff --git a/examples/basics/.npmrc b/examples/basics/.npmrc deleted file mode 100644 index ef83021af3ec..000000000000 --- a/examples/basics/.npmrc +++ /dev/null @@ -1,2 +0,0 @@ -# Expose Astro dependencies for `pnpm` users -shamefully-hoist=true diff --git a/examples/basics/.stackblitzrc b/examples/basics/.stackblitzrc deleted file mode 100644 index 43798ecff844..000000000000 --- a/examples/basics/.stackblitzrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "startCommand": "npm start", - "env": { - "ENABLE_CJS_IMPORTS": true - } -} \ No newline at end of file diff --git a/examples/basics/README.md b/examples/basics/README.md index 15f6eb6931a7..ff19a3e7ece8 100644 --- a/examples/basics/README.md +++ b/examples/basics/README.md @@ -1,42 +1,48 @@ -# Welcome to [Astro](https://astro.build) +# Astro Starter Kit: Basics -[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/starter) +```sh +npm create astro@latest -- --template basics +``` + +[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics) +[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/basics) +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/basics/devcontainer.json) > 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun! +![just-the-basics](https://github.com/withastro/astro/assets/2244813/a0a5533c-a856-4198-8470-2d67b1d7c554) + ## 🚀 Project Structure Inside of your Astro project, you'll see the following folders and files: -``` +```text / ├── public/ -│ └── favicon.ico +│ └── favicon.svg ├── src/ -│ ├── components/ +│ ├── layouts/ │ │ └── Layout.astro │ └── pages/ │ └── index.astro └── package.json ``` -Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. - -There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components or layouts. - -Any static assets, like images, can be placed in the `public/` directory. +To learn more about the folder structure of an Astro project, refer to [our guide on project structure](https://docs.astro.build/en/basics/project-structure/). ## 🧞 Commands All commands are run from the root of the project, from a terminal: -| Command | Action | -| :---------------- | :------------------------------------------- | -| `npm install` | Installs dependencies | -| `npm run dev` | Starts local dev server at `localhost:3000` | -| `npm run build` | Build your production site to `./dist/` | -| `npm run preview` | Preview your build locally, before deploying | +| Command | Action | +| :------------------------ | :----------------------------------------------- | +| `npm install` | Installs dependencies | +| `npm run dev` | Starts local dev server at `localhost:4321` | +| `npm run build` | Build your production site to `./dist/` | +| `npm run preview` | Preview your build locally, before deploying | +| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | +| `npm run astro -- --help` | Get help using the Astro CLI | ## 👀 Want to learn more? -Feel free to check [our documentation](https://github.com/withastro/astro) or jump into our [Discord server](https://astro.build/chat). +Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat). diff --git a/examples/basics/astro.config.mjs b/examples/basics/astro.config.mjs index 882e6515a67e..e762ba5cf616 100644 --- a/examples/basics/astro.config.mjs +++ b/examples/basics/astro.config.mjs @@ -1,3 +1,4 @@ +// @ts-check import { defineConfig } from 'astro/config'; // https://astro.build/config diff --git a/examples/basics/package.json b/examples/basics/package.json index 0db3619f45cf..29f536a91776 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -1,14 +1,15 @@ { "name": "@example/basics", + "type": "module", "version": "0.0.1", "private": true, "scripts": { "dev": "astro dev", - "start": "astro dev", "build": "astro build", - "preview": "astro preview" + "preview": "astro preview", + "astro": "astro" }, - "devDependencies": { - "astro": "^1.0.0-beta.26" + "dependencies": { + "astro": "^5.1.1" } } diff --git a/examples/basics/public/favicon.svg b/examples/basics/public/favicon.svg new file mode 100644 index 000000000000..f157bd1c5e28 --- /dev/null +++ b/examples/basics/public/favicon.svg @@ -0,0 +1,9 @@ + + + + diff --git a/examples/basics/sandbox.config.json b/examples/basics/sandbox.config.json deleted file mode 100644 index 9178af77d7de..000000000000 --- a/examples/basics/sandbox.config.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "infiniteLoopProtection": true, - "hardReloadOnChange": false, - "view": "browser", - "template": "node", - "container": { - "port": 3000, - "startScript": "start", - "node": "14" - } -} diff --git a/examples/basics/src/assets/astro.svg b/examples/basics/src/assets/astro.svg new file mode 100644 index 000000000000..8cf8fb0c7da6 --- /dev/null +++ b/examples/basics/src/assets/astro.svg @@ -0,0 +1 @@ + diff --git a/examples/basics/src/assets/background.svg b/examples/basics/src/assets/background.svg new file mode 100644 index 000000000000..4b2be0ac0e47 --- /dev/null +++ b/examples/basics/src/assets/background.svg @@ -0,0 +1 @@ + diff --git a/examples/basics/src/components/Welcome.astro b/examples/basics/src/components/Welcome.astro new file mode 100644 index 000000000000..6b7b9c70e869 --- /dev/null +++ b/examples/basics/src/components/Welcome.astro @@ -0,0 +1,209 @@ +--- +import astroLogo from '../assets/astro.svg'; +import background from '../assets/background.svg'; +--- + + + + diff --git a/examples/basics/src/layouts/Layout.astro b/examples/basics/src/layouts/Layout.astro index fe43c7e27801..e455c6106729 100644 --- a/examples/basics/src/layouts/Layout.astro +++ b/examples/basics/src/layouts/Layout.astro @@ -1,56 +1,22 @@ ---- -export interface Props { - title: string; -} - -const { title } = Astro.props as Props; ---- - - + - - - - - {title} - - - - + + + + + + Astro Basics + + + + diff --git a/examples/basics/src/pages/index.astro b/examples/basics/src/pages/index.astro index ea7401f118b3..c04f3602b552 100644 --- a/examples/basics/src/pages/index.astro +++ b/examples/basics/src/pages/index.astro @@ -1,73 +1,11 @@ --- +import Welcome from '../components/Welcome.astro'; import Layout from '../layouts/Layout.astro'; -import Card from '../components/Card.astro'; ---- - -
    -

    Welcome to Astro

    -

    - Check out the src/pages directory to get started.
    - Code Challenge: Tweak the "Welcome to Astro" message above. -

    - -
    -
    - - + + + diff --git a/examples/basics/tsconfig.json b/examples/basics/tsconfig.json index 7ac81809afda..8bf91d3bb997 100644 --- a/examples/basics/tsconfig.json +++ b/examples/basics/tsconfig.json @@ -1,15 +1,5 @@ { - "compilerOptions": { - // Enable top-level await, and other modern ESM features. - "target": "ESNext", - "module": "ESNext", - // Enable node-style module resolution, for things like npm package imports. - "moduleResolution": "node", - // Enable JSON imports. - "resolveJsonModule": true, - // Enable stricter transpilation for better output. - "isolatedModules": true, - // Add type definitions for our Vite runtime. - "types": ["vite/client"] - } + "extends": "astro/tsconfigs/strict", + "include": [".astro/types.d.ts", "**/*"], + "exclude": ["dist"] } diff --git a/examples/blog-multiple-authors/.gitignore b/examples/blog-multiple-authors/.gitignore deleted file mode 100644 index 7329a851d0ac..000000000000 --- a/examples/blog-multiple-authors/.gitignore +++ /dev/null @@ -1,20 +0,0 @@ -# build output -dist/ -.output/ - -# dependencies -node_modules/ - -# logs -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* - - -# environment variables -.env -.env.production - -# macOS-specific files -.DS_Store diff --git a/examples/blog-multiple-authors/.npmrc b/examples/blog-multiple-authors/.npmrc deleted file mode 100644 index ef83021af3ec..000000000000 --- a/examples/blog-multiple-authors/.npmrc +++ /dev/null @@ -1,2 +0,0 @@ -# Expose Astro dependencies for `pnpm` users -shamefully-hoist=true diff --git a/examples/blog-multiple-authors/.stackblitzrc b/examples/blog-multiple-authors/.stackblitzrc deleted file mode 100644 index 43798ecff844..000000000000 --- a/examples/blog-multiple-authors/.stackblitzrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "startCommand": "npm start", - "env": { - "ENABLE_CJS_IMPORTS": true - } -} \ No newline at end of file diff --git a/examples/blog-multiple-authors/README.md b/examples/blog-multiple-authors/README.md deleted file mode 100644 index e98036e122af..000000000000 --- a/examples/blog-multiple-authors/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# Astro Starter Kit: Blog with Multiple Authors - -``` -npm init astro -- --template blog-multiple-authors -``` - -[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/blog-multiple-authors) - -> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun! - -Features: - -- ✅ SEO-friendly setup with canonical URLs and OpenGraph data -- ✅ Full Markdown support -- ✅ RSS 2.0 generation -- ✅ Sitemap.xml generation - -## 🚀 Project Structure - -Inside of your Astro project, you'll see the following folders and files: - -``` -/ -├── public/ -│ ├── robots.txt -│ └── favicon.ico -├── src/ -│ ├── components/ -│ │ └── Tour.astro -│ └── pages/ -│ └── index.astro -└── package.json -``` - -Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. - -There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components. - -Any static assets, like images, can be placed in the `public/` directory. - -## 🧞 Commands - -All commands are run from the root of the project, from a terminal: - -| Command | Action | -|:---------------- |:-------------------------------------------- | -| `npm install` | Installs dependencies | -| `npm run dev` | Starts local dev server at `localhost:3000` | -| `npm run build` | Build your production site to `./dist/` | -| `npm run preview` | Preview your build locally, before deploying | - -## 👀 Want to learn more? - -Feel free to check [our documentation](https://github.com/withastro/astro) or jump into our [Discord server](https://astro.build/chat). diff --git a/examples/blog-multiple-authors/astro.config.mjs b/examples/blog-multiple-authors/astro.config.mjs deleted file mode 100644 index 5a51e487a713..000000000000 --- a/examples/blog-multiple-authors/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import preact from '@astrojs/preact'; - -// https://astro.build/config -export default defineConfig({ - // Enable the Preact integration to support Preact JSX components. - integrations: [preact()], -}); diff --git a/examples/blog-multiple-authors/package.json b/examples/blog-multiple-authors/package.json deleted file mode 100644 index e6c39e10b275..000000000000 --- a/examples/blog-multiple-authors/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "@example/blog-multiple-authors", - "version": "0.0.1", - "private": true, - "scripts": { - "dev": "astro dev", - "start": "astro dev", - "build": "astro build", - "preview": "astro preview" - }, - "devDependencies": { - "@astrojs/preact": "^0.1.2", - "astro": "^1.0.0-beta.26", - "sass": "^1.50.1" - }, - "dependencies": { - "preact": "^10.7.1" - } -} diff --git a/examples/blog-multiple-authors/public/favicon.ico b/examples/blog-multiple-authors/public/favicon.ico deleted file mode 100644 index 578ad458b890..000000000000 Binary files a/examples/blog-multiple-authors/public/favicon.ico and /dev/null differ diff --git a/examples/blog-multiple-authors/public/images/chapter-01.jpg b/examples/blog-multiple-authors/public/images/chapter-01.jpg deleted file mode 100644 index a848d3059480..000000000000 Binary files a/examples/blog-multiple-authors/public/images/chapter-01.jpg and /dev/null differ diff --git a/examples/blog-multiple-authors/public/images/chapter-02.jpg b/examples/blog-multiple-authors/public/images/chapter-02.jpg deleted file mode 100644 index 0a18c689d9ee..000000000000 Binary files a/examples/blog-multiple-authors/public/images/chapter-02.jpg and /dev/null differ diff --git a/examples/blog-multiple-authors/public/images/chapter-03.jpg b/examples/blog-multiple-authors/public/images/chapter-03.jpg deleted file mode 100644 index e3b6823cee7a..000000000000 Binary files a/examples/blog-multiple-authors/public/images/chapter-03.jpg and /dev/null differ diff --git a/examples/blog-multiple-authors/public/images/don.jpg b/examples/blog-multiple-authors/public/images/don.jpg deleted file mode 100644 index 4419679de527..000000000000 Binary files a/examples/blog-multiple-authors/public/images/don.jpg and /dev/null differ diff --git a/examples/blog-multiple-authors/public/images/sancho.jpg b/examples/blog-multiple-authors/public/images/sancho.jpg deleted file mode 100644 index 2c2b0c6bdf64..000000000000 Binary files a/examples/blog-multiple-authors/public/images/sancho.jpg and /dev/null differ diff --git a/examples/blog-multiple-authors/sandbox.config.json b/examples/blog-multiple-authors/sandbox.config.json deleted file mode 100644 index 9178af77d7de..000000000000 --- a/examples/blog-multiple-authors/sandbox.config.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "infiniteLoopProtection": true, - "hardReloadOnChange": false, - "view": "browser", - "template": "node", - "container": { - "port": 3000, - "startScript": "start", - "node": "14" - } -} diff --git a/examples/blog-multiple-authors/src/components/MainHead.astro b/examples/blog-multiple-authors/src/components/MainHead.astro deleted file mode 100644 index ca129df8dab1..000000000000 --- a/examples/blog-multiple-authors/src/components/MainHead.astro +++ /dev/null @@ -1,46 +0,0 @@ ---- -import '../styles/global.css'; - -export interface Props { - title: string; - description: string; - image?: string; - type?: string; - next?: string; - prev?: string; - canonicalURL?: string | URL; -} - -const { title, description, image, type, next, prev, canonicalURL } = Astro.props as Props; ---- - - - -{title} - - - - - - - - - - - - - -{next && } -{prev && } - - - - -{image && ()} - - - - - - -{image && ()} diff --git a/examples/blog-multiple-authors/src/components/Nav.astro b/examples/blog-multiple-authors/src/components/Nav.astro deleted file mode 100644 index a2a5fc3a37b6..000000000000 --- a/examples/blog-multiple-authors/src/components/Nav.astro +++ /dev/null @@ -1,63 +0,0 @@ ---- -export interface Props { - title: string; -} -const { title } = Astro.props; ---- - - - - diff --git a/examples/blog-multiple-authors/src/components/Pagination.astro b/examples/blog-multiple-authors/src/components/Pagination.astro deleted file mode 100644 index 8cc3941f6bac..000000000000 --- a/examples/blog-multiple-authors/src/components/Pagination.astro +++ /dev/null @@ -1,44 +0,0 @@ ---- -export interface Props { - prevUrl: string; - nextUrl: string; -} - -const { prevUrl, nextUrl } = Astro.props; ---- - -
    - -
    - - diff --git a/examples/blog-multiple-authors/src/components/PostPreview.astro b/examples/blog-multiple-authors/src/components/PostPreview.astro deleted file mode 100644 index 5a98083488d0..000000000000 --- a/examples/blog-multiple-authors/src/components/PostPreview.astro +++ /dev/null @@ -1,66 +0,0 @@ ---- -export interface Props { - post: any; - author: string; -} -const { post, author } = Astro.props; -const { frontmatter } = post; - -function formatDate(date) { - return new Date(date).toUTCString().replace(/(\d\d\d\d) .*/, '$1'); // remove everything after YYYY -} ---- - -
    -
    -

    {frontmatter.title}

    - {author.name} - -

    - {frontmatter.description} - Read -

    -
    -
    - - diff --git a/examples/blog-multiple-authors/src/data/authors.json b/examples/blog-multiple-authors/src/data/authors.json deleted file mode 100644 index 1eeff3766257..000000000000 --- a/examples/blog-multiple-authors/src/data/authors.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "don": { - "name": "Don Quixote", - "image": "/images/don.jpg" - }, - "sancho": { - "name": "Sancho Panza", - "image": "/images/sancho.jpg" - } -} diff --git a/examples/blog-multiple-authors/src/layouts/post.astro b/examples/blog-multiple-authors/src/layouts/post.astro deleted file mode 100644 index bbfc7b3357d1..000000000000 --- a/examples/blog-multiple-authors/src/layouts/post.astro +++ /dev/null @@ -1,78 +0,0 @@ ---- -import MainHead from '../components/MainHead.astro'; -import Nav from '../components/Nav.astro'; -import authorData from '../data/authors.json'; - -const { content } = Astro.props; -let canonicalURL = Astro.canonicalURL; ---- - - - - {content.title} - - - - - -