@sveltejs/kit 1.0.0-next.46 → 1.0.0-next.462

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 (115) hide show
  1. package/README.md +12 -9
  2. package/package.json +93 -65
  3. package/scripts/special-types/$env+dynamic+private.md +8 -0
  4. package/scripts/special-types/$env+dynamic+public.md +8 -0
  5. package/scripts/special-types/$env+static+private.md +19 -0
  6. package/scripts/special-types/$env+static+public.md +7 -0
  7. package/scripts/special-types/$lib.md +1 -0
  8. package/src/cli.js +112 -0
  9. package/src/constants.js +7 -0
  10. package/src/core/adapt/builder.js +207 -0
  11. package/src/core/adapt/index.js +31 -0
  12. package/src/core/config/default-error.html +56 -0
  13. package/src/core/config/index.js +105 -0
  14. package/src/core/config/options.js +502 -0
  15. package/src/core/config/types.d.ts +1 -0
  16. package/src/core/env.js +112 -0
  17. package/src/core/generate_manifest/index.js +78 -0
  18. package/src/core/prerender/crawl.js +194 -0
  19. package/src/core/prerender/prerender.js +425 -0
  20. package/src/core/prerender/queue.js +80 -0
  21. package/src/core/sync/create_manifest_data/index.js +452 -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 +53 -0
  26. package/src/core/sync/write_client_manifest.js +94 -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 +595 -0
  31. package/src/core/utils.js +70 -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 +45 -0
  35. package/src/exports/node/index.js +145 -0
  36. package/src/exports/node/polyfills.js +40 -0
  37. package/src/exports/vite/build/build_server.js +352 -0
  38. package/src/exports/vite/build/build_service_worker.js +90 -0
  39. package/src/exports/vite/build/utils.js +160 -0
  40. package/src/exports/vite/dev/index.js +546 -0
  41. package/src/exports/vite/index.js +595 -0
  42. package/src/exports/vite/preview/index.js +186 -0
  43. package/src/exports/vite/types.d.ts +3 -0
  44. package/src/exports/vite/utils.js +345 -0
  45. package/src/runtime/app/env.js +1 -0
  46. package/src/runtime/app/environment.js +11 -0
  47. package/src/runtime/app/navigation.js +23 -0
  48. package/src/runtime/app/paths.js +1 -0
  49. package/src/runtime/app/stores.js +102 -0
  50. package/src/runtime/client/ambient.d.ts +24 -0
  51. package/src/runtime/client/client.js +1400 -0
  52. package/src/runtime/client/fetcher.js +60 -0
  53. package/src/runtime/client/parse.js +60 -0
  54. package/src/runtime/client/singletons.js +21 -0
  55. package/src/runtime/client/start.js +45 -0
  56. package/src/runtime/client/types.d.ts +90 -0
  57. package/src/runtime/client/utils.js +140 -0
  58. package/src/runtime/components/error.svelte +16 -0
  59. package/{assets → src/runtime}/components/layout.svelte +0 -0
  60. package/src/runtime/control.js +33 -0
  61. package/src/runtime/env/dynamic/private.js +1 -0
  62. package/src/runtime/env/dynamic/public.js +1 -0
  63. package/src/runtime/env-private.js +6 -0
  64. package/src/runtime/env-public.js +6 -0
  65. package/src/runtime/env.js +6 -0
  66. package/src/runtime/hash.js +16 -0
  67. package/src/runtime/paths.js +11 -0
  68. package/src/runtime/server/data/index.js +146 -0
  69. package/src/runtime/server/endpoint.js +63 -0
  70. package/src/runtime/server/index.js +354 -0
  71. package/src/runtime/server/page/cookie.js +25 -0
  72. package/src/runtime/server/page/crypto.js +239 -0
  73. package/src/runtime/server/page/csp.js +249 -0
  74. package/src/runtime/server/page/fetch.js +269 -0
  75. package/src/runtime/server/page/index.js +404 -0
  76. package/src/runtime/server/page/load_data.js +124 -0
  77. package/src/runtime/server/page/render.js +358 -0
  78. package/src/runtime/server/page/respond_with_error.js +92 -0
  79. package/src/runtime/server/page/serialize_data.js +58 -0
  80. package/src/runtime/server/page/types.d.ts +44 -0
  81. package/src/runtime/server/utils.js +209 -0
  82. package/src/utils/array.js +9 -0
  83. package/src/utils/error.js +22 -0
  84. package/src/utils/escape.js +46 -0
  85. package/src/utils/filesystem.js +108 -0
  86. package/src/utils/functions.js +16 -0
  87. package/src/utils/http.js +55 -0
  88. package/src/utils/misc.js +1 -0
  89. package/src/utils/routing.js +137 -0
  90. package/src/utils/url.js +142 -0
  91. package/svelte-kit.js +1 -1
  92. package/types/ambient.d.ts +347 -0
  93. package/types/index.d.ts +346 -0
  94. package/types/internal.d.ts +386 -0
  95. package/types/private.d.ts +213 -0
  96. package/CHANGELOG.md +0 -456
  97. package/assets/components/error.svelte +0 -13
  98. package/assets/runtime/app/env.js +0 -5
  99. package/assets/runtime/app/navigation.js +0 -44
  100. package/assets/runtime/app/paths.js +0 -1
  101. package/assets/runtime/app/stores.js +0 -93
  102. package/assets/runtime/chunks/utils.js +0 -22
  103. package/assets/runtime/internal/singletons.js +0 -23
  104. package/assets/runtime/internal/start.js +0 -771
  105. package/assets/runtime/paths.js +0 -12
  106. package/dist/chunks/index.js +0 -3522
  107. package/dist/chunks/index2.js +0 -587
  108. package/dist/chunks/index3.js +0 -246
  109. package/dist/chunks/index4.js +0 -539
  110. package/dist/chunks/index5.js +0 -763
  111. package/dist/chunks/index6.js +0 -322
  112. package/dist/chunks/standard.js +0 -99
  113. package/dist/chunks/utils.js +0 -83
  114. package/dist/cli.js +0 -546
  115. package/dist/ssr.js +0 -2581
@@ -0,0 +1,112 @@
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
+ /** @param {'public' | 'private'} type */
28
+ export function create_dynamic_module(type) {
29
+ return `export { env } from '${runtime_base}/env-${type}.js';`;
30
+ }
31
+
32
+ /**
33
+ * @param {string} id
34
+ * @param {Record<string, string>} env
35
+ * @returns {string}
36
+ */
37
+ export function create_static_types(id, env) {
38
+ const declarations = Object.keys(env)
39
+ .filter((k) => valid_identifier.test(k))
40
+ .map((k) => `\texport const ${k}: string;`)
41
+ .join('\n');
42
+
43
+ return `declare module '${id}' {\n${declarations}\n}`;
44
+ }
45
+
46
+ /**
47
+ * @param {string} id
48
+ * @param {Record<string, string>} env
49
+ * @returns {string}
50
+ */
51
+ export function create_dynamic_types(id, env) {
52
+ const properties = Object.keys(env)
53
+ .filter((k) => valid_identifier.test(k))
54
+ .map((k) => `\t\t${k}: string;`);
55
+
56
+ properties.push(`\t\t[key: string]: string | undefined;`);
57
+
58
+ return `declare module '${id}' {\n\texport const env: {\n${properties.join('\n')}\n\t}\n}`;
59
+ }
60
+
61
+ export const reserved = new Set([
62
+ 'do',
63
+ 'if',
64
+ 'in',
65
+ 'for',
66
+ 'let',
67
+ 'new',
68
+ 'try',
69
+ 'var',
70
+ 'case',
71
+ 'else',
72
+ 'enum',
73
+ 'eval',
74
+ 'null',
75
+ 'this',
76
+ 'true',
77
+ 'void',
78
+ 'with',
79
+ 'await',
80
+ 'break',
81
+ 'catch',
82
+ 'class',
83
+ 'const',
84
+ 'false',
85
+ 'super',
86
+ 'throw',
87
+ 'while',
88
+ 'yield',
89
+ 'delete',
90
+ 'export',
91
+ 'import',
92
+ 'public',
93
+ 'return',
94
+ 'static',
95
+ 'switch',
96
+ 'typeof',
97
+ 'default',
98
+ 'extends',
99
+ 'finally',
100
+ 'package',
101
+ 'private',
102
+ 'continue',
103
+ 'debugger',
104
+ 'function',
105
+ 'arguments',
106
+ 'interface',
107
+ 'protected',
108
+ 'implements',
109
+ 'instanceof'
110
+ ]);
111
+
112
+ export const valid_identifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
@@ -0,0 +1,78 @@
1
+ import { s } from '../../utils/misc.js';
2
+ import { get_mime_lookup } from '../utils.js';
3
+
4
+ /**
5
+ * Generates the data used to write the server-side manifest.js file. This data is used in the Vite
6
+ * build process, to power routing, etc.
7
+ * @param {{
8
+ * build_data: import('types').BuildData;
9
+ * relative_path: string;
10
+ * routes: import('types').RouteData[];
11
+ * format?: 'esm' | 'cjs'
12
+ * }} opts
13
+ */
14
+ export function generate_manifest({ build_data, relative_path, routes, format = 'esm' }) {
15
+ /** @typedef {{ index: number, path: string }} LookupEntry */
16
+ /** @type {Map<import('types').PageNode, LookupEntry>} */
17
+ const bundled_nodes = new Map();
18
+
19
+ build_data.manifest_data.nodes.forEach((node, i) => {
20
+ bundled_nodes.set(node, {
21
+ path: `${relative_path}/nodes/${i}.js`,
22
+ index: i
23
+ });
24
+ });
25
+
26
+ /** @type {(path: string) => string} */
27
+ const load =
28
+ format === 'esm'
29
+ ? (path) => `import('${path}')`
30
+ : (path) => `Promise.resolve().then(() => require('${path}'))`;
31
+
32
+ /** @type {(path: string) => string} */
33
+ const loader = (path) => `() => ${load(path)}`;
34
+
35
+ const assets = build_data.manifest_data.assets.map((asset) => asset.file);
36
+ if (build_data.service_worker) {
37
+ assets.push(build_data.service_worker);
38
+ }
39
+
40
+ const matchers = new Set();
41
+
42
+ // prettier-ignore
43
+ // String representation of
44
+ /** @type {import('types').SSRManifest} */
45
+ return `{
46
+ appDir: ${s(build_data.app_dir)},
47
+ assets: new Set(${s(assets)}),
48
+ mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
49
+ _: {
50
+ entry: ${s(build_data.client.entry)},
51
+ nodes: [
52
+ ${Array.from(bundled_nodes.values()).map(node => loader(node.path)).join(',\n\t\t\t\t')}
53
+ ],
54
+ routes: [
55
+ ${routes.map(route => {
56
+ route.types.forEach(type => {
57
+ if (type) matchers.add(type);
58
+ });
59
+
60
+ if (!route.page && !route.endpoint) return;
61
+
62
+ return `{
63
+ id: ${s(route.id)},
64
+ pattern: ${route.pattern},
65
+ names: ${s(route.names)},
66
+ types: ${s(route.types)},
67
+ page: ${s(route.page)},
68
+ endpoint: ${route.endpoint ? loader(`${relative_path}/${build_data.server.vite_manifest[route.endpoint.file].file}`) : 'null'}
69
+ }`;
70
+ }).filter(Boolean).join(',\n\t\t\t\t')}
71
+ ],
72
+ matchers: async () => {
73
+ ${Array.from(matchers).map(type => `const { match: ${type} } = await ${load(`${relative_path}/entries/matchers/${type}.js`)}`).join('\n\t\t\t\t')}
74
+ return { ${Array.from(matchers).join(', ')} };
75
+ }
76
+ }
77
+ }`.replace(/^\t/gm, '');
78
+ }
@@ -0,0 +1,194 @@
1
+ const DOCTYPE = 'DOCTYPE';
2
+ const CDATA_OPEN = '[CDATA[';
3
+ const CDATA_CLOSE = ']]>';
4
+ const COMMENT_OPEN = '--';
5
+ const COMMENT_CLOSE = '-->';
6
+
7
+ const TAG_OPEN = /[a-zA-Z]/;
8
+ const TAG_CHAR = /[a-zA-Z0-9]/;
9
+ const ATTRIBUTE_NAME = /[^\t\n\f />"'=]/;
10
+
11
+ const WHITESPACE = /[\s\n\r]/;
12
+
13
+ /** @param {string} html */
14
+ export function crawl(html) {
15
+ /** @type {string[]} */
16
+ const hrefs = [];
17
+
18
+ let i = 0;
19
+ main: while (i < html.length) {
20
+ const char = html[i];
21
+
22
+ if (char === '<') {
23
+ if (html[i + 1] === '!') {
24
+ i += 2;
25
+
26
+ if (html.slice(i, i + DOCTYPE.length).toUpperCase() === DOCTYPE) {
27
+ i += DOCTYPE.length;
28
+ while (i < html.length) {
29
+ if (html[i++] === '>') {
30
+ continue main;
31
+ }
32
+ }
33
+ }
34
+
35
+ // skip cdata
36
+ if (html.slice(i, i + CDATA_OPEN.length) === CDATA_OPEN) {
37
+ i += CDATA_OPEN.length;
38
+ while (i < html.length) {
39
+ if (html.slice(i, i + CDATA_CLOSE.length) === CDATA_CLOSE) {
40
+ i += CDATA_CLOSE.length;
41
+ continue main;
42
+ }
43
+
44
+ i += 1;
45
+ }
46
+ }
47
+
48
+ // skip comments
49
+ if (html.slice(i, i + COMMENT_OPEN.length) === COMMENT_OPEN) {
50
+ i += COMMENT_OPEN.length;
51
+ while (i < html.length) {
52
+ if (html.slice(i, i + COMMENT_CLOSE.length) === COMMENT_CLOSE) {
53
+ i += COMMENT_CLOSE.length;
54
+ continue main;
55
+ }
56
+
57
+ i += 1;
58
+ }
59
+ }
60
+ }
61
+
62
+ // parse opening tags
63
+ const start = ++i;
64
+ if (TAG_OPEN.test(html[start])) {
65
+ while (i < html.length) {
66
+ if (!TAG_CHAR.test(html[i])) {
67
+ break;
68
+ }
69
+
70
+ i += 1;
71
+ }
72
+
73
+ const tag = html.slice(start, i).toUpperCase();
74
+
75
+ if (tag === 'SCRIPT' || tag === 'STYLE') {
76
+ while (i < html.length) {
77
+ if (
78
+ html[i] === '<' &&
79
+ html[i + 1] === '/' &&
80
+ html.slice(i + 2, i + 2 + tag.length).toUpperCase() === tag
81
+ ) {
82
+ continue main;
83
+ }
84
+
85
+ i += 1;
86
+ }
87
+ }
88
+
89
+ let href = '';
90
+ let rel = '';
91
+
92
+ while (i < html.length) {
93
+ const start = i;
94
+
95
+ const char = html[start];
96
+ if (char === '>') break;
97
+
98
+ if (ATTRIBUTE_NAME.test(char)) {
99
+ i += 1;
100
+
101
+ while (i < html.length) {
102
+ if (!ATTRIBUTE_NAME.test(html[i])) {
103
+ break;
104
+ }
105
+
106
+ i += 1;
107
+ }
108
+
109
+ const name = html.slice(start, i).toLowerCase();
110
+
111
+ while (WHITESPACE.test(html[i])) i += 1;
112
+
113
+ if (html[i] === '=') {
114
+ i += 1;
115
+ while (WHITESPACE.test(html[i])) i += 1;
116
+
117
+ let value;
118
+
119
+ if (html[i] === "'" || html[i] === '"') {
120
+ const quote = html[i++];
121
+
122
+ const start = i;
123
+ let escaped = false;
124
+
125
+ while (i < html.length) {
126
+ if (!escaped) {
127
+ const char = html[i];
128
+
129
+ if (html[i] === quote) {
130
+ break;
131
+ }
132
+
133
+ if (char === '\\') {
134
+ escaped = true;
135
+ }
136
+ }
137
+
138
+ i += 1;
139
+ }
140
+
141
+ value = html.slice(start, i);
142
+ } else {
143
+ const start = i;
144
+ while (html[i] !== '>' && !WHITESPACE.test(html[i])) i += 1;
145
+ value = html.slice(start, i);
146
+
147
+ i -= 1;
148
+ }
149
+
150
+ if (name === 'href') {
151
+ href = value;
152
+ } else if (name === 'rel') {
153
+ rel = value;
154
+ } else if (name === 'src') {
155
+ hrefs.push(value);
156
+ } else if (name === 'srcset') {
157
+ const candidates = [];
158
+ let insideURL = true;
159
+ value = value.trim();
160
+ for (let i = 0; i < value.length; i++) {
161
+ if (value[i] === ',' && (!insideURL || (insideURL && value[i + 1] === ' '))) {
162
+ candidates.push(value.slice(0, i));
163
+ value = value.substring(i + 1).trim();
164
+ i = 0;
165
+ insideURL = true;
166
+ } else if (value[i] === ' ') {
167
+ insideURL = false;
168
+ }
169
+ }
170
+ candidates.push(value);
171
+ for (const candidate of candidates) {
172
+ const src = candidate.split(WHITESPACE)[0];
173
+ hrefs.push(src);
174
+ }
175
+ }
176
+ } else {
177
+ i -= 1;
178
+ }
179
+ }
180
+
181
+ i += 1;
182
+ }
183
+
184
+ if (href && !/\bexternal\b/i.test(rel)) {
185
+ hrefs.push(href);
186
+ }
187
+ }
188
+ }
189
+
190
+ i += 1;
191
+ }
192
+
193
+ return hrefs;
194
+ }