@sveltejs/kit 1.0.0-next.58 → 1.0.0-next.581

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 (134) hide show
  1. package/README.md +5 -2
  2. package/package.json +91 -73
  3. package/postinstall.js +47 -0
  4. package/src/cli.js +108 -0
  5. package/src/constants.js +5 -0
  6. package/src/core/adapt/builder.js +237 -0
  7. package/src/core/adapt/index.js +31 -0
  8. package/src/core/config/default-error.html +56 -0
  9. package/src/core/config/index.js +110 -0
  10. package/src/core/config/options.js +524 -0
  11. package/src/core/config/types.d.ts +1 -0
  12. package/src/core/env.js +138 -0
  13. package/src/core/generate_manifest/index.js +116 -0
  14. package/src/core/prerender/crawl.js +207 -0
  15. package/src/core/prerender/entities.js +2252 -0
  16. package/src/core/prerender/fallback.js +43 -0
  17. package/src/core/prerender/prerender.js +462 -0
  18. package/src/core/prerender/queue.js +80 -0
  19. package/src/core/sync/create_manifest_data/conflict.js +0 -0
  20. package/src/core/sync/create_manifest_data/index.js +532 -0
  21. package/src/core/sync/create_manifest_data/sort.js +161 -0
  22. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  23. package/src/core/sync/sync.js +78 -0
  24. package/src/core/sync/utils.js +33 -0
  25. package/src/core/sync/write_ambient.js +58 -0
  26. package/src/core/sync/write_client_manifest.js +107 -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 +809 -0
  31. package/src/core/utils.js +67 -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 +55 -0
  35. package/src/exports/node/index.js +172 -0
  36. package/src/exports/node/polyfills.js +28 -0
  37. package/src/exports/vite/build/build_server.js +387 -0
  38. package/src/exports/vite/build/build_service_worker.js +92 -0
  39. package/src/exports/vite/build/utils.js +190 -0
  40. package/src/exports/vite/dev/index.js +598 -0
  41. package/src/exports/vite/graph_analysis/index.js +99 -0
  42. package/src/exports/vite/graph_analysis/types.d.ts +5 -0
  43. package/src/exports/vite/graph_analysis/utils.js +6 -0
  44. package/src/exports/vite/index.js +671 -0
  45. package/src/exports/vite/preview/index.js +194 -0
  46. package/src/exports/vite/types.d.ts +3 -0
  47. package/src/exports/vite/utils.js +180 -0
  48. package/src/runtime/app/env.js +1 -0
  49. package/src/runtime/app/environment.js +13 -0
  50. package/src/runtime/app/forms.js +144 -0
  51. package/src/runtime/app/navigation.js +32 -0
  52. package/src/runtime/app/paths.js +1 -0
  53. package/src/runtime/app/stores.js +102 -0
  54. package/src/runtime/client/ambient.d.ts +30 -0
  55. package/src/runtime/client/client.js +1884 -0
  56. package/src/runtime/client/constants.js +10 -0
  57. package/src/runtime/client/fetcher.js +127 -0
  58. package/src/runtime/client/parse.js +60 -0
  59. package/src/runtime/client/singletons.js +21 -0
  60. package/src/runtime/client/start.js +45 -0
  61. package/src/runtime/client/types.d.ts +86 -0
  62. package/src/runtime/client/utils.js +257 -0
  63. package/src/runtime/components/error.svelte +16 -0
  64. package/{assets → src/runtime}/components/layout.svelte +0 -0
  65. package/src/runtime/control.js +45 -0
  66. package/src/runtime/env/dynamic/private.js +1 -0
  67. package/src/runtime/env/dynamic/public.js +1 -0
  68. package/src/runtime/env-private.js +6 -0
  69. package/src/runtime/env-public.js +6 -0
  70. package/src/runtime/env.js +12 -0
  71. package/src/runtime/hash.js +20 -0
  72. package/src/runtime/paths.js +11 -0
  73. package/src/runtime/server/cookie.js +232 -0
  74. package/src/runtime/server/data/index.js +158 -0
  75. package/src/runtime/server/endpoint.js +89 -0
  76. package/src/runtime/server/fetch.js +175 -0
  77. package/src/runtime/server/index.js +449 -0
  78. package/src/runtime/server/page/actions.js +267 -0
  79. package/src/runtime/server/page/crypto.js +239 -0
  80. package/src/runtime/server/page/csp.js +250 -0
  81. package/src/runtime/server/page/index.js +302 -0
  82. package/src/runtime/server/page/load_data.js +284 -0
  83. package/src/runtime/server/page/render.js +410 -0
  84. package/src/runtime/server/page/respond_with_error.js +103 -0
  85. package/src/runtime/server/page/serialize_data.js +87 -0
  86. package/src/runtime/server/page/types.d.ts +35 -0
  87. package/src/runtime/server/utils.js +207 -0
  88. package/src/utils/array.js +9 -0
  89. package/src/utils/error.js +22 -0
  90. package/src/utils/escape.js +46 -0
  91. package/src/utils/exports.js +54 -0
  92. package/src/utils/filesystem.js +177 -0
  93. package/src/utils/functions.js +16 -0
  94. package/src/utils/http.js +72 -0
  95. package/src/utils/misc.js +1 -0
  96. package/src/utils/promises.js +17 -0
  97. package/src/utils/routing.js +201 -0
  98. package/src/utils/unit_test.js +11 -0
  99. package/src/utils/url.js +161 -0
  100. package/svelte-kit.js +1 -1
  101. package/types/ambient.d.ts +437 -0
  102. package/types/index.d.ts +1170 -0
  103. package/types/internal.d.ts +392 -0
  104. package/types/private.d.ts +236 -0
  105. package/types/synthetic/$env+dynamic+private.md +10 -0
  106. package/types/synthetic/$env+dynamic+public.md +8 -0
  107. package/types/synthetic/$env+static+private.md +19 -0
  108. package/types/synthetic/$env+static+public.md +7 -0
  109. package/types/synthetic/$lib.md +5 -0
  110. package/CHANGELOG.md +0 -539
  111. package/assets/components/error.svelte +0 -13
  112. package/assets/runtime/app/env.js +0 -5
  113. package/assets/runtime/app/navigation.js +0 -44
  114. package/assets/runtime/app/paths.js +0 -1
  115. package/assets/runtime/app/stores.js +0 -93
  116. package/assets/runtime/chunks/utils.js +0 -22
  117. package/assets/runtime/internal/singletons.js +0 -23
  118. package/assets/runtime/internal/start.js +0 -820
  119. package/assets/runtime/paths.js +0 -12
  120. package/dist/chunks/index.js +0 -246
  121. package/dist/chunks/index2.js +0 -3545
  122. package/dist/chunks/index3.js +0 -570
  123. package/dist/chunks/index4.js +0 -570
  124. package/dist/chunks/index5.js +0 -771
  125. package/dist/chunks/index6.js +0 -323
  126. package/dist/chunks/standard.js +0 -99
  127. package/dist/chunks/utils.js +0 -44
  128. package/dist/cli.js +0 -558
  129. package/dist/filesystem.cjs +0 -55
  130. package/dist/filesystem.js +0 -44
  131. package/dist/http.js +0 -1
  132. package/dist/ssr.js +0 -2642
  133. package/types.d.ts +0 -76
  134. package/types.internal.d.ts +0 -231
package/README.md CHANGED
@@ -5,11 +5,14 @@ This is the [SvelteKit](https://kit.svelte.dev) framework and CLI.
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
- mkdir my-app
8
+ npm create svelte@latest my-app
9
9
  cd my-app
10
- npm init svelte@next
11
10
  npm install
12
11
  npm run dev
13
12
  ```
14
13
 
15
14
  See the [documentation](https://kit.svelte.dev/docs) to learn more.
15
+
16
+ ## Changelog
17
+
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,74 +1,92 @@
1
1
  {
2
- "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.58",
4
- "type": "module",
5
- "dependencies": {
6
- "@sveltejs/vite-plugin-svelte": "^1.0.0-next.5",
7
- "cheap-watch": "^1.0.3",
8
- "sade": "^1.7.4"
9
- },
10
- "devDependencies": {
11
- "@rollup/plugin-replace": "^2.4.1",
12
- "@types/amphtml-validator": "^1.0.1",
13
- "@types/mime": "^2.0.3",
14
- "@types/node": "^14.14.33",
15
- "@types/rimraf": "^3.0.0",
16
- "@types/sade": "^1.7.2",
17
- "amphtml-validator": "^1.0.34",
18
- "devalue": "^2.0.1",
19
- "eslint": "^7.21.0",
20
- "kleur": "^4.1.4",
21
- "node-fetch": "^3.0.0-beta.9",
22
- "port-authority": "^1.1.2",
23
- "rimraf": "^3.0.2",
24
- "rollup": "^2.41.1",
25
- "sirv": "^1.0.11",
26
- "svelte": "^3.35.0",
27
- "tiny-glob": "^0.2.8",
28
- "typescript": "^4.2.3",
29
- "uvu": "^0.5.1",
30
- "vite": "^2.1.0"
31
- },
32
- "peerDependencies": {
33
- "svelte": "^3.32.1",
34
- "vite": "^2.1.0"
35
- },
36
- "bin": {
37
- "svelte-kit": "svelte-kit.js"
38
- },
39
- "files": [
40
- "assets",
41
- "dist",
42
- "types.d.ts",
43
- "types.internal.d.ts",
44
- "svelte-kit.js"
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.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
- "./http": {
65
- "import": "./dist/http.js"
66
- },
67
- "./filesystem": {
68
- "import": "./dist/filesystem.js",
69
- "require": "./dist/filesystem.cjs"
70
- },
71
- "./types.d.ts": "./types.d.ts"
72
- },
73
- "types": "types.d.ts"
74
- }
2
+ "name": "@sveltejs/kit",
3
+ "version": "1.0.0-next.581",
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": "^2.0.0",
14
+ "@types/cookie": "^0.5.1",
15
+ "cookie": "^0.5.0",
16
+ "devalue": "^4.2.0",
17
+ "esm-env": "^1.0.0",
18
+ "kleur": "^4.1.5",
19
+ "magic-string": "^0.27.0",
20
+ "mime": "^3.0.0",
21
+ "sade": "^1.8.1",
22
+ "set-cookie-parser": "^2.5.1",
23
+ "sirv": "^2.0.2",
24
+ "tiny-glob": "^0.2.9",
25
+ "undici": "5.14.0"
26
+ },
27
+ "devDependencies": {
28
+ "@playwright/test": "^1.28.1",
29
+ "@types/connect": "^3.4.35",
30
+ "@types/marked": "^4.0.7",
31
+ "@types/mime": "^3.0.1",
32
+ "@types/node": "^16.18.6",
33
+ "@types/sade": "^1.7.4",
34
+ "@types/set-cookie-parser": "^2.4.2",
35
+ "marked": "^4.2.3",
36
+ "rollup": "^3.7.0",
37
+ "svelte": "^3.54.0",
38
+ "svelte-preprocess": "^4.10.7",
39
+ "typescript": "^4.9.3",
40
+ "uvu": "^0.5.6",
41
+ "vite": "^4.0.0"
42
+ },
43
+ "peerDependencies": {
44
+ "svelte": "^3.54.0",
45
+ "vite": "^4.0.0"
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
+ "postinstall.js"
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
+ "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
84
+ "check": "tsc",
85
+ "check:all": "tsc && pnpm -r --filter=\"./**\" check",
86
+ "format": "pnpm lint --write",
87
+ "test": "pnpm test:unit && pnpm test:integration",
88
+ "test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
89
+ "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
90
+ "postinstall": "node postinstall.js"
91
+ }
92
+ }
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
+ }
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
+ }
@@ -0,0 +1,5 @@
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';
@@ -0,0 +1,237 @@
1
+ import { existsSync, statSync, createReadStream, createWriteStream } from 'node:fs';
2
+ import { pipeline } from 'node:stream';
3
+ import { promisify } from 'node:util';
4
+ import { fork } from 'node:child_process';
5
+ import { fileURLToPath } from 'node:url';
6
+ import glob from 'tiny-glob';
7
+ import zlib from 'zlib';
8
+ import { copy, rimraf, mkdirp } from '../../utils/filesystem.js';
9
+ import { generate_manifest } from '../generate_manifest/index.js';
10
+ import { get_route_segments } from '../../utils/routing.js';
11
+ import { get_env } from '../../exports/vite/utils.js';
12
+
13
+ const pipe = promisify(pipeline);
14
+
15
+ /**
16
+ * Creates the Builder which is passed to adapters for building the application.
17
+ * @param {{
18
+ * config: import('types').ValidatedConfig;
19
+ * build_data: import('types').BuildData;
20
+ * routes: import('types').RouteData[];
21
+ * prerendered: import('types').Prerendered;
22
+ * log: import('types').Logger;
23
+ * }} opts
24
+ * @returns {import('types').Builder}
25
+ */
26
+ export function create_builder({ config, build_data, routes, prerendered, log }) {
27
+ return {
28
+ log,
29
+ rimraf,
30
+ mkdirp,
31
+ copy,
32
+
33
+ config,
34
+ prerendered,
35
+
36
+ async createEntries(fn) {
37
+ /** @type {import('types').RouteDefinition[]} */
38
+ const facades = routes.map((route) => {
39
+ /** @type {Set<import('types').HttpMethod>} */
40
+ const methods = new Set();
41
+
42
+ if (route.page) {
43
+ methods.add('GET');
44
+ }
45
+
46
+ if (route.endpoint) {
47
+ for (const method of build_data.server.methods[route.endpoint.file]) {
48
+ methods.add(method);
49
+ }
50
+ }
51
+
52
+ return {
53
+ id: route.id,
54
+ segments: get_route_segments(route.id).map((segment) => ({
55
+ dynamic: segment.includes('['),
56
+ rest: segment.includes('[...'),
57
+ content: segment
58
+ })),
59
+ pattern: route.pattern,
60
+ methods: Array.from(methods)
61
+ };
62
+ });
63
+
64
+ const seen = new Set();
65
+
66
+ for (let i = 0; i < routes.length; i += 1) {
67
+ const route = routes[i];
68
+ const { id, filter, complete } = fn(facades[i]);
69
+
70
+ if (seen.has(id)) continue;
71
+ seen.add(id);
72
+
73
+ const group = [route];
74
+
75
+ // figure out which lower priority routes should be considered fallbacks
76
+ for (let j = i + 1; j < routes.length; j += 1) {
77
+ if (filter(facades[j])) {
78
+ group.push(routes[j]);
79
+ }
80
+ }
81
+
82
+ const filtered = new Set(group);
83
+
84
+ // heuristic: if /foo/[bar] is included, /foo/[bar].json should
85
+ // also be included, since the page likely needs the endpoint
86
+ // TODO is this still necessary, given the new way of doing things?
87
+ filtered.forEach((route) => {
88
+ if (route.page) {
89
+ const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
90
+
91
+ if (endpoint) {
92
+ filtered.add(endpoint);
93
+ }
94
+ }
95
+ });
96
+
97
+ if (filtered.size > 0) {
98
+ await complete({
99
+ generateManifest: ({ relativePath }) =>
100
+ generate_manifest({
101
+ build_data,
102
+ relative_path: relativePath,
103
+ routes: Array.from(filtered)
104
+ })
105
+ });
106
+ }
107
+ }
108
+ },
109
+
110
+ generateFallback(dest) {
111
+ // do prerendering in a subprocess so any dangling stuff gets killed upon completion
112
+ const script = fileURLToPath(new URL('../prerender/fallback.js', import.meta.url));
113
+
114
+ const manifest_path = `${config.kit.outDir}/output/server/manifest-full.js`;
115
+
116
+ const env = get_env(config.kit.env, 'production');
117
+
118
+ return new Promise((fulfil, reject) => {
119
+ const child = fork(
120
+ script,
121
+ [dest, manifest_path, JSON.stringify({ ...env.private, ...env.public })],
122
+ {
123
+ stdio: 'inherit'
124
+ }
125
+ );
126
+
127
+ child.on('exit', (code) => {
128
+ if (code) {
129
+ reject(new Error(`Could not create a fallback page — failed with code ${code}`));
130
+ } else {
131
+ fulfil(undefined);
132
+ }
133
+ });
134
+ });
135
+ },
136
+
137
+ generateManifest: ({ relativePath }) => {
138
+ return generate_manifest({
139
+ build_data,
140
+ relative_path: relativePath,
141
+ routes
142
+ });
143
+ },
144
+
145
+ getBuildDirectory(name) {
146
+ return `${config.kit.outDir}/${name}`;
147
+ },
148
+
149
+ getClientDirectory() {
150
+ return `${config.kit.outDir}/output/client`;
151
+ },
152
+
153
+ getServerDirectory() {
154
+ return `${config.kit.outDir}/output/server`;
155
+ },
156
+
157
+ getAppPath() {
158
+ return build_data.app_path;
159
+ },
160
+
161
+ writeClient(dest) {
162
+ return [...copy(`${config.kit.outDir}/output/client`, dest)];
163
+ },
164
+
165
+ // @ts-expect-error
166
+ writePrerendered(dest, opts) {
167
+ // TODO remove for 1.0
168
+ if (opts?.fallback) {
169
+ throw new Error(
170
+ 'The fallback option no longer exists — use builder.generateFallback(fallback) instead'
171
+ );
172
+ }
173
+
174
+ const source = `${config.kit.outDir}/output/prerendered`;
175
+ return [...copy(`${source}/pages`, dest), ...copy(`${source}/dependencies`, dest)];
176
+ },
177
+
178
+ writeServer(dest) {
179
+ return copy(`${config.kit.outDir}/output/server`, dest);
180
+ },
181
+
182
+ // TODO remove these methods for 1.0
183
+ // @ts-expect-error
184
+ writeStatic() {
185
+ throw new Error(
186
+ `writeStatic has been removed. Please ensure you are using the latest version of ${
187
+ config.kit.adapter.name || 'your adapter'
188
+ }`
189
+ );
190
+ },
191
+
192
+ async compress(directory) {
193
+ if (!existsSync(directory)) {
194
+ return;
195
+ }
196
+
197
+ const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', {
198
+ cwd: directory,
199
+ dot: true,
200
+ absolute: true,
201
+ filesOnly: true
202
+ });
203
+
204
+ await Promise.all(
205
+ files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')]))
206
+ );
207
+ },
208
+
209
+ async prerender() {
210
+ throw new Error(
211
+ 'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
212
+ );
213
+ }
214
+ };
215
+ }
216
+
217
+ /**
218
+ * @param {string} file
219
+ * @param {'gz' | 'br'} format
220
+ */
221
+ async function compress_file(file, format = 'gz') {
222
+ const compress =
223
+ format == 'br'
224
+ ? zlib.createBrotliCompress({
225
+ params: {
226
+ [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
227
+ [zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
228
+ [zlib.constants.BROTLI_PARAM_SIZE_HINT]: statSync(file).size
229
+ }
230
+ })
231
+ : zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION });
232
+
233
+ const source = createReadStream(file);
234
+ const destination = createWriteStream(`${file}.${format}`);
235
+
236
+ await pipe(source, compress, destination);
237
+ }
@@ -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.error.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.error.message%</h1>
53
+ </div>
54
+ </div>
55
+ </body>
56
+ </html>