@sveltejs/kit 1.0.0-next.434 → 1.0.0-next.437
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.
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import { pipeline } from 'stream';
|
|
|
5
5
|
import { promisify } from 'util';
|
|
6
6
|
import { copy, rimraf, mkdirp } from '../../utils/filesystem.js';
|
|
7
7
|
import { generate_manifest } from '../generate_manifest/index.js';
|
|
8
|
+
import { get_path } from '../../utils/routing.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Creates the Builder which is passed to adapters for building the application.
|
|
@@ -23,7 +24,7 @@ export function create_builder({ config, build_data, prerendered, log }) {
|
|
|
23
24
|
/** @param {import('types').RouteData} route */
|
|
24
25
|
// TODO routes should come pre-filtered
|
|
25
26
|
function not_prerendered(route) {
|
|
26
|
-
const path = route.page &&
|
|
27
|
+
const path = route.page && get_path(route.id);
|
|
27
28
|
if (path) {
|
|
28
29
|
return !prerendered_paths.has(path) && !prerendered_paths.has(path + '/');
|
|
29
30
|
}
|
|
@@ -9,6 +9,8 @@ import { crawl } from './crawl.js';
|
|
|
9
9
|
import { escape_html_attr } from '../../utils/escape.js';
|
|
10
10
|
import { logger } from '../utils.js';
|
|
11
11
|
import { load_config } from '../config/index.js';
|
|
12
|
+
import { compact } from '../../utils/array.js';
|
|
13
|
+
import { get_path } from '../../utils/routing.js';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @typedef {import('types').PrerenderErrorHandler} PrerenderErrorHandler
|
|
@@ -341,11 +343,10 @@ export async function prerender() {
|
|
|
341
343
|
if (config.prerender.enabled) {
|
|
342
344
|
for (const entry of config.prerender.entries) {
|
|
343
345
|
if (entry === '*') {
|
|
344
|
-
/** @type {import('types').
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
.filter(Boolean);
|
|
346
|
+
/** @type {import('types').SSRManifest} */
|
|
347
|
+
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
|
|
348
|
+
const { routes } = manifest._;
|
|
349
|
+
const entries = compact(routes.map((route) => route.page && get_path(route.id)));
|
|
349
350
|
|
|
350
351
|
for (const entry of entries) {
|
|
351
352
|
enqueue(null, config.paths.base + entry); // TODO can we pre-normalize these?
|
|
@@ -82,6 +82,7 @@ function create_matchers(config, cwd) {
|
|
|
82
82
|
* @param {string} fallback
|
|
83
83
|
*/
|
|
84
84
|
function create_routes_and_nodes(cwd, config, fallback) {
|
|
85
|
+
/** @type {Map<string, import('types').RouteData>} */
|
|
85
86
|
const route_map = new Map();
|
|
86
87
|
|
|
87
88
|
/** @type {Map<string, import('./types').Part[][]>} */
|
|
@@ -321,7 +322,7 @@ function analyze(project_relative, file, component_extensions, module_extensions
|
|
|
321
322
|
const component_extension = component_extensions.find((ext) => file.endsWith(ext));
|
|
322
323
|
if (component_extension) {
|
|
323
324
|
const name = file.slice(0, -component_extension.length);
|
|
324
|
-
const pattern = /^\+(?:(page(?:@(
|
|
325
|
+
const pattern = /^\+(?:(page(?:@(.*))?)|(layout(?:@(.*))?)|(error))$/;
|
|
325
326
|
const match = pattern.exec(name);
|
|
326
327
|
if (!match) {
|
|
327
328
|
// TODO remove for 1.0
|
|
@@ -104,6 +104,27 @@ export async function render_page(event, route, page, options, state, resolve_op
|
|
|
104
104
|
const should_prerender_data = nodes.some((node) => node?.server);
|
|
105
105
|
const data_pathname = `${event.url.pathname.replace(/\/$/, '')}/__data.json`;
|
|
106
106
|
|
|
107
|
+
// it's crucial that we do this before returning the non-SSR response, otherwise
|
|
108
|
+
// SvelteKit will erroneously believe that the path has been prerendered,
|
|
109
|
+
// causing functions to be omitted from the manifesst generated later
|
|
110
|
+
const should_prerender =
|
|
111
|
+
leaf_node.shared?.prerender ?? leaf_node.server?.prerender ?? options.prerender.default;
|
|
112
|
+
if (should_prerender) {
|
|
113
|
+
const mod = leaf_node.server;
|
|
114
|
+
if (mod && (mod.POST || mod.PUT || mod.DELETE || mod.PATCH)) {
|
|
115
|
+
throw new Error('Cannot prerender pages that have endpoints with mutative methods');
|
|
116
|
+
}
|
|
117
|
+
} else if (state.prerendering) {
|
|
118
|
+
// if the page isn't marked as prerenderable (or is explicitly
|
|
119
|
+
// marked NOT prerenderable, if `prerender.default` is `true`),
|
|
120
|
+
// then bail out at this point
|
|
121
|
+
if (!should_prerender) {
|
|
122
|
+
return new Response(undefined, {
|
|
123
|
+
status: 204
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
107
128
|
if (!resolve_opts.ssr) {
|
|
108
129
|
return await render_response({
|
|
109
130
|
branch: [],
|
|
@@ -123,24 +144,6 @@ export async function render_page(event, route, page, options, state, resolve_op
|
|
|
123
144
|
});
|
|
124
145
|
}
|
|
125
146
|
|
|
126
|
-
const should_prerender =
|
|
127
|
-
leaf_node.shared?.prerender ?? leaf_node.server?.prerender ?? options.prerender.default;
|
|
128
|
-
if (should_prerender) {
|
|
129
|
-
const mod = leaf_node.server;
|
|
130
|
-
if (mod && (mod.POST || mod.PUT || mod.DELETE || mod.PATCH)) {
|
|
131
|
-
throw new Error('Cannot prerender pages that have endpoints with mutative methods');
|
|
132
|
-
}
|
|
133
|
-
} else if (state.prerendering) {
|
|
134
|
-
// if the page isn't marked as prerenderable (or is explicitly
|
|
135
|
-
// marked NOT prerenderable, if `prerender.default` is `true`),
|
|
136
|
-
// then bail out at this point
|
|
137
|
-
if (!should_prerender) {
|
|
138
|
-
return new Response(undefined, {
|
|
139
|
-
status: 204
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
147
|
/** @type {Array<Loaded | null>} */
|
|
145
148
|
let branch = [];
|
|
146
149
|
|
package/src/utils/routing.js
CHANGED
|
@@ -96,6 +96,15 @@ export function affects_path(segment) {
|
|
|
96
96
|
return !/^\([^)]+\)$/.test(segment);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Turns a route ID into a path, if possible
|
|
101
|
+
* @param {string} id
|
|
102
|
+
*/
|
|
103
|
+
export function get_path(id) {
|
|
104
|
+
if (id.includes('[')) return null;
|
|
105
|
+
return `/${id.split('/').filter(affects_path).join('/')}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
99
108
|
/**
|
|
100
109
|
* @param {RegExpMatchArray} match
|
|
101
110
|
* @param {string[]} names
|