Skip to content

Commit

Permalink
Merge branch 'sveltejs:master' into fix-9475-adapter-node-log-request…
Browse files Browse the repository at this point in the history
…-error
  • Loading branch information
dreitzner authored Aug 3, 2023
2 parents c2386d5 + 3c24450 commit dab875d
Show file tree
Hide file tree
Showing 424 changed files with 7,997 additions and 4,188 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://unpkg.com/@changesets/config@1.5.0/schema.json",
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": ["@svitejs/changesets-changelog-github-compact", { "repo": "sveltejs/kit" }],
"commit": false,
"linked": [],
Expand Down
19 changes: 11 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"root": true,
"extends": "@sveltejs",
"env": {
"es2022": true
},
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["unicorn"],
"root": true,
"ignorePatterns": ["packages/create-svelte/shared/"],
"ignorePatterns": [
"packages/create-svelte/shared/",
"packages/kit/test/prerendering/*/build",
"packages/adapter-static/test/apps/*/build",
"packages/adapter-cloudflare/files",
"packages/adapter-netlify/files",
"packages/adapter-node/files"
],
"rules": {
"unicorn/prefer-node-protocol": "error"
"no-undef": "off"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: pnpm/action-setup@v2.2.4
- uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '20.x'
cache: pnpm
- run: pnpm install --frozen-lockfile
# check prod dependencies as these would affect users
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm run lint
- run: cd packages/kit && pnpm prepublishOnly
- run: pnpm run check
Tests:
runs-on: ${{ matrix.os }}
Expand All @@ -44,6 +45,9 @@ jobs:
- node-version: 18
os: ubuntu-latest
e2e-browser: 'chromium'
- node-version: 20
os: ubuntu-latest
e2e-browser: 'chromium'
env:
KIT_E2E_BROWSER: ${{matrix.e2e-browser}}
steps:
Expand Down Expand Up @@ -123,3 +127,15 @@ jobs:
retention-days: 3
name: test-failure-cross-platform-${{ matrix.mode }}-${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.e2e-browser }}
path: test-results-cross-platform-${{ matrix.mode }}.tar.gz
Test-create-svelte:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.4
- uses: actions/setup-node@v3
with:
node-version: 16
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: cd packages/kit && pnpm prepublishOnly
- run: pnpm run test:create-svelte
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: pnpm release
publish: pnpm changeset:release
version: pnpm changeset:version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ vite.config.js.timestamp-*
.vercel
.test-tmp
symlink-from
.idea/
17 changes: 15 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ cd kit
pnpm install
```

You can now run SvelteKit by linking it into your project with [pnpm `overrides`](https://pnpm.io/package_json#pnpmoverrides) as demonstrated in the [sandbox example](https://github.com/sveltejs/kit-sandbox) or by running one of the test projects as described in [the testing section](#testing) below.
You can now run SvelteKit by linking it into your project with [pnpm `overrides`](https://pnpm.io/package_json#pnpmoverrides):

```jsonc
{
// ...
"pnpm": {
"overrides": {
"@sveltejs/kit": "link:../path/to/svelte-kit/packages/kit",
// additionally/optional the adapter you're using
"@sveltejs/adapter-auto": "link:../path/to/svelte-kit/packages/adapter-auto"
}
}
}
```

## Code structure

Expand Down Expand Up @@ -44,7 +57,7 @@ Run `pnpm test` to run the tests from all subpackages. Browser tests live in sub

You can run the tests for only a single package by first moving to that directory. E.g. `cd packages/kit`.

You must rebuild each time before running the tests if you've made code changes.
For some packages you must rebuild each time before running the tests if you've made code changes. These packages have a `build` command. Packages like `packages/kit` don't require a build step.

To run a single integration test or otherwise control the running of the tests locally see [the Playwright CLI docs](https://playwright.dev/docs/test-cli). Note that you will need to run these commands from the test project directory such as `packages/kit/test/apps/basics`.

Expand Down
4 changes: 3 additions & 1 deletion documentation/docs/10-getting-started/10-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ title: Introduction

SvelteKit is a framework for rapidly developing robust, performant web applications using [Svelte](https://svelte.dev/). If you're coming from React, SvelteKit is similar to Next. If you're coming from Vue, SvelteKit is similar to Nuxt.

To learn more about the kinds of applications you can build with SvelteKit, see the [FAQ](/faq#what-can-i-make-with-sveltekit).

## What is Svelte?

In short, Svelte is a way of writing user interface components — like a navigation bar, comment section, or contact form — that users see and interact with in their browsers. The Svelte compiler converts your components to JavaScript that can be run to render the HTML for the page and to CSS that styles the page. You don't need to know Svelte to understand the rest of this guide, but it will help. If you'd like to learn more, check out [the Svelte tutorial](https://svelte.dev/tutorial).

## What does SvelteKit provide on top of Svelte?
## SvelteKit vs Svelte

Svelte renders UI components. You can compose these components and render an entire page with just Svelte, but you need more than just Svelte to write an entire app.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ npm install
npm run dev
```

The first command will scaffold a new project in the `my-app` directory asking you if you'd like to set up some basic tooling such as TypeScript. See the FAQ for [pointers on setting up additional tooling](/faq#integrations). The subsequent commands will then install its dependencies and start a server on [localhost:5173](http://localhost:5173).
The first command will scaffold a new project in the `my-app` directory asking you if you'd like to set up some basic tooling such as TypeScript. See the FAQ for [pointers on setting up additional tooling](../faq#integrations). The subsequent commands will then install its dependencies and start a server on [localhost:5173](http://localhost:5173).

There are two basic concepts:

Expand Down
12 changes: 6 additions & 6 deletions documentation/docs/10-getting-started/30-project-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ The `src` directory contains the meat of your project. Everything except `src/ro
- `%sveltekit.body%` — the markup for a rendered page. This should live inside a `<div>` or other element, rather than directly inside `<body>`, to prevent bugs caused by browser extensions injecting elements that are then destroyed by the hydration process. SvelteKit will warn you in development if this is not the case
- `%sveltekit.assets%` — either [`paths.assets`](configuration#paths), if specified, or a relative path to [`paths.base`](configuration#paths)
- `%sveltekit.nonce%` — a [CSP](configuration#csp) nonce for manually included links and scripts, if used
- `%sveltekit.env.[NAME]%` - this will be replaced at render time with the `[NAME]` environment variable, which must begin with the [`publicPrefix`](https://kit.svelte.dev/docs/configuration#env) (usually `PUBLIC_`). It will fallback to `''` if not matched.
- `%sveltekit.env.[NAME]%` - this will be replaced at render time with the `[NAME]` environment variable, which must begin with the [`publicPrefix`](configuration#env) (usually `PUBLIC_`). It will fallback to `''` if not matched.
- `error.html` is the page that is rendered when everything else fails. It can contain the following placeholders:
- `%sveltekit.status%` — the HTTP status
- `%sveltekit.error.message%` — the error message
- `hooks.client.js` contains your client [hooks](/docs/hooks)
- `hooks.server.js` contains your server [hooks](/docs/hooks)
- `service-worker.js` contains your [service worker](/docs/service-workers)
- `hooks.client.js` contains your client [hooks](hooks)
- `hooks.server.js` contains your server [hooks](hooks)
- `service-worker.js` contains your [service worker](service-workers)

You can use `.ts` files instead of `.js` files, if using TypeScript.
(Whether the project contains `.js` or `.ts` files depends on whether you opt to use TypeScript when you create your project. You can switch between JavaScript and TypeScript in the documentation using the toggle at the bottom of this page.)

If you added [Vitest](https://vitest.dev) when you set up your project, your unit tests will live in the `src` directory with a `.test.js` (or `.test.ts`) extension.
If you added [Vitest](https://vitest.dev) when you set up your project, your unit tests will live in the `src` directory with a `.test.js` extension.

### static

Expand Down
12 changes: 8 additions & 4 deletions documentation/docs/10-getting-started/40-web-standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ An instance of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Res

### Headers

The [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) interface allows you to read incoming `request.headers` and set outgoing `response.headers`:
The [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) interface allows you to read incoming `request.headers` and set outgoing `response.headers`. For example, you can get the `request.headers` as shown below, and use the [`json` convenience function](modules#sveltejs-kit-json) to send modified `response.headers`:

```js
// @errors: 2461
/// file: src/routes/what-is-my-user-agent/+server.js
import { json } from '@sveltejs/kit';

/** @type {import('./$types').RequestHandler} */
export function GET(event) {
export function GET({ request }) {
// log all headers
console.log(...event.request.headers);
console.log(...request.headers);

// create a JSON Response using a header we received
return json({
// retrieve a specific header
userAgent: event.request.headers.get('user-agent')
userAgent: request.headers.get('user-agent')
}, {
// set a header on the response
headers: { 'x-custom-header': 'potato' }
});
}
```
Expand Down
11 changes: 6 additions & 5 deletions documentation/docs/20-core-concepts/10-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A `+page.svelte` component defines a page of your app. By default, pages are ren
### +page.js

Often, a page will need to load some data before it can be rendered. For this, we add a `+page.js` (or `+page.ts`, if you're TypeScript-inclined) module that exports a `load` function:
Often, a page will need to load some data before it can be rendered. For this, we add a `+page.js` module that exports a `load` function:

```js
/// file: src/routes/blog/[slug]/+page.js
Expand Down Expand Up @@ -238,7 +238,7 @@ Data returned from a layout's `load` function is also available to all its child
</script>
```

> Often, layout data is unchanged when navigating between pages. SvelteKit will intelligently re-run [`load`](load) functions when necessary.
> Often, layout data is unchanged when navigating between pages. SvelteKit will intelligently rerun [`load`](load) functions when necessary.
### +layout.server.js

Expand All @@ -248,7 +248,7 @@ Like `+layout.js`, `+layout.server.js` can export [page options](page-options)

## +server

As well as pages, you can define routes with a `+server.js` file (sometimes referred to as an 'API route' or an 'endpoint'), which gives you full control over the response. Your `+server.js` file (or `+server.ts`) exports functions corresponding to HTTP verbs like `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, and `OPTIONS` that take a `RequestEvent` argument and return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object.
As well as pages, you can define routes with a `+server.js` file (sometimes referred to as an 'API route' or an 'endpoint'), which gives you full control over the response. Your `+server.js` file exports functions corresponding to HTTP verbs like `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, `OPTIONS`, and `HEAD` that take a `RequestEvent` argument and return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object.

For example we could create an `/api/random-number` route with a `GET` handler:

Expand Down Expand Up @@ -283,7 +283,7 @@ If an error is thrown (either `throw error(...)` or an unexpected error), the re
### Receiving data
By exporting `POST`/`PUT`/`PATCH`/`DELETE`/`OPTIONS` handlers, `+server.js` files can be used to create a complete API:
By exporting `POST`/`PUT`/`PATCH`/`DELETE`/`OPTIONS`/`HEAD` handlers, `+server.js` files can be used to create a complete API:
```svelte
/// file: src/routes/add/+page.svelte
Expand Down Expand Up @@ -330,7 +330,8 @@ export async function POST({ request }) {
`+server.js` files can be placed in the same directory as `+page` files, allowing the same route to be either a page or an API endpoint. To determine which, SvelteKit applies the following rules:
- `PUT`/`PATCH`/`DELETE`/`OPTIONS` requests are always handled by `+server.js` since they do not apply to pages
- `GET`/`POST` requests are treated as page requests if the `accept` header prioritises `text/html` (in other words, it's a browser page request), else they are handled by `+server.js`
- `GET`/`POST`/`HEAD` requests are treated as page requests if the `accept` header prioritises `text/html` (in other words, it's a browser page request), else they are handled by `+server.js`.
- Responses to `GET` requests will include a `Vary: Accept` header, so that proxies and browsers cache HTML and JSON responses separately.
## $types
Expand Down
Loading

0 comments on commit dab875d

Please sign in to comment.