@sveltejs/kit 1.0.0-next.23 → 1.0.0-next.230

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 (83) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +20 -0
  3. package/assets/app/navigation.js +81 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/{runtime/app → app}/stores.js +19 -15
  6. package/assets/chunks/utils.js +13 -0
  7. package/assets/client/singletons.js +18 -0
  8. package/assets/client/start.js +1382 -0
  9. package/assets/components/error.svelte +19 -3
  10. package/assets/env.js +8 -0
  11. package/assets/paths.js +13 -0
  12. package/assets/server/index.js +1998 -0
  13. package/dist/chunks/cert.js +28154 -0
  14. package/dist/chunks/index.js +2391 -0
  15. package/dist/chunks/index2.js +807 -0
  16. package/dist/chunks/index3.js +648 -0
  17. package/dist/chunks/index4.js +109 -0
  18. package/dist/chunks/index5.js +754 -0
  19. package/dist/chunks/index6.js +830 -0
  20. package/dist/chunks/index7.js +15574 -0
  21. package/dist/chunks/index8.js +4207 -0
  22. package/dist/chunks/misc.js +3 -0
  23. package/dist/chunks/multipart-parser.js +449 -0
  24. package/dist/chunks/url.js +62 -0
  25. package/dist/cli.js +1039 -84
  26. package/dist/hooks.js +28 -0
  27. package/dist/install-fetch.js +6514 -0
  28. package/dist/node.js +51 -0
  29. package/package.json +93 -54
  30. package/svelte-kit.js +2 -0
  31. package/types/ambient-modules.d.ts +204 -0
  32. package/types/app.d.ts +45 -0
  33. package/types/config.d.ts +169 -0
  34. package/types/endpoint.d.ts +20 -0
  35. package/types/helper.d.ts +53 -0
  36. package/types/hooks.d.ts +55 -0
  37. package/types/index.d.ts +18 -0
  38. package/types/internal.d.ts +237 -0
  39. package/types/page.d.ts +73 -0
  40. package/CHANGELOG.md +0 -294
  41. package/assets/runtime/app/navigation.js +0 -23
  42. package/assets/runtime/app/navigation.js.map +0 -1
  43. package/assets/runtime/app/paths.js +0 -2
  44. package/assets/runtime/app/paths.js.map +0 -1
  45. package/assets/runtime/app/stores.js.map +0 -1
  46. package/assets/runtime/internal/singletons.js +0 -15
  47. package/assets/runtime/internal/singletons.js.map +0 -1
  48. package/assets/runtime/internal/start.js +0 -591
  49. package/assets/runtime/internal/start.js.map +0 -1
  50. package/assets/runtime/utils-85ebcc60.js +0 -18
  51. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  52. package/dist/api.js +0 -44
  53. package/dist/api.js.map +0 -1
  54. package/dist/build.js +0 -246
  55. package/dist/build.js.map +0 -1
  56. package/dist/cli.js.map +0 -1
  57. package/dist/colors.js +0 -37
  58. package/dist/colors.js.map +0 -1
  59. package/dist/create_app.js +0 -578
  60. package/dist/create_app.js.map +0 -1
  61. package/dist/index.js +0 -367
  62. package/dist/index.js.map +0 -1
  63. package/dist/index2.js +0 -12044
  64. package/dist/index2.js.map +0 -1
  65. package/dist/index3.js +0 -547
  66. package/dist/index3.js.map +0 -1
  67. package/dist/index4.js +0 -73
  68. package/dist/index4.js.map +0 -1
  69. package/dist/index5.js +0 -464
  70. package/dist/index5.js.map +0 -1
  71. package/dist/index6.js +0 -729
  72. package/dist/index6.js.map +0 -1
  73. package/dist/logging.js +0 -43
  74. package/dist/logging.js.map +0 -1
  75. package/dist/package.js +0 -432
  76. package/dist/package.js.map +0 -1
  77. package/dist/renderer.js +0 -2391
  78. package/dist/renderer.js.map +0 -1
  79. package/dist/standard.js +0 -101
  80. package/dist/standard.js.map +0 -1
  81. package/dist/utils.js +0 -54
  82. package/dist/utils.js.map +0 -1
  83. package/svelte-kit +0 -3
package/dist/cli.js CHANGED
@@ -1,92 +1,952 @@
1
- 'use strict';
2
-
3
- var sade = require('sade');
4
- var index = require('./index.js');
5
- require('path');
6
- require('module');
7
- require('url');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- function _interopNamespace(e) {
12
- if (e && e.__esModule) return e;
13
- var n = Object.create(null);
14
- if (e) {
15
- Object.keys(e).forEach(function (k) {
16
- if (k !== 'default') {
17
- var d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: function () {
21
- return e[k];
22
- }
23
- });
24
- }
25
- });
1
+ import sade from 'sade';
2
+ import path__default, { relative } from 'path';
3
+ import { exec as exec$1 } from 'child_process';
4
+ import { createConnection, createServer } from 'net';
5
+ import fs__default from 'fs';
6
+ import * as url from 'url';
7
+ import { fileURLToPath } from 'url';
8
+ import { networkInterfaces, release } from 'os';
9
+
10
+ let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
11
+ if (typeof process !== 'undefined') {
12
+ ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env);
13
+ isTTY = process.stdout && process.stdout.isTTY;
14
+ }
15
+
16
+ const $ = {
17
+ enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (
18
+ FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY
19
+ ),
20
+
21
+ // modifiers
22
+ reset: init(0, 0),
23
+ bold: init(1, 22),
24
+ dim: init(2, 22),
25
+ italic: init(3, 23),
26
+ underline: init(4, 24),
27
+ inverse: init(7, 27),
28
+ hidden: init(8, 28),
29
+ strikethrough: init(9, 29),
30
+
31
+ // colors
32
+ black: init(30, 39),
33
+ red: init(31, 39),
34
+ green: init(32, 39),
35
+ yellow: init(33, 39),
36
+ blue: init(34, 39),
37
+ magenta: init(35, 39),
38
+ cyan: init(36, 39),
39
+ white: init(37, 39),
40
+ gray: init(90, 39),
41
+ grey: init(90, 39),
42
+
43
+ // background colors
44
+ bgBlack: init(40, 49),
45
+ bgRed: init(41, 49),
46
+ bgGreen: init(42, 49),
47
+ bgYellow: init(43, 49),
48
+ bgBlue: init(44, 49),
49
+ bgMagenta: init(45, 49),
50
+ bgCyan: init(46, 49),
51
+ bgWhite: init(47, 49)
52
+ };
53
+
54
+ function run(arr, str) {
55
+ let i=0, tmp, beg='', end='';
56
+ for (; i < arr.length; i++) {
57
+ tmp = arr[i];
58
+ beg += tmp.open;
59
+ end += tmp.close;
60
+ if (!!~str.indexOf(tmp.close)) {
61
+ str = str.replace(tmp.rgx, tmp.close + tmp.open);
62
+ }
26
63
  }
27
- n['default'] = e;
28
- return Object.freeze(n);
64
+ return beg + str + end;
29
65
  }
30
66
 
31
- var sade__default = /*#__PURE__*/_interopDefaultLegacy(sade);
67
+ function chain(has, keys) {
68
+ let ctx = { has, keys };
69
+
70
+ ctx.reset = $.reset.bind(ctx);
71
+ ctx.bold = $.bold.bind(ctx);
72
+ ctx.dim = $.dim.bind(ctx);
73
+ ctx.italic = $.italic.bind(ctx);
74
+ ctx.underline = $.underline.bind(ctx);
75
+ ctx.inverse = $.inverse.bind(ctx);
76
+ ctx.hidden = $.hidden.bind(ctx);
77
+ ctx.strikethrough = $.strikethrough.bind(ctx);
78
+
79
+ ctx.black = $.black.bind(ctx);
80
+ ctx.red = $.red.bind(ctx);
81
+ ctx.green = $.green.bind(ctx);
82
+ ctx.yellow = $.yellow.bind(ctx);
83
+ ctx.blue = $.blue.bind(ctx);
84
+ ctx.magenta = $.magenta.bind(ctx);
85
+ ctx.cyan = $.cyan.bind(ctx);
86
+ ctx.white = $.white.bind(ctx);
87
+ ctx.gray = $.gray.bind(ctx);
88
+ ctx.grey = $.grey.bind(ctx);
89
+
90
+ ctx.bgBlack = $.bgBlack.bind(ctx);
91
+ ctx.bgRed = $.bgRed.bind(ctx);
92
+ ctx.bgGreen = $.bgGreen.bind(ctx);
93
+ ctx.bgYellow = $.bgYellow.bind(ctx);
94
+ ctx.bgBlue = $.bgBlue.bind(ctx);
95
+ ctx.bgMagenta = $.bgMagenta.bind(ctx);
96
+ ctx.bgCyan = $.bgCyan.bind(ctx);
97
+ ctx.bgWhite = $.bgWhite.bind(ctx);
32
98
 
33
- var version = "1.0.0-next.23";
99
+ return ctx;
100
+ }
101
+
102
+ function init(open, close) {
103
+ let blk = {
104
+ open: `\x1b[${open}m`,
105
+ close: `\x1b[${close}m`,
106
+ rgx: new RegExp(`\\x1b\\[${close}m`, 'g')
107
+ };
108
+ return function (txt) {
109
+ if (this !== void 0 && this.has !== void 0) {
110
+ !!~this.has.indexOf(open) || (this.has.push(open),this.keys.push(blk));
111
+ return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+'';
112
+ }
113
+ return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+'';
114
+ };
115
+ }
34
116
 
35
- function get_config() {
117
+ function exec(cmd) {
118
+ return new Promise((fulfil, reject) => {
119
+ exec$1(cmd, (error, stdout, stderr) => {
120
+ if (error) return reject(error);
121
+ fulfil({ stdout, stderr });
122
+ });
123
+ });
124
+ }
125
+
126
+ async function blame(port) {
36
127
  try {
37
- return index.load_config();
128
+ const { stdout } = await exec(`lsof -i :${port} -sTCP:LISTEN -Fp`);
129
+
130
+ if (!stdout) return null;
131
+ const pid = parseInt(stdout.slice(1), 10);
132
+ if (isNaN(pid)) throw new Error(`Invalid stdout ${stdout}`);
133
+
134
+ return pid;
38
135
  } catch (error) {
39
- let message = error.message;
136
+ return null;
137
+ }
138
+ }
139
+
140
+ let promise;
141
+
142
+ function weird() {
143
+ if (!promise) {
144
+ promise = get_weird(9000);
145
+ }
146
+ return promise;
147
+ }
148
+
149
+ function get_weird(port) {
150
+ return new Promise(fulfil => {
151
+ const server = createServer();
152
+
153
+ server.unref();
154
+
155
+ server.on('error', () => {
156
+ fulfil(get_weird(port + 1));
157
+ });
158
+
159
+ server.listen({ port }, () => {
160
+ const server2 = createServer();
161
+
162
+ server2.unref();
163
+
164
+ server2.on('error', () => {
165
+ server.close(() => {
166
+ fulfil(false);
167
+ });
168
+ });
169
+
170
+ server2.listen({ port }, () => {
171
+ server2.close(() => {
172
+ server.close(() => {
173
+ fulfil(true);
174
+ });
175
+ });
176
+ });
177
+ });
178
+ });
179
+ }
180
+
181
+ function check(port) {
182
+ return weird().then(weird => {
183
+ if (weird) {
184
+ return check_weird(port);
185
+ }
186
+
187
+ return new Promise(fulfil => {
188
+ const server = createServer();
189
+
190
+ server.unref();
191
+
192
+ server.on('error', () => {
193
+ fulfil(false);
194
+ });
195
+
196
+ server.listen({ port }, () => {
197
+ server.close(() => {
198
+ fulfil(true);
199
+ });
200
+ });
201
+ });
202
+ });
203
+ }
204
+
205
+ function check_weird(port) {
206
+ return new Promise(fulfil => {
207
+ const client = createConnection({ port }, () => {
208
+ client.end();
209
+ fulfil(false);
210
+ })
211
+ .on('error', () => {
212
+ fulfil(true);
213
+ });
214
+ });
215
+ }
216
+
217
+ /** @param {string} dir */
218
+ function mkdirp(dir) {
219
+ try {
220
+ fs__default.mkdirSync(dir, { recursive: true });
221
+ } catch (/** @type {any} */ e) {
222
+ if (e.code === 'EEXIST') return;
223
+ throw e;
224
+ }
225
+ }
226
+
227
+ /** @param {string} path */
228
+ function rimraf(path) {
229
+ (fs__default.rmSync || fs__default.rmdirSync)(path, { recursive: true, force: true });
230
+ }
231
+
232
+ /**
233
+ * @param {string} source
234
+ * @param {string} target
235
+ * @param {{
236
+ * filter?: (basename: string) => boolean;
237
+ * replace?: Record<string, string>;
238
+ * }} opts
239
+ */
240
+ function copy(source, target, opts = {}) {
241
+ if (!fs__default.existsSync(source)) return [];
242
+
243
+ /** @type {string[]} */
244
+ const files = [];
245
+
246
+ const prefix = posixify(target) + '/';
247
+
248
+ const regex = opts.replace
249
+ ? new RegExp(`\\b(${Object.keys(opts.replace).join('|')})\\b`, 'g')
250
+ : null;
251
+
252
+ /**
253
+ * @param {string} from
254
+ * @param {string} to
255
+ */
256
+ function go(from, to) {
257
+ if (opts.filter && !opts.filter(path__default.basename(from))) return;
258
+
259
+ const stats = fs__default.statSync(from);
260
+
261
+ if (stats.isDirectory()) {
262
+ fs__default.readdirSync(from).forEach((file) => {
263
+ go(path__default.join(from, file), path__default.join(to, file));
264
+ });
265
+ } else {
266
+ mkdirp(path__default.dirname(to));
267
+
268
+ if (opts.replace) {
269
+ const data = fs__default.readFileSync(from, 'utf-8');
270
+ fs__default.writeFileSync(
271
+ to,
272
+ data.replace(
273
+ /** @type {RegExp} */ (regex),
274
+ (match, key) => /** @type {Record<string, string>} */ (opts.replace)[key]
275
+ )
276
+ );
277
+ } else {
278
+ fs__default.copyFileSync(from, to);
279
+ }
280
+
281
+ files.push(to === target ? posixify(path__default.basename(to)) : posixify(to).replace(prefix, ''));
282
+ }
283
+ }
284
+
285
+ go(source, target);
286
+
287
+ return files;
288
+ }
289
+
290
+ /**
291
+ * Get a list of all files in a directory
292
+ * @param {string} cwd - the directory to walk
293
+ * @param {boolean} [dirs] - whether to include directories in the result
294
+ */
295
+ function walk(cwd, dirs = false) {
296
+ /** @type {string[]} */
297
+ const all_files = [];
298
+
299
+ /** @param {string} dir */
300
+ function walk_dir(dir) {
301
+ const files = fs__default.readdirSync(path__default.join(cwd, dir));
302
+
303
+ for (const file of files) {
304
+ const joined = path__default.join(dir, file);
305
+ const stats = fs__default.statSync(path__default.join(cwd, joined));
306
+ if (stats.isDirectory()) {
307
+ if (dirs) all_files.push(joined);
308
+ walk_dir(joined);
309
+ } else {
310
+ all_files.push(joined);
311
+ }
312
+ }
313
+ }
314
+
315
+ return walk_dir(''), all_files;
316
+ }
317
+
318
+ /** @param {string} str */
319
+ function posixify(str) {
320
+ return str.replace(/\\/g, '/');
321
+ }
322
+
323
+ const SVELTE_KIT = '.svelte-kit';
324
+
325
+ // in `svelte-kit dev` and `svelte-kit preview`, we use a fake
326
+ // asset path so that we can serve local assets while still
327
+ // verifying that requests are correctly prefixed
328
+ const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
329
+
330
+ const __filename = fileURLToPath(import.meta.url);
331
+ const __dirname = path__default.dirname(__filename);
332
+
333
+ const runtime = posixify_path(path__default.resolve(`${SVELTE_KIT}/runtime`))
334
+ ;
335
+
336
+ /** @param {string} str */
337
+ function posixify_path(str) {
338
+ const parsed = path__default.parse(str);
339
+ return `/${parsed.dir.slice(parsed.root.length).split(path__default.sep).join('/')}/${parsed.base}`;
340
+ }
341
+
342
+ /** @param {string} dest */
343
+ function copy_assets(dest) {
344
+ {
345
+ let prefix = '..';
346
+ do {
347
+ // we jump through these hoops so that this function
348
+ // works whether or not it's been bundled
349
+ const resolved = path__default.resolve(__dirname, `${prefix}/assets`);
350
+
351
+ if (fs__default.existsSync(resolved)) {
352
+ copy(resolved, dest);
353
+ return;
354
+ }
355
+
356
+ prefix = `../${prefix}`;
357
+ } while (true); // eslint-disable-line
358
+ }
359
+ }
360
+
361
+ function noop() {}
362
+
363
+ /** @param {{ verbose: boolean }} opts */
364
+ function logger({ verbose }) {
365
+ /** @type {import('types/internal').Logger} */
366
+ const log = (msg) => console.log(msg.replace(/^/gm, ' '));
367
+
368
+ /** @param {string} msg */
369
+ const err = (msg) => console.error(msg.replace(/^/gm, ' '));
370
+
371
+ log.success = (msg) => log($.green(`✔ ${msg}`));
372
+ log.error = (msg) => err($.bold().red(msg));
373
+ log.warn = (msg) => log($.bold().yellow(msg));
374
+
375
+ log.minor = verbose ? (msg) => log($.grey(msg)) : noop;
376
+ log.info = verbose ? log : noop;
377
+
378
+ return log;
379
+ }
380
+
381
+ /**
382
+ * Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
383
+ * @param {string} entry
384
+ * @returns {string|null}
385
+ */
386
+ function resolve_entry(entry) {
387
+ if (fs__default.existsSync(entry)) {
388
+ const stats = fs__default.statSync(entry);
389
+ if (stats.isDirectory()) {
390
+ return resolve_entry(path__default.join(entry, 'index'));
391
+ }
392
+
393
+ return entry;
394
+ } else {
395
+ const dir = path__default.dirname(entry);
396
+
397
+ if (fs__default.existsSync(dir)) {
398
+ const base = path__default.basename(entry);
399
+ const files = fs__default.readdirSync(dir);
400
+
401
+ const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
402
+
403
+ if (found) return path__default.join(dir, found);
404
+ }
405
+ }
406
+
407
+ return null;
408
+ }
409
+
410
+ /** @param {import('./create_app/index.js').ManifestData} manifest_data */
411
+ function get_mime_lookup(manifest_data) {
412
+ /** @type {Record<string, string>} */
413
+ const mime = {};
414
+
415
+ manifest_data.assets.forEach((asset) => {
416
+ if (asset.type) {
417
+ const ext = path__default.extname(asset.file);
418
+ mime[ext] = asset.type;
419
+ }
420
+ });
421
+
422
+ return mime;
423
+ }
424
+
425
+ /** @param {import('@sveltejs/kit').ValidatedConfig} config */
426
+ function get_aliases(config) {
427
+ const alias = {
428
+ __GENERATED__: path__default.posix.resolve(`${SVELTE_KIT}/generated`),
429
+ $app: `${runtime}/app`,
430
+ $lib: config.kit.files.lib
431
+ };
432
+
433
+ return alias;
434
+ }
435
+
436
+ /** @typedef {import('./types').Validator} Validator */
437
+
438
+ /** @type {Validator} */
439
+ const options = object(
440
+ {
441
+ extensions: validate(['.svelte'], (input, keypath) => {
442
+ if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
443
+ throw new Error(`${keypath} must be an array of strings`);
444
+ }
445
+
446
+ input.forEach((extension) => {
447
+ if (extension[0] !== '.') {
448
+ throw new Error(`Each member of ${keypath} must start with '.' — saw '${extension}'`);
449
+ }
450
+
451
+ if (!/^(\.[a-z0-9]+)+$/i.test(extension)) {
452
+ throw new Error(`File extensions must be alphanumeric — saw '${extension}'`);
453
+ }
454
+ });
455
+
456
+ return input;
457
+ }),
458
+
459
+ kit: object({
460
+ adapter: validate(null, (input, keypath) => {
461
+ if (typeof input !== 'object' || !input.adapt) {
462
+ let message = `${keypath} should be an object with an "adapt" method`;
463
+
464
+ if (Array.isArray(input) || typeof input === 'string') {
465
+ // for the early adapter adopters
466
+ message += ', rather than the name of an adapter';
467
+ }
468
+
469
+ throw new Error(`${message}. See https://kit.svelte.dev/docs#adapters`);
470
+ }
471
+
472
+ return input;
473
+ }),
474
+
475
+ amp: boolean(false),
40
476
 
41
- if (error.code === 'ENOENT') {
42
- message = 'Missing svelte.config.js';
43
- } else if (error.name === 'SyntaxError') {
44
- message = 'Malformed svelte.config.js';
477
+ appDir: validate('_app', (input, keypath) => {
478
+ assert_string(input, keypath);
479
+
480
+ if (input) {
481
+ if (input.startsWith('/') || input.endsWith('/')) {
482
+ throw new Error(
483
+ "config.kit.appDir cannot start or end with '/'. See https://kit.svelte.dev/docs#configuration"
484
+ );
485
+ }
486
+ } else {
487
+ throw new Error(`${keypath} cannot be empty`);
488
+ }
489
+
490
+ return input;
491
+ }),
492
+
493
+ files: object({
494
+ assets: string('static'),
495
+ hooks: string('src/hooks'),
496
+ lib: string('src/lib'),
497
+ routes: string('src/routes'),
498
+ serviceWorker: string('src/service-worker'),
499
+ template: string('src/app.html')
500
+ }),
501
+
502
+ floc: boolean(false),
503
+
504
+ headers: object({
505
+ host: string(null),
506
+ protocol: string(null)
507
+ }),
508
+
509
+ host: string(null),
510
+
511
+ hydrate: boolean(true),
512
+
513
+ inlineStyleThreshold: number(0),
514
+
515
+ methodOverride: object({
516
+ parameter: string('_method'),
517
+ allowed: validate([], (input, keypath) => {
518
+ if (!Array.isArray(input) || !input.every((method) => typeof method === 'string')) {
519
+ throw new Error(`${keypath} must be an array of strings`);
520
+ }
521
+
522
+ if (input.map((i) => i.toUpperCase()).includes('GET')) {
523
+ throw new Error(`${keypath} cannot contain "GET"`);
524
+ }
525
+
526
+ return input;
527
+ })
528
+ }),
529
+
530
+ package: object({
531
+ dir: string('package'),
532
+ // excludes all .d.ts and filename starting with _
533
+ exports: fun((filepath) => !/^_|\/_|\.d\.ts$/.test(filepath)),
534
+ files: fun(() => true),
535
+ emitTypes: boolean(true)
536
+ }),
537
+
538
+ paths: object({
539
+ base: validate('', (input, keypath) => {
540
+ assert_string(input, keypath);
541
+
542
+ if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
543
+ throw new Error(
544
+ `${keypath} option must be a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs#configuration-paths`
545
+ );
546
+ }
547
+
548
+ return input;
549
+ }),
550
+ assets: validate('', (input, keypath) => {
551
+ assert_string(input, keypath);
552
+
553
+ if (input) {
554
+ if (!/^[a-z]+:\/\//.test(input)) {
555
+ throw new Error(
556
+ `${keypath} option must be an absolute path, if specified. See https://kit.svelte.dev/docs#configuration-paths`
557
+ );
558
+ }
559
+
560
+ if (input.endsWith('/')) {
561
+ throw new Error(
562
+ `${keypath} option must not end with '/'. See https://kit.svelte.dev/docs#configuration-paths`
563
+ );
564
+ }
565
+ }
566
+
567
+ return input;
568
+ })
569
+ }),
570
+
571
+ prerender: object({
572
+ concurrency: number(1),
573
+ crawl: boolean(true),
574
+ enabled: boolean(true),
575
+ entries: validate(['*'], (input, keypath) => {
576
+ if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
577
+ throw new Error(`${keypath} must be an array of strings`);
578
+ }
579
+
580
+ input.forEach((page) => {
581
+ if (page !== '*' && page[0] !== '/') {
582
+ throw new Error(
583
+ `Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
584
+ );
585
+ }
586
+ });
587
+
588
+ return input;
589
+ }),
590
+ // TODO: remove this for the 1.0 release
591
+ force: validate(undefined, (input, keypath) => {
592
+ if (typeof input !== undefined) {
593
+ const newSetting = input ? 'continue' : 'fail';
594
+ const needsSetting = newSetting === 'continue';
595
+ throw new Error(
596
+ `${keypath} has been removed in favor of \`onError\`. In your case, set \`onError\` to "${newSetting}"${
597
+ needsSetting ? '' : ' (or leave it undefined)'
598
+ } to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
599
+ );
600
+ }
601
+ }),
602
+ onError: validate('fail', (input, keypath) => {
603
+ if (typeof input === 'function') return input;
604
+ if (['continue', 'fail'].includes(input)) return input;
605
+ throw new Error(
606
+ `${keypath} should be either a custom function or one of "continue" or "fail"`
607
+ );
608
+ }),
609
+ // TODO: remove this for the 1.0 release
610
+ pages: validate(undefined, (input, keypath) => {
611
+ if (typeof input !== undefined) {
612
+ throw new Error(`${keypath} has been renamed to \`entries\`.`);
613
+ }
614
+ })
615
+ }),
616
+
617
+ protocol: string(null),
618
+
619
+ router: boolean(true),
620
+
621
+ serviceWorker: object({
622
+ register: boolean(true),
623
+ files: fun((filename) => !/\.DS_STORE/.test(filename))
624
+ }),
625
+
626
+ // TODO remove this for 1.0
627
+ ssr: validate(null, (input) => {
628
+ if (input !== undefined) {
629
+ throw new Error(
630
+ 'config.kit.ssr has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'
631
+ );
632
+ }
633
+ }),
634
+
635
+ target: string(null),
636
+
637
+ trailingSlash: list(['never', 'always', 'ignore']),
638
+
639
+ vite: validate(
640
+ () => ({}),
641
+ (input, keypath) => {
642
+ if (typeof input === 'object') {
643
+ const config = input;
644
+ input = () => config;
645
+ }
646
+
647
+ if (typeof input !== 'function') {
648
+ throw new Error(
649
+ `${keypath} must be a Vite config object (https://vitejs.dev/config) or a function that returns one`
650
+ );
651
+ }
652
+
653
+ return input;
654
+ }
655
+ )
656
+ })
657
+ },
658
+ true
659
+ );
660
+
661
+ /**
662
+ * @param {Record<string, Validator>} children
663
+ * @param {boolean} [allow_unknown]
664
+ * @returns {Validator}
665
+ */
666
+ function object(children, allow_unknown = false) {
667
+ return (input, keypath) => {
668
+ /** @type {Record<string, any>} */
669
+ const output = {};
670
+
671
+ if ((input && typeof input !== 'object') || Array.isArray(input)) {
672
+ throw new Error(`${keypath} should be an object`);
673
+ }
674
+
675
+ for (const key in input) {
676
+ if (!(key in children)) {
677
+ if (allow_unknown) {
678
+ output[key] = input[key];
679
+ } else {
680
+ let message = `Unexpected option ${keypath}.${key}`;
681
+
682
+ // special case
683
+ if (keypath === 'config.kit' && key in options) {
684
+ message += ` (did you mean config.${key}?)`;
685
+ }
686
+
687
+ throw new Error(message);
688
+ }
689
+ }
690
+ }
691
+
692
+ for (const key in children) {
693
+ const validator = children[key];
694
+ output[key] = validator(input && input[key], `${keypath}.${key}`);
695
+ }
696
+
697
+ return output;
698
+ };
699
+ }
700
+
701
+ /**
702
+ * @param {any} fallback
703
+ * @param {(value: any, keypath: string) => any} fn
704
+ * @returns {Validator}
705
+ */
706
+ function validate(fallback, fn) {
707
+ return (input, keypath) => {
708
+ return input === undefined ? fallback : fn(input, keypath);
709
+ };
710
+ }
711
+
712
+ /**
713
+ * @param {string | null} fallback
714
+ * @param {boolean} allow_empty
715
+ * @returns {Validator}
716
+ */
717
+ function string(fallback, allow_empty = true) {
718
+ return validate(fallback, (input, keypath) => {
719
+ assert_string(input, keypath);
720
+
721
+ if (!allow_empty && input === '') {
722
+ throw new Error(`${keypath} cannot be empty`);
723
+ }
724
+
725
+ return input;
726
+ });
727
+ }
728
+
729
+ /**
730
+ * @param {number} fallback
731
+ * @returns {Validator}
732
+ */
733
+ function number(fallback) {
734
+ return validate(fallback, (input, keypath) => {
735
+ if (typeof input !== 'number') {
736
+ throw new Error(`${keypath} should be a number, if specified`);
737
+ }
738
+ return input;
739
+ });
740
+ }
741
+
742
+ /**
743
+ * @param {boolean} fallback
744
+ * @returns {Validator}
745
+ */
746
+ function boolean(fallback) {
747
+ return validate(fallback, (input, keypath) => {
748
+ if (typeof input !== 'boolean') {
749
+ throw new Error(`${keypath} should be true or false, if specified`);
45
750
  }
751
+ return input;
752
+ });
753
+ }
754
+
755
+ /**
756
+ * @param {string[]} options
757
+ * @returns {Validator}
758
+ */
759
+ function list(options, fallback = options[0]) {
760
+ return validate(fallback, (input, keypath) => {
761
+ if (!options.includes(input)) {
762
+ // prettier-ignore
763
+ const msg = options.length > 2
764
+ ? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
765
+ : `${keypath} should be either "${options[0]}" or "${options[1]}"`;
766
+
767
+ throw new Error(msg);
768
+ }
769
+ return input;
770
+ });
771
+ }
46
772
 
47
- console.error(index.$.bold().red(message));
48
- console.error(index.$.grey(error.stack));
49
- process.exit(1);
773
+ /**
774
+ * @param {(filename: string) => boolean} fallback
775
+ * @returns {Validator}
776
+ */
777
+ function fun(fallback) {
778
+ return validate(fallback, (input, keypath) => {
779
+ if (typeof input !== 'function') {
780
+ throw new Error(`${keypath} should be a function, if specified`);
781
+ }
782
+ return input;
783
+ });
784
+ }
785
+
786
+ /**
787
+ * @param {string} input
788
+ * @param {string} keypath
789
+ */
790
+ function assert_string(input, keypath) {
791
+ if (typeof input !== 'string') {
792
+ throw new Error(`${keypath} should be a string, if specified`);
793
+ }
794
+ }
795
+
796
+ /**
797
+ * @param {string} cwd
798
+ * @param {import('types/config').ValidatedConfig} config
799
+ */
800
+ function load_template(cwd, config) {
801
+ const { template } = config.kit.files;
802
+ const relative = path__default.relative(cwd, template);
803
+
804
+ if (fs__default.existsSync(template)) {
805
+ const contents = fs__default.readFileSync(template, 'utf8');
806
+ const expected_tags = ['%svelte.head%', '%svelte.body%'];
807
+ expected_tags.forEach((tag) => {
808
+ if (contents.indexOf(tag) === -1) {
809
+ throw new Error(`${relative} is missing ${tag}`);
810
+ }
811
+ });
812
+ } else {
813
+ throw new Error(`${relative} does not exist`);
814
+ }
815
+
816
+ return fs__default.readFileSync(template, 'utf-8');
817
+ }
818
+
819
+ async function load_config({ cwd = process.cwd() } = {}) {
820
+ const config_file = path__default.join(cwd, 'svelte.config.js');
821
+
822
+ if (!fs__default.existsSync(config_file)) {
823
+ throw new Error(
824
+ 'You need to create a svelte.config.js file. See https://kit.svelte.dev/docs#configuration'
825
+ );
826
+ }
827
+
828
+ const config = await import(url.pathToFileURL(config_file).href);
829
+
830
+ const validated = validate_config(config.default);
831
+
832
+ validated.kit.files.assets = path__default.resolve(cwd, validated.kit.files.assets);
833
+ validated.kit.files.hooks = path__default.resolve(cwd, validated.kit.files.hooks);
834
+ validated.kit.files.lib = path__default.resolve(cwd, validated.kit.files.lib);
835
+ validated.kit.files.routes = path__default.resolve(cwd, validated.kit.files.routes);
836
+ validated.kit.files.serviceWorker = path__default.resolve(cwd, validated.kit.files.serviceWorker);
837
+ validated.kit.files.template = path__default.resolve(cwd, validated.kit.files.template);
838
+
839
+ return validated;
840
+ }
841
+
842
+ /**
843
+ * @param {import('types/config').Config} config
844
+ * @returns {import('types/config').ValidatedConfig}
845
+ */
846
+ function validate_config(config) {
847
+ if (typeof config !== 'object') {
848
+ throw new Error(
849
+ 'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs#configuration'
850
+ );
50
851
  }
852
+
853
+ return options(config, 'config');
854
+ }
855
+
856
+ /**
857
+ * @param {string[]} conflicts - array of conflicts in dotted notation
858
+ * @param {string=} pathPrefix - prepended in front of the path
859
+ * @param {string=} scope - used to prefix the whole error message
860
+ */
861
+ function print_config_conflicts(conflicts, pathPrefix = '', scope) {
862
+ const prefix = scope ? scope + ': ' : '';
863
+ const log = logger({ verbose: false });
864
+ conflicts.forEach((conflict) => {
865
+ log.error(
866
+ `${prefix}The value for ${pathPrefix}${conflict} specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.`
867
+ );
868
+ });
869
+ }
870
+
871
+ /**
872
+ * @param {unknown} err
873
+ * @return {Error}
874
+ */
875
+ function coalesce_to_error(err) {
876
+ return err instanceof Error ||
877
+ (err && /** @type {any} */ (err).name && /** @type {any} */ (err).message)
878
+ ? /** @type {Error} */ (err)
879
+ : new Error(JSON.stringify(err));
51
880
  }
52
881
 
53
- function handle_error(error) {
54
- console.log(index.$.bold().red(`> ${error.message}`));
55
- console.log(index.$.gray(error.stack));
882
+ /** @param {unknown} e */
883
+ function handle_error(e) {
884
+ const error = coalesce_to_error(e);
885
+
886
+ if (error.name === 'SyntaxError') throw error;
887
+
888
+ console.error($.bold().red(`> ${error.message}`));
889
+ if (error.stack) {
890
+ console.error($.gray(error.stack.split('\n').slice(1).join('\n')));
891
+ }
892
+
56
893
  process.exit(1);
57
894
  }
58
895
 
59
- async function launch(port) {
60
- const { exec } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('child_process')); });
61
- exec(`${process.platform == 'win32' ? 'start' : 'open'} http://localhost:${port}`);
896
+ /**
897
+ * @param {number} port
898
+ * @param {boolean} https
899
+ */
900
+ async function launch(port, https) {
901
+ const { exec } = await import('child_process');
902
+ let cmd = 'open';
903
+ if (process.platform == 'win32') {
904
+ cmd = 'start';
905
+ } else if (process.platform == 'linux') {
906
+ if (/microsoft/i.test(release())) {
907
+ cmd = 'cmd.exe /c start';
908
+ } else {
909
+ cmd = 'xdg-open';
910
+ }
911
+ }
912
+ exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
62
913
  }
63
914
 
64
- const prog = sade__default['default']('svelte').version(version);
915
+ const prog = sade('svelte-kit').version('1.0.0-next.230');
65
916
 
66
917
  prog
67
918
  .command('dev')
68
919
  .describe('Start a development server')
69
- .option('-p, --port', 'Port', 3000)
70
- .option('-o, --open', 'Open a browser tab', false)
71
- .action(async ({ port, open }) => {
72
- process.env.NODE_ENV = 'development';
73
- const config = get_config();
920
+ .option('-p, --port', 'Port')
921
+ .option('-h, --host', 'Host (only use this on trusted networks)')
922
+ .option('-H, --https', 'Use self-signed HTTPS certificate')
923
+ .option('-o, --open', 'Open a browser tab')
924
+ .action(async ({ port, host, https, open }) => {
925
+ try {
926
+ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
927
+ const config = await load_config();
74
928
 
75
- const { dev } = await Promise.resolve().then(function () { return require('./index2.js'); });
929
+ const { dev } = await import('./chunks/index.js');
76
930
 
77
- try {
78
- const watcher = await dev({ port, config });
931
+ const cwd = process.cwd();
79
932
 
80
- watcher.on('stdout', (data) => {
81
- process.stdout.write(data);
933
+ const { address_info, server_config } = await dev({
934
+ cwd,
935
+ port,
936
+ host,
937
+ https,
938
+ config
82
939
  });
83
940
 
84
- watcher.on('stderr', (data) => {
85
- process.stderr.write(data);
941
+ welcome({
942
+ port: address_info.port,
943
+ host: address_info.address,
944
+ https: !!(https || server_config.https),
945
+ open: open || !!server_config.open,
946
+ loose: server_config.fs.strict === false,
947
+ allow: server_config.fs.allow,
948
+ cwd
86
949
  });
87
-
88
- console.log(index.$.bold().cyan(`> Listening on http://localhost:${watcher.port}`));
89
- if (open) launch(watcher.port);
90
950
  } catch (error) {
91
951
  handle_error(error);
92
952
  }
@@ -95,55 +955,150 @@ prog
95
955
  prog
96
956
  .command('build')
97
957
  .describe('Create a production build of your app')
98
- .action(async () => {
99
- process.env.NODE_ENV = 'production';
100
- const config = get_config();
958
+ .option('--verbose', 'Log more stuff', false)
959
+ .action(async ({ verbose }) => {
960
+ try {
961
+ process.env.NODE_ENV = process.env.NODE_ENV || 'production';
962
+ const config = await load_config();
101
963
 
102
- const { build } = await Promise.resolve().then(function () { return require('./index3.js'); });
964
+ const { build } = await import('./chunks/index3.js');
965
+ const build_data = await build(config);
103
966
 
104
- try {
105
- await build(config);
967
+ console.log(
968
+ `\nRun ${$.bold().cyan('npm run preview')} to preview your production build locally.`
969
+ );
970
+
971
+ if (config.kit.adapter) {
972
+ const { adapt } = await import('./chunks/index5.js');
973
+ await adapt(config, build_data, { verbose });
974
+
975
+ // this is necessary to close any open db connections, etc
976
+ process.exit(0);
977
+ }
978
+
979
+ console.log($.bold().yellow('\nNo adapter specified'));
980
+
981
+ // prettier-ignore
982
+ console.log(
983
+ `See ${$.bold().cyan('https://kit.svelte.dev/docs#adapters')} to learn how to configure your app to run on the platform of your choosing`
984
+ );
106
985
  } catch (error) {
107
986
  handle_error(error);
108
987
  }
109
988
  });
110
989
 
111
990
  prog
112
- .command('start')
991
+ .command('preview')
113
992
  .describe('Serve an already-built app')
114
993
  .option('-p, --port', 'Port', 3000)
994
+ .option('-h, --host', 'Host (only use this on trusted networks)', 'localhost')
995
+ .option('-H, --https', 'Use self-signed HTTPS certificate', false)
115
996
  .option('-o, --open', 'Open a browser tab', false)
116
- .action(async ({ port, open }) => {
117
- process.env.NODE_ENV = 'production';
118
- const config = get_config();
997
+ .action(async ({ port, host, https, open }) => {
998
+ try {
999
+ await check_port(port);
119
1000
 
120
- const { start } = await Promise.resolve().then(function () { return require('./index4.js'); });
1001
+ process.env.NODE_ENV = process.env.NODE_ENV || 'production';
1002
+ const config = await load_config();
121
1003
 
122
- try {
123
- await start({ port, config });
1004
+ const { preview } = await import('./chunks/index6.js');
1005
+
1006
+ await preview({ port, host, config, https });
124
1007
 
125
- console.log(index.$.bold().cyan(`> Listening on http://localhost:${port}`));
126
- if (open) if (open) launch(port);
1008
+ welcome({ port, host, https, open });
127
1009
  } catch (error) {
128
1010
  handle_error(error);
129
1011
  }
130
1012
  });
131
1013
 
132
1014
  prog
133
- .command('adapt')
134
- .describe('Customise your production build for different platforms')
1015
+ .command('package')
1016
+ .describe('Create a package')
1017
+ .option('-d, --dir', 'Destination directory', 'package')
135
1018
  .action(async () => {
136
- process.env.NODE_ENV = 'production';
137
- const config = get_config();
1019
+ try {
1020
+ const config = await load_config();
138
1021
 
139
- const { adapt } = await Promise.resolve().then(function () { return require('./index6.js'); });
1022
+ const { make_package } = await import('./chunks/index7.js');
140
1023
 
141
- try {
142
- await adapt(config);
1024
+ await make_package(config);
143
1025
  } catch (error) {
144
1026
  handle_error(error);
145
1027
  }
146
1028
  });
147
1029
 
148
1030
  prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
149
- //# sourceMappingURL=cli.js.map
1031
+
1032
+ /** @param {number} port */
1033
+ async function check_port(port) {
1034
+ if (await check(port)) {
1035
+ return;
1036
+ }
1037
+ console.error($.bold().red(`Port ${port} is occupied`));
1038
+ const n = await blame(port);
1039
+ if (n) {
1040
+ // prettier-ignore
1041
+ console.error(
1042
+ `Terminate process ${$.bold(n)} or specify a different port with ${$.bold('--port')}\n`
1043
+ );
1044
+ } else {
1045
+ // prettier-ignore
1046
+ console.error(
1047
+ `Terminate the process occupying the port or specify a different port with ${$.bold('--port')}\n`
1048
+ );
1049
+ }
1050
+ process.exit(1);
1051
+ }
1052
+
1053
+ /**
1054
+ * @param {{
1055
+ * open: boolean;
1056
+ * host: string;
1057
+ * https: boolean;
1058
+ * port: number;
1059
+ * loose?: boolean;
1060
+ * allow?: string[];
1061
+ * cwd?: string;
1062
+ * }} param0
1063
+ */
1064
+ function welcome({ port, host, https, open, loose, allow, cwd }) {
1065
+ if (open) launch(port, https);
1066
+
1067
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.230'}\n`));
1068
+
1069
+ const protocol = https ? 'https:' : 'http:';
1070
+ const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
1071
+
1072
+ Object.values(networkInterfaces()).forEach((interfaces) => {
1073
+ if (!interfaces) return;
1074
+ interfaces.forEach((details) => {
1075
+ if (details.family !== 'IPv4') return;
1076
+
1077
+ // prettier-ignore
1078
+ if (details.internal) {
1079
+ console.log(` ${$.gray('local: ')} ${protocol}//${$.bold(`localhost:${port}`)}`);
1080
+ } else {
1081
+ if (details.mac === '00:00:00:00:00:00') return;
1082
+
1083
+ if (exposed) {
1084
+ console.log(` ${$.gray('network:')} ${protocol}//${$.bold(`${details.address}:${port}`)}`);
1085
+ if (loose) {
1086
+ console.log(`\n ${$.yellow('Serving with vite.server.fs.strict: false. Note that all files on your machine will be accessible to anyone on your network.')}`);
1087
+ } else if (allow?.length && cwd) {
1088
+ console.log(`\n ${$.yellow('Note that all files in the following directories will be accessible to anyone on your network: ' + allow.map(a => relative(cwd, a)).join(', '))}`);
1089
+ }
1090
+ } else {
1091
+ console.log(` ${$.gray('network: not exposed')}`);
1092
+ }
1093
+ }
1094
+ });
1095
+ });
1096
+
1097
+ if (!exposed) {
1098
+ console.log('\n Use --host to expose server to other devices on this network');
1099
+ }
1100
+
1101
+ console.log('\n');
1102
+ }
1103
+
1104
+ export { $, SVELTE_KIT as S, runtime as a, SVELTE_KIT_ASSETS as b, coalesce_to_error as c, copy_assets as d, get_aliases as e, posixify as f, get_mime_lookup as g, rimraf as h, copy as i, logger as j, load_template as l, mkdirp as m, print_config_conflicts as p, resolve_entry as r, walk as w };