@sveltejs/kit 1.0.0-next.342 → 1.0.0-next.345

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.
@@ -1668,7 +1668,7 @@ function create_client({ target, session, base, trailing_slash }) {
1668
1668
  }
1669
1669
 
1670
1670
  const node = await load_node({
1671
- module: await nodes[i],
1671
+ module: await components[nodes[i]](),
1672
1672
  url,
1673
1673
  params,
1674
1674
  stuff,
@@ -1750,7 +1750,7 @@ function create_client({ target, session, base, trailing_slash }) {
1750
1750
  * hydrate: {
1751
1751
  * status: number;
1752
1752
  * error: Error;
1753
- * nodes: Array<Promise<import('types').CSRComponent>>;
1753
+ * nodes: number[];
1754
1754
  * params: Record<string, string>;
1755
1755
  * routeId: string | null;
1756
1756
  * };
@@ -1231,11 +1231,7 @@ async function render_response({
1231
1231
  hydrate: ${resolve_opts.ssr && page_config.hydrate ? `{
1232
1232
  status: ${status},
1233
1233
  error: ${serialize_error(error)},
1234
- nodes: [
1235
- ${(branch || [])
1236
- .map(({ node }) => `import(${s(options.prefix + node.entry)})`)
1237
- .join(',\n\t\t\t\t\t\t')}
1238
- ],
1234
+ nodes: [${branch.map(({ node }) => node.index).join(', ')}],
1239
1235
  params: ${devalue(event.params)},
1240
1236
  routeId: ${s(event.routeId)}
1241
1237
  }` : 'null'}
@@ -2,12 +2,12 @@ import path__default from 'path';
2
2
  import { svelte } from '@sveltejs/vite-plugin-svelte';
3
3
  import * as vite from 'vite';
4
4
  import { d as deep_merge } from './object.js';
5
- import { g as get_runtime_path, r as resolve_entry, $, l as load_template, c as coalesce_to_error, a as get_mime_lookup, b as get_aliases, p as print_config_conflicts } from '../cli.js';
5
+ import { g as get_runtime_path, r as resolve_entry, $, l as load_template, c as coalesce_to_error, a as get_mime_lookup, b as load_config, d as get_aliases, p as print_config_conflicts } from '../cli.js';
6
6
  import fs__default from 'fs';
7
7
  import { URL } from 'url';
8
8
  import { S as SVELTE_KIT_ASSETS, s as sirv } from './constants.js';
9
9
  import { installPolyfills } from '../node/polyfills.js';
10
- import { update, init } from './sync.js';
10
+ import { init, update } from './sync.js';
11
11
  import { getRequest, setResponse } from '../node.js';
12
12
  import { p as posixify } from './filesystem.js';
13
13
  import { p as parse_route_id } from './misc.js';
@@ -38,19 +38,21 @@ const cwd$1 = process.cwd();
38
38
  * @returns {Promise<import('vite').Plugin>}
39
39
  */
40
40
  async function create_plugin(config) {
41
- const runtime = get_runtime_path(config);
42
-
43
- process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = '0';
44
-
45
- /** @type {import('types').Respond} */
46
- const respond = (await import(`${runtime}/server/index.js`)).respond;
47
-
48
41
  return {
49
42
  name: 'vite-plugin-svelte-kit',
50
43
 
51
- configureServer(vite) {
44
+ async configureServer(vite) {
52
45
  installPolyfills();
53
46
 
47
+ init(config);
48
+
49
+ const runtime = get_runtime_path(config);
50
+
51
+ process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = '0';
52
+
53
+ /** @type {import('types').Respond} */
54
+ const respond = (await import(`${runtime}/server/index.js`)).respond;
55
+
54
56
  /** @type {import('types').SSRManifest} */
55
57
  let manifest;
56
58
 
@@ -67,7 +69,7 @@ async function create_plugin(config) {
67
69
  css: [],
68
70
  js: []
69
71
  },
70
- nodes: manifest_data.components.map((id) => {
72
+ nodes: manifest_data.components.map((id, index) => {
71
73
  return async () => {
72
74
  const url = id.startsWith('..') ? `/@fs${path__default.posix.resolve(id)}` : `/${id}`;
73
75
 
@@ -105,6 +107,7 @@ async function create_plugin(config) {
105
107
 
106
108
  return {
107
109
  module,
110
+ index,
108
111
  entry: url.endsWith('.svelte') ? url : url + '?import',
109
112
  css: [],
110
113
  js: [],
@@ -175,8 +178,13 @@ async function create_plugin(config) {
175
178
 
176
179
  update_manifest();
177
180
 
178
- vite.watcher.on('add', update_manifest);
179
- vite.watcher.on('unlink', update_manifest);
181
+ for (const event of ['add', 'unlink']) {
182
+ vite.watcher.on(event, (file) => {
183
+ if (file.startsWith(config.kit.files.routes + path__default.sep)) {
184
+ update_manifest();
185
+ }
186
+ });
187
+ }
180
188
 
181
189
  const assets = config.kit.paths.assets ? SVELTE_KIT_ASSETS : config.kit.paths.base;
182
190
  const asset_server = sirv(config.kit.files.assets, {
@@ -451,14 +459,14 @@ const cwd = process.cwd();
451
459
  * port: number,
452
460
  * host?: string,
453
461
  * https: boolean,
454
- * config: import('types').ValidatedConfig
455
462
  * }} Options
456
463
  * @typedef {import('types').SSRComponent} SSRComponent
457
464
  */
458
465
 
459
466
  /** @param {Options} opts */
460
- async function dev({ port, host, https, config }) {
461
- init(config);
467
+ async function dev({ port, host, https }) {
468
+ /** @type {import('types').ValidatedConfig} */
469
+ const config = await load_config();
462
470
 
463
471
  const [vite_config] = deep_merge(
464
472
  {
@@ -535,14 +543,9 @@ async function dev({ port, host, https, config }) {
535
543
  const server = await vite.createServer(merged_config);
536
544
  await server.listen(port);
537
545
 
538
- const address_info = /** @type {import('net').AddressInfo} */ (
539
- /** @type {import('http').Server} */ (server.httpServer).address()
540
- );
541
-
542
546
  return {
543
- address_info,
544
- server_config: vite_config.server,
545
- close: () => server.close()
547
+ server,
548
+ config
546
549
  };
547
550
  }
548
551
 
@@ -2,7 +2,7 @@ import fs__default, { readFileSync, writeFileSync } from 'fs';
2
2
  import path__default, { join, dirname } from 'path';
3
3
  import { p as posixify, m as mkdirp, r as rimraf } from './filesystem.js';
4
4
  import { all } from './sync.js';
5
- import { p as print_config_conflicts, b as get_aliases, r as resolve_entry, g as get_runtime_path, l as load_template } from '../cli.js';
5
+ import { p as print_config_conflicts, d as get_aliases, r as resolve_entry, g as get_runtime_path, l as load_template } from '../cli.js';
6
6
  import { g as generate_manifest } from './index3.js';
7
7
  import * as vite from 'vite';
8
8
  import { s } from './misc.js';
@@ -118,7 +118,7 @@ async function build_service_worker(
118
118
 
119
119
  export const build = [
120
120
  ${Array.from(build)
121
- .map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
121
+ .map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/immutable/${file}`)}`)
122
122
  .join(',\n\t\t\t\t')}
123
123
  ];
124
124
 
@@ -267,7 +267,7 @@ async function build_client({
267
267
  build: {
268
268
  cssCodeSplit: true,
269
269
  manifest: true,
270
- outDir: client_out_dir,
270
+ outDir: `${client_out_dir}/immutable`,
271
271
  polyfillDynamicImport: false,
272
272
  rollupOptions: {
273
273
  input,
@@ -303,7 +303,9 @@ async function build_client({
303
303
  const { chunks, assets } = await create_build(merged_config);
304
304
 
305
305
  /** @type {import('vite').Manifest} */
306
- const vite_manifest = JSON.parse(fs__default.readFileSync(`${client_out_dir}/manifest.json`, 'utf-8'));
306
+ const vite_manifest = JSON.parse(
307
+ fs__default.readFileSync(`${client_out_dir}/immutable/manifest.json`, 'utf-8')
308
+ );
307
309
 
308
310
  const entry = posixify(client_entry_file);
309
311
  const entry_js = new Set();
@@ -388,7 +390,7 @@ export class Server {
388
390
  manifest,
389
391
  method_override: ${s(config.kit.methodOverride)},
390
392
  paths: { base, assets },
391
- prefix: assets + '/${config.kit.appDir}/',
393
+ prefix: assets + '/${config.kit.appDir}/immutable/',
392
394
  prerender: {
393
395
  default: ${config.kit.prerender.default},
394
396
  enabled: ${config.kit.prerender.enabled}
@@ -598,6 +600,7 @@ async function build_server(
598
600
 
599
601
  const exports = [
600
602
  'export { module };',
603
+ `export const index = ${i};`,
601
604
  `export const entry = '${client.vite_manifest[component].file}';`,
602
605
  `export const js = ${s(Array.from(js))};`,
603
606
  `export const css = ${s(Array.from(css))};`
@@ -1312,15 +1315,18 @@ async function build(config, { log }) {
1312
1315
 
1313
1316
  const { manifest_data } = all(config);
1314
1317
 
1318
+ // TODO this is so that Vite's preloading works. Unfortunately, it fails
1319
+ // during `svelte-kit preview`, because we use a local asset path. If Vite
1320
+ // used relative paths, I _think_ this could get fixed. Issue here:
1321
+ // https://github.com/vitejs/vite/issues/2009
1322
+ const { base, assets } = config.kit.paths;
1323
+ const assets_base = `${assets || base}/${config.kit.appDir}/immutable/`;
1324
+
1315
1325
  const options = {
1316
1326
  cwd,
1317
1327
  config,
1318
1328
  build_dir,
1319
- // TODO this is so that Vite's preloading works. Unfortunately, it fails
1320
- // during `svelte-kit preview`, because we use a local asset path. If Vite
1321
- // used relative paths, I _think_ this could get fixed. Issue here:
1322
- // https://github.com/vitejs/vite/issues/2009
1323
- assets_base: `${config.kit.paths.assets || config.kit.paths.base}/${config.kit.appDir}/`,
1329
+ assets_base,
1324
1330
  manifest_data,
1325
1331
  output_dir,
1326
1332
  client_entry_file: path__default.relative(cwd, `${get_runtime_path(config)}/client/start.js`),
@@ -1351,8 +1357,8 @@ async function build(config, { log }) {
1351
1357
 
1352
1358
  const files = new Set([
1353
1359
  ...static_files,
1354
- ...client.chunks.map((chunk) => `${config.kit.appDir}/${chunk.fileName}`),
1355
- ...client.assets.map((chunk) => `${config.kit.appDir}/${chunk.fileName}`)
1360
+ ...client.chunks.map((chunk) => `${config.kit.appDir}/immutable/${chunk.fileName}`),
1361
+ ...client.assets.map((chunk) => `${config.kit.appDir}/immutable/${chunk.fileName}`)
1356
1362
  ]);
1357
1363
 
1358
1364
  // TODO is this right?
@@ -6,6 +6,7 @@ import { S as SVELTE_KIT_ASSETS, s as sirv } from './constants.js';
6
6
  import { pathToFileURL } from 'url';
7
7
  import { getRequest, setResponse } from '../node.js';
8
8
  import { installPolyfills } from '../node/polyfills.js';
9
+ import { b as load_config } from '../cli.js';
9
10
  import 'querystring';
10
11
  import 'stream';
11
12
  import 'node:http';
@@ -16,6 +17,10 @@ import 'node:util';
16
17
  import 'node:url';
17
18
  import 'net';
18
19
  import 'crypto';
20
+ import 'sade';
21
+ import 'child_process';
22
+ import 'chokidar';
23
+ import 'os';
19
24
 
20
25
  /** @typedef {import('http').IncomingMessage} Req */
21
26
  /** @typedef {import('http').ServerResponse} Res */
@@ -37,14 +42,14 @@ const mutable = (dir) =>
37
42
  * @param {{
38
43
  * port: number;
39
44
  * host?: string;
40
- * config: import('types').ValidatedConfig;
41
45
  * https?: boolean;
42
46
  * cwd?: string;
43
47
  * }} opts
44
48
  */
45
- async function preview({ port, host, config, https: use_https = false }) {
49
+ async function preview({ port, host, https: use_https = false }) {
46
50
  installPolyfills();
47
51
 
52
+ const config = await load_config();
48
53
  const { paths } = config.kit;
49
54
  const base = paths.base;
50
55
  const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
@@ -75,8 +80,12 @@ async function preview({ port, host, config, https: use_https = false }) {
75
80
  scoped(
76
81
  assets,
77
82
  sirv(join(config.kit.outDir, 'output/client'), {
78
- maxAge: 31536000,
79
- immutable: true
83
+ setHeaders: (res, pathname) => {
84
+ // only apply to build directory, not e.g. version.json
85
+ if (pathname.startsWith(`/${config.kit.appDir}/immutable`)) {
86
+ res.setHeader('cache-control', 'public,max-age=31536000,immutable');
87
+ }
88
+ }
80
89
  })
81
90
  ),
82
91
 
@@ -172,7 +181,7 @@ async function preview({ port, host, config, https: use_https = false }) {
172
181
 
173
182
  return new Promise((fulfil) => {
174
183
  http_server.listen(port, host, () => {
175
- fulfil(http_server);
184
+ fulfil({ server: http_server, config });
176
185
  });
177
186
  });
178
187
  }
@@ -5,7 +5,7 @@ import { $ } from '../cli.js';
5
5
  import chokidar from 'chokidar';
6
6
  import { w as walk$1, m as mkdirp, p as posixify, r as rimraf, c as copy } from './filesystem.js';
7
7
  import { createRequire } from 'module';
8
- import { a as write_tsconfig } from './write_tsconfig.js';
8
+ import { b as write_tsconfig } from './write_tsconfig.js';
9
9
  import 'sade';
10
10
  import 'child_process';
11
11
  import 'net';
@@ -4,7 +4,7 @@ import { g as get_runtime_path } from '../cli.js';
4
4
  import { p as posixify, c as copy, r as rimraf } from './filesystem.js';
5
5
  import { p as parse_route_id, s } from './misc.js';
6
6
  import { fileURLToPath } from 'url';
7
- import { w as write_if_changed, t as trim, a as write_tsconfig } from './write_tsconfig.js';
7
+ import { w as write_if_changed, t as trim, a as write, b as write_tsconfig } from './write_tsconfig.js';
8
8
  import 'sade';
9
9
  import 'child_process';
10
10
  import 'net';
@@ -821,10 +821,7 @@ function write_types(config, manifest_data) {
821
821
  const parts = (key || 'index').split('/');
822
822
  parts.push('__types', /** @type {string} */ (parts.pop()));
823
823
 
824
- write_if_changed(
825
- `${config.kit.outDir}/types/${parts.join('/')}.d.ts`,
826
- content.join('\n').trim()
827
- );
824
+ write(`${config.kit.outDir}/types/${parts.join('/')}.d.ts`, content.join('\n').trim());
828
825
  });
829
826
  }
830
827
 
@@ -12,12 +12,20 @@ const previous_contents = new Map();
12
12
  */
13
13
  function write_if_changed(file, code) {
14
14
  if (code !== previous_contents.get(file)) {
15
- previous_contents.set(file, code);
16
- mkdirp(path__default.dirname(file));
17
- fs__default.writeFileSync(file, code);
15
+ write(file, code);
18
16
  }
19
17
  }
20
18
 
19
+ /**
20
+ * @param {string} file
21
+ * @param {string} code
22
+ */
23
+ function write(file, code) {
24
+ previous_contents.set(file, code);
25
+ mkdirp(path__default.dirname(file));
26
+ fs__default.writeFileSync(file, code);
27
+ }
28
+
21
29
  /** @param {string} str */
22
30
  function trim(str) {
23
31
  const indentation = /** @type {RegExpExecArray} */ (/\n?(\s*)/.exec(str))[1];
@@ -157,4 +165,4 @@ function validate(config, cwd, out, user_file) {
157
165
  }
158
166
  }
159
167
 
160
- export { write_tsconfig as a, trim as t, write_if_changed as w };
168
+ export { write as a, write_tsconfig as b, trim as t, write_if_changed as w };
package/dist/cli.js CHANGED
@@ -904,7 +904,7 @@ async function launch(port, https, base) {
904
904
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
905
905
  }
906
906
 
907
- const prog = sade('svelte-kit').version('1.0.0-next.342');
907
+ const prog = sade('svelte-kit').version('1.0.0-next.345');
908
908
 
909
909
  prog
910
910
  .command('dev')
@@ -922,30 +922,34 @@ prog
922
922
  /** @type {() => Promise<void>} */
923
923
  let close;
924
924
 
925
- /** @param {import('types').ValidatedConfig} config */
926
- async function start(config) {
925
+ async function start() {
927
926
  const { dev } = await import('./chunks/index.js');
928
927
 
929
- const { address_info, server_config, close } = await dev({
928
+ const { server, config } = await dev({
930
929
  port,
931
930
  host,
932
- https,
933
- config
931
+ https
934
932
  });
935
933
 
934
+ const address_info = /** @type {import('net').AddressInfo} */ (
935
+ /** @type {import('http').Server} */ (server.httpServer).address()
936
+ );
937
+
938
+ const vite_config = server.config;
939
+
936
940
  welcome({
937
941
  port: address_info.port,
938
942
  host: address_info.address,
939
- https: !!(https || server_config.https),
940
- open: first && (open || !!server_config.open),
943
+ https: !!(https || vite_config.server.https),
944
+ open: first && (open || !!vite_config.server.open),
941
945
  base: config.kit.paths.base,
942
- loose: server_config.fs.strict === false,
943
- allow: server_config.fs.allow
946
+ loose: vite_config.server.fs.strict === false,
947
+ allow: vite_config.server.fs.allow
944
948
  });
945
949
 
946
950
  first = false;
947
951
 
948
- return close;
952
+ return server.close;
949
953
  }
950
954
 
951
955
  async function relaunch() {
@@ -953,9 +957,8 @@ prog
953
957
  relaunching = true;
954
958
 
955
959
  try {
956
- const updated_config = await load_config();
957
960
  await close();
958
- close = await start(updated_config);
961
+ close = await start();
959
962
 
960
963
  if (id !== uid) relaunch();
961
964
  } catch (e) {
@@ -975,8 +978,7 @@ prog
975
978
 
976
979
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
977
980
 
978
- const config = await load_config();
979
- close = await start(config);
981
+ close = await start();
980
982
 
981
983
  chokidar.watch('svelte.config.js', { ignoreInitial: true }).on('change', () => {
982
984
  if (relaunching) uid += 1;
@@ -1039,11 +1041,10 @@ prog
1039
1041
  await check_port(port);
1040
1042
 
1041
1043
  process.env.NODE_ENV = process.env.NODE_ENV || 'production';
1042
- const config = await load_config();
1043
1044
 
1044
1045
  const { preview } = await import('./chunks/index5.js');
1045
1046
 
1046
- await preview({ port, host, config, https });
1047
+ const { config } = await preview({ port, host, https });
1047
1048
 
1048
1049
  welcome({ port, host, https, open, base: config.kit.paths.base });
1049
1050
  } catch (error) {
@@ -1122,7 +1123,7 @@ async function check_port(port) {
1122
1123
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1123
1124
  if (open) launch(port, https, base);
1124
1125
 
1125
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.342'}\n`));
1126
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.345'}\n`));
1126
1127
 
1127
1128
  const protocol = https ? 'https:' : 'http:';
1128
1129
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
@@ -1160,4 +1161,4 @@ function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1160
1161
  console.log('\n');
1161
1162
  }
1162
1163
 
1163
- export { $, get_mime_lookup as a, get_aliases as b, coalesce_to_error as c, get_runtime_path as g, load_template as l, print_config_conflicts as p, resolve_entry as r };
1164
+ export { $, get_mime_lookup as a, load_config as b, coalesce_to_error as c, get_aliases as d, get_runtime_path as g, load_template as l, print_config_conflicts as p, resolve_entry as r };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.342",
3
+ "version": "1.0.0-next.345",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "types": "types/index.d.ts",
63
63
  "engines": {
64
- "node": ">=16"
64
+ "node": ">=16.7"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "rollup -c && node scripts/cp.js src/runtime/components assets/components && npm run types",
@@ -226,6 +226,8 @@ export interface SSREndpoint {
226
226
 
227
227
  export interface SSRNode {
228
228
  module: SSRComponent;
229
+ /** index into the `components` array in client-manifest.js */
230
+ index: number;
229
231
  /** client-side module URL for this component */
230
232
  entry: string;
231
233
  /** external CSS files */