@sveltejs/kit 1.0.0-next.43 → 1.0.0-next.430

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 (104) hide show
  1. package/README.md +12 -9
  2. package/package.json +95 -63
  3. package/src/cli.js +112 -0
  4. package/src/core/adapt/builder.js +207 -0
  5. package/src/core/adapt/index.js +19 -0
  6. package/src/core/config/index.js +86 -0
  7. package/src/core/config/options.js +488 -0
  8. package/src/core/config/types.d.ts +1 -0
  9. package/src/core/constants.js +5 -0
  10. package/src/core/env.js +97 -0
  11. package/src/core/generate_manifest/index.js +99 -0
  12. package/src/core/prerender/crawl.js +194 -0
  13. package/src/core/prerender/prerender.js +378 -0
  14. package/src/core/prerender/queue.js +80 -0
  15. package/src/core/sync/create_manifest_data/index.js +506 -0
  16. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  17. package/src/core/sync/sync.js +59 -0
  18. package/src/core/sync/utils.js +44 -0
  19. package/src/core/sync/write_ambient.js +27 -0
  20. package/src/core/sync/write_client_manifest.js +82 -0
  21. package/src/core/sync/write_matchers.js +25 -0
  22. package/src/core/sync/write_root.js +91 -0
  23. package/src/core/sync/write_tsconfig.js +195 -0
  24. package/src/core/sync/write_types.js +775 -0
  25. package/src/core/utils.js +70 -0
  26. package/src/hooks.js +26 -0
  27. package/src/index/index.js +45 -0
  28. package/src/index/private.js +33 -0
  29. package/src/node/index.js +145 -0
  30. package/src/node/polyfills.js +40 -0
  31. package/src/runtime/app/env.js +11 -0
  32. package/src/runtime/app/navigation.js +22 -0
  33. package/src/runtime/app/paths.js +1 -0
  34. package/src/runtime/app/stores.js +102 -0
  35. package/src/runtime/client/ambient.d.ts +17 -0
  36. package/src/runtime/client/client.js +1289 -0
  37. package/src/runtime/client/fetcher.js +60 -0
  38. package/src/runtime/client/parse.js +36 -0
  39. package/src/runtime/client/singletons.js +21 -0
  40. package/src/runtime/client/start.js +46 -0
  41. package/src/runtime/client/types.d.ts +105 -0
  42. package/src/runtime/client/utils.js +113 -0
  43. package/src/runtime/components/error.svelte +16 -0
  44. package/{assets → src/runtime}/components/layout.svelte +0 -0
  45. package/src/runtime/env/dynamic/private.js +1 -0
  46. package/src/runtime/env/dynamic/public.js +1 -0
  47. package/src/runtime/env-private.js +7 -0
  48. package/src/runtime/env-public.js +7 -0
  49. package/src/runtime/env.js +6 -0
  50. package/src/runtime/hash.js +16 -0
  51. package/src/runtime/paths.js +11 -0
  52. package/src/runtime/server/endpoint.js +58 -0
  53. package/src/runtime/server/index.js +448 -0
  54. package/src/runtime/server/page/cookie.js +25 -0
  55. package/src/runtime/server/page/crypto.js +239 -0
  56. package/src/runtime/server/page/csp.js +249 -0
  57. package/src/runtime/server/page/fetch.js +266 -0
  58. package/src/runtime/server/page/index.js +416 -0
  59. package/src/runtime/server/page/load_data.js +135 -0
  60. package/src/runtime/server/page/render.js +362 -0
  61. package/src/runtime/server/page/respond_with_error.js +94 -0
  62. package/src/runtime/server/page/types.d.ts +44 -0
  63. package/src/runtime/server/utils.js +116 -0
  64. package/src/utils/error.js +22 -0
  65. package/src/utils/escape.js +104 -0
  66. package/src/utils/filesystem.js +108 -0
  67. package/src/utils/http.js +55 -0
  68. package/src/utils/misc.js +1 -0
  69. package/src/utils/routing.js +108 -0
  70. package/src/utils/url.js +97 -0
  71. package/src/vite/build/build_server.js +337 -0
  72. package/src/vite/build/build_service_worker.js +90 -0
  73. package/src/vite/build/utils.js +160 -0
  74. package/src/vite/dev/index.js +551 -0
  75. package/src/vite/index.js +574 -0
  76. package/src/vite/preview/index.js +186 -0
  77. package/src/vite/types.d.ts +3 -0
  78. package/src/vite/utils.js +345 -0
  79. package/svelte-kit.js +1 -1
  80. package/types/ambient.d.ts +357 -0
  81. package/types/index.d.ts +343 -0
  82. package/types/internal.d.ts +308 -0
  83. package/types/private.d.ts +209 -0
  84. package/CHANGELOG.md +0 -431
  85. package/assets/components/error.svelte +0 -13
  86. package/assets/runtime/app/env.js +0 -5
  87. package/assets/runtime/app/navigation.js +0 -41
  88. package/assets/runtime/app/paths.js +0 -1
  89. package/assets/runtime/app/stores.js +0 -93
  90. package/assets/runtime/chunks/utils.js +0 -19
  91. package/assets/runtime/internal/singletons.js +0 -23
  92. package/assets/runtime/internal/start.js +0 -770
  93. package/assets/runtime/paths.js +0 -12
  94. package/dist/.DS_Store +0 -0
  95. package/dist/chunks/index.js +0 -3521
  96. package/dist/chunks/index2.js +0 -587
  97. package/dist/chunks/index3.js +0 -246
  98. package/dist/chunks/index4.js +0 -538
  99. package/dist/chunks/index5.js +0 -761
  100. package/dist/chunks/index6.js +0 -322
  101. package/dist/chunks/standard.js +0 -99
  102. package/dist/chunks/utils.js +0 -83
  103. package/dist/cli.js +0 -546
  104. package/dist/ssr.js +0 -2581
@@ -0,0 +1,337 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { mkdirp, posixify } from '../../utils/filesystem.js';
4
+ import { get_vite_config, merge_vite_configs, resolve_entry } from '../utils.js';
5
+ import { load_template } from '../../core/config/index.js';
6
+ import { runtime_directory } from '../../core/utils.js';
7
+ import { create_build, find_deps, get_default_build_config, is_http_method } from './utils.js';
8
+ import { s } from '../../utils/misc.js';
9
+
10
+ /**
11
+ * @param {{
12
+ * hooks: string;
13
+ * config: import('types').ValidatedConfig;
14
+ * has_service_worker: boolean;
15
+ * runtime: string;
16
+ * template: string;
17
+ * }} opts
18
+ */
19
+ const server_template = ({ config, hooks, has_service_worker, runtime, template }) => `
20
+ import root from '__GENERATED__/root.svelte';
21
+ import { respond } from '${runtime}/server/index.js';
22
+ import { set_paths, assets, base } from '${runtime}/paths.js';
23
+ import { set_prerendering } from '${runtime}/env.js';
24
+ import { set_private_env } from '${runtime}/env-private.js';
25
+ import { set_public_env } from '${runtime}/env-public.js';
26
+
27
+ const template = ({ head, body, assets, nonce }) => ${s(template)
28
+ .replace('%sveltekit.head%', '" + head + "')
29
+ .replace('%sveltekit.body%', '" + body + "')
30
+ .replace(/%sveltekit\.assets%/g, '" + assets + "')
31
+ .replace(/%sveltekit\.nonce%/g, '" + nonce + "')};
32
+
33
+ let read = null;
34
+
35
+ set_paths(${s(config.kit.paths)});
36
+
37
+ let default_protocol = 'https';
38
+
39
+ // allow paths to be globally overridden
40
+ // in svelte-kit preview and in prerendering
41
+ export function override(settings) {
42
+ default_protocol = settings.protocol || default_protocol;
43
+ set_paths(settings.paths);
44
+ set_prerendering(settings.prerendering);
45
+ read = settings.read;
46
+ }
47
+
48
+ export class Server {
49
+ constructor(manifest) {
50
+ this.options = {
51
+ csp: ${s(config.kit.csp)},
52
+ dev: false,
53
+ get_stack: error => String(error), // for security
54
+ handle_error: (error, event) => {
55
+ this.options.hooks.handleError({
56
+ error,
57
+ event,
58
+
59
+ // TODO remove for 1.0
60
+ // @ts-expect-error
61
+ get request() {
62
+ throw new Error('request in handleError has been replaced with event. See https://github.com/sveltejs/kit/pull/3384 for details');
63
+ }
64
+ });
65
+ error.stack = this.options.get_stack(error);
66
+ },
67
+ hooks: null,
68
+ hydrate: ${s(config.kit.browser.hydrate)},
69
+ manifest,
70
+ method_override: ${s(config.kit.methodOverride)},
71
+ paths: { base, assets },
72
+ prerender: {
73
+ default: ${config.kit.prerender.default},
74
+ enabled: ${config.kit.prerender.enabled}
75
+ },
76
+ public_env: {},
77
+ read,
78
+ root,
79
+ service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
80
+ router: ${s(config.kit.browser.router)},
81
+ template,
82
+ template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
83
+ trailing_slash: ${s(config.kit.trailingSlash)}
84
+ };
85
+ }
86
+
87
+ init({ env }) {
88
+ const entries = Object.entries(env);
89
+
90
+ const prv = Object.fromEntries(entries.filter(([k]) => !k.startsWith('${
91
+ config.kit.env.publicPrefix
92
+ }')));
93
+
94
+ const pub = Object.fromEntries(entries.filter(([k]) => k.startsWith('${
95
+ config.kit.env.publicPrefix
96
+ }')));
97
+
98
+ set_private_env(prv);
99
+ set_public_env(pub);
100
+
101
+ this.options.public_env = pub;
102
+ }
103
+
104
+ async respond(request, options = {}) {
105
+ if (!(request instanceof Request)) {
106
+ throw new Error('The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
107
+ }
108
+
109
+ if (!this.options.hooks) {
110
+ const module = await import(${s(hooks)});
111
+ this.options.hooks = {
112
+ handle: module.handle || (({ event, resolve }) => resolve(event)),
113
+ handleError: module.handleError || (({ error }) => console.error(error.stack)),
114
+ externalFetch: module.externalFetch || fetch
115
+ };
116
+ }
117
+
118
+ return respond(request, this.options, options);
119
+ }
120
+ }
121
+ `;
122
+
123
+ /**
124
+ * @param {{
125
+ * cwd: string;
126
+ * config: import('types').ValidatedConfig;
127
+ * vite_config: import('vite').ResolvedConfig;
128
+ * vite_config_env: import('vite').ConfigEnv;
129
+ * manifest_data: import('types').ManifestData;
130
+ * build_dir: string;
131
+ * output_dir: string;
132
+ * service_worker_entry_file: string | null;
133
+ * }} options
134
+ * @param {{ vite_manifest: import('vite').Manifest, assets: import('rollup').OutputAsset[] }} client
135
+ */
136
+ export async function build_server(options, client) {
137
+ const {
138
+ cwd,
139
+ config,
140
+ vite_config,
141
+ vite_config_env,
142
+ manifest_data,
143
+ build_dir,
144
+ output_dir,
145
+ service_worker_entry_file
146
+ } = options;
147
+
148
+ let hooks_file = resolve_entry(config.kit.files.hooks);
149
+ if (!hooks_file || !fs.existsSync(hooks_file)) {
150
+ hooks_file = path.join(config.kit.outDir, 'build/hooks.js');
151
+ fs.writeFileSync(hooks_file, '');
152
+ }
153
+
154
+ /** @type {Record<string, string>} */
155
+ const input = {
156
+ index: `${build_dir}/index.js`
157
+ };
158
+
159
+ // add entry points for every endpoint...
160
+ manifest_data.routes.forEach((route) => {
161
+ if (route.type === 'endpoint') {
162
+ const resolved = path.resolve(cwd, route.file);
163
+ const relative = decodeURIComponent(path.relative(config.kit.files.routes, resolved));
164
+ const name = posixify(path.join('entries/endpoints', relative.replace(/\.js$/, '')));
165
+ input[name] = resolved;
166
+ }
167
+ });
168
+
169
+ // ...and every component used by pages...
170
+ manifest_data.nodes.forEach((node) => {
171
+ for (const file of [node.component, node.shared, node.server]) {
172
+ if (file) {
173
+ const resolved = path.resolve(cwd, file);
174
+ const relative = decodeURIComponent(path.relative(config.kit.files.routes, resolved));
175
+
176
+ const name = relative.startsWith('..')
177
+ ? posixify(path.join('entries/fallbacks', path.basename(file)))
178
+ : posixify(path.join('entries/pages', relative.replace(/\.js$/, '')));
179
+ input[name] = resolved;
180
+ }
181
+ }
182
+ });
183
+
184
+ // ...and every matcher
185
+ Object.entries(manifest_data.matchers).forEach(([key, file]) => {
186
+ const name = posixify(path.join('entries/matchers', key));
187
+ input[name] = path.resolve(cwd, file);
188
+ });
189
+
190
+ /** @type {(file: string) => string} */
191
+ const app_relative = (file) => {
192
+ const relative_file = path.relative(build_dir, path.resolve(cwd, file));
193
+ return relative_file[0] === '.' ? relative_file : `./${relative_file}`;
194
+ };
195
+
196
+ fs.writeFileSync(
197
+ input.index,
198
+ server_template({
199
+ config,
200
+ hooks: app_relative(hooks_file),
201
+ has_service_worker: config.kit.serviceWorker.register && !!service_worker_entry_file,
202
+ runtime: posixify(path.relative(build_dir, runtime_directory)),
203
+ template: load_template(cwd, config)
204
+ })
205
+ );
206
+
207
+ const merged_config = merge_vite_configs(
208
+ get_default_build_config({ config, input, ssr: true, outDir: `${output_dir}/server` }),
209
+ await get_vite_config(vite_config, vite_config_env)
210
+ );
211
+
212
+ const { chunks } = await create_build(merged_config);
213
+
214
+ /** @type {import('vite').Manifest} */
215
+ const vite_manifest = JSON.parse(
216
+ fs.readFileSync(`${output_dir}/server/${vite_config.build.manifest}`, 'utf-8')
217
+ );
218
+
219
+ mkdirp(`${output_dir}/server/nodes`);
220
+ mkdirp(`${output_dir}/server/stylesheets`);
221
+
222
+ const stylesheet_lookup = new Map();
223
+
224
+ client.assets.forEach((asset) => {
225
+ if (asset.fileName.endsWith('.css')) {
226
+ if (asset.source.length < config.kit.inlineStyleThreshold) {
227
+ const index = stylesheet_lookup.size;
228
+ const file = `${output_dir}/server/stylesheets/${index}.js`;
229
+
230
+ fs.writeFileSync(file, `// ${asset.fileName}\nexport default ${s(asset.source)};`);
231
+ stylesheet_lookup.set(asset.fileName, index);
232
+ }
233
+ }
234
+ });
235
+
236
+ manifest_data.nodes.forEach((node, i) => {
237
+ /** @type {string[]} */
238
+ const imports = [];
239
+
240
+ // String representation of
241
+ /** @type {import('types').SSRNode} */
242
+ /** @type {string[]} */
243
+ const exports = [`export const index = ${i};`];
244
+
245
+ /** @type {string[]} */
246
+ const imported = [];
247
+
248
+ /** @type {string[]} */
249
+ const stylesheets = [];
250
+
251
+ if (node.component) {
252
+ const entry = find_deps(client.vite_manifest, node.component, true);
253
+
254
+ imported.push(...entry.imports);
255
+ stylesheets.push(...entry.stylesheets);
256
+
257
+ exports.push(
258
+ `export const component = async () => (await import('../${
259
+ vite_manifest[node.component].file
260
+ }')).default;`,
261
+ `export const file = '${entry.file}';` // TODO what is this?
262
+ );
263
+ }
264
+
265
+ if (node.shared) {
266
+ const entry = find_deps(client.vite_manifest, node.shared, true);
267
+
268
+ imported.push(...entry.imports);
269
+ stylesheets.push(...entry.stylesheets);
270
+
271
+ imports.push(`import * as shared from '../${vite_manifest[node.shared].file}';`);
272
+ exports.push(`export { shared };`);
273
+ }
274
+
275
+ if (node.server) {
276
+ imports.push(`import * as server from '../${vite_manifest[node.server].file}';`);
277
+ exports.push(`export { server };`);
278
+ }
279
+
280
+ exports.push(
281
+ `export const imports = ${s(imported)};`,
282
+ `export const stylesheets = ${s(stylesheets)};`
283
+ );
284
+
285
+ /** @type {string[]} */
286
+ const styles = [];
287
+
288
+ stylesheets.forEach((file) => {
289
+ if (stylesheet_lookup.has(file)) {
290
+ const index = stylesheet_lookup.get(file);
291
+ const name = `stylesheet_${index}`;
292
+ imports.push(`import ${name} from '../stylesheets/${index}.js';`);
293
+ styles.push(`\t${s(file)}: ${name}`);
294
+ }
295
+ });
296
+
297
+ if (styles.length > 0) {
298
+ exports.push(`export const inline_styles = () => ({\n${styles.join(',\n')}\n});`);
299
+ }
300
+
301
+ const out = `${output_dir}/server/nodes/${i}.js`;
302
+ fs.writeFileSync(out, `${imports.join('\n')}\n\n${exports.join('\n')}\n`);
303
+ });
304
+
305
+ return {
306
+ chunks,
307
+ vite_manifest,
308
+ methods: get_methods(cwd, chunks, manifest_data)
309
+ };
310
+ }
311
+
312
+ /**
313
+ * @param {string} cwd
314
+ * @param {import('rollup').OutputChunk[]} output
315
+ * @param {import('types').ManifestData} manifest_data
316
+ */
317
+ function get_methods(cwd, output, manifest_data) {
318
+ /** @type {Record<string, string[]>} */
319
+ const lookup = {};
320
+ output.forEach((chunk) => {
321
+ if (!chunk.facadeModuleId) return;
322
+ const id = chunk.facadeModuleId.slice(cwd.length + 1);
323
+ lookup[id] = chunk.exports;
324
+ });
325
+
326
+ /** @type {Record<string, import('types').HttpMethod[]>} */
327
+ const methods = {};
328
+ manifest_data.routes.forEach((route) => {
329
+ const file = route.type === 'endpoint' ? route.file : route.leaf.server;
330
+
331
+ if (file && lookup[file]) {
332
+ methods[file] = lookup[file].filter(is_http_method);
333
+ }
334
+ });
335
+
336
+ return methods;
337
+ }
@@ -0,0 +1,90 @@
1
+ import fs from 'fs';
2
+ import * as vite from 'vite';
3
+ import { s } from '../../utils/misc.js';
4
+ import { assets_base } from './utils.js';
5
+
6
+ /**
7
+ * @param {{
8
+ * config: import('types').ValidatedConfig;
9
+ * vite_config: import('vite').ResolvedConfig;
10
+ * vite_config_env: import('vite').ConfigEnv;
11
+ * manifest_data: import('types').ManifestData;
12
+ * output_dir: string;
13
+ * service_worker_entry_file: string | null;
14
+ * }} options
15
+ * @param {import('types').Prerendered} prerendered
16
+ * @param {import('vite').Manifest} client_manifest
17
+ */
18
+ export async function build_service_worker(
19
+ { config, manifest_data, output_dir, service_worker_entry_file },
20
+ prerendered,
21
+ client_manifest
22
+ ) {
23
+ const build = new Set();
24
+ for (const key in client_manifest) {
25
+ const { file, css = [], assets = [] } = client_manifest[key];
26
+ build.add(file);
27
+ css.forEach((file) => build.add(file));
28
+ assets.forEach((file) => build.add(file));
29
+ }
30
+
31
+ const service_worker = `${config.kit.outDir}/generated/service-worker.js`;
32
+
33
+ fs.writeFileSync(
34
+ service_worker,
35
+ `
36
+ // TODO remove for 1.0
37
+ export const timestamp = {
38
+ toString: () => {
39
+ throw new Error('\`timestamp\` has been removed from $service-worker. Use \`version\` instead');
40
+ }
41
+ };
42
+
43
+ export const build = [
44
+ ${Array.from(build)
45
+ .map((file) => `${s(`${config.kit.paths.base}/${file}`)}`)
46
+ .join(',\n\t\t\t\t')}
47
+ ];
48
+
49
+ export const files = [
50
+ ${manifest_data.assets
51
+ .filter((asset) => config.kit.serviceWorker.files(asset.file))
52
+ .map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`)
53
+ .join(',\n\t\t\t\t')}
54
+ ];
55
+
56
+ export const prerendered = [
57
+ ${prerendered.paths.map((path) => s(path)).join(',\n\t\t\t\t')}
58
+ ];
59
+
60
+ export const version = ${s(config.kit.version.name)};
61
+ `
62
+ .replace(/^\t{3}/gm, '')
63
+ .trim()
64
+ );
65
+
66
+ await vite.build({
67
+ base: assets_base(config.kit),
68
+ build: {
69
+ lib: {
70
+ entry: /** @type {string} */ (service_worker_entry_file),
71
+ name: 'app',
72
+ formats: ['es']
73
+ },
74
+ rollupOptions: {
75
+ output: {
76
+ entryFileNames: 'service-worker.js'
77
+ }
78
+ },
79
+ outDir: `${output_dir}/client`,
80
+ emptyOutDir: false
81
+ },
82
+ configFile: false,
83
+ resolve: {
84
+ alias: {
85
+ '$service-worker': service_worker,
86
+ $lib: config.kit.files.lib
87
+ }
88
+ }
89
+ });
90
+ }
@@ -0,0 +1,160 @@
1
+ import * as vite from 'vite';
2
+ import { get_aliases } from '../utils.js';
3
+
4
+ /**
5
+ * @typedef {import('rollup').RollupOutput} RollupOutput
6
+ * @typedef {import('rollup').OutputChunk} OutputChunk
7
+ * @typedef {import('rollup').OutputAsset} OutputAsset
8
+ */
9
+
10
+ /**
11
+ * Invokes Vite.
12
+ * @param {import('vite').UserConfig} config
13
+ */
14
+ export async function create_build(config) {
15
+ const { output } = /** @type {RollupOutput} */ (
16
+ await vite.build({ ...config, configFile: false })
17
+ );
18
+
19
+ const chunks = output.filter(
20
+ /** @returns {output is OutputChunk} */ (output) => output.type === 'chunk'
21
+ );
22
+
23
+ const assets = output.filter(
24
+ /** @returns {output is OutputAsset} */ (output) => output.type === 'asset'
25
+ );
26
+
27
+ return { chunks, assets };
28
+ }
29
+
30
+ /**
31
+ * Adds transitive JS and CSS dependencies to the js and css inputs.
32
+ * @param {import('vite').Manifest} manifest
33
+ * @param {string} entry
34
+ * @param {boolean} add_dynamic_css
35
+ */
36
+ export function find_deps(manifest, entry, add_dynamic_css) {
37
+ /** @type {Set<string>} */
38
+ const seen = new Set();
39
+
40
+ /** @type {Set<string>} */
41
+ const imports = new Set();
42
+
43
+ /** @type {Set<string>} */
44
+ const stylesheets = new Set();
45
+
46
+ /**
47
+ * @param {string} file
48
+ * @param {boolean} add_js
49
+ */
50
+ function traverse(file, add_js) {
51
+ if (seen.has(file)) return;
52
+ seen.add(file);
53
+
54
+ const chunk = manifest[file];
55
+
56
+ if (add_js) imports.add(chunk.file);
57
+
58
+ if (chunk.css) {
59
+ chunk.css.forEach((file) => stylesheets.add(file));
60
+ }
61
+
62
+ if (chunk.imports) {
63
+ chunk.imports.forEach((file) => traverse(file, add_js));
64
+ }
65
+
66
+ if (add_dynamic_css && chunk.dynamicImports) {
67
+ chunk.dynamicImports.forEach((file) => traverse(file, false));
68
+ }
69
+ }
70
+
71
+ traverse(entry, true);
72
+
73
+ return {
74
+ file: manifest[entry].file,
75
+ imports: Array.from(imports),
76
+ stylesheets: Array.from(stylesheets)
77
+ };
78
+ }
79
+
80
+ /**
81
+ * The Vite configuration that we use by default.
82
+ * @param {{
83
+ * config: import('types').ValidatedConfig;
84
+ * input: Record<string, string>;
85
+ * ssr: boolean;
86
+ * outDir: string;
87
+ * }} options
88
+ * @return {import('vite').UserConfig}
89
+ */
90
+ export function get_default_build_config({ config, input, ssr, outDir }) {
91
+ const prefix = `${config.kit.appDir}/immutable`;
92
+
93
+ return {
94
+ appType: 'custom',
95
+ base: ssr ? assets_base(config.kit) : './',
96
+ build: {
97
+ cssCodeSplit: true,
98
+ // don't use the default name to avoid collisions with 'static/manifest.json'
99
+ manifest: 'vite-manifest.json',
100
+ outDir,
101
+ polyfillModulePreload: false,
102
+ rollupOptions: {
103
+ input,
104
+ output: {
105
+ format: 'esm',
106
+ entryFileNames: ssr ? '[name].js' : `${prefix}/[name]-[hash].js`,
107
+ chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name]-[hash].js`,
108
+ assetFileNames: `${prefix}/assets/[name]-[hash][extname]`
109
+ },
110
+ preserveEntrySignatures: 'strict'
111
+ },
112
+ ssr,
113
+ target: ssr ? 'node14.8' : undefined
114
+ },
115
+ define: {
116
+ __SVELTEKIT_ADAPTER_NAME__: JSON.stringify(config.kit.adapter?.name),
117
+ __SVELTEKIT_APP_VERSION__: JSON.stringify(config.kit.version.name),
118
+ __SVELTEKIT_APP_VERSION_FILE__: JSON.stringify(`${config.kit.appDir}/version.json`),
119
+ __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
120
+ __SVELTEKIT_DEV__: 'false'
121
+ },
122
+ publicDir: ssr ? false : config.kit.files.assets,
123
+ resolve: {
124
+ alias: get_aliases(config.kit)
125
+ },
126
+ optimizeDeps: {
127
+ exclude: ['@sveltejs/kit']
128
+ },
129
+ ssr: {
130
+ noExternal: ['@sveltejs/kit']
131
+ },
132
+ worker: {
133
+ rollupOptions: {
134
+ output: {
135
+ entryFileNames: `${prefix}/workers/[name]-[hash].js`,
136
+ chunkFileNames: `${prefix}/workers/chunks/[name]-[hash].js`
137
+ }
138
+ }
139
+ }
140
+ };
141
+ }
142
+
143
+ /**
144
+ * @param {import('types').ValidatedKitConfig} config
145
+ * @returns {string}
146
+ */
147
+ export function assets_base(config) {
148
+ return config.paths.assets || config.paths.base || './';
149
+ }
150
+
151
+ const method_names = new Set(['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']);
152
+
153
+ // If we'd written this in TypeScript, it could be easy...
154
+ /**
155
+ * @param {string} str
156
+ * @returns {str is import('types').HttpMethod}
157
+ */
158
+ export function is_http_method(str) {
159
+ return method_names.has(str);
160
+ }