@sveltejs/kit 1.0.0-next.402 → 1.0.0-next.406
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/package.json +24 -25
- package/{dist → src}/cli.js +19 -18
- package/{dist/chunks/index3.js → src/core/adapt/builder.js} +52 -63
- package/src/core/adapt/index.js +19 -0
- package/src/core/config/index.js +86 -0
- package/{dist/chunks/index.js → src/core/config/options.js} +7 -194
- package/src/core/config/types.d.ts +1 -0
- package/src/core/constants.js +3 -0
- package/src/core/generate_manifest/index.js +99 -0
- package/src/core/prerender/crawl.js +194 -0
- package/src/core/prerender/prerender.js +378 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/index.js +492 -0
- package/src/core/sync/create_manifest_data/types.d.ts +40 -0
- package/src/core/sync/sync.js +59 -0
- package/src/core/sync/utils.js +97 -0
- package/src/core/sync/write_ambient.js +87 -0
- package/src/core/sync/write_client_manifest.js +82 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +88 -0
- package/{dist/chunks → src/core/sync}/write_tsconfig.js +24 -108
- package/src/core/sync/write_types.js +738 -0
- package/src/core/utils.js +58 -0
- package/{dist → src}/hooks.js +1 -3
- package/src/index/index.js +45 -0
- package/src/index/private.js +31 -0
- package/src/node/index.js +145 -0
- package/src/node/polyfills.js +40 -0
- package/src/packaging/index.js +218 -0
- package/src/packaging/types.d.ts +8 -0
- package/src/packaging/typescript.js +150 -0
- package/src/packaging/utils.js +138 -0
- package/{assets → src/runtime}/app/env.js +3 -5
- package/src/runtime/app/navigation.js +22 -0
- package/src/runtime/app/paths.js +1 -0
- package/{assets → src/runtime}/app/stores.js +6 -9
- package/src/runtime/client/ambient.d.ts +17 -0
- package/{assets/client/start.js → src/runtime/client/client.js} +302 -878
- package/src/runtime/client/fetcher.js +60 -0
- package/src/runtime/client/parse.js +36 -0
- package/{assets → src/runtime}/client/singletons.js +2 -4
- package/src/runtime/client/start.js +48 -0
- package/src/runtime/client/types.d.ts +106 -0
- package/src/runtime/client/utils.js +113 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/{assets → src/runtime}/env/dynamic/private.js +0 -0
- package/{assets → src/runtime}/env/dynamic/public.js +0 -0
- package/{assets → src/runtime}/env-private.js +2 -4
- package/{assets → src/runtime}/env-public.js +2 -4
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +16 -0
- package/{assets → src/runtime}/paths.js +3 -5
- package/src/runtime/server/endpoint.js +42 -0
- package/src/runtime/server/index.js +434 -0
- package/src/runtime/server/page/cookie.js +25 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +249 -0
- package/src/runtime/server/page/fetch.js +265 -0
- package/src/runtime/server/page/index.js +423 -0
- package/src/runtime/server/page/load_data.js +94 -0
- package/src/runtime/server/page/render.js +357 -0
- package/src/runtime/server/page/respond_with_error.js +105 -0
- package/src/runtime/server/page/types.d.ts +44 -0
- package/src/runtime/server/utils.js +116 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +104 -0
- package/{dist/chunks → src/utils}/filesystem.js +22 -24
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/routing.js +107 -0
- package/src/utils/url.js +97 -0
- package/src/vite/build/build_server.js +333 -0
- package/src/vite/build/build_service_worker.js +90 -0
- package/src/vite/build/utils.js +152 -0
- package/src/vite/dev/index.js +565 -0
- package/src/vite/index.js +536 -0
- package/src/vite/preview/index.js +186 -0
- package/src/vite/types.d.ts +3 -0
- package/src/vite/utils.js +335 -0
- package/svelte-kit.js +1 -10
- package/types/ambient.d.ts +5 -12
- package/types/index.d.ts +91 -44
- package/types/internal.d.ts +50 -72
- package/types/private.d.ts +2 -1
- package/assets/app/navigation.js +0 -24
- package/assets/app/paths.js +0 -1
- package/assets/components/error.svelte +0 -29
- package/assets/env.js +0 -8
- package/assets/server/index.js +0 -3579
- package/dist/chunks/error.js +0 -12
- package/dist/chunks/index2.js +0 -15745
- package/dist/chunks/multipart-parser.js +0 -458
- package/dist/chunks/sync.js +0 -1366
- package/dist/chunks/utils.js +0 -66
- package/dist/node/polyfills.js +0 -17778
- package/dist/node.js +0 -348
- package/dist/prerender.js +0 -788
- package/dist/vite.js +0 -2520
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.406",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -12,11 +12,20 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
|
14
14
|
"chokidar": "^3.5.3",
|
|
15
|
-
"
|
|
15
|
+
"cookie": "^0.5.0",
|
|
16
|
+
"devalue": "^2.0.1",
|
|
17
|
+
"kleur": "^4.1.4",
|
|
18
|
+
"magic-string": "^0.26.2",
|
|
19
|
+
"mime": "^3.0.0",
|
|
20
|
+
"node-fetch": "^3.2.4",
|
|
21
|
+
"sade": "^1.8.1",
|
|
22
|
+
"set-cookie-parser": "^2.4.8",
|
|
23
|
+
"sirv": "^2.0.2",
|
|
24
|
+
"tiny-glob": "^0.2.9",
|
|
25
|
+
"undici": "^5.8.1"
|
|
16
26
|
},
|
|
17
27
|
"devDependencies": {
|
|
18
28
|
"@playwright/test": "^1.23.4",
|
|
19
|
-
"@rollup/plugin-replace": "^4.0.0",
|
|
20
29
|
"@types/connect": "^3.4.35",
|
|
21
30
|
"@types/cookie": "^0.5.1",
|
|
22
31
|
"@types/marked": "^4.0.3",
|
|
@@ -24,25 +33,12 @@
|
|
|
24
33
|
"@types/node": "^16.11.36",
|
|
25
34
|
"@types/sade": "^1.7.4",
|
|
26
35
|
"@types/set-cookie-parser": "^2.4.2",
|
|
27
|
-
"cookie": "^0.5.0",
|
|
28
|
-
"cross-env": "^7.0.3",
|
|
29
|
-
"devalue": "^2.0.1",
|
|
30
|
-
"kleur": "^4.1.4",
|
|
31
|
-
"locate-character": "^2.0.5",
|
|
32
36
|
"marked": "^4.0.16",
|
|
33
|
-
"mime": "^3.0.0",
|
|
34
|
-
"node-fetch": "^3.2.4",
|
|
35
37
|
"rollup": "^2.75.7",
|
|
36
|
-
"selfsigned": "^2.0.1",
|
|
37
|
-
"set-cookie-parser": "^2.4.8",
|
|
38
|
-
"sirv": "^2.0.2",
|
|
39
38
|
"svelte": "^3.48.0",
|
|
40
|
-
"svelte-check": "^2.7.1",
|
|
41
39
|
"svelte-preprocess": "^4.10.6",
|
|
42
40
|
"svelte2tsx": "~0.5.10",
|
|
43
|
-
"tiny-glob": "^0.2.9",
|
|
44
41
|
"typescript": "^4.7.4",
|
|
45
|
-
"undici": "^5.6.1",
|
|
46
42
|
"uvu": "^0.5.3",
|
|
47
43
|
"vite": "^3.0.0"
|
|
48
44
|
},
|
|
@@ -54,27 +50,31 @@
|
|
|
54
50
|
"svelte-kit": "svelte-kit.js"
|
|
55
51
|
},
|
|
56
52
|
"files": [
|
|
57
|
-
"
|
|
58
|
-
"
|
|
53
|
+
"src",
|
|
54
|
+
"!src/**/*.spec.js",
|
|
55
|
+
"!src/packaging/test",
|
|
56
|
+
"!src/core/**/fixtures",
|
|
57
|
+
"!src/core/sync/create_manifest_data/test",
|
|
59
58
|
"types",
|
|
60
59
|
"svelte-kit.js"
|
|
61
60
|
],
|
|
62
61
|
"exports": {
|
|
63
62
|
"./package.json": "./package.json",
|
|
64
63
|
".": {
|
|
64
|
+
"import": "./src/index/index.js",
|
|
65
65
|
"types": "./types/index.d.ts"
|
|
66
66
|
},
|
|
67
67
|
"./node": {
|
|
68
|
-
"import": "./
|
|
68
|
+
"import": "./src/node/index.js"
|
|
69
69
|
},
|
|
70
70
|
"./node/polyfills": {
|
|
71
|
-
"import": "./
|
|
71
|
+
"import": "./src/node/polyfills.js"
|
|
72
72
|
},
|
|
73
73
|
"./hooks": {
|
|
74
|
-
"import": "./
|
|
74
|
+
"import": "./src/hooks.js"
|
|
75
75
|
},
|
|
76
76
|
"./vite": {
|
|
77
|
-
"import": "./
|
|
77
|
+
"import": "./src/vite/index.js"
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
"types": "types/index.d.ts",
|
|
@@ -82,16 +82,15 @@
|
|
|
82
82
|
"node": ">=16.9"
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
|
-
"build": "
|
|
85
|
+
"build": "npm run types",
|
|
86
86
|
"dev": "rollup -cw",
|
|
87
87
|
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
|
|
88
88
|
"check": "tsc",
|
|
89
89
|
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
|
|
90
90
|
"format": "npm run lint -- --write",
|
|
91
|
-
"test": "npm run test:unit && npm run test:
|
|
91
|
+
"test": "npm run test:unit && npm run test:packaging && npm run test:integration",
|
|
92
92
|
"test:integration": "pnpm run -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
93
93
|
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\" -i packaging",
|
|
94
|
-
"test:typings": "tsc --project test/typings",
|
|
95
94
|
"test:packaging": "uvu src/packaging \"(spec\\.js|test[\\\\/]index\\.js)\"",
|
|
96
95
|
"types": "node scripts/extract-types.js",
|
|
97
96
|
"postinstall": "node svelte-kit.js sync"
|
package/{dist → src}/cli.js
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import colors from 'kleur';
|
|
4
4
|
import sade from 'sade';
|
|
5
|
-
import {
|
|
6
|
-
import '
|
|
5
|
+
import { load_config } from './core/config/index.js';
|
|
6
|
+
import { coalesce_to_error } from './utils/error.js';
|
|
7
7
|
|
|
8
8
|
/** @param {unknown} e */
|
|
9
9
|
function handle_error(e) {
|
|
@@ -11,15 +11,16 @@ function handle_error(e) {
|
|
|
11
11
|
|
|
12
12
|
if (error.name === 'SyntaxError') throw error;
|
|
13
13
|
|
|
14
|
-
console.error(
|
|
14
|
+
console.error(colors.bold().red(`> ${error.message}`));
|
|
15
15
|
if (error.stack) {
|
|
16
|
-
console.error(
|
|
16
|
+
console.error(colors.gray(error.stack.split('\n').slice(1).join('\n')));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const
|
|
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);
|
|
23
24
|
|
|
24
25
|
prog
|
|
25
26
|
.command('package')
|
|
@@ -28,7 +29,7 @@ prog
|
|
|
28
29
|
.action(async ({ watch }) => {
|
|
29
30
|
try {
|
|
30
31
|
const config = await load_config();
|
|
31
|
-
const packaging = await import('./
|
|
32
|
+
const packaging = await import('./packaging/index.js');
|
|
32
33
|
|
|
33
34
|
await (watch ? packaging.watch(config) : packaging.build(config));
|
|
34
35
|
} catch (error) {
|
|
@@ -45,13 +46,13 @@ prog
|
|
|
45
46
|
|
|
46
47
|
// TODO remove for 1.0
|
|
47
48
|
if (event === 'prepare') {
|
|
48
|
-
const pkg = JSON.parse(
|
|
49
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
49
50
|
const message =
|
|
50
51
|
pkg.scripts.prepare === 'svelte-kit sync'
|
|
51
52
|
? `\`svelte-kit sync\` now runs on "postinstall" — please remove the "prepare" script from your package.json\n`
|
|
52
53
|
: `\`svelte-kit sync\` now runs on "postinstall" — please remove it from your "prepare" script\n`;
|
|
53
54
|
|
|
54
|
-
console.error(
|
|
55
|
+
console.error(colors.bold().red(message));
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -59,15 +60,15 @@ prog
|
|
|
59
60
|
process.chdir(process.env.INIT_CWD);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
if (!
|
|
63
|
-
console.warn(`Missing ${
|
|
63
|
+
if (!fs.existsSync('svelte.config.js')) {
|
|
64
|
+
console.warn(`Missing ${path.resolve('svelte.config.js')} — skipping`);
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
try {
|
|
68
69
|
const config = await load_config();
|
|
69
|
-
const sync = await import('./
|
|
70
|
-
sync.all(config, mode);
|
|
70
|
+
const sync = await import('./core/sync/sync.js');
|
|
71
|
+
await sync.all(config, mode);
|
|
71
72
|
} catch (error) {
|
|
72
73
|
handle_error(error);
|
|
73
74
|
}
|
|
@@ -87,7 +88,7 @@ function replace(command) {
|
|
|
87
88
|
.describe(`No longer available — use vite ${command} instead`)
|
|
88
89
|
.action(async () => {
|
|
89
90
|
const message = `\n> svelte-kit ${command} is no longer available — use vite ${command} instead`;
|
|
90
|
-
console.error(
|
|
91
|
+
console.error(colors.bold().red(message));
|
|
91
92
|
|
|
92
93
|
const steps = [
|
|
93
94
|
'Install vite as a devDependency with npm/pnpm/etc',
|
|
@@ -96,12 +97,12 @@ function replace(command) {
|
|
|
96
97
|
];
|
|
97
98
|
|
|
98
99
|
steps.forEach((step, i) => {
|
|
99
|
-
console.error(` ${i + 1}. ${
|
|
100
|
+
console.error(` ${i + 1}. ${colors.cyan(step)}`);
|
|
100
101
|
});
|
|
101
102
|
|
|
102
103
|
console.error(
|
|
103
104
|
`
|
|
104
|
-
${
|
|
105
|
+
${colors.grey('// vite.config.js')}
|
|
105
106
|
import { sveltekit } from '@sveltejs/kit/vite';
|
|
106
107
|
|
|
107
108
|
/** @type {import('vite').UserConfig} */
|
|
@@ -1,44 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
import '
|
|
6
|
-
import '
|
|
7
|
-
import '
|
|
8
|
-
import 'node:fs';
|
|
9
|
-
import 'node:path';
|
|
10
|
-
import '@sveltejs/vite-plugin-svelte';
|
|
11
|
-
import 'vite';
|
|
12
|
-
import './sync.js';
|
|
13
|
-
import './utils.js';
|
|
14
|
-
import './write_tsconfig.js';
|
|
15
|
-
import 'querystring';
|
|
16
|
-
import '../node.js';
|
|
17
|
-
import '../node/polyfills.js';
|
|
18
|
-
import 'assert';
|
|
19
|
-
import 'net';
|
|
20
|
-
import 'http';
|
|
21
|
-
import 'stream';
|
|
22
|
-
import 'buffer';
|
|
23
|
-
import 'util';
|
|
24
|
-
import 'stream/web';
|
|
25
|
-
import 'perf_hooks';
|
|
26
|
-
import 'util/types';
|
|
27
|
-
import 'events';
|
|
28
|
-
import 'tls';
|
|
29
|
-
import 'async_hooks';
|
|
30
|
-
import 'console';
|
|
31
|
-
import 'zlib';
|
|
32
|
-
import 'node:http';
|
|
33
|
-
import 'node:https';
|
|
34
|
-
import 'node:zlib';
|
|
35
|
-
import 'node:stream';
|
|
36
|
-
import 'node:buffer';
|
|
37
|
-
import 'node:util';
|
|
38
|
-
import 'node:url';
|
|
39
|
-
import 'node:net';
|
|
40
|
-
import 'crypto';
|
|
41
|
-
import './error.js';
|
|
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';
|
|
42
8
|
|
|
43
9
|
/**
|
|
44
10
|
* Creates the Builder which is passed to adapters for building the application.
|
|
@@ -50,20 +16,45 @@ import './error.js';
|
|
|
50
16
|
* }} opts
|
|
51
17
|
* @returns {import('types').Builder}
|
|
52
18
|
*/
|
|
53
|
-
function create_builder({ config, build_data, prerendered, log }) {
|
|
19
|
+
export function create_builder({ config, build_data, prerendered, log }) {
|
|
54
20
|
/** @type {Set<string>} */
|
|
55
21
|
const prerendered_paths = new Set(prerendered.paths);
|
|
56
22
|
|
|
57
23
|
/** @param {import('types').RouteData} route */
|
|
58
24
|
// TODO routes should come pre-filtered
|
|
59
25
|
function not_prerendered(route) {
|
|
60
|
-
|
|
61
|
-
|
|
26
|
+
const path = route.type === 'page' && !route.id.includes('[') && `/${route.id}`;
|
|
27
|
+
if (path) {
|
|
28
|
+
return !prerendered_paths.has(path) && !prerendered_paths.has(path + '/');
|
|
62
29
|
}
|
|
63
30
|
|
|
64
31
|
return true;
|
|
65
32
|
}
|
|
66
33
|
|
|
34
|
+
const pipe = promisify(pipeline);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} file
|
|
38
|
+
* @param {'gz' | 'br'} format
|
|
39
|
+
*/
|
|
40
|
+
async function compress_file(file, format = 'gz') {
|
|
41
|
+
const compress =
|
|
42
|
+
format == 'br'
|
|
43
|
+
? zlib.createBrotliCompress({
|
|
44
|
+
params: {
|
|
45
|
+
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
|
|
46
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
|
|
47
|
+
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: statSync(file).size
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
: zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION });
|
|
51
|
+
|
|
52
|
+
const source = createReadStream(file);
|
|
53
|
+
const destination = createWriteStream(`${file}.${format}`);
|
|
54
|
+
|
|
55
|
+
await pipe(source, compress, destination);
|
|
56
|
+
}
|
|
57
|
+
|
|
67
58
|
return {
|
|
68
59
|
log,
|
|
69
60
|
rimraf,
|
|
@@ -190,6 +181,23 @@ function create_builder({ config, build_data, prerendered, log }) {
|
|
|
190
181
|
);
|
|
191
182
|
},
|
|
192
183
|
|
|
184
|
+
async compress(directory) {
|
|
185
|
+
if (!existsSync(directory)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', {
|
|
190
|
+
cwd: directory,
|
|
191
|
+
dot: true,
|
|
192
|
+
absolute: true,
|
|
193
|
+
filesOnly: true
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
await Promise.all(
|
|
197
|
+
files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')]))
|
|
198
|
+
);
|
|
199
|
+
},
|
|
200
|
+
|
|
193
201
|
async prerender() {
|
|
194
202
|
throw new Error(
|
|
195
203
|
'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
|
|
@@ -197,22 +205,3 @@ function create_builder({ config, build_data, prerendered, log }) {
|
|
|
197
205
|
}
|
|
198
206
|
};
|
|
199
207
|
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @param {import('types').ValidatedConfig} config
|
|
203
|
-
* @param {import('types').BuildData} build_data
|
|
204
|
-
* @param {import('types').Prerendered} prerendered
|
|
205
|
-
* @param {{ log: import('types').Logger }} opts
|
|
206
|
-
*/
|
|
207
|
-
async function adapt(config, build_data, prerendered, { log }) {
|
|
208
|
-
const { name, adapt } = config.kit.adapter;
|
|
209
|
-
|
|
210
|
-
console.log($.bold().cyan(`\n> Using ${name}`));
|
|
211
|
-
|
|
212
|
-
const builder = create_builder({ config, build_data, prerendered, log });
|
|
213
|
-
await adapt(builder);
|
|
214
|
-
|
|
215
|
-
log.success('done');
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export { adapt };
|
|
@@ -0,0 +1,19 @@
|
|
|
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 {{ log: import('types').Logger }} opts
|
|
9
|
+
*/
|
|
10
|
+
export async function adapt(config, build_data, prerendered, { log }) {
|
|
11
|
+
const { name, adapt } = config.kit.adapter;
|
|
12
|
+
|
|
13
|
+
console.log(colors.bold().cyan(`\n> Using ${name}`));
|
|
14
|
+
|
|
15
|
+
const builder = create_builder({ config, build_data, prerendered, log });
|
|
16
|
+
await adapt(builder);
|
|
17
|
+
|
|
18
|
+
log.success('done');
|
|
19
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import * as url from 'url';
|
|
4
|
+
import options from './options.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Loads the template (src/app.html by default) and validates that it has the
|
|
8
|
+
* required content.
|
|
9
|
+
* @param {string} cwd
|
|
10
|
+
* @param {import('types').ValidatedConfig} config
|
|
11
|
+
*/
|
|
12
|
+
export function load_template(cwd, config) {
|
|
13
|
+
const { template } = config.kit.files;
|
|
14
|
+
const relative = path.relative(cwd, template);
|
|
15
|
+
|
|
16
|
+
if (fs.existsSync(template)) {
|
|
17
|
+
const contents = fs.readFileSync(template, 'utf8');
|
|
18
|
+
|
|
19
|
+
// TODO remove this for 1.0
|
|
20
|
+
const match = /%svelte\.([a-z]+)%/.exec(contents);
|
|
21
|
+
if (match) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
|
|
28
|
+
expected_tags.forEach((tag) => {
|
|
29
|
+
if (contents.indexOf(tag) === -1) {
|
|
30
|
+
throw new Error(`${relative} is missing ${tag}`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error(`${relative} does not exist`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return fs.readFileSync(template, 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Loads and validates svelte.config.js
|
|
42
|
+
* @param {{ cwd?: string }} options
|
|
43
|
+
* @returns {Promise<import('types').ValidatedConfig>}
|
|
44
|
+
*/
|
|
45
|
+
export async function load_config({ cwd = process.cwd() } = {}) {
|
|
46
|
+
const config_file = path.join(cwd, 'svelte.config.js');
|
|
47
|
+
|
|
48
|
+
if (!fs.existsSync(config_file)) {
|
|
49
|
+
return process_config({}, { cwd });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
|
|
53
|
+
|
|
54
|
+
return process_config(config.default, { cwd });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {import('types').Config} config
|
|
59
|
+
* @returns {import('types').ValidatedConfig}
|
|
60
|
+
*/
|
|
61
|
+
function process_config(config, { cwd = process.cwd() } = {}) {
|
|
62
|
+
const validated = validate_config(config);
|
|
63
|
+
|
|
64
|
+
validated.kit.outDir = path.resolve(cwd, validated.kit.outDir);
|
|
65
|
+
|
|
66
|
+
for (const key in validated.kit.files) {
|
|
67
|
+
// @ts-expect-error this is typescript at its stupidest
|
|
68
|
+
validated.kit.files[key] = path.resolve(cwd, validated.kit.files[key]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return validated;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {import('types').Config} config
|
|
76
|
+
* @returns {import('types').ValidatedConfig}
|
|
77
|
+
*/
|
|
78
|
+
export function validate_config(config) {
|
|
79
|
+
if (typeof config !== 'object') {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs/configuration'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return options(config, 'config');
|
|
86
|
+
}
|
|
@@ -1,113 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path__default, { join } from 'path';
|
|
3
|
-
import * as url from 'url';
|
|
4
|
-
|
|
5
|
-
let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
|
|
6
|
-
if (typeof process !== 'undefined') {
|
|
7
|
-
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
|
|
8
|
-
isTTY = process.stdout && process.stdout.isTTY;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const $ = {
|
|
12
|
-
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (
|
|
13
|
-
FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY
|
|
14
|
-
),
|
|
15
|
-
|
|
16
|
-
// modifiers
|
|
17
|
-
reset: init(0, 0),
|
|
18
|
-
bold: init(1, 22),
|
|
19
|
-
dim: init(2, 22),
|
|
20
|
-
italic: init(3, 23),
|
|
21
|
-
underline: init(4, 24),
|
|
22
|
-
inverse: init(7, 27),
|
|
23
|
-
hidden: init(8, 28),
|
|
24
|
-
strikethrough: init(9, 29),
|
|
25
|
-
|
|
26
|
-
// colors
|
|
27
|
-
black: init(30, 39),
|
|
28
|
-
red: init(31, 39),
|
|
29
|
-
green: init(32, 39),
|
|
30
|
-
yellow: init(33, 39),
|
|
31
|
-
blue: init(34, 39),
|
|
32
|
-
magenta: init(35, 39),
|
|
33
|
-
cyan: init(36, 39),
|
|
34
|
-
white: init(37, 39),
|
|
35
|
-
gray: init(90, 39),
|
|
36
|
-
grey: init(90, 39),
|
|
37
|
-
|
|
38
|
-
// background colors
|
|
39
|
-
bgBlack: init(40, 49),
|
|
40
|
-
bgRed: init(41, 49),
|
|
41
|
-
bgGreen: init(42, 49),
|
|
42
|
-
bgYellow: init(43, 49),
|
|
43
|
-
bgBlue: init(44, 49),
|
|
44
|
-
bgMagenta: init(45, 49),
|
|
45
|
-
bgCyan: init(46, 49),
|
|
46
|
-
bgWhite: init(47, 49)
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
function run(arr, str) {
|
|
50
|
-
let i=0, tmp, beg='', end='';
|
|
51
|
-
for (; i < arr.length; i++) {
|
|
52
|
-
tmp = arr[i];
|
|
53
|
-
beg += tmp.open;
|
|
54
|
-
end += tmp.close;
|
|
55
|
-
if (!!~str.indexOf(tmp.close)) {
|
|
56
|
-
str = str.replace(tmp.rgx, tmp.close + tmp.open);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return beg + str + end;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function chain(has, keys) {
|
|
63
|
-
let ctx = { has, keys };
|
|
64
|
-
|
|
65
|
-
ctx.reset = $.reset.bind(ctx);
|
|
66
|
-
ctx.bold = $.bold.bind(ctx);
|
|
67
|
-
ctx.dim = $.dim.bind(ctx);
|
|
68
|
-
ctx.italic = $.italic.bind(ctx);
|
|
69
|
-
ctx.underline = $.underline.bind(ctx);
|
|
70
|
-
ctx.inverse = $.inverse.bind(ctx);
|
|
71
|
-
ctx.hidden = $.hidden.bind(ctx);
|
|
72
|
-
ctx.strikethrough = $.strikethrough.bind(ctx);
|
|
73
|
-
|
|
74
|
-
ctx.black = $.black.bind(ctx);
|
|
75
|
-
ctx.red = $.red.bind(ctx);
|
|
76
|
-
ctx.green = $.green.bind(ctx);
|
|
77
|
-
ctx.yellow = $.yellow.bind(ctx);
|
|
78
|
-
ctx.blue = $.blue.bind(ctx);
|
|
79
|
-
ctx.magenta = $.magenta.bind(ctx);
|
|
80
|
-
ctx.cyan = $.cyan.bind(ctx);
|
|
81
|
-
ctx.white = $.white.bind(ctx);
|
|
82
|
-
ctx.gray = $.gray.bind(ctx);
|
|
83
|
-
ctx.grey = $.grey.bind(ctx);
|
|
84
|
-
|
|
85
|
-
ctx.bgBlack = $.bgBlack.bind(ctx);
|
|
86
|
-
ctx.bgRed = $.bgRed.bind(ctx);
|
|
87
|
-
ctx.bgGreen = $.bgGreen.bind(ctx);
|
|
88
|
-
ctx.bgYellow = $.bgYellow.bind(ctx);
|
|
89
|
-
ctx.bgBlue = $.bgBlue.bind(ctx);
|
|
90
|
-
ctx.bgMagenta = $.bgMagenta.bind(ctx);
|
|
91
|
-
ctx.bgCyan = $.bgCyan.bind(ctx);
|
|
92
|
-
ctx.bgWhite = $.bgWhite.bind(ctx);
|
|
93
|
-
|
|
94
|
-
return ctx;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function init(open, close) {
|
|
98
|
-
let blk = {
|
|
99
|
-
open: `\x1b[${open}m`,
|
|
100
|
-
close: `\x1b[${close}m`,
|
|
101
|
-
rgx: new RegExp(`\\x1b\\[${close}m`, 'g')
|
|
102
|
-
};
|
|
103
|
-
return function (txt) {
|
|
104
|
-
if (this !== void 0 && this.has !== void 0) {
|
|
105
|
-
!!~this.has.indexOf(open) || (this.has.push(open),this.keys.push(blk));
|
|
106
|
-
return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+'';
|
|
107
|
-
}
|
|
108
|
-
return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+'';
|
|
109
|
-
};
|
|
110
|
-
}
|
|
1
|
+
import { join } from 'path';
|
|
111
2
|
|
|
112
3
|
/** @typedef {import('./types').Validator} Validator */
|
|
113
4
|
|
|
@@ -400,7 +291,11 @@ const options = object(
|
|
|
400
291
|
// TODO remove for 1.0
|
|
401
292
|
router: error((keypath) => `${keypath} has been moved to config.kit.browser.router`),
|
|
402
293
|
|
|
403
|
-
|
|
294
|
+
// TODO remove for 1.0
|
|
295
|
+
routes: error(
|
|
296
|
+
(keypath) =>
|
|
297
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/discussions/5774 for details`
|
|
298
|
+
),
|
|
404
299
|
|
|
405
300
|
serviceWorker: object({
|
|
406
301
|
register: boolean(true),
|
|
@@ -590,86 +485,4 @@ function error(fn) {
|
|
|
590
485
|
});
|
|
591
486
|
}
|
|
592
487
|
|
|
593
|
-
|
|
594
|
-
* Loads the template (src/app.html by default) and validates that it has the
|
|
595
|
-
* required content.
|
|
596
|
-
* @param {string} cwd
|
|
597
|
-
* @param {import('types').ValidatedConfig} config
|
|
598
|
-
*/
|
|
599
|
-
function load_template(cwd, config) {
|
|
600
|
-
const { template } = config.kit.files;
|
|
601
|
-
const relative = path__default.relative(cwd, template);
|
|
602
|
-
|
|
603
|
-
if (fs__default.existsSync(template)) {
|
|
604
|
-
const contents = fs__default.readFileSync(template, 'utf8');
|
|
605
|
-
|
|
606
|
-
// TODO remove this for 1.0
|
|
607
|
-
const match = /%svelte\.([a-z]+)%/.exec(contents);
|
|
608
|
-
if (match) {
|
|
609
|
-
throw new Error(
|
|
610
|
-
`%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
|
|
615
|
-
expected_tags.forEach((tag) => {
|
|
616
|
-
if (contents.indexOf(tag) === -1) {
|
|
617
|
-
throw new Error(`${relative} is missing ${tag}`);
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
} else {
|
|
621
|
-
throw new Error(`${relative} does not exist`);
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return fs__default.readFileSync(template, 'utf-8');
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
/**
|
|
628
|
-
* Loads and validates svelte.config.js
|
|
629
|
-
* @param {{ cwd?: string }} options
|
|
630
|
-
* @returns {Promise<import('types').ValidatedConfig>}
|
|
631
|
-
*/
|
|
632
|
-
async function load_config({ cwd = process.cwd() } = {}) {
|
|
633
|
-
const config_file = path__default.join(cwd, 'svelte.config.js');
|
|
634
|
-
|
|
635
|
-
if (!fs__default.existsSync(config_file)) {
|
|
636
|
-
return process_config({}, { cwd });
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
|
|
640
|
-
|
|
641
|
-
return process_config(config.default, { cwd });
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* @param {import('types').Config} config
|
|
646
|
-
* @returns {import('types').ValidatedConfig}
|
|
647
|
-
*/
|
|
648
|
-
function process_config(config, { cwd = process.cwd() } = {}) {
|
|
649
|
-
const validated = validate_config(config);
|
|
650
|
-
|
|
651
|
-
validated.kit.outDir = path__default.resolve(cwd, validated.kit.outDir);
|
|
652
|
-
|
|
653
|
-
for (const key in validated.kit.files) {
|
|
654
|
-
// @ts-expect-error this is typescript at its stupidest
|
|
655
|
-
validated.kit.files[key] = path__default.resolve(cwd, validated.kit.files[key]);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
return validated;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* @param {import('types').Config} config
|
|
663
|
-
* @returns {import('types').ValidatedConfig}
|
|
664
|
-
*/
|
|
665
|
-
function validate_config(config) {
|
|
666
|
-
if (typeof config !== 'object') {
|
|
667
|
-
throw new Error(
|
|
668
|
-
'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs/configuration'
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
return options(config, 'config');
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
export { $, load_template as a, load_config as l };
|
|
488
|
+
export default options;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Validator<T = any> = (input: T, keypath: string) => T;
|