@sveltejs/kit 1.0.0-next.45 → 1.0.0-next.450
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/package.json +92 -63
- package/src/cli.js +112 -0
- package/src/constants.js +7 -0
- package/src/core/adapt/builder.js +223 -0
- package/src/core/adapt/index.js +19 -0
- package/src/core/config/index.js +86 -0
- package/src/core/config/options.js +488 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/env.js +97 -0
- package/src/core/generate_manifest/index.js +78 -0
- package/src/core/prerender/crawl.js +194 -0
- package/src/core/prerender/prerender.js +380 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/index.js +452 -0
- package/src/core/sync/create_manifest_data/types.d.ts +37 -0
- package/src/core/sync/sync.js +59 -0
- package/src/core/sync/utils.js +33 -0
- package/src/core/sync/write_ambient.js +27 -0
- package/src/core/sync/write_client_manifest.js +94 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +91 -0
- package/src/core/sync/write_tsconfig.js +195 -0
- package/src/core/sync/write_types/index.js +596 -0
- package/src/core/utils.js +70 -0
- package/src/exports/hooks/index.js +1 -0
- package/src/exports/hooks/sequence.js +26 -0
- package/src/exports/index.js +45 -0
- package/src/exports/node/index.js +145 -0
- package/src/exports/node/polyfills.js +40 -0
- package/src/exports/vite/build/build_server.js +348 -0
- package/src/exports/vite/build/build_service_worker.js +90 -0
- package/src/exports/vite/build/utils.js +160 -0
- package/src/exports/vite/dev/index.js +543 -0
- package/src/exports/vite/index.js +588 -0
- package/src/exports/vite/preview/index.js +186 -0
- package/src/exports/vite/types.d.ts +3 -0
- package/src/exports/vite/utils.js +345 -0
- package/src/runtime/app/env.js +1 -0
- package/src/runtime/app/environment.js +11 -0
- package/src/runtime/app/navigation.js +22 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +24 -0
- package/src/runtime/client/client.js +1394 -0
- package/src/runtime/client/fetcher.js +60 -0
- package/src/runtime/client/parse.js +60 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +48 -0
- package/src/runtime/client/types.d.ts +88 -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/src/runtime/control.js +33 -0
- package/src/runtime/env/dynamic/private.js +1 -0
- package/src/runtime/env/dynamic/public.js +1 -0
- package/src/runtime/env-private.js +7 -0
- package/src/runtime/env-public.js +7 -0
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +16 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/data/index.js +146 -0
- package/src/runtime/server/endpoint.js +50 -0
- package/src/runtime/server/index.js +369 -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 +266 -0
- package/src/runtime/server/page/index.js +413 -0
- package/src/runtime/server/page/load_data.js +124 -0
- package/src/runtime/server/page/render.js +379 -0
- package/src/runtime/server/page/respond_with_error.js +94 -0
- package/src/runtime/server/page/types.d.ts +44 -0
- package/src/runtime/server/utils.js +137 -0
- package/src/utils/array.js +9 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +104 -0
- package/src/utils/filesystem.js +108 -0
- package/src/utils/functions.js +16 -0
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/routing.js +146 -0
- package/src/utils/url.js +142 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +366 -0
- package/types/index.d.ts +345 -0
- package/types/internal.d.ts +379 -0
- package/types/private.d.ts +209 -0
- package/CHANGELOG.md +0 -450
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -41
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -19
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -770
- package/assets/runtime/paths.js +0 -12
- package/dist/chunks/index.js +0 -3521
- package/dist/chunks/index2.js +0 -587
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -536
- package/dist/chunks/index5.js +0 -761
- package/dist/chunks/index6.js +0 -322
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -83
- package/dist/cli.js +0 -546
- package/dist/ssr.js +0 -2580
package/README.md
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# The fastest way to build Svelte apps
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is the [SvelteKit](https://kit.svelte.dev) framework and CLI.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The quickest way to get started is via the [create-svelte](https://github.com/sveltejs/kit/tree/master/packages/create-svelte) package:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm create svelte@latest my-app
|
|
9
|
+
cd my-app
|
|
10
|
+
npm install
|
|
11
|
+
npm run dev
|
|
12
|
+
```
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
See the [documentation](https://kit.svelte.dev/docs) to learn more.
|
|
10
15
|
|
|
11
|
-
##
|
|
16
|
+
## Changelog
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Then, clone the corresponding [svelte-app-demo](https://github.com/sveltejs/svelte-app-demo) repo and follow the instructions therein.
|
|
18
|
+
[The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md).
|
package/package.json
CHANGED
|
@@ -1,64 +1,93 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
2
|
+
"name": "@sveltejs/kit",
|
|
3
|
+
"version": "1.0.0-next.450",
|
|
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.1",
|
|
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.7.4",
|
|
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
|
+
],
|
|
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
|
+
"build": "npm run types",
|
|
83
|
+
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
|
|
84
|
+
"check": "tsc",
|
|
85
|
+
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
|
|
86
|
+
"format": "npm run lint -- --write",
|
|
87
|
+
"test": "npm run test:unit && npm run test:integration",
|
|
88
|
+
"test:integration": "pnpm run -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
89
|
+
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
|
|
90
|
+
"types": "node scripts/extract-types.js",
|
|
91
|
+
"postinstall": "node svelte-kit.js sync"
|
|
92
|
+
}
|
|
93
|
+
}
|
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
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// in `vite dev` and `vite preview`, we use a fake asset path so that we can
|
|
2
|
+
// serve local assets while verifying that requests are correctly prefixed
|
|
3
|
+
export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
|
|
4
|
+
|
|
5
|
+
export const GENERATED_COMMENT = '// this file is generated — do not edit it\n';
|
|
6
|
+
|
|
7
|
+
export const DATA_SUFFIX = '/__data.js';
|
|
@@ -0,0 +1,223 @@
|
|
|
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_path } from '../../utils/routing.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates the Builder which is passed to adapters for building the application.
|
|
12
|
+
* @param {{
|
|
13
|
+
* config: import('types').ValidatedConfig;
|
|
14
|
+
* build_data: import('types').BuildData;
|
|
15
|
+
* prerendered: import('types').Prerendered;
|
|
16
|
+
* log: import('types').Logger;
|
|
17
|
+
* }} opts
|
|
18
|
+
* @returns {import('types').Builder}
|
|
19
|
+
*/
|
|
20
|
+
export function create_builder({ config, build_data, prerendered, log }) {
|
|
21
|
+
/** @type {Set<string>} */
|
|
22
|
+
const prerendered_paths = new Set(prerendered.paths);
|
|
23
|
+
|
|
24
|
+
/** @param {import('types').RouteData} route */
|
|
25
|
+
// TODO routes should come pre-filtered
|
|
26
|
+
function not_prerendered(route) {
|
|
27
|
+
const path = route.page && get_path(route.id);
|
|
28
|
+
if (path) {
|
|
29
|
+
return !prerendered_paths.has(path) && !prerendered_paths.has(path + '/');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pipe = promisify(pipeline);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {string} file
|
|
39
|
+
* @param {'gz' | 'br'} format
|
|
40
|
+
*/
|
|
41
|
+
async function compress_file(file, format = 'gz') {
|
|
42
|
+
const compress =
|
|
43
|
+
format == 'br'
|
|
44
|
+
? zlib.createBrotliCompress({
|
|
45
|
+
params: {
|
|
46
|
+
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
|
|
47
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
|
|
48
|
+
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: statSync(file).size
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
: zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION });
|
|
52
|
+
|
|
53
|
+
const source = createReadStream(file);
|
|
54
|
+
const destination = createWriteStream(`${file}.${format}`);
|
|
55
|
+
|
|
56
|
+
await pipe(source, compress, destination);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
log,
|
|
61
|
+
rimraf,
|
|
62
|
+
mkdirp,
|
|
63
|
+
copy,
|
|
64
|
+
|
|
65
|
+
config,
|
|
66
|
+
prerendered,
|
|
67
|
+
|
|
68
|
+
async createEntries(fn) {
|
|
69
|
+
const { routes } = build_data.manifest_data;
|
|
70
|
+
|
|
71
|
+
/** @type {import('types').RouteDefinition[]} */
|
|
72
|
+
const facades = routes.map((route) => {
|
|
73
|
+
const methods = new Set();
|
|
74
|
+
|
|
75
|
+
if (route.page) {
|
|
76
|
+
methods.add('SET');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (route.endpoint) {
|
|
80
|
+
for (const method of build_data.server.methods[route.endpoint.file]) {
|
|
81
|
+
methods.add(method);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
id: route.id,
|
|
87
|
+
type: route.page ? 'page' : 'endpoint', // TODO change this if support pages+endpoints
|
|
88
|
+
segments: route.id.split('/').map((segment) => ({
|
|
89
|
+
dynamic: segment.includes('['),
|
|
90
|
+
rest: segment.includes('[...'),
|
|
91
|
+
content: segment
|
|
92
|
+
})),
|
|
93
|
+
pattern: route.pattern,
|
|
94
|
+
methods: Array.from(methods)
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const seen = new Set();
|
|
99
|
+
|
|
100
|
+
for (let i = 0; i < routes.length; i += 1) {
|
|
101
|
+
const route = routes[i];
|
|
102
|
+
const { id, filter, complete } = fn(facades[i]);
|
|
103
|
+
|
|
104
|
+
if (seen.has(id)) continue;
|
|
105
|
+
seen.add(id);
|
|
106
|
+
|
|
107
|
+
const group = [route];
|
|
108
|
+
|
|
109
|
+
// figure out which lower priority routes should be considered fallbacks
|
|
110
|
+
for (let j = i + 1; j < routes.length; j += 1) {
|
|
111
|
+
if (filter(facades[j])) {
|
|
112
|
+
group.push(routes[j]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const filtered = new Set(group.filter(not_prerendered));
|
|
117
|
+
|
|
118
|
+
// heuristic: if /foo/[bar] is included, /foo/[bar].json should
|
|
119
|
+
// also be included, since the page likely needs the endpoint
|
|
120
|
+
// TODO is this still necessary, given the new way of doing things?
|
|
121
|
+
filtered.forEach((route) => {
|
|
122
|
+
if (route.page) {
|
|
123
|
+
const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
|
|
124
|
+
|
|
125
|
+
if (endpoint) {
|
|
126
|
+
filtered.add(endpoint);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (filtered.size > 0) {
|
|
132
|
+
await complete({
|
|
133
|
+
generateManifest: ({ relativePath, format }) =>
|
|
134
|
+
generate_manifest({
|
|
135
|
+
build_data,
|
|
136
|
+
relative_path: relativePath,
|
|
137
|
+
routes: Array.from(filtered),
|
|
138
|
+
format
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
generateManifest: ({ relativePath, format }) => {
|
|
146
|
+
return generate_manifest({
|
|
147
|
+
build_data,
|
|
148
|
+
relative_path: relativePath,
|
|
149
|
+
routes: build_data.manifest_data.routes.filter(not_prerendered),
|
|
150
|
+
format
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
getBuildDirectory(name) {
|
|
155
|
+
return `${config.kit.outDir}/${name}`;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
getClientDirectory() {
|
|
159
|
+
return `${config.kit.outDir}/output/client`;
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
getServerDirectory() {
|
|
163
|
+
return `${config.kit.outDir}/output/server`;
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
getStaticDirectory() {
|
|
167
|
+
return config.kit.files.assets;
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
writeClient(dest) {
|
|
171
|
+
return [...copy(`${config.kit.outDir}/output/client`, dest)];
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
writePrerendered(dest, { fallback } = {}) {
|
|
175
|
+
const source = `${config.kit.outDir}/output/prerendered`;
|
|
176
|
+
const files = [...copy(`${source}/pages`, dest), ...copy(`${source}/dependencies`, dest)];
|
|
177
|
+
|
|
178
|
+
if (fallback) {
|
|
179
|
+
files.push(fallback);
|
|
180
|
+
copy(`${source}/fallback.html`, `${dest}/${fallback}`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return files;
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
writeServer(dest) {
|
|
187
|
+
return copy(`${config.kit.outDir}/output/server`, dest);
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
// TODO remove these methods for 1.0
|
|
191
|
+
// @ts-expect-error
|
|
192
|
+
writeStatic() {
|
|
193
|
+
throw new Error(
|
|
194
|
+
`writeStatic has been removed. Please ensure you are using the latest version of ${
|
|
195
|
+
config.kit.adapter.name || 'your adapter'
|
|
196
|
+
}`
|
|
197
|
+
);
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
async compress(directory) {
|
|
201
|
+
if (!existsSync(directory)) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', {
|
|
206
|
+
cwd: directory,
|
|
207
|
+
dot: true,
|
|
208
|
+
absolute: true,
|
|
209
|
+
filesOnly: true
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
await Promise.all(
|
|
213
|
+
files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')]))
|
|
214
|
+
);
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
async prerender() {
|
|
218
|
+
throw new Error(
|
|
219
|
+
'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
@@ -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
|
+
}
|