@sveltejs/kit 1.0.0-next.175 → 1.0.0-next.179

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.
@@ -412,7 +412,7 @@ function page_store(value) {
412
412
  function initial_fetch(resource, opts) {
413
413
  const url = typeof resource === 'string' ? resource : resource.url;
414
414
 
415
- let selector = `script[data-type="svelte-data"][data-url="${url}"]`;
415
+ let selector = `script[data-type="svelte-data"][data-url=${JSON.stringify(url)}]`;
416
416
 
417
417
  if (opts && typeof opts.body === 'string') {
418
418
  selector += `[data-body="${hash(opts.body)}"]`;
@@ -776,9 +776,11 @@ class Renderer {
776
776
  */
777
777
  async _get_navigation_result_from_branch({ page, branch }) {
778
778
  const filtered = /** @type {import('./types').BranchNode[] } */ (branch.filter(Boolean));
779
+ const redirect = filtered.find((f) => f.loaded && f.loaded.redirect);
779
780
 
780
781
  /** @type {import('./types').NavigationResult} */
781
782
  const result = {
783
+ redirect: redirect && redirect.loaded ? redirect.loaded.redirect : undefined,
782
784
  state: {
783
785
  page,
784
786
  branch,
@@ -4278,7 +4278,8 @@ class Watcher extends EventEmitter {
4278
4278
  server: {
4279
4279
  fs: {
4280
4280
  strict: true
4281
- }
4281
+ },
4282
+ strictPort: true
4282
4283
  }
4283
4284
  };
4284
4285
 
@@ -4294,7 +4295,7 @@ class Watcher extends EventEmitter {
4294
4295
  });
4295
4296
 
4296
4297
  /** @type {[any, string[]]} */
4297
- const [merged_config, conflicts] = deep_merge(modified_vite_config, {
4298
+ let [merged_config, conflicts] = deep_merge(modified_vite_config, {
4298
4299
  configFile: false,
4299
4300
  root: this.cwd,
4300
4301
  resolve: {
@@ -4321,15 +4322,21 @@ class Watcher extends EventEmitter {
4321
4322
  kit_plugin
4322
4323
  ],
4323
4324
  publicDir: this.config.kit.files.assets,
4324
- server: {
4325
- host: this.host,
4326
- https: this.https
4327
- },
4328
4325
  base: this.config.kit.paths.assets.startsWith('/') ? `${this.config.kit.paths.assets}/` : '/'
4329
4326
  });
4330
4327
 
4331
4328
  print_config_conflicts(conflicts, 'kit.vite.');
4332
4329
 
4330
+ // optional config from command-line flags
4331
+ // these should take precedence, but not print conflict warnings
4332
+ [merged_config] = deep_merge(merged_config, {
4333
+ server: {
4334
+ host: this.host,
4335
+ https: this.https,
4336
+ port: this.port
4337
+ }
4338
+ });
4339
+
4333
4340
  this.vite = await vite.createServer(merged_config);
4334
4341
  remove_html_middlewares(this.vite.middlewares);
4335
4342
  await this.vite.listen(this.port);
package/dist/cli.js CHANGED
@@ -817,18 +817,16 @@ async function launch(port, https) {
817
817
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
818
818
  }
819
819
 
820
- const prog = sade('svelte-kit').version('1.0.0-next.175');
820
+ const prog = sade('svelte-kit').version('1.0.0-next.179');
821
821
 
822
822
  prog
823
823
  .command('dev')
824
824
  .describe('Start a development server')
825
- .option('-p, --port', 'Port', 3000)
826
- .option('-h, --host', 'Host (only use this on trusted networks)', 'localhost')
827
- .option('-H, --https', 'Use self-signed HTTPS certificate', false)
828
- .option('-o, --open', 'Open a browser tab', false)
825
+ .option('-p, --port', 'Port')
826
+ .option('-h, --host', 'Host (only use this on trusted networks)')
827
+ .option('-H, --https', 'Use self-signed HTTPS certificate')
828
+ .option('-o, --open', 'Open a browser tab')
829
829
  .action(async ({ port, host, https, open }) => {
830
- await check_port(port);
831
-
832
830
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
833
831
  const config = await get_config();
834
832
 
@@ -845,7 +843,15 @@ prog
845
843
  process.stderr.write(data);
846
844
  });
847
845
 
848
- welcome({ port, host, https, open });
846
+ if (!watcher.vite || !watcher.vite.httpServer) {
847
+ throw Error('Could not find server');
848
+ }
849
+ // we never start the server on a socket path, so address will be of type AddressInfo
850
+ const chosen_port = /** @type {import('net').AddressInfo} */ (
851
+ watcher.vite.httpServer.address()
852
+ ).port;
853
+
854
+ welcome({ port: chosen_port, host, https, open });
849
855
  } catch (error) {
850
856
  handle_error(error);
851
857
  }
@@ -960,10 +966,10 @@ async function check_port(port) {
960
966
  function welcome({ port, host, https, open }) {
961
967
  if (open) launch(port, https);
962
968
 
963
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.175'}\n`));
969
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.179'}\n`));
964
970
 
965
971
  const protocol = https ? 'https:' : 'http:';
966
- const exposed = host !== 'localhost' && host !== '127.0.0.1';
972
+ const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
967
973
 
968
974
  Object.values(networkInterfaces()).forEach((interfaces) => {
969
975
  if (!interfaces) return;
package/dist/ssr.js CHANGED
@@ -106,7 +106,7 @@ async function render_endpoint(request, route, match) {
106
106
  var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
107
107
  var unsafeChars = /[<>\b\f\n\r\t\0\u2028\u2029]/g;
108
108
  var reserved = /^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
109
- var escaped$1 = {
109
+ var escaped = {
110
110
  '<': '\\u003C',
111
111
  '>': '\\u003E',
112
112
  '/': '\\u002F',
@@ -287,7 +287,7 @@ function getType(thing) {
287
287
  return Object.prototype.toString.call(thing).slice(8, -1);
288
288
  }
289
289
  function escapeUnsafeChar(c) {
290
- return escaped$1[c] || c;
290
+ return escaped[c] || c;
291
291
  }
292
292
  function escapeUnsafeChars(str) {
293
293
  return str.replace(unsafeChars, escapeUnsafeChar);
@@ -306,8 +306,8 @@ function stringifyString(str) {
306
306
  if (char === '"') {
307
307
  result += '\\"';
308
308
  }
309
- else if (char in escaped$1) {
310
- result += escaped$1[char];
309
+ else if (char in escaped) {
310
+ result += escaped[char];
311
311
  }
312
312
  else if (code >= 0xd800 && code <= 0xdfff) {
313
313
  var next = str.charCodeAt(i + 1);
@@ -399,6 +399,85 @@ function hash(value) {
399
399
  return (hash >>> 0).toString(36);
400
400
  }
401
401
 
402
+ /** @type {Record<string, string>} */
403
+ const escape_json_string_in_html_dict = {
404
+ '"': '\\"',
405
+ '<': '\\u003C',
406
+ '>': '\\u003E',
407
+ '/': '\\u002F',
408
+ '\\': '\\\\',
409
+ '\b': '\\b',
410
+ '\f': '\\f',
411
+ '\n': '\\n',
412
+ '\r': '\\r',
413
+ '\t': '\\t',
414
+ '\0': '\\0',
415
+ '\u2028': '\\u2028',
416
+ '\u2029': '\\u2029'
417
+ };
418
+
419
+ /** @param {string} str */
420
+ function escape_json_string_in_html(str) {
421
+ return escape(
422
+ str,
423
+ escape_json_string_in_html_dict,
424
+ (code) => `\\u${code.toString(16).toUpperCase()}`
425
+ );
426
+ }
427
+
428
+ /** @type {Record<string, string>} */
429
+ const escape_html_attr_dict = {
430
+ '<': '&lt;',
431
+ '>': '&gt;',
432
+ '"': '&quot;'
433
+ };
434
+
435
+ /**
436
+ * use for escaping string values to be used html attributes on the page
437
+ * e.g.
438
+ * <script data-url="here">
439
+ *
440
+ * @param {string} str
441
+ * @returns string escaped string
442
+ */
443
+ function escape_html_attr(str) {
444
+ return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
445
+ }
446
+
447
+ /**
448
+ *
449
+ * @param str {string} string to escape
450
+ * @param dict {Record<string, string>} dictionary of character replacements
451
+ * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
452
+ * @returns {string}
453
+ */
454
+ function escape(str, dict, unicode_encoder) {
455
+ let result = '';
456
+
457
+ for (let i = 0; i < str.length; i += 1) {
458
+ const char = str.charAt(i);
459
+ const code = char.charCodeAt(0);
460
+
461
+ if (char in dict) {
462
+ result += dict[char];
463
+ } else if (code >= 0xd800 && code <= 0xdfff) {
464
+ const next = str.charCodeAt(i + 1);
465
+
466
+ // If this is the beginning of a [high, low] surrogate pair,
467
+ // add the next two characters, otherwise escape
468
+ if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
469
+ result += char + str[++i];
470
+ } else {
471
+ result += unicode_encoder(code);
472
+ }
473
+ } else {
474
+ result += char;
475
+ }
476
+ }
477
+
478
+ return result;
479
+ }
480
+
402
481
  const s$1 = JSON.stringify;
403
482
 
404
483
  // TODO rename this function/module
@@ -564,7 +643,9 @@ async function render_response({
564
643
 
565
644
  ${serialized_data
566
645
  .map(({ url, body, json }) => {
567
- let attributes = `type="application/json" data-type="svelte-data" data-url="${url}"`;
646
+ let attributes = `type="application/json" data-type="svelte-data" data-url=${escape_html_attr(
647
+ url
648
+ )}`;
568
649
  if (body) attributes += ` data-body="${hash(body)}"`;
569
650
 
570
651
  return `<script ${attributes}>${json}</script>`;
@@ -921,7 +1002,7 @@ async function load_node({
921
1002
  fetched.push({
922
1003
  url,
923
1004
  body: /** @type {string} */ (opts.body),
924
- json: `{"status":${response.status},"statusText":${s(response.statusText)},"headers":${s(headers)},"body":${escape(body)}}`
1005
+ json: `{"status":${response.status},"statusText":${s(response.statusText)},"headers":${s(headers)},"body":"${escape_json_string_in_html(body)}"}`
925
1006
  });
926
1007
  }
927
1008
 
@@ -985,53 +1066,6 @@ async function load_node({
985
1066
  };
986
1067
  }
987
1068
 
988
- /** @type {Record<string, string>} */
989
- const escaped = {
990
- '<': '\\u003C',
991
- '>': '\\u003E',
992
- '/': '\\u002F',
993
- '\\': '\\\\',
994
- '\b': '\\b',
995
- '\f': '\\f',
996
- '\n': '\\n',
997
- '\r': '\\r',
998
- '\t': '\\t',
999
- '\0': '\\0',
1000
- '\u2028': '\\u2028',
1001
- '\u2029': '\\u2029'
1002
- };
1003
-
1004
- /** @param {string} str */
1005
- function escape(str) {
1006
- let result = '"';
1007
-
1008
- for (let i = 0; i < str.length; i += 1) {
1009
- const char = str.charAt(i);
1010
- const code = char.charCodeAt(0);
1011
-
1012
- if (char === '"') {
1013
- result += '\\"';
1014
- } else if (char in escaped) {
1015
- result += escaped[char];
1016
- } else if (code >= 0xd800 && code <= 0xdfff) {
1017
- const next = str.charCodeAt(i + 1);
1018
-
1019
- // If this is the beginning of a [high, low] surrogate pair,
1020
- // add the next two characters, otherwise escape
1021
- if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
1022
- result += char + str[++i];
1023
- } else {
1024
- result += `\\u${code.toString(16).toUpperCase()}`;
1025
- }
1026
- } else {
1027
- result += char;
1028
- }
1029
- }
1030
-
1031
- result += '"';
1032
- return result;
1033
- }
1034
-
1035
1069
  const absolute = /^([a-z]+:)?\/?\//;
1036
1070
 
1037
1071
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.175",
3
+ "version": "1.0.0-next.179",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -9,10 +9,10 @@
9
9
  "homepage": "https://kit.svelte.dev",
10
10
  "type": "module",
11
11
  "dependencies": {
12
- "@sveltejs/vite-plugin-svelte": "^1.0.0-next.24",
12
+ "@sveltejs/vite-plugin-svelte": "^1.0.0-next.26",
13
13
  "cheap-watch": "^1.0.4",
14
14
  "sade": "^1.7.4",
15
- "vite": "^2.5.7"
15
+ "vite": "^2.6.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@rollup/plugin-replace": "^3.0.0",