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

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/assets/kit.js CHANGED
@@ -68,21 +68,24 @@ function is_string(s) {
68
68
  return typeof s === 'string' || s instanceof String;
69
69
  }
70
70
 
71
+ const text_types = new Set([
72
+ 'application/xml',
73
+ 'application/json',
74
+ 'application/x-www-form-urlencoded',
75
+ 'multipart/form-data'
76
+ ]);
77
+
71
78
  /**
72
79
  * Decides how the body should be parsed based on its mime type. Should match what's in parse_body
73
80
  *
74
81
  * @param {string | undefined | null} content_type The `content-type` header of a request/response.
75
82
  * @returns {boolean}
76
83
  */
77
- function is_content_type_textual(content_type) {
84
+ function is_text(content_type) {
78
85
  if (!content_type) return true; // defaults to json
79
- const [type] = content_type.split(';'); // get the mime type
80
- return (
81
- type === 'text/plain' ||
82
- type === 'application/json' ||
83
- type === 'application/x-www-form-urlencoded' ||
84
- type === 'multipart/form-data'
85
- );
86
+ const type = content_type.split(';')[0].toLowerCase(); // get the mime type
87
+
88
+ return type.startsWith('text/') || type.endsWith('+xml') || text_types.has(type);
86
89
  }
87
90
 
88
91
  /**
@@ -121,9 +124,7 @@ async function render_endpoint(request, route, match) {
121
124
  headers = lowercase_keys(headers);
122
125
  const type = get_single_valued_header(headers, 'content-type');
123
126
 
124
- const is_type_textual = is_content_type_textual(type);
125
-
126
- if (!is_type_textual && !(body instanceof Uint8Array || is_string(body))) {
127
+ if (!is_text(type) && !(body instanceof Uint8Array || is_string(body))) {
127
128
  return error(
128
129
  `${preface}: body must be an instance of string or Uint8Array if content-type is not a supported textual content-type`
129
130
  );
@@ -1,6 +1,7 @@
1
1
  import Root from '../../generated/root.svelte';
2
2
  import { fallback, routes } from '../../generated/manifest.js';
3
3
  import { g as get_base_uri } from '../chunks/utils.js';
4
+ import { tick } from 'svelte';
4
5
  import { writable } from 'svelte/store';
5
6
  import { init } from './singletons.js';
6
7
  import { set_paths } from '../paths.js';
@@ -661,7 +662,7 @@ class Renderer {
661
662
  this._init(navigation_result);
662
663
  }
663
664
 
664
- // opts must be passed if we're navigating...
665
+ // opts must be passed if we're navigating
665
666
  if (opts) {
666
667
  const { hash, scroll, keepfocus } = opts;
667
668
 
@@ -670,7 +671,8 @@ class Renderer {
670
671
  document.body.focus();
671
672
  }
672
673
 
673
- await 0;
674
+ // need to render the DOM before we can scroll to the rendered elements
675
+ await tick();
674
676
 
675
677
  if (this.autoscroll) {
676
678
  const deep_linked = hash && document.getElementById(hash.slice(1));
@@ -686,8 +688,8 @@ class Renderer {
686
688
  }
687
689
  }
688
690
  } else {
689
- // ...they will not be supplied if we're simply invalidating
690
- await 0;
691
+ // in this case we're simply invalidating
692
+ await tick();
691
693
  }
692
694
 
693
695
  this.loading.promise = null;
@@ -9,13 +9,4 @@ function coalesce_to_error(err) {
9
9
  : new Error(JSON.stringify(err));
10
10
  }
11
11
 
12
- /**
13
- * @param {Error} err
14
- * @param {any} errorCode
15
- * @return {err is Error & {code: any}}
16
- */
17
- function has_error_code(err, errorCode = undefined) {
18
- return 'code' in err && (errorCode === undefined || /** @type {any} */ (err).code === errorCode);
19
- }
20
-
21
- export { coalesce_to_error as c, has_error_code as h };
12
+ export { coalesce_to_error as c };
package/dist/cli.js CHANGED
@@ -1,12 +1,12 @@
1
- import fs__default, { existsSync } from 'fs';
2
1
  import sade from 'sade';
3
2
  import path__default, { relative } from 'path';
4
3
  import { exec as exec$1 } from 'child_process';
5
4
  import { createConnection, createServer } from 'net';
5
+ import fs__default from 'fs';
6
6
  import * as url from 'url';
7
7
  import { fileURLToPath } from 'url';
8
8
  import { networkInterfaces, release } from 'os';
9
- import { c as coalesce_to_error, h as has_error_code } from './chunks/error.js';
9
+ import { c as coalesce_to_error } from './chunks/error.js';
10
10
 
11
11
  let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
12
12
  if (typeof process !== 'undefined') {
@@ -762,10 +762,14 @@ function load_template(cwd, config) {
762
762
  }
763
763
 
764
764
  async function load_config({ cwd = process.cwd() } = {}) {
765
- const config_file_esm = path__default.join(cwd, 'svelte.config.js');
766
- const config_file = fs__default.existsSync(config_file_esm)
767
- ? config_file_esm
768
- : path__default.join(cwd, 'svelte.config.cjs');
765
+ const config_file = path__default.join(cwd, 'svelte.config.js');
766
+
767
+ if (!fs__default.existsSync(config_file)) {
768
+ throw new Error(
769
+ 'You need to create a svelte.config.js file. See https://kit.svelte.dev/docs#configuration'
770
+ );
771
+ }
772
+
769
773
  const config = await import(url.pathToFileURL(config_file).href);
770
774
 
771
775
  const validated = validate_config(config.default);
@@ -785,17 +789,9 @@ async function load_config({ cwd = process.cwd() } = {}) {
785
789
  * @returns {import('types/config').ValidatedConfig}
786
790
  */
787
791
  function validate_config(config) {
788
- const type = typeof config;
789
-
790
- if (type === 'undefined') {
791
- throw new Error(
792
- 'Your config is missing default exports. Make sure to include "export default config;"'
793
- );
794
- }
795
-
796
- if (type !== 'object') {
792
+ if (typeof config !== 'object') {
797
793
  throw new Error(
798
- `Unexpected config type "${type}", make sure your default export is an object.`
794
+ 'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs#configuration'
799
795
  );
800
796
  }
801
797
 
@@ -817,52 +813,17 @@ function print_config_conflicts(conflicts, pathPrefix = '', scope) {
817
813
  });
818
814
  }
819
815
 
820
- async function get_config() {
821
- // TODO this is temporary, for the benefit of early adopters
822
- if (existsSync('svelte.config.cjs')) {
823
- // prettier-ignore
824
- console.error($.bold().red(
825
- 'svelte.config.cjs should be renamed to svelte.config.js and converted to an ES module. See https://kit.svelte.dev/docs#configuration for an example'
826
- ));
827
- }
828
-
829
- if (existsSync('vite.config.js')) {
830
- // prettier-ignore
831
- console.error($.bold().red(
832
- 'Please remove vite.config.js and put Vite config in svelte.config.js: https://kit.svelte.dev/docs#configuration-vite'
833
- ));
834
- }
816
+ /** @param {unknown} e */
817
+ function handle_error(e) {
818
+ const error = coalesce_to_error(e);
835
819
 
836
- try {
837
- return await load_config();
838
- } catch (err) {
839
- const error = coalesce_to_error(err);
840
- let message = error.message;
841
-
842
- if (
843
- has_error_code(error, 'MODULE_NOT_FOUND') &&
844
- /Cannot find module svelte\.config\./.test(error.message)
845
- ) {
846
- message = 'Missing svelte.config.js';
847
- } else if (error.name === 'SyntaxError') {
848
- message = 'Malformed svelte.config.js';
849
- }
820
+ if (error.name === 'SyntaxError') throw error;
850
821
 
851
- console.error($.bold().red(message));
852
- if (error.stack) {
853
- console.error($.grey(error.stack));
854
- }
855
- process.exit(1);
822
+ console.log($.bold().red(`> ${error.message}`));
823
+ if (error.stack) {
824
+ console.log($.gray(error.stack.split('\n').slice(1).join('\n')));
856
825
  }
857
- }
858
826
 
859
- /** @param {unknown} error */
860
- function handle_error(error) {
861
- const err = coalesce_to_error(error);
862
- console.log($.bold().red(`> ${err.message}`));
863
- if (err.stack) {
864
- console.log($.gray(err.stack));
865
- }
866
827
  process.exit(1);
867
828
  }
868
829
 
@@ -885,7 +846,7 @@ async function launch(port, https) {
885
846
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
886
847
  }
887
848
 
888
- const prog = sade('svelte-kit').version('1.0.0-next.216');
849
+ const prog = sade('svelte-kit').version('1.0.0-next.217');
889
850
 
890
851
  prog
891
852
  .command('dev')
@@ -895,12 +856,12 @@ prog
895
856
  .option('-H, --https', 'Use self-signed HTTPS certificate')
896
857
  .option('-o, --open', 'Open a browser tab')
897
858
  .action(async ({ port, host, https, open }) => {
898
- process.env.NODE_ENV = process.env.NODE_ENV || 'development';
899
- const config = await get_config();
859
+ try {
860
+ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
861
+ const config = await load_config();
900
862
 
901
- const { dev } = await import('./chunks/index.js');
863
+ const { dev } = await import('./chunks/index.js');
902
864
 
903
- try {
904
865
  const cwd = process.cwd();
905
866
 
906
867
  const { address_info, server_config } = await dev({
@@ -930,10 +891,10 @@ prog
930
891
  .describe('Create a production build of your app')
931
892
  .option('--verbose', 'Log more stuff', false)
932
893
  .action(async ({ verbose }) => {
933
- process.env.NODE_ENV = process.env.NODE_ENV || 'production';
934
- const config = await get_config();
935
-
936
894
  try {
895
+ process.env.NODE_ENV = process.env.NODE_ENV || 'production';
896
+ const config = await load_config();
897
+
937
898
  const { build } = await import('./chunks/index3.js');
938
899
  const build_data = await build(config);
939
900
 
@@ -968,14 +929,14 @@ prog
968
929
  .option('-H, --https', 'Use self-signed HTTPS certificate', false)
969
930
  .option('-o, --open', 'Open a browser tab', false)
970
931
  .action(async ({ port, host, https, open }) => {
971
- await check_port(port);
932
+ try {
933
+ await check_port(port);
972
934
 
973
- process.env.NODE_ENV = process.env.NODE_ENV || 'production';
974
- const config = await get_config();
935
+ process.env.NODE_ENV = process.env.NODE_ENV || 'production';
936
+ const config = await load_config();
975
937
 
976
- const { preview } = await import('./chunks/index6.js');
938
+ const { preview } = await import('./chunks/index6.js');
977
939
 
978
- try {
979
940
  await preview({ port, host, config, https });
980
941
 
981
942
  welcome({ port, host, https, open });
@@ -989,11 +950,11 @@ prog
989
950
  .describe('Create a package')
990
951
  .option('-d, --dir', 'Destination directory', 'package')
991
952
  .action(async () => {
992
- const config = await get_config();
953
+ try {
954
+ const config = await load_config();
993
955
 
994
- const { make_package } = await import('./chunks/index7.js');
956
+ const { make_package } = await import('./chunks/index7.js');
995
957
 
996
- try {
997
958
  await make_package(config);
998
959
  } catch (error) {
999
960
  handle_error(error);
@@ -1037,7 +998,7 @@ async function check_port(port) {
1037
998
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1038
999
  if (open) launch(port, https);
1039
1000
 
1040
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.216'}\n`));
1001
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.217'}\n`));
1041
1002
 
1042
1003
  const protocol = https ? 'https:' : 'http:';
1043
1004
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/dist/ssr.js CHANGED
@@ -50,21 +50,24 @@ function is_string(s) {
50
50
  return typeof s === 'string' || s instanceof String;
51
51
  }
52
52
 
53
+ const text_types = new Set([
54
+ 'application/xml',
55
+ 'application/json',
56
+ 'application/x-www-form-urlencoded',
57
+ 'multipart/form-data'
58
+ ]);
59
+
53
60
  /**
54
61
  * Decides how the body should be parsed based on its mime type. Should match what's in parse_body
55
62
  *
56
63
  * @param {string | undefined | null} content_type The `content-type` header of a request/response.
57
64
  * @returns {boolean}
58
65
  */
59
- function is_content_type_textual(content_type) {
66
+ function is_text(content_type) {
60
67
  if (!content_type) return true; // defaults to json
61
- const [type] = content_type.split(';'); // get the mime type
62
- return (
63
- type === 'text/plain' ||
64
- type === 'application/json' ||
65
- type === 'application/x-www-form-urlencoded' ||
66
- type === 'multipart/form-data'
67
- );
68
+ const type = content_type.split(';')[0].toLowerCase(); // get the mime type
69
+
70
+ return type.startsWith('text/') || type.endsWith('+xml') || text_types.has(type);
68
71
  }
69
72
 
70
73
  /**
@@ -103,9 +106,7 @@ async function render_endpoint(request, route, match) {
103
106
  headers = lowercase_keys(headers);
104
107
  const type = get_single_valued_header(headers, 'content-type');
105
108
 
106
- const is_type_textual = is_content_type_textual(type);
107
-
108
- if (!is_type_textual && !(body instanceof Uint8Array || is_string(body))) {
109
+ if (!is_text(type) && !(body instanceof Uint8Array || is_string(body))) {
109
110
  return error(
110
111
  `${preface}: body must be an instance of string or Uint8Array if content-type is not a supported textual content-type`
111
112
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.216",
3
+ "version": "1.0.0-next.217",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -39,6 +39,7 @@
39
39
  "sirv": "^1.0.19",
40
40
  "svelte": "^3.44.2",
41
41
  "svelte-check": "^2.2.10",
42
+ "svelte-preprocess": "^4.9.8",
42
43
  "svelte2tsx": "~0.4.10",
43
44
  "tiny-glob": "^0.2.9",
44
45
  "uvu": "^0.5.2"