@sveltejs/kit 1.0.0-next.198 → 1.0.0-next.199

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.
@@ -13,12 +13,14 @@ function scroll_state() {
13
13
  }
14
14
 
15
15
  /**
16
- * @param {Node | null} node
17
- * @returns {HTMLAnchorElement | SVGAElement | null}
16
+ * @param {Event} event
17
+ * @returns {HTMLAnchorElement | SVGAElement | undefined}
18
18
  */
19
- function find_anchor(node) {
20
- while (node && node.nodeName.toUpperCase() !== 'A') node = node.parentNode; // SVG <a> elements have a lowercase name
21
- return /** @type {HTMLAnchorElement | SVGAElement} */ (node);
19
+ function find_anchor(event) {
20
+ const node = event
21
+ .composedPath()
22
+ .find((e) => e instanceof Node && e.nodeName.toUpperCase() === 'A'); // SVG <a> elements have a lowercase name
23
+ return /** @type {HTMLAnchorElement | SVGAElement | undefined} */ (node);
22
24
  }
23
25
 
24
26
  /**
@@ -99,7 +101,7 @@ class Router {
99
101
 
100
102
  /** @param {MouseEvent|TouchEvent} event */
101
103
  const trigger_prefetch = (event) => {
102
- const a = find_anchor(/** @type {Node} */ (event.target));
104
+ const a = find_anchor(event);
103
105
  if (a && a.href && a.hasAttribute('sveltekit:prefetch')) {
104
106
  this.prefetch(get_href(a));
105
107
  }
@@ -129,7 +131,7 @@ class Router {
129
131
  if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
130
132
  if (event.defaultPrevented) return;
131
133
 
132
- const a = find_anchor(/** @type {Node} */ (event.target));
134
+ const a = find_anchor(event);
133
135
  if (!a) return;
134
136
 
135
137
  if (!a.href) return;
@@ -656,44 +658,50 @@ class Renderer {
656
658
  this._init(navigation_result);
657
659
  }
658
660
 
659
- const { hash, scroll, keepfocus } = opts || {};
661
+ // opts must be passed if we're navigating...
662
+ if (opts) {
663
+ const { hash, scroll, keepfocus } = opts;
660
664
 
661
- if (!keepfocus) {
662
- getSelection()?.removeAllRanges();
663
- document.body.focus();
664
- }
665
+ if (!keepfocus) {
666
+ getSelection()?.removeAllRanges();
667
+ document.body.focus();
668
+ }
665
669
 
666
- const old_page_y_offset = Math.round(pageYOffset);
667
- const old_max_page_y_offset = document.documentElement.scrollHeight - innerHeight;
668
-
669
- await 0;
670
-
671
- const new_page_y_offset = Math.round(pageYOffset);
672
- const new_max_page_y_offset = document.documentElement.scrollHeight - innerHeight;
673
-
674
- // After `await 0`, the `onMount()` function in the component executed.
675
- // Check if no scrolling happened on mount.
676
- const no_scroll_happened =
677
- // In most cases, we can compare whether `pageYOffset` changed between navigation
678
- new_page_y_offset === Math.min(old_page_y_offset, new_max_page_y_offset) ||
679
- // But if the page is scrolled to/near the bottom, the browser would also scroll
680
- // to/near the bottom of the new page on navigation. Since we can't detect when this
681
- // behaviour happens, we naively compare by the y offset from the bottom of the page.
682
- old_max_page_y_offset - old_page_y_offset === new_max_page_y_offset - new_page_y_offset;
683
-
684
- // If there was no scrolling, we run on our custom scroll handling
685
- if (no_scroll_happened) {
686
- const deep_linked = hash && document.getElementById(hash.slice(1));
687
- if (scroll) {
688
- scrollTo(scroll.x, scroll.y);
689
- } else if (deep_linked) {
690
- // Here we use `scrollIntoView` on the element instead of `scrollTo`
691
- // because it natively supports the `scroll-margin` and `scroll-behavior`
692
- // CSS properties.
693
- deep_linked.scrollIntoView();
694
- } else {
695
- scrollTo(0, 0);
670
+ const old_page_y_offset = Math.round(pageYOffset);
671
+ const old_max_page_y_offset = document.documentElement.scrollHeight - innerHeight;
672
+
673
+ await 0;
674
+
675
+ const new_page_y_offset = Math.round(pageYOffset);
676
+ const new_max_page_y_offset = document.documentElement.scrollHeight - innerHeight;
677
+
678
+ // After `await 0`, the `onMount()` function in the component executed.
679
+ // Check if no scrolling happened on mount.
680
+ const no_scroll_happened =
681
+ // In most cases, we can compare whether `pageYOffset` changed between navigation
682
+ new_page_y_offset === Math.min(old_page_y_offset, new_max_page_y_offset) ||
683
+ // But if the page is scrolled to/near the bottom, the browser would also scroll
684
+ // to/near the bottom of the new page on navigation. Since we can't detect when this
685
+ // behaviour happens, we naively compare by the y offset from the bottom of the page.
686
+ old_max_page_y_offset - old_page_y_offset === new_max_page_y_offset - new_page_y_offset;
687
+
688
+ // If there was no scrolling, we run on our custom scroll handling
689
+ if (no_scroll_happened) {
690
+ const deep_linked = hash && document.getElementById(hash.slice(1));
691
+ if (scroll) {
692
+ scrollTo(scroll.x, scroll.y);
693
+ } else if (deep_linked) {
694
+ // Here we use `scrollIntoView` on the element instead of `scrollTo`
695
+ // because it natively supports the `scroll-margin` and `scroll-behavior`
696
+ // CSS properties.
697
+ deep_linked.scrollIntoView();
698
+ } else {
699
+ scrollTo(0, 0);
700
+ }
696
701
  }
702
+ } else {
703
+ // ...they will not be supplied if we're simply invalidating
704
+ await 0;
697
705
  }
698
706
 
699
707
  this.loading.promise = null;
@@ -1,7 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { createRequire } from 'module';
4
- import { r as rimraf, w as walk$1, m as mkdirp } from '../cli.js';
4
+ import { r as rimraf, w as walk$1, $, m as mkdirp } from '../cli.js';
5
5
  import 'sade';
6
6
  import 'child_process';
7
7
  import 'net';
@@ -15292,7 +15292,14 @@ async function make_package(config, cwd = process.cwd()) {
15292
15292
  if (!config.kit.package.files(normalized)) {
15293
15293
  const dts_file = (svelte_ext ? file : file.slice(0, -ext.length)) + '.d.ts';
15294
15294
  const dts_path = path.join(abs_package_dir, dts_file);
15295
- if (fs.existsSync(dts_path)) fs.unlinkSync(dts_path);
15295
+ if (fs.existsSync(dts_path)) {
15296
+ fs.unlinkSync(dts_path);
15297
+
15298
+ const dir = path.dirname(dts_path);
15299
+ if (fs.readdirSync(dir).length === 0) {
15300
+ fs.rmdirSync(dir);
15301
+ }
15302
+ }
15296
15303
  continue;
15297
15304
  }
15298
15305
 
@@ -15367,14 +15374,14 @@ async function make_package(config, cwd = process.cwd()) {
15367
15374
  console.warn(
15368
15375
  'Cannot generate a "svelte" entry point because ' +
15369
15376
  'the "." entry in "exports" is not a string. ' +
15370
- 'If you set it by hand, please also set one of the options as a "svelte" entry point'
15377
+ 'If you set it by hand, please also set one of the options as a "svelte" entry point\n'
15371
15378
  );
15372
15379
  }
15373
15380
  } else {
15374
15381
  console.warn(
15375
15382
  'Cannot generate a "svelte" entry point because ' +
15376
15383
  'the "." entry in "exports" is missing. ' +
15377
- 'Please specify one or set a "svelte" entry point yourself'
15384
+ 'Please specify one or set a "svelte" entry point yourself\n'
15378
15385
  );
15379
15386
  }
15380
15387
  }
@@ -15392,13 +15399,20 @@ async function make_package(config, cwd = process.cwd()) {
15392
15399
  const package_path = path.join(abs_package_dir, pathname);
15393
15400
  if (!fs.existsSync(package_path)) fs.copyFileSync(full_path, package_path);
15394
15401
  }
15402
+
15403
+ const from = path.relative(cwd, config.kit.files.lib);
15404
+ const to = path.relative(cwd, config.kit.package.dir);
15405
+ console.log($.bold().green(`${from} -> ${to}`));
15406
+ console.log(`Successfully built '${pkg.name}' package. To publish it to npm:`);
15407
+ console.log($.bold().cyan(` cd ${to}`));
15408
+ console.log($.bold().cyan(' npm publish\n'));
15395
15409
  }
15396
15410
 
15397
15411
  /**
15398
15412
  * Resolves the `$lib` alias.
15399
15413
  *
15400
15414
  * TODO: make this more generic to also handle other aliases the user could have defined
15401
- * via `kit.vite.resolve.alias`. Also investage how to do this in a more robust way
15415
+ * via `kit.vite.resolve.alias`. Also investigate how to do this in a more robust way
15402
15416
  * (right now regex string replacement is used).
15403
15417
  * For more discussion see https://github.com/sveltejs/kit/pull/2453
15404
15418
  *
package/dist/cli.js CHANGED
@@ -255,8 +255,12 @@ function copy(from, to, filter = () => true) {
255
255
  return files;
256
256
  }
257
257
 
258
- /** @param {string} cwd */
259
- function walk(cwd) {
258
+ /**
259
+ * Get a list of all files in a directory
260
+ * @param {string} cwd - the directory to walk
261
+ * @param {boolean} [dirs] - whether to include directories in the result
262
+ */
263
+ function walk(cwd, dirs = false) {
260
264
  /** @type {string[]} */
261
265
  const all_files = [];
262
266
 
@@ -268,6 +272,7 @@ function walk(cwd) {
268
272
  const joined = path__default.join(dir, file);
269
273
  const stats = fs__default.statSync(path__default.join(cwd, joined));
270
274
  if (stats.isDirectory()) {
275
+ if (dirs) all_files.push(joined);
271
276
  walk_dir(joined);
272
277
  } else {
273
278
  all_files.push(joined);
@@ -817,7 +822,7 @@ async function launch(port, https) {
817
822
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
818
823
  }
819
824
 
820
- const prog = sade('svelte-kit').version('1.0.0-next.198');
825
+ const prog = sade('svelte-kit').version('1.0.0-next.199');
821
826
 
822
827
  prog
823
828
  .command('dev')
@@ -982,7 +987,7 @@ async function check_port(port) {
982
987
  function welcome({ port, host, https, open, loose, allow, cwd }) {
983
988
  if (open) launch(port, https);
984
989
 
985
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.198'}\n`));
990
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.199'}\n`));
986
991
 
987
992
  const protocol = https ? 'https:' : 'http:';
988
993
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/dist/ssr.js CHANGED
@@ -1752,9 +1752,15 @@ async function respond(incoming, options, state = {}) {
1752
1752
  if (response.status === 200) {
1753
1753
  const cache_control = get_single_valued_header(response.headers, 'cache-control');
1754
1754
  if (!cache_control || !/(no-store|immutable)/.test(cache_control)) {
1755
+ let if_none_match_value = request.headers['if-none-match'];
1756
+ // ignore W/ prefix https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match#directives
1757
+ if (if_none_match_value?.startsWith('W/"')) {
1758
+ if_none_match_value = if_none_match_value.substring(2);
1759
+ }
1760
+
1755
1761
  const etag = `"${hash(response.body || '')}"`;
1756
1762
 
1757
- if (request.headers['if-none-match'] === etag) {
1763
+ if (if_none_match_value === etag) {
1758
1764
  return {
1759
1765
  status: 304,
1760
1766
  headers: {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.198",
3
+ "version": "1.0.0-next.199",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",