@sveltejs/kit 1.0.0-next.40 → 1.0.0-next.402

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 (48) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +13 -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 +1845 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env/dynamic/private.js +1 -0
  10. package/assets/env/dynamic/public.js +1 -0
  11. package/assets/env-private.js +9 -0
  12. package/assets/env-public.js +9 -0
  13. package/assets/env.js +8 -0
  14. package/assets/{runtime/chunks/paths.js → paths.js} +4 -3
  15. package/assets/server/index.js +3579 -0
  16. package/dist/chunks/error.js +12 -0
  17. package/dist/chunks/filesystem.js +110 -0
  18. package/dist/chunks/index.js +541 -3385
  19. package/dist/chunks/index2.js +15631 -473
  20. package/dist/chunks/index3.js +189 -217
  21. package/dist/chunks/multipart-parser.js +458 -0
  22. package/dist/chunks/sync.js +1366 -0
  23. package/dist/chunks/utils.js +40 -57
  24. package/dist/chunks/write_tsconfig.js +273 -0
  25. package/dist/cli.js +85 -513
  26. package/dist/hooks.js +28 -0
  27. package/dist/node/polyfills.js +17778 -0
  28. package/dist/node.js +348 -0
  29. package/dist/prerender.js +788 -0
  30. package/dist/vite.js +2520 -0
  31. package/package.json +98 -64
  32. package/svelte-kit.js +10 -1
  33. package/types/ambient.d.ts +375 -0
  34. package/types/index.d.ts +298 -0
  35. package/types/internal.d.ts +335 -0
  36. package/types/private.d.ts +235 -0
  37. package/CHANGELOG.md +0 -411
  38. package/assets/runtime/app/env.js +0 -5
  39. package/assets/runtime/app/navigation.js +0 -41
  40. package/assets/runtime/app/paths.js +0 -1
  41. package/assets/runtime/chunks/utils.js +0 -19
  42. package/assets/runtime/internal/singletons.js +0 -23
  43. package/assets/runtime/internal/start.js +0 -770
  44. package/dist/chunks/index4.js +0 -526
  45. package/dist/chunks/index5.js +0 -761
  46. package/dist/chunks/index6.js +0 -322
  47. package/dist/chunks/standard.js +0 -99
  48. package/dist/ssr.js +0 -2523
@@ -1,77 +1,45 @@
1
- import path, { dirname, resolve } from 'path';
2
- import { $ } from '../cli.js';
3
- import fs, { existsSync } from 'fs';
4
- import { fileURLToPath } from 'url';
1
+ import path__default from 'path';
2
+ import { $ } from './index.js';
3
+ import 'url';
5
4
 
6
- /** @param {string} dir */
7
- function mkdirp(dir) {
8
- try {
9
- fs.mkdirSync(dir, { recursive: true });
10
- } catch (e) {
11
- if (e.code === 'EEXIST') return;
12
- throw e;
5
+ /**
6
+ * Get the prefix for the `runtime` directory, for use with import declarations
7
+ * @param {import('types').ValidatedKitConfig} config
8
+ */
9
+ function get_runtime_prefix(config) {
10
+ {
11
+ return posixify_path(path__default.join(config.outDir, 'runtime'));
13
12
  }
14
13
  }
15
14
 
16
- /** @param {string} path */
17
- function rimraf(path) {
18
- (fs.rmSync || fs.rmdirSync)(path, { recursive: true, force: true });
19
- }
20
-
21
15
  /**
22
- * @param {string} from
23
- * @param {string} to
24
- * @param {(basename: string) => boolean} filter
16
+ * Get the resolved path of the `runtime` directory
17
+ * @param {import('types').ValidatedKitConfig} config
25
18
  */
26
- function copy(from, to, filter = () => true) {
27
- if (!fs.existsSync(from)) return [];
28
- if (!filter(path.basename(from))) return [];
29
-
30
- const files = [];
31
- const stats = fs.statSync(from);
32
-
33
- if (stats.isDirectory()) {
34
- fs.readdirSync(from).forEach((file) => {
35
- files.push(...copy(path.join(from, file), path.join(to, file)));
36
- });
37
- } else {
38
- mkdirp(path.dirname(to));
39
- fs.copyFileSync(from, to);
40
- files.push(to);
19
+ function get_runtime_directory(config) {
20
+ {
21
+ return path__default.join(config.outDir, 'runtime');
41
22
  }
42
-
43
- return files;
44
23
  }
45
24
 
46
- const __filename = fileURLToPath(import.meta.url);
47
- const __dirname = dirname(__filename);
48
-
49
- /** @param {string} dest */
50
- function copy_assets(dest) {
51
- let prefix = '..';
52
- do {
53
- // we jump through these hoops so that this function
54
- // works whether or not it's been bundled
55
- const resolved = resolve(__dirname, `${prefix}/assets`);
56
-
57
- if (existsSync(resolved)) {
58
- copy(resolved, dest);
59
- return;
60
- }
61
-
62
- prefix = `../${prefix}`;
63
- } while (true); // eslint-disable-line
25
+ /** @param {string} str */
26
+ function posixify_path(str) {
27
+ const parsed = path__default.parse(str);
28
+ return `/${parsed.dir.slice(parsed.root.length).split(path__default.sep).join('/')}/${parsed.base}`;
64
29
  }
65
30
 
66
31
  function noop() {}
67
32
 
68
33
  /** @param {{ verbose: boolean }} opts */
69
34
  function logger({ verbose }) {
70
- /** @type {import('../types').Logger} */
35
+ /** @type {import('types').Logger} */
71
36
  const log = (msg) => console.log(msg.replace(/^/gm, ' '));
72
37
 
38
+ /** @param {string} msg */
39
+ const err = (msg) => console.error(msg.replace(/^/gm, ' '));
40
+
73
41
  log.success = (msg) => log($.green(`✔ ${msg}`));
74
- log.error = (msg) => log($.bold().red(msg));
42
+ log.error = (msg) => err($.bold().red(msg));
75
43
  log.warn = (msg) => log($.bold().yellow(msg));
76
44
 
77
45
  log.minor = verbose ? (msg) => log($.grey(msg)) : noop;
@@ -80,4 +48,19 @@ function logger({ verbose }) {
80
48
  return log;
81
49
  }
82
50
 
83
- export { copy as a, copy_assets as c, logger as l, mkdirp as m, rimraf as r };
51
+ /** @param {import('types').ManifestData} manifest_data */
52
+ function get_mime_lookup(manifest_data) {
53
+ /** @type {Record<string, string>} */
54
+ const mime = {};
55
+
56
+ manifest_data.assets.forEach((asset) => {
57
+ if (asset.type) {
58
+ const ext = path__default.extname(asset.file);
59
+ mime[ext] = asset.type;
60
+ }
61
+ });
62
+
63
+ return mime;
64
+ }
65
+
66
+ export { get_runtime_prefix as a, get_mime_lookup as b, get_runtime_directory as g, logger as l };
@@ -0,0 +1,273 @@
1
+ import fs__default from 'fs';
2
+ import path__default from 'path';
3
+ import { $ } from './index.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
+ const reserved = new Set([
37
+ 'do',
38
+ 'if',
39
+ 'in',
40
+ 'for',
41
+ 'let',
42
+ 'new',
43
+ 'try',
44
+ 'var',
45
+ 'case',
46
+ 'else',
47
+ 'enum',
48
+ 'eval',
49
+ 'null',
50
+ 'this',
51
+ 'true',
52
+ 'void',
53
+ 'with',
54
+ 'await',
55
+ 'break',
56
+ 'catch',
57
+ 'class',
58
+ 'const',
59
+ 'false',
60
+ 'super',
61
+ 'throw',
62
+ 'while',
63
+ 'yield',
64
+ 'delete',
65
+ 'export',
66
+ 'import',
67
+ 'public',
68
+ 'return',
69
+ 'static',
70
+ 'switch',
71
+ 'typeof',
72
+ 'default',
73
+ 'extends',
74
+ 'finally',
75
+ 'package',
76
+ 'private',
77
+ 'continue',
78
+ 'debugger',
79
+ 'function',
80
+ 'arguments',
81
+ 'interface',
82
+ 'protected',
83
+ 'implements',
84
+ 'instanceof'
85
+ ]);
86
+
87
+ const valid_identifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
88
+
89
+ /**
90
+ * @param {string} cwd
91
+ * @param {string} file
92
+ */
93
+ function maybe_file(cwd, file) {
94
+ const resolved = path__default.resolve(cwd, file);
95
+ if (fs__default.existsSync(resolved)) {
96
+ return resolved;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * @param {string} file
102
+ */
103
+ function project_relative(file) {
104
+ return posixify(path__default.relative('.', file));
105
+ }
106
+
107
+ /**
108
+ * @param {string} file
109
+ */
110
+ function remove_trailing_slashstar(file) {
111
+ if (file.endsWith('/*')) {
112
+ return file.slice(0, -2);
113
+ } else {
114
+ return file;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Writes the tsconfig that the user's tsconfig inherits from.
120
+ * @param {import('types').ValidatedKitConfig} config
121
+ */
122
+ function write_tsconfig(config, cwd = process.cwd()) {
123
+ const out = path__default.join(config.outDir, 'tsconfig.json');
124
+ const user_file = maybe_file(cwd, 'tsconfig.json') || maybe_file(cwd, 'jsconfig.json');
125
+
126
+ if (user_file) validate(config, cwd, out, user_file);
127
+
128
+ /** @param {string} file */
129
+ const config_relative = (file) => posixify(path__default.relative(config.outDir, file));
130
+
131
+ const include = ['ambient.d.ts'];
132
+ for (const dir of [config.files.routes, config.files.lib]) {
133
+ const relative = project_relative(path__default.dirname(dir));
134
+ include.push(config_relative(`${relative}/**/*.js`));
135
+ include.push(config_relative(`${relative}/**/*.ts`));
136
+ include.push(config_relative(`${relative}/**/*.svelte`));
137
+ }
138
+
139
+ write_if_changed(
140
+ out,
141
+ JSON.stringify(
142
+ {
143
+ compilerOptions: {
144
+ // generated options
145
+ baseUrl: config_relative('.'),
146
+ paths: get_tsconfig_paths(config),
147
+ rootDirs: [config_relative('.'), './types'],
148
+
149
+ // essential options
150
+ // svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
151
+ // to enforce using \`import type\` instead of \`import\` for Types.
152
+ importsNotUsedAsValues: 'error',
153
+ // Vite compiles modules one at a time
154
+ isolatedModules: true,
155
+ // TypeScript doesn't know about import usages in the template because it only sees the
156
+ // script of a Svelte file. Therefore preserve all value imports. Requires TS 4.5 or higher.
157
+ preserveValueImports: true,
158
+
159
+ // This is required for svelte-kit package to work as expected
160
+ // Can be overwritten
161
+ lib: ['esnext', 'DOM', 'DOM.Iterable'],
162
+ moduleResolution: 'node',
163
+ module: 'esnext',
164
+ target: 'esnext'
165
+ },
166
+ include,
167
+ exclude: [config_relative('node_modules/**'), './[!ambient.d.ts]**']
168
+ },
169
+ null,
170
+ '\t'
171
+ )
172
+ );
173
+ }
174
+
175
+ /**
176
+ * @param {import('types').ValidatedKitConfig} config
177
+ * @param {string} cwd
178
+ * @param {string} out
179
+ * @param {string} user_file
180
+ */
181
+ function validate(config, cwd, out, user_file) {
182
+ // we have to eval the file, since it's not parseable as JSON (contains comments)
183
+ const user_tsconfig_json = fs__default.readFileSync(user_file, 'utf-8');
184
+ const user_tsconfig = (0, eval)(`(${user_tsconfig_json})`);
185
+
186
+ // we need to check that the user's tsconfig extends the framework config
187
+ const extend = user_tsconfig.extends;
188
+ const extends_framework_config = extend && path__default.resolve(cwd, extend) === out;
189
+
190
+ const kind = path__default.basename(user_file);
191
+
192
+ if (extends_framework_config) {
193
+ const { paths: user_paths } = user_tsconfig.compilerOptions || {};
194
+
195
+ if (user_paths && fs__default.existsSync(config.files.lib)) {
196
+ /** @type {string[]} */
197
+ const lib = user_paths['$lib'] || [];
198
+ /** @type {string[]} */
199
+ const lib_ = user_paths['$lib/*'] || [];
200
+
201
+ const missing_lib_paths =
202
+ !lib.some((relative) => path__default.resolve(cwd, relative) === config.files.lib) ||
203
+ !lib_.some((relative) => path__default.resolve(cwd, relative) === path__default.join(config.files.lib, '/*'));
204
+
205
+ if (missing_lib_paths) {
206
+ console.warn(
207
+ $
208
+ .bold()
209
+ .yellow(`Your compilerOptions.paths in ${kind} should include the following:`)
210
+ );
211
+ const relative = posixify(path__default.relative('.', config.files.lib));
212
+ console.warn(`{\n "$lib":["${relative}"],\n "$lib/*":["${relative}/*"]\n}`);
213
+ }
214
+ }
215
+ } else {
216
+ let relative = posixify(path__default.relative('.', out));
217
+ if (!relative.startsWith('./')) relative = './' + relative;
218
+
219
+ console.warn(
220
+ $.bold().yellow(`Your ${kind} should extend the configuration generated by SvelteKit:`)
221
+ );
222
+ console.warn(`{\n "extends": "${relative}"\n}`);
223
+ }
224
+ }
225
+
226
+ // <something><optional /*>
227
+ const alias_regex = /^(.+?)(\/\*)?$/;
228
+ // <path><optional /* or .fileending>
229
+ const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
230
+
231
+ /**
232
+ * Generates tsconfig path aliases from kit's aliases.
233
+ * Related to vite alias creation.
234
+ *
235
+ * @param {import('types').ValidatedKitConfig} config
236
+ */
237
+ function get_tsconfig_paths(config) {
238
+ const alias = {
239
+ ...config.alias
240
+ };
241
+ if (fs__default.existsSync(project_relative(config.files.lib))) {
242
+ alias['$lib'] = project_relative(config.files.lib);
243
+ }
244
+
245
+ /** @type {Record<string, string[]>} */
246
+ const paths = {};
247
+
248
+ for (const [key, value] of Object.entries(alias)) {
249
+ const key_match = alias_regex.exec(key);
250
+ if (!key_match) throw new Error(`Invalid alias key: ${key}`);
251
+
252
+ const value_match = value_regex.exec(value);
253
+ if (!value_match) throw new Error(`Invalid alias value: ${value}`);
254
+
255
+ const rel_path = project_relative(remove_trailing_slashstar(value));
256
+ const slashstar = key_match[2];
257
+
258
+ if (slashstar) {
259
+ paths[key] = [rel_path + '/*'];
260
+ } else {
261
+ paths[key] = [rel_path];
262
+ const fileending = value_match[4];
263
+
264
+ if (!fileending && !(key + '/*' in alias)) {
265
+ paths[key + '/*'] = [rel_path + '/*'];
266
+ }
267
+ }
268
+ }
269
+
270
+ return paths;
271
+ }
272
+
273
+ export { write as a, write_tsconfig as b, reserved as r, trim as t, valid_identifier as v, write_if_changed as w };