@sveltejs/kit 1.0.0-next.99 → 1.0.1

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 (141) hide show
  1. package/README.md +5 -1
  2. package/package.json +91 -77
  3. package/postinstall.js +47 -0
  4. package/src/cli.js +44 -0
  5. package/src/constants.js +5 -0
  6. package/src/core/adapt/builder.js +221 -0
  7. package/src/core/adapt/index.js +31 -0
  8. package/src/core/config/default-error.html +56 -0
  9. package/src/core/config/index.js +100 -0
  10. package/src/core/config/options.js +387 -0
  11. package/src/core/config/types.d.ts +1 -0
  12. package/src/core/env.js +138 -0
  13. package/src/core/generate_manifest/index.js +116 -0
  14. package/src/core/prerender/crawl.js +207 -0
  15. package/src/core/prerender/entities.js +2252 -0
  16. package/src/core/prerender/fallback.js +43 -0
  17. package/src/core/prerender/prerender.js +459 -0
  18. package/src/core/prerender/queue.js +80 -0
  19. package/src/core/sync/create_manifest_data/conflict.js +0 -0
  20. package/src/core/sync/create_manifest_data/index.js +523 -0
  21. package/src/core/sync/create_manifest_data/sort.js +161 -0
  22. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  23. package/src/core/sync/sync.js +59 -0
  24. package/src/core/sync/utils.js +33 -0
  25. package/src/core/sync/write_ambient.js +58 -0
  26. package/src/core/sync/write_client_manifest.js +107 -0
  27. package/src/core/sync/write_matchers.js +25 -0
  28. package/src/core/sync/write_root.js +91 -0
  29. package/src/core/sync/write_tsconfig.js +195 -0
  30. package/src/core/sync/write_types/index.js +809 -0
  31. package/src/core/utils.js +67 -0
  32. package/src/exports/hooks/index.js +1 -0
  33. package/src/exports/hooks/sequence.js +44 -0
  34. package/src/exports/index.js +55 -0
  35. package/src/exports/node/index.js +172 -0
  36. package/src/exports/node/polyfills.js +28 -0
  37. package/src/exports/vite/build/build_server.js +359 -0
  38. package/src/exports/vite/build/build_service_worker.js +85 -0
  39. package/src/exports/vite/build/utils.js +230 -0
  40. package/src/exports/vite/dev/index.js +597 -0
  41. package/src/exports/vite/graph_analysis/index.js +99 -0
  42. package/src/exports/vite/graph_analysis/types.d.ts +5 -0
  43. package/src/exports/vite/graph_analysis/utils.js +6 -0
  44. package/src/exports/vite/index.js +708 -0
  45. package/src/exports/vite/preview/index.js +194 -0
  46. package/src/exports/vite/types.d.ts +3 -0
  47. package/src/exports/vite/utils.js +184 -0
  48. package/src/runtime/app/env.js +1 -0
  49. package/src/runtime/app/environment.js +13 -0
  50. package/src/runtime/app/forms.js +135 -0
  51. package/src/runtime/app/navigation.js +22 -0
  52. package/src/runtime/app/paths.js +1 -0
  53. package/src/runtime/app/stores.js +57 -0
  54. package/src/runtime/client/ambient.d.ts +30 -0
  55. package/src/runtime/client/client.js +1725 -0
  56. package/src/runtime/client/constants.js +10 -0
  57. package/src/runtime/client/fetcher.js +127 -0
  58. package/src/runtime/client/parse.js +60 -0
  59. package/src/runtime/client/singletons.js +21 -0
  60. package/src/runtime/client/start.js +45 -0
  61. package/src/runtime/client/types.d.ts +86 -0
  62. package/src/runtime/client/utils.js +257 -0
  63. package/src/runtime/components/error.svelte +6 -0
  64. package/{assets → src/runtime}/components/layout.svelte +0 -0
  65. package/src/runtime/control.js +45 -0
  66. package/src/runtime/env/dynamic/private.js +1 -0
  67. package/src/runtime/env/dynamic/public.js +1 -0
  68. package/src/runtime/env-private.js +6 -0
  69. package/src/runtime/env-public.js +6 -0
  70. package/src/runtime/env.js +12 -0
  71. package/src/runtime/hash.js +20 -0
  72. package/src/runtime/paths.js +11 -0
  73. package/src/runtime/server/cookie.js +228 -0
  74. package/src/runtime/server/data/index.js +158 -0
  75. package/src/runtime/server/endpoint.js +86 -0
  76. package/src/runtime/server/fetch.js +175 -0
  77. package/src/runtime/server/index.js +405 -0
  78. package/src/runtime/server/page/actions.js +267 -0
  79. package/src/runtime/server/page/crypto.js +239 -0
  80. package/src/runtime/server/page/csp.js +250 -0
  81. package/src/runtime/server/page/index.js +326 -0
  82. package/src/runtime/server/page/load_data.js +270 -0
  83. package/src/runtime/server/page/render.js +393 -0
  84. package/src/runtime/server/page/respond_with_error.js +103 -0
  85. package/src/runtime/server/page/serialize_data.js +87 -0
  86. package/src/runtime/server/page/types.d.ts +35 -0
  87. package/src/runtime/server/utils.js +179 -0
  88. package/src/utils/array.js +9 -0
  89. package/src/utils/error.js +22 -0
  90. package/src/utils/escape.js +46 -0
  91. package/src/utils/exports.js +54 -0
  92. package/src/utils/filesystem.js +178 -0
  93. package/src/utils/functions.js +16 -0
  94. package/src/utils/http.js +72 -0
  95. package/src/utils/misc.js +1 -0
  96. package/src/utils/promises.js +17 -0
  97. package/src/utils/routing.js +201 -0
  98. package/src/utils/unit_test.js +11 -0
  99. package/src/utils/url.js +161 -0
  100. package/svelte-kit.js +1 -1
  101. package/types/ambient.d.ts +451 -0
  102. package/types/index.d.ts +1168 -5
  103. package/types/internal.d.ts +348 -159
  104. package/types/private.d.ts +237 -0
  105. package/types/synthetic/$env+dynamic+private.md +10 -0
  106. package/types/synthetic/$env+dynamic+public.md +8 -0
  107. package/types/synthetic/$env+static+private.md +19 -0
  108. package/types/synthetic/$env+static+public.md +7 -0
  109. package/types/synthetic/$lib.md +5 -0
  110. package/CHANGELOG.md +0 -825
  111. package/assets/components/error.svelte +0 -21
  112. package/assets/runtime/app/env.js +0 -16
  113. package/assets/runtime/app/navigation.js +0 -53
  114. package/assets/runtime/app/paths.js +0 -1
  115. package/assets/runtime/app/stores.js +0 -87
  116. package/assets/runtime/chunks/utils.js +0 -13
  117. package/assets/runtime/env.js +0 -8
  118. package/assets/runtime/internal/singletons.js +0 -20
  119. package/assets/runtime/internal/start.js +0 -1061
  120. package/assets/runtime/paths.js +0 -12
  121. package/dist/chunks/_commonjsHelpers.js +0 -8
  122. package/dist/chunks/cert.js +0 -29079
  123. package/dist/chunks/constants.js +0 -3
  124. package/dist/chunks/index.js +0 -3532
  125. package/dist/chunks/index2.js +0 -583
  126. package/dist/chunks/index3.js +0 -31
  127. package/dist/chunks/index4.js +0 -1004
  128. package/dist/chunks/index5.js +0 -327
  129. package/dist/chunks/index6.js +0 -325
  130. package/dist/chunks/standard.js +0 -99
  131. package/dist/chunks/utils.js +0 -149
  132. package/dist/cli.js +0 -711
  133. package/dist/http.js +0 -66
  134. package/dist/install-fetch.js +0 -1699
  135. package/dist/ssr.js +0 -1523
  136. package/types/ambient-modules.d.ts +0 -115
  137. package/types/config.d.ts +0 -101
  138. package/types/endpoint.d.ts +0 -23
  139. package/types/helper.d.ts +0 -19
  140. package/types/hooks.d.ts +0 -21
  141. package/types/page.d.ts +0 -30
@@ -0,0 +1,116 @@
1
+ import { s } from '../../utils/misc.js';
2
+ import { get_mime_lookup } from '../utils.js';
3
+ import { resolve_symlinks } from '../../exports/vite/build/utils.js';
4
+ import { compact } from '../../utils/array.js';
5
+ import { join_relative } from '../../utils/filesystem.js';
6
+
7
+ /**
8
+ * Generates the data used to write the server-side manifest.js file. This data is used in the Vite
9
+ * build process, to power routing, etc.
10
+ * @param {{
11
+ * build_data: import('types').BuildData;
12
+ * relative_path: string;
13
+ * routes: import('types').RouteData[];
14
+ * }} opts
15
+ */
16
+ export function generate_manifest({ build_data, relative_path, routes }) {
17
+ /**
18
+ * @type {Map<any, number>} The new index of each node in the filtered nodes array
19
+ */
20
+ const reindexed = new Map();
21
+ /**
22
+ * All nodes actually used in the routes definition (prerendered routes are omitted).
23
+ * Root layout/error is always included as they are needed for 404 and root errors.
24
+ * @type {Set<any>}
25
+ */
26
+ const used_nodes = new Set([0, 1]);
27
+
28
+ for (const route of routes) {
29
+ if (route.page) {
30
+ for (const i of route.page.layouts) used_nodes.add(i);
31
+ for (const i of route.page.errors) used_nodes.add(i);
32
+ used_nodes.add(route.page.leaf);
33
+ }
34
+ }
35
+
36
+ const node_paths = compact(
37
+ build_data.manifest_data.nodes.map((_, i) => {
38
+ if (used_nodes.has(i)) {
39
+ reindexed.set(i, reindexed.size);
40
+ return join_relative(relative_path, `/nodes/${i}.js`);
41
+ }
42
+ })
43
+ );
44
+
45
+ /** @typedef {{ index: number, path: string }} LookupEntry */
46
+ /** @type {Map<import('types').PageNode, LookupEntry>} */
47
+ const bundled_nodes = new Map();
48
+
49
+ build_data.manifest_data.nodes.forEach((node, i) => {
50
+ bundled_nodes.set(node, {
51
+ path: join_relative(relative_path, `/nodes/${i}.js`),
52
+ index: i
53
+ });
54
+ });
55
+
56
+ /** @type {(path: string) => string} */
57
+ const loader = (path) => `() => import('${path}')`;
58
+
59
+ const assets = build_data.manifest_data.assets.map((asset) => asset.file);
60
+ if (build_data.service_worker) {
61
+ assets.push(build_data.service_worker);
62
+ }
63
+
64
+ const matchers = new Set();
65
+
66
+ /** @param {Array<number | undefined>} indexes */
67
+ function get_nodes(indexes) {
68
+ let string = indexes.map((n) => reindexed.get(n) ?? '').join(',');
69
+
70
+ if (indexes.at(-1) === undefined) {
71
+ // since JavaScript ignores trailing commas, we need to insert a dummy
72
+ // comma so that the array has the correct length if the last item
73
+ // is undefined
74
+ string += ',';
75
+ }
76
+
77
+ return `[${string}]`;
78
+ }
79
+
80
+ // prettier-ignore
81
+ // String representation of
82
+ /** @type {import('types').SSRManifest} */
83
+ return `{
84
+ appDir: ${s(build_data.app_dir)},
85
+ appPath: ${s(build_data.app_path)},
86
+ assets: new Set(${s(assets)}),
87
+ mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
88
+ _: {
89
+ entry: ${s(build_data.client.entry)},
90
+ nodes: [
91
+ ${(node_paths).map(loader).join(',\n\t\t\t\t')}
92
+ ],
93
+ routes: [
94
+ ${routes.map(route => {
95
+ route.params.forEach(param => {
96
+ if (param.matcher) matchers.add(param.matcher);
97
+ });
98
+
99
+ if (!route.page && !route.endpoint) return;
100
+
101
+ return `{
102
+ id: ${s(route.id)},
103
+ pattern: ${route.pattern},
104
+ params: ${s(route.params)},
105
+ page: ${route.page ? `{ layouts: ${get_nodes(route.page.layouts)}, errors: ${get_nodes(route.page.errors)}, leaf: ${reindexed.get(route.page.leaf)} }` : 'null'},
106
+ endpoint: ${route.endpoint ? loader(join_relative(relative_path, resolve_symlinks(build_data.server.vite_manifest, route.endpoint.file).chunk.file)) : 'null'}
107
+ }`;
108
+ }).filter(Boolean).join(',\n\t\t\t\t')}
109
+ ],
110
+ matchers: async () => {
111
+ ${Array.from(matchers).map(type => `const { match: ${type} } = await import ('${(join_relative(relative_path, `/entries/matchers/${type}.js`))}')`).join('\n\t\t\t\t')}
112
+ return { ${Array.from(matchers).join(', ')} };
113
+ }
114
+ }
115
+ }`.replace(/^\t/gm, '');
116
+ }
@@ -0,0 +1,207 @@
1
+ import { decode } from './entities.js';
2
+
3
+ const DOCTYPE = 'DOCTYPE';
4
+ const CDATA_OPEN = '[CDATA[';
5
+ const CDATA_CLOSE = ']]>';
6
+ const COMMENT_OPEN = '--';
7
+ const COMMENT_CLOSE = '-->';
8
+
9
+ const TAG_OPEN = /[a-zA-Z]/;
10
+ const TAG_CHAR = /[a-zA-Z0-9]/;
11
+ const ATTRIBUTE_NAME = /[^\t\n\f />"'=]/;
12
+
13
+ const WHITESPACE = /[\s\n\r]/;
14
+
15
+ /** @param {string} html */
16
+ export function crawl(html) {
17
+ /** @type {string[]} */
18
+ const ids = [];
19
+
20
+ /** @type {string[]} */
21
+ const hrefs = [];
22
+
23
+ let i = 0;
24
+ main: while (i < html.length) {
25
+ const char = html[i];
26
+
27
+ if (char === '<') {
28
+ if (html[i + 1] === '!') {
29
+ i += 2;
30
+
31
+ if (html.slice(i, i + DOCTYPE.length).toUpperCase() === DOCTYPE) {
32
+ i += DOCTYPE.length;
33
+ while (i < html.length) {
34
+ if (html[i++] === '>') {
35
+ continue main;
36
+ }
37
+ }
38
+ }
39
+
40
+ // skip cdata
41
+ if (html.slice(i, i + CDATA_OPEN.length) === CDATA_OPEN) {
42
+ i += CDATA_OPEN.length;
43
+ while (i < html.length) {
44
+ if (html.slice(i, i + CDATA_CLOSE.length) === CDATA_CLOSE) {
45
+ i += CDATA_CLOSE.length;
46
+ continue main;
47
+ }
48
+
49
+ i += 1;
50
+ }
51
+ }
52
+
53
+ // skip comments
54
+ if (html.slice(i, i + COMMENT_OPEN.length) === COMMENT_OPEN) {
55
+ i += COMMENT_OPEN.length;
56
+ while (i < html.length) {
57
+ if (html.slice(i, i + COMMENT_CLOSE.length) === COMMENT_CLOSE) {
58
+ i += COMMENT_CLOSE.length;
59
+ continue main;
60
+ }
61
+
62
+ i += 1;
63
+ }
64
+ }
65
+ }
66
+
67
+ // parse opening tags
68
+ const start = ++i;
69
+ if (TAG_OPEN.test(html[start])) {
70
+ while (i < html.length) {
71
+ if (!TAG_CHAR.test(html[i])) {
72
+ break;
73
+ }
74
+
75
+ i += 1;
76
+ }
77
+
78
+ const tag = html.slice(start, i).toUpperCase();
79
+
80
+ if (tag === 'SCRIPT' || tag === 'STYLE') {
81
+ while (i < html.length) {
82
+ if (
83
+ html[i] === '<' &&
84
+ html[i + 1] === '/' &&
85
+ html.slice(i + 2, i + 2 + tag.length).toUpperCase() === tag
86
+ ) {
87
+ continue main;
88
+ }
89
+
90
+ i += 1;
91
+ }
92
+ }
93
+
94
+ let href = '';
95
+ let rel = '';
96
+
97
+ while (i < html.length) {
98
+ const start = i;
99
+
100
+ const char = html[start];
101
+ if (char === '>') break;
102
+
103
+ if (ATTRIBUTE_NAME.test(char)) {
104
+ i += 1;
105
+
106
+ while (i < html.length) {
107
+ if (!ATTRIBUTE_NAME.test(html[i])) {
108
+ break;
109
+ }
110
+
111
+ i += 1;
112
+ }
113
+
114
+ const name = html.slice(start, i).toLowerCase();
115
+
116
+ while (WHITESPACE.test(html[i])) i += 1;
117
+
118
+ if (html[i] === '=') {
119
+ i += 1;
120
+ while (WHITESPACE.test(html[i])) i += 1;
121
+
122
+ let value;
123
+
124
+ if (html[i] === "'" || html[i] === '"') {
125
+ const quote = html[i++];
126
+
127
+ const start = i;
128
+ let escaped = false;
129
+
130
+ while (i < html.length) {
131
+ if (escaped) {
132
+ escaped = false;
133
+ } else {
134
+ const char = html[i];
135
+
136
+ if (html[i] === quote) {
137
+ break;
138
+ }
139
+
140
+ if (char === '\\') {
141
+ escaped = true;
142
+ }
143
+ }
144
+
145
+ i += 1;
146
+ }
147
+
148
+ value = html.slice(start, i);
149
+ } else {
150
+ const start = i;
151
+ while (html[i] !== '>' && !WHITESPACE.test(html[i])) i += 1;
152
+ value = html.slice(start, i);
153
+
154
+ i -= 1;
155
+ }
156
+
157
+ value = decode(value);
158
+
159
+ if (name === 'href') {
160
+ href = value;
161
+ } else if (name === 'id') {
162
+ ids.push(value);
163
+ } else if (name === 'name') {
164
+ if (tag === 'A') ids.push(value);
165
+ } else if (name === 'rel') {
166
+ rel = value;
167
+ } else if (name === 'src') {
168
+ hrefs.push(value);
169
+ } else if (name === 'srcset') {
170
+ const candidates = [];
171
+ let insideURL = true;
172
+ value = value.trim();
173
+ for (let i = 0; i < value.length; i++) {
174
+ if (value[i] === ',' && (!insideURL || (insideURL && value[i + 1] === ' '))) {
175
+ candidates.push(value.slice(0, i));
176
+ value = value.substring(i + 1).trim();
177
+ i = 0;
178
+ insideURL = true;
179
+ } else if (value[i] === ' ') {
180
+ insideURL = false;
181
+ }
182
+ }
183
+ candidates.push(value);
184
+ for (const candidate of candidates) {
185
+ const src = candidate.split(WHITESPACE)[0];
186
+ hrefs.push(src);
187
+ }
188
+ }
189
+ } else {
190
+ i -= 1;
191
+ }
192
+ }
193
+
194
+ i += 1;
195
+ }
196
+
197
+ if (href && !/\bexternal\b/i.test(rel)) {
198
+ hrefs.push(href);
199
+ }
200
+ }
201
+ }
202
+
203
+ i += 1;
204
+ }
205
+
206
+ return { ids, hrefs };
207
+ }