@sveltejs/kit 1.0.0-next.326 → 1.0.0-next.327

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.
@@ -23,6 +23,7 @@ import 'node:zlib';
23
23
  import 'node:stream';
24
24
  import 'node:util';
25
25
  import 'node:url';
26
+ import './write_tsconfig.js';
26
27
  import 'stream';
27
28
 
28
29
  /**
@@ -10,6 +10,7 @@ import { n as normalize_path, d as deep_merge, r as resolve, i as is_root_relati
10
10
  import { svelte } from '@sveltejs/vite-plugin-svelte';
11
11
  import { pathToFileURL, URL as URL$1 } from 'url';
12
12
  import { installFetch } from '../install-fetch.js';
13
+ import './write_tsconfig.js';
13
14
  import 'sade';
14
15
  import 'child_process';
15
16
  import 'net';
@@ -5,6 +5,7 @@ import { $ } from '../cli.js';
5
5
  import chokidar from 'chokidar';
6
6
  import { w as walk$1, m as mkdirp, p as posixify, r as rimraf, c as copy } from './filesystem.js';
7
7
  import { createRequire } from 'module';
8
+ import { a as write_tsconfig } from './write_tsconfig.js';
8
9
  import 'sade';
9
10
  import 'child_process';
10
11
  import 'net';
@@ -15547,6 +15548,9 @@ async function build(config, cwd = process.cwd()) {
15547
15548
  rimraf(dir);
15548
15549
  mkdirp(dir);
15549
15550
 
15551
+ // Make sure generated tsconfig is up-to-date
15552
+ write_tsconfig(config);
15553
+
15550
15554
  const files = scan(config);
15551
15555
 
15552
15556
  if (config.kit.package.emitTypes) {
@@ -1,9 +1,10 @@
1
1
  import path__default from 'path';
2
2
  import fs__default from 'fs';
3
- import { g as get_runtime_path, $ } from '../cli.js';
4
- import { p as posixify, c as copy, m as mkdirp } from './filesystem.js';
3
+ import { g as get_runtime_path } from '../cli.js';
4
+ import { p as posixify, c as copy } from './filesystem.js';
5
5
  import { p as parse_route_id, s } from './misc.js';
6
6
  import { fileURLToPath } from 'url';
7
+ import { w as write_if_changed, t as trim, a as write_tsconfig } from './write_tsconfig.js';
7
8
  import 'sade';
8
9
  import 'child_process';
9
10
  import 'net';
@@ -581,28 +582,6 @@ function copy_assets(dest) {
581
582
  } while (true); // eslint-disable-line
582
583
  }
583
584
 
584
- /** @type {Map<string, string>} */
585
- const previous_contents = new Map();
586
-
587
- /**
588
- * @param {string} file
589
- * @param {string} code
590
- */
591
- function write_if_changed(file, code) {
592
- if (code !== previous_contents.get(file)) {
593
- previous_contents.set(file, code);
594
- mkdirp(path__default.dirname(file));
595
- fs__default.writeFileSync(file, code);
596
- }
597
- }
598
-
599
- /** @param {string} str */
600
- function trim(str) {
601
- const indentation = /** @type {RegExpExecArray} */ (/\n?(\s*)/.exec(str))[1];
602
- const pattern = new RegExp(`^${indentation}`, 'gm');
603
- return str.replace(pattern, '').trim();
604
- }
605
-
606
585
  /**
607
586
  * @param {import('types').ManifestData} manifest_data
608
587
  * @param {string} base
@@ -763,128 +742,6 @@ function write_root(manifest_data, output) {
763
742
  );
764
743
  }
765
744
 
766
- /** @param {string} file */
767
- const exists = (file) => fs__default.existsSync(file) && file;
768
-
769
- /** @param {import('types').ValidatedConfig} config */
770
- function write_tsconfig(config) {
771
- const out = path__default.join(config.kit.outDir, 'tsconfig.json');
772
- const user_file = exists('tsconfig.json') || exists('jsconfig.json');
773
-
774
- if (user_file) validate(config, out, user_file);
775
-
776
- /** @param {string} file */
777
- const project_relative = (file) => posixify(path__default.relative('.', file));
778
-
779
- /** @param {string} file */
780
- const config_relative = (file) => posixify(path__default.relative(config.kit.outDir, file));
781
-
782
- const dirs = new Set([
783
- project_relative(path__default.dirname(config.kit.files.routes)),
784
- project_relative(path__default.dirname(config.kit.files.lib))
785
- ]);
786
-
787
- /** @type {string[]} */
788
- const include = [];
789
- dirs.forEach((dir) => {
790
- include.push(config_relative(`${dir}/**/*.js`));
791
- include.push(config_relative(`${dir}/**/*.ts`));
792
- include.push(config_relative(`${dir}/**/*.svelte`));
793
- });
794
-
795
- write_if_changed(
796
- out,
797
- JSON.stringify(
798
- {
799
- compilerOptions: {
800
- // generated options
801
- baseUrl: config_relative('.'),
802
- paths: fs__default.existsSync(config.kit.files.lib)
803
- ? {
804
- $lib: [project_relative(config.kit.files.lib)],
805
- '$lib/*': [project_relative(config.kit.files.lib + '/*')]
806
- }
807
- : {},
808
- rootDirs: [config_relative('.'), './types'],
809
-
810
- // essential options
811
- // svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
812
- // to enforce using \`import type\` instead of \`import\` for Types.
813
- importsNotUsedAsValues: 'error',
814
- // Vite compiles modules one at a time
815
- isolatedModules: true,
816
- // TypeScript doesn't know about import usages in the template because it only sees the
817
- // script of a Svelte file. Therefore preserve all value imports. Requires TS 4.5 or higher.
818
- preserveValueImports: true,
819
-
820
- // This is required for svelte-kit package to work as expected
821
- // Can be overwritten
822
- lib: ['esnext', 'DOM'],
823
- moduleResolution: 'node',
824
- module: 'esnext',
825
- target: 'esnext'
826
- },
827
- include,
828
- exclude: [config_relative('node_modules/**'), './**']
829
- },
830
- null,
831
- '\t'
832
- )
833
- );
834
- }
835
-
836
- /**
837
- * @param {import('types').ValidatedConfig} config
838
- * @param {string} out
839
- * @param {string} user_file
840
- */
841
- function validate(config, out, user_file) {
842
- // we have to eval the file, since it's not parseable as JSON (contains comments)
843
- const user_tsconfig_json = fs__default.readFileSync(user_file, 'utf-8');
844
- const user_tsconfig = (0, eval)(`(${user_tsconfig_json})`);
845
-
846
- // we need to check that the user's tsconfig extends the framework config
847
- const extend = user_tsconfig.extends;
848
- const extends_framework_config = extend && path__default.resolve('.', extend) === out;
849
-
850
- if (extends_framework_config) {
851
- const { paths: user_paths } = user_tsconfig.compilerOptions || {};
852
-
853
- if (user_paths && fs__default.existsSync(config.kit.files.lib)) {
854
- /** @type {string[]} */
855
- const lib = user_paths['$lib'] || [];
856
- /** @type {string[]} */
857
- const lib_ = user_paths['$lib/*'] || [];
858
-
859
- const missing_lib_paths =
860
- !lib.some((relative) => path__default.resolve('.', relative) === config.kit.files.lib) ||
861
- !lib_.some(
862
- (relative) => path__default.resolve('.', relative) === path__default.join(config.kit.files.lib, '/*')
863
- );
864
-
865
- if (missing_lib_paths) {
866
- console.warn(
867
- $
868
- .bold()
869
- .yellow(`Your compilerOptions.paths in ${user_file} should include the following:`)
870
- );
871
- const relative = posixify(path__default.relative('.', config.kit.files.lib));
872
- console.warn(`{\n "$lib":["${relative}"],\n "$lib/*":["${relative}/*"]\n}`);
873
- }
874
- }
875
- } else {
876
- let relative = posixify(path__default.relative('.', out));
877
- if (!relative.startsWith('./')) relative = './' + relative;
878
-
879
- console.warn(
880
- $
881
- .bold()
882
- .yellow(`Your ${user_file} should extend the configuration generated by SvelteKit:`)
883
- );
884
- console.warn(`{\n "extends": "${relative}"\n}`);
885
- }
886
- }
887
-
888
745
  /** @param {string} imports */
889
746
  const header = (imports) => `
890
747
  // this file is auto-generated
@@ -0,0 +1,150 @@
1
+ import fs__default from 'fs';
2
+ import path__default from 'path';
3
+ import { $ } from '../cli.js';
4
+ import { m as mkdirp, p as posixify } from './filesystem.js';
5
+
6
+ /** @type {Map<string, string>} */
7
+ const previous_contents = new Map();
8
+
9
+ /**
10
+ * @param {string} file
11
+ * @param {string} code
12
+ */
13
+ function write_if_changed(file, code) {
14
+ if (code !== previous_contents.get(file)) {
15
+ previous_contents.set(file, code);
16
+ mkdirp(path__default.dirname(file));
17
+ fs__default.writeFileSync(file, code);
18
+ }
19
+ }
20
+
21
+ /** @param {string} str */
22
+ function trim(str) {
23
+ const indentation = /** @type {RegExpExecArray} */ (/\n?(\s*)/.exec(str))[1];
24
+ const pattern = new RegExp(`^${indentation}`, 'gm');
25
+ return str.replace(pattern, '').trim();
26
+ }
27
+
28
+ /** @param {string} file */
29
+ const exists = (file) => fs__default.existsSync(file) && file;
30
+
31
+ /** @param {import('types').ValidatedConfig} config */
32
+ function write_tsconfig(config) {
33
+ const out = path__default.join(config.kit.outDir, 'tsconfig.json');
34
+ const user_file = exists('tsconfig.json') || exists('jsconfig.json');
35
+
36
+ if (user_file) validate(config, out, user_file);
37
+
38
+ /** @param {string} file */
39
+ const project_relative = (file) => posixify(path__default.relative('.', file));
40
+
41
+ /** @param {string} file */
42
+ const config_relative = (file) => posixify(path__default.relative(config.kit.outDir, file));
43
+
44
+ const dirs = new Set([
45
+ project_relative(path__default.dirname(config.kit.files.routes)),
46
+ project_relative(path__default.dirname(config.kit.files.lib))
47
+ ]);
48
+
49
+ /** @type {string[]} */
50
+ const include = [];
51
+ dirs.forEach((dir) => {
52
+ include.push(config_relative(`${dir}/**/*.js`));
53
+ include.push(config_relative(`${dir}/**/*.ts`));
54
+ include.push(config_relative(`${dir}/**/*.svelte`));
55
+ });
56
+
57
+ write_if_changed(
58
+ out,
59
+ JSON.stringify(
60
+ {
61
+ compilerOptions: {
62
+ // generated options
63
+ baseUrl: config_relative('.'),
64
+ paths: fs__default.existsSync(config.kit.files.lib)
65
+ ? {
66
+ $lib: [project_relative(config.kit.files.lib)],
67
+ '$lib/*': [project_relative(config.kit.files.lib + '/*')]
68
+ }
69
+ : {},
70
+ rootDirs: [config_relative('.'), './types'],
71
+
72
+ // essential options
73
+ // svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
74
+ // to enforce using \`import type\` instead of \`import\` for Types.
75
+ importsNotUsedAsValues: 'error',
76
+ // Vite compiles modules one at a time
77
+ isolatedModules: true,
78
+ // TypeScript doesn't know about import usages in the template because it only sees the
79
+ // script of a Svelte file. Therefore preserve all value imports. Requires TS 4.5 or higher.
80
+ preserveValueImports: true,
81
+
82
+ // This is required for svelte-kit package to work as expected
83
+ // Can be overwritten
84
+ lib: ['esnext', 'DOM'],
85
+ moduleResolution: 'node',
86
+ module: 'esnext',
87
+ target: 'esnext'
88
+ },
89
+ include,
90
+ exclude: [config_relative('node_modules/**'), './**']
91
+ },
92
+ null,
93
+ '\t'
94
+ )
95
+ );
96
+ }
97
+
98
+ /**
99
+ * @param {import('types').ValidatedConfig} config
100
+ * @param {string} out
101
+ * @param {string} user_file
102
+ */
103
+ function validate(config, out, user_file) {
104
+ // we have to eval the file, since it's not parseable as JSON (contains comments)
105
+ const user_tsconfig_json = fs__default.readFileSync(user_file, 'utf-8');
106
+ const user_tsconfig = (0, eval)(`(${user_tsconfig_json})`);
107
+
108
+ // we need to check that the user's tsconfig extends the framework config
109
+ const extend = user_tsconfig.extends;
110
+ const extends_framework_config = extend && path__default.resolve('.', extend) === out;
111
+
112
+ if (extends_framework_config) {
113
+ const { paths: user_paths } = user_tsconfig.compilerOptions || {};
114
+
115
+ if (user_paths && fs__default.existsSync(config.kit.files.lib)) {
116
+ /** @type {string[]} */
117
+ const lib = user_paths['$lib'] || [];
118
+ /** @type {string[]} */
119
+ const lib_ = user_paths['$lib/*'] || [];
120
+
121
+ const missing_lib_paths =
122
+ !lib.some((relative) => path__default.resolve('.', relative) === config.kit.files.lib) ||
123
+ !lib_.some(
124
+ (relative) => path__default.resolve('.', relative) === path__default.join(config.kit.files.lib, '/*')
125
+ );
126
+
127
+ if (missing_lib_paths) {
128
+ console.warn(
129
+ $
130
+ .bold()
131
+ .yellow(`Your compilerOptions.paths in ${user_file} should include the following:`)
132
+ );
133
+ const relative = posixify(path__default.relative('.', config.kit.files.lib));
134
+ console.warn(`{\n "$lib":["${relative}"],\n "$lib/*":["${relative}/*"]\n}`);
135
+ }
136
+ }
137
+ } else {
138
+ let relative = posixify(path__default.relative('.', out));
139
+ if (!relative.startsWith('./')) relative = './' + relative;
140
+
141
+ console.warn(
142
+ $
143
+ .bold()
144
+ .yellow(`Your ${user_file} should extend the configuration generated by SvelteKit:`)
145
+ );
146
+ console.warn(`{\n "extends": "${relative}"\n}`);
147
+ }
148
+ }
149
+
150
+ export { write_tsconfig as a, trim as t, write_if_changed as w };
package/dist/cli.js CHANGED
@@ -870,7 +870,7 @@ async function launch(port, https, base) {
870
870
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
871
871
  }
872
872
 
873
- const prog = sade('svelte-kit').version('1.0.0-next.326');
873
+ const prog = sade('svelte-kit').version('1.0.0-next.327');
874
874
 
875
875
  prog
876
876
  .command('dev')
@@ -1049,7 +1049,7 @@ async function check_port(port) {
1049
1049
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1050
1050
  if (open) launch(port, https, base);
1051
1051
 
1052
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.326'}\n`));
1052
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.327'}\n`));
1053
1053
 
1054
1054
  const protocol = https ? 'https:' : 'http:';
1055
1055
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.326",
3
+ "version": "1.0.0-next.327",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -151,7 +151,7 @@ declare module '$app/navigation' {
151
151
  */
152
152
  declare module '$app/paths' {
153
153
  /**
154
- * A string that matches [`config.kit.paths.base`](/docs/configuration#paths). It must begin, but not end, with a `/`.
154
+ * A string that matches [`config.kit.paths.base`](/docs/configuration#paths). It must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string.
155
155
  */
156
156
  export const base: `/${string}`;
157
157
  /**