@sveltejs/kit 1.0.0-next.29 → 1.0.0-next.292

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