@sveltejs/kit 1.2.10 → 1.3.1

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.
@@ -1,4 +1,4 @@
1
- import { OutputAsset, OutputChunk } from 'rollup';
1
+ import { OutputChunk } from 'rollup';
2
2
  import { SvelteComponent } from 'svelte/internal';
3
3
  import {
4
4
  Config,
@@ -7,7 +7,6 @@ import {
7
7
  HandleServerError,
8
8
  KitConfig,
9
9
  Load,
10
- RequestEvent,
11
10
  RequestHandler,
12
11
  ResolveOptions,
13
12
  Server,
@@ -49,22 +48,13 @@ export interface BuildData {
49
48
  app_path: string;
50
49
  manifest_data: ManifestData;
51
50
  service_worker: string | null;
52
- client: {
53
- assets: OutputAsset[];
54
- chunks: OutputChunk[];
55
- entry: {
56
- file: string;
57
- imports: string[];
58
- stylesheets: string[];
59
- fonts: string[];
60
- };
61
- vite_manifest: import('vite').Manifest;
62
- };
63
- server: {
64
- chunks: OutputChunk[];
65
- methods: Record<string, HttpMethod[]>;
66
- vite_manifest: import('vite').Manifest;
67
- };
51
+ client_entry: {
52
+ file: string;
53
+ imports: string[];
54
+ stylesheets: string[];
55
+ fonts: string[];
56
+ } | null;
57
+ server_manifest: import('vite').Manifest;
68
58
  }
69
59
 
70
60
  export interface CSRPageNode {
@@ -73,7 +63,6 @@ export interface CSRPageNode {
73
63
  load?: Load;
74
64
  trailingSlash?: TrailingSlash;
75
65
  };
76
- has_server_load: boolean;
77
66
  }
78
67
 
79
68
  export type CSRPageNodeLoader = () => Promise<CSRPageNode>;
@@ -244,6 +233,17 @@ export interface ServerErrorNode {
244
233
  status?: number;
245
234
  }
246
235
 
236
+ export interface ServerMetadata {
237
+ nodes: Array<{ has_server_load: boolean }>;
238
+ routes: Map<
239
+ string,
240
+ {
241
+ prerender: PrerenderOption | undefined;
242
+ methods: HttpMethod[];
243
+ }
244
+ >;
245
+ }
246
+
247
247
  export interface SSRComponent {
248
248
  default: {
249
249
  render(props: Record<string, any>): {
@@ -261,7 +261,7 @@ export type SSRComponentLoader = () => Promise<SSRComponent>;
261
261
 
262
262
  export interface SSRNode {
263
263
  component: SSRComponentLoader;
264
- /** index into the `components` array in client-manifest.js */
264
+ /** index into the `components` array in client/manifest.js */
265
265
  index: number;
266
266
  /** client-side module URL for this component */
267
267
  file: string;
@@ -1,113 +0,0 @@
1
- import { writeFileSync } from 'fs';
2
- import { join } from 'path';
3
- import { pathToFileURL } from 'url';
4
- import { get_option } from '../../runtime/server/utils.js';
5
- import {
6
- validate_common_exports,
7
- validate_page_server_exports,
8
- validate_server_exports
9
- } from '../../utils/exports.js';
10
- import { load_config } from '../config/index.js';
11
- import { prerender } from './prerender.js';
12
-
13
- const [, , client_out_dir, manifest_path, results_path, verbose, env_json] = process.argv;
14
- const env = JSON.parse(env_json);
15
-
16
- /** @type {import('types').SSRManifest} */
17
- const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
18
-
19
- /** @type {import('types').PrerenderMap} */
20
- const prerender_map = new Map();
21
-
22
- /** @type {import('types').ValidatedKitConfig} */
23
- const config = (await load_config()).kit;
24
-
25
- const server_root = join(config.outDir, 'output');
26
-
27
- /** @type {import('types').ServerInternalModule} */
28
- const internal = await import(pathToFileURL(`${server_root}/server/internal.js`).href);
29
-
30
- /** @type {import('types').ServerModule} */
31
- const { Server } = await import(pathToFileURL(`${server_root}/server/index.js`).href);
32
-
33
- // configure `import { building } from '$app/environment'` —
34
- // essential we do this before analysing the code
35
- internal.set_building(true);
36
-
37
- // set env, in case it's used in initialisation
38
- const entries = Object.entries(env);
39
- const prefix = config.env.publicPrefix;
40
- internal.set_private_env(Object.fromEntries(entries.filter(([k]) => !k.startsWith(prefix))));
41
- internal.set_public_env(Object.fromEntries(entries.filter(([k]) => k.startsWith(prefix))));
42
-
43
- // analyse routes
44
- for (const route of manifest._.routes) {
45
- if (route.endpoint) {
46
- const mod = await route.endpoint();
47
- if (mod.prerender !== undefined) {
48
- validate_server_exports(mod, route.id);
49
-
50
- if (mod.prerender && (mod.POST || mod.PATCH || mod.PUT || mod.DELETE)) {
51
- throw new Error(
52
- `Cannot prerender a +server file with POST, PATCH, PUT, or DELETE (${route.id})`
53
- );
54
- }
55
-
56
- prerender_map.set(route.id, mod.prerender);
57
- }
58
- }
59
-
60
- if (route.page) {
61
- const nodes = await Promise.all(
62
- [...route.page.layouts, route.page.leaf].map((n) => {
63
- if (n !== undefined) return manifest._.nodes[n]();
64
- })
65
- );
66
-
67
- const layouts = nodes.slice(0, -1);
68
- const page = nodes.at(-1);
69
-
70
- for (const layout of layouts) {
71
- if (layout) {
72
- validate_common_exports(layout.server, route.id);
73
- validate_common_exports(layout.universal, route.id);
74
- }
75
- }
76
-
77
- if (page) {
78
- validate_page_server_exports(page.server, route.id);
79
- validate_common_exports(page.universal, route.id);
80
- }
81
-
82
- const should_prerender = get_option(nodes, 'prerender');
83
- const prerender =
84
- should_prerender === true ||
85
- // Try prerendering if ssr is false and no server needed. Set it to 'auto' so that
86
- // the route is not removed from the manifest, there could be a server load function.
87
- // People can opt out of this behavior by explicitly setting prerender to false
88
- (should_prerender !== false && get_option(nodes, 'ssr') === false && !page?.server?.actions
89
- ? 'auto'
90
- : should_prerender ?? false);
91
-
92
- prerender_map.set(route.id, prerender);
93
- }
94
- }
95
-
96
- const { prerendered } = await prerender({
97
- Server,
98
- internal,
99
- manifest,
100
- prerender_map,
101
- client_out_dir,
102
- verbose,
103
- env
104
- });
105
-
106
- writeFileSync(
107
- results_path,
108
- JSON.stringify({ prerendered, prerender_map }, (_key, value) =>
109
- value instanceof Map ? Array.from(value.entries()) : value
110
- )
111
- );
112
-
113
- process.exit(0);
@@ -1,25 +0,0 @@
1
- import { s } from '../../utils/misc.js';
2
- import { relative_path } from '../../utils/filesystem.js';
3
- import { write_if_changed } from './utils.js';
4
-
5
- /**
6
- * @param {import('types').ManifestData} manifest_data
7
- * @param {string} output
8
- */
9
- export function write_matchers(manifest_data, output) {
10
- const imports = [];
11
- const matchers = [];
12
-
13
- for (const key in manifest_data.matchers) {
14
- const src = manifest_data.matchers[key];
15
-
16
- imports.push(`import { match as ${key} } from ${s(relative_path(output, src))};`);
17
- matchers.push(key);
18
- }
19
-
20
- const module = imports.length
21
- ? `${imports.join('\n')}\n\nexport const matchers = { ${matchers.join(', ')} };`
22
- : 'export const matchers = {};';
23
-
24
- write_if_changed(`${output}/client-matchers.js`, module);
25
- }