@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
@@ -1,569 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { r as rimraf, c as copy_assets } from './utils.js';
4
- import { c as create_manifest_data, a as create_app } from './index2.js';
5
- import vite from 'vite';
6
- import svelte from '@sveltejs/vite-plugin-svelte';
7
- import '../cli.js';
8
- import 'sade';
9
- import 'url';
10
- import './standard.js';
11
-
12
- /** @param {any} value */
13
- const s = (value) => JSON.stringify(value);
14
-
15
- /** @typedef {Record<string, {
16
- * file: string;
17
- * css: string[];
18
- * imports: string[];
19
- * }>} ClientManifest */
20
-
21
- /**
22
- * @param {import('../../../types.internal').ValidatedConfig} config
23
- * @param {{
24
- * cwd?: string;
25
- * runtime?: string;
26
- * }} [opts]
27
- */
28
- async function build(config, { cwd = process.cwd(), runtime = '@sveltejs/kit/ssr' } = {}) {
29
- const build_dir = path.resolve(cwd, '.svelte/build');
30
-
31
- rimraf(build_dir);
32
-
33
- const options = {
34
- cwd,
35
- config,
36
- build_dir,
37
- base:
38
- config.kit.paths.assets === '/.'
39
- ? `/${config.kit.appDir}/`
40
- : `${config.kit.paths.assets}/${config.kit.appDir}/`,
41
- manifest: create_manifest_data({
42
- config,
43
- output: build_dir,
44
- cwd
45
- }),
46
- output_dir: path.resolve(cwd, '.svelte/output'),
47
- client_entry_file: '.svelte/build/runtime/internal/start.js',
48
- service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker)
49
- };
50
-
51
- const client_manifest = await build_client(options);
52
- await build_server(options, client_manifest, runtime);
53
-
54
- if (options.service_worker_entry_file) {
55
- const { base, assets } = config.kit.paths;
56
-
57
- if (assets !== base && assets !== '/.') {
58
- throw new Error('Cannot use service worker alongside config.kit.paths.assets');
59
- }
60
-
61
- await build_service_worker(options, client_manifest);
62
- }
63
- }
64
-
65
- /**
66
- * @param {{
67
- * cwd: string;
68
- * base: string;
69
- * config: import('../../../types.internal').ValidatedConfig
70
- * manifest: import('../../../types.internal').ManifestData
71
- * build_dir: string;
72
- * output_dir: string;
73
- * client_entry_file: string;
74
- * service_worker_entry_file: string;
75
- * }} options
76
- */
77
- async function build_client({
78
- cwd,
79
- base,
80
- config,
81
- manifest,
82
- build_dir,
83
- output_dir,
84
- client_entry_file,
85
- service_worker_entry_file
86
- }) {
87
- create_app({
88
- manifest_data: manifest,
89
- output: build_dir,
90
- cwd
91
- });
92
-
93
- copy_assets(build_dir);
94
-
95
- process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';
96
- process.env.VITE_SVELTEKIT_SERVICE_WORKER = service_worker_entry_file ? '/service-worker.js' : '';
97
-
98
- const client_out_dir = `${output_dir}/client/${config.kit.appDir}`;
99
- const client_manifest_file = `${client_out_dir}/manifest.json`;
100
-
101
- /** @type {Record<string, string>} */
102
- const input = {
103
- start: path.resolve(cwd, client_entry_file)
104
- };
105
-
106
- manifest.components.forEach((file) => {
107
- const resolved = path.resolve(cwd, file);
108
- const relative = path.relative(config.kit.files.routes, resolved);
109
- input[path.join('pages', relative)] = resolved;
110
- });
111
-
112
- /** @type {any} */
113
- const user_config = config.kit.vite();
114
-
115
- await vite.build({
116
- ...user_config,
117
- configFile: false,
118
- root: cwd,
119
- base,
120
- build: {
121
- ...user_config.build,
122
- cssCodeSplit: true,
123
- manifest: true,
124
- lib: {
125
- // TODO i'm not convinced this block is necessary if we're
126
- // providing inputs explicitly via rollupOptions, but without
127
- // it Vite complains about the dynamic import polyfill
128
- entry: client_entry_file,
129
- name: 'app',
130
- formats: ['es']
131
- },
132
- outDir: client_out_dir,
133
- rollupOptions: {
134
- ...(user_config.build && user_config.build.rollupOptions),
135
- input,
136
- output: {
137
- entryFileNames: '[name]-[hash].js',
138
- chunkFileNames: 'chunks/[name]-[hash].js',
139
- assetFileNames: 'assets/[name]-[hash][extname]'
140
- },
141
- preserveEntrySignatures: 'strict'
142
- }
143
- },
144
- resolve: {
145
- ...user_config.resolve,
146
- alias: {
147
- ...(user_config.resolve && user_config.resolve.alias),
148
- $app: path.resolve(`${build_dir}/runtime/app`),
149
- $lib: config.kit.files.lib
150
- }
151
- },
152
- plugins: [
153
- ...(user_config.plugins || []),
154
- svelte({
155
- extensions: config.extensions
156
- })
157
- ]
158
- });
159
-
160
- /** @type {ClientManifest} */
161
- const client_manifest = JSON.parse(fs.readFileSync(client_manifest_file, 'utf-8'));
162
- fs.unlinkSync(client_manifest_file);
163
-
164
- return client_manifest;
165
- }
166
-
167
- /**
168
- * @param {{
169
- * cwd: string;
170
- * base: string;
171
- * config: import('../../../types.internal').ValidatedConfig
172
- * manifest: import('../../../types.internal').ManifestData
173
- * build_dir: string;
174
- * output_dir: string;
175
- * client_entry_file: string;
176
- * service_worker_entry_file: string;
177
- * }} options
178
- * @param {ClientManifest} client_manifest
179
- * @param {string} runtime
180
- */
181
- async function build_server(
182
- { cwd, base, config, manifest, build_dir, output_dir, client_entry_file },
183
- client_manifest,
184
- runtime
185
- ) {
186
- let setup_file = resolve_entry(config.kit.files.setup);
187
- if (!fs.existsSync(setup_file)) {
188
- setup_file = path.resolve(cwd, '.svelte/build/setup.js');
189
- fs.writeFileSync(setup_file, '');
190
- }
191
-
192
- const app_file = `${build_dir}/app.js`;
193
-
194
- /** @type {(file: string) => string} */
195
- const app_relative = (file) => {
196
- const relative_file = path.relative(build_dir, path.resolve(cwd, file));
197
- return relative_file[0] === '.' ? relative_file : `./${relative_file}`;
198
- };
199
-
200
- const component_indexes = new Map();
201
- manifest.components.forEach((c, i) => {
202
- component_indexes.set(c, i);
203
- });
204
-
205
- /** @param {string} c */
206
- const stringify_component = (c) => `() => import(${s(`${app_relative(c)}`)})`;
207
-
208
- const entry = `${config.kit.paths.assets}/${config.kit.appDir}/${client_manifest[client_entry_file].file}`;
209
-
210
- /** @type {Set<string>} */
211
- const common_js_deps = new Set();
212
-
213
- /** @type {Set<string>} */
214
- const common_css_deps = new Set();
215
-
216
- /** @type {Map<string, Set<string>>} */
217
- const js_deps_by_file = new Map();
218
-
219
- /** @type {Map<string, Set<string>>} */
220
- const css_deps_by_file = new Map();
221
-
222
- /**
223
- * @param {string} file
224
- * @param {Set<string>} js_deps
225
- * @param {Set<string>} css_deps
226
- */
227
- function find_deps(file, js_deps, css_deps) {
228
- const chunk = client_manifest[file];
229
-
230
- js_deps.add(chunk.file);
231
-
232
- if (chunk.css) {
233
- chunk.css.forEach((file) => css_deps.add(file));
234
- }
235
-
236
- if (chunk.imports) {
237
- chunk.imports.forEach((file) => find_deps(file, js_deps, css_deps));
238
- }
239
- }
240
-
241
- find_deps(client_entry_file, common_js_deps, common_css_deps);
242
-
243
- // TODO ideally we wouldn't embed the css_lookup, but this is the easiest
244
- // way to be able to inline CSS into AMP documents. if we come up with
245
- // something better, we could use it for non-AMP documents too, as
246
- // critical CSS below a certain threshold _should_ be inlined
247
-
248
- /** @type {Record<string, string>} */
249
- const amp_css_lookup = {};
250
-
251
- /** @type {Record<string, string>} */
252
- const client_component_lookup = {};
253
-
254
- [client_entry_file, ...manifest.components].forEach((file) => {
255
- client_component_lookup[file] = client_manifest[file].file;
256
-
257
- const js_deps = new Set();
258
- const css_deps = new Set();
259
-
260
- js_deps_by_file.set(file, js_deps);
261
- css_deps_by_file.set(file, css_deps);
262
-
263
- find_deps(file, js_deps, css_deps);
264
-
265
- css_deps.forEach((file) => {
266
- const resolved = `${output_dir}/client/${config.kit.appDir}/${file}`;
267
- const contents = fs.readFileSync(resolved, 'utf-8');
268
-
269
- amp_css_lookup[file] = contents;
270
- });
271
- });
272
-
273
- // prettier-ignore
274
- fs.writeFileSync(
275
- app_file,
276
- `
277
- import { ssr } from '${runtime}';
278
- import root from './generated/root.svelte';
279
- import { set_paths } from './runtime/paths.js';
280
- import * as setup from ${s(app_relative(setup_file))};
281
-
282
- const template = ({ head, body }) => ${s(fs.readFileSync(config.kit.files.template, 'utf-8'))
283
- .replace('%svelte.head%', '" + head + "')
284
- .replace('%svelte.body%', '" + body + "')};
285
-
286
- set_paths(${s(config.kit.paths)});
287
-
288
- // allow paths to be overridden in svelte-kit start
289
- export function init({ paths }) {
290
- set_paths(paths);
291
- }
292
-
293
- const d = decodeURIComponent;
294
- const empty = () => ({});
295
-
296
- const components = [
297
- ${manifest.components.map((c) => stringify_component(c)).join(',\n\t\t\t\t')}
298
- ];
299
-
300
- ${config.kit.amp ? `
301
- const amp_css_lookup = ${s(amp_css_lookup)};` : ''}
302
-
303
- const client_component_lookup = ${s(client_component_lookup)};
304
-
305
- const manifest = {
306
- assets: ${s(manifest.assets)},
307
- layout: ${stringify_component(manifest.layout)},
308
- error: ${stringify_component(manifest.error)},
309
- routes: [
310
- ${manifest.routes
311
- .map((route) => {
312
- if (route.type === 'page') {
313
- const params = get_params(route.params);
314
- const parts = route.parts.map(id => `{ id: ${s(id)}, load: components[${component_indexes.get(id)}] }`);
315
-
316
- const js_deps = new Set(common_js_deps);
317
- const css_deps = new Set(common_css_deps);
318
-
319
- for (const file of route.parts) {
320
- js_deps_by_file.get(file).forEach(asset => {
321
- js_deps.add(asset);
322
- });
323
-
324
- css_deps_by_file.get(file).forEach(asset => {
325
- css_deps.add(asset);
326
- });
327
- }
328
-
329
- return `{
330
- type: 'page',
331
- pattern: ${route.pattern},
332
- params: ${params},
333
- parts: [${parts.join(', ')}],
334
- css: [${Array.from(css_deps).map(s).join(', ')}],
335
- js: [${Array.from(js_deps).map(s).join(', ')}]
336
- }`;
337
- } else {
338
- const params = get_params(route.params);
339
- const load = `() => import(${s(app_relative(route.file))})`;
340
-
341
- return `{
342
- type: 'endpoint',
343
- pattern: ${route.pattern},
344
- params: ${params},
345
- load: ${load}
346
- }`;
347
- }
348
- })
349
- .join(',\n\t\t\t\t\t')}
350
- ]
351
- };
352
-
353
- export function render(request, {
354
- paths = ${s(config.kit.paths)},
355
- local = false,
356
- only_render_prerenderable_pages = false,
357
- get_static_file
358
- } = {}) {
359
- return ssr(request, {
360
- paths,
361
- local,
362
- template,
363
- manifest,
364
- target: ${s(config.kit.target)},
365
- entry: ${s(entry)},
366
- root,
367
- setup,
368
- dev: false,
369
- amp: ${config.kit.amp},
370
- only_render_prerenderable_pages,
371
- app_dir: ${s(config.kit.appDir)},
372
- host: ${s(config.kit.host)},
373
- host_header: ${s(config.kit.hostHeader)},
374
- get_component_path: id => ${s(`${config.kit.paths.assets}/${config.kit.appDir}/`)} + client_component_lookup[id],
375
- get_stack: error => error.stack,
376
- get_static_file,
377
- get_amp_css: dep => amp_css_lookup[dep]
378
- });
379
- }
380
- `
381
- .replace(/^\t{3}/gm, '')
382
- .trim()
383
- );
384
-
385
- /** @type {any} */
386
- const user_config = config.kit.vite();
387
-
388
- await vite.build({
389
- ...user_config,
390
- configFile: false,
391
- root: cwd,
392
- base,
393
- build: {
394
- target: 'es2018',
395
- ...user_config.build,
396
- ssr: true,
397
- lib: {
398
- entry: app_file,
399
- name: 'app',
400
- formats: ['es']
401
- },
402
- outDir: `${output_dir}/server`
403
- },
404
- resolve: {
405
- ...user_config.resolve,
406
- alias: {
407
- ...(user_config.resolve && user_config.resolve.alias),
408
- $app: path.resolve(`${build_dir}/runtime/app`),
409
- $lib: config.kit.files.lib
410
- }
411
- },
412
- plugins: [
413
- ...(user_config.plugins || []),
414
- svelte({
415
- extensions: config.extensions
416
- })
417
- ],
418
- // this API is marked as @alpha https://github.com/vitejs/vite/blob/27785f7fcc5b45987b5f0bf308137ddbdd9f79ea/packages/vite/src/node/config.ts#L129
419
- // it's not exposed in the typescript definitions as a result
420
- // so we need to ignore the fact that it's missing
421
- // @ts-ignore
422
- ssr: {
423
- ...user_config.ssr,
424
- noExternal: [
425
- 'svelte',
426
- '@sveltejs/kit',
427
- ...((user_config.ssr && user_config.ssr.noExternal) || [])
428
- ]
429
- },
430
- optimizeDeps: {
431
- entries: []
432
- }
433
- });
434
- }
435
-
436
- /**
437
- * @param {{
438
- * cwd: string;
439
- * base: string;
440
- * config: import('../../../types.internal').ValidatedConfig
441
- * manifest: import('../../../types.internal').ManifestData
442
- * build_dir: string;
443
- * output_dir: string;
444
- * client_entry_file: string;
445
- * service_worker_entry_file: string;
446
- * }} options
447
- * @param {ClientManifest} client_manifest
448
- */
449
- async function build_service_worker(
450
- { cwd, base, config, manifest, build_dir, output_dir, service_worker_entry_file },
451
- client_manifest
452
- ) {
453
- // TODO add any assets referenced in template .html file, e.g. favicon?
454
- const app_files = new Set();
455
- for (const key in client_manifest) {
456
- const { file, css } = client_manifest[key];
457
- app_files.add(file);
458
- if (css) {
459
- css.forEach((file) => {
460
- app_files.add(file);
461
- });
462
- }
463
- }
464
-
465
- fs.writeFileSync(
466
- `${build_dir}/runtime/service-worker.js`,
467
- `
468
- export const timestamp = ${Date.now()};
469
-
470
- export const build = [
471
- ${Array.from(app_files)
472
- .map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
473
- .join(',\n\t\t\t\t')}
474
- ];
475
-
476
- export const assets = [
477
- ${manifest.assets
478
- .map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`)
479
- .join(',\n\t\t\t\t')}
480
- ];
481
- `
482
- .replace(/^\t{3}/gm, '')
483
- .trim()
484
- );
485
-
486
- /** @type {any} */
487
- const user_config = config.kit.vite();
488
-
489
- await vite.build({
490
- ...user_config,
491
- configFile: false,
492
- root: cwd,
493
- base,
494
- build: {
495
- ...user_config.build,
496
- lib: {
497
- entry: service_worker_entry_file,
498
- name: 'app',
499
- formats: ['es']
500
- },
501
- rollupOptions: {
502
- ...(user_config.build && user_config.build.rollupOptions),
503
- output: {
504
- entryFileNames: 'service-worker.js'
505
- }
506
- },
507
- outDir: `${output_dir}/client`,
508
- emptyOutDir: false
509
- },
510
- resolve: {
511
- ...user_config.resolve,
512
- alias: {
513
- ...(user_config.resolve && user_config.resolve.alias),
514
- '$service-worker': path.resolve(`${build_dir}/runtime/service-worker`)
515
- }
516
- },
517
- optimizeDeps: {
518
- entries: []
519
- }
520
- });
521
- }
522
-
523
- /**
524
- * @param {string} entry
525
- * @returns {string}
526
- */
527
- function resolve_entry(entry) {
528
- if (fs.existsSync(entry)) {
529
- const stats = fs.statSync(entry);
530
- if (stats.isDirectory()) {
531
- return resolve_entry(path.join(entry, 'index'));
532
- }
533
-
534
- return entry;
535
- } else {
536
- const dir = path.dirname(entry);
537
-
538
- if (fs.existsSync(dir)) {
539
- const base = path.basename(entry);
540
- const files = fs.readdirSync(dir);
541
-
542
- const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
543
-
544
- if (found) return path.join(dir, found);
545
- }
546
- }
547
-
548
- return null;
549
- }
550
-
551
- /** @param {string[]} array */
552
- function get_params(array) {
553
- // given an array of params like `['x', 'y', 'z']` for
554
- // src/routes/[x]/[y]/[z]/svelte, create a function
555
- // that turns a RexExpMatchArray into ({ x, y, z })
556
- return array.length
557
- ? '(m) => ({ ' +
558
- array
559
- .map((param, i) => {
560
- return param.startsWith('...')
561
- ? `${param.slice(3)}: d(m[${i + 1}])`
562
- : `${param}: d(m[${i + 1}])`;
563
- })
564
- .join(', ') +
565
- '})'
566
- : 'empty';
567
- }
568
-
569
- export { build };