@sveltejs/kit 1.0.0-next.46 → 1.0.0-next.462

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.
Files changed (115) hide show
  1. package/README.md +12 -9
  2. package/package.json +93 -65
  3. package/scripts/special-types/$env+dynamic+private.md +8 -0
  4. package/scripts/special-types/$env+dynamic+public.md +8 -0
  5. package/scripts/special-types/$env+static+private.md +19 -0
  6. package/scripts/special-types/$env+static+public.md +7 -0
  7. package/scripts/special-types/$lib.md +1 -0
  8. package/src/cli.js +112 -0
  9. package/src/constants.js +7 -0
  10. package/src/core/adapt/builder.js +207 -0
  11. package/src/core/adapt/index.js +31 -0
  12. package/src/core/config/default-error.html +56 -0
  13. package/src/core/config/index.js +105 -0
  14. package/src/core/config/options.js +502 -0
  15. package/src/core/config/types.d.ts +1 -0
  16. package/src/core/env.js +112 -0
  17. package/src/core/generate_manifest/index.js +78 -0
  18. package/src/core/prerender/crawl.js +194 -0
  19. package/src/core/prerender/prerender.js +425 -0
  20. package/src/core/prerender/queue.js +80 -0
  21. package/src/core/sync/create_manifest_data/index.js +452 -0
  22. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  23. package/src/core/sync/sync.js +59 -0
  24. package/src/core/sync/utils.js +33 -0
  25. package/src/core/sync/write_ambient.js +53 -0
  26. package/src/core/sync/write_client_manifest.js +94 -0
  27. package/src/core/sync/write_matchers.js +25 -0
  28. package/src/core/sync/write_root.js +91 -0
  29. package/src/core/sync/write_tsconfig.js +195 -0
  30. package/src/core/sync/write_types/index.js +595 -0
  31. package/src/core/utils.js +70 -0
  32. package/src/exports/hooks/index.js +1 -0
  33. package/src/exports/hooks/sequence.js +44 -0
  34. package/src/exports/index.js +45 -0
  35. package/src/exports/node/index.js +145 -0
  36. package/src/exports/node/polyfills.js +40 -0
  37. package/src/exports/vite/build/build_server.js +352 -0
  38. package/src/exports/vite/build/build_service_worker.js +90 -0
  39. package/src/exports/vite/build/utils.js +160 -0
  40. package/src/exports/vite/dev/index.js +546 -0
  41. package/src/exports/vite/index.js +595 -0
  42. package/src/exports/vite/preview/index.js +186 -0
  43. package/src/exports/vite/types.d.ts +3 -0
  44. package/src/exports/vite/utils.js +345 -0
  45. package/src/runtime/app/env.js +1 -0
  46. package/src/runtime/app/environment.js +11 -0
  47. package/src/runtime/app/navigation.js +23 -0
  48. package/src/runtime/app/paths.js +1 -0
  49. package/src/runtime/app/stores.js +102 -0
  50. package/src/runtime/client/ambient.d.ts +24 -0
  51. package/src/runtime/client/client.js +1400 -0
  52. package/src/runtime/client/fetcher.js +60 -0
  53. package/src/runtime/client/parse.js +60 -0
  54. package/src/runtime/client/singletons.js +21 -0
  55. package/src/runtime/client/start.js +45 -0
  56. package/src/runtime/client/types.d.ts +90 -0
  57. package/src/runtime/client/utils.js +140 -0
  58. package/src/runtime/components/error.svelte +16 -0
  59. package/{assets → src/runtime}/components/layout.svelte +0 -0
  60. package/src/runtime/control.js +33 -0
  61. package/src/runtime/env/dynamic/private.js +1 -0
  62. package/src/runtime/env/dynamic/public.js +1 -0
  63. package/src/runtime/env-private.js +6 -0
  64. package/src/runtime/env-public.js +6 -0
  65. package/src/runtime/env.js +6 -0
  66. package/src/runtime/hash.js +16 -0
  67. package/src/runtime/paths.js +11 -0
  68. package/src/runtime/server/data/index.js +146 -0
  69. package/src/runtime/server/endpoint.js +63 -0
  70. package/src/runtime/server/index.js +354 -0
  71. package/src/runtime/server/page/cookie.js +25 -0
  72. package/src/runtime/server/page/crypto.js +239 -0
  73. package/src/runtime/server/page/csp.js +249 -0
  74. package/src/runtime/server/page/fetch.js +269 -0
  75. package/src/runtime/server/page/index.js +404 -0
  76. package/src/runtime/server/page/load_data.js +124 -0
  77. package/src/runtime/server/page/render.js +358 -0
  78. package/src/runtime/server/page/respond_with_error.js +92 -0
  79. package/src/runtime/server/page/serialize_data.js +58 -0
  80. package/src/runtime/server/page/types.d.ts +44 -0
  81. package/src/runtime/server/utils.js +209 -0
  82. package/src/utils/array.js +9 -0
  83. package/src/utils/error.js +22 -0
  84. package/src/utils/escape.js +46 -0
  85. package/src/utils/filesystem.js +108 -0
  86. package/src/utils/functions.js +16 -0
  87. package/src/utils/http.js +55 -0
  88. package/src/utils/misc.js +1 -0
  89. package/src/utils/routing.js +137 -0
  90. package/src/utils/url.js +142 -0
  91. package/svelte-kit.js +1 -1
  92. package/types/ambient.d.ts +347 -0
  93. package/types/index.d.ts +346 -0
  94. package/types/internal.d.ts +386 -0
  95. package/types/private.d.ts +213 -0
  96. package/CHANGELOG.md +0 -456
  97. package/assets/components/error.svelte +0 -13
  98. package/assets/runtime/app/env.js +0 -5
  99. package/assets/runtime/app/navigation.js +0 -44
  100. package/assets/runtime/app/paths.js +0 -1
  101. package/assets/runtime/app/stores.js +0 -93
  102. package/assets/runtime/chunks/utils.js +0 -22
  103. package/assets/runtime/internal/singletons.js +0 -23
  104. package/assets/runtime/internal/start.js +0 -771
  105. package/assets/runtime/paths.js +0 -12
  106. package/dist/chunks/index.js +0 -3522
  107. package/dist/chunks/index2.js +0 -587
  108. package/dist/chunks/index3.js +0 -246
  109. package/dist/chunks/index4.js +0 -539
  110. package/dist/chunks/index5.js +0 -763
  111. package/dist/chunks/index6.js +0 -322
  112. package/dist/chunks/standard.js +0 -99
  113. package/dist/chunks/utils.js +0 -83
  114. package/dist/cli.js +0 -546
  115. package/dist/ssr.js +0 -2581
package/README.md CHANGED
@@ -1,15 +1,18 @@
1
- # @sveltejs/kit
1
+ # The fastest way to build Svelte apps
2
2
 
3
- Here be dragons, etc etc.
3
+ This is the [SvelteKit](https://kit.svelte.dev) framework and CLI.
4
4
 
5
- This project aims to replicate Sapper's functionality in its entirety, minus building for deployment (which can be handled by 'adapters' that do various opinionated things with the output of `snowpack build`).
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
- It's currently missing a ton of stuff but I figured I'd throw it up on GitHub anyway partly for the sake of 'working in the open' but mostly because I need an issue tracker to organise my thoughts.
7
+ ```bash
8
+ npm create svelte@latest my-app
9
+ cd my-app
10
+ npm install
11
+ npm run dev
12
+ ```
8
13
 
9
- There are no tests yet or anything like that. Some of the code has just been straight copied over from the existing Sapper repo, but a pleasing amount of it can safely be left behind.
14
+ See the [documentation](https://kit.svelte.dev/docs) to learn more.
10
15
 
11
- ## Trying it out
16
+ ## Changelog
12
17
 
13
- Clone this repo, `npm install`, and `npm link`. That will create a global link to the `svelte` bin. You can then either `npm run build` or `npm run dev`, if you intend to make changes and see them immediately reflected.
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,66 +1,94 @@
1
1
  {
2
- "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.46",
4
- "type": "module",
5
- "dependencies": {
6
- "@sveltejs/vite-plugin-svelte": "1.0.0-next.3",
7
- "@svitejs/vite-plugin-svelte": "^0.10.0",
8
- "cheap-watch": "^1.0.3",
9
- "sade": "^1.7.4"
10
- },
11
- "devDependencies": {
12
- "@rollup/plugin-replace": "^2.4.1",
13
- "@sveltejs/app-utils": "1.0.0-next.3",
14
- "@types/amphtml-validator": "^1.0.1",
15
- "@types/mime": "^2.0.3",
16
- "@types/node": "^14.14.33",
17
- "@types/rimraf": "^3.0.0",
18
- "@types/sade": "^1.7.2",
19
- "amphtml-validator": "^1.0.34",
20
- "devalue": "^2.0.1",
21
- "eslint": "^7.21.0",
22
- "kleur": "^4.1.4",
23
- "node-fetch": "^3.0.0-beta.9",
24
- "port-authority": "^1.1.2",
25
- "rimraf": "^3.0.2",
26
- "rollup": "^2.41.1",
27
- "sirv": "^1.0.11",
28
- "svelte": "^3.35.0",
29
- "tiny-glob": "^0.2.8",
30
- "typescript": "^4.2.3",
31
- "uvu": "^0.5.1",
32
- "vite": "^2.0.5"
33
- },
34
- "peerDependencies": {
35
- "svelte": "^3.32.1",
36
- "vite": "^2.0.4"
37
- },
38
- "bin": {
39
- "svelte-kit": "svelte-kit.js"
40
- },
41
- "files": [
42
- "assets",
43
- "dist",
44
- "client"
45
- ],
46
- "scripts": {
47
- "dev": "rm -rf assets/runtime && rollup -cw",
48
- "build": "rm -rf assets/runtime && rollup -c",
49
- "lint": "eslint --ignore-path .gitignore \"src/**/*.{ts,mjs,js,svelte}\" && npm run check-format",
50
- "check": "npx tsc -p tsconfig.enforced.json",
51
- "check-all": "npx tsc -p tsconfig.all.json",
52
- "format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore",
53
- "check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
54
- "prepublishOnly": "npm run build",
55
- "test": "npm run test:unit && npm run test:integration",
56
- "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
57
- "test:integration": "uvu test test.js"
58
- },
59
- "exports": {
60
- "./package.json": "./package.json",
61
- "./ssr": {
62
- "import": "./dist/ssr.js"
63
- }
64
- },
65
- "types": "types.d.ts"
66
- }
2
+ "name": "@sveltejs/kit",
3
+ "version": "1.0.0-next.462",
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.3",
14
+ "cookie": "^0.5.0",
15
+ "devalue": "^3.1.2",
16
+ "kleur": "^4.1.4",
17
+ "magic-string": "^0.26.2",
18
+ "mime": "^3.0.0",
19
+ "node-fetch": "^3.2.4",
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.8.1"
25
+ },
26
+ "devDependencies": {
27
+ "@playwright/test": "^1.25.0",
28
+ "@types/connect": "^3.4.35",
29
+ "@types/cookie": "^0.5.1",
30
+ "@types/marked": "^4.0.3",
31
+ "@types/mime": "^3.0.0",
32
+ "@types/node": "^16.11.36",
33
+ "@types/sade": "^1.7.4",
34
+ "@types/set-cookie-parser": "^2.4.2",
35
+ "marked": "^4.0.16",
36
+ "rollup": "^2.78.1",
37
+ "svelte": "^3.48.0",
38
+ "svelte-preprocess": "^4.10.6",
39
+ "typescript": "^4.8.2",
40
+ "uvu": "^0.5.3",
41
+ "vite": "^3.1.0-beta.1"
42
+ },
43
+ "peerDependencies": {
44
+ "svelte": "^3.44.0",
45
+ "vite": "^3.1.0-beta.1"
46
+ },
47
+ "bin": {
48
+ "svelte-kit": "svelte-kit.js"
49
+ },
50
+ "files": [
51
+ "src",
52
+ "!src/**/*.spec.js",
53
+ "!src/core/**/fixtures",
54
+ "!src/core/**/test",
55
+ "types",
56
+ "svelte-kit.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 svelte-kit.js sync"
93
+ }
94
+ }
@@ -0,0 +1,8 @@
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#kit-env-publicprefix).
2
+
3
+ This module cannot be imported into client-side code.
4
+
5
+ ```ts
6
+ import { env } from '$env/dynamic/private';
7
+ console.log(env.DEPLOYMENT_SPECIFIC_VARIABLE);
8
+ ```
@@ -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#kit-env-publicprefix) (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 client-side code. This module only includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#kit-env-publicprefix).
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#kit-env-publicprefix) (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 @@
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.
package/src/cli.js ADDED
@@ -0,0 +1,112 @@
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 (event === 'postinstall' && process.env.INIT_CWD) {
45
+ process.chdir(process.env.INIT_CWD);
46
+ }
47
+
48
+ if (!fs.existsSync('svelte.config.js')) {
49
+ console.warn(`Missing ${path.resolve('svelte.config.js')} — skipping`);
50
+ return;
51
+ }
52
+
53
+ try {
54
+ const config = await load_config();
55
+ const sync = await import('./core/sync/sync.js');
56
+ await sync.all(config, mode);
57
+ } catch (error) {
58
+ handle_error(error);
59
+ }
60
+ });
61
+
62
+ // TODO remove for 1.0
63
+ replace('dev');
64
+ replace('build');
65
+ replace('preview');
66
+ prog
67
+ .command('package')
68
+ .describe('No longer available - use @sveltejs/package instead')
69
+ .action(() => {
70
+ console.error(
71
+ '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'
72
+ );
73
+ });
74
+
75
+ prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
76
+
77
+ /** @param {string} command */
78
+ function replace(command) {
79
+ prog
80
+ .command(command)
81
+ .describe(`No longer available — use vite ${command} instead`)
82
+ .action(async () => {
83
+ const message = `\n> svelte-kit ${command} is no longer available — use vite ${command} instead`;
84
+ console.error(colors.bold().red(message));
85
+
86
+ const steps = [
87
+ 'Install vite as a devDependency with npm/pnpm/etc',
88
+ 'Create a vite.config.js with the @sveltejs/kit/vite plugin (see below)',
89
+ `Update your package.json scripts to reference \`vite ${command}\` instead of \`svelte-kit ${command}\``
90
+ ];
91
+
92
+ steps.forEach((step, i) => {
93
+ console.error(` ${i + 1}. ${colors.cyan(step)}`);
94
+ });
95
+
96
+ console.error(
97
+ `
98
+ ${colors.grey('// vite.config.js')}
99
+ import { sveltekit } from '@sveltejs/kit/vite';
100
+
101
+ /** @type {import('vite').UserConfig} */
102
+ const config = {
103
+ plugins: [sveltekit()]
104
+ };
105
+
106
+ export default config;
107
+
108
+ `.replace(/^\t{4}/gm, '')
109
+ );
110
+ process.exit(1);
111
+ });
112
+ }
@@ -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,207 @@
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
+ type: route.page ? 'page' : 'endpoint', // TODO change this if support pages+endpoints
50
+ segments: route.id.split('/').map((segment) => ({
51
+ dynamic: segment.includes('['),
52
+ rest: segment.includes('[...'),
53
+ content: segment
54
+ })),
55
+ pattern: route.pattern,
56
+ methods: Array.from(methods)
57
+ };
58
+ });
59
+
60
+ const seen = new Set();
61
+
62
+ for (let i = 0; i < routes.length; i += 1) {
63
+ const route = routes[i];
64
+ const { id, filter, complete } = fn(facades[i]);
65
+
66
+ if (seen.has(id)) continue;
67
+ seen.add(id);
68
+
69
+ const group = [route];
70
+
71
+ // figure out which lower priority routes should be considered fallbacks
72
+ for (let j = i + 1; j < routes.length; j += 1) {
73
+ if (filter(facades[j])) {
74
+ group.push(routes[j]);
75
+ }
76
+ }
77
+
78
+ const filtered = new Set(group);
79
+
80
+ // heuristic: if /foo/[bar] is included, /foo/[bar].json should
81
+ // also be included, since the page likely needs the endpoint
82
+ // TODO is this still necessary, given the new way of doing things?
83
+ filtered.forEach((route) => {
84
+ if (route.page) {
85
+ const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
86
+
87
+ if (endpoint) {
88
+ filtered.add(endpoint);
89
+ }
90
+ }
91
+ });
92
+
93
+ if (filtered.size > 0) {
94
+ await complete({
95
+ generateManifest: ({ relativePath, format }) =>
96
+ generate_manifest({
97
+ build_data,
98
+ relative_path: relativePath,
99
+ routes: Array.from(filtered),
100
+ format
101
+ })
102
+ });
103
+ }
104
+ }
105
+ },
106
+
107
+ generateManifest: ({ relativePath, format }) => {
108
+ return generate_manifest({
109
+ build_data,
110
+ relative_path: relativePath,
111
+ routes,
112
+ format
113
+ });
114
+ },
115
+
116
+ getBuildDirectory(name) {
117
+ return `${config.kit.outDir}/${name}`;
118
+ },
119
+
120
+ getClientDirectory() {
121
+ return `${config.kit.outDir}/output/client`;
122
+ },
123
+
124
+ getServerDirectory() {
125
+ return `${config.kit.outDir}/output/server`;
126
+ },
127
+
128
+ getStaticDirectory() {
129
+ return config.kit.files.assets;
130
+ },
131
+
132
+ writeClient(dest) {
133
+ return [...copy(`${config.kit.outDir}/output/client`, dest)];
134
+ },
135
+
136
+ writePrerendered(dest, { fallback } = {}) {
137
+ const source = `${config.kit.outDir}/output/prerendered`;
138
+ const files = [...copy(`${source}/pages`, dest), ...copy(`${source}/dependencies`, dest)];
139
+
140
+ if (fallback) {
141
+ files.push(fallback);
142
+ copy(`${source}/fallback.html`, `${dest}/${fallback}`);
143
+ }
144
+
145
+ return files;
146
+ },
147
+
148
+ writeServer(dest) {
149
+ return copy(`${config.kit.outDir}/output/server`, dest);
150
+ },
151
+
152
+ // TODO remove these methods for 1.0
153
+ // @ts-expect-error
154
+ writeStatic() {
155
+ throw new Error(
156
+ `writeStatic has been removed. Please ensure you are using the latest version of ${
157
+ config.kit.adapter.name || 'your adapter'
158
+ }`
159
+ );
160
+ },
161
+
162
+ async compress(directory) {
163
+ if (!existsSync(directory)) {
164
+ return;
165
+ }
166
+
167
+ const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', {
168
+ cwd: directory,
169
+ dot: true,
170
+ absolute: true,
171
+ filesOnly: true
172
+ });
173
+
174
+ await Promise.all(
175
+ files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')]))
176
+ );
177
+ },
178
+
179
+ async prerender() {
180
+ throw new Error(
181
+ 'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
182
+ );
183
+ }
184
+ };
185
+ }
186
+
187
+ /**
188
+ * @param {string} file
189
+ * @param {'gz' | 'br'} format
190
+ */
191
+ async function compress_file(file, format = 'gz') {
192
+ const compress =
193
+ format == 'br'
194
+ ? zlib.createBrotliCompress({
195
+ params: {
196
+ [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
197
+ [zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
198
+ [zlib.constants.BROTLI_PARAM_SIZE_HINT]: statSync(file).size
199
+ }
200
+ })
201
+ : zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION });
202
+
203
+ const source = createReadStream(file);
204
+ const destination = createWriteStream(`${file}.${format}`);
205
+
206
+ await pipe(source, compress, destination);
207
+ }
@@ -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
+ }
@@ -0,0 +1,56 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>%sveltekit.message%</title>
6
+
7
+ <style>
8
+ body {
9
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
10
+ Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
11
+ display: flex;
12
+ align-items: center;
13
+ justify-content: center;
14
+ height: 100vh;
15
+ }
16
+
17
+ .error {
18
+ display: flex;
19
+ align-items: center;
20
+ max-width: 32rem;
21
+ margin: 0 1rem;
22
+ }
23
+
24
+ .status {
25
+ font-weight: 200;
26
+ font-size: 3rem;
27
+ line-height: 1;
28
+ position: relative;
29
+ top: -0.05rem;
30
+ }
31
+
32
+ .message {
33
+ border-left: 1px solid #ccc;
34
+ padding: 0 0 0 1rem;
35
+ margin: 0 0 0 1rem;
36
+ min-height: 2.5rem;
37
+ display: flex;
38
+ align-items: center;
39
+ }
40
+
41
+ .message h1 {
42
+ font-weight: 400;
43
+ font-size: 1em;
44
+ margin: 0;
45
+ }
46
+ </style>
47
+ </head>
48
+ <body>
49
+ <div class="error">
50
+ <span class="status">%sveltekit.status%</span>
51
+ <div class="message">
52
+ <h1>%sveltekit.message%</h1>
53
+ </div>
54
+ </div>
55
+ </body>
56
+ </html>