@sveltejs/kit 1.2.9 → 1.3.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": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -226,6 +226,10 @@ const options = object(
226
226
  files: fun((filename) => !/\.DS_Store/.test(filename))
227
227
  }),
228
228
 
229
+ typescript: object({
230
+ config: fun((config) => config)
231
+ }),
232
+
229
233
  version: object({
230
234
  name: string(Date.now().toString()),
231
235
  pollInterval: number(0)
@@ -362,7 +366,7 @@ function list(options, fallback = options[0]) {
362
366
  }
363
367
 
364
368
  /**
365
- * @param {(filename: string) => boolean} fallback
369
+ * @param {(...args: any) => any} fallback
366
370
  * @returns {Validator}
367
371
  */
368
372
  function fun(fallback) {
@@ -34,7 +34,7 @@ function remove_trailing_slashstar(file) {
34
34
  }
35
35
 
36
36
  /**
37
- * Writes the tsconfig that the user's tsconfig inherits from.
37
+ * Generates the tsconfig that the user's tsconfig inherits from.
38
38
  * @param {import('types').ValidatedKitConfig} kit
39
39
  */
40
40
  export function write_tsconfig(kit, cwd = process.cwd()) {
@@ -72,6 +72,15 @@ export function write_tsconfig(kit, cwd = process.cwd()) {
72
72
  }
73
73
  }
74
74
 
75
+ write_if_changed(out, JSON.stringify(get_tsconfig(kit, include_base_url), null, '\t'));
76
+ }
77
+
78
+ /**
79
+ * Generates the tsconfig that the user's tsconfig inherits from.
80
+ * @param {import('types').ValidatedKitConfig} kit
81
+ * @param {boolean} include_base_url
82
+ */
83
+ export function get_tsconfig(kit, include_base_url) {
75
84
  /** @param {string} file */
76
85
  const config_relative = (file) => posixify(path.relative(kit.outDir, file));
77
86
 
@@ -98,40 +107,35 @@ export function write_tsconfig(kit, cwd = process.cwd()) {
98
107
  exclude.push(config_relative(`${kit.files.serviceWorker}.d.ts`));
99
108
  }
100
109
 
101
- write_if_changed(
102
- out,
103
- JSON.stringify(
104
- {
105
- compilerOptions: {
106
- // generated options
107
- baseUrl: include_base_url ? config_relative('.') : undefined,
108
- paths: get_tsconfig_paths(kit, include_base_url),
109
- rootDirs: [config_relative('.'), './types'],
110
-
111
- // essential options
112
- // svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
113
- // to enforce using \`import type\` instead of \`import\` for Types.
114
- importsNotUsedAsValues: 'error',
115
- // Vite compiles modules one at a time
116
- isolatedModules: true,
117
- // TypeScript doesn't know about import usages in the template because it only sees the
118
- // script of a Svelte file. Therefore preserve all value imports. Requires TS 4.5 or higher.
119
- preserveValueImports: true,
120
-
121
- // This is required for svelte-package to work as expected
122
- // Can be overwritten
123
- lib: ['esnext', 'DOM', 'DOM.Iterable'],
124
- moduleResolution: 'node',
125
- module: 'esnext',
126
- target: 'esnext'
127
- },
128
- include,
129
- exclude
130
- },
131
- null,
132
- '\t'
133
- )
134
- );
110
+ const config = {
111
+ compilerOptions: {
112
+ // generated options
113
+ baseUrl: include_base_url ? config_relative('.') : undefined,
114
+ paths: get_tsconfig_paths(kit, include_base_url),
115
+ rootDirs: [config_relative('.'), './types'],
116
+
117
+ // essential options
118
+ // svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
119
+ // to enforce using \`import type\` instead of \`import\` for Types.
120
+ importsNotUsedAsValues: 'error',
121
+ // Vite compiles modules one at a time
122
+ isolatedModules: true,
123
+ // TypeScript doesn't know about import usages in the template because it only sees the
124
+ // script of a Svelte file. Therefore preserve all value imports. Requires TS 4.5 or higher.
125
+ preserveValueImports: true,
126
+
127
+ // This is required for svelte-package to work as expected
128
+ // Can be overwritten
129
+ lib: ['esnext', 'DOM', 'DOM.Iterable'],
130
+ moduleResolution: 'node',
131
+ module: 'esnext',
132
+ target: 'esnext'
133
+ },
134
+ include,
135
+ exclude
136
+ };
137
+
138
+ return kit.typescript.config(config) ?? config;
135
139
  }
136
140
 
137
141
  /** @param {string} cwd */
@@ -212,7 +216,7 @@ const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
212
216
  * @param {import('types').ValidatedKitConfig} config
213
217
  * @param {boolean} include_base_url
214
218
  */
215
- export function get_tsconfig_paths(config, include_base_url) {
219
+ function get_tsconfig_paths(config, include_base_url) {
216
220
  /** @param {string} file */
217
221
  const config_relative = (file) => posixify(path.relative(config.outDir, file));
218
222
 
@@ -1531,11 +1531,22 @@ export function create_client({ target, base }) {
1531
1531
  // with history.go, which means we end up back here, hence this check
1532
1532
  if (event.state[INDEX_KEY] === current_history_index) return;
1533
1533
 
1534
+ const scroll = scroll_positions[event.state[INDEX_KEY]];
1535
+
1536
+ // if the only change is the hash, we don't need to do anything...
1537
+ if (current.url.href.split('#')[0] === location.href.split('#')[0]) {
1538
+ // ...except handle scroll
1539
+ scroll_positions[current_history_index] = scroll_state();
1540
+ current_history_index = event.state[INDEX_KEY];
1541
+ scrollTo(scroll.x, scroll.y);
1542
+ return;
1543
+ }
1544
+
1534
1545
  const delta = event.state[INDEX_KEY] - current_history_index;
1535
1546
 
1536
1547
  navigate({
1537
1548
  url: new URL(location.href),
1538
- scroll: scroll_positions[event.state[INDEX_KEY]],
1549
+ scroll,
1539
1550
  keepfocus: false,
1540
1551
  redirect_chain: [],
1541
1552
  details: null,
@@ -69,23 +69,23 @@ export async function handle_action_json_request(event, options, server) {
69
69
  });
70
70
  }
71
71
  } catch (e) {
72
- const error = normalize_error(e);
72
+ const err = normalize_error(e);
73
73
 
74
- if (error instanceof Redirect) {
74
+ if (err instanceof Redirect) {
75
75
  return action_json({
76
76
  type: 'redirect',
77
- status: error.status,
78
- location: error.location
77
+ status: err.status,
78
+ location: err.location
79
79
  });
80
80
  }
81
81
 
82
82
  return action_json(
83
83
  {
84
84
  type: 'error',
85
- error: await handle_error_and_jsonify(event, options, check_incorrect_fail_use(error))
85
+ error: await handle_error_and_jsonify(event, options, check_incorrect_fail_use(err))
86
86
  },
87
87
  {
88
- status: error instanceof HttpError ? error.status : 500
88
+ status: err instanceof HttpError ? err.status : 500
89
89
  }
90
90
  );
91
91
  }
@@ -110,19 +110,18 @@ function action_json(data, init) {
110
110
 
111
111
  /**
112
112
  * @param {import('types').RequestEvent} event
113
- * @param {import('types').SSRNode} leaf_node
114
113
  */
115
- export function is_action_request(event, leaf_node) {
116
- return leaf_node.server && event.request.method !== 'GET' && event.request.method !== 'HEAD';
114
+ export function is_action_request(event) {
115
+ return event.request.method === 'POST';
117
116
  }
118
117
 
119
118
  /**
120
119
  * @param {import('types').RequestEvent} event
121
- * @param {import('types').SSRNode['server']} server
120
+ * @param {import('types').SSRNode['server'] | undefined} server
122
121
  * @returns {Promise<import('types').ActionResult>}
123
122
  */
124
123
  export async function handle_action_request(event, server) {
125
- const actions = server.actions;
124
+ const actions = server?.actions;
126
125
 
127
126
  if (!actions) {
128
127
  // TODO should this be a different error altogether?
@@ -161,19 +160,19 @@ export async function handle_action_request(event, server) {
161
160
  };
162
161
  }
163
162
  } catch (e) {
164
- const error = normalize_error(e);
163
+ const err = normalize_error(e);
165
164
 
166
- if (error instanceof Redirect) {
165
+ if (err instanceof Redirect) {
167
166
  return {
168
167
  type: 'redirect',
169
- status: error.status,
170
- location: error.location
168
+ status: err.status,
169
+ location: err.location
171
170
  };
172
171
  }
173
172
 
174
173
  return {
175
174
  type: 'error',
176
- error: check_incorrect_fail_use(error)
175
+ error: check_incorrect_fail_use(err)
177
176
  };
178
177
  }
179
178
  }
@@ -59,7 +59,7 @@ export async function render_page(event, route, page, options, manifest, state,
59
59
  /** @type {import('types').ActionResult | undefined} */
60
60
  let action_result = undefined;
61
61
 
62
- if (is_action_request(event, leaf_node)) {
62
+ if (is_action_request(event)) {
63
63
  // for action requests, first call handler in +page.server.js
64
64
  // (this also determines status code)
65
65
  action_result = await handle_action_request(event, leaf_node.server);
@@ -85,7 +85,7 @@ export async function render_page(event, route, page, options, manifest, state,
85
85
 
86
86
  if (should_prerender) {
87
87
  const mod = leaf_node.server;
88
- if (mod && mod.actions) {
88
+ if (mod?.actions) {
89
89
  throw new Error('Cannot prerender pages with actions');
90
90
  }
91
91
  } else if (state.prerendering) {
package/types/index.d.ts CHANGED
@@ -503,6 +503,14 @@ export interface KitConfig {
503
503
  */
504
504
  files?(filepath: string): boolean;
505
505
  };
506
+ typescript?: {
507
+ /**
508
+ * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
509
+ * This is useful for — to example — extend a shared `tsconfig.json` in a monorepo root
510
+ * @default (config) => config
511
+ */
512
+ config?: (config: Record<string, any>) => Record<string, any> | void;
513
+ };
506
514
  /**
507
515
  * Client-side navigation can be buggy if you deploy a new version of your app while people are using it. If the code for the new page is already loaded, it may have stale content; if it isn't, the app's route manifest may point to a JavaScript file that no longer exists. SvelteKit solves this problem by falling back to traditional full-page navigation if it detects that a new version has been deployed, using the `name` specified here (which defaults to a timestamp of the build).
508
516
  *