@sveltejs/kit 1.0.0-next.217 → 1.0.0-next.220

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.
@@ -486,10 +486,6 @@ function create_manifest_data({ config, output, cwd = process.cwd() }) {
486
486
  throw new Error(`Invalid route ${file} — brackets are unbalanced`);
487
487
  }
488
488
 
489
- if (/.+\[\.\.\.[^\]]+\]/.test(segment) || /\[\.\.\.[^\]]+\].+/.test(segment)) {
490
- throw new Error(`Invalid route ${file} — rest parameter must be a standalone segment`);
491
- }
492
-
493
489
  const parts = get_parts(segment, file);
494
490
  const is_index = is_dir ? false : basename.startsWith('index.');
495
491
  const is_page = config.extensions.indexOf(ext) !== -1;
@@ -750,31 +746,37 @@ function get_parts(part, file) {
750
746
  function get_pattern(segments, add_trailing_slash) {
751
747
  const path = segments
752
748
  .map((segment) => {
753
- return segment[0].rest
754
- ? '(?:\\/(.*))?'
755
- : '\\/' +
756
- segment
757
- .map((part) => {
758
- return part.dynamic
759
- ? '([^/]+?)'
760
- : // allow users to specify characters on the file system in an encoded manner
761
- part.content
762
- .normalize()
763
- // We use [ and ] to denote parameters, so users must encode these on the file
764
- // system to match against them. We don't decode all characters since others
765
- // can already be epressed and so that '%' can be easily used directly in filenames
766
- .replace(/%5[Bb]/g, '[')
767
- .replace(/%5[Dd]/g, ']')
768
- // '#', '/', and '?' can only appear in URL path segments in an encoded manner.
769
- // They will not be touched by decodeURI so need to be encoded here, so
770
- // that we can match against them.
771
- // We skip '/' since you can't create a file with it on any OS
772
- .replace(/#/g, '%23')
773
- .replace(/\?/g, '%3F')
774
- // escape characters that have special meaning in regex
775
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
776
- })
777
- .join('');
749
+ if (segment.length === 1 && segment[0].rest) {
750
+ // special case — `src/routes/foo/[...bar]/baz` matches `/foo/baz`
751
+ // so we need to make the leading slash optional
752
+ return '(?:\\/(.*))?';
753
+ }
754
+
755
+ const parts = segment.map((part) => {
756
+ if (part.rest) return '(.*?)';
757
+ if (part.dynamic) return '([^/]+?)';
758
+
759
+ return (
760
+ part.content
761
+ // allow users to specify characters on the file system in an encoded manner
762
+ .normalize()
763
+ // We use [ and ] to denote parameters, so users must encode these on the file
764
+ // system to match against them. We don't decode all characters since others
765
+ // can already be epressed and so that '%' can be easily used directly in filenames
766
+ .replace(/%5[Bb]/g, '[')
767
+ .replace(/%5[Dd]/g, ']')
768
+ // '#', '/', and '?' can only appear in URL path segments in an encoded manner.
769
+ // They will not be touched by decodeURI so need to be encoded here, so
770
+ // that we can match against them.
771
+ // We skip '/' since you can't create a file with it on any OS
772
+ .replace(/#/g, '%23')
773
+ .replace(/\?/g, '%3F')
774
+ // escape characters that have special meaning in regex
775
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
776
+ );
777
+ });
778
+
779
+ return '\\/' + parts.join('');
778
780
  })
779
781
  .join('');
780
782
 
@@ -262,9 +262,10 @@ import { set_paths, assets, base } from './runtime/paths.js';
262
262
  import { set_prerendering } from './runtime/env.js';
263
263
  import * as user_hooks from ${s(hooks)};
264
264
 
265
- const template = ({ head, body }) => ${s(load_template(cwd, config))
265
+ const template = ({ head, body, assets }) => ${s(load_template(cwd, config))
266
266
  .replace('%svelte.head%', '" + head + "')
267
- .replace('%svelte.body%', '" + body + "')};
267
+ .replace('%svelte.body%', '" + body + "')
268
+ .replace(/%svelte\.assets%/g, '" + assets + "')};
268
269
 
269
270
  let read = null;
270
271
 
@@ -371,7 +371,12 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
371
371
  if (element === 'a' || element === 'link') {
372
372
  if (is_rel_external(attrs)) continue;
373
373
 
374
- hrefs.push(get_href(attrs));
374
+ let href = get_href(attrs);
375
+ if (!href) continue;
376
+
377
+ const i = href.indexOf('#');
378
+ href = i < 0 ? href : href.substring(0, i);
379
+ hrefs.push(href);
375
380
  } else {
376
381
  if (element === 'img') {
377
382
  hrefs.push(get_src(attrs));
@@ -470,6 +475,8 @@ function create_builder({ cwd, config, build_data, log }) {
470
475
  mkdirp,
471
476
  copy,
472
477
 
478
+ appDir: config.kit.appDir,
479
+
473
480
  createEntries(fn) {
474
481
  generated_manifest = true;
475
482
 
@@ -1,9 +1,9 @@
1
1
  import * as fs from 'fs';
2
2
  import fs__default, { readdirSync, statSync } from 'fs';
3
- import require$$2 from 'http';
4
- import require$$3 from 'https';
3
+ import http from 'http';
4
+ import https from 'https';
5
5
  import { resolve, join, normalize } from 'path';
6
- import * as require$$7 from 'querystring';
6
+ import * as qs from 'querystring';
7
7
  import { pathToFileURL } from 'url';
8
8
  import { getRawBody } from '../node.js';
9
9
  import { __fetch_polyfill } from '../install-fetch.js';
@@ -16,6 +16,19 @@ import 'node:util';
16
16
  import 'node:url';
17
17
  import 'net';
18
18
 
19
+ function totalist(dir, callback, pre='') {
20
+ dir = resolve('.', dir);
21
+ let arr = readdirSync(dir);
22
+ let i=0, abs, stats;
23
+ for (; i < arr.length; i++) {
24
+ abs = join(dir, arr[i]);
25
+ stats = statSync(abs);
26
+ stats.isDirectory()
27
+ ? totalist(abs, callback, join(pre, arr[i]))
28
+ : callback(join(pre, arr[i]), abs, stats);
29
+ }
30
+ }
31
+
19
32
  /**
20
33
  * @typedef ParsedURL
21
34
  * @type {import('.').ParsedURL}
@@ -47,7 +60,7 @@ function parse(req) {
47
60
  search = raw.substring(idx);
48
61
  pathname = raw.substring(0, idx);
49
62
  if (search.length > 1) {
50
- query = require$$7.parse(search.substring(1));
63
+ query = qs.parse(search.substring(1));
51
64
  }
52
65
  }
53
66
  }
@@ -55,19 +68,6 @@ function parse(req) {
55
68
  return req._parsedUrl = { pathname, search, query, raw };
56
69
  }
57
70
 
58
- function list(dir, callback, pre='') {
59
- dir = resolve('.', dir);
60
- let arr = readdirSync(dir);
61
- let i=0, abs, stats;
62
- for (; i < arr.length; i++) {
63
- abs = join(dir, arr[i]);
64
- stats = statSync(abs);
65
- stats.isDirectory()
66
- ? list(abs, callback, join(pre, arr[i]))
67
- : callback(join(pre, arr[i]), abs, stats);
68
- }
69
- }
70
-
71
71
  const mimes = {
72
72
  "ez": "application/andrew-inset",
73
73
  "aw": "application/applixware",
@@ -625,7 +625,7 @@ function sirv (dir, opts={}) {
625
625
  else if (cc && opts.maxAge === 0) cc += ',must-revalidate';
626
626
 
627
627
  if (!opts.dev) {
628
- list(dir, (name, abs, stats) => {
628
+ totalist(dir, (name, abs, stats) => {
629
629
  if (/\.well-known[\\+\/]/.test(name)) ; // keep
630
630
  else if (!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)) return;
631
631
 
@@ -819,8 +819,8 @@ async function get_server(use_https, user_config, handler) {
819
819
 
820
820
  return Promise.resolve(
821
821
  use_https
822
- ? require$$3.createServer(/** @type {https.ServerOptions} */ (https_options), handler)
823
- : require$$2.createServer(handler)
822
+ ? https.createServer(/** @type {https.ServerOptions} */ (https_options), handler)
823
+ : http.createServer(handler)
824
824
  );
825
825
  }
826
826