@sveltejs/kit 1.0.0-next.250 → 1.0.0-next.254

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.
@@ -1,7 +1,7 @@
1
1
  import fs__default from 'fs';
2
2
  import path__default from 'path';
3
3
  import { s } from './misc.js';
4
- import { m as mkdirp, b as runtime, f as posixify } from '../cli.js';
4
+ import { m as mkdirp, r as runtime, f as posixify } from '../cli.js';
5
5
 
6
6
  /**
7
7
  * Takes zero or more objects and returns a new object that has all the values
@@ -1,6 +1,6 @@
1
1
  import fs__default from 'fs';
2
2
  import path__default from 'path';
3
- import { p as print_config_conflicts, a as SVELTE_KIT, d as copy_assets, f as posixify, e as get_aliases, r as resolve_entry, l as load_template, b as runtime, m as mkdirp, h as rimraf } from '../cli.js';
3
+ import { p as print_config_conflicts, b as SVELTE_KIT, d as copy_assets, f as posixify, e as get_aliases, a as resolve_entry, l as load_template, r as runtime, m as mkdirp, h as rimraf } from '../cli.js';
4
4
  import { d as deep_merge, a as create_app, c as create_manifest_data } from './index2.js';
5
5
  import { g as generate_manifest } from './index4.js';
6
6
  import vite from 'vite';
@@ -63,7 +63,7 @@ async function build_service_worker(
63
63
  );
64
64
 
65
65
  /** @type {[any, string[]]} */
66
- const [merged_config, conflicts] = deep_merge(config.kit.vite(), {
66
+ const [merged_config, conflicts] = deep_merge(await config.kit.vite(), {
67
67
  configFile: false,
68
68
  root: cwd,
69
69
  base: assets_base,
@@ -151,6 +151,10 @@ async function build_client({
151
151
  output_dir,
152
152
  client_entry_file
153
153
  }) {
154
+ process.env.VITE_SVELTEKIT_APP_VERSION = config.kit.version.name;
155
+ process.env.VITE_SVELTEKIT_APP_VERSION_FILE = `${config.kit.appDir}/version.json`;
156
+ process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = `${config.kit.version.pollInterval}`;
157
+
154
158
  create_app({
155
159
  manifest_data,
156
160
  output: `${SVELTE_KIT}/generated`,
@@ -182,7 +186,7 @@ async function build_client({
182
186
  });
183
187
 
184
188
  /** @type {[any, string[]]} */
185
- const [merged_config, conflicts] = deep_merge(config.kit.vite(), {
189
+ const [merged_config, conflicts] = deep_merge(await config.kit.vite(), {
186
190
  configFile: false,
187
191
  root: cwd,
188
192
  base: assets_base,
@@ -227,6 +231,11 @@ async function build_client({
227
231
  const entry_css = new Set();
228
232
  find_deps(entry, vite_manifest, entry_js, entry_css);
229
233
 
234
+ fs__default.writeFileSync(
235
+ `${client_out_dir}/version.json`,
236
+ JSON.stringify({ version: process.env.VITE_SVELTEKIT_APP_VERSION })
237
+ );
238
+
230
239
  return {
231
240
  assets,
232
241
  chunks,
@@ -411,7 +420,7 @@ async function build_server(
411
420
  );
412
421
 
413
422
  /** @type {import('vite').UserConfig} */
414
- const vite_config = config.kit.vite();
423
+ const vite_config = await config.kit.vite();
415
424
 
416
425
  const default_config = {
417
426
  build: {
@@ -1,9 +1,8 @@
1
- import { m as mkdirp, a as SVELTE_KIT, h as rimraf, i as copy, $, j as logger } from '../cli.js';
1
+ import { m as mkdirp, b as SVELTE_KIT, h as rimraf, i as copy, $, j as logger } from '../cli.js';
2
2
  import { readFileSync, writeFileSync } from 'fs';
3
- import { resolve, join, dirname } from 'path';
3
+ import { resolve as resolve$1, join, dirname } from 'path';
4
4
  import { pathToFileURL, URL } from 'url';
5
5
  import { __fetch_polyfill } from '../install-fetch.js';
6
- import { e as escape_html_attr, r as resolve$1, i as is_root_relative } from './url.js';
7
6
  import { g as generate_manifest } from './index4.js';
8
7
  import 'sade';
9
8
  import 'child_process';
@@ -17,6 +16,45 @@ import 'node:util';
17
16
  import 'node:url';
18
17
  import './misc.js';
19
18
 
19
+ const absolute = /^([a-z]+:)?\/?\//;
20
+ const scheme = /^[a-z]+:/;
21
+
22
+ /**
23
+ * @param {string} base
24
+ * @param {string} path
25
+ */
26
+ function resolve(base, path) {
27
+ if (scheme.test(path)) return path;
28
+
29
+ const base_match = absolute.exec(base);
30
+ const path_match = absolute.exec(path);
31
+
32
+ if (!base_match) {
33
+ throw new Error(`bad base path: "${base}"`);
34
+ }
35
+
36
+ const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
37
+ const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
38
+
39
+ baseparts.pop();
40
+
41
+ for (let i = 0; i < pathparts.length; i += 1) {
42
+ const part = pathparts[i];
43
+ if (part === '.') continue;
44
+ else if (part === '..') baseparts.pop();
45
+ else baseparts.push(part);
46
+ }
47
+
48
+ const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
49
+
50
+ return `${prefix}${baseparts.join('/')}`;
51
+ }
52
+
53
+ /** @param {string} path */
54
+ function is_root_relative(path) {
55
+ return path[0] === '/' && path[1] !== '/';
56
+ }
57
+
20
58
  /** @typedef {{
21
59
  * fn: () => Promise<any>,
22
60
  * fulfil: (value: any) => void,
@@ -291,6 +329,61 @@ function crawl(html) {
291
329
  return hrefs;
292
330
  }
293
331
 
332
+ /** @type {Record<string, string>} */
333
+
334
+ /** @type {Record<string, string>} */
335
+ const escape_html_attr_dict = {
336
+ '<': '&lt;',
337
+ '>': '&gt;',
338
+ '"': '&quot;'
339
+ };
340
+
341
+ /**
342
+ * use for escaping string values to be used html attributes on the page
343
+ * e.g.
344
+ * <script data-url="here">
345
+ *
346
+ * @param {string} str
347
+ * @returns string escaped string
348
+ */
349
+ function escape_html_attr(str) {
350
+ return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
351
+ }
352
+
353
+ /**
354
+ *
355
+ * @param str {string} string to escape
356
+ * @param dict {Record<string, string>} dictionary of character replacements
357
+ * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
358
+ * @returns {string}
359
+ */
360
+ function escape(str, dict, unicode_encoder) {
361
+ let result = '';
362
+
363
+ for (let i = 0; i < str.length; i += 1) {
364
+ const char = str.charAt(i);
365
+ const code = char.charCodeAt(0);
366
+
367
+ if (char in dict) {
368
+ result += dict[char];
369
+ } else if (code >= 0xd800 && code <= 0xdfff) {
370
+ const next = str.charCodeAt(i + 1);
371
+
372
+ // If this is the beginning of a [high, low] surrogate pair,
373
+ // add the next two characters, otherwise escape
374
+ if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
375
+ result += char + str[++i];
376
+ } else {
377
+ result += unicode_encoder(code);
378
+ }
379
+ } else {
380
+ result += char;
381
+ }
382
+ }
383
+
384
+ return result;
385
+ }
386
+
294
387
  /**
295
388
  * @typedef {import('types/config').PrerenderErrorHandler} PrerenderErrorHandler
296
389
  * @typedef {import('types/config').PrerenderOnErrorValue} OnError
@@ -342,11 +435,11 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
342
435
 
343
436
  mkdirp(out);
344
437
 
345
- const dir = resolve(cwd, `${SVELTE_KIT}/output`);
438
+ const dir = resolve$1(cwd, `${SVELTE_KIT}/output`);
346
439
 
347
440
  const seen = new Set();
348
441
 
349
- const server_root = resolve(dir);
442
+ const server_root = resolve$1(dir);
350
443
 
351
444
  /** @type {import('types/internal').AppModule} */
352
445
  const { App, override } = await import(pathToFileURL(`${server_root}/server/app.js`).href);
@@ -465,7 +558,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
465
558
  `<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
466
559
  );
467
560
 
468
- const resolved = resolve$1(path, location);
561
+ const resolved = resolve(path, location);
469
562
  if (is_root_relative(resolved)) {
470
563
  enqueue(resolved, path);
471
564
  }
@@ -520,7 +613,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
520
613
  for (const href of crawl(text)) {
521
614
  if (href.startsWith('data:') || href.startsWith('#')) continue;
522
615
 
523
- const resolved = resolve$1(path, href);
616
+ const resolved = resolve(path, href);
524
617
  if (!is_root_relative(resolved)) continue;
525
618
 
526
619
  const parsed = new URL(resolved, 'http://localhost');
@@ -6,7 +6,7 @@ import { s as sirv } from './build.js';
6
6
  import { pathToFileURL } from 'url';
7
7
  import { getRequest, setResponse } from '../node.js';
8
8
  import { __fetch_polyfill } from '../install-fetch.js';
9
- import { a as SVELTE_KIT, S as SVELTE_KIT_ASSETS } from '../cli.js';
9
+ import { b as SVELTE_KIT, S as SVELTE_KIT_ASSETS } from '../cli.js';
10
10
  import 'querystring';
11
11
  import 'stream';
12
12
  import 'node:http';
@@ -81,7 +81,7 @@ async function preview({
81
81
  const app = new App(manifest);
82
82
 
83
83
  /** @type {import('vite').UserConfig} */
84
- const vite_config = (config.kit.vite && config.kit.vite()) || {};
84
+ const vite_config = (config.kit.vite && (await config.kit.vite())) || {};
85
85
 
86
86
  const server = await get_server(use_https, vite_config, (req, res) => {
87
87
  if (req.url == null) {
package/dist/cli.js CHANGED
@@ -688,6 +688,11 @@ const options = object(
688
688
 
689
689
  trailingSlash: list(['never', 'always', 'ignore']),
690
690
 
691
+ version: object({
692
+ name: string(Date.now().toString()),
693
+ pollInterval: number(0)
694
+ }),
695
+
691
696
  vite: validate(
692
697
  () => ({}),
693
698
  (input, keypath) => {
@@ -989,7 +994,7 @@ async function launch(port, https) {
989
994
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
990
995
  }
991
996
 
992
- const prog = sade('svelte-kit').version('1.0.0-next.250');
997
+ const prog = sade('svelte-kit').version('1.0.0-next.254');
993
998
 
994
999
  prog
995
1000
  .command('dev')
@@ -1147,7 +1152,7 @@ async function check_port(port) {
1147
1152
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1148
1153
  if (open) launch(port, https);
1149
1154
 
1150
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.250'}\n`));
1155
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.254'}\n`));
1151
1156
 
1152
1157
  const protocol = https ? 'https:' : 'http:';
1153
1158
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
@@ -1184,4 +1189,4 @@ function welcome({ port, host, https, open, loose, allow, cwd }) {
1184
1189
  console.log('\n');
1185
1190
  }
1186
1191
 
1187
- export { $, SVELTE_KIT_ASSETS as S, SVELTE_KIT as a, runtime as b, coalesce_to_error as c, copy_assets as d, get_aliases as e, posixify as f, get_mime_lookup as g, rimraf as h, copy as i, logger as j, load_template as l, mkdirp as m, print_config_conflicts as p, resolve_entry as r, walk as w };
1192
+ export { $, SVELTE_KIT_ASSETS as S, resolve_entry as a, SVELTE_KIT as b, coalesce_to_error as c, copy_assets as d, get_aliases as e, posixify as f, get_mime_lookup as g, rimraf as h, copy as i, logger as j, load_template as l, mkdirp as m, print_config_conflicts as p, runtime as r, walk as w };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.250",
3
+ "version": "1.0.0-next.254",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -40,7 +40,7 @@
40
40
  "svelte": "^3.44.2",
41
41
  "svelte-check": "^2.2.10",
42
42
  "svelte-preprocess": "^4.9.8",
43
- "svelte2tsx": "~0.4.10",
43
+ "svelte2tsx": "~0.5.0",
44
44
  "tiny-glob": "^0.2.9",
45
45
  "uvu": "^0.5.2"
46
46
  },
@@ -107,16 +107,11 @@ declare module '$app/stores' {
107
107
  * Most of the time, you won't need to use it.
108
108
  */
109
109
  export function getStores<Session = any>(): {
110
- navigating: Readable<Navigating | null>;
111
- page: Readable<{
112
- url: URL;
113
- params: Record<string, string>;
114
- status: number;
115
- error: Error | null;
116
- }>;
110
+ navigating: typeof navigating;
111
+ page: typeof page;
117
112
  session: Writable<Session>;
113
+ updated: typeof updated;
118
114
  };
119
- export const url: Readable<URL>;
120
115
  /**
121
116
  * A readable store whose value contains page data.
122
117
  */
@@ -138,6 +133,11 @@ declare module '$app/stores' {
138
133
  * It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself.
139
134
  */
140
135
  export const session: Writable<any>;
136
+ /**
137
+ * A writable store indicating if the site was updated since the store was created.
138
+ * It can be written to when custom logic is required to detect updates.
139
+ */
140
+ export const updated: Readable<boolean> & { check: () => boolean };
141
141
  }
142
142
 
143
143
  declare module '$service-worker' {
package/types/config.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CompileOptions } from 'svelte/types/compiler/interfaces';
2
2
  import { UserConfig as ViteConfig } from 'vite';
3
3
  import { CspDirectives } from './csp';
4
- import { RecursiveRequired } from './helper';
4
+ import { MaybePromise, RecursiveRequired } from './helper';
5
5
  import { HttpMethod, Logger, RouteSegment, TrailingSlash } from './internal';
6
6
 
7
7
  export interface RouteDefinition {
@@ -165,7 +165,11 @@ export interface Config {
165
165
  };
166
166
  target?: string;
167
167
  trailingSlash?: TrailingSlash;
168
- vite?: ViteConfig | (() => ViteConfig);
168
+ version?: {
169
+ name?: string;
170
+ pollInterval?: number;
171
+ };
172
+ vite?: ViteConfig | (() => MaybePromise<ViteConfig>);
169
173
  };
170
174
  preprocess?: any;
171
175
  }
@@ -1,119 +0,0 @@
1
- /** @type {Record<string, string>} */
2
- const escape_json_string_in_html_dict = {
3
- '"': '\\"',
4
- '<': '\\u003C',
5
- '>': '\\u003E',
6
- '/': '\\u002F',
7
- '\\': '\\\\',
8
- '\b': '\\b',
9
- '\f': '\\f',
10
- '\n': '\\n',
11
- '\r': '\\r',
12
- '\t': '\\t',
13
- '\0': '\\0',
14
- '\u2028': '\\u2028',
15
- '\u2029': '\\u2029'
16
- };
17
-
18
- /** @param {string} str */
19
- function escape_json_string_in_html(str) {
20
- return escape(
21
- str,
22
- escape_json_string_in_html_dict,
23
- (code) => `\\u${code.toString(16).toUpperCase()}`
24
- );
25
- }
26
-
27
- /** @type {Record<string, string>} */
28
- const escape_html_attr_dict = {
29
- '<': '&lt;',
30
- '>': '&gt;',
31
- '"': '&quot;'
32
- };
33
-
34
- /**
35
- * use for escaping string values to be used html attributes on the page
36
- * e.g.
37
- * <script data-url="here">
38
- *
39
- * @param {string} str
40
- * @returns string escaped string
41
- */
42
- function escape_html_attr(str) {
43
- return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
44
- }
45
-
46
- /**
47
- *
48
- * @param str {string} string to escape
49
- * @param dict {Record<string, string>} dictionary of character replacements
50
- * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
51
- * @returns {string}
52
- */
53
- function escape(str, dict, unicode_encoder) {
54
- let result = '';
55
-
56
- for (let i = 0; i < str.length; i += 1) {
57
- const char = str.charAt(i);
58
- const code = char.charCodeAt(0);
59
-
60
- if (char in dict) {
61
- result += dict[char];
62
- } else if (code >= 0xd800 && code <= 0xdfff) {
63
- const next = str.charCodeAt(i + 1);
64
-
65
- // If this is the beginning of a [high, low] surrogate pair,
66
- // add the next two characters, otherwise escape
67
- if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
68
- result += char + str[++i];
69
- } else {
70
- result += unicode_encoder(code);
71
- }
72
- } else {
73
- result += char;
74
- }
75
- }
76
-
77
- return result;
78
- }
79
-
80
- const absolute = /^([a-z]+:)?\/?\//;
81
- const scheme = /^[a-z]+:/;
82
-
83
- /**
84
- * @param {string} base
85
- * @param {string} path
86
- */
87
- function resolve(base, path) {
88
- if (scheme.test(path)) return path;
89
-
90
- const base_match = absolute.exec(base);
91
- const path_match = absolute.exec(path);
92
-
93
- if (!base_match) {
94
- throw new Error(`bad base path: "${base}"`);
95
- }
96
-
97
- const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
98
- const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
99
-
100
- baseparts.pop();
101
-
102
- for (let i = 0; i < pathparts.length; i += 1) {
103
- const part = pathparts[i];
104
- if (part === '.') continue;
105
- else if (part === '..') baseparts.pop();
106
- else baseparts.push(part);
107
- }
108
-
109
- const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
110
-
111
- return `${prefix}${baseparts.join('/')}`;
112
- }
113
-
114
- /** @param {string} path */
115
- function is_root_relative(path) {
116
- return path[0] === '/' && path[1] !== '/';
117
- }
118
-
119
- export { escape_json_string_in_html as a, escape_html_attr as e, is_root_relative as i, resolve as r };