@sveltejs/kit 1.0.0-next.51 → 1.0.0-next.511
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/package.json +93 -67
- package/postinstall.js +47 -0
- package/scripts/special-types/$env+dynamic+private.md +10 -0
- package/scripts/special-types/$env+dynamic+public.md +8 -0
- package/scripts/special-types/$env+static+private.md +19 -0
- package/scripts/special-types/$env+static+public.md +7 -0
- package/scripts/special-types/$lib.md +5 -0
- package/src/cli.js +108 -0
- package/src/constants.js +7 -0
- package/src/core/adapt/builder.js +206 -0
- package/src/core/adapt/index.js +31 -0
- package/src/core/config/default-error.html +56 -0
- package/src/core/config/index.js +110 -0
- package/src/core/config/options.js +504 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/env.js +121 -0
- package/src/core/generate_manifest/index.js +93 -0
- package/src/core/prerender/crawl.js +198 -0
- package/src/core/prerender/entities.js +2252 -0
- package/src/core/prerender/prerender.js +458 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/index.js +488 -0
- package/src/core/sync/create_manifest_data/types.d.ts +37 -0
- package/src/core/sync/sync.js +70 -0
- package/src/core/sync/utils.js +33 -0
- package/src/core/sync/write_ambient.js +53 -0
- package/src/core/sync/write_client_manifest.js +106 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +91 -0
- package/src/core/sync/write_tsconfig.js +195 -0
- package/src/core/sync/write_types/index.js +783 -0
- package/src/core/utils.js +70 -0
- package/src/exports/hooks/index.js +1 -0
- package/src/exports/hooks/sequence.js +44 -0
- package/src/exports/index.js +45 -0
- package/src/exports/node/index.js +161 -0
- package/src/exports/node/polyfills.js +28 -0
- package/src/exports/vite/build/build_server.js +378 -0
- package/src/exports/vite/build/build_service_worker.js +91 -0
- package/src/exports/vite/build/utils.js +180 -0
- package/src/exports/vite/dev/index.js +577 -0
- package/src/exports/vite/graph_analysis/index.js +277 -0
- package/src/exports/vite/graph_analysis/types.d.ts +5 -0
- package/src/exports/vite/graph_analysis/utils.js +30 -0
- package/src/exports/vite/index.js +598 -0
- package/src/exports/vite/preview/index.js +189 -0
- package/src/exports/vite/types.d.ts +3 -0
- package/src/exports/vite/utils.js +157 -0
- package/src/runtime/app/env.js +1 -0
- package/src/runtime/app/environment.js +11 -0
- package/src/runtime/app/forms.js +122 -0
- package/src/runtime/app/navigation.js +23 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +30 -0
- package/src/runtime/client/client.js +1587 -0
- package/src/runtime/client/fetcher.js +107 -0
- package/src/runtime/client/parse.js +60 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +37 -0
- package/src/runtime/client/types.d.ts +84 -0
- package/src/runtime/client/utils.js +159 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/src/runtime/control.js +98 -0
- package/src/runtime/env/dynamic/private.js +1 -0
- package/src/runtime/env/dynamic/public.js +1 -0
- package/src/runtime/env-private.js +6 -0
- package/src/runtime/env-public.js +6 -0
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +20 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/cookie.js +166 -0
- package/src/runtime/server/data/index.js +136 -0
- package/src/runtime/server/endpoint.js +92 -0
- package/src/runtime/server/fetch.js +174 -0
- package/src/runtime/server/index.js +349 -0
- package/src/runtime/server/page/actions.js +243 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +250 -0
- package/src/runtime/server/page/index.js +301 -0
- package/src/runtime/server/page/load_data.js +211 -0
- package/src/runtime/server/page/render.js +342 -0
- package/src/runtime/server/page/respond_with_error.js +100 -0
- package/src/runtime/server/page/serialize_data.js +87 -0
- package/src/runtime/server/page/types.d.ts +35 -0
- package/src/runtime/server/utils.js +176 -0
- package/src/utils/array.js +9 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +46 -0
- package/src/utils/filesystem.js +137 -0
- package/src/utils/functions.js +16 -0
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/promises.js +17 -0
- package/src/utils/routing.js +117 -0
- package/src/utils/unit_test.js +11 -0
- package/src/utils/url.js +142 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +431 -0
- package/types/index.d.ts +474 -0
- package/types/internal.d.ts +378 -0
- package/types/private.d.ts +224 -0
- package/CHANGELOG.md +0 -490
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -44
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -22
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -776
- package/assets/runtime/paths.js +0 -12
- package/dist/chunks/index.js +0 -3528
- package/dist/chunks/index2.js +0 -587
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -536
- package/dist/chunks/index5.js +0 -763
- package/dist/chunks/index6.js +0 -322
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -83
- package/dist/cli.js +0 -550
- package/dist/ssr.js +0 -2599
- package/types.d.ts +0 -72
- package/types.internal.d.ts +0 -217
package/README.md
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# The fastest way to build Svelte apps
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is the [SvelteKit](https://kit.svelte.dev) framework and CLI.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The quickest way to get started is via the [create-svelte](https://github.com/sveltejs/kit/tree/master/packages/create-svelte) package:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm create svelte@latest my-app
|
|
9
|
+
cd my-app
|
|
10
|
+
npm install
|
|
11
|
+
npm run dev
|
|
12
|
+
```
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
See the [documentation](https://kit.svelte.dev/docs) to learn more.
|
|
10
15
|
|
|
11
|
-
##
|
|
16
|
+
## Changelog
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Then, clone the corresponding [svelte-app-demo](https://github.com/sveltejs/svelte-app-demo) repo and follow the instructions therein.
|
|
18
|
+
[The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md).
|
package/package.json
CHANGED
|
@@ -1,68 +1,94 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
2
|
+
"name": "@sveltejs/kit",
|
|
3
|
+
"version": "1.0.0-next.511",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/sveltejs/kit",
|
|
7
|
+
"directory": "packages/kit"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://kit.svelte.dev",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@sveltejs/vite-plugin-svelte": "^1.0.5",
|
|
14
|
+
"@types/cookie": "^0.5.1",
|
|
15
|
+
"cookie": "^0.5.0",
|
|
16
|
+
"devalue": "^4.0.0",
|
|
17
|
+
"kleur": "^4.1.4",
|
|
18
|
+
"magic-string": "^0.26.2",
|
|
19
|
+
"mime": "^3.0.0",
|
|
20
|
+
"sade": "^1.8.1",
|
|
21
|
+
"set-cookie-parser": "^2.4.8",
|
|
22
|
+
"sirv": "^2.0.2",
|
|
23
|
+
"tiny-glob": "^0.2.9",
|
|
24
|
+
"undici": "^5.11.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@playwright/test": "^1.25.0",
|
|
28
|
+
"@types/connect": "^3.4.35",
|
|
29
|
+
"@types/marked": "^4.0.3",
|
|
30
|
+
"@types/mime": "^3.0.0",
|
|
31
|
+
"@types/node": "^16.11.36",
|
|
32
|
+
"@types/sade": "^1.7.4",
|
|
33
|
+
"@types/set-cookie-parser": "^2.4.2",
|
|
34
|
+
"marked": "^4.0.16",
|
|
35
|
+
"rollup": "^2.78.1",
|
|
36
|
+
"svelte": "^3.48.0",
|
|
37
|
+
"svelte-preprocess": "^4.10.6",
|
|
38
|
+
"typescript": "^4.8.2",
|
|
39
|
+
"uvu": "^0.5.3",
|
|
40
|
+
"vite": "^3.1.1"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"svelte": "^3.44.0",
|
|
44
|
+
"vite": "^3.1.0"
|
|
45
|
+
},
|
|
46
|
+
"bin": {
|
|
47
|
+
"svelte-kit": "svelte-kit.js"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"src",
|
|
51
|
+
"!src/**/*.spec.js",
|
|
52
|
+
"!src/core/**/fixtures",
|
|
53
|
+
"!src/core/**/test",
|
|
54
|
+
"types",
|
|
55
|
+
"svelte-kit.js",
|
|
56
|
+
"postinstall.js",
|
|
57
|
+
"scripts/special-types"
|
|
58
|
+
],
|
|
59
|
+
"exports": {
|
|
60
|
+
"./package.json": "./package.json",
|
|
61
|
+
".": {
|
|
62
|
+
"types": "./types/index.d.ts",
|
|
63
|
+
"import": "./src/exports/index.js"
|
|
64
|
+
},
|
|
65
|
+
"./node": {
|
|
66
|
+
"import": "./src/exports/node/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./node/polyfills": {
|
|
69
|
+
"import": "./src/exports/node/polyfills.js"
|
|
70
|
+
},
|
|
71
|
+
"./hooks": {
|
|
72
|
+
"import": "./src/exports/hooks/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./vite": {
|
|
75
|
+
"import": "./src/exports/vite/index.js"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"types": "types/index.d.ts",
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=16.14"
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"build": "npm run types",
|
|
84
|
+
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
|
|
85
|
+
"check": "tsc",
|
|
86
|
+
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
|
|
87
|
+
"format": "npm run lint -- --write",
|
|
88
|
+
"test": "npm run test:unit && npm run test:integration",
|
|
89
|
+
"test:integration": "pnpm run -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
90
|
+
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
|
|
91
|
+
"types": "node scripts/extract-types.js",
|
|
92
|
+
"postinstall": "node postinstall.js"
|
|
93
|
+
}
|
|
94
|
+
}
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import glob from 'tiny-glob/sync.js';
|
|
4
|
+
import { load_config } from './src/core/config/index.js';
|
|
5
|
+
import * as sync from './src/core/sync/sync.js';
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const cwd = process.env.INIT_CWD ?? process.cwd();
|
|
9
|
+
process.chdir(cwd);
|
|
10
|
+
|
|
11
|
+
if (fs.existsSync('package.json')) {
|
|
12
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
13
|
+
|
|
14
|
+
const directories = [];
|
|
15
|
+
|
|
16
|
+
if (pkg.workspaces) {
|
|
17
|
+
// we have to do this because of https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
|
|
18
|
+
const packages = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages;
|
|
19
|
+
|
|
20
|
+
for (const directory of packages) {
|
|
21
|
+
directories.push(...glob(directory, { cwd }).map((dir) => path.resolve(cwd, dir)));
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
directories.push(cwd);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const cwd of directories) {
|
|
28
|
+
process.chdir(cwd);
|
|
29
|
+
|
|
30
|
+
if (!fs.existsSync('package.json')) continue;
|
|
31
|
+
if (!fs.existsSync('svelte.config.js')) continue;
|
|
32
|
+
|
|
33
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
34
|
+
if (!pkg.dependencies?.['@sveltejs/kit'] && !pkg.devDependencies?.['@sveltejs/kit']) continue;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const config = await load_config();
|
|
38
|
+
await sync.all(config, 'development');
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.log('Error while trying to sync SvelteKit config');
|
|
41
|
+
console.log(error.stack);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(error.stack);
|
|
47
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
This module provides access to runtime environment variables, as defined by the platform you're running on. For example if you're using [`adapter-node`](https://github.com/sveltejs/kit/tree/master/packages/adapter-node) (or running [`vite preview`](https://kit.svelte.dev/docs/cli)), this is equivalent to `process.env`. This module only includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env).
|
|
2
|
+
|
|
3
|
+
This module cannot be imported into public-facing code.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { env } from '$env/dynamic/private';
|
|
7
|
+
console.log(env.DEPLOYMENT_SPECIFIC_VARIABLE);
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
> In `dev`, `$env/dynamic` always includes environment variables from `.env`. In `prod`, this behavior will depend on your adapter.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Similar to [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), but only includes variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env) (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code.
|
|
2
|
+
|
|
3
|
+
Note that public dynamic environment variables must all be sent from the server to the client, causing larger network requests — when possible, use `$env/static/public` instead.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { env } from '$env/dynamic/public';
|
|
7
|
+
console.log(env.PUBLIC_DEPLOYMENT_SPECIFIC_VARIABLE);
|
|
8
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Environment variables [loaded by Vite](https://vitejs.dev/guide/env-and-mode.html#env-files) from `.env` files and `process.env`. Like [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), this module cannot be imported into public-facing code. This module only includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env).
|
|
2
|
+
|
|
3
|
+
_Unlike_ [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), the values exported from this module are statically injected into your bundle at build time, enabling optimisations like dead code elimination.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { API_KEY } from '$env/static/private';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Note that all environment variables referenced in your code should be declared (for example in an `.env` file), even if they don't have a value until the app is deployed:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
MY_FEATURE_FLAG=""
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You can override `.env` values from the command line like so:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
MY_FEATURE_FLAG="enabled" npm run dev
|
|
19
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Similar to [`$env/static/private`](https://kit.svelte.dev/docs/modules#$env-static-private), except that it only includes environment variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env) (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code.
|
|
2
|
+
|
|
3
|
+
Values are replaced statically at build time.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { PUBLIC_BASE_URL } from '$env/static/public';
|
|
7
|
+
```
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
This is a simple alias to `src/lib`, or whatever directory is specified as [`config.kit.files.lib`](https://kit.svelte.dev/docs/configuration#files). It allows you to access common components and utility modules without `../../../../` nonsense.
|
|
2
|
+
|
|
3
|
+
#### `$lib/server`
|
|
4
|
+
|
|
5
|
+
A subdirectory of `$lib`. SvelteKit will prevent you from importing any modules in `$lib/server` into public-facing code. See [server-only modules](/docs/server-only-modules).
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import colors from 'kleur';
|
|
4
|
+
import sade from 'sade';
|
|
5
|
+
import { load_config } from './core/config/index.js';
|
|
6
|
+
import { coalesce_to_error } from './utils/error.js';
|
|
7
|
+
|
|
8
|
+
/** @param {unknown} e */
|
|
9
|
+
function handle_error(e) {
|
|
10
|
+
const error = coalesce_to_error(e);
|
|
11
|
+
|
|
12
|
+
if (error.name === 'SyntaxError') throw error;
|
|
13
|
+
|
|
14
|
+
console.error(colors.bold().red(`> ${error.message}`));
|
|
15
|
+
if (error.stack) {
|
|
16
|
+
console.error(colors.gray(error.stack.split('\n').slice(1).join('\n')));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
23
|
+
const prog = sade('svelte-kit').version(pkg.version);
|
|
24
|
+
|
|
25
|
+
prog
|
|
26
|
+
.command('sync')
|
|
27
|
+
.describe('Synchronise generated files')
|
|
28
|
+
.option('--mode', 'Specify a mode for loading environment variables', 'development')
|
|
29
|
+
.action(async ({ mode }) => {
|
|
30
|
+
const event = process.env.npm_lifecycle_event;
|
|
31
|
+
|
|
32
|
+
// TODO remove for 1.0
|
|
33
|
+
if (event === 'prepare') {
|
|
34
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
35
|
+
const message =
|
|
36
|
+
pkg.scripts.prepare === 'svelte-kit sync'
|
|
37
|
+
? `\`svelte-kit sync\` now runs on "postinstall" — please remove the "prepare" script from your package.json\n`
|
|
38
|
+
: `\`svelte-kit sync\` now runs on "postinstall" — please remove it from your "prepare" script\n`;
|
|
39
|
+
|
|
40
|
+
console.error(colors.bold().red(message));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!fs.existsSync('svelte.config.js')) {
|
|
45
|
+
console.warn(`Missing ${path.resolve('svelte.config.js')} — skipping`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const config = await load_config();
|
|
51
|
+
const sync = await import('./core/sync/sync.js');
|
|
52
|
+
await sync.all(config, mode);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
handle_error(error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// TODO remove for 1.0
|
|
59
|
+
replace('dev');
|
|
60
|
+
replace('build');
|
|
61
|
+
replace('preview');
|
|
62
|
+
prog
|
|
63
|
+
.command('package')
|
|
64
|
+
.describe('No longer available - use @sveltejs/package instead')
|
|
65
|
+
.action(() => {
|
|
66
|
+
console.error(
|
|
67
|
+
'svelte-kit package has been removed. It now lives in its own npm package. See the PR on how to migrate: https://github.com/sveltejs/kit/pull/5730'
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
|
|
72
|
+
|
|
73
|
+
/** @param {string} command */
|
|
74
|
+
function replace(command) {
|
|
75
|
+
prog
|
|
76
|
+
.command(command)
|
|
77
|
+
.describe(`No longer available — use vite ${command} instead`)
|
|
78
|
+
.action(async () => {
|
|
79
|
+
const message = `\n> svelte-kit ${command} is no longer available — use vite ${command} instead`;
|
|
80
|
+
console.error(colors.bold().red(message));
|
|
81
|
+
|
|
82
|
+
const steps = [
|
|
83
|
+
'Install vite as a devDependency with npm/pnpm/etc',
|
|
84
|
+
'Create a vite.config.js with the @sveltejs/kit/vite plugin (see below)',
|
|
85
|
+
`Update your package.json scripts to reference \`vite ${command}\` instead of \`svelte-kit ${command}\``
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
steps.forEach((step, i) => {
|
|
89
|
+
console.error(` ${i + 1}. ${colors.cyan(step)}`);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
console.error(
|
|
93
|
+
`
|
|
94
|
+
${colors.grey('// vite.config.js')}
|
|
95
|
+
import { sveltekit } from '@sveltejs/kit/vite';
|
|
96
|
+
|
|
97
|
+
/** @type {import('vite').UserConfig} */
|
|
98
|
+
const config = {
|
|
99
|
+
plugins: [sveltekit()]
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export default config;
|
|
103
|
+
|
|
104
|
+
`.replace(/^\t{4}/gm, '')
|
|
105
|
+
);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
});
|
|
108
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// in `vite dev` and `vite preview`, we use a fake asset path so that we can
|
|
2
|
+
// serve local assets while verifying that requests are correctly prefixed
|
|
3
|
+
export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
|
|
4
|
+
|
|
5
|
+
export const GENERATED_COMMENT = '// this file is generated — do not edit it\n';
|
|
6
|
+
|
|
7
|
+
export const DATA_SUFFIX = '/__data.js';
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import glob from 'tiny-glob';
|
|
2
|
+
import zlib from 'zlib';
|
|
3
|
+
import { existsSync, statSync, createReadStream, createWriteStream } from 'fs';
|
|
4
|
+
import { pipeline } from 'stream';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import { copy, rimraf, mkdirp } from '../../utils/filesystem.js';
|
|
7
|
+
import { generate_manifest } from '../generate_manifest/index.js';
|
|
8
|
+
|
|
9
|
+
const pipe = promisify(pipeline);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates the Builder which is passed to adapters for building the application.
|
|
13
|
+
* @param {{
|
|
14
|
+
* config: import('types').ValidatedConfig;
|
|
15
|
+
* build_data: import('types').BuildData;
|
|
16
|
+
* routes: import('types').RouteData[];
|
|
17
|
+
* prerendered: import('types').Prerendered;
|
|
18
|
+
* log: import('types').Logger;
|
|
19
|
+
* }} opts
|
|
20
|
+
* @returns {import('types').Builder}
|
|
21
|
+
*/
|
|
22
|
+
export function create_builder({ config, build_data, routes, prerendered, log }) {
|
|
23
|
+
return {
|
|
24
|
+
log,
|
|
25
|
+
rimraf,
|
|
26
|
+
mkdirp,
|
|
27
|
+
copy,
|
|
28
|
+
|
|
29
|
+
config,
|
|
30
|
+
prerendered,
|
|
31
|
+
|
|
32
|
+
async createEntries(fn) {
|
|
33
|
+
/** @type {import('types').RouteDefinition[]} */
|
|
34
|
+
const facades = routes.map((route) => {
|
|
35
|
+
const methods = new Set();
|
|
36
|
+
|
|
37
|
+
if (route.page) {
|
|
38
|
+
methods.add('SET');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (route.endpoint) {
|
|
42
|
+
for (const method of build_data.server.methods[route.endpoint.file]) {
|
|
43
|
+
methods.add(method);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
id: route.id,
|
|
49
|
+
segments: route.id.split('/').map((segment) => ({
|
|
50
|
+
dynamic: segment.includes('['),
|
|
51
|
+
rest: segment.includes('[...'),
|
|
52
|
+
content: segment
|
|
53
|
+
})),
|
|
54
|
+
pattern: route.pattern,
|
|
55
|
+
methods: Array.from(methods)
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < routes.length; i += 1) {
|
|
62
|
+
const route = routes[i];
|
|
63
|
+
const { id, filter, complete } = fn(facades[i]);
|
|
64
|
+
|
|
65
|
+
if (seen.has(id)) continue;
|
|
66
|
+
seen.add(id);
|
|
67
|
+
|
|
68
|
+
const group = [route];
|
|
69
|
+
|
|
70
|
+
// figure out which lower priority routes should be considered fallbacks
|
|
71
|
+
for (let j = i + 1; j < routes.length; j += 1) {
|
|
72
|
+
if (filter(facades[j])) {
|
|
73
|
+
group.push(routes[j]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const filtered = new Set(group);
|
|
78
|
+
|
|
79
|
+
// heuristic: if /foo/[bar] is included, /foo/[bar].json should
|
|
80
|
+
// also be included, since the page likely needs the endpoint
|
|
81
|
+
// TODO is this still necessary, given the new way of doing things?
|
|
82
|
+
filtered.forEach((route) => {
|
|
83
|
+
if (route.page) {
|
|
84
|
+
const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
|
|
85
|
+
|
|
86
|
+
if (endpoint) {
|
|
87
|
+
filtered.add(endpoint);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (filtered.size > 0) {
|
|
93
|
+
await complete({
|
|
94
|
+
generateManifest: ({ relativePath, format }) =>
|
|
95
|
+
generate_manifest({
|
|
96
|
+
build_data,
|
|
97
|
+
relative_path: relativePath,
|
|
98
|
+
routes: Array.from(filtered),
|
|
99
|
+
format
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
generateManifest: ({ relativePath, format }) => {
|
|
107
|
+
return generate_manifest({
|
|
108
|
+
build_data,
|
|
109
|
+
relative_path: relativePath,
|
|
110
|
+
routes,
|
|
111
|
+
format
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
getBuildDirectory(name) {
|
|
116
|
+
return `${config.kit.outDir}/${name}`;
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
getClientDirectory() {
|
|
120
|
+
return `${config.kit.outDir}/output/client`;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
getServerDirectory() {
|
|
124
|
+
return `${config.kit.outDir}/output/server`;
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
getStaticDirectory() {
|
|
128
|
+
return config.kit.files.assets;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
writeClient(dest) {
|
|
132
|
+
return [...copy(`${config.kit.outDir}/output/client`, dest)];
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
writePrerendered(dest, { fallback } = {}) {
|
|
136
|
+
const source = `${config.kit.outDir}/output/prerendered`;
|
|
137
|
+
const files = [...copy(`${source}/pages`, dest), ...copy(`${source}/dependencies`, dest)];
|
|
138
|
+
|
|
139
|
+
if (fallback) {
|
|
140
|
+
files.push(fallback);
|
|
141
|
+
copy(`${source}/fallback.html`, `${dest}/${fallback}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return files;
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
writeServer(dest) {
|
|
148
|
+
return copy(`${config.kit.outDir}/output/server`, dest);
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
// TODO remove these methods for 1.0
|
|
152
|
+
// @ts-expect-error
|
|
153
|
+
writeStatic() {
|
|
154
|
+
throw new Error(
|
|
155
|
+
`writeStatic has been removed. Please ensure you are using the latest version of ${
|
|
156
|
+
config.kit.adapter.name || 'your adapter'
|
|
157
|
+
}`
|
|
158
|
+
);
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
async compress(directory) {
|
|
162
|
+
if (!existsSync(directory)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', {
|
|
167
|
+
cwd: directory,
|
|
168
|
+
dot: true,
|
|
169
|
+
absolute: true,
|
|
170
|
+
filesOnly: true
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
await Promise.all(
|
|
174
|
+
files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')]))
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
async prerender() {
|
|
179
|
+
throw new Error(
|
|
180
|
+
'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @param {string} file
|
|
188
|
+
* @param {'gz' | 'br'} format
|
|
189
|
+
*/
|
|
190
|
+
async function compress_file(file, format = 'gz') {
|
|
191
|
+
const compress =
|
|
192
|
+
format == 'br'
|
|
193
|
+
? zlib.createBrotliCompress({
|
|
194
|
+
params: {
|
|
195
|
+
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
|
|
196
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
|
|
197
|
+
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: statSync(file).size
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
: zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION });
|
|
201
|
+
|
|
202
|
+
const source = createReadStream(file);
|
|
203
|
+
const destination = createWriteStream(`${file}.${format}`);
|
|
204
|
+
|
|
205
|
+
await pipe(source, compress, destination);
|
|
206
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import colors from 'kleur';
|
|
2
|
+
import { create_builder } from './builder.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {import('types').ValidatedConfig} config
|
|
6
|
+
* @param {import('types').BuildData} build_data
|
|
7
|
+
* @param {import('types').Prerendered} prerendered
|
|
8
|
+
* @param {import('types').PrerenderMap} prerender_map
|
|
9
|
+
* @param {{ log: import('types').Logger }} opts
|
|
10
|
+
*/
|
|
11
|
+
export async function adapt(config, build_data, prerendered, prerender_map, { log }) {
|
|
12
|
+
const { name, adapt } = config.kit.adapter;
|
|
13
|
+
|
|
14
|
+
console.log(colors.bold().cyan(`\n> Using ${name}`));
|
|
15
|
+
|
|
16
|
+
const builder = create_builder({
|
|
17
|
+
config,
|
|
18
|
+
build_data,
|
|
19
|
+
routes: build_data.manifest_data.routes.filter((route) => {
|
|
20
|
+
if (!route.page && !route.endpoint) return false;
|
|
21
|
+
|
|
22
|
+
const prerender = prerender_map.get(route.id);
|
|
23
|
+
return prerender === false || prerender === undefined || prerender === 'auto';
|
|
24
|
+
}),
|
|
25
|
+
prerendered,
|
|
26
|
+
log
|
|
27
|
+
});
|
|
28
|
+
await adapt(builder);
|
|
29
|
+
|
|
30
|
+
log.success('done');
|
|
31
|
+
}
|