@sveltejs/kit 1.0.0-next.50 → 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.
- package/README.md +12 -9
- package/package.json +94 -67
- package/postinstall.js +38 -0
- package/scripts/special-types/$env+dynamic+private.md +10 -0
- package/scripts/special-types/$env+dynamic+public.md +8 -0
- package/scripts/special-types/$env+static+private.md +19 -0
- package/scripts/special-types/$env+static+public.md +7 -0
- package/scripts/special-types/$lib.md +5 -0
- package/src/cli.js +108 -0
- package/src/constants.js +7 -0
- package/src/core/adapt/builder.js +206 -0
- package/src/core/adapt/index.js +31 -0
- package/src/core/config/default-error.html +56 -0
- package/src/core/config/index.js +110 -0
- package/src/core/config/options.js +504 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/env.js +121 -0
- package/src/core/generate_manifest/index.js +93 -0
- package/src/core/prerender/crawl.js +198 -0
- package/src/core/prerender/entities.js +2252 -0
- package/src/core/prerender/prerender.js +431 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/index.js +488 -0
- package/src/core/sync/create_manifest_data/types.d.ts +37 -0
- package/src/core/sync/sync.js +70 -0
- package/src/core/sync/utils.js +33 -0
- package/src/core/sync/write_ambient.js +53 -0
- package/src/core/sync/write_client_manifest.js +106 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +91 -0
- package/src/core/sync/write_tsconfig.js +195 -0
- package/src/core/sync/write_types/index.js +678 -0
- package/src/core/utils.js +70 -0
- package/src/exports/hooks/index.js +1 -0
- package/src/exports/hooks/sequence.js +44 -0
- package/src/exports/index.js +45 -0
- package/src/exports/node/index.js +173 -0
- package/src/exports/node/polyfills.js +41 -0
- package/src/exports/vite/build/build_server.js +378 -0
- package/src/exports/vite/build/build_service_worker.js +90 -0
- package/src/exports/vite/build/utils.js +180 -0
- package/src/exports/vite/dev/index.js +577 -0
- package/src/exports/vite/graph_analysis/index.js +277 -0
- package/src/exports/vite/graph_analysis/types.d.ts +5 -0
- package/src/exports/vite/graph_analysis/utils.js +30 -0
- package/src/exports/vite/index.js +598 -0
- package/src/exports/vite/preview/index.js +189 -0
- package/src/exports/vite/types.d.ts +3 -0
- package/src/exports/vite/utils.js +157 -0
- package/src/runtime/app/env.js +1 -0
- package/src/runtime/app/environment.js +11 -0
- package/src/runtime/app/forms.js +114 -0
- package/src/runtime/app/navigation.js +23 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +26 -0
- package/src/runtime/client/client.js +1583 -0
- package/src/runtime/client/fetcher.js +107 -0
- package/src/runtime/client/parse.js +60 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +37 -0
- package/src/runtime/client/types.d.ts +84 -0
- package/src/runtime/client/utils.js +159 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/src/runtime/control.js +98 -0
- package/src/runtime/env/dynamic/private.js +1 -0
- package/src/runtime/env/dynamic/public.js +1 -0
- package/src/runtime/env-private.js +6 -0
- package/src/runtime/env-public.js +6 -0
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +16 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/cookie.js +127 -0
- package/src/runtime/server/data/index.js +136 -0
- package/src/runtime/server/endpoint.js +90 -0
- package/src/runtime/server/index.js +340 -0
- package/src/runtime/server/page/actions.js +243 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +250 -0
- package/src/runtime/server/page/fetch.js +301 -0
- package/src/runtime/server/page/index.js +304 -0
- package/src/runtime/server/page/load_data.js +124 -0
- package/src/runtime/server/page/render.js +342 -0
- package/src/runtime/server/page/respond_with_error.js +104 -0
- package/src/runtime/server/page/serialize_data.js +87 -0
- package/src/runtime/server/page/types.d.ts +41 -0
- package/src/runtime/server/utils.js +179 -0
- package/src/utils/array.js +9 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +46 -0
- package/src/utils/filesystem.js +137 -0
- package/src/utils/functions.js +16 -0
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/routing.js +117 -0
- package/src/utils/unit_test.js +11 -0
- package/src/utils/url.js +142 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +426 -0
- package/types/index.d.ts +444 -0
- package/types/internal.d.ts +378 -0
- package/types/private.d.ts +224 -0
- package/CHANGELOG.md +0 -484
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -44
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -22
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -779
- package/assets/runtime/paths.js +0 -12
- package/dist/chunks/index.js +0 -3516
- package/dist/chunks/index2.js +0 -587
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -528
- package/dist/chunks/index5.js +0 -763
- package/dist/chunks/index6.js +0 -322
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -83
- package/dist/cli.js +0 -550
- package/dist/ssr.js +0 -2588
- package/types.d.ts +0 -89
- package/types.internal.d.ts +0 -191
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { normalizePath } from 'vite';
|
|
3
|
+
import { remove_query_from_id, get_module_types } from './utils.js';
|
|
4
|
+
|
|
5
|
+
/** @typedef {import('./types').ImportGraph} ImportGraph */
|
|
6
|
+
|
|
7
|
+
const CWD_ID = normalizePath(process.cwd());
|
|
8
|
+
const NODE_MODULES_ID = normalizePath(path.resolve(process.cwd(), 'node_modules'));
|
|
9
|
+
const ILLEGAL_IMPORTS = new Set([
|
|
10
|
+
'/@id/__x00__$env/dynamic/private', //dev
|
|
11
|
+
'\0$env/dynamic/private', // prod
|
|
12
|
+
'/@id/__x00__$env/static/private', // dev
|
|
13
|
+
'\0$env/static/private' // prod
|
|
14
|
+
]);
|
|
15
|
+
const ILLEGAL_MODULE_NAME_PATTERN = /.*\.server\..+/;
|
|
16
|
+
|
|
17
|
+
export class IllegalModuleGuard {
|
|
18
|
+
/** @type {string} */
|
|
19
|
+
#lib_dir;
|
|
20
|
+
|
|
21
|
+
/** @type {string} */
|
|
22
|
+
#server_dir;
|
|
23
|
+
|
|
24
|
+
/** @type {Array<ImportGraph>} */
|
|
25
|
+
#chain = [];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} lib_dir
|
|
29
|
+
*/
|
|
30
|
+
constructor(lib_dir) {
|
|
31
|
+
this.#lib_dir = normalizePath(lib_dir);
|
|
32
|
+
this.#server_dir = normalizePath(path.resolve(lib_dir, 'server'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Assert that a node imports no illegal modules.
|
|
37
|
+
* @param {ImportGraph} node
|
|
38
|
+
* @returns {void}
|
|
39
|
+
*/
|
|
40
|
+
assert_legal(node) {
|
|
41
|
+
this.#chain.push(node);
|
|
42
|
+
for (const child of node.children) {
|
|
43
|
+
if (this.#is_illegal(child.id)) {
|
|
44
|
+
this.#chain.push(child);
|
|
45
|
+
const error = this.#format_illegal_import_chain(this.#chain);
|
|
46
|
+
this.#chain = []; // Reset the chain in case we want to reuse this guard
|
|
47
|
+
throw new Error(error);
|
|
48
|
+
}
|
|
49
|
+
this.assert_legal(child);
|
|
50
|
+
}
|
|
51
|
+
this.#chain.pop();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* `true` if the provided ID represents a server-only module, else `false`.
|
|
56
|
+
* @param {string} module_id
|
|
57
|
+
* @returns {boolean}
|
|
58
|
+
*/
|
|
59
|
+
#is_illegal(module_id) {
|
|
60
|
+
if (this.#is_kit_illegal(module_id) || this.#is_user_illegal(module_id)) return true;
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* `true` if the provided ID represents a Kit-defined server-only module, else `false`.
|
|
66
|
+
* @param {string} module_id
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
#is_kit_illegal(module_id) {
|
|
70
|
+
return ILLEGAL_IMPORTS.has(module_id);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* `true` if the provided ID represents a user-defined server-only module, else `false`.
|
|
75
|
+
* @param {string} module_id
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
#is_user_illegal(module_id) {
|
|
79
|
+
if (module_id.startsWith(this.#server_dir)) return true;
|
|
80
|
+
|
|
81
|
+
// files outside the project root are ignored
|
|
82
|
+
if (!module_id.startsWith(CWD_ID)) return false;
|
|
83
|
+
|
|
84
|
+
// so are files inside node_modules
|
|
85
|
+
if (module_id.startsWith(NODE_MODULES_ID)) return false;
|
|
86
|
+
|
|
87
|
+
return ILLEGAL_MODULE_NAME_PATTERN.test(path.basename(module_id));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {string} str
|
|
92
|
+
* @param {number} times
|
|
93
|
+
*/
|
|
94
|
+
#repeat(str, times) {
|
|
95
|
+
return new Array(times + 1).join(str);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create a formatted error for an illegal import.
|
|
100
|
+
* @param {Array<ImportGraph>} stack
|
|
101
|
+
*/
|
|
102
|
+
#format_illegal_import_chain(stack) {
|
|
103
|
+
const dev_virtual_prefix = '/@id/__x00__';
|
|
104
|
+
const prod_virtual_prefix = '\0';
|
|
105
|
+
|
|
106
|
+
stack = stack.map((graph) => {
|
|
107
|
+
if (graph.id.startsWith(dev_virtual_prefix)) {
|
|
108
|
+
return { ...graph, id: graph.id.replace(dev_virtual_prefix, '') };
|
|
109
|
+
}
|
|
110
|
+
if (graph.id.startsWith(prod_virtual_prefix)) {
|
|
111
|
+
return { ...graph, id: graph.id.replace(prod_virtual_prefix, '') };
|
|
112
|
+
}
|
|
113
|
+
if (graph.id.startsWith(this.#lib_dir)) {
|
|
114
|
+
return { ...graph, id: graph.id.replace(this.#lib_dir, '$lib') };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { ...graph, id: path.relative(process.cwd(), graph.id) };
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const pyramid = stack
|
|
121
|
+
.map(
|
|
122
|
+
(file, i) =>
|
|
123
|
+
`${this.#repeat(' ', i * 2)}- ${file.id} ${
|
|
124
|
+
file.dynamic ? '(imported by parent dynamically)' : ''
|
|
125
|
+
}`
|
|
126
|
+
)
|
|
127
|
+
.join('\n');
|
|
128
|
+
|
|
129
|
+
return `Cannot import ${stack.at(-1)?.id} into public-facing code:\n${pyramid}`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** @implements {ImportGraph} */
|
|
134
|
+
export class RollupImportGraph {
|
|
135
|
+
/** @type {(id: string) => import('rollup').ModuleInfo | null} */
|
|
136
|
+
#node_getter;
|
|
137
|
+
|
|
138
|
+
/** @type {import('rollup').ModuleInfo} */
|
|
139
|
+
#module_info;
|
|
140
|
+
|
|
141
|
+
/** @type {string} */
|
|
142
|
+
id;
|
|
143
|
+
|
|
144
|
+
/** @type {boolean} */
|
|
145
|
+
dynamic;
|
|
146
|
+
|
|
147
|
+
/** @type {Set<string>} */
|
|
148
|
+
#seen;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
152
|
+
* @param {import('rollup').ModuleInfo} node
|
|
153
|
+
*/
|
|
154
|
+
constructor(node_getter, node) {
|
|
155
|
+
this.#node_getter = node_getter;
|
|
156
|
+
this.#module_info = node;
|
|
157
|
+
this.id = remove_query_from_id(normalizePath(node.id));
|
|
158
|
+
this.dynamic = false;
|
|
159
|
+
this.#seen = new Set();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
164
|
+
* @param {import('rollup').ModuleInfo} node
|
|
165
|
+
* @param {boolean} dynamic
|
|
166
|
+
* @param {Set<string>} seen;
|
|
167
|
+
* @returns {RollupImportGraph}
|
|
168
|
+
*/
|
|
169
|
+
static #new_internal(node_getter, node, dynamic, seen) {
|
|
170
|
+
const instance = new RollupImportGraph(node_getter, node);
|
|
171
|
+
instance.dynamic = dynamic;
|
|
172
|
+
instance.#seen = seen;
|
|
173
|
+
return instance;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
get children() {
|
|
177
|
+
return this.#children();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
*#children() {
|
|
181
|
+
if (this.#seen.has(this.id)) return;
|
|
182
|
+
this.#seen.add(this.id);
|
|
183
|
+
for (const id of this.#module_info.importedIds) {
|
|
184
|
+
const child = this.#node_getter(id);
|
|
185
|
+
if (child === null) return;
|
|
186
|
+
yield RollupImportGraph.#new_internal(this.#node_getter, child, false, this.#seen);
|
|
187
|
+
}
|
|
188
|
+
for (const id of this.#module_info.dynamicallyImportedIds) {
|
|
189
|
+
const child = this.#node_getter(id);
|
|
190
|
+
if (child === null) return;
|
|
191
|
+
yield RollupImportGraph.#new_internal(this.#node_getter, child, true, this.#seen);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** @implements {ImportGraph} */
|
|
197
|
+
export class ViteImportGraph {
|
|
198
|
+
/** @type {Set<string>} */
|
|
199
|
+
#module_types;
|
|
200
|
+
|
|
201
|
+
/** @type {import('vite').ModuleNode} */
|
|
202
|
+
#module_info;
|
|
203
|
+
|
|
204
|
+
/** @type {string} */
|
|
205
|
+
id;
|
|
206
|
+
|
|
207
|
+
/** @type {Set<string>} */
|
|
208
|
+
#seen;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @param {Set<string>} module_types Module types to analyze, eg '.js', '.ts', etc.
|
|
212
|
+
* @param {import('vite').ModuleNode} node
|
|
213
|
+
*/
|
|
214
|
+
constructor(module_types, node) {
|
|
215
|
+
this.#module_types = module_types;
|
|
216
|
+
this.#module_info = node;
|
|
217
|
+
this.id = remove_query_from_id(normalizePath(node.id ?? ''));
|
|
218
|
+
this.#seen = new Set();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @param {Set<string>} module_types Module types to analyze, eg '.js', '.ts', etc.
|
|
223
|
+
* @param {import('vite').ModuleNode} node
|
|
224
|
+
* @param {Set<string>} seen
|
|
225
|
+
* @returns {ViteImportGraph}
|
|
226
|
+
*/
|
|
227
|
+
static #new_internal(module_types, node, seen) {
|
|
228
|
+
const instance = new ViteImportGraph(module_types, node);
|
|
229
|
+
instance.#seen = seen;
|
|
230
|
+
return instance;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
get dynamic() {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
get children() {
|
|
238
|
+
return this.#children();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
*#children() {
|
|
242
|
+
if (this.#seen.has(this.id)) return;
|
|
243
|
+
this.#seen.add(this.id);
|
|
244
|
+
for (const child of this.#module_info.importedModules) {
|
|
245
|
+
if (!this.#module_types.has(path.extname(this.id))) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
yield ViteImportGraph.#new_internal(this.#module_types, child, this.#seen);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Throw an error if a private module is imported from a client-side node.
|
|
255
|
+
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
256
|
+
* @param {import('rollup').ModuleInfo} node
|
|
257
|
+
* @param {string} lib_dir
|
|
258
|
+
* @returns {void}
|
|
259
|
+
*/
|
|
260
|
+
export function prevent_illegal_rollup_imports(node_getter, node, lib_dir) {
|
|
261
|
+
const graph = new RollupImportGraph(node_getter, node);
|
|
262
|
+
const guard = new IllegalModuleGuard(lib_dir);
|
|
263
|
+
guard.assert_legal(graph);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Throw an error if a private module is imported from a client-side node.
|
|
268
|
+
* @param {import('vite').ModuleNode} node
|
|
269
|
+
* @param {string} lib_dir
|
|
270
|
+
* @param {Iterable<string>} module_types File extensions to analyze in addition to the defaults: `.ts`, `.js`, etc.
|
|
271
|
+
* @returns {void}
|
|
272
|
+
*/
|
|
273
|
+
export function prevent_illegal_vite_imports(node, lib_dir, module_types) {
|
|
274
|
+
const graph = new ViteImportGraph(get_module_types(module_types), node);
|
|
275
|
+
const guard = new IllegalModuleGuard(lib_dir);
|
|
276
|
+
guard.assert_legal(graph);
|
|
277
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const query_pattern = /\?.*$/s;
|
|
2
|
+
|
|
3
|
+
/** @param {string} path */
|
|
4
|
+
export function remove_query_from_id(path) {
|
|
5
|
+
return path.replace(query_pattern, '');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Vite does some weird things with import trees in dev
|
|
10
|
+
* for example, a Tailwind app.css will appear to import
|
|
11
|
+
* every file in the project. This isn't a problem for
|
|
12
|
+
* Rollup during build.
|
|
13
|
+
* @param {Iterable<string>} config_module_types
|
|
14
|
+
*/
|
|
15
|
+
export const get_module_types = (config_module_types) => {
|
|
16
|
+
return new Set([
|
|
17
|
+
'',
|
|
18
|
+
'.ts',
|
|
19
|
+
'.js',
|
|
20
|
+
'.svelte',
|
|
21
|
+
'.mts',
|
|
22
|
+
'.mjs',
|
|
23
|
+
'.cts',
|
|
24
|
+
'.cjs',
|
|
25
|
+
'.svelte.md',
|
|
26
|
+
'.svx',
|
|
27
|
+
'.md',
|
|
28
|
+
...config_module_types
|
|
29
|
+
]);
|
|
30
|
+
};
|