@sveltejs/kit 1.0.0-next.31 → 1.0.0-next.310

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