@sveltejs/kit 1.0.0-next.43 → 1.0.0-next.430

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 (104) hide show
  1. package/README.md +12 -9
  2. package/package.json +95 -63
  3. package/src/cli.js +112 -0
  4. package/src/core/adapt/builder.js +207 -0
  5. package/src/core/adapt/index.js +19 -0
  6. package/src/core/config/index.js +86 -0
  7. package/src/core/config/options.js +488 -0
  8. package/src/core/config/types.d.ts +1 -0
  9. package/src/core/constants.js +5 -0
  10. package/src/core/env.js +97 -0
  11. package/src/core/generate_manifest/index.js +99 -0
  12. package/src/core/prerender/crawl.js +194 -0
  13. package/src/core/prerender/prerender.js +378 -0
  14. package/src/core/prerender/queue.js +80 -0
  15. package/src/core/sync/create_manifest_data/index.js +506 -0
  16. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  17. package/src/core/sync/sync.js +59 -0
  18. package/src/core/sync/utils.js +44 -0
  19. package/src/core/sync/write_ambient.js +27 -0
  20. package/src/core/sync/write_client_manifest.js +82 -0
  21. package/src/core/sync/write_matchers.js +25 -0
  22. package/src/core/sync/write_root.js +91 -0
  23. package/src/core/sync/write_tsconfig.js +195 -0
  24. package/src/core/sync/write_types.js +775 -0
  25. package/src/core/utils.js +70 -0
  26. package/src/hooks.js +26 -0
  27. package/src/index/index.js +45 -0
  28. package/src/index/private.js +33 -0
  29. package/src/node/index.js +145 -0
  30. package/src/node/polyfills.js +40 -0
  31. package/src/runtime/app/env.js +11 -0
  32. package/src/runtime/app/navigation.js +22 -0
  33. package/src/runtime/app/paths.js +1 -0
  34. package/src/runtime/app/stores.js +102 -0
  35. package/src/runtime/client/ambient.d.ts +17 -0
  36. package/src/runtime/client/client.js +1289 -0
  37. package/src/runtime/client/fetcher.js +60 -0
  38. package/src/runtime/client/parse.js +36 -0
  39. package/src/runtime/client/singletons.js +21 -0
  40. package/src/runtime/client/start.js +46 -0
  41. package/src/runtime/client/types.d.ts +105 -0
  42. package/src/runtime/client/utils.js +113 -0
  43. package/src/runtime/components/error.svelte +16 -0
  44. package/{assets → src/runtime}/components/layout.svelte +0 -0
  45. package/src/runtime/env/dynamic/private.js +1 -0
  46. package/src/runtime/env/dynamic/public.js +1 -0
  47. package/src/runtime/env-private.js +7 -0
  48. package/src/runtime/env-public.js +7 -0
  49. package/src/runtime/env.js +6 -0
  50. package/src/runtime/hash.js +16 -0
  51. package/src/runtime/paths.js +11 -0
  52. package/src/runtime/server/endpoint.js +58 -0
  53. package/src/runtime/server/index.js +448 -0
  54. package/src/runtime/server/page/cookie.js +25 -0
  55. package/src/runtime/server/page/crypto.js +239 -0
  56. package/src/runtime/server/page/csp.js +249 -0
  57. package/src/runtime/server/page/fetch.js +266 -0
  58. package/src/runtime/server/page/index.js +416 -0
  59. package/src/runtime/server/page/load_data.js +135 -0
  60. package/src/runtime/server/page/render.js +362 -0
  61. package/src/runtime/server/page/respond_with_error.js +94 -0
  62. package/src/runtime/server/page/types.d.ts +44 -0
  63. package/src/runtime/server/utils.js +116 -0
  64. package/src/utils/error.js +22 -0
  65. package/src/utils/escape.js +104 -0
  66. package/src/utils/filesystem.js +108 -0
  67. package/src/utils/http.js +55 -0
  68. package/src/utils/misc.js +1 -0
  69. package/src/utils/routing.js +108 -0
  70. package/src/utils/url.js +97 -0
  71. package/src/vite/build/build_server.js +337 -0
  72. package/src/vite/build/build_service_worker.js +90 -0
  73. package/src/vite/build/utils.js +160 -0
  74. package/src/vite/dev/index.js +551 -0
  75. package/src/vite/index.js +574 -0
  76. package/src/vite/preview/index.js +186 -0
  77. package/src/vite/types.d.ts +3 -0
  78. package/src/vite/utils.js +345 -0
  79. package/svelte-kit.js +1 -1
  80. package/types/ambient.d.ts +357 -0
  81. package/types/index.d.ts +343 -0
  82. package/types/internal.d.ts +308 -0
  83. package/types/private.d.ts +209 -0
  84. package/CHANGELOG.md +0 -431
  85. package/assets/components/error.svelte +0 -13
  86. package/assets/runtime/app/env.js +0 -5
  87. package/assets/runtime/app/navigation.js +0 -41
  88. package/assets/runtime/app/paths.js +0 -1
  89. package/assets/runtime/app/stores.js +0 -93
  90. package/assets/runtime/chunks/utils.js +0 -19
  91. package/assets/runtime/internal/singletons.js +0 -23
  92. package/assets/runtime/internal/start.js +0 -770
  93. package/assets/runtime/paths.js +0 -12
  94. package/dist/.DS_Store +0 -0
  95. package/dist/chunks/index.js +0 -3521
  96. package/dist/chunks/index2.js +0 -587
  97. package/dist/chunks/index3.js +0 -246
  98. package/dist/chunks/index4.js +0 -538
  99. package/dist/chunks/index5.js +0 -761
  100. package/dist/chunks/index6.js +0 -322
  101. package/dist/chunks/standard.js +0 -99
  102. package/dist/chunks/utils.js +0 -83
  103. package/dist/cli.js +0 -546
  104. package/dist/ssr.js +0 -2581
package/dist/cli.js DELETED
@@ -1,546 +0,0 @@
1
- import { existsSync } from 'fs';
2
- import sade from 'sade';
3
- import { pathToFileURL, resolve as resolve$1 } from 'url';
4
- import path from 'path';
5
-
6
- let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
7
- if (typeof process !== 'undefined') {
8
- ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env);
9
- isTTY = process.stdout && process.stdout.isTTY;
10
- }
11
-
12
- const $ = {
13
- enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (
14
- FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY
15
- ),
16
-
17
- // modifiers
18
- reset: init(0, 0),
19
- bold: init(1, 22),
20
- dim: init(2, 22),
21
- italic: init(3, 23),
22
- underline: init(4, 24),
23
- inverse: init(7, 27),
24
- hidden: init(8, 28),
25
- strikethrough: init(9, 29),
26
-
27
- // colors
28
- black: init(30, 39),
29
- red: init(31, 39),
30
- green: init(32, 39),
31
- yellow: init(33, 39),
32
- blue: init(34, 39),
33
- magenta: init(35, 39),
34
- cyan: init(36, 39),
35
- white: init(37, 39),
36
- gray: init(90, 39),
37
- grey: init(90, 39),
38
-
39
- // background colors
40
- bgBlack: init(40, 49),
41
- bgRed: init(41, 49),
42
- bgGreen: init(42, 49),
43
- bgYellow: init(43, 49),
44
- bgBlue: init(44, 49),
45
- bgMagenta: init(45, 49),
46
- bgCyan: init(46, 49),
47
- bgWhite: init(47, 49)
48
- };
49
-
50
- function run(arr, str) {
51
- let i=0, tmp, beg='', end='';
52
- for (; i < arr.length; i++) {
53
- tmp = arr[i];
54
- beg += tmp.open;
55
- end += tmp.close;
56
- if (!!~str.indexOf(tmp.close)) {
57
- str = str.replace(tmp.rgx, tmp.close + tmp.open);
58
- }
59
- }
60
- return beg + str + end;
61
- }
62
-
63
- function chain(has, keys) {
64
- let ctx = { has, keys };
65
-
66
- ctx.reset = $.reset.bind(ctx);
67
- ctx.bold = $.bold.bind(ctx);
68
- ctx.dim = $.dim.bind(ctx);
69
- ctx.italic = $.italic.bind(ctx);
70
- ctx.underline = $.underline.bind(ctx);
71
- ctx.inverse = $.inverse.bind(ctx);
72
- ctx.hidden = $.hidden.bind(ctx);
73
- ctx.strikethrough = $.strikethrough.bind(ctx);
74
-
75
- ctx.black = $.black.bind(ctx);
76
- ctx.red = $.red.bind(ctx);
77
- ctx.green = $.green.bind(ctx);
78
- ctx.yellow = $.yellow.bind(ctx);
79
- ctx.blue = $.blue.bind(ctx);
80
- ctx.magenta = $.magenta.bind(ctx);
81
- ctx.cyan = $.cyan.bind(ctx);
82
- ctx.white = $.white.bind(ctx);
83
- ctx.gray = $.gray.bind(ctx);
84
- ctx.grey = $.grey.bind(ctx);
85
-
86
- ctx.bgBlack = $.bgBlack.bind(ctx);
87
- ctx.bgRed = $.bgRed.bind(ctx);
88
- ctx.bgGreen = $.bgGreen.bind(ctx);
89
- ctx.bgYellow = $.bgYellow.bind(ctx);
90
- ctx.bgBlue = $.bgBlue.bind(ctx);
91
- ctx.bgMagenta = $.bgMagenta.bind(ctx);
92
- ctx.bgCyan = $.bgCyan.bind(ctx);
93
- ctx.bgWhite = $.bgWhite.bind(ctx);
94
-
95
- return ctx;
96
- }
97
-
98
- function init(open, close) {
99
- let blk = {
100
- open: `\x1b[${open}m`,
101
- close: `\x1b[${close}m`,
102
- rgx: new RegExp(`\\x1b\\[${close}m`, 'g')
103
- };
104
- return function (txt) {
105
- if (this !== void 0 && this.has !== void 0) {
106
- !!~this.has.indexOf(open) || (this.has.push(open),this.keys.push(blk));
107
- return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+'';
108
- }
109
- return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+'';
110
- };
111
- }
112
-
113
- const noop = () => {};
114
-
115
- /** @typedef {import('./types').ConfigDefinition} ConfigDefinition */
116
-
117
- /** @type {Record<string, ConfigDefinition>} */
118
- const options = {
119
- compilerOptions: {
120
- type: 'leaf',
121
- default: null,
122
- validate: noop
123
- },
124
-
125
- extensions: {
126
- type: 'leaf',
127
- default: ['.svelte'],
128
- validate: (option, keypath) => {
129
- if (!Array.isArray(option) || !option.every((page) => typeof page === 'string')) {
130
- throw new Error(`${keypath} must be an array of strings`);
131
- }
132
-
133
- option.forEach((extension) => {
134
- if (extension[0] !== '.') {
135
- throw new Error(`Each member of ${keypath} must start with '.' — saw '${extension}'`);
136
- }
137
-
138
- if (!/^(\.[a-z0-9]+)+$/i.test(extension)) {
139
- throw new Error(`File extensions must be alphanumeric — saw '${extension}'`);
140
- }
141
- });
142
-
143
- return option;
144
- }
145
- },
146
-
147
- kit: {
148
- type: 'branch',
149
- children: {
150
- adapter: {
151
- type: 'leaf',
152
- default: [null],
153
- validate: (option, keypath) => {
154
- // support both `adapter: 'foo'` and `adapter: ['foo', opts]`
155
- if (!Array.isArray(option)) {
156
- option = [option];
157
- }
158
-
159
- // TODO allow inline functions
160
- assert_is_string(option[0], keypath);
161
-
162
- return option;
163
- }
164
- },
165
-
166
- amp: expect_boolean(false),
167
-
168
- appDir: expect_string('_app', false),
169
-
170
- files: {
171
- type: 'branch',
172
- children: {
173
- assets: expect_string('static'),
174
- routes: expect_string('src/routes'),
175
- serviceWorker: expect_string('src/service-worker'),
176
- setup: expect_string('src/setup'),
177
- template: expect_string('src/app.html')
178
- }
179
- },
180
-
181
- host: expect_string(null),
182
-
183
- hostHeader: expect_string(null),
184
-
185
- paths: {
186
- type: 'branch',
187
- children: {
188
- base: expect_string(''),
189
- assets: expect_string('')
190
- }
191
- },
192
-
193
- prerender: {
194
- type: 'branch',
195
- children: {
196
- crawl: expect_boolean(true),
197
- enabled: expect_boolean(true),
198
- force: expect_boolean(false),
199
- pages: {
200
- type: 'leaf',
201
- default: ['*'],
202
- validate: (option, keypath) => {
203
- if (!Array.isArray(option) || !option.every((page) => typeof page === 'string')) {
204
- throw new Error(`${keypath} must be an array of strings`);
205
- }
206
-
207
- option.forEach((page) => {
208
- if (page !== '*' && page[0] !== '/') {
209
- throw new Error(
210
- `Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
211
- );
212
- }
213
- });
214
-
215
- return option;
216
- }
217
- }
218
- }
219
- },
220
-
221
- // used for testing
222
- startGlobal: expect_string(null),
223
-
224
- target: expect_string(null)
225
- }
226
- },
227
-
228
- preprocess: {
229
- type: 'leaf',
230
- default: null,
231
- validate: noop
232
- }
233
- };
234
-
235
- /**
236
- * @param {string} string
237
- * @param {boolean} allow_empty
238
- * @returns {ConfigDefinition}
239
- */
240
- function expect_string(string, allow_empty = true) {
241
- return {
242
- type: 'leaf',
243
- default: string,
244
- validate: (option, keypath) => {
245
- assert_is_string(option, keypath);
246
- if (!allow_empty && option === '') {
247
- throw new Error(`${keypath} cannot be empty`);
248
- }
249
- return option;
250
- }
251
- };
252
- }
253
-
254
- /**
255
- * @param {boolean} boolean
256
- * @returns {ConfigDefinition}
257
- */
258
- function expect_boolean(boolean) {
259
- return {
260
- type: 'leaf',
261
- default: boolean,
262
- validate: (option, keypath) => {
263
- if (typeof option !== 'boolean') {
264
- throw new Error(`${keypath} should be true or false, if specified`);
265
- }
266
- return option;
267
- }
268
- };
269
- }
270
-
271
- /**
272
- * @param {any} option
273
- * @param {string} keypath
274
- */
275
- function assert_is_string(option, keypath) {
276
- if (typeof option !== 'string') {
277
- throw new Error(`${keypath} should be a string, if specified`);
278
- }
279
- }
280
-
281
- /** @typedef {import('./types').ConfigDefinition} ConfigDefinition */
282
-
283
- /**
284
- * @param {Record<string, ConfigDefinition>} definition
285
- * @param {any} option
286
- * @param {string} keypath
287
- * @returns {any}
288
- */
289
- function validate(definition, option, keypath) {
290
- for (const key in option) {
291
- if (!(key in definition)) {
292
- let message = `Unexpected option ${keypath}.${key}`;
293
-
294
- if (keypath === 'config' && key in options.kit) {
295
- message += ` (did you mean config.kit.${key}?)`;
296
- } else if (keypath === 'config.kit' && key in options) {
297
- message += ` (did you mean config.${key}?)`;
298
- }
299
-
300
- throw new Error(message);
301
- }
302
- }
303
-
304
- /** @type {Record<string, any>} */
305
- const merged = {};
306
-
307
- for (const key in definition) {
308
- const expected = definition[key];
309
- const actual = option[key];
310
-
311
- const child_keypath = `${keypath}.${key}`;
312
-
313
- if (key in option) {
314
- if (expected.type === 'branch') {
315
- if (actual && (typeof actual !== 'object' || Array.isArray(actual))) {
316
- throw new Error(`${keypath}.${key} should be an object`);
317
- }
318
-
319
- merged[key] = validate(expected.children, actual, child_keypath);
320
- } else {
321
- merged[key] = expected.validate(actual, child_keypath);
322
- }
323
- } else {
324
- merged[key] =
325
- expected.type === 'branch'
326
- ? validate(expected.children, {}, child_keypath)
327
- : expected.default;
328
- }
329
- }
330
-
331
- return merged;
332
- }
333
-
334
- /**
335
- * @param {string} from
336
- * @param {string} to
337
- */
338
- function resolve(from, to) {
339
- // the `/.` is weird, but allows `${assets}/images/blah.jpg` to work
340
- // when `assets` is empty
341
- return remove_trailing_slash(resolve$1(add_trailing_slash(from), to)) || '/.';
342
- }
343
-
344
- /**
345
- * @param {string} str
346
- */
347
- function add_trailing_slash(str) {
348
- return str.endsWith('/') ? str : `${str}/`;
349
- }
350
-
351
- /**
352
- * @param {string} str
353
- */
354
- function remove_trailing_slash(str) {
355
- return str.endsWith('/') ? str.slice(0, -1) : str;
356
- }
357
-
358
- async function load_config({ cwd = process.cwd() } = {}) {
359
- const config_file = path.join(cwd, 'svelte.config.cjs');
360
- const config = await import(pathToFileURL(config_file).href);
361
- const validated = validate_config(config.default);
362
-
363
- validated.kit.files.assets = path.resolve(cwd, validated.kit.files.assets);
364
- validated.kit.files.routes = path.resolve(cwd, validated.kit.files.routes);
365
- validated.kit.files.serviceWorker = path.resolve(cwd, validated.kit.files.serviceWorker);
366
- validated.kit.files.setup = path.resolve(cwd, validated.kit.files.setup);
367
- validated.kit.files.template = path.resolve(cwd, validated.kit.files.template);
368
-
369
- // TODO check all the `files` exist when the config is loaded?
370
- // TODO check that `target` is present in the provided template
371
-
372
- return validated;
373
- }
374
-
375
- /**
376
- * @param {import('../../../types').Config} config
377
- * @returns {import('../../types.js').ValidatedConfig}
378
- */
379
- function validate_config(config) {
380
- /** @type {import('../../types.js').ValidatedConfig} */
381
- const validated = validate(options, config, 'config');
382
-
383
- // resolve paths
384
- const { paths } = validated.kit;
385
-
386
- if (paths.base !== '' && !paths.base.startsWith('/')) {
387
- throw new Error('config.kit.paths.base must be a root-relative path');
388
- }
389
-
390
- paths.assets = resolve(paths.base, paths.assets);
391
-
392
- return validated;
393
- }
394
-
395
- async function get_config() {
396
- // TODO this is temporary, for the benefit of early adopters
397
- if (existsSync('snowpack.config.js') || existsSync('snowpack.config.cjs')) {
398
- // prettier-ignore
399
- console.error($.bold().red(
400
- 'SvelteKit now uses https://vitejs.dev. Please replace snowpack.config.js with vite.config.js:'
401
- ));
402
-
403
- // prettier-ignore
404
- console.error(`
405
- import { resolve } from 'path';
406
-
407
- export default {
408
- resolve: {
409
- alias: {
410
- $components: resolve('src/components')
411
- }
412
- }
413
- };
414
- `.replace(/^\t{3}/gm, '').replace(/\t/gm, ' ').trim());
415
- }
416
-
417
- try {
418
- return await load_config();
419
- } catch (error) {
420
- let message = error.message;
421
-
422
- if (error.code === 'MODULE_NOT_FOUND') {
423
- if (existsSync('svelte.config.js')) {
424
- // TODO this is temporary, for the benefit of early adopters
425
- message =
426
- 'You must rename svelte.config.js to svelte.config.cjs, and snowpack.config.js to snowpack.config.cjs';
427
- } else {
428
- message = 'Missing svelte.config.cjs';
429
- }
430
- } else if (error.name === 'SyntaxError') {
431
- message = 'Malformed svelte.config.cjs';
432
- }
433
-
434
- console.error($.bold().red(message));
435
- console.error($.grey(error.stack));
436
- process.exit(1);
437
- }
438
- }
439
-
440
- /** @param {Error} error */
441
- function handle_error(error) {
442
- console.log($.bold().red(`> ${error.message}`));
443
- console.log($.gray(error.stack));
444
- process.exit(1);
445
- }
446
-
447
- /** @param {number} port */
448
- async function launch(port) {
449
- const { exec } = await import('child_process');
450
- exec(`${process.platform == 'win32' ? 'start' : 'open'} http://localhost:${port}`);
451
- }
452
-
453
- const prog = sade('svelte-kit').version('1.0.0-next.43');
454
-
455
- prog
456
- .command('dev')
457
- .describe('Start a development server')
458
- .option('-p, --port', 'Port', 3000)
459
- .option('-o, --open', 'Open a browser tab', false)
460
- .action(async ({ port, open }) => {
461
- process.env.NODE_ENV = 'development';
462
- const config = await get_config();
463
-
464
- const { dev } = await import('./chunks/index.js');
465
-
466
- try {
467
- const watcher = await dev({ port, config });
468
-
469
- watcher.on('stdout', (data) => {
470
- process.stdout.write(data);
471
- });
472
-
473
- watcher.on('stderr', (data) => {
474
- process.stderr.write(data);
475
- });
476
-
477
- console.log($.bold().cyan(`> Listening on http://localhost:${watcher.port}`));
478
- if (open) launch(watcher.port);
479
- } catch (error) {
480
- handle_error(error);
481
- }
482
- });
483
-
484
- prog
485
- .command('build')
486
- .describe('Create a production build of your app')
487
- .option('--verbose', 'Log more stuff', false)
488
- .action(async ({ verbose }) => {
489
- process.env.NODE_ENV = 'production';
490
- const config = await get_config();
491
-
492
- try {
493
- const { build } = await import('./chunks/index4.js');
494
- await build(config);
495
-
496
- console.log(`\nRun ${$.bold().cyan('npm start')} to try your app locally.`);
497
-
498
- if (config.kit.adapter[0]) {
499
- const { adapt } = await import('./chunks/index5.js');
500
- await adapt(config, { verbose });
501
- } else {
502
- console.log($.bold().yellow('\nNo adapter specified'));
503
-
504
- // prettier-ignore
505
- console.log(
506
- `See ${$.bold().cyan('https://kit.svelte.dev/docs#adapters')} to learn how to configure your app to run on the platform of your choosing`
507
- );
508
- }
509
- } catch (error) {
510
- handle_error(error);
511
- }
512
- });
513
-
514
- prog
515
- .command('start')
516
- .describe('Serve an already-built app')
517
- .option('-p, --port', 'Port', 3000)
518
- .option('-o, --open', 'Open a browser tab', false)
519
- .action(async ({ port, open }) => {
520
- process.env.NODE_ENV = 'production';
521
- const config = await get_config();
522
-
523
- const { start } = await import('./chunks/index6.js');
524
-
525
- try {
526
- await start({ port, config });
527
-
528
- console.log($.bold().cyan(`> Listening on http://localhost:${port}`));
529
- if (open) if (open) launch(port);
530
- } catch (error) {
531
- handle_error(error);
532
- }
533
- });
534
-
535
- // For the benefit of early-adopters. Can later be removed
536
- prog
537
- .command('adapt')
538
- .describe('Customise your production build for different platforms')
539
- .option('--verbose', 'Log more stuff', false)
540
- .action(async () => {
541
- console.log('"svelte-kit build" will now run the adapter');
542
- });
543
-
544
- prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
545
-
546
- export { $ };