@sveltejs/kit 1.0.0-next.195 → 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,23 +658,35 @@ class Renderer {
656
658
  this._init(navigation_result);
657
659
  }
658
660
 
659
- if (!opts) {
660
- await 0;
661
- } else {
661
+ // opts must be passed if we're navigating...
662
+ if (opts) {
662
663
  const { hash, scroll, keepfocus } = opts;
663
664
 
664
665
  if (!keepfocus) {
666
+ getSelection()?.removeAllRanges();
665
667
  document.body.focus();
666
668
  }
667
669
 
668
- const oldPageYOffset = pageYOffset;
670
+ const old_page_y_offset = Math.round(pageYOffset);
671
+ const old_max_page_y_offset = document.documentElement.scrollHeight - innerHeight;
672
+
669
673
  await 0;
670
- const maxPageYOffset = document.body.scrollHeight - innerHeight;
674
+
675
+ const new_page_y_offset = Math.round(pageYOffset);
676
+ const new_max_page_y_offset = document.documentElement.scrollHeight - innerHeight;
671
677
 
672
678
  // After `await 0`, the `onMount()` function in the component executed.
673
- // If there was no scrolling happening (checked via `pageYOffset`),
674
- // continue on our custom scroll handling
675
- if (pageYOffset === Math.min(oldPageYOffset, maxPageYOffset)) {
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) {
676
690
  const deep_linked = hash && document.getElementById(hash.slice(1));
677
691
  if (scroll) {
678
692
  scrollTo(scroll.x, scroll.y);
@@ -685,6 +699,9 @@ class Renderer {
685
699
  scrollTo(0, 0);
686
700
  }
687
701
  }
702
+ } else {
703
+ // ...they will not be supplied if we're simply invalidating
704
+ await 0;
688
705
  }
689
706
 
690
707
  this.loading.promise = null;
@@ -2,6 +2,7 @@
2
2
  * @param {Record<string, string | string[]>} headers
3
3
  * @param {string} key
4
4
  * @returns {string | undefined}
5
+ * @throws {Error}
5
6
  */
6
7
  function get_single_valued_header(headers, key) {
7
8
  const value = headers[key];
@@ -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.195');
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.195'}\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
@@ -587,6 +587,9 @@ async function render_response({
587
587
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
588
588
  <noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
589
589
  <script async src="https://cdn.ampproject.org/v0.js"></script>`;
590
+ init += options.service_worker
591
+ ? '<script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>'
592
+ : '';
590
593
  } else if (include_js) {
591
594
  // prettier-ignore
592
595
  init = `<script type="module">
@@ -625,7 +628,9 @@ async function render_response({
625
628
  }
626
629
 
627
630
  if (options.service_worker) {
628
- init += `<script>
631
+ init += options.amp
632
+ ? `<amp-install-serviceworker src="${options.service_worker}" layout="nodisplay"></amp-install-serviceworker>`
633
+ : `<script>
629
634
  if ('serviceWorker' in navigator) {
630
635
  navigator.serviceWorker.register('${options.service_worker}');
631
636
  }
@@ -1747,9 +1752,15 @@ async function respond(incoming, options, state = {}) {
1747
1752
  if (response.status === 200) {
1748
1753
  const cache_control = get_single_valued_header(response.headers, 'cache-control');
1749
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
+
1750
1761
  const etag = `"${hash(response.body || '')}"`;
1751
1762
 
1752
- if (request.headers['if-none-match'] === etag) {
1763
+ if (if_none_match_value === etag) {
1753
1764
  return {
1754
1765
  status: 304,
1755
1766
  headers: {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.195",
3
+ "version": "1.0.0-next.199",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -21,7 +21,6 @@
21
21
  "@types/marked": "^3.0.1",
22
22
  "@types/mime": "^2.0.3",
23
23
  "@types/node": "^16.10.3",
24
- "@types/rimraf": "^3.0.2",
25
24
  "@types/sade": "^1.7.3",
26
25
  "amphtml-validator": "^1.0.35",
27
26
  "cookie": "^0.4.1",
@@ -33,7 +32,6 @@
33
32
  "mime": "^2.5.2",
34
33
  "node-fetch": "^3.0.0",
35
34
  "port-authority": "^1.1.2",
36
- "rimraf": "^3.0.2",
37
35
  "rollup": "^2.58.0",
38
36
  "selfsigned": "^1.10.11",
39
37
  "sirv": "^1.0.17",