@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,121 @@
1
+ import { GENERATED_COMMENT } from '../constants.js';
2
+ import { runtime_base } from './utils.js';
3
+
4
+ /**
5
+ * @param {string} id
6
+ * @param {Record<string, string>} env
7
+ * @returns {string}
8
+ */
9
+ export function create_static_module(id, env) {
10
+ /** @type {string[]} */
11
+ const declarations = [];
12
+
13
+ for (const key in env) {
14
+ if (!valid_identifier.test(key) || reserved.has(key)) {
15
+ continue;
16
+ }
17
+
18
+ const comment = `/** @type {import('${id}').${key}} */`;
19
+ const declaration = `export const ${key} = ${JSON.stringify(env[key])};`;
20
+
21
+ declarations.push(`${comment}\n${declaration}`);
22
+ }
23
+
24
+ return GENERATED_COMMENT + declarations.join('\n\n');
25
+ }
26
+
27
+ /**
28
+ * @param {'public' | 'private'} type
29
+ * @param {Record<string, string> | undefined} dev_values If in a development mode, values to pre-populate the module with.
30
+ */
31
+ export function create_dynamic_module(type, dev_values) {
32
+ if (dev_values) {
33
+ const objectKeys = Object.entries(dev_values).map(
34
+ ([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`
35
+ );
36
+ return `const env = {\n${objectKeys.join(',\n')}\n}\n\nexport { env }`;
37
+ }
38
+ return `export { env } from '${runtime_base}/env-${type}.js';`;
39
+ }
40
+
41
+ /**
42
+ * @param {string} id
43
+ * @param {Record<string, string>} env
44
+ * @returns {string}
45
+ */
46
+ export function create_static_types(id, env) {
47
+ const declarations = Object.keys(env)
48
+ .filter((k) => valid_identifier.test(k))
49
+ .map((k) => `\texport const ${k}: string;`)
50
+ .join('\n');
51
+
52
+ return `declare module '${id}' {\n${declarations}\n}`;
53
+ }
54
+
55
+ /**
56
+ * @param {string} id
57
+ * @param {Record<string, string>} env
58
+ * @returns {string}
59
+ */
60
+ export function create_dynamic_types(id, env) {
61
+ const properties = Object.keys(env)
62
+ .filter((k) => valid_identifier.test(k))
63
+ .map((k) => `\t\t${k}: string;`);
64
+
65
+ properties.push(`\t\t[key: string]: string | undefined;`);
66
+
67
+ return `declare module '${id}' {\n\texport const env: {\n${properties.join('\n')}\n\t}\n}`;
68
+ }
69
+
70
+ export const reserved = new Set([
71
+ 'do',
72
+ 'if',
73
+ 'in',
74
+ 'for',
75
+ 'let',
76
+ 'new',
77
+ 'try',
78
+ 'var',
79
+ 'case',
80
+ 'else',
81
+ 'enum',
82
+ 'eval',
83
+ 'null',
84
+ 'this',
85
+ 'true',
86
+ 'void',
87
+ 'with',
88
+ 'await',
89
+ 'break',
90
+ 'catch',
91
+ 'class',
92
+ 'const',
93
+ 'false',
94
+ 'super',
95
+ 'throw',
96
+ 'while',
97
+ 'yield',
98
+ 'delete',
99
+ 'export',
100
+ 'import',
101
+ 'public',
102
+ 'return',
103
+ 'static',
104
+ 'switch',
105
+ 'typeof',
106
+ 'default',
107
+ 'extends',
108
+ 'finally',
109
+ 'package',
110
+ 'private',
111
+ 'continue',
112
+ 'debugger',
113
+ 'function',
114
+ 'arguments',
115
+ 'interface',
116
+ 'protected',
117
+ 'implements',
118
+ 'instanceof'
119
+ ]);
120
+
121
+ export const valid_identifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
@@ -0,0 +1,125 @@
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
+ * format?: 'esm' | 'cjs'
15
+ * }} opts
16
+ */
17
+ export function generate_manifest({ build_data, relative_path, routes, format = 'esm' }) {
18
+ /**
19
+ * @type {Map<any, number>} The new index of each node in the filtered nodes array
20
+ */
21
+ const reindexed = new Map();
22
+ /**
23
+ * All nodes actually used in the routes definition (prerendered routes are omitted).
24
+ * Root layout/error is always included as they are needed for 404 and root errors.
25
+ * @type {Set<any>}
26
+ */
27
+ const used_nodes = new Set([0, 1]);
28
+
29
+ for (const route of routes) {
30
+ if (route.page) {
31
+ for (const i of route.page.layouts) used_nodes.add(i);
32
+ for (const i of route.page.errors) used_nodes.add(i);
33
+ used_nodes.add(route.page.leaf);
34
+ }
35
+ }
36
+
37
+ const node_paths = compact(
38
+ build_data.manifest_data.nodes.map((_, i) => {
39
+ if (used_nodes.has(i)) {
40
+ reindexed.set(i, reindexed.size);
41
+ return join_relative(relative_path, `/nodes/${i}.js`);
42
+ }
43
+ })
44
+ );
45
+
46
+ /** @typedef {{ index: number, path: string }} LookupEntry */
47
+ /** @type {Map<import('types').PageNode, LookupEntry>} */
48
+ const bundled_nodes = new Map();
49
+
50
+ build_data.manifest_data.nodes.forEach((node, i) => {
51
+ bundled_nodes.set(node, {
52
+ path: join_relative(relative_path, `/nodes/${i}.js`),
53
+ index: i
54
+ });
55
+ });
56
+
57
+ /** @type {(path: string) => string} */
58
+ const load =
59
+ format === 'esm'
60
+ ? (path) => `import('${path}')`
61
+ : (path) => `Promise.resolve().then(() => require('${path}'))`;
62
+
63
+ /** @type {(path: string) => string} */
64
+ const loader = (path) => `() => ${load(path)}`;
65
+
66
+ const assets = build_data.manifest_data.assets.map((asset) => asset.file);
67
+ if (build_data.service_worker) {
68
+ assets.push(build_data.service_worker);
69
+ }
70
+
71
+ const matchers = new Set();
72
+
73
+ /** @param {Array<number | undefined>} indexes */
74
+ function get_nodes(indexes) {
75
+ let string = indexes.map((n) => reindexed.get(n) ?? '').join(',');
76
+
77
+ if (indexes.at(-1) === undefined) {
78
+ // since JavaScript ignores trailing commas, we need to insert a dummy
79
+ // comma so that the array has the correct length if the last item
80
+ // is undefined
81
+ string += ',';
82
+ }
83
+
84
+ return `[${string}]`;
85
+ }
86
+
87
+ // prettier-ignore
88
+ // String representation of
89
+ /** @type {import('types').SSRManifest} */
90
+ return `{
91
+ appDir: ${s(build_data.app_dir)},
92
+ appPath: ${s(build_data.app_path)},
93
+ assets: new Set(${s(assets)}),
94
+ mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
95
+ _: {
96
+ entry: ${s(build_data.client.entry)},
97
+ nodes: [
98
+ ${(node_paths).map(loader).join(',\n\t\t\t\t')}
99
+ ],
100
+ routes: [
101
+ ${routes.map(route => {
102
+ route.types.forEach(type => {
103
+ if (type) matchers.add(type);
104
+ });
105
+
106
+ if (!route.page && !route.endpoint) return;
107
+
108
+ return `{
109
+ id: ${s(route.id)},
110
+ pattern: ${route.pattern},
111
+ names: ${s(route.names)},
112
+ types: ${s(route.types)},
113
+ optional: ${s(route.optional)},
114
+ page: ${route.page ? `{ layouts: ${get_nodes(route.page.layouts)}, errors: ${get_nodes(route.page.errors)}, leaf: ${reindexed.get(route.page.leaf)} }` : 'null'},
115
+ endpoint: ${route.endpoint ? loader(join_relative(relative_path, resolve_symlinks(build_data.server.vite_manifest, route.endpoint.file).chunk.file)) : 'null'}
116
+ }`;
117
+ }).filter(Boolean).join(',\n\t\t\t\t')}
118
+ ],
119
+ matchers: async () => {
120
+ ${Array.from(matchers).map(type => `const { match: ${type} } = await ${load(join_relative(relative_path, `/entries/matchers/${type}.js`))}`).join('\n\t\t\t\t')}
121
+ return { ${Array.from(matchers).join(', ')} };
122
+ }
123
+ }
124
+ }`.replace(/^\t/gm, '');
125
+ }
@@ -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
+ }