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

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 +1996 -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 +19 -15
  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 +1015 -354
  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 +996 -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 +1926 -0
  32. package/package.json +96 -54
  33. package/svelte-kit.js +2 -0
  34. package/types/ambient-modules.d.ts +191 -0
  35. package/types/app.d.ts +45 -0
  36. package/types/config.d.ts +168 -0
  37. package/types/endpoint.d.ts +20 -0
  38. package/types/helper.d.ts +53 -0
  39. package/types/hooks.d.ts +55 -0
  40. package/types/index.d.ts +18 -0
  41. package/types/internal.d.ts +237 -0
  42. package/types/page.d.ts +73 -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,908 @@
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();
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);
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
+ }
38
458
 
39
- if (error.code === 'ENOENT') {
40
- message = 'Missing svelte.config.js';
41
- } else if (error.name === 'SyntaxError') {
42
- message = 'Malformed svelte.config.js';
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
+ methodOverride: object({
483
+ parameter: string('_method'),
484
+ allowed: validate([], (input, keypath) => {
485
+ if (!Array.isArray(input) || !input.every((method) => typeof method === 'string')) {
486
+ throw new Error(`${keypath} must be an array of strings`);
487
+ }
488
+
489
+ if (input.map((i) => i.toUpperCase()).includes('GET')) {
490
+ throw new Error(`${keypath} cannot contain "GET"`);
491
+ }
492
+
493
+ return input;
494
+ })
495
+ }),
496
+
497
+ package: object({
498
+ dir: string('package'),
499
+ // excludes all .d.ts and filename starting with _
500
+ exports: fun((filepath) => !/^_|\/_|\.d\.ts$/.test(filepath)),
501
+ files: fun(() => true),
502
+ emitTypes: boolean(true)
503
+ }),
504
+
505
+ paths: object({
506
+ base: validate('', (input, keypath) => {
507
+ assert_string(input, keypath);
508
+
509
+ if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
510
+ throw new Error(
511
+ `${keypath} option must be a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs#configuration-paths`
512
+ );
513
+ }
514
+
515
+ return input;
516
+ }),
517
+ assets: validate('', (input, keypath) => {
518
+ assert_string(input, keypath);
519
+
520
+ if (input) {
521
+ if (!/^[a-z]+:\/\//.test(input)) {
522
+ throw new Error(
523
+ `${keypath} option must be an absolute path, if specified. See https://kit.svelte.dev/docs#configuration-paths`
524
+ );
525
+ }
526
+
527
+ if (input.endsWith('/')) {
528
+ throw new Error(
529
+ `${keypath} option must not end with '/'. See https://kit.svelte.dev/docs#configuration-paths`
530
+ );
531
+ }
532
+ }
533
+
534
+ return input;
535
+ })
536
+ }),
537
+
538
+ prerender: object({
539
+ concurrency: number(1),
540
+ crawl: boolean(true),
541
+ enabled: boolean(true),
542
+ entries: validate(['*'], (input, keypath) => {
543
+ if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
544
+ throw new Error(`${keypath} must be an array of strings`);
545
+ }
546
+
547
+ input.forEach((page) => {
548
+ if (page !== '*' && page[0] !== '/') {
549
+ throw new Error(
550
+ `Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
551
+ );
552
+ }
553
+ });
554
+
555
+ return input;
556
+ }),
557
+ // TODO: remove this for the 1.0 release
558
+ force: validate(undefined, (input, keypath) => {
559
+ if (typeof input !== undefined) {
560
+ const newSetting = input ? 'continue' : 'fail';
561
+ const needsSetting = newSetting === 'continue';
562
+ throw new Error(
563
+ `${keypath} has been removed in favor of \`onError\`. In your case, set \`onError\` to "${newSetting}"${
564
+ needsSetting ? '' : ' (or leave it undefined)'
565
+ } to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
566
+ );
567
+ }
568
+ }),
569
+ onError: validate('fail', (input, keypath) => {
570
+ if (typeof input === 'function') return input;
571
+ if (['continue', 'fail'].includes(input)) return input;
572
+ throw new Error(
573
+ `${keypath} should be either a custom function or one of "continue" or "fail"`
574
+ );
575
+ }),
576
+ // TODO: remove this for the 1.0 release
577
+ pages: validate(undefined, (input, keypath) => {
578
+ if (typeof input !== undefined) {
579
+ throw new Error(`${keypath} has been renamed to \`entries\`.`);
580
+ }
581
+ })
582
+ }),
583
+
584
+ protocol: string(null),
585
+
586
+ router: boolean(true),
587
+
588
+ serviceWorker: object({
589
+ register: boolean(true),
590
+ files: fun((filename) => !/\.DS_STORE/.test(filename))
591
+ }),
592
+
593
+ // TODO remove this for 1.0
594
+ ssr: validate(null, (input) => {
595
+ if (input !== undefined) {
596
+ throw new Error(
597
+ 'config.kit.ssr has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'
598
+ );
599
+ }
600
+ }),
601
+
602
+ target: string(null),
603
+
604
+ trailingSlash: list(['never', 'always', 'ignore']),
605
+
606
+ vite: validate(
607
+ () => ({}),
608
+ (input, keypath) => {
609
+ if (typeof input === 'object') {
610
+ const config = input;
611
+ input = () => config;
612
+ }
613
+
614
+ if (typeof input !== 'function') {
615
+ throw new Error(
616
+ `${keypath} must be a Vite config object (https://vitejs.dev/config) or a function that returns one`
617
+ );
618
+ }
619
+
620
+ return input;
621
+ }
622
+ )
623
+ })
624
+ },
625
+ true
626
+ );
627
+
628
+ /**
629
+ * @param {Record<string, Validator>} children
630
+ * @param {boolean} [allow_unknown]
631
+ * @returns {Validator}
632
+ */
633
+ function object(children, allow_unknown = false) {
634
+ return (input, keypath) => {
635
+ /** @type {Record<string, any>} */
636
+ const output = {};
637
+
638
+ if ((input && typeof input !== 'object') || Array.isArray(input)) {
639
+ throw new Error(`${keypath} should be an object`);
640
+ }
641
+
642
+ for (const key in input) {
643
+ if (!(key in children)) {
644
+ if (allow_unknown) {
645
+ output[key] = input[key];
646
+ } else {
647
+ let message = `Unexpected option ${keypath}.${key}`;
648
+
649
+ // special case
650
+ if (keypath === 'config.kit' && key in options) {
651
+ message += ` (did you mean config.${key}?)`;
652
+ }
653
+
654
+ throw new Error(message);
655
+ }
656
+ }
657
+ }
658
+
659
+ for (const key in children) {
660
+ const validator = children[key];
661
+ output[key] = validator(input && input[key], `${keypath}.${key}`);
662
+ }
663
+
664
+ return output;
665
+ };
666
+ }
667
+
668
+ /**
669
+ * @param {any} fallback
670
+ * @param {(value: any, keypath: string) => any} fn
671
+ * @returns {Validator}
672
+ */
673
+ function validate(fallback, fn) {
674
+ return (input, keypath) => {
675
+ return input === undefined ? fallback : fn(input, keypath);
676
+ };
677
+ }
678
+
679
+ /**
680
+ * @param {string | null} fallback
681
+ * @param {boolean} allow_empty
682
+ * @returns {Validator}
683
+ */
684
+ function string(fallback, allow_empty = true) {
685
+ return validate(fallback, (input, keypath) => {
686
+ assert_string(input, keypath);
687
+
688
+ if (!allow_empty && input === '') {
689
+ throw new Error(`${keypath} cannot be empty`);
43
690
  }
44
691
 
45
- console.error(_package.$.bold().red(message));
46
- console.error(_package.$.grey(error.stack));
47
- process.exit(1);
692
+ return input;
693
+ });
694
+ }
695
+
696
+ /**
697
+ * @param {number} fallback
698
+ * @returns {Validator}
699
+ */
700
+ function number(fallback) {
701
+ return validate(fallback, (input, keypath) => {
702
+ if (typeof input !== 'number') {
703
+ throw new Error(`${keypath} should be a number, if specified`);
704
+ }
705
+ return input;
706
+ });
707
+ }
708
+
709
+ /**
710
+ * @param {boolean} fallback
711
+ * @returns {Validator}
712
+ */
713
+ function boolean(fallback) {
714
+ return validate(fallback, (input, keypath) => {
715
+ if (typeof input !== 'boolean') {
716
+ throw new Error(`${keypath} should be true or false, if specified`);
717
+ }
718
+ return input;
719
+ });
720
+ }
721
+
722
+ /**
723
+ * @param {string[]} options
724
+ * @returns {Validator}
725
+ */
726
+ function list(options, fallback = options[0]) {
727
+ return validate(fallback, (input, keypath) => {
728
+ if (!options.includes(input)) {
729
+ // prettier-ignore
730
+ const msg = options.length > 2
731
+ ? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
732
+ : `${keypath} should be either "${options[0]}" or "${options[1]}"`;
733
+
734
+ throw new Error(msg);
735
+ }
736
+ return input;
737
+ });
738
+ }
739
+
740
+ /**
741
+ * @param {(filename: string) => boolean} fallback
742
+ * @returns {Validator}
743
+ */
744
+ function fun(fallback) {
745
+ return validate(fallback, (input, keypath) => {
746
+ if (typeof input !== 'function') {
747
+ throw new Error(`${keypath} should be a function, if specified`);
748
+ }
749
+ return input;
750
+ });
751
+ }
752
+
753
+ /**
754
+ * @param {string} input
755
+ * @param {string} keypath
756
+ */
757
+ function assert_string(input, keypath) {
758
+ if (typeof input !== 'string') {
759
+ throw new Error(`${keypath} should be a string, if specified`);
760
+ }
761
+ }
762
+
763
+ /**
764
+ * @param {string} cwd
765
+ * @param {import('types/config').ValidatedConfig} config
766
+ */
767
+ function load_template(cwd, config) {
768
+ const { template } = config.kit.files;
769
+ const relative = path__default.relative(cwd, template);
770
+
771
+ if (fs__default.existsSync(template)) {
772
+ const contents = fs__default.readFileSync(template, 'utf8');
773
+ const expected_tags = ['%svelte.head%', '%svelte.body%'];
774
+ expected_tags.forEach((tag) => {
775
+ if (contents.indexOf(tag) === -1) {
776
+ throw new Error(`${relative} is missing ${tag}`);
777
+ }
778
+ });
779
+ } else {
780
+ throw new Error(`${relative} does not exist`);
48
781
  }
782
+
783
+ return fs__default.readFileSync(template, 'utf-8');
784
+ }
785
+
786
+ async function load_config({ cwd = process.cwd() } = {}) {
787
+ const config_file = path__default.join(cwd, 'svelte.config.js');
788
+
789
+ if (!fs__default.existsSync(config_file)) {
790
+ throw new Error(
791
+ 'You need to create a svelte.config.js file. See https://kit.svelte.dev/docs#configuration'
792
+ );
793
+ }
794
+
795
+ const config = await import(url.pathToFileURL(config_file).href);
796
+
797
+ const validated = validate_config(config.default);
798
+
799
+ validated.kit.files.assets = path__default.resolve(cwd, validated.kit.files.assets);
800
+ validated.kit.files.hooks = path__default.resolve(cwd, validated.kit.files.hooks);
801
+ validated.kit.files.lib = path__default.resolve(cwd, validated.kit.files.lib);
802
+ validated.kit.files.routes = path__default.resolve(cwd, validated.kit.files.routes);
803
+ validated.kit.files.serviceWorker = path__default.resolve(cwd, validated.kit.files.serviceWorker);
804
+ validated.kit.files.template = path__default.resolve(cwd, validated.kit.files.template);
805
+
806
+ return validated;
49
807
  }
50
808
 
51
- function handle_error(error) {
52
- console.log(_package.$.bold().red(`> ${error.message}`));
53
- console.log(_package.$.gray(error.stack));
809
+ /**
810
+ * @param {import('types/config').Config} config
811
+ * @returns {import('types/config').ValidatedConfig}
812
+ */
813
+ function validate_config(config) {
814
+ if (typeof config !== 'object') {
815
+ throw new Error(
816
+ 'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs#configuration'
817
+ );
818
+ }
819
+
820
+ return options(config, 'config');
821
+ }
822
+
823
+ /**
824
+ * @param {string[]} conflicts - array of conflicts in dotted notation
825
+ * @param {string=} pathPrefix - prepended in front of the path
826
+ * @param {string=} scope - used to prefix the whole error message
827
+ */
828
+ function print_config_conflicts(conflicts, pathPrefix = '', scope) {
829
+ const prefix = scope ? scope + ': ' : '';
830
+ const log = logger({ verbose: false });
831
+ conflicts.forEach((conflict) => {
832
+ log.error(
833
+ `${prefix}The value for ${pathPrefix}${conflict} specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.`
834
+ );
835
+ });
836
+ }
837
+
838
+ /** @param {unknown} e */
839
+ function handle_error(e) {
840
+ const error = coalesce_to_error(e);
841
+
842
+ if (error.name === 'SyntaxError') throw error;
843
+
844
+ console.log($.bold().red(`> ${error.message}`));
845
+ if (error.stack) {
846
+ console.log($.gray(error.stack.split('\n').slice(1).join('\n')));
847
+ }
848
+
54
849
  process.exit(1);
55
850
  }
56
851
 
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}`);
852
+ /**
853
+ * @param {number} port
854
+ * @param {boolean} https
855
+ */
856
+ async function launch(port, https) {
857
+ const { exec } = await import('child_process');
858
+ let cmd = 'open';
859
+ if (process.platform == 'win32') {
860
+ cmd = 'start';
861
+ } else if (process.platform == 'linux') {
862
+ if (/microsoft/i.test(release())) {
863
+ cmd = 'cmd.exe /c start';
864
+ } else {
865
+ cmd = 'xdg-open';
866
+ }
867
+ }
868
+ exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
60
869
  }
61
870
 
62
- const prog = sade__default['default']('svelte').version(_package.version);
871
+ const prog = sade('svelte-kit').version('1.0.0-next.223');
63
872
 
64
873
  prog
65
874
  .command('dev')
66
875
  .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();
876
+ .option('-p, --port', 'Port')
877
+ .option('-h, --host', 'Host (only use this on trusted networks)')
878
+ .option('-H, --https', 'Use self-signed HTTPS certificate')
879
+ .option('-o, --open', 'Open a browser tab')
880
+ .action(async ({ port, host, https, open }) => {
881
+ try {
882
+ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
883
+ const config = await load_config();
72
884
 
73
- const { dev } = await Promise.resolve().then(function () { return require('./index.js'); });
885
+ const { dev } = await import('./chunks/index.js');
74
886
 
75
- try {
76
- const watcher = await dev({ port, config });
887
+ const cwd = process.cwd();
77
888
 
78
- watcher.on('stdout', (data) => {
79
- process.stdout.write(data);
889
+ const { address_info, server_config } = await dev({
890
+ cwd,
891
+ port,
892
+ host,
893
+ https,
894
+ config
80
895
  });
81
896
 
82
- watcher.on('stderr', (data) => {
83
- process.stderr.write(data);
897
+ welcome({
898
+ port: address_info.port,
899
+ host: address_info.address,
900
+ https: !!(https || server_config.https),
901
+ open: open || !!server_config.open,
902
+ loose: server_config.fs.strict === false,
903
+ allow: server_config.fs.allow,
904
+ cwd
84
905
  });
85
-
86
- console.log(_package.$.bold().cyan(`> Listening on http://localhost:${watcher.port}`));
87
- if (open) launch(watcher.port);
88
906
  } catch (error) {
89
907
  handle_error(error);
90
908
  }
@@ -93,55 +911,150 @@ prog
93
911
  prog
94
912
  .command('build')
95
913
  .describe('Create a production build of your app')
96
- .action(async () => {
97
- process.env.NODE_ENV = 'production';
98
- const config = get_config();
914
+ .option('--verbose', 'Log more stuff', false)
915
+ .action(async ({ verbose }) => {
916
+ try {
917
+ process.env.NODE_ENV = process.env.NODE_ENV || 'production';
918
+ const config = await load_config();
99
919
 
100
- const { build } = await Promise.resolve().then(function () { return require('./index2.js'); });
920
+ const { build } = await import('./chunks/index3.js');
921
+ const build_data = await build(config);
101
922
 
102
- try {
103
- await build(config);
923
+ console.log(
924
+ `\nRun ${$.bold().cyan('npm run preview')} to preview your production build locally.`
925
+ );
926
+
927
+ if (config.kit.adapter) {
928
+ const { adapt } = await import('./chunks/index5.js');
929
+ await adapt(config, build_data, { verbose });
930
+
931
+ // this is necessary to close any open db connections, etc
932
+ process.exit(0);
933
+ }
934
+
935
+ console.log($.bold().yellow('\nNo adapter specified'));
936
+
937
+ // prettier-ignore
938
+ console.log(
939
+ `See ${$.bold().cyan('https://kit.svelte.dev/docs#adapters')} to learn how to configure your app to run on the platform of your choosing`
940
+ );
104
941
  } catch (error) {
105
942
  handle_error(error);
106
943
  }
107
944
  });
108
945
 
109
946
  prog
110
- .command('start')
947
+ .command('preview')
111
948
  .describe('Serve an already-built app')
112
949
  .option('-p, --port', 'Port', 3000)
950
+ .option('-h, --host', 'Host (only use this on trusted networks)', 'localhost')
951
+ .option('-H, --https', 'Use self-signed HTTPS certificate', false)
113
952
  .option('-o, --open', 'Open a browser tab', false)
114
- .action(async ({ port, open }) => {
115
- process.env.NODE_ENV = 'production';
116
- const config = get_config();
953
+ .action(async ({ port, host, https, open }) => {
954
+ try {
955
+ await check_port(port);
117
956
 
118
- const { start } = await Promise.resolve().then(function () { return require('./index3.js'); });
957
+ process.env.NODE_ENV = process.env.NODE_ENV || 'production';
958
+ const config = await load_config();
119
959
 
120
- try {
121
- await start({ port, config });
960
+ const { preview } = await import('./chunks/index6.js');
122
961
 
123
- console.log(_package.$.bold().cyan(`> Listening on http://localhost:${port}`));
124
- if (open) if (open) launch(port);
962
+ await preview({ port, host, config, https });
963
+
964
+ welcome({ port, host, https, open });
125
965
  } catch (error) {
126
966
  handle_error(error);
127
967
  }
128
968
  });
129
969
 
130
970
  prog
131
- .command('adapt')
132
- .describe('Customise your production build for different platforms')
971
+ .command('package')
972
+ .describe('Create a package')
973
+ .option('-d, --dir', 'Destination directory', 'package')
133
974
  .action(async () => {
134
- process.env.NODE_ENV = 'production';
135
- const config = get_config();
975
+ try {
976
+ const config = await load_config();
136
977
 
137
- const { adapt } = await Promise.resolve().then(function () { return require('./index5.js'); });
978
+ const { make_package } = await import('./chunks/index7.js');
138
979
 
139
- try {
140
- await adapt(config);
980
+ await make_package(config);
141
981
  } catch (error) {
142
982
  handle_error(error);
143
983
  }
144
984
  });
145
985
 
146
986
  prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
147
- //# sourceMappingURL=cli.js.map
987
+
988
+ /** @param {number} port */
989
+ async function check_port(port) {
990
+ if (await check(port)) {
991
+ return;
992
+ }
993
+ console.log($.bold().red(`Port ${port} is occupied`));
994
+ const n = await blame(port);
995
+ if (n) {
996
+ // prettier-ignore
997
+ console.log(
998
+ `Terminate process ${$.bold(n)} or specify a different port with ${$.bold('--port')}\n`
999
+ );
1000
+ } else {
1001
+ // prettier-ignore
1002
+ console.log(
1003
+ `Terminate the process occupying the port or specify a different port with ${$.bold('--port')}\n`
1004
+ );
1005
+ }
1006
+ process.exit(1);
1007
+ }
1008
+
1009
+ /**
1010
+ * @param {{
1011
+ * open: boolean;
1012
+ * host: string;
1013
+ * https: boolean;
1014
+ * port: number;
1015
+ * loose?: boolean;
1016
+ * allow?: string[];
1017
+ * cwd?: string;
1018
+ * }} param0
1019
+ */
1020
+ function welcome({ port, host, https, open, loose, allow, cwd }) {
1021
+ if (open) launch(port, https);
1022
+
1023
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.223'}\n`));
1024
+
1025
+ const protocol = https ? 'https:' : 'http:';
1026
+ const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
1027
+
1028
+ Object.values(networkInterfaces()).forEach((interfaces) => {
1029
+ if (!interfaces) return;
1030
+ interfaces.forEach((details) => {
1031
+ if (details.family !== 'IPv4') return;
1032
+
1033
+ // prettier-ignore
1034
+ if (details.internal) {
1035
+ console.log(` ${$.gray('local: ')} ${protocol}//${$.bold(`localhost:${port}`)}`);
1036
+ } else {
1037
+ if (details.mac === '00:00:00:00:00:00') return;
1038
+
1039
+ if (exposed) {
1040
+ console.log(` ${$.gray('network:')} ${protocol}//${$.bold(`${details.address}:${port}`)}`);
1041
+ if (loose) {
1042
+ 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.')}`);
1043
+ } else if (allow?.length && cwd) {
1044
+ 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(', '))}`);
1045
+ }
1046
+ } else {
1047
+ console.log(` ${$.gray('network: not exposed')}`);
1048
+ }
1049
+ }
1050
+ });
1051
+ });
1052
+
1053
+ if (!exposed) {
1054
+ console.log('\n Use --host to expose server to other devices on this network');
1055
+ }
1056
+
1057
+ console.log('\n');
1058
+ }
1059
+
1060
+ 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 };