@sveltejs/kit 1.2.10 → 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.10",
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,
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
  *