@sveltejs/kit 1.0.0-next.389 → 1.0.0-next.391

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.
@@ -1596,9 +1596,12 @@ async function render_response({
1596
1596
  const assets =
1597
1597
  options.paths.assets || (segments.length > 0 ? segments.map(() => '..').join('/') : '.');
1598
1598
 
1599
- const html = await resolve_opts.transformPage({
1600
- html: options.template({ head, body, assets, nonce: /** @type {string} */ (csp.nonce) })
1601
- });
1599
+ // TODO flush chunks as early as we can
1600
+ const html =
1601
+ (await resolve_opts.transformPageChunk({
1602
+ html: options.template({ head, body, assets, nonce: /** @type {string} */ (csp.nonce) }),
1603
+ done: true
1604
+ })) || '';
1602
1605
 
1603
1606
  const headers = new Headers({
1604
1607
  'content-type': 'text/html',
@@ -3377,7 +3380,7 @@ async function respond(request, options, state) {
3377
3380
  /** @type {import('types').RequiredResolveOptions} */
3378
3381
  let resolve_opts = {
3379
3382
  ssr: true,
3380
- transformPage: default_transform
3383
+ transformPageChunk: default_transform
3381
3384
  };
3382
3385
 
3383
3386
  // TODO match route before calling handle?
@@ -3387,9 +3390,17 @@ async function respond(request, options, state) {
3387
3390
  event,
3388
3391
  resolve: async (event, opts) => {
3389
3392
  if (opts) {
3393
+ // TODO remove for 1.0
3394
+ // @ts-expect-error
3395
+ if (opts.transformPage) {
3396
+ throw new Error(
3397
+ 'transformPage has been replaced by transformPageChunk — see https://github.com/sveltejs/kit/pull/5657 for more information'
3398
+ );
3399
+ }
3400
+
3390
3401
  resolve_opts = {
3391
3402
  ssr: opts.ssr !== false,
3392
- transformPage: opts.transformPage || default_transform
3403
+ transformPageChunk: opts.transformPageChunk || default_transform
3393
3404
  };
3394
3405
  }
3395
3406
 
@@ -3,7 +3,7 @@ import * as path from 'path';
3
3
  import { join, relative, dirname } from 'path';
4
4
  import { $ } from './error.js';
5
5
  import chokidar from 'chokidar';
6
- import { d as walk$1, m as mkdirp, p as posixify, r as rimraf, b as write_tsconfig, c as copy } from './write_tsconfig.js';
6
+ import { w as walk$1, m as mkdirp, p as posixify, r as rimraf, d as write_tsconfig, c as copy } from './write_tsconfig.js';
7
7
  import { createRequire } from 'module';
8
8
  import 'url';
9
9
 
@@ -2,7 +2,7 @@ import path__default from 'path';
2
2
  import fs__default from 'fs';
3
3
  import { $ } from './error.js';
4
4
  import { fileURLToPath } from 'url';
5
- import { p as posixify, c as copy, w as write_if_changed, t as trim, r as rimraf, a as write, b as write_tsconfig } from './write_tsconfig.js';
5
+ import { p as posixify, c as copy, a as write_if_changed, t as trim, r as rimraf, b as write, d as write_tsconfig } from './write_tsconfig.js';
6
6
 
7
7
  /**
8
8
  * @param typeMap [Object] Map of MIME type -> Array[extensions]
@@ -271,4 +271,4 @@ function validate(config, cwd, out, user_file) {
271
271
  }
272
272
  }
273
273
 
274
- export { write as a, write_tsconfig as b, copy as c, walk as d, mkdirp as m, posixify as p, rimraf as r, trim as t, write_if_changed as w };
274
+ export { write_if_changed as a, write as b, copy as c, write_tsconfig as d, mkdirp as m, posixify as p, rimraf as r, trim as t, walk as w };
package/dist/cli.js CHANGED
@@ -18,7 +18,7 @@ function handle_error(e) {
18
18
  process.exit(1);
19
19
  }
20
20
 
21
- const prog = sade('svelte-kit').version('1.0.0-next.389');
21
+ const prog = sade('svelte-kit').version('1.0.0-next.391');
22
22
 
23
23
  prog
24
24
  .command('package')
package/dist/vite.js CHANGED
@@ -5,7 +5,7 @@ import { a as load_template, $, c as coalesce_to_error, l as load_config } from
5
5
  import { svelte } from '@sveltejs/vite-plugin-svelte';
6
6
  import * as vite from 'vite';
7
7
  import { loadConfigFromFile } from 'vite';
8
- import { p as posixify, m as mkdirp, r as rimraf } from './chunks/write_tsconfig.js';
8
+ import { p as posixify, m as mkdirp, w as walk, r as rimraf } from './chunks/write_tsconfig.js';
9
9
  import { g as get_runtime_directory, s, i as init, a as get_runtime_prefix, u as update, b as get_mime_lookup, p as parse_route_id, c as all, l as logger } from './chunks/sync.js';
10
10
  import { URL as URL$1, pathToFileURL } from 'url';
11
11
  import { installPolyfills } from './node/polyfills.js';
@@ -1134,12 +1134,12 @@ const REDIRECT = 3;
1134
1134
  /**
1135
1135
  * @param {{
1136
1136
  * config: import('types').ValidatedKitConfig;
1137
- * entries: string[];
1138
- * files: Set<string>;
1137
+ * client_out_dir: string;
1138
+ * manifest_path: string;
1139
1139
  * log: Logger;
1140
1140
  * }} opts
1141
1141
  */
1142
- async function prerender({ config, entries, files, log }) {
1142
+ async function prerender({ config, client_out_dir, manifest_path, log }) {
1143
1143
  /** @type {import('types').Prerendered} */
1144
1144
  const prerendered = {
1145
1145
  pages: new Map(),
@@ -1240,6 +1240,7 @@ async function prerender({ config, entries, files, log }) {
1240
1240
  return file;
1241
1241
  }
1242
1242
 
1243
+ const files = new Set(walk(client_out_dir).map(posixify));
1243
1244
  const seen = new Set();
1244
1245
  const written = new Set();
1245
1246
 
@@ -1397,6 +1398,12 @@ async function prerender({ config, entries, files, log }) {
1397
1398
  if (config.prerender.enabled) {
1398
1399
  for (const entry of config.prerender.entries) {
1399
1400
  if (entry === '*') {
1401
+ /** @type {import('types').ManifestData} */
1402
+ const { routes } = (await import(pathToFileURL(manifest_path).href)).manifest._;
1403
+ const entries = routes
1404
+ .map((route) => (route.type === 'page' ? route.path : ''))
1405
+ .filter(Boolean);
1406
+
1400
1407
  for (const entry of entries) {
1401
1408
  enqueue(null, config.paths.base + entry); // TODO can we pre-normalize these?
1402
1409
  }
@@ -2910,6 +2917,9 @@ function kit() {
2910
2917
  /** @type {import('types').BuildData} */
2911
2918
  let build_data;
2912
2919
 
2920
+ /** @type {string | undefined} */
2921
+ let deferred_warning;
2922
+
2913
2923
  /**
2914
2924
  * @type {{
2915
2925
  * build_dir: string;
@@ -2998,7 +3008,8 @@ function kit() {
2998
3008
 
2999
3009
  const new_config = vite_client_build_config();
3000
3010
 
3001
- warn_overridden_config(config, new_config);
3011
+ const warning = warn_overridden_config(config, new_config);
3012
+ if (warning) console.error(warning + '\n');
3002
3013
 
3003
3014
  return new_config;
3004
3015
  }
@@ -3045,7 +3056,8 @@ function kit() {
3045
3056
  }
3046
3057
  }
3047
3058
  };
3048
- warn_overridden_config(config, result);
3059
+
3060
+ deferred_warning = warn_overridden_config(config, result);
3049
3061
  return result;
3050
3062
  },
3051
3063
 
@@ -3112,8 +3124,9 @@ function kit() {
3112
3124
  server
3113
3125
  };
3114
3126
 
3127
+ const manifest_path = `${paths.output_dir}/server/manifest.js`;
3115
3128
  fs__default.writeFileSync(
3116
- `${paths.output_dir}/server/manifest.js`,
3129
+ manifest_path,
3117
3130
  `export const manifest = ${generate_manifest({
3118
3131
  build_data,
3119
3132
  relative_path: '.',
@@ -3124,27 +3137,10 @@ function kit() {
3124
3137
  process.env.SVELTEKIT_SERVER_BUILD_COMPLETED = 'true';
3125
3138
  log.info('Prerendering');
3126
3139
 
3127
- const static_files = manifest_data.assets.map((asset) => posixify(asset.file));
3128
-
3129
- const files = new Set([
3130
- ...static_files,
3131
- ...chunks.map((chunk) => chunk.fileName),
3132
- ...assets.map((chunk) => chunk.fileName)
3133
- ]);
3134
-
3135
- // TODO is this right?
3136
- static_files.forEach((file) => {
3137
- if (file.endsWith('/index.html')) {
3138
- files.add(file.slice(0, -11));
3139
- }
3140
- });
3141
-
3142
3140
  prerendered = await prerender({
3143
3141
  config: svelte_config.kit,
3144
- entries: manifest_data.routes
3145
- .map((route) => (route.type === 'page' ? route.path : ''))
3146
- .filter(Boolean),
3147
- files,
3142
+ client_out_dir: vite_config.build.outDir,
3143
+ manifest_path,
3148
3144
  log
3149
3145
  });
3150
3146
 
@@ -3199,6 +3195,14 @@ function kit() {
3199
3195
  * @see https://vitejs.dev/guide/api-plugin.html#configureserver
3200
3196
  */
3201
3197
  async configureServer(vite) {
3198
+ // This method is called by Vite after clearing the screen.
3199
+ // This patch ensures we can log any important messages afterwards for the user to see.
3200
+ const print_urls = vite.printUrls;
3201
+ vite.printUrls = function () {
3202
+ print_urls.apply(this);
3203
+ if (deferred_warning) console.error('\n' + deferred_warning);
3204
+ };
3205
+
3202
3206
  return await dev(vite, vite_config, svelte_config);
3203
3207
  },
3204
3208
 
@@ -3248,11 +3252,12 @@ function collect_output(bundle) {
3248
3252
  */
3249
3253
  function warn_overridden_config(config, resolved_config) {
3250
3254
  const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);
3255
+
3251
3256
  if (overridden.length > 0) {
3252
- console.log(
3253
- $.bold().red('The following Vite config options will be overridden by SvelteKit:')
3257
+ return (
3258
+ $.bold().red('The following Vite config options will be overridden by SvelteKit:') +
3259
+ overridden.map((key) => `\n - ${key}`).join('')
3254
3260
  );
3255
- console.log(overridden.map((key) => ` - ${key}`).join('\n'));
3256
3261
  }
3257
3262
  }
3258
3263
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.389",
3
+ "version": "1.0.0-next.391",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
package/types/index.d.ts CHANGED
@@ -261,7 +261,7 @@ export interface RequestHandlerOutput<Output = ResponseBody> {
261
261
 
262
262
  export interface ResolveOptions {
263
263
  ssr?: boolean;
264
- transformPage?: ({ html }: { html: string }) => MaybePromise<string>;
264
+ transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
265
265
  }
266
266
 
267
267
  export type ResponseBody = JSONValue | Uint8Array | ReadableStream | Error;