@sveltejs/kit 1.0.0-next.21 → 1.0.0-next.213

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