@sveltejs/kit 1.0.0-next.22 → 1.0.0-next.220

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 (82) hide show
  1. package/README.md +12 -9
  2. package/assets/components/error.svelte +19 -3
  3. package/assets/kit.js +1935 -0
  4. package/assets/runtime/app/env.js +20 -0
  5. package/assets/runtime/app/navigation.js +55 -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 +12 -9
  11. package/assets/runtime/internal/start.js +991 -356
  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 +12 -0
  16. package/dist/chunks/index.js +476 -0
  17. package/dist/chunks/index2.js +817 -0
  18. package/dist/chunks/index3.js +640 -0
  19. package/dist/chunks/index4.js +109 -0
  20. package/dist/chunks/index5.js +635 -0
  21. package/dist/chunks/index6.js +827 -0
  22. package/dist/chunks/index7.js +15575 -0
  23. package/dist/chunks/index8.js +4207 -0
  24. package/dist/chunks/misc.js +3 -0
  25. package/dist/chunks/multipart-parser.js +449 -0
  26. package/dist/chunks/url.js +62 -0
  27. package/dist/cli.js +974 -83
  28. package/dist/hooks.js +28 -0
  29. package/dist/install-fetch.js +6514 -0
  30. package/dist/node.js +51 -0
  31. package/dist/ssr.js +1865 -0
  32. package/package.json +96 -54
  33. package/svelte-kit.js +2 -0
  34. package/types/ambient-modules.d.ts +190 -0
  35. package/types/app.d.ts +45 -0
  36. package/types/config.d.ts +165 -0
  37. package/types/endpoint.d.ts +18 -0
  38. package/types/helper.d.ts +41 -0
  39. package/types/hooks.d.ts +48 -0
  40. package/types/index.d.ts +17 -0
  41. package/types/internal.d.ts +231 -0
  42. package/types/page.d.ts +71 -0
  43. package/CHANGELOG.md +0 -288
  44. package/assets/runtime/app/navigation.js.map +0 -1
  45. package/assets/runtime/app/paths.js.map +0 -1
  46. package/assets/runtime/app/stores.js.map +0 -1
  47. package/assets/runtime/internal/singletons.js.map +0 -1
  48. package/assets/runtime/internal/start.js.map +0 -1
  49. package/assets/runtime/utils-85ebcc60.js +0 -18
  50. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  51. package/dist/api.js +0 -44
  52. package/dist/api.js.map +0 -1
  53. package/dist/build.js +0 -246
  54. package/dist/build.js.map +0 -1
  55. package/dist/cli.js.map +0 -1
  56. package/dist/colors.js +0 -37
  57. package/dist/colors.js.map +0 -1
  58. package/dist/create_app.js +0 -578
  59. package/dist/create_app.js.map +0 -1
  60. package/dist/index.js +0 -12042
  61. package/dist/index.js.map +0 -1
  62. package/dist/index2.js +0 -544
  63. package/dist/index2.js.map +0 -1
  64. package/dist/index3.js +0 -71
  65. package/dist/index3.js.map +0 -1
  66. package/dist/index4.js +0 -466
  67. package/dist/index4.js.map +0 -1
  68. package/dist/index5.js +0 -729
  69. package/dist/index5.js.map +0 -1
  70. package/dist/index6.js +0 -730
  71. package/dist/index6.js.map +0 -1
  72. package/dist/logging.js +0 -43
  73. package/dist/logging.js.map +0 -1
  74. package/dist/package.js +0 -432
  75. package/dist/package.js.map +0 -1
  76. package/dist/renderer.js +0 -2391
  77. package/dist/renderer.js.map +0 -1
  78. package/dist/standard.js +0 -101
  79. package/dist/standard.js.map +0 -1
  80. package/dist/utils.js +0 -54
  81. package/dist/utils.js.map +0 -1
  82. package/svelte-kit +0 -3
package/dist/cli.js CHANGED
@@ -1,90 +1,886 @@
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
- }
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
+ import { c as coalesce_to_error } 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
+ }
26
64
  }
27
- n['default'] = e;
28
- return Object.freeze(n);
65
+ return beg + str + end;
29
66
  }
30
67
 
31
- var sade__default = /*#__PURE__*/_interopDefaultLegacy(sade);
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);
32
90
 
33
- function get_config() {
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) {
34
128
  try {
35
- return _package.load_config();
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;
36
136
  } catch (error) {
37
- let message = error.message;
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();
38
153
 
39
- if (error.code === 'ENOENT') {
40
- message = 'Missing svelte.config.js';
41
- } else if (error.name === 'SyntaxError') {
42
- message = 'Malformed svelte.config.js';
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);
43
186
  }
44
187
 
45
- console.error(_package.$.bold().red(message));
46
- console.error(_package.$.grey(error.stack));
47
- process.exit(1);
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);
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;
48
225
  }
49
226
  }
50
227
 
51
- function handle_error(error) {
52
- console.log(_package.$.bold().red(`> ${error.message}`));
53
- console.log(_package.$.gray(error.stack));
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} config
744
+ */
745
+ function load_template(cwd, config) {
746
+ const { template } = config.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}`);
755
+ }
756
+ });
757
+ } else {
758
+ throw new Error(`${relative} does not exist`);
759
+ }
760
+
761
+ return fs__default.readFileSync(template, 'utf-8');
762
+ }
763
+
764
+ async function load_config({ cwd = process.cwd() } = {}) {
765
+ const config_file = path__default.join(cwd, 'svelte.config.js');
766
+
767
+ if (!fs__default.existsSync(config_file)) {
768
+ throw new Error(
769
+ 'You need to create a svelte.config.js file. See https://kit.svelte.dev/docs#configuration'
770
+ );
771
+ }
772
+
773
+ const config = await import(url.pathToFileURL(config_file).href);
774
+
775
+ const validated = validate_config(config.default);
776
+
777
+ validated.kit.files.assets = path__default.resolve(cwd, validated.kit.files.assets);
778
+ validated.kit.files.hooks = path__default.resolve(cwd, validated.kit.files.hooks);
779
+ validated.kit.files.lib = path__default.resolve(cwd, validated.kit.files.lib);
780
+ validated.kit.files.routes = path__default.resolve(cwd, validated.kit.files.routes);
781
+ validated.kit.files.serviceWorker = path__default.resolve(cwd, validated.kit.files.serviceWorker);
782
+ validated.kit.files.template = path__default.resolve(cwd, validated.kit.files.template);
783
+
784
+ return validated;
785
+ }
786
+
787
+ /**
788
+ * @param {import('types/config').Config} config
789
+ * @returns {import('types/config').ValidatedConfig}
790
+ */
791
+ function validate_config(config) {
792
+ if (typeof config !== 'object') {
793
+ throw new Error(
794
+ 'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs#configuration'
795
+ );
796
+ }
797
+
798
+ return options(config, 'config');
799
+ }
800
+
801
+ /**
802
+ * @param {string[]} conflicts - array of conflicts in dotted notation
803
+ * @param {string=} pathPrefix - prepended in front of the path
804
+ * @param {string=} scope - used to prefix the whole error message
805
+ */
806
+ function print_config_conflicts(conflicts, pathPrefix = '', scope) {
807
+ const prefix = scope ? scope + ': ' : '';
808
+ const log = logger({ verbose: false });
809
+ conflicts.forEach((conflict) => {
810
+ log.error(
811
+ `${prefix}The value for ${pathPrefix}${conflict} specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.`
812
+ );
813
+ });
814
+ }
815
+
816
+ /** @param {unknown} e */
817
+ function handle_error(e) {
818
+ const error = coalesce_to_error(e);
819
+
820
+ if (error.name === 'SyntaxError') throw error;
821
+
822
+ console.log($.bold().red(`> ${error.message}`));
823
+ if (error.stack) {
824
+ console.log($.gray(error.stack.split('\n').slice(1).join('\n')));
825
+ }
826
+
54
827
  process.exit(1);
55
828
  }
56
829
 
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}`);
830
+ /**
831
+ * @param {number} port
832
+ * @param {boolean} https
833
+ */
834
+ async function launch(port, https) {
835
+ const { exec } = await import('child_process');
836
+ let cmd = 'open';
837
+ if (process.platform == 'win32') {
838
+ cmd = 'start';
839
+ } else if (process.platform == 'linux') {
840
+ if (/microsoft/i.test(release())) {
841
+ cmd = 'cmd.exe /c start';
842
+ } else {
843
+ cmd = 'xdg-open';
844
+ }
845
+ }
846
+ exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
60
847
  }
61
848
 
62
- const prog = sade__default['default']('svelte').version(_package.version);
849
+ const prog = sade('svelte-kit').version('1.0.0-next.220');
63
850
 
64
851
  prog
65
852
  .command('dev')
66
853
  .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();
854
+ .option('-p, --port', 'Port')
855
+ .option('-h, --host', 'Host (only use this on trusted networks)')
856
+ .option('-H, --https', 'Use self-signed HTTPS certificate')
857
+ .option('-o, --open', 'Open a browser tab')
858
+ .action(async ({ port, host, https, open }) => {
859
+ try {
860
+ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
861
+ const config = await load_config();
72
862
 
73
- const { dev } = await Promise.resolve().then(function () { return require('./index.js'); });
863
+ const { dev } = await import('./chunks/index.js');
74
864
 
75
- try {
76
- const watcher = await dev({ port, config });
865
+ const cwd = process.cwd();
77
866
 
78
- watcher.on('stdout', (data) => {
79
- process.stdout.write(data);
867
+ const { address_info, server_config } = await dev({
868
+ cwd,
869
+ port,
870
+ host,
871
+ https,
872
+ config
80
873
  });
81
874
 
82
- watcher.on('stderr', (data) => {
83
- process.stderr.write(data);
875
+ welcome({
876
+ port: address_info.port,
877
+ host: address_info.address,
878
+ https: !!(https || server_config.https),
879
+ open: open || !!server_config.open,
880
+ loose: server_config.fs.strict === false,
881
+ allow: server_config.fs.allow,
882
+ cwd
84
883
  });
85
-
86
- console.log(_package.$.bold().cyan(`> Listening on http://localhost:${watcher.port}`));
87
- if (open) launch(watcher.port);
88
884
  } catch (error) {
89
885
  handle_error(error);
90
886
  }
@@ -93,55 +889,150 @@ prog
93
889
  prog
94
890
  .command('build')
95
891
  .describe('Create a production build of your app')
96
- .action(async () => {
97
- process.env.NODE_ENV = 'production';
98
- const config = get_config();
892
+ .option('--verbose', 'Log more stuff', false)
893
+ .action(async ({ verbose }) => {
894
+ try {
895
+ process.env.NODE_ENV = process.env.NODE_ENV || 'production';
896
+ const config = await load_config();
99
897
 
100
- const { build } = await Promise.resolve().then(function () { return require('./index2.js'); });
898
+ const { build } = await import('./chunks/index3.js');
899
+ const build_data = await build(config);
101
900
 
102
- try {
103
- await build(config);
901
+ console.log(
902
+ `\nRun ${$.bold().cyan('npm run preview')} to preview your production build locally.`
903
+ );
904
+
905
+ if (config.kit.adapter) {
906
+ const { adapt } = await import('./chunks/index5.js');
907
+ await adapt(config, build_data, { verbose });
908
+
909
+ // this is necessary to close any open db connections, etc
910
+ process.exit(0);
911
+ }
912
+
913
+ console.log($.bold().yellow('\nNo adapter specified'));
914
+
915
+ // prettier-ignore
916
+ console.log(
917
+ `See ${$.bold().cyan('https://kit.svelte.dev/docs#adapters')} to learn how to configure your app to run on the platform of your choosing`
918
+ );
104
919
  } catch (error) {
105
920
  handle_error(error);
106
921
  }
107
922
  });
108
923
 
109
924
  prog
110
- .command('start')
925
+ .command('preview')
111
926
  .describe('Serve an already-built app')
112
927
  .option('-p, --port', 'Port', 3000)
928
+ .option('-h, --host', 'Host (only use this on trusted networks)', 'localhost')
929
+ .option('-H, --https', 'Use self-signed HTTPS certificate', false)
113
930
  .option('-o, --open', 'Open a browser tab', false)
114
- .action(async ({ port, open }) => {
115
- process.env.NODE_ENV = 'production';
116
- const config = get_config();
931
+ .action(async ({ port, host, https, open }) => {
932
+ try {
933
+ await check_port(port);
117
934
 
118
- const { start } = await Promise.resolve().then(function () { return require('./index3.js'); });
935
+ process.env.NODE_ENV = process.env.NODE_ENV || 'production';
936
+ const config = await load_config();
119
937
 
120
- try {
121
- await start({ port, config });
938
+ const { preview } = await import('./chunks/index6.js');
122
939
 
123
- console.log(_package.$.bold().cyan(`> Listening on http://localhost:${port}`));
124
- if (open) if (open) launch(port);
940
+ await preview({ port, host, config, https });
941
+
942
+ welcome({ port, host, https, open });
125
943
  } catch (error) {
126
944
  handle_error(error);
127
945
  }
128
946
  });
129
947
 
130
948
  prog
131
- .command('adapt')
132
- .describe('Customise your production build for different platforms')
949
+ .command('package')
950
+ .describe('Create a package')
951
+ .option('-d, --dir', 'Destination directory', 'package')
133
952
  .action(async () => {
134
- process.env.NODE_ENV = 'production';
135
- const config = get_config();
953
+ try {
954
+ const config = await load_config();
136
955
 
137
- const { adapt } = await Promise.resolve().then(function () { return require('./index5.js'); });
956
+ const { make_package } = await import('./chunks/index7.js');
138
957
 
139
- try {
140
- await adapt(config);
958
+ await make_package(config);
141
959
  } catch (error) {
142
960
  handle_error(error);
143
961
  }
144
962
  });
145
963
 
146
964
  prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
147
- //# sourceMappingURL=cli.js.map
965
+
966
+ /** @param {number} port */
967
+ async function check_port(port) {
968
+ if (await check(port)) {
969
+ return;
970
+ }
971
+ console.log($.bold().red(`Port ${port} is occupied`));
972
+ const n = await blame(port);
973
+ if (n) {
974
+ // prettier-ignore
975
+ console.log(
976
+ `Terminate process ${$.bold(n)} or specify a different port with ${$.bold('--port')}\n`
977
+ );
978
+ } else {
979
+ // prettier-ignore
980
+ console.log(
981
+ `Terminate the process occupying the port or specify a different port with ${$.bold('--port')}\n`
982
+ );
983
+ }
984
+ process.exit(1);
985
+ }
986
+
987
+ /**
988
+ * @param {{
989
+ * open: boolean;
990
+ * host: string;
991
+ * https: boolean;
992
+ * port: number;
993
+ * loose?: boolean;
994
+ * allow?: string[];
995
+ * cwd?: string;
996
+ * }} param0
997
+ */
998
+ function welcome({ port, host, https, open, loose, allow, cwd }) {
999
+ if (open) launch(port, https);
1000
+
1001
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.220'}\n`));
1002
+
1003
+ const protocol = https ? 'https:' : 'http:';
1004
+ const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
1005
+
1006
+ Object.values(networkInterfaces()).forEach((interfaces) => {
1007
+ if (!interfaces) return;
1008
+ interfaces.forEach((details) => {
1009
+ if (details.family !== 'IPv4') return;
1010
+
1011
+ // prettier-ignore
1012
+ if (details.internal) {
1013
+ console.log(` ${$.gray('local: ')} ${protocol}//${$.bold(`localhost:${port}`)}`);
1014
+ } else {
1015
+ if (details.mac === '00:00:00:00:00:00') return;
1016
+
1017
+ if (exposed) {
1018
+ console.log(` ${$.gray('network:')} ${protocol}//${$.bold(`${details.address}:${port}`)}`);
1019
+ if (loose) {
1020
+ 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.')}`);
1021
+ } else if (allow?.length && cwd) {
1022
+ 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(', '))}`);
1023
+ }
1024
+ } else {
1025
+ console.log(` ${$.gray('network: not exposed')}`);
1026
+ }
1027
+ }
1028
+ });
1029
+ });
1030
+
1031
+ if (!exposed) {
1032
+ console.log('\n Use --host to expose server to other devices on this network');
1033
+ }
1034
+
1035
+ console.log('\n');
1036
+ }
1037
+
1038
+ export { $, rimraf as a, posixify as b, copy_assets as c, copy as d, logger as e, get_mime_lookup as g, load_template as l, mkdirp as m, print_config_conflicts as p, resolve_entry as r, walk as w };