@sveltejs/kit 1.0.0-next.57 → 1.0.0-next.570

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 (132) hide show
  1. package/README.md +5 -2
  2. package/package.json +90 -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 +206 -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 +522 -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/prerender.js +457 -0
  17. package/src/core/prerender/queue.js +80 -0
  18. package/src/core/sync/create_manifest_data/conflict.js +0 -0
  19. package/src/core/sync/create_manifest_data/index.js +531 -0
  20. package/src/core/sync/create_manifest_data/sort.js +161 -0
  21. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  22. package/src/core/sync/sync.js +78 -0
  23. package/src/core/sync/utils.js +33 -0
  24. package/src/core/sync/write_ambient.js +58 -0
  25. package/src/core/sync/write_client_manifest.js +107 -0
  26. package/src/core/sync/write_matchers.js +25 -0
  27. package/src/core/sync/write_root.js +91 -0
  28. package/src/core/sync/write_tsconfig.js +195 -0
  29. package/src/core/sync/write_types/index.js +809 -0
  30. package/src/core/utils.js +67 -0
  31. package/src/exports/hooks/index.js +1 -0
  32. package/src/exports/hooks/sequence.js +44 -0
  33. package/src/exports/index.js +55 -0
  34. package/src/exports/node/index.js +172 -0
  35. package/src/exports/node/polyfills.js +28 -0
  36. package/src/exports/vite/build/build_server.js +385 -0
  37. package/src/exports/vite/build/build_service_worker.js +92 -0
  38. package/src/exports/vite/build/utils.js +191 -0
  39. package/src/exports/vite/dev/index.js +595 -0
  40. package/src/exports/vite/graph_analysis/index.js +99 -0
  41. package/src/exports/vite/graph_analysis/types.d.ts +5 -0
  42. package/src/exports/vite/graph_analysis/utils.js +6 -0
  43. package/src/exports/vite/index.js +643 -0
  44. package/src/exports/vite/preview/index.js +193 -0
  45. package/src/exports/vite/types.d.ts +3 -0
  46. package/src/exports/vite/utils.js +178 -0
  47. package/src/runtime/app/env.js +1 -0
  48. package/src/runtime/app/environment.js +11 -0
  49. package/src/runtime/app/forms.js +141 -0
  50. package/src/runtime/app/navigation.js +33 -0
  51. package/src/runtime/app/paths.js +1 -0
  52. package/src/runtime/app/stores.js +102 -0
  53. package/src/runtime/client/ambient.d.ts +30 -0
  54. package/src/runtime/client/client.js +1846 -0
  55. package/src/runtime/client/constants.js +10 -0
  56. package/src/runtime/client/fetcher.js +126 -0
  57. package/src/runtime/client/parse.js +60 -0
  58. package/src/runtime/client/singletons.js +21 -0
  59. package/src/runtime/client/start.js +44 -0
  60. package/src/runtime/client/types.d.ts +86 -0
  61. package/src/runtime/client/utils.js +254 -0
  62. package/src/runtime/components/error.svelte +16 -0
  63. package/{assets → src/runtime}/components/layout.svelte +0 -0
  64. package/src/runtime/control.js +45 -0
  65. package/src/runtime/env/dynamic/private.js +1 -0
  66. package/src/runtime/env/dynamic/public.js +1 -0
  67. package/src/runtime/env-private.js +6 -0
  68. package/src/runtime/env-public.js +6 -0
  69. package/src/runtime/env.js +12 -0
  70. package/src/runtime/hash.js +20 -0
  71. package/src/runtime/paths.js +11 -0
  72. package/src/runtime/server/cookie.js +237 -0
  73. package/src/runtime/server/data/index.js +152 -0
  74. package/src/runtime/server/endpoint.js +89 -0
  75. package/src/runtime/server/fetch.js +175 -0
  76. package/src/runtime/server/index.js +413 -0
  77. package/src/runtime/server/page/actions.js +258 -0
  78. package/src/runtime/server/page/crypto.js +239 -0
  79. package/src/runtime/server/page/csp.js +250 -0
  80. package/src/runtime/server/page/index.js +303 -0
  81. package/src/runtime/server/page/load_data.js +259 -0
  82. package/src/runtime/server/page/render.js +393 -0
  83. package/src/runtime/server/page/respond_with_error.js +102 -0
  84. package/src/runtime/server/page/serialize_data.js +87 -0
  85. package/src/runtime/server/page/types.d.ts +35 -0
  86. package/src/runtime/server/utils.js +207 -0
  87. package/src/utils/array.js +9 -0
  88. package/src/utils/error.js +22 -0
  89. package/src/utils/escape.js +46 -0
  90. package/src/utils/filesystem.js +177 -0
  91. package/src/utils/functions.js +16 -0
  92. package/src/utils/http.js +72 -0
  93. package/src/utils/misc.js +1 -0
  94. package/src/utils/promises.js +17 -0
  95. package/src/utils/routing.js +201 -0
  96. package/src/utils/unit_test.js +11 -0
  97. package/src/utils/url.js +159 -0
  98. package/svelte-kit.js +1 -1
  99. package/types/ambient.d.ts +437 -0
  100. package/types/index.d.ts +1161 -0
  101. package/types/internal.d.ts +388 -0
  102. package/types/private.d.ts +236 -0
  103. package/types/synthetic/$env+dynamic+private.md +10 -0
  104. package/types/synthetic/$env+dynamic+public.md +8 -0
  105. package/types/synthetic/$env+static+private.md +19 -0
  106. package/types/synthetic/$env+static+public.md +7 -0
  107. package/types/synthetic/$lib.md +5 -0
  108. package/CHANGELOG.md +0 -532
  109. package/assets/components/error.svelte +0 -13
  110. package/assets/runtime/app/env.js +0 -5
  111. package/assets/runtime/app/navigation.js +0 -44
  112. package/assets/runtime/app/paths.js +0 -1
  113. package/assets/runtime/app/stores.js +0 -93
  114. package/assets/runtime/chunks/utils.js +0 -22
  115. package/assets/runtime/internal/singletons.js +0 -23
  116. package/assets/runtime/internal/start.js +0 -819
  117. package/assets/runtime/paths.js +0 -12
  118. package/dist/chunks/index.js +0 -246
  119. package/dist/chunks/index2.js +0 -3545
  120. package/dist/chunks/index3.js +0 -570
  121. package/dist/chunks/index4.js +0 -570
  122. package/dist/chunks/index5.js +0 -762
  123. package/dist/chunks/index6.js +0 -323
  124. package/dist/chunks/standard.js +0 -99
  125. package/dist/chunks/utils.js +0 -44
  126. package/dist/cli.js +0 -558
  127. package/dist/filesystem.cjs +0 -55
  128. package/dist/filesystem.js +0 -44
  129. package/dist/http.js +0 -1
  130. package/dist/ssr.js +0 -2620
  131. package/types.d.ts +0 -76
  132. 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,91 @@
1
1
  {
2
- "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.57",
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.570",
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.3.1",
14
+ "@types/cookie": "^0.5.1",
15
+ "cookie": "^0.5.0",
16
+ "devalue": "^4.2.0",
17
+ "kleur": "^4.1.5",
18
+ "magic-string": "^0.26.7",
19
+ "mime": "^3.0.0",
20
+ "sade": "^1.8.1",
21
+ "set-cookie-parser": "^2.5.1",
22
+ "sirv": "^2.0.2",
23
+ "tiny-glob": "^0.2.9",
24
+ "undici": "5.13.0"
25
+ },
26
+ "devDependencies": {
27
+ "@playwright/test": "^1.28.1",
28
+ "@types/connect": "^3.4.35",
29
+ "@types/marked": "^4.0.7",
30
+ "@types/mime": "^3.0.1",
31
+ "@types/node": "^16.18.3",
32
+ "@types/sade": "^1.7.4",
33
+ "@types/set-cookie-parser": "^2.4.2",
34
+ "marked": "^4.2.3",
35
+ "rollup": "^2.79.1",
36
+ "svelte": "^3.53.1",
37
+ "svelte-preprocess": "^4.10.7",
38
+ "typescript": "^4.9.3",
39
+ "uvu": "^0.5.6",
40
+ "vite": "^3.2.4"
41
+ },
42
+ "peerDependencies": {
43
+ "svelte": "^3.44.0",
44
+ "vite": "^3.2.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
+ ],
58
+ "exports": {
59
+ "./package.json": "./package.json",
60
+ ".": {
61
+ "types": "./types/index.d.ts",
62
+ "import": "./src/exports/index.js"
63
+ },
64
+ "./node": {
65
+ "import": "./src/exports/node/index.js"
66
+ },
67
+ "./node/polyfills": {
68
+ "import": "./src/exports/node/polyfills.js"
69
+ },
70
+ "./hooks": {
71
+ "import": "./src/exports/hooks/index.js"
72
+ },
73
+ "./vite": {
74
+ "import": "./src/exports/vite/index.js"
75
+ }
76
+ },
77
+ "types": "types/index.d.ts",
78
+ "engines": {
79
+ "node": ">=16.14"
80
+ },
81
+ "scripts": {
82
+ "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
83
+ "check": "tsc",
84
+ "check:all": "tsc && pnpm -r --filter=\"./**\" check",
85
+ "format": "pnpm lint --write",
86
+ "test": "pnpm test:unit && pnpm test:integration",
87
+ "test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
88
+ "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
89
+ "postinstall": "node postinstall.js"
90
+ }
91
+ }
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,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
+ import { get_route_segments } from '../../utils/routing.js';
9
+
10
+ const pipe = promisify(pipeline);
11
+
12
+ /**
13
+ * Creates the Builder which is passed to adapters for building the application.
14
+ * @param {{
15
+ * config: import('types').ValidatedConfig;
16
+ * build_data: import('types').BuildData;
17
+ * routes: import('types').RouteData[];
18
+ * prerendered: import('types').Prerendered;
19
+ * log: import('types').Logger;
20
+ * }} opts
21
+ * @returns {import('types').Builder}
22
+ */
23
+ export function create_builder({ config, build_data, routes, prerendered, log }) {
24
+ return {
25
+ log,
26
+ rimraf,
27
+ mkdirp,
28
+ copy,
29
+
30
+ config,
31
+ prerendered,
32
+
33
+ async createEntries(fn) {
34
+ /** @type {import('types').RouteDefinition[]} */
35
+ const facades = routes.map((route) => {
36
+ /** @type {Set<import('types').HttpMethod>} */
37
+ const methods = new Set();
38
+
39
+ if (route.page) {
40
+ methods.add('GET');
41
+ }
42
+
43
+ if (route.endpoint) {
44
+ for (const method of build_data.server.methods[route.endpoint.file]) {
45
+ methods.add(method);
46
+ }
47
+ }
48
+
49
+ return {
50
+ id: route.id,
51
+ segments: get_route_segments(route.id).map((segment) => ({
52
+ dynamic: segment.includes('['),
53
+ rest: segment.includes('[...'),
54
+ content: segment
55
+ })),
56
+ pattern: route.pattern,
57
+ methods: Array.from(methods)
58
+ };
59
+ });
60
+
61
+ const seen = new Set();
62
+
63
+ for (let i = 0; i < routes.length; i += 1) {
64
+ const route = routes[i];
65
+ const { id, filter, complete } = fn(facades[i]);
66
+
67
+ if (seen.has(id)) continue;
68
+ seen.add(id);
69
+
70
+ const group = [route];
71
+
72
+ // figure out which lower priority routes should be considered fallbacks
73
+ for (let j = i + 1; j < routes.length; j += 1) {
74
+ if (filter(facades[j])) {
75
+ group.push(routes[j]);
76
+ }
77
+ }
78
+
79
+ const filtered = new Set(group);
80
+
81
+ // heuristic: if /foo/[bar] is included, /foo/[bar].json should
82
+ // also be included, since the page likely needs the endpoint
83
+ // TODO is this still necessary, given the new way of doing things?
84
+ filtered.forEach((route) => {
85
+ if (route.page) {
86
+ const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
87
+
88
+ if (endpoint) {
89
+ filtered.add(endpoint);
90
+ }
91
+ }
92
+ });
93
+
94
+ if (filtered.size > 0) {
95
+ await complete({
96
+ generateManifest: ({ relativePath }) =>
97
+ generate_manifest({
98
+ build_data,
99
+ relative_path: relativePath,
100
+ routes: Array.from(filtered)
101
+ })
102
+ });
103
+ }
104
+ }
105
+ },
106
+
107
+ generateManifest: ({ relativePath }) => {
108
+ return generate_manifest({
109
+ build_data,
110
+ relative_path: relativePath,
111
+ routes
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
+ getAppPath() {
128
+ return build_data.app_path;
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
+ }
@@ -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>