@sveltejs/kit 1.0.0-next.45 → 1.0.0-next.452

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 (108) hide show
  1. package/README.md +12 -9
  2. package/package.json +92 -63
  3. package/src/cli.js +112 -0
  4. package/src/constants.js +7 -0
  5. package/src/core/adapt/builder.js +223 -0
  6. package/src/core/adapt/index.js +19 -0
  7. package/src/core/config/index.js +86 -0
  8. package/src/core/config/options.js +488 -0
  9. package/src/core/config/types.d.ts +1 -0
  10. package/src/core/env.js +112 -0
  11. package/src/core/generate_manifest/index.js +78 -0
  12. package/src/core/prerender/crawl.js +194 -0
  13. package/src/core/prerender/prerender.js +380 -0
  14. package/src/core/prerender/queue.js +80 -0
  15. package/src/core/sync/create_manifest_data/index.js +452 -0
  16. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  17. package/src/core/sync/sync.js +59 -0
  18. package/src/core/sync/utils.js +33 -0
  19. package/src/core/sync/write_ambient.js +53 -0
  20. package/src/core/sync/write_client_manifest.js +94 -0
  21. package/src/core/sync/write_matchers.js +25 -0
  22. package/src/core/sync/write_root.js +91 -0
  23. package/src/core/sync/write_tsconfig.js +195 -0
  24. package/src/core/sync/write_types/index.js +596 -0
  25. package/src/core/utils.js +70 -0
  26. package/src/exports/hooks/index.js +1 -0
  27. package/src/exports/hooks/sequence.js +26 -0
  28. package/src/exports/index.js +45 -0
  29. package/src/exports/node/index.js +145 -0
  30. package/src/exports/node/polyfills.js +40 -0
  31. package/src/exports/vite/build/build_server.js +348 -0
  32. package/src/exports/vite/build/build_service_worker.js +90 -0
  33. package/src/exports/vite/build/utils.js +160 -0
  34. package/src/exports/vite/dev/index.js +543 -0
  35. package/src/exports/vite/index.js +588 -0
  36. package/src/exports/vite/preview/index.js +186 -0
  37. package/src/exports/vite/types.d.ts +3 -0
  38. package/src/exports/vite/utils.js +345 -0
  39. package/src/runtime/app/env.js +1 -0
  40. package/src/runtime/app/environment.js +11 -0
  41. package/src/runtime/app/navigation.js +22 -0
  42. package/src/runtime/app/paths.js +1 -0
  43. package/src/runtime/app/stores.js +102 -0
  44. package/src/runtime/client/ambient.d.ts +24 -0
  45. package/src/runtime/client/client.js +1394 -0
  46. package/src/runtime/client/fetcher.js +60 -0
  47. package/src/runtime/client/parse.js +60 -0
  48. package/src/runtime/client/singletons.js +21 -0
  49. package/src/runtime/client/start.js +48 -0
  50. package/src/runtime/client/types.d.ts +88 -0
  51. package/src/runtime/client/utils.js +113 -0
  52. package/src/runtime/components/error.svelte +16 -0
  53. package/{assets → src/runtime}/components/layout.svelte +0 -0
  54. package/src/runtime/control.js +33 -0
  55. package/src/runtime/env/dynamic/private.js +1 -0
  56. package/src/runtime/env/dynamic/public.js +1 -0
  57. package/src/runtime/env-private.js +6 -0
  58. package/src/runtime/env-public.js +6 -0
  59. package/src/runtime/env.js +6 -0
  60. package/src/runtime/hash.js +16 -0
  61. package/src/runtime/paths.js +11 -0
  62. package/src/runtime/server/data/index.js +146 -0
  63. package/src/runtime/server/endpoint.js +50 -0
  64. package/src/runtime/server/index.js +369 -0
  65. package/src/runtime/server/page/cookie.js +25 -0
  66. package/src/runtime/server/page/crypto.js +239 -0
  67. package/src/runtime/server/page/csp.js +249 -0
  68. package/src/runtime/server/page/fetch.js +266 -0
  69. package/src/runtime/server/page/index.js +413 -0
  70. package/src/runtime/server/page/load_data.js +124 -0
  71. package/src/runtime/server/page/render.js +379 -0
  72. package/src/runtime/server/page/respond_with_error.js +94 -0
  73. package/src/runtime/server/page/types.d.ts +44 -0
  74. package/src/runtime/server/utils.js +137 -0
  75. package/src/utils/array.js +9 -0
  76. package/src/utils/error.js +22 -0
  77. package/src/utils/escape.js +104 -0
  78. package/src/utils/filesystem.js +108 -0
  79. package/src/utils/functions.js +16 -0
  80. package/src/utils/http.js +55 -0
  81. package/src/utils/misc.js +1 -0
  82. package/src/utils/routing.js +146 -0
  83. package/src/utils/url.js +142 -0
  84. package/svelte-kit.js +1 -1
  85. package/types/ambient.d.ts +319 -0
  86. package/types/index.d.ts +345 -0
  87. package/types/internal.d.ts +379 -0
  88. package/types/private.d.ts +209 -0
  89. package/CHANGELOG.md +0 -450
  90. package/assets/components/error.svelte +0 -13
  91. package/assets/runtime/app/env.js +0 -5
  92. package/assets/runtime/app/navigation.js +0 -41
  93. package/assets/runtime/app/paths.js +0 -1
  94. package/assets/runtime/app/stores.js +0 -93
  95. package/assets/runtime/chunks/utils.js +0 -19
  96. package/assets/runtime/internal/singletons.js +0 -23
  97. package/assets/runtime/internal/start.js +0 -770
  98. package/assets/runtime/paths.js +0 -12
  99. package/dist/chunks/index.js +0 -3521
  100. package/dist/chunks/index2.js +0 -587
  101. package/dist/chunks/index3.js +0 -246
  102. package/dist/chunks/index4.js +0 -536
  103. package/dist/chunks/index5.js +0 -761
  104. package/dist/chunks/index6.js +0 -322
  105. package/dist/chunks/standard.js +0 -99
  106. package/dist/chunks/utils.js +0 -83
  107. package/dist/cli.js +0 -546
  108. package/dist/ssr.js +0 -2580
@@ -0,0 +1,186 @@
1
+ import fs from 'fs';
2
+ import { join } from 'path';
3
+ import sirv from 'sirv';
4
+ import { pathToFileURL } from 'url';
5
+ import { getRequest, setResponse } from '../../../exports/node/index.js';
6
+ import { installPolyfills } from '../../../exports/node/polyfills.js';
7
+ import { SVELTE_KIT_ASSETS } from '../../../constants.js';
8
+ import { loadEnv } from 'vite';
9
+
10
+ /** @typedef {import('http').IncomingMessage} Req */
11
+ /** @typedef {import('http').ServerResponse} Res */
12
+ /** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
13
+
14
+ /**
15
+ * @param {{
16
+ * middlewares: import('connect').Server;
17
+ * httpServer: import('http').Server;
18
+ * }} vite
19
+ * @param {import('vite').ResolvedConfig} vite_config
20
+ * @param {import('types').ValidatedConfig} svelte_config
21
+ */
22
+ export async function preview(vite, vite_config, svelte_config) {
23
+ installPolyfills();
24
+
25
+ const { paths } = svelte_config.kit;
26
+ const base = paths.base;
27
+ const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
28
+
29
+ const protocol = vite_config.preview.https ? 'https' : 'http';
30
+
31
+ const etag = `"${Date.now()}"`;
32
+
33
+ const index_file = join(svelte_config.kit.outDir, 'output/server/index.js');
34
+ const manifest_file = join(svelte_config.kit.outDir, 'output/server/manifest.js');
35
+
36
+ /** @type {import('types').ServerModule} */
37
+ const { Server, override } = await import(pathToFileURL(index_file).href);
38
+ const { manifest } = await import(pathToFileURL(manifest_file).href);
39
+
40
+ override({
41
+ paths: { base, assets },
42
+ prerendering: false,
43
+ protocol,
44
+ read: (file) => fs.readFileSync(join(svelte_config.kit.files.assets, file))
45
+ });
46
+
47
+ const server = new Server(manifest);
48
+ await server.init({
49
+ env: loadEnv(vite_config.mode, process.cwd(), '')
50
+ });
51
+
52
+ return () => {
53
+ // generated client assets and the contents of `static`
54
+ vite.middlewares.use(
55
+ scoped(
56
+ assets,
57
+ sirv(join(svelte_config.kit.outDir, 'output/client'), {
58
+ setHeaders: (res, pathname) => {
59
+ // only apply to immutable directory, not e.g. version.json
60
+ if (pathname.startsWith(`/${svelte_config.kit.appDir}/immutable`)) {
61
+ res.setHeader('cache-control', 'public,max-age=31536000,immutable');
62
+ }
63
+ }
64
+ })
65
+ )
66
+ );
67
+
68
+ vite.middlewares.use((req, res, next) => {
69
+ const original_url = /** @type {string} */ (req.url);
70
+ const { pathname } = new URL(original_url, 'http://dummy');
71
+
72
+ if (pathname.startsWith(base)) {
73
+ next();
74
+ } else {
75
+ res.statusCode = 404;
76
+ res.end(`Not found (did you mean ${base + pathname}?)`);
77
+ }
78
+ });
79
+
80
+ // prerendered dependencies
81
+ vite.middlewares.use(
82
+ scoped(base, mutable(join(svelte_config.kit.outDir, 'output/prerendered/dependencies')))
83
+ );
84
+
85
+ // prerendered pages (we can't just use sirv because we need to
86
+ // preserve the correct trailingSlash behaviour)
87
+ vite.middlewares.use(
88
+ scoped(base, (req, res, next) => {
89
+ let if_none_match_value = req.headers['if-none-match'];
90
+
91
+ if (if_none_match_value?.startsWith('W/"')) {
92
+ if_none_match_value = if_none_match_value.substring(2);
93
+ }
94
+
95
+ if (if_none_match_value === etag) {
96
+ res.statusCode = 304;
97
+ res.end();
98
+ return;
99
+ }
100
+
101
+ const { pathname } = new URL(/** @type {string} */ (req.url), 'http://dummy');
102
+
103
+ // only treat this as a page if it doesn't include an extension
104
+ if (pathname === '/' || /\/[^./]+\/?$/.test(pathname)) {
105
+ const file = join(
106
+ svelte_config.kit.outDir,
107
+ 'output/prerendered/pages' +
108
+ pathname +
109
+ (pathname.endsWith('/') ? 'index.html' : '.html')
110
+ );
111
+
112
+ if (fs.existsSync(file)) {
113
+ res.writeHead(200, {
114
+ 'content-type': 'text/html',
115
+ etag
116
+ });
117
+
118
+ fs.createReadStream(file).pipe(res);
119
+ return;
120
+ }
121
+ }
122
+
123
+ next();
124
+ })
125
+ );
126
+
127
+ // SSR
128
+ vite.middlewares.use(async (req, res) => {
129
+ const host = req.headers['host'];
130
+
131
+ let request;
132
+
133
+ try {
134
+ request = await getRequest(`${protocol}://${host}`, req);
135
+ } catch (/** @type {any} */ err) {
136
+ res.statusCode = err.status || 400;
137
+ return res.end(err.reason || 'Invalid request body');
138
+ }
139
+
140
+ setResponse(
141
+ res,
142
+ await server.respond(request, {
143
+ getClientAddress: () => {
144
+ const { remoteAddress } = req.socket;
145
+ if (remoteAddress) return remoteAddress;
146
+ throw new Error('Could not determine clientAddress');
147
+ }
148
+ })
149
+ );
150
+ });
151
+ };
152
+ }
153
+
154
+ /**
155
+ * @param {string} dir
156
+ * @returns {Handler}
157
+ */
158
+ const mutable = (dir) =>
159
+ fs.existsSync(dir)
160
+ ? sirv(dir, {
161
+ etag: true,
162
+ maxAge: 0
163
+ })
164
+ : (_req, _res, next) => next();
165
+
166
+ /**
167
+ * @param {string} scope
168
+ * @param {Handler} handler
169
+ * @returns {Handler}
170
+ */
171
+ function scoped(scope, handler) {
172
+ if (scope === '') return handler;
173
+
174
+ return (req, res, next) => {
175
+ if (req.url?.startsWith(scope)) {
176
+ const original_url = req.url;
177
+ req.url = req.url.slice(scope.length);
178
+ handler(req, res, () => {
179
+ req.url = original_url;
180
+ next();
181
+ });
182
+ } else {
183
+ next();
184
+ }
185
+ };
186
+ }
@@ -0,0 +1,3 @@
1
+ export interface EnforcedConfig {
2
+ [key: string]: EnforcedConfig | true;
3
+ }
@@ -0,0 +1,345 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { loadConfigFromFile, loadEnv, normalizePath } from 'vite';
4
+ import { runtime_directory } from '../../core/utils.js';
5
+ import { posixify } from '../../utils/filesystem.js';
6
+
7
+ /**
8
+ * @param {import('vite').ResolvedConfig} config
9
+ * @param {import('vite').ConfigEnv} config_env
10
+ * @return {Promise<import('vite').UserConfig>}
11
+ */
12
+ export async function get_vite_config(config, config_env) {
13
+ const loaded = await loadConfigFromFile(
14
+ config_env,
15
+ config.configFile,
16
+ undefined,
17
+ config.logLevel
18
+ );
19
+
20
+ if (!loaded) {
21
+ throw new Error('Could not load Vite config');
22
+ }
23
+ return { ...loaded.config, mode: config_env.mode };
24
+ }
25
+
26
+ /**
27
+ * @param {...import('vite').UserConfig} configs
28
+ * @returns {import('vite').UserConfig}
29
+ */
30
+ export function merge_vite_configs(...configs) {
31
+ return deep_merge(
32
+ ...configs.map((config) => ({
33
+ ...config,
34
+ resolve: {
35
+ ...config.resolve,
36
+ alias: normalize_alias(config.resolve?.alias || {})
37
+ }
38
+ }))
39
+ );
40
+ }
41
+
42
+ /**
43
+ * Takes zero or more objects and returns a new object that has all the values
44
+ * deeply merged together. None of the original objects will be mutated at any
45
+ * level, and the returned object will have no references to the original
46
+ * objects at any depth. If there's a conflict the last one wins, except for
47
+ * arrays which will be combined.
48
+ * @param {...Object} objects
49
+ * @returns {Record<string, any>} the merged object
50
+ */
51
+ export function deep_merge(...objects) {
52
+ const result = {};
53
+ /** @type {string[]} */
54
+ objects.forEach((o) => merge_into(result, o));
55
+ return result;
56
+ }
57
+
58
+ /**
59
+ * normalize kit.vite.resolve.alias as an array
60
+ * @param {import('vite').AliasOptions} o
61
+ * @returns {import('vite').Alias[]}
62
+ */
63
+ function normalize_alias(o) {
64
+ if (Array.isArray(o)) return o;
65
+ return Object.entries(o).map(([find, replacement]) => ({ find, replacement }));
66
+ }
67
+
68
+ /**
69
+ * Merges b into a, recursively, mutating a.
70
+ * @param {Record<string, any>} a
71
+ * @param {Record<string, any>} b
72
+ */
73
+ function merge_into(a, b) {
74
+ /**
75
+ * Checks for "plain old Javascript object", typically made as an object
76
+ * literal. Excludes Arrays and built-in types like Buffer.
77
+ * @param {any} x
78
+ */
79
+ const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
80
+
81
+ for (const prop in b) {
82
+ if (is_plain_object(b[prop])) {
83
+ if (!is_plain_object(a[prop])) {
84
+ a[prop] = {};
85
+ }
86
+ merge_into(a[prop], b[prop]);
87
+ } else if (Array.isArray(b[prop])) {
88
+ if (!Array.isArray(a[prop])) {
89
+ a[prop] = [];
90
+ }
91
+ a[prop].push(...b[prop]);
92
+ } else {
93
+ a[prop] = b[prop];
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Transforms kit.alias to a valid vite.resolve.alias array.
100
+ * Related to tsconfig path alias creation.
101
+ *
102
+ * @param {import('types').ValidatedKitConfig} config
103
+ * */
104
+ export function get_aliases(config) {
105
+ /** @type {import('vite').Alias[]} */
106
+ const alias = [
107
+ { find: '__GENERATED__', replacement: path.posix.join(config.outDir, 'generated') },
108
+ { find: '$app', replacement: `${runtime_directory}/app` },
109
+ // For now, we handle `$lib` specially here rather than make it a default value for
110
+ // `config.kit.alias` since it has special meaning for packaging, etc.
111
+ { find: '$lib', replacement: config.files.lib }
112
+ ];
113
+
114
+ for (let [key, value] of Object.entries(config.alias)) {
115
+ value = posixify(value);
116
+ if (value.endsWith('/*')) {
117
+ value = value.slice(0, -2);
118
+ }
119
+ if (key.endsWith('/*')) {
120
+ // Doing just `{ find: key.slice(0, -2) ,..}` would mean `import .. from "key"` would also be matched, which we don't want
121
+ alias.push({
122
+ find: new RegExp(`^${escape_for_regexp(key.slice(0, -2))}\\/(.+)$`),
123
+ replacement: `${path.resolve(value)}/$1`
124
+ });
125
+ } else if (key + '/*' in config.alias) {
126
+ // key and key/* both exist -> the replacement for key needs to happen _only_ on import .. from "key"
127
+ alias.push({
128
+ find: new RegExp(`^${escape_for_regexp(key)}$`),
129
+ replacement: path.resolve(value)
130
+ });
131
+ } else {
132
+ alias.push({ find: key, replacement: path.resolve(value) });
133
+ }
134
+ }
135
+
136
+ return alias;
137
+ }
138
+
139
+ /**
140
+ * @param {string} str
141
+ */
142
+ function escape_for_regexp(str) {
143
+ return str.replace(/[.*+?^${}()|[\]\\]/g, (match) => '\\' + match);
144
+ }
145
+
146
+ /**
147
+ * Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
148
+ * @param {string} entry
149
+ * @returns {string|null}
150
+ */
151
+ export function resolve_entry(entry) {
152
+ if (fs.existsSync(entry)) {
153
+ const stats = fs.statSync(entry);
154
+ if (stats.isDirectory()) {
155
+ return resolve_entry(path.join(entry, 'index'));
156
+ }
157
+
158
+ return entry;
159
+ } else {
160
+ const dir = path.dirname(entry);
161
+
162
+ if (fs.existsSync(dir)) {
163
+ const base = path.basename(entry);
164
+ const files = fs.readdirSync(dir);
165
+
166
+ const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
167
+
168
+ if (found) return path.join(dir, found);
169
+ }
170
+ }
171
+
172
+ return null;
173
+ }
174
+
175
+ /**
176
+ * @param {string} str
177
+ * @param {number} times
178
+ */
179
+ function repeat(str, times) {
180
+ return new Array(times + 1).join(str);
181
+ }
182
+
183
+ /**
184
+ * Create a formatted error for an illegal import.
185
+ * @param {Array<{name: string, dynamic: boolean}>} stack
186
+ */
187
+ function format_illegal_import_chain(stack) {
188
+ const dev_virtual_prefix = '/@id/__x00__';
189
+ const prod_virtual_prefix = '\0';
190
+
191
+ stack = stack.map((file) => {
192
+ if (file.name.startsWith(dev_virtual_prefix)) {
193
+ return { ...file, name: file.name.replace(dev_virtual_prefix, '') };
194
+ }
195
+ if (file.name.startsWith(prod_virtual_prefix)) {
196
+ return { ...file, name: file.name.replace(prod_virtual_prefix, '') };
197
+ }
198
+
199
+ return { ...file, name: path.relative(process.cwd(), file.name) };
200
+ });
201
+
202
+ const pyramid = stack
203
+ .map(
204
+ (file, i) =>
205
+ `${repeat(' ', i * 2)}- ${file.name} ${
206
+ file.dynamic ? '(imported by parent dynamically)' : ''
207
+ }`
208
+ )
209
+ .join('\n');
210
+
211
+ return `Cannot import ${stack.at(-1)?.name} into client-side code:\n${pyramid}`;
212
+ }
213
+
214
+ /**
215
+ * Load environment variables from process.env and .env files
216
+ * @param {import('types').ValidatedKitConfig['env']} env_config
217
+ * @param {string} mode
218
+ */
219
+ export function get_env(env_config, mode) {
220
+ const entries = Object.entries(loadEnv(mode, env_config.dir, ''));
221
+
222
+ return {
223
+ public: Object.fromEntries(entries.filter(([k]) => k.startsWith(env_config.publicPrefix))),
224
+ private: Object.fromEntries(entries.filter(([k]) => !k.startsWith(env_config.publicPrefix)))
225
+ };
226
+ }
227
+
228
+ /**
229
+ * @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
230
+ * @param {import('rollup').ModuleInfo} node
231
+ * @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
232
+ */
233
+ export function prevent_illegal_rollup_imports(node_getter, node, illegal_imports) {
234
+ const chain = find_illegal_rollup_imports(node_getter, node, false, illegal_imports);
235
+ if (chain) throw new Error(format_illegal_import_chain(chain));
236
+ }
237
+
238
+ const query_pattern = /\?.*$/s;
239
+
240
+ /** @param {string} path */
241
+ function remove_query_from_path(path) {
242
+ return path.replace(query_pattern, '');
243
+ }
244
+
245
+ /**
246
+ * @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
247
+ * @param {import('rollup').ModuleInfo} node
248
+ * @param {boolean} dynamic
249
+ * @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
250
+ * @param {Set<string>} seen
251
+ * @returns {Array<import('types').ImportNode> | null}
252
+ */
253
+ const find_illegal_rollup_imports = (
254
+ node_getter,
255
+ node,
256
+ dynamic,
257
+ illegal_imports,
258
+ seen = new Set()
259
+ ) => {
260
+ const name = remove_query_from_path(normalizePath(node.id));
261
+ if (seen.has(name)) return null;
262
+ seen.add(name);
263
+
264
+ if (illegal_imports.has(name)) {
265
+ return [{ name, dynamic }];
266
+ }
267
+
268
+ for (const id of node.importedIds) {
269
+ const child = node_getter(id);
270
+ const chain =
271
+ child && find_illegal_rollup_imports(node_getter, child, false, illegal_imports, seen);
272
+ if (chain) return [{ name, dynamic }, ...chain];
273
+ }
274
+
275
+ for (const id of node.dynamicallyImportedIds) {
276
+ const child = node_getter(id);
277
+ const chain =
278
+ child && find_illegal_rollup_imports(node_getter, child, true, illegal_imports, seen);
279
+ if (chain) return [{ name, dynamic }, ...chain];
280
+ }
281
+
282
+ return null;
283
+ };
284
+
285
+ /**
286
+ * Vite does some weird things with import trees in dev
287
+ * for example, a Tailwind app.css will appear to import
288
+ * every file in the project. This isn't a problem for
289
+ * Rollup during build.
290
+ * @param {Iterable<string>} config_module_types
291
+ */
292
+ const get_module_types = (config_module_types) => {
293
+ return new Set([
294
+ '.ts',
295
+ '.js',
296
+ '.svelte',
297
+ '.mts',
298
+ '.mjs',
299
+ '.cts',
300
+ '.cjs',
301
+ '.svelte.md',
302
+ '.svx',
303
+ '.md',
304
+ ...config_module_types
305
+ ]);
306
+ };
307
+
308
+ /**
309
+ * Throw an error if a private module is imported from a client-side node.
310
+ * @param {import('vite').ModuleNode} node
311
+ * @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
312
+ * @param {Iterable<string>} module_types File extensions to analyze in addition to the defaults: `.ts`, `.js`, etc.
313
+ */
314
+ export function prevent_illegal_vite_imports(node, illegal_imports, module_types) {
315
+ const chain = find_illegal_vite_imports(node, illegal_imports, get_module_types(module_types));
316
+ if (chain) throw new Error(format_illegal_import_chain(chain));
317
+ }
318
+
319
+ /**
320
+ * @param {import('vite').ModuleNode} node
321
+ * @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
322
+ * @param {Set<string>} module_types File extensions to analyze: `.ts`, `.js`, etc.
323
+ * @param {Set<string>} seen
324
+ * @returns {Array<import('types').ImportNode> | null}
325
+ */
326
+ function find_illegal_vite_imports(node, illegal_imports, module_types, seen = new Set()) {
327
+ if (!node.id) return null; // TODO when does this happen?
328
+ const name = remove_query_from_path(normalizePath(node.id));
329
+
330
+ if (path.extname(name) !== '' && (seen.has(name) || !module_types.has(path.extname(name)))) {
331
+ return null;
332
+ }
333
+ seen.add(name);
334
+
335
+ if (name && illegal_imports.has(name)) {
336
+ return [{ name, dynamic: false }];
337
+ }
338
+
339
+ for (const child of node.importedModules) {
340
+ const chain = child && find_illegal_vite_imports(child, illegal_imports, module_types, seen);
341
+ if (chain) return [{ name, dynamic: false }, ...chain];
342
+ }
343
+
344
+ return null;
345
+ }
@@ -0,0 +1 @@
1
+ throw new Error('$app/env has been renamed to $app/environment');
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @type {import('$app/environment').browser}
3
+ */
4
+ export const browser = !import.meta.env.SSR;
5
+
6
+ /**
7
+ * @type {import('$app/environment').dev}
8
+ */
9
+ export const dev = __SVELTEKIT_DEV__;
10
+
11
+ export { prerendering } from '../env.js';
@@ -0,0 +1,22 @@
1
+ import { client } from '../client/singletons.js';
2
+
3
+ /**
4
+ * @param {string} name
5
+ */
6
+ function guard(name) {
7
+ return () => {
8
+ throw new Error(`Cannot call ${name}(...) on the server`);
9
+ };
10
+ }
11
+
12
+ const ssr = import.meta.env.SSR;
13
+
14
+ export const disableScrollHandling = ssr
15
+ ? guard('disableScrollHandling')
16
+ : client.disable_scroll_handling;
17
+ export const goto = ssr ? guard('goto') : client.goto;
18
+ export const invalidate = ssr ? guard('invalidate') : client.invalidate;
19
+ export const prefetch = ssr ? guard('prefetch') : client.prefetch;
20
+ export const prefetchRoutes = ssr ? guard('prefetchRoutes') : client.prefetch_routes;
21
+ export const beforeNavigate = ssr ? () => {} : client.before_navigate;
22
+ export const afterNavigate = ssr ? () => {} : client.after_navigate;
@@ -0,0 +1 @@
1
+ export { base, assets } from '../paths.js';
@@ -0,0 +1,102 @@
1
+ import { getContext } from 'svelte';
2
+ import { browser } from './environment.js';
3
+ import { stores as browser_stores } from '../client/singletons.js';
4
+
5
+ // TODO remove this (for 1.0? after 1.0?)
6
+ let warned = false;
7
+ export function stores() {
8
+ if (!warned) {
9
+ console.error('stores() is deprecated; use getStores() instead');
10
+ warned = true;
11
+ }
12
+ return getStores();
13
+ }
14
+
15
+ /**
16
+ * @type {import('$app/stores').getStores}
17
+ */
18
+ export const getStores = () => {
19
+ const stores = browser ? browser_stores : getContext('__svelte__');
20
+
21
+ const readonly_stores = {
22
+ page: {
23
+ subscribe: stores.page.subscribe
24
+ },
25
+ navigating: {
26
+ subscribe: stores.navigating.subscribe
27
+ },
28
+ updated: stores.updated
29
+ };
30
+
31
+ // TODO remove this for 1.0
32
+ Object.defineProperties(readonly_stores, {
33
+ preloading: {
34
+ get() {
35
+ console.error('stores.preloading is deprecated; use stores.navigating instead');
36
+ return {
37
+ subscribe: stores.navigating.subscribe
38
+ };
39
+ },
40
+ enumerable: false
41
+ },
42
+ session: {
43
+ get() {
44
+ removed_session();
45
+ return {};
46
+ },
47
+ enumerable: false
48
+ }
49
+ });
50
+
51
+ return readonly_stores;
52
+ };
53
+
54
+ /** @type {typeof import('$app/stores').page} */
55
+ export const page = {
56
+ /** @param {(value: any) => void} fn */
57
+ subscribe(fn) {
58
+ const store = getStores().page;
59
+ return store.subscribe(fn);
60
+ }
61
+ };
62
+
63
+ /** @type {typeof import('$app/stores').navigating} */
64
+ export const navigating = {
65
+ subscribe(fn) {
66
+ const store = getStores().navigating;
67
+ return store.subscribe(fn);
68
+ }
69
+ };
70
+
71
+ function removed_session() {
72
+ // TODO remove for 1.0
73
+ throw new Error(
74
+ 'stores.session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
75
+ );
76
+ }
77
+
78
+ export const session = {
79
+ subscribe: removed_session,
80
+ set: removed_session,
81
+ update: removed_session
82
+ };
83
+
84
+ /** @type {typeof import('$app/stores').updated} */
85
+ export const updated = {
86
+ subscribe(fn) {
87
+ const store = getStores().updated;
88
+
89
+ if (browser) {
90
+ updated.check = store.check;
91
+ }
92
+
93
+ return store.subscribe(fn);
94
+ },
95
+ check: () => {
96
+ throw new Error(
97
+ browser
98
+ ? `Cannot check updated store before subscribing`
99
+ : `Can only check updated store in browser`
100
+ );
101
+ }
102
+ };
@@ -0,0 +1,24 @@
1
+ declare module '__GENERATED__/client-manifest.js' {
2
+ import { CSRPageNodeLoader, ParamMatcher } from 'types';
3
+
4
+ /**
5
+ * A list of all the error/layout/page nodes used in the app
6
+ */
7
+ export const nodes: CSRPageNodeLoader[];
8
+
9
+ /**
10
+ * A list of all layout node ids that have a server load function.
11
+ * Pages are not present because it's shorter to encode it on the leaf itself.
12
+ */
13
+ export const server_loads: number[];
14
+
15
+ /**
16
+ * A map of `[routeId: string]: [leaf, layouts, errors]` tuples, which
17
+ * is parsed into an array of routes on startup. The numbers refer to the indices in `nodes`.
18
+ * If the leaf number is negative, it means it does use a server load function and the complement is the node index.
19
+ * The route layout and error nodes are not referenced, they are always number 0 and 1 and always apply.
20
+ */
21
+ export const dictionary: Record<string, [leaf: number, layouts: number[], errors?: number[]]>;
22
+
23
+ export const matchers: Record<string, ParamMatcher>;
24
+ }