@sveltejs/kit 1.0.0-next.34 → 1.0.0-next.342

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.
Files changed (73) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +16 -0
  3. package/assets/app/navigation.js +24 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/app/stores.js +97 -0
  6. package/assets/client/singletons.js +13 -0
  7. package/assets/client/start.js +1782 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env.js +8 -0
  10. package/assets/paths.js +13 -0
  11. package/assets/server/index.js +3367 -0
  12. package/dist/chunks/cert.js +28154 -0
  13. package/dist/chunks/constants.js +663 -0
  14. package/dist/chunks/filesystem.js +110 -0
  15. package/dist/chunks/index.js +549 -0
  16. package/dist/chunks/index2.js +1385 -0
  17. package/dist/chunks/index3.js +118 -0
  18. package/dist/chunks/index4.js +183 -0
  19. package/dist/chunks/index5.js +253 -0
  20. package/dist/chunks/index6.js +15749 -0
  21. package/dist/chunks/misc.js +78 -0
  22. package/dist/chunks/multipart-parser.js +450 -0
  23. package/dist/chunks/object.js +83 -0
  24. package/dist/chunks/sync.js +858 -0
  25. package/dist/chunks/write_tsconfig.js +160 -0
  26. package/dist/cli.js +1097 -64
  27. package/dist/hooks.js +28 -0
  28. package/dist/node/polyfills.js +6514 -0
  29. package/dist/node.js +301 -0
  30. package/package.json +80 -62
  31. package/svelte-kit.js +0 -1
  32. package/types/ambient.d.ts +307 -0
  33. package/types/index.d.ts +292 -0
  34. package/types/internal.d.ts +321 -0
  35. package/types/private.d.ts +235 -0
  36. package/CHANGELOG.md +0 -362
  37. package/assets/runtime/app/navigation.js +0 -23
  38. package/assets/runtime/app/navigation.js.map +0 -1
  39. package/assets/runtime/app/paths.js +0 -2
  40. package/assets/runtime/app/paths.js.map +0 -1
  41. package/assets/runtime/app/stores.js +0 -78
  42. package/assets/runtime/app/stores.js.map +0 -1
  43. package/assets/runtime/internal/singletons.js +0 -15
  44. package/assets/runtime/internal/singletons.js.map +0 -1
  45. package/assets/runtime/internal/start.js +0 -591
  46. package/assets/runtime/internal/start.js.map +0 -1
  47. package/assets/runtime/utils-85ebcc60.js +0 -18
  48. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  49. package/dist/api.js +0 -32
  50. package/dist/api.js.map +0 -1
  51. package/dist/cli.js.map +0 -1
  52. package/dist/create_app.js +0 -577
  53. package/dist/create_app.js.map +0 -1
  54. package/dist/index.js +0 -329
  55. package/dist/index.js.map +0 -1
  56. package/dist/index2.js +0 -14368
  57. package/dist/index2.js.map +0 -1
  58. package/dist/index3.js +0 -545
  59. package/dist/index3.js.map +0 -1
  60. package/dist/index4.js +0 -71
  61. package/dist/index4.js.map +0 -1
  62. package/dist/index5.js +0 -465
  63. package/dist/index5.js.map +0 -1
  64. package/dist/index6.js +0 -729
  65. package/dist/index6.js.map +0 -1
  66. package/dist/renderer.js +0 -2413
  67. package/dist/renderer.js.map +0 -1
  68. package/dist/standard.js +0 -100
  69. package/dist/standard.js.map +0 -1
  70. package/dist/utils.js +0 -57
  71. package/dist/utils.js.map +0 -1
  72. package/dist/vite.js +0 -317
  73. package/dist/vite.js.map +0 -1
@@ -0,0 +1,160 @@
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, cwd = process.cwd()) {
33
+ const out = path__default.join(config.kit.outDir, 'tsconfig.json');
34
+ const user_file =
35
+ exists(path__default.resolve(cwd, 'tsconfig.json')) || exists(path__default.resolve(cwd, 'jsconfig.json'));
36
+
37
+ if (user_file) validate(config, cwd, out, user_file);
38
+
39
+ /** @param {string} file */
40
+ const project_relative = (file) => posixify(path__default.relative('.', file));
41
+
42
+ /** @param {string} file */
43
+ const config_relative = (file) => posixify(path__default.relative(config.kit.outDir, file));
44
+
45
+ const dirs = new Set([
46
+ project_relative(path__default.dirname(config.kit.files.routes)),
47
+ project_relative(path__default.dirname(config.kit.files.lib))
48
+ ]);
49
+
50
+ /** @type {string[]} */
51
+ const include = [];
52
+ dirs.forEach((dir) => {
53
+ include.push(config_relative(`${dir}/**/*.js`));
54
+ include.push(config_relative(`${dir}/**/*.ts`));
55
+ include.push(config_relative(`${dir}/**/*.svelte`));
56
+ });
57
+
58
+ /** @type {Record<string, string[]>} */
59
+ const paths = {};
60
+ const alias = {
61
+ $lib: project_relative(config.kit.files.lib),
62
+ ...config.kit.alias
63
+ };
64
+ for (const [key, value] of Object.entries(alias)) {
65
+ if (fs__default.existsSync(project_relative(value))) {
66
+ paths[key] = [project_relative(value)];
67
+ paths[key + '/*'] = [project_relative(value) + '/*'];
68
+ }
69
+ }
70
+
71
+ write_if_changed(
72
+ out,
73
+ JSON.stringify(
74
+ {
75
+ compilerOptions: {
76
+ // generated options
77
+ baseUrl: config_relative('.'),
78
+ paths,
79
+ rootDirs: [config_relative('.'), './types'],
80
+
81
+ // essential options
82
+ // svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
83
+ // to enforce using \`import type\` instead of \`import\` for Types.
84
+ importsNotUsedAsValues: 'error',
85
+ // Vite compiles modules one at a time
86
+ isolatedModules: true,
87
+ // TypeScript doesn't know about import usages in the template because it only sees the
88
+ // script of a Svelte file. Therefore preserve all value imports. Requires TS 4.5 or higher.
89
+ preserveValueImports: true,
90
+
91
+ // This is required for svelte-kit package to work as expected
92
+ // Can be overwritten
93
+ lib: ['esnext', 'DOM'],
94
+ moduleResolution: 'node',
95
+ module: 'esnext',
96
+ target: 'esnext'
97
+ },
98
+ include,
99
+ exclude: [config_relative('node_modules/**'), './**']
100
+ },
101
+ null,
102
+ '\t'
103
+ )
104
+ );
105
+ }
106
+
107
+ /**
108
+ * @param {import('types').ValidatedConfig} config
109
+ * @param {string} cwd
110
+ * @param {string} out
111
+ * @param {string} user_file
112
+ */
113
+ function validate(config, cwd, out, user_file) {
114
+ // we have to eval the file, since it's not parseable as JSON (contains comments)
115
+ const user_tsconfig_json = fs__default.readFileSync(user_file, 'utf-8');
116
+ const user_tsconfig = (0, eval)(`(${user_tsconfig_json})`);
117
+
118
+ // we need to check that the user's tsconfig extends the framework config
119
+ const extend = user_tsconfig.extends;
120
+ const extends_framework_config = extend && path__default.resolve(cwd, extend) === out;
121
+
122
+ const kind = path__default.basename(user_file);
123
+
124
+ if (extends_framework_config) {
125
+ const { paths: user_paths } = user_tsconfig.compilerOptions || {};
126
+
127
+ if (user_paths && fs__default.existsSync(config.kit.files.lib)) {
128
+ /** @type {string[]} */
129
+ const lib = user_paths['$lib'] || [];
130
+ /** @type {string[]} */
131
+ const lib_ = user_paths['$lib/*'] || [];
132
+
133
+ const missing_lib_paths =
134
+ !lib.some((relative) => path__default.resolve(cwd, relative) === config.kit.files.lib) ||
135
+ !lib_.some(
136
+ (relative) => path__default.resolve(cwd, relative) === path__default.join(config.kit.files.lib, '/*')
137
+ );
138
+
139
+ if (missing_lib_paths) {
140
+ console.warn(
141
+ $
142
+ .bold()
143
+ .yellow(`Your compilerOptions.paths in ${kind} should include the following:`)
144
+ );
145
+ const relative = posixify(path__default.relative('.', config.kit.files.lib));
146
+ console.warn(`{\n "$lib":["${relative}"],\n "$lib/*":["${relative}/*"]\n}`);
147
+ }
148
+ }
149
+ } else {
150
+ let relative = posixify(path__default.relative('.', out));
151
+ if (!relative.startsWith('./')) relative = './' + relative;
152
+
153
+ console.warn(
154
+ $.bold().yellow(`Your ${kind} should extend the configuration generated by SvelteKit:`)
155
+ );
156
+ console.warn(`{\n "extends": "${relative}"\n}`);
157
+ }
158
+ }
159
+
160
+ export { write_tsconfig as a, trim as t, write_if_changed as w };