@sveltejs/kit 1.0.0-next.52 → 1.0.0-next.520

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