@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.
Files changed (128) hide show
  1. package/README.md +5 -2
  2. package/package.json +93 -67
  3. package/postinstall.js +47 -0
  4. package/scripts/special-types/$env+dynamic+private.md +10 -0
  5. package/scripts/special-types/$env+dynamic+public.md +8 -0
  6. package/scripts/special-types/$env+static+private.md +19 -0
  7. package/scripts/special-types/$env+static+public.md +7 -0
  8. package/scripts/special-types/$lib.md +5 -0
  9. package/src/cli.js +108 -0
  10. package/src/constants.js +5 -0
  11. package/src/core/adapt/builder.js +212 -0
  12. package/src/core/adapt/index.js +31 -0
  13. package/src/core/config/default-error.html +56 -0
  14. package/src/core/config/index.js +110 -0
  15. package/src/core/config/options.js +516 -0
  16. package/src/core/config/types.d.ts +1 -0
  17. package/src/core/env.js +121 -0
  18. package/src/core/generate_manifest/index.js +125 -0
  19. package/src/core/prerender/crawl.js +207 -0
  20. package/src/core/prerender/entities.js +2252 -0
  21. package/src/core/prerender/prerender.js +460 -0
  22. package/src/core/prerender/queue.js +80 -0
  23. package/src/core/sync/create_manifest_data/conflict.js +0 -0
  24. package/src/core/sync/create_manifest_data/index.js +513 -0
  25. package/src/core/sync/create_manifest_data/sort.js +161 -0
  26. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  27. package/src/core/sync/sync.js +78 -0
  28. package/src/core/sync/utils.js +33 -0
  29. package/src/core/sync/write_ambient.js +53 -0
  30. package/src/core/sync/write_client_manifest.js +106 -0
  31. package/src/core/sync/write_matchers.js +25 -0
  32. package/src/core/sync/write_root.js +91 -0
  33. package/src/core/sync/write_tsconfig.js +195 -0
  34. package/src/core/sync/write_types/index.js +809 -0
  35. package/src/core/utils.js +67 -0
  36. package/src/exports/hooks/index.js +1 -0
  37. package/src/exports/hooks/sequence.js +44 -0
  38. package/src/exports/index.js +45 -0
  39. package/src/exports/node/index.js +172 -0
  40. package/src/exports/node/polyfills.js +28 -0
  41. package/src/exports/vite/build/build_server.js +384 -0
  42. package/src/exports/vite/build/build_service_worker.js +92 -0
  43. package/src/exports/vite/build/utils.js +195 -0
  44. package/src/exports/vite/dev/index.js +588 -0
  45. package/src/exports/vite/graph_analysis/index.js +107 -0
  46. package/src/exports/vite/graph_analysis/types.d.ts +5 -0
  47. package/src/exports/vite/graph_analysis/utils.js +6 -0
  48. package/src/exports/vite/index.js +651 -0
  49. package/src/exports/vite/preview/index.js +193 -0
  50. package/src/exports/vite/types.d.ts +3 -0
  51. package/src/exports/vite/utils.js +171 -0
  52. package/src/runtime/app/env.js +1 -0
  53. package/src/runtime/app/environment.js +11 -0
  54. package/src/runtime/app/forms.js +141 -0
  55. package/src/runtime/app/navigation.js +23 -0
  56. package/src/runtime/app/paths.js +1 -0
  57. package/src/runtime/app/stores.js +102 -0
  58. package/src/runtime/client/ambient.d.ts +30 -0
  59. package/src/runtime/client/client.js +1726 -0
  60. package/src/runtime/client/fetcher.js +121 -0
  61. package/src/runtime/client/parse.js +60 -0
  62. package/src/runtime/client/singletons.js +21 -0
  63. package/src/runtime/client/start.js +43 -0
  64. package/src/runtime/client/types.d.ts +84 -0
  65. package/src/runtime/client/utils.js +166 -0
  66. package/src/runtime/components/error.svelte +16 -0
  67. package/{assets → src/runtime}/components/layout.svelte +0 -0
  68. package/src/runtime/control.js +98 -0
  69. package/src/runtime/env/dynamic/private.js +1 -0
  70. package/src/runtime/env/dynamic/public.js +1 -0
  71. package/src/runtime/env-private.js +6 -0
  72. package/src/runtime/env-public.js +6 -0
  73. package/src/runtime/env.js +6 -0
  74. package/src/runtime/hash.js +20 -0
  75. package/src/runtime/paths.js +11 -0
  76. package/src/runtime/server/cookie.js +231 -0
  77. package/src/runtime/server/data/index.js +144 -0
  78. package/src/runtime/server/endpoint.js +89 -0
  79. package/src/runtime/server/fetch.js +164 -0
  80. package/src/runtime/server/index.js +375 -0
  81. package/src/runtime/server/page/actions.js +258 -0
  82. package/src/runtime/server/page/crypto.js +239 -0
  83. package/src/runtime/server/page/csp.js +250 -0
  84. package/src/runtime/server/page/index.js +303 -0
  85. package/src/runtime/server/page/load_data.js +258 -0
  86. package/src/runtime/server/page/render.js +391 -0
  87. package/src/runtime/server/page/respond_with_error.js +102 -0
  88. package/src/runtime/server/page/serialize_data.js +87 -0
  89. package/src/runtime/server/page/types.d.ts +35 -0
  90. package/src/runtime/server/utils.js +205 -0
  91. package/src/utils/array.js +9 -0
  92. package/src/utils/error.js +22 -0
  93. package/src/utils/escape.js +46 -0
  94. package/src/utils/filesystem.js +166 -0
  95. package/src/utils/functions.js +16 -0
  96. package/src/utils/http.js +72 -0
  97. package/src/utils/misc.js +1 -0
  98. package/src/utils/promises.js +17 -0
  99. package/src/utils/routing.js +168 -0
  100. package/src/utils/unit_test.js +11 -0
  101. package/src/utils/url.js +159 -0
  102. package/svelte-kit.js +1 -1
  103. package/types/ambient.d.ts +469 -0
  104. package/types/index.d.ts +775 -0
  105. package/types/internal.d.ts +381 -0
  106. package/types/private.d.ts +229 -0
  107. package/CHANGELOG.md +0 -519
  108. package/assets/components/error.svelte +0 -13
  109. package/assets/runtime/app/env.js +0 -5
  110. package/assets/runtime/app/navigation.js +0 -48
  111. package/assets/runtime/app/paths.js +0 -1
  112. package/assets/runtime/app/stores.js +0 -93
  113. package/assets/runtime/chunks/utils.js +0 -22
  114. package/assets/runtime/internal/singletons.js +0 -23
  115. package/assets/runtime/internal/start.js +0 -823
  116. package/assets/runtime/paths.js +0 -12
  117. package/dist/chunks/index.js +0 -3544
  118. package/dist/chunks/index2.js +0 -572
  119. package/dist/chunks/index3.js +0 -246
  120. package/dist/chunks/index4.js +0 -569
  121. package/dist/chunks/index5.js +0 -751
  122. package/dist/chunks/index6.js +0 -323
  123. package/dist/chunks/standard.js +0 -99
  124. package/dist/chunks/utils.js +0 -83
  125. package/dist/cli.js +0 -558
  126. package/dist/ssr.js +0 -2620
  127. package/types.d.ts +0 -74
  128. 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
+ }
@@ -0,0 +1,11 @@
1
+ import { suite } from 'uvu';
2
+
3
+ /**
4
+ * @param {string} name
5
+ * @param {(suite: import('uvu').Test<import('uvu').Context>) => void} fn
6
+ */
7
+ export function describe(name, fn) {
8
+ const s = suite(name);
9
+ fn(s);
10
+ s.run();
11
+ }
@@ -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 './dist/cli.js';
2
+ import './src/cli.js';