diff --git a/.changeset/hungry-lizards-float.md b/.changeset/hungry-lizards-float.md new file mode 100644 index 000000000..fdac0767b --- /dev/null +++ b/.changeset/hungry-lizards-float.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': patch +--- + +Refactor static adapter to use updateConfig method diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f7c2aa2a..f0e9af1fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,9 @@ env: 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: @@ -112,11 +115,13 @@ jobs: needs: build strategy: matrix: - OS: [ubuntu-latest, windows-latest] + OS: [ubuntu-latest] NODE_VERSION: [16, 18] include: - os: macos-latest NODE_VERSION: 16 + - os: windows-latest + NODE_VERSION: 16 fail-fast: false env: NODE_VERSION: ${{ matrix.NODE_VERSION }} @@ -221,4 +226,3 @@ jobs: run: pnpm run test:smoke env: SKIP_OG: 1 - NODE_OPTIONS: "--max-old-space-size=4096" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 347fd2e6d..ff03da286 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,17 +7,17 @@ We welcome contributions of any size and skill level. As an open source project, ## Quick Guide -### Prerequisite +### Prerequisites ```shell -node: "^14.18.0 || >=16.12.0" -pnpm: "^7.9.5" +node: "^>=16.12.0" +pnpm: "^8.2.0" # otherwise, your build will fail ``` ### 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 ... @@ -35,7 +35,7 @@ To automatically handle merge conflicts in `pnpm-lock.yaml`, you should run the ```shell pnpm add -g @pnpm/merge-driver -pnpx npm-merge-driver install --driver-name pnpm-merge-driver --driver "pnpm-merge-driver %A %O %B %P" --files pnpm-lock.yaml +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 @@ -44,7 +44,7 @@ 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 dependcies will be preinstalled and the tests will run automatically ensuring you've got a green base from which to start working. +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). @@ -63,7 +63,7 @@ During the development process, you may want to test your changes to ensure they 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 ``` @@ -77,7 +77,7 @@ Overall, it's up to personal preference which method to use. For smaller changes 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" ``` @@ -168,7 +168,7 @@ Server-side rendering (SSR) can be complicated. The Astro package (`packages/ast - `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 @@ -198,7 +198,7 @@ By default, `create-astro` and [astro.new](https://astro.new) point to this bran ## Releasing Astro -_Note: Only [core maintainers (L3+)](https://github.com/withastro/.github/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. @@ -230,15 +230,15 @@ git reset --hard 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/atlassian/changesets/blob/main/docs/snapshot-releases.md +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 diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts index a93d02adb..33ce8f6f9 100644 --- a/packages/astro/src/runtime/server/endpoint.ts +++ b/packages/astro/src/runtime/server/endpoint.ts @@ -40,6 +40,7 @@ ${chosenMethod} requests are not available when building a static site. Update y return response; } + // TODO: Remove support for old API in Astro 3.0 if (handler.length > 1) { // eslint-disable-next-line no-console console.warn(` @@ -57,6 +58,7 @@ Update your code to remove this warning.`); if (prop in target) { return Reflect.get(target, prop); } else if (prop in params) { + // TODO: Remove support for old API in Astro 3.0 // eslint-disable-next-line no-console console.warn(` API routes no longer pass params as the first argument. Instead an object containing a params property is provided in the form of: diff --git a/packages/astro/test/api-routes.test.js b/packages/astro/test/api-routes.test.js index 2536ad18f..278d2454e 100644 --- a/packages/astro/test/api-routes.test.js +++ b/packages/astro/test/api-routes.test.js @@ -10,38 +10,6 @@ describe('API routes', () => { await fixture.build(); }); - describe('Deprecated API', () => { - it('two argument supported', async () => { - const one = JSON.parse(await fixture.readFile('/old-api/twoarg/one.json')); - expect(one).to.deep.equal({ - param: 'one', - pathname: '/old-api/twoarg/one.json', - }); - const two = JSON.parse(await fixture.readFile('/old-api/twoarg/two.json')); - expect(two).to.deep.equal({ - param: 'two', - pathname: '/old-api/twoarg/two.json', - }); - }); - - it('param first argument is supported', async () => { - const one = JSON.parse(await fixture.readFile('/old-api/onearg/one.json')); - expect(one).to.deep.equal({ - param: 'one', - }); - }); - }); - - describe('1.0 API', () => { - it('Receives a context argument', async () => { - const one = JSON.parse(await fixture.readFile('/context/data/one.json')); - expect(one).to.deep.equal({ - param: 'one', - pathname: '/context/data/one.json', - }); - }); - }); - describe('Binary data', () => { it('can be returned from a response', async () => { const dat = await fixture.readFile('/binary.dat', null); diff --git a/packages/astro/test/astro-envs.test.js b/packages/astro/test/astro-envs.test.js index d2d06c28d..402878da5 100644 --- a/packages/astro/test/astro-envs.test.js +++ b/packages/astro/test/astro-envs.test.js @@ -53,7 +53,6 @@ describe('Environment Variables', () => { it('includes public env in client-side JS', async () => { let dirs = await fixture.readdir('/_astro'); - console.log(dirs); let found = false; // Look in all of the .js files to see if the public env is inlined. diff --git a/packages/astro/test/dev-routing.test.js b/packages/astro/test/dev-routing.test.js index c0f87375a..be3186493 100644 --- a/packages/astro/test/dev-routing.test.js +++ b/packages/astro/test/dev-routing.test.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { loadFixture } from './test-utils.js'; +import { loadFixture, silentLogging } from './test-utils.js'; describe('Development Routing', () => { describe('No site config', () => { @@ -10,7 +10,9 @@ describe('Development Routing', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/without-site-config/' }); - devServer = await fixture.startDevServer(); + devServer = await fixture.startDevServer({ + logging: silentLogging, + }); }); after(async () => { diff --git a/packages/astro/test/dynamic-endpoint-collision.js b/packages/astro/test/dynamic-endpoint-collision.js index b8620568a..e1f4b2f03 100644 --- a/packages/astro/test/dynamic-endpoint-collision.js +++ b/packages/astro/test/dynamic-endpoint-collision.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; import { load as cheerioLoad } from 'cheerio'; -import { loadFixture } from './test-utils.js'; +import { loadFixture, silentLogging } from './test-utils.js'; describe('Dynamic endpoint collision', () => { describe('build', () => { @@ -31,7 +31,9 @@ describe('Dynamic endpoint collision', () => { root: './fixtures/dynamic-endpoint-collision/', }); - devServer = await fixture.startDevServer(); + devServer = await fixture.startDevServer({ + logging: silentLogging, + }); }); after(async () => { diff --git a/packages/astro/test/error-bad-js.test.js b/packages/astro/test/error-bad-js.test.js index 4315add2c..9149d8ad5 100644 --- a/packages/astro/test/error-bad-js.test.js +++ b/packages/astro/test/error-bad-js.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; +import { loadFixture, silentLogging } from './test-utils.js'; describe('Errors in JavaScript', () => { /** @type {import('./test-utils').Fixture} */ @@ -12,8 +12,13 @@ describe('Errors in JavaScript', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/error-bad-js', + vite: { + logLevel: 'silent', + }, + }); + devServer = await fixture.startDevServer({ + logging: silentLogging, }); - devServer = await fixture.startDevServer(); }); after(async () => { diff --git a/packages/astro/test/error-non-error.test.js b/packages/astro/test/error-non-error.test.js index facf99633..023807be8 100644 --- a/packages/astro/test/error-non-error.test.js +++ b/packages/astro/test/error-non-error.test.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { loadFixture } from './test-utils.js'; +import { loadFixture, silentLogging } from './test-utils.js'; describe('Can handle errors that are not instanceof Error', () => { /** @type {import('./test-utils').Fixture} */ @@ -12,7 +12,9 @@ describe('Can handle errors that are not instanceof Error', () => { fixture = await loadFixture({ root: './fixtures/error-non-error', }); - devServer = await fixture.startDevServer(); + devServer = await fixture.startDevServer({ + logging: silentLogging, + }); }); after(async () => { diff --git a/packages/astro/test/fixtures/api-routes/src/pages/old-api/onearg/[param].json.js b/packages/astro/test/fixtures/api-routes/src/pages/old-api/onearg/[param].json.js deleted file mode 100644 index 63771f8e0..000000000 --- a/packages/astro/test/fixtures/api-routes/src/pages/old-api/onearg/[param].json.js +++ /dev/null @@ -1,23 +0,0 @@ - -export function getStaticPaths() { - return [ - { - params: { - param: 'one' - } - }, - { - params: { - param: 'two' - } - }, - ] -} - -export function get(params) { - return { - body: JSON.stringify({ - param: params.param - }) - }; -} diff --git a/packages/astro/test/fixtures/api-routes/src/pages/old-api/twoarg/[param].json.js b/packages/astro/test/fixtures/api-routes/src/pages/old-api/twoarg/[param].json.js deleted file mode 100644 index ab71d6896..000000000 --- a/packages/astro/test/fixtures/api-routes/src/pages/old-api/twoarg/[param].json.js +++ /dev/null @@ -1,24 +0,0 @@ - -export function getStaticPaths() { - return [ - { - params: { - param: 'one' - } - }, - { - params: { - param: 'two' - } - }, - ] -} - -export function get(params, request) { - return { - body: JSON.stringify({ - param: params.param, - pathname: new URL(request.url).pathname - }) - }; -} diff --git a/packages/astro/test/fixtures/component-library/package.json b/packages/astro/test/fixtures/component-library/package.json index 23c861101..0a677ced2 100644 --- a/packages/astro/test/fixtures/component-library/package.json +++ b/packages/astro/test/fixtures/component-library/package.json @@ -8,7 +8,9 @@ "@astrojs/svelte": "workspace:*", "@test/component-library-shared": "workspace:*", "astro": "workspace:*", + "preact": "^10.13.2", "react": "^18.1.0", - "react-dom": "^18.1.0" + "react-dom": "^18.1.0", + "svelte": "^3.58.0" } } diff --git a/packages/astro/test/fixtures/slots-svelte/src/components/Counter.svelte b/packages/astro/test/fixtures/slots-svelte/src/components/Counter.svelte index 24f4e734e..b03e016b7 100644 --- a/packages/astro/test/fixtures/slots-svelte/src/components/Counter.svelte +++ b/packages/astro/test/fixtures/slots-svelte/src/components/Counter.svelte @@ -28,7 +28,4 @@ margin-top: 2em; place-items: center; } - .message { - text-align: center; - } diff --git a/packages/astro/test/fixtures/ssr-api-route/src/pages/food.json.js b/packages/astro/test/fixtures/ssr-api-route/src/pages/food.json.js index fecf83051..1f9ea5f29 100644 --- a/packages/astro/test/fixtures/ssr-api-route/src/pages/food.json.js +++ b/packages/astro/test/fixtures/ssr-api-route/src/pages/food.json.js @@ -9,7 +9,7 @@ export function get() { }; } -export async function post(params, request) { +export async function post({ params, request }) { const body = await request.text(); return new Response(body === `some data` ? `ok` : `not ok`, { status: 200, diff --git a/packages/astro/test/fixtures/static-build/src/pages/data/[slug].json.ts b/packages/astro/test/fixtures/static-build/src/pages/data/[slug].json.ts index 51a12db2e..2bcfe50a1 100644 --- a/packages/astro/test/fixtures/static-build/src/pages/data/[slug].json.ts +++ b/packages/astro/test/fixtures/static-build/src/pages/data/[slug].json.ts @@ -5,7 +5,7 @@ export async function getStaticPaths() { ] } -export async function get(params) { +export async function get({ params }) { return { body: JSON.stringify({ slug: params.slug, diff --git a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/[slug].json.ts b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/[slug].json.ts index b18660955..364c886e3 100644 --- a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/[slug].json.ts +++ b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/[slug].json.ts @@ -5,7 +5,7 @@ export async function getStaticPaths() { ]; } -export async function get(params) { +export async function get({ params }) { return { body: JSON.stringify({ slug: params.slug, diff --git a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/data/[slug].json.ts b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/data/[slug].json.ts index eea44d90b..4392c7ee7 100644 --- a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/data/[slug].json.ts +++ b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/data/[slug].json.ts @@ -5,7 +5,7 @@ export async function getStaticPaths() { ]; } -export async function get(params) { +export async function get({ params }) { return { body: JSON.stringify({ slug: params.slug, diff --git a/packages/astro/test/react-component.test.js b/packages/astro/test/react-component.test.js index 8c22cc861..7205b0342 100644 --- a/packages/astro/test/react-component.test.js +++ b/packages/astro/test/react-component.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; import { load as cheerioLoad } from 'cheerio'; -import { isWindows, loadFixture } from './test-utils.js'; +import { isWindows, loadFixture, silentLogging } from './test-utils.js'; let fixture; @@ -103,7 +103,9 @@ describe('React Components', () => { let devServer; before(async () => { - devServer = await fixture.startDevServer(); + devServer = await fixture.startDevServer({ + logging: silentLogging, + }); }); after(async () => { diff --git a/packages/astro/test/root-srcdir-css.test.js b/packages/astro/test/root-srcdir-css.test.js index 31fcc14d1..3902b4ab2 100644 --- a/packages/astro/test/root-srcdir-css.test.js +++ b/packages/astro/test/root-srcdir-css.test.js @@ -18,7 +18,6 @@ describe('srcDir', () => { const relPath = $('link').attr('href'); const css = await fixture.readFile(relPath); - console.log(css); expect(css).to.match(/body{color:green}/); }); }); diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index e6a9d648a..3acf8df48 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -68,6 +68,12 @@ export const defaultLogging = { level: 'error', }; +/** @type {import('../src/core/logger/core').LogOptions} */ +export const silentLogging = { + dest: nodeLogDestination, + level: 'silent', +}; + /** * Load Astro fixture * @param {AstroConfig} inlineConfig Astro config partial (note: must specify `root`) diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index c03c78218..5455edbc0 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -19,12 +19,17 @@ export default function vercelStatic({ analytics }: VercelStaticConfig = {}): As return { name: '@astrojs/vercel', hooks: { - 'astro:config:setup': ({ command, config, injectScript }) => { + 'astro:config:setup': ({ command, config, updateConfig, injectScript }) => { if (command === 'build' && analytics) { injectScript('page', 'import "@astrojs/vercel/analytics"'); } - config.outDir = new URL('./static/', getVercelOutput(config.root)); - config.build.format = 'directory'; + const outDir = new URL('./static/', getVercelOutput(config.root)); + updateConfig({ + outDir, + build: { + format: 'directory', + }, + }); }, 'astro:config:done': ({ setAdapter, config }) => { setAdapter(getAdapter()); diff --git a/packages/webapi/test/fetch.js b/packages/webapi/test/fetch.js index 49aab31dc..ce0a2e700 100644 --- a/packages/webapi/test/fetch.js +++ b/packages/webapi/test/fetch.js @@ -13,13 +13,13 @@ describe('Fetch', () => { it('Fetch with https', async () => { const { fetch } = target - const response = await fetch('https://api.openbrewerydb.org/breweries') + const response = await fetch('https://astro.build') expect(response.constructor).to.equal(target.Response) - const json = await response.json() + const html = await response.text() - expect(json).to.be.an('array') + expect(html).to.include(' { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9a4a9f6e6..e5e776285 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2242,12 +2242,18 @@ importers: astro: specifier: workspace:* version: link:../../.. + preact: + specifier: ^10.13.2 + version: 10.13.2 react: specifier: ^18.1.0 version: 18.2.0 react-dom: specifier: ^18.1.0 version: 18.2.0(react@18.2.0) + svelte: + specifier: ^3.58.0 + version: 3.58.0 packages/astro/test/fixtures/component-library-shared: dependencies: @@ -15363,6 +15369,10 @@ packages: /preact@10.12.0: resolution: {integrity: sha512-+w8ix+huD8CNZemheC53IPjMUFk921i02o30u0K6h53spMX41y/QhVDnG/nU2k42/69tvqWmVsgNLIiwRAcmxg==} + /preact@10.13.2: + resolution: {integrity: sha512-q44QFLhOhty2Bd0Y46fnYW0gD/cbVM9dUVtNTDKPcdXSMA7jfY+Jpd6rk3GB0lcQss0z5s/6CmVP0Z/hV+g6pw==} + dev: false + /prebuild-install@7.1.1: resolution: {integrity: sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==} engines: {node: '>=10'} @@ -16705,6 +16715,11 @@ packages: resolution: {integrity: sha512-S+87/P0Ve67HxKkEV23iCdAh/SX1xiSfjF1HOglno/YTbSTW7RniICMCofWGdJJbdjw3S+0PfFb1JtGfTXE0oQ==} engines: {node: '>= 8'} + /svelte@3.58.0: + resolution: {integrity: sha512-brIBNNB76mXFmU/Kerm4wFnkskBbluBDCjx/8TcpYRb298Yh2dztS2kQ6bhtjMcvUhd5ynClfwpz5h2gnzdQ1A==} + engines: {node: '>= 8'} + dev: false + /svg-tags@1.0.0: resolution: {integrity: sha512-ovssysQTa+luh7A5Weu3Rta6FJlFBBbInjOh722LIt6klpU2/HtdUbszju/G4devcvk8PGt7FCLv5wftu3THUA==} dev: false