Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnysprinkles committed Jun 11, 2021
2 parents a11a64b + 9a7195b commit 7e8e4ef
Show file tree
Hide file tree
Showing 26 changed files with 181 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-pumas-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

add optional state parameter for goto function
5 changes: 5 additions & 0 deletions .changeset/heavy-ways-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-node': minor
---

Allow sirv to looks for precompiled gzip and brotli files by default
5 changes: 5 additions & 0 deletions .changeset/long-hotels-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Allow vite.alias to be an array
7 changes: 7 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@
"gorgeous-radios-matter",
"gorgeous-radios-tan",
"gorgeous-taxis-smash",
"great-bugs-travel",
"great-kangaroos-eat",
"great-queens-rule",
"green-spoons-count",
"happy-dancers-call",
"happy-nails-draw",
"happy-pumas-thank",
"healthy-moons-attend",
"healthy-pumpkins-bathe",
"heavy-humans-check",
Expand Down Expand Up @@ -143,6 +145,7 @@
"light-roses-teach",
"little-shirts-happen",
"long-bulldogs-invent",
"long-hotels-hunt",
"long-moles-fold",
"loud-seals-remember",
"lovely-apricots-fail",
Expand Down Expand Up @@ -227,6 +230,7 @@
"sharp-days-exercise",
"sharp-mangos-tickle",
"sharp-pigs-study",
"shy-jeans-fly",
"shy-mails-share",
"silver-elephants-tap",
"silver-hounds-clean",
Expand All @@ -248,6 +252,7 @@
"smooth-rockets-sneeze",
"smooth-shoes-mix",
"smooth-shrimps-fly",
"soft-bikes-bake",
"soft-houses-pump",
"soft-students-cover",
"spicy-geese-accept",
Expand Down Expand Up @@ -290,6 +295,7 @@
"tiny-candles-repeat",
"tiny-gorillas-whisper",
"tiny-kids-sort",
"tiny-socks-sparkle",
"tiny-starfishes-exist",
"tough-chefs-remember",
"tough-lamps-brake",
Expand All @@ -303,6 +309,7 @@
"twelve-feet-deny",
"twelve-goats-knock",
"twelve-onions-burn",
"twenty-dryers-hope",
"two-crabs-tease",
"two-students-melt",
"two-ties-begin",
Expand Down
6 changes: 6 additions & 0 deletions .changeset/shy-jeans-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/kit': patch
---

* update vite-plugin-svelte to 1.0.0-next.11 and use its named export
* update vite to 2.3.7
5 changes: 5 additions & 0 deletions .changeset/soft-bikes-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Fix navigation when `base` path is set and validate that option's value
5 changes: 5 additions & 0 deletions .changeset/tiny-socks-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-node': patch
---

Bundle server-side app during adapt phase
13 changes: 7 additions & 6 deletions documentation/docs/03-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ type LoadOutput = {
If `load` returns nothing, SvelteKit will [fall through](#routing-advanced-fallthrough-routes) to other routes until something responds, or will respond with a generic 404.

> `load` only applies to components that define pages, not the components that they import.
>
> It is important to note that `load` may run on either the server or in the client browser. Code called inside `load` blocks:
>
> - should use the SvelteKit-provided [`fetch`](#loading-input-fetch) method for getting data in order to avoid duplicate network requests
> - should generally run on the same domain as any upstream API servers requiring credentials
> - should not reference `window`, `document`, or any browser-specific objects
> - should not reference any API keys or secrets directly, which will be exposed to the client, but instead call an endpoint using any required secrets
### Input

Expand Down Expand Up @@ -91,12 +98,6 @@ So if the example above was `src/routes/blog/[slug].svelte` and the URL was `htt

`context` is passed from layout components to child layouts and page components. For the root `__layout.svelte` component, it is equal to `{}`, but if that component's `load` function returns an object with a `context` property, it will be available to subsequent `load` functions.

> It is important to note that `load` may run on either the server or in the client browser. Code called inside `load` blocks:
>
> - should run on the same domain as any upstream API servers requiring credentials
> - should not reference `window`, `document` or any browser-specific objects
> - should not reference any API keys or secrets, which will be exposed to the client
### Output

If you return a Promise from `load`, SvelteKit will delay rendering until the promise resolves. The return value has several properties, all optional:
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/05-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { amp, browser, dev, prerendering } from '$app/env';
import { goto, invalidate, prefetch, prefetchRoutes } from '$app/navigation';
```

- `goto(href, { replaceState, noscroll })` returns a `Promise` that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `href`. The second argument is optional. If `replaceState` is true, a new history entry won't be created. If `noscroll` is true, the browser won't scroll to the top of the page after navigation.
- `goto(href, { replaceState, noscroll, state })` returns a `Promise` that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `href`. The second argument is optional. If `replaceState` is true, a new history entry won't be created. If `noscroll` is true, the browser won't scroll to the top of the page after navigation. If state is set, its value will be used to set the initital state of the new history entry, it defaults to `{}`.
- `invalidate(href)` causes any `load` functions belonging to the currently active page to re-run if they `fetch` the resource in question. It returns a `Promise` that resolves when the page is subsequently updated.
- `prefetch(href)` programmatically prefetches the given page, which means a) ensuring that the code for the page is loaded, and b) calling the page's `load` function with the appropriate options. This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with [sveltekit:prefetch](#anchor-options-sveltekit-prefetch). If the next navigation is to `href`, the values returned from `load` will be used, making navigation instantaneous. Returns a `Promise` that resolves when the prefetch is complete.
- `prefetchRoutes(routes)` — programmatically prefetches the code for routes that haven't yet been fetched. Typically, you might call this to speed up subsequent navigation. If no argument is given, all routes will be fetched; otherwise, you can specify routes by any matching pathname such as `/about` (to match `src/routes/about.svelte`) or `/blog/*` (to match `src/routes/blog/[slug].svelte`). Unlike `prefetch`, this won't call `load` for individual pages. Returns a `Promise` that resolves when the routes have been prefetched.
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/14-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Whether to [hydrate](#ssr-and-javascript-hydrate) the server-rendered HTML with
An object containing zero or more of the following `string` values:

- `assets` — an absolute path, or a path relative to `base`, where your app's files are served from. This is useful if your files are served from a storage bucket of some kind
- `base` — a root-relative (i.e. starts with `/`) path that specifies where your app is served from. This allows the app to live on a non-root path
- `base` — a root-relative path that must start, but not end with `/` (e.g. `/base-path`). This specifies where your app is served from and allows the app to live on a non-root path

### prerender

Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sveltejs/adapter-node

## 1.0.0-next.25

### Patch Changes

- 0b780a6: Bundle server-side app during adapt phase

## 1.0.0-next.24

### Patch Changes
Expand Down
17 changes: 12 additions & 5 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { copyFileSync } from 'fs';
import { readFileSync } from 'fs';
import { join } from 'path';
import { fileURLToPath } from 'url';
import esbuild from 'esbuild';

/**
* @param {{
Expand All @@ -18,11 +19,17 @@ export default function ({ out = 'build' } = {}) {
utils.copy_client_files(static_directory);
utils.copy_static_files(static_directory);

utils.log.minor('Copying server');
utils.copy_server_files(out);

utils.log.minor('Building server');
const files = fileURLToPath(new URL('./files', import.meta.url));
copyFileSync(`${files}/server.js`, `${out}/index.js`);
utils.copy(files, '.svelte-kit/node');
await esbuild.build({
entryPoints: ['.svelte-kit/node/index.js'],
outfile: join(out, 'index.js'),
bundle: true,
external: Object.keys(JSON.parse(readFileSync('package.json', 'utf8')).dependencies || {}),
format: 'esm',
platform: 'node'
});

utils.log.minor('Prerendering static pages');
await utils.prerender({
Expand Down
5 changes: 4 additions & 1 deletion packages/adapter-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-node",
"version": "1.0.0-next.24",
"version": "1.0.0-next.25",
"type": "module",
"exports": {
"import": "./index.js"
Expand All @@ -20,6 +20,9 @@
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"prepublishOnly": "npm run build"
},
"dependencies": {
"esbuild": "^0.12.5"
},
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@sveltejs/kit": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-node/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import json from '@rollup/plugin-json';
export default {
input: 'src/index.js',
output: {
file: 'files/server.js',
file: 'files/index.js',
format: 'esm',
sourcemap: true
},
plugins: [nodeResolve(), commonjs(), json()],
external: ['./app.js', ...require('module').builtinModules]
external: ['../output/server/app.js', ...require('module').builtinModules]
};
7 changes: 4 additions & 3 deletions packages/adapter-node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import './require_shim';
import { createServer } from './server';
/*eslint import/no-unresolved: [2, { ignore: ['\.\/app\.js$'] }]*/
import * as app from './app.js';
// TODO hardcoding the relative location makes this brittle
import { render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved

const { HOST = '0.0.0.0', PORT = 3000 } = process.env;

const instance = createServer({ render: app.render }).listen(PORT, HOST, () => {
const instance = createServer({ render }).listen(PORT, HOST, () => {
console.log(`Listening on port ${PORT}`);
});

Expand Down
2 changes: 2 additions & 0 deletions packages/adapter-node/src/require_shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { createRequire } from 'module';
global.require = createRequire(import.meta.url);
4 changes: 3 additions & 1 deletion packages/adapter-node/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export function createServer({ render }) {
const assets_handler = fs.existsSync(paths.assets)
? sirv(paths.assets, {
maxAge: 31536000,
immutable: true
immutable: true,
gzip: true,
brotli: true
})
: noop_handler;

Expand Down
17 changes: 17 additions & 0 deletions packages/kit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @sveltejs/kit

## 1.0.0-next.115

### Patch Changes

- 523c3e2: Allow vite.alias to be an array
- 6fd46d1: \* update vite-plugin-svelte to 1.0.0-next.11 and use its named export
- update vite to 2.3.7
- dc56d3c: Fix navigation when `base` path is set and validate that option's value

## 1.0.0-next.114

### Patch Changes

- 5aa64ab: fix: SSL for HMR websockets #844
- fae75f1: add optional state parameter for goto function
- fbd5f8a: package command can now transpile TypeScript files

## 1.0.0-next.113

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@sveltejs/kit",
"version": "1.0.0-next.113",
"version": "1.0.0-next.115",
"type": "module",
"dependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.10",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.11",
"cheap-watch": "^1.0.3",
"sade": "^1.7.4",
"vite": "2.3.6"
"vite": "2.3.7"
},
"devDependencies": {
"@rollup/plugin-replace": "^2.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { copy_assets, get_no_external, posixify, resolve_entry } from '../utils.
import { deep_merge, print_config_conflicts } from '../config/index.js';
import { create_app } from '../../core/create_app/index.js';
import vite from 'vite';
import svelte from '@sveltejs/vite-plugin-svelte';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import glob from 'tiny-glob/sync.js';
import { SVELTE_KIT } from '../constants.js';

Expand Down
6 changes: 4 additions & 2 deletions packages/kit/src/core/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ export function validate_config(config) {
// resolve paths
const { paths } = validated.kit;

if (paths.base !== '' && !paths.base.startsWith('/')) {
throw new Error('config.kit.paths.base must be a root-relative path');
if (paths.base !== '' && (paths.base.endsWith('/') || !paths.base.startsWith('/'))) {
throw new Error(
"kit.paths.base option must be a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs#configuration-paths"
);
}

paths.assets = resolve(paths.base, paths.assets);
Expand Down
14 changes: 13 additions & 1 deletion packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,19 @@ test('fails if paths.base is not root-relative', () => {
}
}
});
}, /^config\.kit\.paths\.base must be a root-relative path$/);
}, /^kit\.paths\.base option must be a root-relative path that starts but doesn't end with '\/'. See https:\/\/kit\.svelte\.dev\/docs#configuration-paths$/);
});

test("fails if paths.base ends with '/'", () => {
assert.throws(() => {
validate_config({
kit: {
paths: {
base: '/github-pages/'
}
}
});
}, /^kit\.paths\.base option must be a root-relative path that starts but doesn't end with '\/'. See https:\/\/kit\.svelte\.dev\/docs#configuration-paths$/);
});

test('fails if prerender.pages are invalid', () => {
Expand Down
23 changes: 18 additions & 5 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { respond } from '../../runtime/server/index.js';
import { getRawBody } from '../node/index.js';
import { copy_assets, get_no_external, resolve_entry } from '../utils.js';
import { deep_merge, print_config_conflicts } from '../config/index.js';
import svelte from '@sveltejs/vite-plugin-svelte';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { get_server } from '../server/index.js';
import '../../install-fetch.js';
import { SVELTE_KIT } from '../constants.js';
Expand Down Expand Up @@ -85,15 +85,28 @@ class Watcher extends EventEmitter {

this.server = await get_server(this.https, user_config, (req, res) => handler(req, res));

const alias = user_config.resolve && user_config.resolve.alias;

/** @type {[any, string[]]} */
const [merged_config, conflicts] = deep_merge(user_config, {
configFile: false,
root: this.cwd,
resolve: {
alias: {
$app: path.resolve(`${this.dir}/runtime/app`),
$lib: this.config.kit.files.lib
}
alias: Array.isArray(alias)
? [
{
find: '$app',
replacement: path.resolve(`${this.dir}/runtime/app`)
},
{
find: '$lib',
replacement: this.config.kit.files.lib
}
]
: {
$app: path.resolve(`${this.dir}/runtime/app`),
$lib: this.config.kit.files.lib
}
},
plugins: [
svelte({
Expand Down
Loading

0 comments on commit 7e8e4ef

Please sign in to comment.