@sveltejs/kit 1.0.0-next.5 → 1.0.0-next.500

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 (138) hide show
  1. package/README.md +12 -9
  2. package/package.json +94 -52
  3. package/postinstall.js +38 -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 +7 -0
  11. package/src/core/adapt/builder.js +206 -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 +504 -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 +93 -0
  19. package/src/core/prerender/crawl.js +198 -0
  20. package/src/core/prerender/entities.js +2252 -0
  21. package/src/core/prerender/prerender.js +431 -0
  22. package/src/core/prerender/queue.js +80 -0
  23. package/src/core/sync/create_manifest_data/index.js +488 -0
  24. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  25. package/src/core/sync/sync.js +70 -0
  26. package/src/core/sync/utils.js +33 -0
  27. package/src/core/sync/write_ambient.js +53 -0
  28. package/src/core/sync/write_client_manifest.js +106 -0
  29. package/src/core/sync/write_matchers.js +25 -0
  30. package/src/core/sync/write_root.js +91 -0
  31. package/src/core/sync/write_tsconfig.js +195 -0
  32. package/src/core/sync/write_types/index.js +678 -0
  33. package/src/core/utils.js +70 -0
  34. package/src/exports/hooks/index.js +1 -0
  35. package/src/exports/hooks/sequence.js +44 -0
  36. package/src/exports/index.js +45 -0
  37. package/src/exports/node/index.js +173 -0
  38. package/src/exports/node/polyfills.js +41 -0
  39. package/src/exports/vite/build/build_server.js +378 -0
  40. package/src/exports/vite/build/build_service_worker.js +90 -0
  41. package/src/exports/vite/build/utils.js +180 -0
  42. package/src/exports/vite/dev/index.js +577 -0
  43. package/src/exports/vite/graph_analysis/index.js +277 -0
  44. package/src/exports/vite/graph_analysis/types.d.ts +5 -0
  45. package/src/exports/vite/graph_analysis/utils.js +30 -0
  46. package/src/exports/vite/index.js +598 -0
  47. package/src/exports/vite/preview/index.js +189 -0
  48. package/src/exports/vite/types.d.ts +3 -0
  49. package/src/exports/vite/utils.js +157 -0
  50. package/src/runtime/app/env.js +1 -0
  51. package/src/runtime/app/environment.js +11 -0
  52. package/src/runtime/app/forms.js +114 -0
  53. package/src/runtime/app/navigation.js +23 -0
  54. package/src/runtime/app/paths.js +1 -0
  55. package/src/runtime/app/stores.js +102 -0
  56. package/src/runtime/client/ambient.d.ts +26 -0
  57. package/src/runtime/client/client.js +1583 -0
  58. package/src/runtime/client/fetcher.js +107 -0
  59. package/src/runtime/client/parse.js +60 -0
  60. package/src/runtime/client/singletons.js +21 -0
  61. package/src/runtime/client/start.js +37 -0
  62. package/src/runtime/client/types.d.ts +84 -0
  63. package/src/runtime/client/utils.js +159 -0
  64. package/src/runtime/components/error.svelte +16 -0
  65. package/{assets → src/runtime}/components/layout.svelte +0 -0
  66. package/src/runtime/control.js +98 -0
  67. package/src/runtime/env/dynamic/private.js +1 -0
  68. package/src/runtime/env/dynamic/public.js +1 -0
  69. package/src/runtime/env-private.js +6 -0
  70. package/src/runtime/env-public.js +6 -0
  71. package/src/runtime/env.js +6 -0
  72. package/src/runtime/hash.js +16 -0
  73. package/src/runtime/paths.js +11 -0
  74. package/src/runtime/server/cookie.js +127 -0
  75. package/src/runtime/server/data/index.js +136 -0
  76. package/src/runtime/server/endpoint.js +90 -0
  77. package/src/runtime/server/index.js +340 -0
  78. package/src/runtime/server/page/actions.js +243 -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/fetch.js +301 -0
  82. package/src/runtime/server/page/index.js +304 -0
  83. package/src/runtime/server/page/load_data.js +124 -0
  84. package/src/runtime/server/page/render.js +342 -0
  85. package/src/runtime/server/page/respond_with_error.js +104 -0
  86. package/src/runtime/server/page/serialize_data.js +87 -0
  87. package/src/runtime/server/page/types.d.ts +41 -0
  88. package/src/runtime/server/utils.js +179 -0
  89. package/src/utils/array.js +9 -0
  90. package/src/utils/error.js +22 -0
  91. package/src/utils/escape.js +46 -0
  92. package/src/utils/filesystem.js +137 -0
  93. package/src/utils/functions.js +16 -0
  94. package/src/utils/http.js +55 -0
  95. package/src/utils/misc.js +1 -0
  96. package/src/utils/routing.js +117 -0
  97. package/src/utils/unit_test.js +11 -0
  98. package/src/utils/url.js +142 -0
  99. package/svelte-kit.js +2 -0
  100. package/types/ambient.d.ts +426 -0
  101. package/types/index.d.ts +444 -0
  102. package/types/internal.d.ts +378 -0
  103. package/types/private.d.ts +224 -0
  104. package/CHANGELOG.md +0 -177
  105. package/assets/components/error.svelte +0 -13
  106. package/assets/runtime/app/navigation.js +0 -47
  107. package/assets/runtime/app/navigation.js.map +0 -1
  108. package/assets/runtime/app/stores.js +0 -78
  109. package/assets/runtime/app/stores.js.map +0 -1
  110. package/assets/runtime/internal/singletons.js +0 -10
  111. package/assets/runtime/internal/singletons.js.map +0 -1
  112. package/assets/runtime/internal/start.js +0 -517
  113. package/assets/runtime/internal/start.js.map +0 -1
  114. package/dist/api.js +0 -40
  115. package/dist/api.js.map +0 -1
  116. package/dist/cli.js +0 -128
  117. package/dist/cli.js.map +0 -1
  118. package/dist/create_app.js +0 -550
  119. package/dist/create_app.js.map +0 -1
  120. package/dist/index.js +0 -8331
  121. package/dist/index.js.map +0 -1
  122. package/dist/index2.js +0 -509
  123. package/dist/index2.js.map +0 -1
  124. package/dist/index3.js +0 -63
  125. package/dist/index3.js.map +0 -1
  126. package/dist/index4.js +0 -466
  127. package/dist/index4.js.map +0 -1
  128. package/dist/index5.js +0 -276
  129. package/dist/index5.js.map +0 -1
  130. package/dist/package.js +0 -235
  131. package/dist/package.js.map +0 -1
  132. package/dist/renderer.js +0 -2398
  133. package/dist/renderer.js.map +0 -1
  134. package/dist/standard.js +0 -101
  135. package/dist/standard.js.map +0 -1
  136. package/dist/utils.js +0 -58
  137. package/dist/utils.js.map +0 -1
  138. package/svelte-kit +0 -3
@@ -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,93 @@
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
+
5
+ /**
6
+ * Generates the data used to write the server-side manifest.js file. This data is used in the Vite
7
+ * build process, to power routing, etc.
8
+ * @param {{
9
+ * build_data: import('types').BuildData;
10
+ * relative_path: string;
11
+ * routes: import('types').RouteData[];
12
+ * format?: 'esm' | 'cjs'
13
+ * }} opts
14
+ */
15
+ export function generate_manifest({ build_data, relative_path, routes, format = 'esm' }) {
16
+ /** @typedef {{ index: number, path: string }} LookupEntry */
17
+ /** @type {Map<import('types').PageNode, LookupEntry>} */
18
+ const bundled_nodes = new Map();
19
+
20
+ build_data.manifest_data.nodes.forEach((node, i) => {
21
+ bundled_nodes.set(node, {
22
+ path: `${relative_path}/nodes/${i}.js`,
23
+ index: i
24
+ });
25
+ });
26
+
27
+ /** @type {(path: string) => string} */
28
+ const load =
29
+ format === 'esm'
30
+ ? (path) => `import('${path}')`
31
+ : (path) => `Promise.resolve().then(() => require('${path}'))`;
32
+
33
+ /** @type {(path: string) => string} */
34
+ const loader = (path) => `() => ${load(path)}`;
35
+
36
+ const assets = build_data.manifest_data.assets.map((asset) => asset.file);
37
+ if (build_data.service_worker) {
38
+ assets.push(build_data.service_worker);
39
+ }
40
+
41
+ const matchers = new Set();
42
+
43
+ // prettier-ignore
44
+ // String representation of
45
+ /** @type {import('types').SSRManifest} */
46
+ return `{
47
+ appDir: ${s(build_data.app_dir)},
48
+ assets: new Set(${s(assets)}),
49
+ mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
50
+ _: {
51
+ entry: ${s(build_data.client.entry)},
52
+ nodes: [
53
+ ${Array.from(bundled_nodes.values()).map(node => loader(node.path)).join(',\n\t\t\t\t')}
54
+ ],
55
+ routes: [
56
+ ${routes.map(route => {
57
+ route.types.forEach(type => {
58
+ if (type) matchers.add(type);
59
+ });
60
+
61
+ if (!route.page && !route.endpoint) return;
62
+
63
+ return `{
64
+ id: ${s(route.id)},
65
+ pattern: ${route.pattern},
66
+ names: ${s(route.names)},
67
+ types: ${s(route.types)},
68
+ page: ${route.page ? `{ layouts: ${get_nodes(route.page.layouts)}, errors: ${get_nodes(route.page.errors)}, leaf: ${route.page.leaf} }` : 'null'},
69
+ endpoint: ${route.endpoint ? loader(`${relative_path}/${resolve_symlinks(build_data.server.vite_manifest, route.endpoint.file).chunk.file}`) : 'null'}
70
+ }`;
71
+ }).filter(Boolean).join(',\n\t\t\t\t')}
72
+ ],
73
+ matchers: async () => {
74
+ ${Array.from(matchers).map(type => `const { match: ${type} } = await ${load(`${relative_path}/entries/matchers/${type}.js`)}`).join('\n\t\t\t\t')}
75
+ return { ${Array.from(matchers).join(', ')} };
76
+ }
77
+ }
78
+ }`.replace(/^\t/gm, '');
79
+ }
80
+
81
+ /** @param {Array<number | undefined>} indexes */
82
+ function get_nodes(indexes) {
83
+ let string = indexes.map((n) => n ?? '').join(',');
84
+
85
+ if (indexes.at(-1) === undefined) {
86
+ // since JavaScript ignores trailing commas, we need to insert a dummy
87
+ // comma so that the array has the correct length if the last item
88
+ // is undefined
89
+ string += ',';
90
+ }
91
+
92
+ return `[${string}]`;
93
+ }
@@ -0,0 +1,198 @@
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 hrefs = [];
19
+
20
+ let i = 0;
21
+ main: while (i < html.length) {
22
+ const char = html[i];
23
+
24
+ if (char === '<') {
25
+ if (html[i + 1] === '!') {
26
+ i += 2;
27
+
28
+ if (html.slice(i, i + DOCTYPE.length).toUpperCase() === DOCTYPE) {
29
+ i += DOCTYPE.length;
30
+ while (i < html.length) {
31
+ if (html[i++] === '>') {
32
+ continue main;
33
+ }
34
+ }
35
+ }
36
+
37
+ // skip cdata
38
+ if (html.slice(i, i + CDATA_OPEN.length) === CDATA_OPEN) {
39
+ i += CDATA_OPEN.length;
40
+ while (i < html.length) {
41
+ if (html.slice(i, i + CDATA_CLOSE.length) === CDATA_CLOSE) {
42
+ i += CDATA_CLOSE.length;
43
+ continue main;
44
+ }
45
+
46
+ i += 1;
47
+ }
48
+ }
49
+
50
+ // skip comments
51
+ if (html.slice(i, i + COMMENT_OPEN.length) === COMMENT_OPEN) {
52
+ i += COMMENT_OPEN.length;
53
+ while (i < html.length) {
54
+ if (html.slice(i, i + COMMENT_CLOSE.length) === COMMENT_CLOSE) {
55
+ i += COMMENT_CLOSE.length;
56
+ continue main;
57
+ }
58
+
59
+ i += 1;
60
+ }
61
+ }
62
+ }
63
+
64
+ // parse opening tags
65
+ const start = ++i;
66
+ if (TAG_OPEN.test(html[start])) {
67
+ while (i < html.length) {
68
+ if (!TAG_CHAR.test(html[i])) {
69
+ break;
70
+ }
71
+
72
+ i += 1;
73
+ }
74
+
75
+ const tag = html.slice(start, i).toUpperCase();
76
+
77
+ if (tag === 'SCRIPT' || tag === 'STYLE') {
78
+ while (i < html.length) {
79
+ if (
80
+ html[i] === '<' &&
81
+ html[i + 1] === '/' &&
82
+ html.slice(i + 2, i + 2 + tag.length).toUpperCase() === tag
83
+ ) {
84
+ continue main;
85
+ }
86
+
87
+ i += 1;
88
+ }
89
+ }
90
+
91
+ let href = '';
92
+ let rel = '';
93
+
94
+ while (i < html.length) {
95
+ const start = i;
96
+
97
+ const char = html[start];
98
+ if (char === '>') break;
99
+
100
+ if (ATTRIBUTE_NAME.test(char)) {
101
+ i += 1;
102
+
103
+ while (i < html.length) {
104
+ if (!ATTRIBUTE_NAME.test(html[i])) {
105
+ break;
106
+ }
107
+
108
+ i += 1;
109
+ }
110
+
111
+ const name = html.slice(start, i).toLowerCase();
112
+
113
+ while (WHITESPACE.test(html[i])) i += 1;
114
+
115
+ if (html[i] === '=') {
116
+ i += 1;
117
+ while (WHITESPACE.test(html[i])) i += 1;
118
+
119
+ let value;
120
+
121
+ if (html[i] === "'" || html[i] === '"') {
122
+ const quote = html[i++];
123
+
124
+ const start = i;
125
+ let escaped = false;
126
+
127
+ while (i < html.length) {
128
+ if (!escaped) {
129
+ const char = html[i];
130
+
131
+ if (html[i] === quote) {
132
+ break;
133
+ }
134
+
135
+ if (char === '\\') {
136
+ escaped = true;
137
+ }
138
+ }
139
+
140
+ i += 1;
141
+ }
142
+
143
+ value = html.slice(start, i);
144
+ } else {
145
+ const start = i;
146
+ while (html[i] !== '>' && !WHITESPACE.test(html[i])) i += 1;
147
+ value = html.slice(start, i);
148
+
149
+ i -= 1;
150
+ }
151
+
152
+ value = decode(value);
153
+
154
+ if (name === 'href') {
155
+ href = value;
156
+ } else if (name === 'rel') {
157
+ rel = value;
158
+ } else if (name === 'src') {
159
+ hrefs.push(value);
160
+ } else if (name === 'srcset') {
161
+ const candidates = [];
162
+ let insideURL = true;
163
+ value = value.trim();
164
+ for (let i = 0; i < value.length; i++) {
165
+ if (value[i] === ',' && (!insideURL || (insideURL && value[i + 1] === ' '))) {
166
+ candidates.push(value.slice(0, i));
167
+ value = value.substring(i + 1).trim();
168
+ i = 0;
169
+ insideURL = true;
170
+ } else if (value[i] === ' ') {
171
+ insideURL = false;
172
+ }
173
+ }
174
+ candidates.push(value);
175
+ for (const candidate of candidates) {
176
+ const src = candidate.split(WHITESPACE)[0];
177
+ hrefs.push(src);
178
+ }
179
+ }
180
+ } else {
181
+ i -= 1;
182
+ }
183
+ }
184
+
185
+ i += 1;
186
+ }
187
+
188
+ if (href && !/\bexternal\b/i.test(rel)) {
189
+ hrefs.push(href);
190
+ }
191
+ }
192
+ }
193
+
194
+ i += 1;
195
+ }
196
+
197
+ return hrefs;
198
+ }