@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,168 @@
|
|
|
1
|
+
const param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates the regex pattern, extracts parameter names, and generates types for a route
|
|
5
|
+
* @param {string} id
|
|
6
|
+
*/
|
|
7
|
+
export function parse_route_id(id) {
|
|
8
|
+
/** @type {string[]} */
|
|
9
|
+
const names = [];
|
|
10
|
+
|
|
11
|
+
/** @type {string[]} */
|
|
12
|
+
const types = [];
|
|
13
|
+
|
|
14
|
+
/** @type {boolean[]} */
|
|
15
|
+
const optional = [];
|
|
16
|
+
|
|
17
|
+
// `/foo` should get an optional trailing slash, `/foo.json` should not
|
|
18
|
+
// const add_trailing_slash = !/\.[a-z]+$/.test(key);
|
|
19
|
+
let add_trailing_slash = true;
|
|
20
|
+
|
|
21
|
+
const pattern =
|
|
22
|
+
id === '/'
|
|
23
|
+
? /^\/$/
|
|
24
|
+
: new RegExp(
|
|
25
|
+
`^${get_route_segments(id)
|
|
26
|
+
.map((segment, i, segments) => {
|
|
27
|
+
// special case — /[...rest]/ could contain zero segments
|
|
28
|
+
const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
|
|
29
|
+
if (rest_match) {
|
|
30
|
+
names.push(rest_match[1]);
|
|
31
|
+
types.push(rest_match[2]);
|
|
32
|
+
optional.push(false);
|
|
33
|
+
return '(?:/(.*))?';
|
|
34
|
+
}
|
|
35
|
+
// special case — /[[optional]]/ could contain zero segments
|
|
36
|
+
const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
|
|
37
|
+
if (optional_match) {
|
|
38
|
+
names.push(optional_match[1]);
|
|
39
|
+
types.push(optional_match[2]);
|
|
40
|
+
optional.push(true);
|
|
41
|
+
return '(?:/([^/]+))?';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const is_last = i === segments.length - 1;
|
|
45
|
+
|
|
46
|
+
if (!segment) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const parts = segment.split(/\[(.+?)\](?!\])/);
|
|
51
|
+
const result = parts
|
|
52
|
+
.map((content, i) => {
|
|
53
|
+
if (i % 2) {
|
|
54
|
+
if (content.startsWith('x+')) {
|
|
55
|
+
return escape(String.fromCharCode(parseInt(content.slice(2), 16)));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (content.startsWith('u+')) {
|
|
59
|
+
return escape(
|
|
60
|
+
String.fromCharCode(
|
|
61
|
+
...content
|
|
62
|
+
.slice(2)
|
|
63
|
+
.split('-')
|
|
64
|
+
.map((code) => parseInt(code, 16))
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const match = param_pattern.exec(content);
|
|
70
|
+
if (!match) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const [, is_optional, is_rest, name, type] = match;
|
|
77
|
+
// It's assumed that the following invalid route id cases are already checked
|
|
78
|
+
// - unbalanced brackets
|
|
79
|
+
// - optional param following rest param
|
|
80
|
+
|
|
81
|
+
names.push(name);
|
|
82
|
+
types.push(type);
|
|
83
|
+
optional.push(!!is_optional);
|
|
84
|
+
return is_rest ? '(.*?)' : is_optional ? '([^/]*)?' : '([^/]+?)';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (is_last && content.includes('.')) add_trailing_slash = false;
|
|
88
|
+
|
|
89
|
+
return escape(content);
|
|
90
|
+
})
|
|
91
|
+
.join('');
|
|
92
|
+
|
|
93
|
+
return '/' + result;
|
|
94
|
+
})
|
|
95
|
+
.join('')}${add_trailing_slash ? '/?' : ''}$`
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return { pattern, names, types, optional };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Returns `false` for `(group)` segments
|
|
103
|
+
* @param {string} segment
|
|
104
|
+
*/
|
|
105
|
+
function affects_path(segment) {
|
|
106
|
+
return !/^\([^)]+\)$/.test(segment);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Splits a route id into its segments, removing segments that
|
|
111
|
+
* don't affect the path (i.e. groups). The root route is represented by `/`
|
|
112
|
+
* and will be returned as `['']`.
|
|
113
|
+
* @param {string} route
|
|
114
|
+
* @returns string[]
|
|
115
|
+
*/
|
|
116
|
+
export function get_route_segments(route) {
|
|
117
|
+
return route.slice(1).split('/').filter(affects_path);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {RegExpMatchArray} match
|
|
122
|
+
* @param {{
|
|
123
|
+
* names: string[];
|
|
124
|
+
* types: string[];
|
|
125
|
+
* optional: boolean[];
|
|
126
|
+
* }} candidate
|
|
127
|
+
* @param {Record<string, import('types').ParamMatcher>} matchers
|
|
128
|
+
*/
|
|
129
|
+
export function exec(match, { names, types, optional }, matchers) {
|
|
130
|
+
/** @type {Record<string, string>} */
|
|
131
|
+
const params = {};
|
|
132
|
+
|
|
133
|
+
for (let i = 0; i < names.length; i += 1) {
|
|
134
|
+
const name = names[i];
|
|
135
|
+
const type = types[i];
|
|
136
|
+
let value = match[i + 1];
|
|
137
|
+
|
|
138
|
+
if (value || !optional[i]) {
|
|
139
|
+
if (type) {
|
|
140
|
+
const matcher = matchers[type];
|
|
141
|
+
if (!matcher) throw new Error(`Missing "${type}" param matcher`); // TODO do this ahead of time?
|
|
142
|
+
|
|
143
|
+
if (!matcher(value)) return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
params[name] = value ?? '';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return params;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** @param {string} str */
|
|
154
|
+
function escape(str) {
|
|
155
|
+
return (
|
|
156
|
+
str
|
|
157
|
+
.normalize()
|
|
158
|
+
// escape [ and ] before escaping other characters, since they are used in the replacements
|
|
159
|
+
.replace(/[[\]]/g, '\\$&')
|
|
160
|
+
// replace %, /, ? and # with their encoded versions because decode_pathname leaves them untouched
|
|
161
|
+
.replace(/%/g, '%25')
|
|
162
|
+
.replace(/\//g, '%2[Ff]')
|
|
163
|
+
.replace(/\?/g, '%3[Ff]')
|
|
164
|
+
.replace(/#/g, '%23')
|
|
165
|
+
// escape characters that have special meaning in regex
|
|
166
|
+
.replace(/[.*+?^${}()|\\]/g, '\\$&')
|
|
167
|
+
);
|
|
168
|
+
}
|
package/src/utils/url.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const absolute = /^([a-z]+:)?\/?\//;
|
|
2
|
+
const scheme = /^[a-z]+:/;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} base
|
|
6
|
+
* @param {string} path
|
|
7
|
+
*/
|
|
8
|
+
export function resolve(base, path) {
|
|
9
|
+
if (scheme.test(path)) return path;
|
|
10
|
+
if (path[0] === '#') return base + path;
|
|
11
|
+
|
|
12
|
+
const base_match = absolute.exec(base);
|
|
13
|
+
const path_match = absolute.exec(path);
|
|
14
|
+
|
|
15
|
+
if (!base_match) {
|
|
16
|
+
throw new Error(`bad base path: "${base}"`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
|
|
20
|
+
const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
|
|
21
|
+
|
|
22
|
+
baseparts.pop();
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < pathparts.length; i += 1) {
|
|
25
|
+
const part = pathparts[i];
|
|
26
|
+
if (part === '.') continue;
|
|
27
|
+
else if (part === '..') baseparts.pop();
|
|
28
|
+
else baseparts.push(part);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
|
|
32
|
+
|
|
33
|
+
return `${prefix}${baseparts.join('/')}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @param {string} path */
|
|
37
|
+
export function is_root_relative(path) {
|
|
38
|
+
return path[0] === '/' && path[1] !== '/';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} path
|
|
43
|
+
* @param {import('types').TrailingSlash} trailing_slash
|
|
44
|
+
*/
|
|
45
|
+
export function normalize_path(path, trailing_slash) {
|
|
46
|
+
if (path === '/' || trailing_slash === 'ignore') return path;
|
|
47
|
+
|
|
48
|
+
if (trailing_slash === 'never') {
|
|
49
|
+
return path.endsWith('/') ? path.slice(0, -1) : path;
|
|
50
|
+
} else if (trailing_slash === 'always' && !path.endsWith('/')) {
|
|
51
|
+
return path + '/';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return path;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Decode pathname excluding %25 to prevent further double decoding of params
|
|
59
|
+
* @param {string} pathname
|
|
60
|
+
*/
|
|
61
|
+
export function decode_pathname(pathname) {
|
|
62
|
+
return pathname.split('%25').map(decodeURI).join('%25');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @param {Record<string, string>} params */
|
|
66
|
+
export function decode_params(params) {
|
|
67
|
+
for (const key in params) {
|
|
68
|
+
// input has already been decoded by decodeURI
|
|
69
|
+
// now handle the rest
|
|
70
|
+
params[key] = decodeURIComponent(params[key]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return params;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* URL properties that could change during the lifetime of the page,
|
|
78
|
+
* which excludes things like `origin`
|
|
79
|
+
* @type {Array<keyof URL>}
|
|
80
|
+
*/
|
|
81
|
+
const tracked_url_properties = ['href', 'pathname', 'search', 'searchParams', 'toString', 'toJSON'];
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {URL} url
|
|
85
|
+
* @param {() => void} callback
|
|
86
|
+
*/
|
|
87
|
+
export function make_trackable(url, callback) {
|
|
88
|
+
const tracked = new URL(url);
|
|
89
|
+
|
|
90
|
+
for (const property of tracked_url_properties) {
|
|
91
|
+
let value = tracked[property];
|
|
92
|
+
|
|
93
|
+
Object.defineProperty(tracked, property, {
|
|
94
|
+
get() {
|
|
95
|
+
callback();
|
|
96
|
+
return value;
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!__SVELTEKIT_BROWSER__) {
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
tracked[Symbol.for('nodejs.util.inspect.custom')] = (depth, opts, inspect) => {
|
|
107
|
+
return inspect(url, opts);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
disable_hash(tracked);
|
|
112
|
+
|
|
113
|
+
return tracked;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Disallow access to `url.hash` on the server and in `load`
|
|
118
|
+
* @param {URL} url
|
|
119
|
+
*/
|
|
120
|
+
export function disable_hash(url) {
|
|
121
|
+
Object.defineProperty(url, 'hash', {
|
|
122
|
+
get() {
|
|
123
|
+
throw new Error(
|
|
124
|
+
'Cannot access event.url.hash. Consider using `$page.url.hash` inside a component instead'
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Disallow access to `url.search` and `url.searchParams` during prerendering
|
|
132
|
+
* @param {URL} url
|
|
133
|
+
*/
|
|
134
|
+
export function disable_search(url) {
|
|
135
|
+
for (const property of ['search', 'searchParams']) {
|
|
136
|
+
Object.defineProperty(url, property, {
|
|
137
|
+
get() {
|
|
138
|
+
throw new Error(`Cannot access url.${property} on a page with prerendering enabled`);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const DATA_SUFFIX = '/__data.json';
|
|
145
|
+
|
|
146
|
+
/** @param {string} pathname */
|
|
147
|
+
export function has_data_suffix(pathname) {
|
|
148
|
+
return pathname.endsWith(DATA_SUFFIX);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** @param {string} pathname */
|
|
152
|
+
export function add_data_suffix(pathname) {
|
|
153
|
+
return pathname.replace(/\/$/, '') + DATA_SUFFIX;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** @param {string} pathname */
|
|
157
|
+
export function strip_data_suffix(pathname) {
|
|
158
|
+
return pathname.slice(0, -DATA_SUFFIX.length);
|
|
159
|
+
}
|
package/svelte-kit.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import './
|
|
2
|
+
import './src/cli.js';
|