@sveltejs/kit 1.0.0-next.55 → 1.0.0-next.550
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 +5 -2
- package/package.json +93 -67
- package/postinstall.js +47 -0
- package/scripts/special-types/$env+dynamic+private.md +10 -0
- package/scripts/special-types/$env+dynamic+public.md +8 -0
- package/scripts/special-types/$env+static+private.md +19 -0
- package/scripts/special-types/$env+static+public.md +7 -0
- package/scripts/special-types/$lib.md +5 -0
- package/src/cli.js +108 -0
- package/src/constants.js +5 -0
- package/src/core/adapt/builder.js +212 -0
- package/src/core/adapt/index.js +31 -0
- package/src/core/config/default-error.html +56 -0
- package/src/core/config/index.js +110 -0
- package/src/core/config/options.js +516 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/env.js +121 -0
- package/src/core/generate_manifest/index.js +125 -0
- package/src/core/prerender/crawl.js +207 -0
- package/src/core/prerender/entities.js +2252 -0
- package/src/core/prerender/prerender.js +460 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/conflict.js +0 -0
- package/src/core/sync/create_manifest_data/index.js +513 -0
- package/src/core/sync/create_manifest_data/sort.js +161 -0
- package/src/core/sync/create_manifest_data/types.d.ts +37 -0
- package/src/core/sync/sync.js +78 -0
- package/src/core/sync/utils.js +33 -0
- package/src/core/sync/write_ambient.js +53 -0
- package/src/core/sync/write_client_manifest.js +106 -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 +809 -0
- package/src/core/utils.js +67 -0
- package/src/exports/hooks/index.js +1 -0
- package/src/exports/hooks/sequence.js +44 -0
- package/src/exports/index.js +45 -0
- package/src/exports/node/index.js +172 -0
- package/src/exports/node/polyfills.js +28 -0
- package/src/exports/vite/build/build_server.js +384 -0
- package/src/exports/vite/build/build_service_worker.js +92 -0
- package/src/exports/vite/build/utils.js +195 -0
- package/src/exports/vite/dev/index.js +588 -0
- package/src/exports/vite/graph_analysis/index.js +107 -0
- package/src/exports/vite/graph_analysis/types.d.ts +5 -0
- package/src/exports/vite/graph_analysis/utils.js +6 -0
- package/src/exports/vite/index.js +651 -0
- package/src/exports/vite/preview/index.js +193 -0
- package/src/exports/vite/types.d.ts +3 -0
- package/src/exports/vite/utils.js +171 -0
- package/src/runtime/app/env.js +1 -0
- package/src/runtime/app/environment.js +11 -0
- package/src/runtime/app/forms.js +141 -0
- package/src/runtime/app/navigation.js +23 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +30 -0
- package/src/runtime/client/client.js +1726 -0
- package/src/runtime/client/fetcher.js +121 -0
- package/src/runtime/client/parse.js +60 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +43 -0
- package/src/runtime/client/types.d.ts +84 -0
- package/src/runtime/client/utils.js +166 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/src/runtime/control.js +98 -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 +6 -0
- package/src/runtime/env-public.js +6 -0
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +20 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/cookie.js +231 -0
- package/src/runtime/server/data/index.js +144 -0
- package/src/runtime/server/endpoint.js +89 -0
- package/src/runtime/server/fetch.js +164 -0
- package/src/runtime/server/index.js +375 -0
- package/src/runtime/server/page/actions.js +258 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +250 -0
- package/src/runtime/server/page/index.js +303 -0
- package/src/runtime/server/page/load_data.js +258 -0
- package/src/runtime/server/page/render.js +391 -0
- package/src/runtime/server/page/respond_with_error.js +102 -0
- package/src/runtime/server/page/serialize_data.js +87 -0
- package/src/runtime/server/page/types.d.ts +35 -0
- package/src/runtime/server/utils.js +205 -0
- package/src/utils/array.js +9 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +46 -0
- package/src/utils/filesystem.js +166 -0
- package/src/utils/functions.js +16 -0
- package/src/utils/http.js +72 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/promises.js +17 -0
- package/src/utils/routing.js +168 -0
- package/src/utils/unit_test.js +11 -0
- package/src/utils/url.js +159 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +469 -0
- package/types/index.d.ts +775 -0
- package/types/internal.d.ts +381 -0
- package/types/private.d.ts +229 -0
- package/CHANGELOG.md +0 -519
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -48
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -22
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -823
- package/assets/runtime/paths.js +0 -12
- package/dist/chunks/index.js +0 -3544
- package/dist/chunks/index2.js +0 -572
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -569
- package/dist/chunks/index5.js +0 -751
- package/dist/chunks/index6.js +0 -323
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -83
- package/dist/cli.js +0 -558
- package/dist/ssr.js +0 -2620
- package/types.d.ts +0 -74
- package/types.internal.d.ts +0 -237
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import sirv from 'sirv';
|
|
4
|
+
import { pathToFileURL } from 'url';
|
|
5
|
+
import { getRequest, setResponse } from '../../../exports/node/index.js';
|
|
6
|
+
import { installPolyfills } from '../../../exports/node/polyfills.js';
|
|
7
|
+
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
8
|
+
import { loadEnv, normalizePath } from 'vite';
|
|
9
|
+
|
|
10
|
+
/** @typedef {import('http').IncomingMessage} Req */
|
|
11
|
+
/** @typedef {import('http').ServerResponse} Res */
|
|
12
|
+
/** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {{
|
|
16
|
+
* middlewares: import('connect').Server;
|
|
17
|
+
* httpServer: import('http').Server;
|
|
18
|
+
* }} vite
|
|
19
|
+
* @param {import('vite').ResolvedConfig} vite_config
|
|
20
|
+
* @param {import('types').ValidatedConfig} svelte_config
|
|
21
|
+
*/
|
|
22
|
+
export async function preview(vite, vite_config, svelte_config) {
|
|
23
|
+
installPolyfills();
|
|
24
|
+
|
|
25
|
+
const { paths } = svelte_config.kit;
|
|
26
|
+
const base = paths.base;
|
|
27
|
+
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
|
|
28
|
+
|
|
29
|
+
const protocol = vite_config.preview.https ? 'https' : 'http';
|
|
30
|
+
|
|
31
|
+
const etag = `"${Date.now()}"`;
|
|
32
|
+
|
|
33
|
+
const index_file = join(svelte_config.kit.outDir, 'output/server/index.js');
|
|
34
|
+
const manifest_file = join(svelte_config.kit.outDir, 'output/server/manifest.js');
|
|
35
|
+
|
|
36
|
+
/** @type {import('types').ServerModule} */
|
|
37
|
+
const { Server, override } = await import(pathToFileURL(index_file).href);
|
|
38
|
+
const { manifest } = await import(pathToFileURL(manifest_file).href);
|
|
39
|
+
|
|
40
|
+
override({
|
|
41
|
+
paths: { base, assets },
|
|
42
|
+
prerendering: false,
|
|
43
|
+
protocol,
|
|
44
|
+
read: (file) => fs.readFileSync(join(svelte_config.kit.files.assets, file))
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const server = new Server(manifest);
|
|
48
|
+
await server.init({
|
|
49
|
+
env: loadEnv(vite_config.mode, svelte_config.kit.env.dir, '')
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
// generated client assets and the contents of `static`
|
|
54
|
+
vite.middlewares.use(
|
|
55
|
+
scoped(
|
|
56
|
+
assets,
|
|
57
|
+
sirv(join(svelte_config.kit.outDir, 'output/client'), {
|
|
58
|
+
setHeaders: (res, pathname) => {
|
|
59
|
+
// only apply to immutable directory, not e.g. version.json
|
|
60
|
+
if (pathname.startsWith(`/${svelte_config.kit.appDir}/immutable`)) {
|
|
61
|
+
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
vite.middlewares.use((req, res, next) => {
|
|
69
|
+
const original_url = /** @type {string} */ (req.url);
|
|
70
|
+
const { pathname } = new URL(original_url, 'http://dummy');
|
|
71
|
+
|
|
72
|
+
if (pathname.startsWith(base)) {
|
|
73
|
+
next();
|
|
74
|
+
} else {
|
|
75
|
+
res.statusCode = 404;
|
|
76
|
+
res.end(`Not found (did you mean ${base + pathname}?)`);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// prerendered dependencies
|
|
81
|
+
vite.middlewares.use(
|
|
82
|
+
scoped(base, mutable(join(svelte_config.kit.outDir, 'output/prerendered/dependencies')))
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// prerendered pages (we can't just use sirv because we need to
|
|
86
|
+
// preserve the correct trailingSlash behaviour)
|
|
87
|
+
vite.middlewares.use(
|
|
88
|
+
scoped(base, (req, res, next) => {
|
|
89
|
+
let if_none_match_value = req.headers['if-none-match'];
|
|
90
|
+
|
|
91
|
+
if (if_none_match_value?.startsWith('W/"')) {
|
|
92
|
+
if_none_match_value = if_none_match_value.substring(2);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (if_none_match_value === etag) {
|
|
96
|
+
res.statusCode = 304;
|
|
97
|
+
res.end();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const { pathname } = new URL(/** @type {string} */ (req.url), 'http://dummy');
|
|
102
|
+
|
|
103
|
+
let filename = normalizePath(
|
|
104
|
+
join(svelte_config.kit.outDir, 'output/prerendered/pages' + pathname)
|
|
105
|
+
);
|
|
106
|
+
let prerendered = is_file(filename);
|
|
107
|
+
|
|
108
|
+
if (!prerendered) {
|
|
109
|
+
filename += filename.endsWith('/') ? 'index.html' : '.html';
|
|
110
|
+
prerendered = is_file(filename);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (prerendered) {
|
|
114
|
+
res.writeHead(200, {
|
|
115
|
+
'content-type': 'text/html',
|
|
116
|
+
etag
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
fs.createReadStream(filename).pipe(res);
|
|
120
|
+
} else {
|
|
121
|
+
next();
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// SSR
|
|
127
|
+
vite.middlewares.use(async (req, res) => {
|
|
128
|
+
const host = req.headers['host'];
|
|
129
|
+
|
|
130
|
+
let request;
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
request = await getRequest({
|
|
134
|
+
base: `${protocol}://${host}`,
|
|
135
|
+
request: req
|
|
136
|
+
});
|
|
137
|
+
} catch (/** @type {any} */ err) {
|
|
138
|
+
res.statusCode = err.status || 400;
|
|
139
|
+
return res.end('Invalid request body');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setResponse(
|
|
143
|
+
res,
|
|
144
|
+
await server.respond(request, {
|
|
145
|
+
getClientAddress: () => {
|
|
146
|
+
const { remoteAddress } = req.socket;
|
|
147
|
+
if (remoteAddress) return remoteAddress;
|
|
148
|
+
throw new Error('Could not determine clientAddress');
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {string} dir
|
|
158
|
+
* @returns {Handler}
|
|
159
|
+
*/
|
|
160
|
+
const mutable = (dir) =>
|
|
161
|
+
fs.existsSync(dir)
|
|
162
|
+
? sirv(dir, {
|
|
163
|
+
etag: true,
|
|
164
|
+
maxAge: 0
|
|
165
|
+
})
|
|
166
|
+
: (_req, _res, next) => next();
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @param {string} scope
|
|
170
|
+
* @param {Handler} handler
|
|
171
|
+
* @returns {Handler}
|
|
172
|
+
*/
|
|
173
|
+
function scoped(scope, handler) {
|
|
174
|
+
if (scope === '') return handler;
|
|
175
|
+
|
|
176
|
+
return (req, res, next) => {
|
|
177
|
+
if (req.url?.startsWith(scope)) {
|
|
178
|
+
const original_url = req.url;
|
|
179
|
+
req.url = req.url.slice(scope.length);
|
|
180
|
+
handler(req, res, () => {
|
|
181
|
+
req.url = original_url;
|
|
182
|
+
next();
|
|
183
|
+
});
|
|
184
|
+
} else {
|
|
185
|
+
next();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** @param {string} path */
|
|
191
|
+
function is_file(path) {
|
|
192
|
+
return fs.existsSync(path) && !fs.statSync(path).isDirectory();
|
|
193
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { loadConfigFromFile, loadEnv } from 'vite';
|
|
3
|
+
import { runtime_directory } from '../../core/utils.js';
|
|
4
|
+
import { posixify } from '../../utils/filesystem.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {import('vite').ResolvedConfig} config
|
|
8
|
+
* @param {import('vite').ConfigEnv} config_env
|
|
9
|
+
* @return {Promise<import('vite').UserConfig>}
|
|
10
|
+
*/
|
|
11
|
+
export async function get_vite_config(config, config_env) {
|
|
12
|
+
const loaded = await loadConfigFromFile(
|
|
13
|
+
config_env,
|
|
14
|
+
config.configFile,
|
|
15
|
+
undefined,
|
|
16
|
+
config.logLevel
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (!loaded) {
|
|
20
|
+
throw new Error('Could not load Vite config');
|
|
21
|
+
}
|
|
22
|
+
return { ...loaded.config, mode: config_env.mode };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {...import('vite').UserConfig} configs
|
|
27
|
+
* @returns {import('vite').UserConfig}
|
|
28
|
+
*/
|
|
29
|
+
export function merge_vite_configs(...configs) {
|
|
30
|
+
return deep_merge(
|
|
31
|
+
...configs.map((config) => ({
|
|
32
|
+
...config,
|
|
33
|
+
resolve: {
|
|
34
|
+
...config.resolve,
|
|
35
|
+
alias: normalize_alias(config.resolve?.alias || {})
|
|
36
|
+
}
|
|
37
|
+
}))
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Takes zero or more objects and returns a new object that has all the values
|
|
43
|
+
* deeply merged together. None of the original objects will be mutated at any
|
|
44
|
+
* level, and the returned object will have no references to the original
|
|
45
|
+
* objects at any depth. If there's a conflict the last one wins, except for
|
|
46
|
+
* arrays which will be combined.
|
|
47
|
+
* @param {...Object} objects
|
|
48
|
+
* @returns {Record<string, any>} the merged object
|
|
49
|
+
*/
|
|
50
|
+
export function deep_merge(...objects) {
|
|
51
|
+
const result = {};
|
|
52
|
+
/** @type {string[]} */
|
|
53
|
+
objects.forEach((o) => merge_into(result, o));
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* normalize kit.vite.resolve.alias as an array
|
|
59
|
+
* @param {import('vite').AliasOptions} o
|
|
60
|
+
* @returns {import('vite').Alias[]}
|
|
61
|
+
*/
|
|
62
|
+
function normalize_alias(o) {
|
|
63
|
+
if (Array.isArray(o)) return o;
|
|
64
|
+
return Object.entries(o).map(([find, replacement]) => ({ find, replacement }));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Merges b into a, recursively, mutating a.
|
|
69
|
+
* @param {Record<string, any>} a
|
|
70
|
+
* @param {Record<string, any>} b
|
|
71
|
+
*/
|
|
72
|
+
function merge_into(a, b) {
|
|
73
|
+
/**
|
|
74
|
+
* Checks for "plain old Javascript object", typically made as an object
|
|
75
|
+
* literal. Excludes Arrays and built-in types like Buffer.
|
|
76
|
+
* @param {any} x
|
|
77
|
+
*/
|
|
78
|
+
const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
|
|
79
|
+
|
|
80
|
+
for (const prop in b) {
|
|
81
|
+
if (is_plain_object(b[prop])) {
|
|
82
|
+
if (!is_plain_object(a[prop])) {
|
|
83
|
+
a[prop] = {};
|
|
84
|
+
}
|
|
85
|
+
merge_into(a[prop], b[prop]);
|
|
86
|
+
} else if (Array.isArray(b[prop])) {
|
|
87
|
+
if (!Array.isArray(a[prop])) {
|
|
88
|
+
a[prop] = [];
|
|
89
|
+
}
|
|
90
|
+
a[prop].push(...b[prop]);
|
|
91
|
+
} else {
|
|
92
|
+
a[prop] = b[prop];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Transforms kit.alias to a valid vite.resolve.alias array.
|
|
99
|
+
*
|
|
100
|
+
* Related to tsconfig path alias creation.
|
|
101
|
+
*
|
|
102
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
103
|
+
* */
|
|
104
|
+
export function get_config_aliases(config) {
|
|
105
|
+
/** @type {import('vite').Alias[]} */
|
|
106
|
+
const alias = [
|
|
107
|
+
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
108
|
+
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
109
|
+
{ find: '$lib', replacement: config.files.lib }
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
for (let [key, value] of Object.entries(config.alias)) {
|
|
113
|
+
value = posixify(value);
|
|
114
|
+
if (value.endsWith('/*')) {
|
|
115
|
+
value = value.slice(0, -2);
|
|
116
|
+
}
|
|
117
|
+
if (key.endsWith('/*')) {
|
|
118
|
+
// Doing just `{ find: key.slice(0, -2) ,..}` would mean `import .. from "key"` would also be matched, which we don't want
|
|
119
|
+
alias.push({
|
|
120
|
+
find: new RegExp(`^${escape_for_regexp(key.slice(0, -2))}\\/(.+)$`),
|
|
121
|
+
replacement: `${path.resolve(value)}/$1`
|
|
122
|
+
});
|
|
123
|
+
} else if (key + '/*' in config.alias) {
|
|
124
|
+
// key and key/* both exist -> the replacement for key needs to happen _only_ on import .. from "key"
|
|
125
|
+
alias.push({
|
|
126
|
+
find: new RegExp(`^${escape_for_regexp(key)}$`),
|
|
127
|
+
replacement: path.resolve(value)
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
alias.push({ find: key, replacement: path.resolve(value) });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return alias;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Returns Vite aliases for generated and runtime files.
|
|
139
|
+
*
|
|
140
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
141
|
+
* */
|
|
142
|
+
export function get_app_aliases(config) {
|
|
143
|
+
/** @type {import('vite').Alias[]} */
|
|
144
|
+
const alias = [
|
|
145
|
+
{ find: '__GENERATED__', replacement: path.posix.join(config.outDir, 'generated') },
|
|
146
|
+
{ find: '$app', replacement: `${runtime_directory}/app` }
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
return alias;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @param {string} str
|
|
154
|
+
*/
|
|
155
|
+
function escape_for_regexp(str) {
|
|
156
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, (match) => '\\' + match);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Load environment variables from process.env and .env files
|
|
161
|
+
* @param {import('types').ValidatedKitConfig['env']} env_config
|
|
162
|
+
* @param {string} mode
|
|
163
|
+
*/
|
|
164
|
+
export function get_env(env_config, mode) {
|
|
165
|
+
const entries = Object.entries(loadEnv(mode, env_config.dir, ''));
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
public: Object.fromEntries(entries.filter(([k]) => k.startsWith(env_config.publicPrefix))),
|
|
169
|
+
private: Object.fromEntries(entries.filter(([k]) => !k.startsWith(env_config.publicPrefix)))
|
|
170
|
+
};
|
|
171
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throw new Error('$app/env has been renamed to $app/environment');
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as devalue from 'devalue';
|
|
2
|
+
import { client } from '../client/singletons.js';
|
|
3
|
+
import { invalidateAll } from './navigation.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} name
|
|
7
|
+
*/
|
|
8
|
+
function guard(name) {
|
|
9
|
+
return () => {
|
|
10
|
+
throw new Error(`Cannot call ${name}(...) on the server`);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ssr = import.meta.env.SSR;
|
|
15
|
+
|
|
16
|
+
/** @type {import('$app/forms').applyAction} */
|
|
17
|
+
export const applyAction = ssr ? guard('applyAction') : client.apply_action;
|
|
18
|
+
|
|
19
|
+
/** @type {import('$app/forms').deserialize} */
|
|
20
|
+
export function deserialize(result) {
|
|
21
|
+
const parsed = JSON.parse(result);
|
|
22
|
+
if (parsed.data) {
|
|
23
|
+
parsed.data = devalue.parse(parsed.data);
|
|
24
|
+
}
|
|
25
|
+
return parsed;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @type {import('$app/forms').enhance} */
|
|
29
|
+
export function enhance(form, submit = () => {}) {
|
|
30
|
+
/**
|
|
31
|
+
* @param {{
|
|
32
|
+
* action: URL;
|
|
33
|
+
* result: import('types').ActionResult;
|
|
34
|
+
* reset?: boolean
|
|
35
|
+
* }} opts
|
|
36
|
+
*/
|
|
37
|
+
const fallback_callback = async ({ action, result, reset }) => {
|
|
38
|
+
if (result.type === 'success') {
|
|
39
|
+
if (reset !== false) {
|
|
40
|
+
// We call reset from the prototype to avoid DOM clobbering
|
|
41
|
+
HTMLFormElement.prototype.reset.call(form);
|
|
42
|
+
}
|
|
43
|
+
await invalidateAll();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// For success/invalid results, only apply action if it belongs to the
|
|
47
|
+
// current page, otherwise `form` will be updated erroneously
|
|
48
|
+
if (
|
|
49
|
+
location.origin + location.pathname === action.origin + action.pathname ||
|
|
50
|
+
result.type === 'redirect' ||
|
|
51
|
+
result.type === 'error'
|
|
52
|
+
) {
|
|
53
|
+
applyAction(result);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** @param {SubmitEvent} event */
|
|
58
|
+
async function handle_submit(event) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
|
|
61
|
+
const action = new URL(
|
|
62
|
+
// We can't do submitter.formAction directly because that property is always set
|
|
63
|
+
// We do cloneNode for avoid DOM clobbering - https://github.com/sveltejs/kit/issues/7593
|
|
64
|
+
event.submitter?.hasAttribute('formaction')
|
|
65
|
+
? /** @type {HTMLButtonElement | HTMLInputElement} */ (event.submitter).formAction
|
|
66
|
+
: /** @type {HTMLFormElement} */ (HTMLFormElement.prototype.cloneNode.call(form)).action
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const data = new FormData(form);
|
|
70
|
+
|
|
71
|
+
const submitter_name = event.submitter?.getAttribute('name');
|
|
72
|
+
if (submitter_name) {
|
|
73
|
+
data.append(submitter_name, event.submitter?.getAttribute('value') ?? '');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const controller = new AbortController();
|
|
77
|
+
|
|
78
|
+
let cancelled = false;
|
|
79
|
+
const cancel = () => (cancelled = true);
|
|
80
|
+
|
|
81
|
+
const callback =
|
|
82
|
+
(await submit({
|
|
83
|
+
action,
|
|
84
|
+
cancel,
|
|
85
|
+
controller,
|
|
86
|
+
data,
|
|
87
|
+
form
|
|
88
|
+
})) ?? fallback_callback;
|
|
89
|
+
if (cancelled) return;
|
|
90
|
+
|
|
91
|
+
/** @type {import('types').ActionResult} */
|
|
92
|
+
let result;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const response = await fetch(action, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers: {
|
|
98
|
+
accept: 'application/json',
|
|
99
|
+
'x-sveltekit-action': 'true'
|
|
100
|
+
},
|
|
101
|
+
cache: 'no-store',
|
|
102
|
+
body: data,
|
|
103
|
+
signal: controller.signal
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
result = deserialize(await response.text());
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (/** @type {any} */ (error)?.name === 'AbortError') return;
|
|
109
|
+
result = { type: 'error', error };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
callback({
|
|
113
|
+
action,
|
|
114
|
+
data,
|
|
115
|
+
form,
|
|
116
|
+
update: (opts) => fallback_callback({ action, result, reset: opts?.reset }),
|
|
117
|
+
// @ts-expect-error generic constraints stuff we don't care about
|
|
118
|
+
result,
|
|
119
|
+
// TODO remove for 1.0
|
|
120
|
+
get type() {
|
|
121
|
+
throw new Error('(result) => {...} has changed to ({ result }) => {...}');
|
|
122
|
+
},
|
|
123
|
+
get location() {
|
|
124
|
+
throw new Error('(result) => {...} has changed to ({ result }) => {...}');
|
|
125
|
+
},
|
|
126
|
+
get error() {
|
|
127
|
+
throw new Error('(result) => {...} has changed to ({ result }) => {...}');
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// @ts-expect-error
|
|
133
|
+
HTMLFormElement.prototype.addEventListener.call(form, 'submit', handle_submit);
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
destroy() {
|
|
137
|
+
// @ts-expect-error
|
|
138
|
+
HTMLFormElement.prototype.removeEventListener.call(form, 'submit', handle_submit);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { client } from '../client/singletons.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} name
|
|
5
|
+
*/
|
|
6
|
+
function guard(name) {
|
|
7
|
+
return () => {
|
|
8
|
+
throw new Error(`Cannot call ${name}(...) on the server`);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ssr = import.meta.env.SSR;
|
|
13
|
+
|
|
14
|
+
export const disableScrollHandling = ssr
|
|
15
|
+
? guard('disableScrollHandling')
|
|
16
|
+
: client.disable_scroll_handling;
|
|
17
|
+
export const goto = ssr ? guard('goto') : client.goto;
|
|
18
|
+
export const invalidate = ssr ? guard('invalidate') : client.invalidate;
|
|
19
|
+
export const invalidateAll = ssr ? guard('invalidateAll') : client.invalidateAll;
|
|
20
|
+
export const prefetch = ssr ? guard('prefetch') : client.prefetch;
|
|
21
|
+
export const prefetchRoutes = ssr ? guard('prefetchRoutes') : client.prefetch_routes;
|
|
22
|
+
export const beforeNavigate = ssr ? () => {} : client.before_navigate;
|
|
23
|
+
export const afterNavigate = ssr ? () => {} : client.after_navigate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { base, assets } from '../paths.js';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getContext } from 'svelte';
|
|
2
|
+
import { browser } from './environment.js';
|
|
3
|
+
import { stores as browser_stores } from '../client/singletons.js';
|
|
4
|
+
|
|
5
|
+
// TODO remove this (for 1.0? after 1.0?)
|
|
6
|
+
let warned = false;
|
|
7
|
+
export function stores() {
|
|
8
|
+
if (!warned) {
|
|
9
|
+
console.error('stores() is deprecated; use getStores() instead');
|
|
10
|
+
warned = true;
|
|
11
|
+
}
|
|
12
|
+
return getStores();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {import('$app/stores').getStores}
|
|
17
|
+
*/
|
|
18
|
+
export const getStores = () => {
|
|
19
|
+
const stores = browser ? browser_stores : getContext('__svelte__');
|
|
20
|
+
|
|
21
|
+
const readonly_stores = {
|
|
22
|
+
page: {
|
|
23
|
+
subscribe: stores.page.subscribe
|
|
24
|
+
},
|
|
25
|
+
navigating: {
|
|
26
|
+
subscribe: stores.navigating.subscribe
|
|
27
|
+
},
|
|
28
|
+
updated: stores.updated
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// TODO remove this for 1.0
|
|
32
|
+
Object.defineProperties(readonly_stores, {
|
|
33
|
+
preloading: {
|
|
34
|
+
get() {
|
|
35
|
+
console.error('stores.preloading is deprecated; use stores.navigating instead');
|
|
36
|
+
return {
|
|
37
|
+
subscribe: stores.navigating.subscribe
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
enumerable: false
|
|
41
|
+
},
|
|
42
|
+
session: {
|
|
43
|
+
get() {
|
|
44
|
+
removed_session();
|
|
45
|
+
return {};
|
|
46
|
+
},
|
|
47
|
+
enumerable: false
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return readonly_stores;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** @type {typeof import('$app/stores').page} */
|
|
55
|
+
export const page = {
|
|
56
|
+
/** @param {(value: any) => void} fn */
|
|
57
|
+
subscribe(fn) {
|
|
58
|
+
const store = getStores().page;
|
|
59
|
+
return store.subscribe(fn);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** @type {typeof import('$app/stores').navigating} */
|
|
64
|
+
export const navigating = {
|
|
65
|
+
subscribe(fn) {
|
|
66
|
+
const store = getStores().navigating;
|
|
67
|
+
return store.subscribe(fn);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function removed_session() {
|
|
72
|
+
// TODO remove for 1.0
|
|
73
|
+
throw new Error(
|
|
74
|
+
'stores.session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const session = {
|
|
79
|
+
subscribe: removed_session,
|
|
80
|
+
set: removed_session,
|
|
81
|
+
update: removed_session
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** @type {typeof import('$app/stores').updated} */
|
|
85
|
+
export const updated = {
|
|
86
|
+
subscribe(fn) {
|
|
87
|
+
const store = getStores().updated;
|
|
88
|
+
|
|
89
|
+
if (browser) {
|
|
90
|
+
updated.check = store.check;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return store.subscribe(fn);
|
|
94
|
+
},
|
|
95
|
+
check: () => {
|
|
96
|
+
throw new Error(
|
|
97
|
+
browser
|
|
98
|
+
? `Cannot check updated store before subscribing`
|
|
99
|
+
: `Can only check updated store in browser`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare module '__GENERATED__/client-manifest.js' {
|
|
2
|
+
import { CSRPageNodeLoader, ClientHooks, ParamMatcher } from 'types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A list of all the error/layout/page nodes used in the app
|
|
6
|
+
*/
|
|
7
|
+
export const nodes: CSRPageNodeLoader[];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A list of all layout node ids that have a server load function.
|
|
11
|
+
* Pages are not present because it's shorter to encode it on the leaf itself.
|
|
12
|
+
*/
|
|
13
|
+
export const server_loads: number[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A map of `[routeId: string]: [leaf, layouts, errors]` tuples, which
|
|
17
|
+
* is parsed into an array of routes on startup. The numbers refer to the indices in `nodes`.
|
|
18
|
+
* If the leaf number is negative, it means it does use a server load function and the complement is the node index.
|
|
19
|
+
* The route layout and error nodes are not referenced, they are always number 0 and 1 and always apply.
|
|
20
|
+
*/
|
|
21
|
+
export const dictionary: Record<string, [leaf: number, layouts: number[], errors?: number[]]>;
|
|
22
|
+
|
|
23
|
+
export const matchers: Record<string, ParamMatcher>;
|
|
24
|
+
|
|
25
|
+
export const hooks: ClientHooks;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare module '__GENERATED__/root.svelte' {
|
|
29
|
+
export { SvelteComponent as default } from 'svelte';
|
|
30
|
+
}
|