@sveltejs/kit 1.0.0-next.306 → 1.0.0-next.309

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.
@@ -269,7 +269,7 @@ function parse_route_id(id) {
269
269
  ? /^\/$/
270
270
  : new RegExp(
271
271
  `^${decodeURIComponent(id)
272
- .split(/(?:@(?:~|[a-zA-Z0-9_-]*))?(?:\/|$)/)
272
+ .split(/(?:@[a-zA-Z0-9_-]+)?(?:\/|$)/)
273
273
  .map((segment, i, segments) => {
274
274
  // special case — /[...rest]/ could contain zero segments
275
275
  const match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
@@ -1161,7 +1161,14 @@ async function render_response({
1161
1161
  stores: {
1162
1162
  page: writable(null),
1163
1163
  navigating: writable(null),
1164
- session,
1164
+ /** @type {import('svelte/store').Writable<App.Session>} */
1165
+ session: {
1166
+ ...session,
1167
+ subscribe: (fn) => {
1168
+ is_private = true;
1169
+ return session.subscribe(fn);
1170
+ }
1171
+ },
1165
1172
  updated
1166
1173
  },
1167
1174
  /** @type {import('types').Page} */
@@ -1199,17 +1206,7 @@ async function render_response({
1199
1206
  props[`props_${i}`] = await branch[i].loaded.props;
1200
1207
  }
1201
1208
 
1202
- let session_tracking_active = false;
1203
- const unsubscribe = session.subscribe(() => {
1204
- if (session_tracking_active) is_private = true;
1205
- });
1206
- session_tracking_active = true;
1207
-
1208
- try {
1209
- rendered = options.root.render(props);
1210
- } finally {
1211
- unsubscribe();
1212
- }
1209
+ rendered = options.root.render(props);
1213
1210
  } else {
1214
1211
  rendered = { head: '', html: '', css: { code: '', map: null } };
1215
1212
  }
@@ -2081,38 +2078,46 @@ async function respond_with_error({
2081
2078
  resolve_opts
2082
2079
  }) {
2083
2080
  try {
2084
- const default_layout = await options.manifest._.nodes[0](); // 0 is always the root layout
2085
- const default_error = await options.manifest._.nodes[1](); // 1 is always the root error
2081
+ const branch = [];
2082
+ let stuff = {};
2083
+
2084
+ if (resolve_opts.ssr) {
2085
+ const default_layout = await options.manifest._.nodes[0](); // 0 is always the root layout
2086
+ const default_error = await options.manifest._.nodes[1](); // 1 is always the root error
2087
+
2088
+ const layout_loaded = /** @type {Loaded} */ (
2089
+ await load_node({
2090
+ event,
2091
+ options,
2092
+ state,
2093
+ route: null,
2094
+ node: default_layout,
2095
+ $session,
2096
+ stuff: {},
2097
+ is_error: false,
2098
+ is_leaf: false
2099
+ })
2100
+ );
2086
2101
 
2087
- const layout_loaded = /** @type {Loaded} */ (
2088
- await load_node({
2089
- event,
2090
- options,
2091
- state,
2092
- route: null,
2093
- node: default_layout,
2094
- $session,
2095
- stuff: {},
2096
- is_error: false,
2097
- is_leaf: false
2098
- })
2099
- );
2102
+ const error_loaded = /** @type {Loaded} */ (
2103
+ await load_node({
2104
+ event,
2105
+ options,
2106
+ state,
2107
+ route: null,
2108
+ node: default_error,
2109
+ $session,
2110
+ stuff: layout_loaded ? layout_loaded.stuff : {},
2111
+ is_error: true,
2112
+ is_leaf: false,
2113
+ status,
2114
+ error
2115
+ })
2116
+ );
2100
2117
 
2101
- const error_loaded = /** @type {Loaded} */ (
2102
- await load_node({
2103
- event,
2104
- options,
2105
- state,
2106
- route: null,
2107
- node: default_error,
2108
- $session,
2109
- stuff: layout_loaded ? layout_loaded.stuff : {},
2110
- is_error: true,
2111
- is_leaf: false,
2112
- status,
2113
- error
2114
- })
2115
- );
2118
+ branch.push(layout_loaded, error_loaded);
2119
+ stuff = error_loaded.stuff;
2120
+ }
2116
2121
 
2117
2122
  return await render_response({
2118
2123
  options,
@@ -2122,10 +2127,10 @@ async function respond_with_error({
2122
2127
  hydrate: options.hydrate,
2123
2128
  router: options.router
2124
2129
  },
2125
- stuff: error_loaded.stuff,
2130
+ stuff,
2126
2131
  status,
2127
2132
  error,
2128
- branch: [layout_loaded, error_loaded],
2133
+ branch,
2129
2134
  event,
2130
2135
  resolve_opts
2131
2136
  });
@@ -433,7 +433,6 @@ async function dev({ cwd, port, host, https, config }) {
433
433
  fs: {
434
434
  allow: [
435
435
  ...new Set([
436
- config.kit.files.assets,
437
436
  config.kit.files.lib,
438
437
  config.kit.files.routes,
439
438
  config.kit.outDir,
@@ -714,7 +714,7 @@ function crawl(html) {
714
714
  if (html[i + 1] === '!') {
715
715
  i += 2;
716
716
 
717
- if (html.substr(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
717
+ if (html.slice(i, i + DOCTYPE.length).toUpperCase() === DOCTYPE) {
718
718
  i += DOCTYPE.length;
719
719
  while (i < html.length) {
720
720
  if (html[i++] === '>') {
@@ -724,10 +724,10 @@ function crawl(html) {
724
724
  }
725
725
 
726
726
  // skip cdata
727
- if (html.substr(i, CDATA_OPEN.length) === CDATA_OPEN) {
727
+ if (html.slice(i, i + CDATA_OPEN.length) === CDATA_OPEN) {
728
728
  i += CDATA_OPEN.length;
729
729
  while (i < html.length) {
730
- if (html.substr(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
730
+ if (html.slice(i, i + CDATA_CLOSE.length) === CDATA_CLOSE) {
731
731
  i += CDATA_CLOSE.length;
732
732
  continue main;
733
733
  }
@@ -737,10 +737,10 @@ function crawl(html) {
737
737
  }
738
738
 
739
739
  // skip comments
740
- if (html.substr(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
740
+ if (html.slice(i, i + COMMENT_OPEN.length) === COMMENT_OPEN) {
741
741
  i += COMMENT_OPEN.length;
742
742
  while (i < html.length) {
743
- if (html.substr(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
743
+ if (html.slice(i, i + COMMENT_CLOSE.length) === COMMENT_CLOSE) {
744
744
  i += COMMENT_CLOSE.length;
745
745
  continue main;
746
746
  }
@@ -768,7 +768,7 @@ function crawl(html) {
768
768
  if (
769
769
  html[i] === '<' &&
770
770
  html[i + 1] === '/' &&
771
- html.substr(i + 2, tag.length).toUpperCase() === tag
771
+ html.slice(i + 2, i + 2 + tag.length).toUpperCase() === tag
772
772
  ) {
773
773
  continue main;
774
774
  }
@@ -17,7 +17,7 @@ function parse_route_id(id) {
17
17
  ? /^\/$/
18
18
  : new RegExp(
19
19
  `^${decodeURIComponent(id)
20
- .split(/(?:@(?:~|[a-zA-Z0-9_-]*))?(?:\/|$)/)
20
+ .split(/(?:@[a-zA-Z0-9_-]+)?(?:\/|$)/)
21
21
  .map((segment, i, segments) => {
22
22
  // special case — /[...rest]/ could contain zero segments
23
23
  const match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
@@ -195,7 +195,9 @@ function create_manifest_data({
195
195
  const extension = valid_extensions.find((ext) => file.endsWith(ext));
196
196
  if (!extension) return;
197
197
 
198
- const id = file.slice(0, -extension.length).replace(/\/?index(\.[a-z]+)?$/, '$1');
198
+ const id = file
199
+ .slice(0, -extension.length)
200
+ .replace(/(?:^|\/)index((?:@[a-zA-Z0-9_-]+)?(?:\.[a-z]+)?)?$/, '$1');
199
201
  const project_relative = `${routes_base}/${file}`;
200
202
 
201
203
  const segments = id.split('/');
package/dist/cli.js CHANGED
@@ -870,7 +870,7 @@ async function launch(port, https, base) {
870
870
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
871
871
  }
872
872
 
873
- const prog = sade('svelte-kit').version('1.0.0-next.306');
873
+ const prog = sade('svelte-kit').version('1.0.0-next.309');
874
874
 
875
875
  prog
876
876
  .command('dev')
@@ -981,7 +981,6 @@ prog
981
981
  prog
982
982
  .command('package')
983
983
  .describe('Create a package')
984
- .option('-d, --dir', 'Destination directory', 'package')
985
984
  .action(async () => {
986
985
  try {
987
986
  const config = await load_config();
@@ -1050,7 +1049,7 @@ async function check_port(port) {
1050
1049
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1051
1050
  if (open) launch(port, https, base);
1052
1051
 
1053
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.306'}\n`));
1052
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.309'}\n`));
1054
1053
 
1055
1054
  const protocol = https ? 'https:' : 'http:';
1056
1055
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.306",
3
+ "version": "1.0.0-next.309",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
package/types/index.d.ts CHANGED
@@ -223,14 +223,14 @@ export interface RequestHandler<
223
223
  Params extends Record<string, string> = Record<string, string>,
224
224
  Output extends ResponseBody = ResponseBody
225
225
  > {
226
- (event: RequestEvent<Params>): RequestHandlerOutput<Output>;
226
+ (event: RequestEvent<Params>): MaybePromise<RequestHandlerOutput<Output>>;
227
227
  }
228
228
 
229
- export type RequestHandlerOutput<Output extends ResponseBody = ResponseBody> = MaybePromise<{
229
+ export interface RequestHandlerOutput<Output extends ResponseBody = ResponseBody> {
230
230
  status?: number;
231
231
  headers?: Headers | Partial<ResponseHeaders>;
232
232
  body?: Output;
233
- }>;
233
+ }
234
234
 
235
235
  export type ResponseBody = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
236
236