@sveltejs/kit 1.0.0-next.35 → 1.0.0-next.350

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