@sveltejs/kit 2.31.0 → 2.32.0

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": "2.31.0",
3
+ "version": "2.32.0",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -558,9 +558,9 @@ async function kit({ svelte_config }) {
558
558
  // are added to the module graph
559
559
  enforce: 'pre',
560
560
 
561
- async resolveId(id, importer) {
561
+ async resolveId(id, importer, options) {
562
562
  if (importer && !importer.endsWith('index.html')) {
563
- const resolved = await this.resolve(id, importer, { skipSelf: true });
563
+ const resolved = await this.resolve(id, importer, { ...options, skipSelf: true });
564
564
 
565
565
  if (resolved) {
566
566
  const normalized = normalize_id(resolved.id, normalized_lib, normalized_cwd);
@@ -609,6 +609,7 @@ async function kit({ svelte_config }) {
609
609
  const chain = [normalized];
610
610
 
611
611
  let current = normalized;
612
+ let includes_remote_file = false;
612
613
 
613
614
  while (true) {
614
615
  const importers = import_map.get(current);
@@ -619,9 +620,11 @@ async function kit({ svelte_config }) {
619
620
 
620
621
  chain.push((current = candidates[0]));
621
622
 
622
- if (entrypoints.has(current)) {
623
- let message = `Cannot import ${normalized} into code that runs in the browser, as this could leak sensitive information.`;
623
+ includes_remote_file ||= svelte_config.kit.moduleExtensions.some((ext) => {
624
+ return current.endsWith(`.remote${ext}`);
625
+ });
624
626
 
627
+ if (entrypoints.has(current)) {
625
628
  const pyramid = chain
626
629
  .reverse()
627
630
  .map((id, i) => {
@@ -629,6 +632,15 @@ async function kit({ svelte_config }) {
629
632
  })
630
633
  .join(' imports\n');
631
634
 
635
+ if (includes_remote_file) {
636
+ error_for_missing_config(
637
+ 'remote functions',
638
+ 'kit.experimental.remoteFunctions',
639
+ 'true'
640
+ );
641
+ }
642
+
643
+ let message = `Cannot import ${normalized} into code that runs in the browser, as this could leak sensitive information.`;
632
644
  message += `\n\n${pyramid}`;
633
645
  message += `\n\nIf you're only using the import as a type, change it to \`import type\`.`;
634
646
 
@@ -794,7 +806,7 @@ async function kit({ svelte_config }) {
794
806
  }
795
807
  if (!kit.experimental.instrumentation.server) {
796
808
  error_for_missing_config(
797
- 'instrumentation.server.js',
809
+ '`instrumentation.server.js`',
798
810
  'kit.experimental.instrumentation.server',
799
811
  'true'
800
812
  );
@@ -206,13 +206,11 @@ export function error_for_missing_config(feature_name, path, value) {
206
206
  return acc.replace(hole, `${indent}${part}: ${rhs}`);
207
207
  }, hole);
208
208
 
209
- throw new Error(
209
+ throw stackless(
210
210
  dedent`\
211
- To enable \`${feature_name}\`, add the following to your \`svelte.config.js\`:
211
+ To enable ${feature_name}, add the following to your \`svelte.config.js\`:
212
212
 
213
- \`\`\`js
214
213
  ${result}
215
- \`\`\`
216
214
  `
217
215
  );
218
216
  }
@@ -2,7 +2,7 @@
2
2
  /** @import { RemoteInfo, MaybePromise } from 'types' */
3
3
  /** @import { StandardSchemaV1 } from '@standard-schema/spec' */
4
4
  import { get_request_store } from '@sveltejs/kit/internal/server';
5
- import { check_experimental, create_validator, run_remote_function } from './shared.js';
5
+ import { create_validator, run_remote_function } from './shared.js';
6
6
 
7
7
  /**
8
8
  * Creates a remote command. When called from the browser, the function will be invoked on the server via a `fetch` call.
@@ -51,8 +51,6 @@ import { check_experimental, create_validator, run_remote_function } from './sha
51
51
  */
52
52
  /*@__NO_SIDE_EFFECTS__*/
53
53
  export function command(validate_or_fn, maybe_fn) {
54
- check_experimental('command');
55
-
56
54
  /** @type {(arg?: Input) => Output} */
57
55
  const fn = maybe_fn ?? validate_or_fn;
58
56
 
@@ -1,7 +1,7 @@
1
1
  /** @import { RemoteForm } from '@sveltejs/kit' */
2
2
  /** @import { RemoteInfo, MaybePromise } from 'types' */
3
3
  import { get_request_store } from '@sveltejs/kit/internal/server';
4
- import { check_experimental, run_remote_function } from './shared.js';
4
+ import { run_remote_function } from './shared.js';
5
5
 
6
6
  /**
7
7
  * Creates a form object that can be spread onto a `<form>` element.
@@ -16,8 +16,6 @@ import { check_experimental, run_remote_function } from './shared.js';
16
16
  /*@__NO_SIDE_EFFECTS__*/
17
17
  // @ts-ignore we don't want to prefix `fn` with an underscore, as that will be user-visible
18
18
  export function form(fn) {
19
- check_experimental('form');
20
-
21
19
  /**
22
20
  * @param {string | number | boolean} [key]
23
21
  */
@@ -7,7 +7,6 @@ import { get_request_store } from '@sveltejs/kit/internal/server';
7
7
  import { create_remote_cache_key, stringify, stringify_remote_arg } from '../../../shared.js';
8
8
  import { app_dir, base } from '__sveltekit/paths';
9
9
  import {
10
- check_experimental,
11
10
  create_validator,
12
11
  get_response,
13
12
  parse_remote_response,
@@ -65,8 +64,6 @@ import {
65
64
  */
66
65
  /*@__NO_SIDE_EFFECTS__*/
67
66
  export function prerender(validate_or_fn, fn_or_options, maybe_options) {
68
- check_experimental('prerender');
69
-
70
67
  const maybe_fn = typeof fn_or_options === 'function' ? fn_or_options : undefined;
71
68
 
72
69
  /** @type {typeof maybe_options} */
@@ -4,12 +4,7 @@
4
4
  import { get_request_store } from '@sveltejs/kit/internal/server';
5
5
  import { create_remote_cache_key, stringify_remote_arg } from '../../../shared.js';
6
6
  import { prerendering } from '__sveltekit/environment';
7
- import {
8
- check_experimental,
9
- create_validator,
10
- get_response,
11
- run_remote_function
12
- } from './shared.js';
7
+ import { create_validator, get_response, run_remote_function } from './shared.js';
13
8
 
14
9
  /**
15
10
  * Creates a remote query. When called from the browser, the function will be invoked on the server via a `fetch` call.
@@ -58,8 +53,6 @@ import {
58
53
  */
59
54
  /*@__NO_SIDE_EFFECTS__*/
60
55
  export function query(validate_or_fn, maybe_fn) {
61
- check_experimental('query');
62
-
63
56
  /** @type {(arg?: Input) => Output} */
64
57
  const fn = maybe_fn ?? validate_or_fn;
65
58
 
@@ -74,15 +74,6 @@ export function get_response(id, arg, state, get_result) {
74
74
  return ((state.remote_data ??= {})[cache_key] ??= get_result());
75
75
  }
76
76
 
77
- /** @param {string} feature */
78
- export function check_experimental(feature) {
79
- if (!__SVELTEKIT_EXPERIMENTAL__REMOTE_FUNCTIONS__) {
80
- throw new Error(
81
- `Cannot use \`${feature}\` from \`$app/server\` without the experimental flag set to true. Please set kit.experimental.remoteFunctions to \`true\` in your config.`
82
- );
83
- }
84
- }
85
-
86
77
  /**
87
78
  * @param {any} data
88
79
  * @param {ServerHooks['transport']} transport
@@ -311,6 +311,9 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
311
311
  }
312
312
  }
313
313
 
314
+ /** @type {ReadableStream<Uint8Array>} */
315
+ let teed_body;
316
+
314
317
  const proxy = new Proxy(response, {
315
318
  get(response, key, _receiver) {
316
319
  /**
@@ -342,6 +345,39 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
342
345
  });
343
346
  }
344
347
 
348
+ if (key === 'body') {
349
+ if (response.body === null) {
350
+ return null;
351
+ }
352
+
353
+ if (teed_body) {
354
+ return teed_body;
355
+ }
356
+
357
+ const [a, b] = response.body.tee();
358
+
359
+ void (async () => {
360
+ let result = new Uint8Array();
361
+
362
+ for await (const chunk of a) {
363
+ const combined = new Uint8Array(result.length + chunk.length);
364
+
365
+ combined.set(result, 0);
366
+ combined.set(chunk, result.length);
367
+
368
+ result = combined;
369
+ }
370
+
371
+ if (dependency) {
372
+ dependency.body = new Uint8Array(result);
373
+ }
374
+
375
+ void push_fetched(base64_encode(result), true);
376
+ })();
377
+
378
+ return (teed_body = b);
379
+ }
380
+
345
381
  if (key === 'arrayBuffer') {
346
382
  return async () => {
347
383
  const buffer = await response.arrayBuffer();
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '2.31.0';
4
+ export const VERSION = '2.32.0';