@sveltejs/kit 1.0.0-next.418 → 1.0.0-next.419
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 +1 -2
- package/src/runtime/server/page/index.js +17 -9
- package/src/runtime/server/page/render.js +25 -7
- package/src/vite/build/build_server.js +0 -1
- package/src/vite/build/utils.js +15 -11
- package/src/vite/dev/index.js +0 -1
- package/src/vite/index.js +2 -2
- package/types/internal.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.419",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
|
14
|
-
"chokidar": "^3.5.3",
|
|
15
14
|
"cookie": "^0.5.0",
|
|
16
15
|
"devalue": "^2.0.1",
|
|
17
16
|
"kleur": "^4.1.4",
|
|
@@ -77,7 +77,7 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
if (event.request.method === 'POST' && result?.location) {
|
|
80
|
-
return redirect_response(
|
|
80
|
+
return redirect_response(303, result.location);
|
|
81
81
|
}
|
|
82
82
|
} else {
|
|
83
83
|
event.setHeaders({
|
|
@@ -95,6 +95,9 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
const should_prerender_data = nodes.some((node) => node?.server);
|
|
99
|
+
const data_pathname = `${event.url.pathname.replace(/\/$/, '')}/__data.json`;
|
|
100
|
+
|
|
98
101
|
if (!resolve_opts.ssr) {
|
|
99
102
|
return await render_response({
|
|
100
103
|
branch: [],
|
|
@@ -214,6 +217,16 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
214
217
|
const error = normalize_error(e);
|
|
215
218
|
|
|
216
219
|
if (error instanceof Redirect) {
|
|
220
|
+
if (state.prerendering && should_prerender_data) {
|
|
221
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
222
|
+
response: new Response(undefined),
|
|
223
|
+
body: JSON.stringify({
|
|
224
|
+
type: 'redirect',
|
|
225
|
+
location: error.location
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
217
230
|
return redirect_response(error.status, error.location);
|
|
218
231
|
}
|
|
219
232
|
|
|
@@ -267,19 +280,14 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
267
280
|
}
|
|
268
281
|
}
|
|
269
282
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const pathname = `${event.url.pathname.replace(/\/$/, '')}/__data.json`;
|
|
273
|
-
|
|
274
|
-
const dependency = {
|
|
283
|
+
if (state.prerendering && should_prerender_data) {
|
|
284
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
275
285
|
response: new Response(undefined),
|
|
276
286
|
body: JSON.stringify({
|
|
277
287
|
type: 'data',
|
|
278
288
|
nodes: branch.map((branch_node) => ({ data: branch_node?.server_data }))
|
|
279
289
|
})
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
state.prerendering.dependencies.set(pathname, dependency);
|
|
290
|
+
});
|
|
283
291
|
}
|
|
284
292
|
|
|
285
293
|
// TODO use validation_errors
|
|
@@ -150,9 +150,31 @@ export async function render_response({
|
|
|
150
150
|
|
|
151
151
|
const target = hash(body);
|
|
152
152
|
|
|
153
|
+
/**
|
|
154
|
+
* The prefix to use for static assets. Replaces `%sveltekit.assets%` in the template
|
|
155
|
+
* @type {string}
|
|
156
|
+
*/
|
|
157
|
+
let assets;
|
|
158
|
+
|
|
159
|
+
if (options.paths.assets) {
|
|
160
|
+
// if an asset path is specified, use it
|
|
161
|
+
assets = options.paths.assets;
|
|
162
|
+
} else if (state.prerendering?.fallback) {
|
|
163
|
+
// if we're creating a fallback page, asset paths need to be root-relative
|
|
164
|
+
assets = options.paths.base;
|
|
165
|
+
} else {
|
|
166
|
+
// otherwise we want asset paths to be relative to the page, so that they
|
|
167
|
+
// will work in odd contexts like IPFS, the internet archive, and so on
|
|
168
|
+
const segments = event.url.pathname.slice(options.paths.base.length).split('/').slice(2);
|
|
169
|
+
assets = segments.length > 0 ? segments.map(() => '..').join('/') : '.';
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** @param {string} path */
|
|
173
|
+
const prefixed = (path) => (path.startsWith('/') ? path : `${assets}/${path}`);
|
|
174
|
+
|
|
153
175
|
// prettier-ignore
|
|
154
176
|
const init_app = `
|
|
155
|
-
import { set_public_env, start } from ${s(
|
|
177
|
+
import { set_public_env, start } from ${s(prefixed(entry.file))};
|
|
156
178
|
|
|
157
179
|
set_public_env(${s(options.public_env)});
|
|
158
180
|
|
|
@@ -195,7 +217,7 @@ export async function render_response({
|
|
|
195
217
|
}
|
|
196
218
|
|
|
197
219
|
for (const dep of stylesheets) {
|
|
198
|
-
const path =
|
|
220
|
+
const path = prefixed(dep);
|
|
199
221
|
const attributes = [];
|
|
200
222
|
|
|
201
223
|
if (csp.style_needs_nonce) {
|
|
@@ -217,7 +239,7 @@ export async function render_response({
|
|
|
217
239
|
|
|
218
240
|
if (page_config.router || page_config.hydrate) {
|
|
219
241
|
for (const dep of modulepreloads) {
|
|
220
|
-
const path =
|
|
242
|
+
const path = prefixed(dep);
|
|
221
243
|
link_header_preloads.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
|
|
222
244
|
if (state.prerendering) {
|
|
223
245
|
head += `\n\t<link rel="modulepreload" href="${path}">`;
|
|
@@ -292,10 +314,6 @@ export async function render_response({
|
|
|
292
314
|
}
|
|
293
315
|
}
|
|
294
316
|
|
|
295
|
-
const segments = event.url.pathname.slice(options.paths.base.length).split('/').slice(2);
|
|
296
|
-
const assets =
|
|
297
|
-
options.paths.assets || (segments.length > 0 ? segments.map(() => '..').join('/') : '.');
|
|
298
|
-
|
|
299
317
|
// TODO flush chunks as early as we can
|
|
300
318
|
const html =
|
|
301
319
|
(await resolve_opts.transformPageChunk({
|
package/src/vite/build/utils.js
CHANGED
|
@@ -88,9 +88,11 @@ export function find_deps(manifest, entry, add_dynamic_css) {
|
|
|
88
88
|
* @return {import('vite').UserConfig}
|
|
89
89
|
*/
|
|
90
90
|
export const get_default_config = function ({ config, input, ssr, outDir }) {
|
|
91
|
+
const prefix = `${config.kit.appDir}/immutable`;
|
|
92
|
+
|
|
91
93
|
return {
|
|
92
94
|
appType: 'custom',
|
|
93
|
-
base: assets_base(config.kit),
|
|
95
|
+
base: ssr ? assets_base(config.kit) : './',
|
|
94
96
|
build: {
|
|
95
97
|
cssCodeSplit: true,
|
|
96
98
|
// don't use the default name to avoid collisions with 'static/manifest.json'
|
|
@@ -101,11 +103,9 @@ export const get_default_config = function ({ config, input, ssr, outDir }) {
|
|
|
101
103
|
input,
|
|
102
104
|
output: {
|
|
103
105
|
format: 'esm',
|
|
104
|
-
entryFileNames: ssr ? '[name].js' : `${
|
|
105
|
-
chunkFileNames: ssr
|
|
106
|
-
|
|
107
|
-
: `${config.kit.appDir}/immutable/chunks/[name]-[hash].js`,
|
|
108
|
-
assetFileNames: `${config.kit.appDir}/immutable/assets/[name]-[hash][extname]`
|
|
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
109
|
},
|
|
110
110
|
preserveEntrySignatures: 'strict'
|
|
111
111
|
},
|
|
@@ -125,6 +125,14 @@ export const get_default_config = function ({ config, input, ssr, outDir }) {
|
|
|
125
125
|
},
|
|
126
126
|
ssr: {
|
|
127
127
|
noExternal: ['@sveltejs/kit']
|
|
128
|
+
},
|
|
129
|
+
worker: {
|
|
130
|
+
rollupOptions: {
|
|
131
|
+
output: {
|
|
132
|
+
entryFileNames: `${prefix}/workers/[name]-[hash].js`,
|
|
133
|
+
chunkFileNames: `${prefix}/workers/chunks/[name]-[hash].js`
|
|
134
|
+
}
|
|
135
|
+
}
|
|
128
136
|
}
|
|
129
137
|
};
|
|
130
138
|
};
|
|
@@ -134,11 +142,7 @@ export const get_default_config = function ({ config, input, ssr, outDir }) {
|
|
|
134
142
|
* @returns {string}
|
|
135
143
|
*/
|
|
136
144
|
export function assets_base(config) {
|
|
137
|
-
|
|
138
|
-
// during `svelte-kit preview`, because we use a local asset path. This
|
|
139
|
-
// may be fixed in Vite 3: https://github.com/vitejs/vite/issues/2009
|
|
140
|
-
const { base, assets } = config.paths;
|
|
141
|
-
return `${assets || base}/`;
|
|
145
|
+
return config.paths.assets || config.paths.base || './';
|
|
142
146
|
}
|
|
143
147
|
|
|
144
148
|
const method_names = new Set(['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']);
|
package/src/vite/dev/index.js
CHANGED
|
@@ -432,7 +432,6 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
|
432
432
|
base: svelte_config.kit.paths.base,
|
|
433
433
|
assets
|
|
434
434
|
},
|
|
435
|
-
prefix: '',
|
|
436
435
|
prerender: {
|
|
437
436
|
default: svelte_config.kit.prerender.default,
|
|
438
437
|
enabled: svelte_config.kit.prerender.enabled
|
package/src/vite/index.js
CHANGED
|
@@ -207,7 +207,7 @@ function kit() {
|
|
|
207
207
|
paths = {
|
|
208
208
|
build_dir: `${svelte_config.kit.outDir}/build`,
|
|
209
209
|
output_dir: `${svelte_config.kit.outDir}/output`,
|
|
210
|
-
client_out_dir: `${svelte_config.kit.outDir}/output/client
|
|
210
|
+
client_out_dir: `${svelte_config.kit.outDir}/output/client`
|
|
211
211
|
};
|
|
212
212
|
|
|
213
213
|
illegal_imports = new Set([
|
|
@@ -230,7 +230,7 @@ function kit() {
|
|
|
230
230
|
/** @type {import('vite').UserConfig} */
|
|
231
231
|
const result = {
|
|
232
232
|
appType: 'custom',
|
|
233
|
-
base: '
|
|
233
|
+
base: './',
|
|
234
234
|
build: {
|
|
235
235
|
rollupOptions: {
|
|
236
236
|
// Vite dependency crawler needs an explicit JS entry point
|