@sveltejs/kit 1.0.0-next.409 → 1.0.0-next.411

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.409",
3
+ "version": "1.0.0-next.411",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -67,14 +67,7 @@ export default function create_manifest_data({
67
67
 
68
68
  if (file[0] !== '+') return; // not a route file
69
69
 
70
- const item = analyze(file, config.extensions, config.kit.moduleExtensions);
71
-
72
- if (!item) {
73
- throw new Error(
74
- `Files and directories prefixed with + are reserved (saw ${project_relative})`
75
- );
76
- }
77
-
70
+ const item = analyze(project_relative, file, config.extensions, config.kit.moduleExtensions);
78
71
  const id = segments.join('/');
79
72
 
80
73
  if (/\]\[/.test(id)) {
@@ -275,19 +268,22 @@ export default function create_manifest_data({
275
268
  }
276
269
 
277
270
  /**
271
+ * @param {string} project_relative
278
272
  * @param {string} file
279
273
  * @param {string[]} component_extensions
280
274
  * @param {string[]} module_extensions
281
- * @returns {import('./types').RouteFile | null}
275
+ * @returns {import('./types').RouteFile}
282
276
  */
283
- function analyze(file, component_extensions, module_extensions) {
277
+ function analyze(project_relative, file, component_extensions, module_extensions) {
284
278
  const component_extension = component_extensions.find((ext) => file.endsWith(ext));
285
279
  if (component_extension) {
286
280
  const name = file.slice(0, -component_extension.length);
287
281
  const pattern =
288
282
  /^\+(?:(page(?:@([a-zA-Z0-9_-]+))?)|(layout(?:-([a-zA-Z0-9_-]+))?(?:@([a-zA-Z0-9_-]+))?)|(error))$/;
289
283
  const match = pattern.exec(name);
290
- if (!match) return null;
284
+ if (!match) {
285
+ throw new Error(`Files prefixed with + are reserved (saw ${project_relative})`);
286
+ }
291
287
 
292
288
  return {
293
289
  kind: 'component',
@@ -302,21 +298,29 @@ function analyze(file, component_extensions, module_extensions) {
302
298
  const module_extension = module_extensions.find((ext) => file.endsWith(ext));
303
299
  if (module_extension) {
304
300
  const name = file.slice(0, -module_extension.length);
305
- const pattern = /^\+(?:(server)|(page(\.server)?)|(layout(?:-([a-zA-Z0-9_-]+))?(\.server)?))$/;
301
+ const pattern =
302
+ /^\+(?:(server)|(page(?:@([a-zA-Z0-9_-]+))?(\.server)?)|(layout(?:-([a-zA-Z0-9_-]+))?(?:@([a-zA-Z0-9_-]+))?(\.server)?))$/;
306
303
  const match = pattern.exec(name);
307
- if (!match) return null;
304
+ if (!match) {
305
+ throw new Error(`Files prefixed with + are reserved (saw ${project_relative})`);
306
+ } else if (match[3] || match[7]) {
307
+ throw new Error(
308
+ // prettier-ignore
309
+ `Only Svelte files can reference named layouts. Remove '@${match[3] || match[7]}' from ${file} (at ${project_relative})`
310
+ );
311
+ }
308
312
 
309
- const kind = !!(match[1] || match[3] || match[6]) ? 'server' : 'shared';
313
+ const kind = !!(match[1] || match[4] || match[8]) ? 'server' : 'shared';
310
314
 
311
315
  return {
312
316
  kind,
313
317
  is_page: !!match[2],
314
- is_layout: !!match[4],
315
- declares_layout: match[5]
318
+ is_layout: !!match[5],
319
+ declares_layout: match[6]
316
320
  };
317
321
  }
318
322
 
319
- return null;
323
+ throw new Error(`Files and directories prefixed with + are reserved (saw ${project_relative})`);
320
324
  }
321
325
 
322
326
  /**
@@ -431,17 +431,12 @@ function process_node(ts, node, outdir, params, groups) {
431
431
  function get_data_type(file_path, method, fallback, proxy) {
432
432
  if (proxy) {
433
433
  if (proxy.exports.includes(method)) {
434
- if (proxy.modified) {
435
- const basename = path.basename(file_path);
436
- return `Kit.AwaitedProperties<Awaited<ReturnType<typeof import('./proxy${basename}').${method}>>>`;
437
- } else {
438
- // If the file wasn't tweaked, we can use the return type of the original file.
439
- // The advantage is that type updates are reflected without saving.
440
- return `Kit.AwaitedProperties<Awaited<ReturnType<typeof import("${path_to_original(
441
- outdir,
442
- file_path
443
- )}").${method}>>>`;
444
- }
434
+ // If the file wasn't tweaked, we can use the return type of the original file.
435
+ // The advantage is that type updates are reflected without saving.
436
+ const from = proxy.modified
437
+ ? `./proxy${replace_ext_with_js(path.basename(file_path))}`
438
+ : path_to_original(outdir, file_path);
439
+ return `Kit.AwaitedProperties<Awaited<ReturnType<typeof import('${from}').${method}>>>`;
445
440
  } else {
446
441
  return fallback;
447
442
  }
@@ -621,7 +616,11 @@ export function tweak_types(ts, content, names) {
621
616
 
622
617
  const rhs = declaration.initializer;
623
618
 
624
- if (rhs && (ts.isArrowFunction(rhs) || ts.isFunctionExpression(rhs))) {
619
+ if (
620
+ rhs &&
621
+ (ts.isArrowFunction(rhs) || ts.isFunctionExpression(rhs)) &&
622
+ rhs.parameters.length
623
+ ) {
625
624
  const arg = rhs.parameters[0];
626
625
 
627
626
  const add_parens = content[arg.pos - 1] !== '(';
@@ -389,6 +389,7 @@ export function create_client({ target, session, base, trailing_slash }) {
389
389
  * status: number;
390
390
  * error: HttpError | Error | null;
391
391
  * routeId: string | null;
392
+ * validation_errors?: string | undefined;
392
393
  * }} opts
393
394
  */
394
395
  async function get_navigation_result_from_branch({
@@ -397,7 +398,8 @@ export function create_client({ target, session, base, trailing_slash }) {
397
398
  branch,
398
399
  status,
399
400
  error,
400
- routeId
401
+ routeId,
402
+ validation_errors
401
403
  }) {
402
404
  const filtered = /** @type {import('./types').BranchNode[] } */ (branch.filter(Boolean));
403
405
 
@@ -412,7 +414,8 @@ export function create_client({ target, session, base, trailing_slash }) {
412
414
  session_id
413
415
  },
414
416
  props: {
415
- components: filtered.map((branch_node) => branch_node.node.component)
417
+ components: filtered.map((branch_node) => branch_node.node.component),
418
+ errors: validation_errors
416
419
  }
417
420
  };
418
421
 
@@ -1211,8 +1214,16 @@ export function create_client({ target, session, base, trailing_slash }) {
1211
1214
  let result;
1212
1215
 
1213
1216
  try {
1214
- const script = document.querySelector(`script[sveltekit\\:data-type="server_data"]`);
1215
- const server_data = script?.textContent ? JSON.parse(script.textContent) : [];
1217
+ /**
1218
+ * @param {string} type
1219
+ * @param {any} fallback
1220
+ */
1221
+ const parse = (type, fallback) => {
1222
+ const script = document.querySelector(`script[sveltekit\\:data-type="${type}"]`);
1223
+ return script?.textContent ? JSON.parse(script.textContent) : fallback;
1224
+ };
1225
+ const server_data = parse('server_data', []);
1226
+ const validation_errors = parse('validation_errors', undefined);
1216
1227
 
1217
1228
  const branch_promises = node_ids.map(async (n, i) => {
1218
1229
  return load_node({
@@ -1243,6 +1254,7 @@ export function create_client({ target, session, base, trailing_slash }) {
1243
1254
  error.message
1244
1255
  )
1245
1256
  : error,
1257
+ validation_errors,
1246
1258
  routeId
1247
1259
  });
1248
1260
  } catch (e) {
@@ -52,6 +52,7 @@ export function create_fetch({ event, options, state, route }) {
52
52
  if (
53
53
  key !== 'authorization' &&
54
54
  key !== 'connection' &&
55
+ key !== 'content-length' &&
55
56
  key !== 'cookie' &&
56
57
  key !== 'host' &&
57
58
  key !== 'if-none-match' &&
@@ -266,6 +266,12 @@ export async function render_response({
266
266
  );
267
267
  }
268
268
 
269
+ if (validation_errors) {
270
+ serialized_data.push(
271
+ render_json_payload_script({ type: 'validation_errors' }, validation_errors)
272
+ );
273
+ }
274
+
269
275
  body += `\n\t${serialized_data.join('\n\t')}`;
270
276
  }
271
277
 
@@ -141,7 +141,8 @@ export interface PageData {
141
141
 
142
142
  export type PayloadScriptAttributes =
143
143
  | { type: 'data'; url: string; body?: string }
144
- | { type: 'server_data' };
144
+ | { type: 'server_data' }
145
+ | { type: 'validation_errors' };
145
146
 
146
147
  export interface PrerenderDependency {
147
148
  response: Response;