@sveltejs/kit 1.0.0-next.38 → 1.0.0-next.380

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 (42) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +28 -0
  3. package/assets/app/navigation.js +24 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/{runtime/app → app}/stores.js +33 -29
  6. package/assets/client/singletons.js +13 -0
  7. package/assets/client/start.js +1803 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env.js +8 -0
  10. package/assets/{runtime/chunks/paths.js → paths.js} +4 -3
  11. package/assets/server/index.js +3563 -0
  12. package/dist/chunks/_commonjsHelpers.js +3 -0
  13. package/dist/chunks/error.js +664 -0
  14. package/dist/chunks/index.js +15292 -3067
  15. package/dist/chunks/index2.js +186 -555
  16. package/dist/chunks/multipart-parser.js +445 -0
  17. package/dist/chunks/sync.js +1007 -0
  18. package/dist/chunks/write_tsconfig.js +274 -0
  19. package/dist/cli.js +66 -514
  20. package/dist/hooks.js +28 -0
  21. package/dist/node/polyfills.js +12240 -0
  22. package/dist/node.js +5883 -0
  23. package/dist/vite.js +3243 -0
  24. package/package.json +97 -64
  25. package/types/ambient.d.ts +345 -0
  26. package/types/index.d.ts +289 -0
  27. package/types/internal.d.ts +326 -0
  28. package/types/private.d.ts +235 -0
  29. package/CHANGELOG.md +0 -399
  30. package/assets/runtime/app/env.js +0 -5
  31. package/assets/runtime/app/navigation.js +0 -41
  32. package/assets/runtime/app/paths.js +0 -1
  33. package/assets/runtime/chunks/utils.js +0 -19
  34. package/assets/runtime/internal/singletons.js +0 -23
  35. package/assets/runtime/internal/start.js +0 -770
  36. package/dist/chunks/index3.js +0 -246
  37. package/dist/chunks/index4.js +0 -511
  38. package/dist/chunks/index5.js +0 -761
  39. package/dist/chunks/index6.js +0 -322
  40. package/dist/chunks/standard.js +0 -99
  41. package/dist/chunks/utils.js +0 -83
  42. package/dist/ssr.js +0 -2523
@@ -0,0 +1,274 @@
1
+ import fs__default from 'fs';
2
+ import path__default from 'path';
3
+ import { $ } from './error.js';
4
+
5
+ /** @param {string} dir */
6
+ function mkdirp(dir) {
7
+ try {
8
+ fs__default.mkdirSync(dir, { recursive: true });
9
+ } catch (/** @type {any} */ e) {
10
+ if (e.code === 'EEXIST') return;
11
+ throw e;
12
+ }
13
+ }
14
+
15
+ /** @param {string} path */
16
+ function rimraf(path) {
17
+ fs__default.rmSync(path, { force: true, recursive: true });
18
+ }
19
+
20
+ /**
21
+ * @param {string} source
22
+ * @param {string} target
23
+ * @param {{
24
+ * filter?: (basename: string) => boolean;
25
+ * replace?: Record<string, string>;
26
+ * }} opts
27
+ */
28
+ function copy(source, target, opts = {}) {
29
+ if (!fs__default.existsSync(source)) return [];
30
+
31
+ /** @type {string[]} */
32
+ const files = [];
33
+
34
+ const prefix = posixify(target) + '/';
35
+
36
+ const regex = opts.replace
37
+ ? new RegExp(`\\b(${Object.keys(opts.replace).join('|')})\\b`, 'g')
38
+ : null;
39
+
40
+ /**
41
+ * @param {string} from
42
+ * @param {string} to
43
+ */
44
+ function go(from, to) {
45
+ if (opts.filter && !opts.filter(path__default.basename(from))) return;
46
+
47
+ const stats = fs__default.statSync(from);
48
+
49
+ if (stats.isDirectory()) {
50
+ fs__default.readdirSync(from).forEach((file) => {
51
+ go(path__default.join(from, file), path__default.join(to, file));
52
+ });
53
+ } else {
54
+ mkdirp(path__default.dirname(to));
55
+
56
+ if (opts.replace) {
57
+ const data = fs__default.readFileSync(from, 'utf-8');
58
+ fs__default.writeFileSync(
59
+ to,
60
+ data.replace(
61
+ /** @type {RegExp} */ (regex),
62
+ (match, key) => /** @type {Record<string, string>} */ (opts.replace)[key]
63
+ )
64
+ );
65
+ } else {
66
+ fs__default.copyFileSync(from, to);
67
+ }
68
+
69
+ files.push(to === target ? posixify(path__default.basename(to)) : posixify(to).replace(prefix, ''));
70
+ }
71
+ }
72
+
73
+ go(source, target);
74
+
75
+ return files;
76
+ }
77
+
78
+ /**
79
+ * Get a list of all files in a directory
80
+ * @param {string} cwd - the directory to walk
81
+ * @param {boolean} [dirs] - whether to include directories in the result
82
+ */
83
+ function walk(cwd, dirs = false) {
84
+ /** @type {string[]} */
85
+ const all_files = [];
86
+
87
+ /** @param {string} dir */
88
+ function walk_dir(dir) {
89
+ const files = fs__default.readdirSync(path__default.join(cwd, dir));
90
+
91
+ for (const file of files) {
92
+ const joined = path__default.join(dir, file);
93
+ const stats = fs__default.statSync(path__default.join(cwd, joined));
94
+ if (stats.isDirectory()) {
95
+ if (dirs) all_files.push(joined);
96
+ walk_dir(joined);
97
+ } else {
98
+ all_files.push(joined);
99
+ }
100
+ }
101
+ }
102
+
103
+ return walk_dir(''), all_files;
104
+ }
105
+
106
+ /** @param {string} str */
107
+ function posixify(str) {
108
+ return str.replace(/\\/g, '/');
109
+ }
110
+
111
+ /** @type {Map<string, string>} */
112
+ const previous_contents = new Map();
113
+
114
+ /**
115
+ * @param {string} file
116
+ * @param {string} code
117
+ */
118
+ function write_if_changed(file, code) {
119
+ if (code !== previous_contents.get(file)) {
120
+ write(file, code);
121
+ }
122
+ }
123
+
124
+ /**
125
+ * @param {string} file
126
+ * @param {string} code
127
+ */
128
+ function write(file, code) {
129
+ previous_contents.set(file, code);
130
+ mkdirp(path__default.dirname(file));
131
+ fs__default.writeFileSync(file, code);
132
+ }
133
+
134
+ /** @param {string} str */
135
+ function trim(str) {
136
+ const indentation = /** @type {RegExpExecArray} */ (/\n?(\s*)/.exec(str))[1];
137
+ const pattern = new RegExp(`^${indentation}`, 'gm');
138
+ return str.replace(pattern, '').trim();
139
+ }
140
+
141
+ /** @param {string} file */
142
+ const exists = (file) => fs__default.existsSync(file) && file;
143
+
144
+ /**
145
+ * Writes the tsconfig that the user's tsconfig inherits from.
146
+ * @param {import('types').ValidatedKitConfig} config
147
+ */
148
+ function write_tsconfig(config, cwd = process.cwd()) {
149
+ const out = path__default.join(config.outDir, 'tsconfig.json');
150
+ const user_file =
151
+ exists(path__default.resolve(cwd, 'tsconfig.json')) || exists(path__default.resolve(cwd, 'jsconfig.json'));
152
+
153
+ if (user_file) validate(config, cwd, out, user_file);
154
+
155
+ /** @param {string} file */
156
+ const project_relative = (file) => posixify(path__default.relative('.', file));
157
+
158
+ /** @param {string} file */
159
+ const config_relative = (file) => posixify(path__default.relative(config.outDir, file));
160
+
161
+ const dirs = new Set([
162
+ project_relative(path__default.dirname(config.files.routes)),
163
+ project_relative(path__default.dirname(config.files.lib))
164
+ ]);
165
+
166
+ /** @type {string[]} */
167
+ const include = [];
168
+ dirs.forEach((dir) => {
169
+ include.push(config_relative(`${dir}/**/*.js`));
170
+ include.push(config_relative(`${dir}/**/*.ts`));
171
+ include.push(config_relative(`${dir}/**/*.svelte`));
172
+ });
173
+
174
+ /** @type {Record<string, string[]>} */
175
+ const paths = {};
176
+ const alias = {
177
+ $lib: project_relative(config.files.lib),
178
+ ...config.alias
179
+ };
180
+ for (const [key, value] of Object.entries(alias)) {
181
+ if (fs__default.existsSync(project_relative(value))) {
182
+ paths[key] = [project_relative(value)];
183
+ paths[key + '/*'] = [project_relative(value) + '/*'];
184
+ }
185
+ }
186
+
187
+ write_if_changed(
188
+ out,
189
+ JSON.stringify(
190
+ {
191
+ compilerOptions: {
192
+ // generated options
193
+ baseUrl: config_relative('.'),
194
+ paths,
195
+ rootDirs: [config_relative('.'), './types'],
196
+
197
+ // essential options
198
+ // svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
199
+ // to enforce using \`import type\` instead of \`import\` for Types.
200
+ importsNotUsedAsValues: 'error',
201
+ // Vite compiles modules one at a time
202
+ isolatedModules: true,
203
+ // TypeScript doesn't know about import usages in the template because it only sees the
204
+ // script of a Svelte file. Therefore preserve all value imports. Requires TS 4.5 or higher.
205
+ preserveValueImports: true,
206
+
207
+ // This is required for svelte-kit package to work as expected
208
+ // Can be overwritten
209
+ lib: ['esnext', 'DOM'],
210
+ moduleResolution: 'node',
211
+ module: 'esnext',
212
+ target: 'esnext'
213
+ },
214
+ include,
215
+ exclude: [config_relative('node_modules/**'), './**']
216
+ },
217
+ null,
218
+ '\t'
219
+ )
220
+ );
221
+ }
222
+
223
+ /**
224
+ * @param {import('types').ValidatedKitConfig} config
225
+ * @param {string} cwd
226
+ * @param {string} out
227
+ * @param {string} user_file
228
+ */
229
+ function validate(config, cwd, out, user_file) {
230
+ // we have to eval the file, since it's not parseable as JSON (contains comments)
231
+ const user_tsconfig_json = fs__default.readFileSync(user_file, 'utf-8');
232
+ const user_tsconfig = (0, eval)(`(${user_tsconfig_json})`);
233
+
234
+ // we need to check that the user's tsconfig extends the framework config
235
+ const extend = user_tsconfig.extends;
236
+ const extends_framework_config = extend && path__default.resolve(cwd, extend) === out;
237
+
238
+ const kind = path__default.basename(user_file);
239
+
240
+ if (extends_framework_config) {
241
+ const { paths: user_paths } = user_tsconfig.compilerOptions || {};
242
+
243
+ if (user_paths && fs__default.existsSync(config.files.lib)) {
244
+ /** @type {string[]} */
245
+ const lib = user_paths['$lib'] || [];
246
+ /** @type {string[]} */
247
+ const lib_ = user_paths['$lib/*'] || [];
248
+
249
+ const missing_lib_paths =
250
+ !lib.some((relative) => path__default.resolve(cwd, relative) === config.files.lib) ||
251
+ !lib_.some((relative) => path__default.resolve(cwd, relative) === path__default.join(config.files.lib, '/*'));
252
+
253
+ if (missing_lib_paths) {
254
+ console.warn(
255
+ $
256
+ .bold()
257
+ .yellow(`Your compilerOptions.paths in ${kind} should include the following:`)
258
+ );
259
+ const relative = posixify(path__default.relative('.', config.files.lib));
260
+ console.warn(`{\n "$lib":["${relative}"],\n "$lib/*":["${relative}/*"]\n}`);
261
+ }
262
+ }
263
+ } else {
264
+ let relative = posixify(path__default.relative('.', out));
265
+ if (!relative.startsWith('./')) relative = './' + relative;
266
+
267
+ console.warn(
268
+ $.bold().yellow(`Your ${kind} should extend the configuration generated by SvelteKit:`)
269
+ );
270
+ console.warn(`{\n "extends": "${relative}"\n}`);
271
+ }
272
+ }
273
+
274
+ export { write as a, write_tsconfig as b, copy as c, walk as d, mkdirp as m, posixify as p, rimraf as r, trim as t, write_if_changed as w };