@sveltejs/kit 1.0.0-next.251 → 1.0.0-next.255

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: {
@@ -626,7 +635,7 @@ async function build(config) {
626
635
  const build_data = {
627
636
  app_dir: config.kit.appDir,
628
637
  manifest_data: options.manifest_data,
629
- service_worker: options.service_worker_entry_file ? 'service_worker.js' : null, // TODO make file configurable?
638
+ service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
630
639
  client,
631
640
  server,
632
641
  static: options.manifest_data.assets.map((asset) => posixify(asset.file)),
@@ -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,
@@ -123,7 +161,7 @@ function crawl(html) {
123
161
  if (html[i + 1] === '!') {
124
162
  i += 2;
125
163
 
126
- if (html.substr(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
164
+ if (html.substring(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
127
165
  i += DOCTYPE.length;
128
166
  while (i < html.length) {
129
167
  if (html[i++] === '>') {
@@ -133,10 +171,10 @@ function crawl(html) {
133
171
  }
134
172
 
135
173
  // skip cdata
136
- if (html.substr(i, CDATA_OPEN.length) === CDATA_OPEN) {
174
+ if (html.substring(i, CDATA_OPEN.length) === CDATA_OPEN) {
137
175
  i += CDATA_OPEN.length;
138
176
  while (i < html.length) {
139
- if (html.substr(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
177
+ if (html.substring(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
140
178
  i += CDATA_CLOSE.length;
141
179
  continue main;
142
180
  }
@@ -146,10 +184,10 @@ function crawl(html) {
146
184
  }
147
185
 
148
186
  // skip comments
149
- if (html.substr(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
187
+ if (html.substring(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
150
188
  i += COMMENT_OPEN.length;
151
189
  while (i < html.length) {
152
- if (html.substr(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
190
+ if (html.substring(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
153
191
  i += COMMENT_CLOSE.length;
154
192
  continue main;
155
193
  }
@@ -177,7 +215,7 @@ function crawl(html) {
177
215
  if (
178
216
  html[i] === '<' &&
179
217
  html[i + 1] === '/' &&
180
- html.substr(i + 2, tag.length).toUpperCase() === tag
218
+ html.substring(i + 2, tag.length).toUpperCase() === tag
181
219
  ) {
182
220
  continue main;
183
221
  }
@@ -273,6 +311,8 @@ function crawl(html) {
273
311
  hrefs.push(src);
274
312
  }
275
313
  }
314
+ } else {
315
+ i -= 1;
276
316
  }
277
317
  }
278
318
 
@@ -291,6 +331,61 @@ function crawl(html) {
291
331
  return hrefs;
292
332
  }
293
333
 
334
+ /** @type {Record<string, string>} */
335
+
336
+ /** @type {Record<string, string>} */
337
+ const escape_html_attr_dict = {
338
+ '<': '&lt;',
339
+ '>': '&gt;',
340
+ '"': '&quot;'
341
+ };
342
+
343
+ /**
344
+ * use for escaping string values to be used html attributes on the page
345
+ * e.g.
346
+ * <script data-url="here">
347
+ *
348
+ * @param {string} str
349
+ * @returns string escaped string
350
+ */
351
+ function escape_html_attr(str) {
352
+ return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
353
+ }
354
+
355
+ /**
356
+ *
357
+ * @param str {string} string to escape
358
+ * @param dict {Record<string, string>} dictionary of character replacements
359
+ * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
360
+ * @returns {string}
361
+ */
362
+ function escape(str, dict, unicode_encoder) {
363
+ let result = '';
364
+
365
+ for (let i = 0; i < str.length; i += 1) {
366
+ const char = str.charAt(i);
367
+ const code = char.charCodeAt(0);
368
+
369
+ if (char in dict) {
370
+ result += dict[char];
371
+ } else if (code >= 0xd800 && code <= 0xdfff) {
372
+ const next = str.charCodeAt(i + 1);
373
+
374
+ // If this is the beginning of a [high, low] surrogate pair,
375
+ // add the next two characters, otherwise escape
376
+ if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
377
+ result += char + str[++i];
378
+ } else {
379
+ result += unicode_encoder(code);
380
+ }
381
+ } else {
382
+ result += char;
383
+ }
384
+ }
385
+
386
+ return result;
387
+ }
388
+
294
389
  /**
295
390
  * @typedef {import('types/config').PrerenderErrorHandler} PrerenderErrorHandler
296
391
  * @typedef {import('types/config').PrerenderOnErrorValue} OnError
@@ -342,11 +437,11 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
342
437
 
343
438
  mkdirp(out);
344
439
 
345
- const dir = resolve(cwd, `${SVELTE_KIT}/output`);
440
+ const dir = resolve$1(cwd, `${SVELTE_KIT}/output`);
346
441
 
347
442
  const seen = new Set();
348
443
 
349
- const server_root = resolve(dir);
444
+ const server_root = resolve$1(dir);
350
445
 
351
446
  /** @type {import('types/internal').AppModule} */
352
447
  const { App, override } = await import(pathToFileURL(`${server_root}/server/app.js`).href);
@@ -465,7 +560,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
465
560
  `<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
466
561
  );
467
562
 
468
- const resolved = resolve$1(path, location);
563
+ const resolved = resolve(path, location);
469
564
  if (is_root_relative(resolved)) {
470
565
  enqueue(resolved, path);
471
566
  }
@@ -520,7 +615,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
520
615
  for (const href of crawl(text)) {
521
616
  if (href.startsWith('data:') || href.startsWith('#')) continue;
522
617
 
523
- const resolved = resolve$1(path, href);
618
+ const resolved = resolve(path, href);
524
619
  if (!is_root_relative(resolved)) continue;
525
620
 
526
621
  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.251');
997
+ const prog = sade('svelte-kit').version('1.0.0-next.255');
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.251'}\n`));
1155
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.255'}\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.251",
3
+ "version": "1.0.0-next.255",
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 };