@sveltejs/kit 1.3.6 → 1.3.8

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -80,13 +80,14 @@
80
80
  "node": "^16.14 || >=18"
81
81
  },
82
82
  "scripts": {
83
- "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
83
+ "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore && eslint src/**",
84
84
  "check": "tsc",
85
85
  "check:all": "tsc && pnpm -r --filter=\"./**\" check",
86
86
  "format": "pnpm lint --write",
87
87
  "test": "pnpm test:unit && pnpm test:integration",
88
88
  "test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
89
- "test:cross-platform": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform",
89
+ "test:cross-platform:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:dev",
90
+ "test:cross-platform:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build",
90
91
  "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
91
92
  "postinstall": "node postinstall.js"
92
93
  }
package/src/cli.js CHANGED
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import colors from 'kleur';
4
4
  import sade from 'sade';
5
5
  import { load_config } from './core/config/index.js';
@@ -1,10 +1,10 @@
1
+ import { fork } from 'node:child_process';
1
2
  import { existsSync, statSync, createReadStream, createWriteStream } from 'node:fs';
2
3
  import { pipeline } from 'node:stream';
3
- import { promisify } from 'node:util';
4
- import { fork } from 'node:child_process';
5
4
  import { fileURLToPath } from 'node:url';
5
+ import { promisify } from 'node:util';
6
+ import zlib from 'node:zlib';
6
7
  import glob from 'tiny-glob';
7
- import zlib from 'zlib';
8
8
  import { copy, rimraf, mkdirp } from '../../utils/filesystem.js';
9
9
  import { generate_manifest } from '../generate_manifest/index.js';
10
10
  import { get_route_segments } from '../../utils/routing.js';
@@ -1,6 +1,6 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import * as url from 'url';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import * as url from 'node:url';
4
4
  import options from './options.js';
5
5
 
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { join } from 'path';
1
+ import { join } from 'node:path';
2
2
 
3
3
  /** @typedef {import('./types').Validator} Validator */
4
4
 
@@ -1,5 +1,5 @@
1
- import { join } from 'path';
2
- import { pathToFileURL } from 'url';
1
+ import { join } from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
3
3
  import { get_option } from '../../runtime/server/utils.js';
4
4
  import {
5
5
  validate_common_exports,
@@ -1,6 +1,6 @@
1
- import { readFileSync, writeFileSync } from 'fs';
2
- import { dirname, join } from 'path';
3
- import { pathToFileURL } from 'url';
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
4
  import { mkdirp } from '../../utils/filesystem.js';
5
5
  import { installPolyfills } from '../../exports/node/polyfills.js';
6
6
  import { load_config } from '../config/index.js';
@@ -361,6 +361,15 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) {
361
361
  saved.set(file, dest);
362
362
  }
363
363
 
364
+ if (
365
+ config.prerender.entries.length > 1 ||
366
+ config.prerender.entries[0] !== '*' ||
367
+ prerender_map.size > 0
368
+ ) {
369
+ // Only log if we're actually going to do something to not confuse users
370
+ log.info('Prerendering');
371
+ }
372
+
364
373
  for (const entry of config.prerender.entries) {
365
374
  if (entry === '*') {
366
375
  for (const [id, prerender] of prerender_map) {
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import mime from 'mime';
4
4
  import { runtime_directory } from '../../utils.js';
5
5
  import { posixify } from '../../../utils/filesystem.js';
@@ -1,4 +1,4 @@
1
- import path from 'path';
1
+ import path from 'node:path';
2
2
  import create_manifest_data from './create_manifest_data/index.js';
3
3
  import { write_client_manifest } from './write_client_manifest.js';
4
4
  import { write_root } from './write_root.js';
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import { mkdirp } from '../../utils/filesystem.js';
4
4
 
5
5
  /** @type {Map<string, string>} */
@@ -1,10 +1,10 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
3
4
  import { get_env } from '../../exports/vite/utils.js';
4
5
  import { GENERATED_COMMENT } from '../../constants.js';
5
6
  import { create_dynamic_types, create_static_types } from '../env.js';
6
7
  import { write_if_changed } from './utils.js';
7
- import { fileURLToPath } from 'url';
8
8
 
9
9
  // TODO these types should be described in a neutral place, rather than
10
10
  // inside either `packages/kit` or `kit.svelte.dev`
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import colors from 'kleur';
4
4
  import { posixify } from '../../utils/filesystem.js';
5
5
  import { write_if_changed } from './utils.js';
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import MagicString from 'magic-string';
4
4
  import { posixify, rimraf, walk } from '../../../utils/filesystem.js';
5
5
  import { compact } from '../../../utils/array.js';
package/src/core/utils.js CHANGED
@@ -1,6 +1,6 @@
1
- import path from 'path';
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
2
3
  import colors from 'kleur';
3
- import { fileURLToPath } from 'url';
4
4
  import { posixify, to_fs } from '../utils/filesystem.js';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
+ import { ReadableStream, TransformStream, WritableStream } from 'node:stream/web';
2
+ import { webcrypto as crypto } from 'node:crypto';
1
3
  import { fetch, Response, Request, Headers, FormData } from 'undici';
2
- import { ReadableStream, TransformStream, WritableStream } from 'stream/web';
3
- import { webcrypto as crypto } from 'crypto';
4
4
 
5
5
  /** @type {Record<string, any>} */
6
6
  const globals = {
@@ -1,4 +1,4 @@
1
- import fs from 'fs';
1
+ import fs from 'node:fs';
2
2
  import * as vite from 'vite';
3
3
  import { s } from '../../../utils/misc.js';
4
4
  import { get_config_aliases } from '../utils.js';
@@ -1,8 +1,8 @@
1
- import fs from 'fs';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { URL } from 'node:url';
2
4
  import colors from 'kleur';
3
- import path from 'path';
4
5
  import sirv from 'sirv';
5
- import { URL } from 'url';
6
6
  import { isCSSRequest, loadEnv } from 'vite';
7
7
  import { getRequest, setResponse } from '../../../exports/node/index.js';
8
8
  import { installPolyfills } from '../../../exports/node/polyfills.js';
@@ -1,4 +1,4 @@
1
- import path from 'path';
1
+ import path from 'node:path';
2
2
  import { posixify } from '../../../utils/filesystem.js';
3
3
 
4
4
  const ILLEGAL_IMPORTS = new Set(['\0$env/dynamic/private', '\0$env/static/private']);
@@ -139,10 +139,12 @@ export async function sveltekit() {
139
139
  return [...svelte(vite_plugin_svelte_options), ...kit({ svelte_config })];
140
140
  }
141
141
 
142
- /**
143
- * If `true`, the server build has been completed and we're creating the client build
144
- */
145
- let secondary_build = false;
142
+ // These variables live outside the `kit()` function because it is re-invoked by each Vite build
143
+
144
+ let secondary_build_started = false;
145
+
146
+ /** @type {import('types').ManifestData} */
147
+ let manifest_data;
146
148
 
147
149
  /**
148
150
  * Returns the SvelteKit Vite plugin. Vite executes Rollup hooks as well as some of its own.
@@ -167,17 +169,14 @@ function kit({ svelte_config }) {
167
169
  /** @type {import('vite').ConfigEnv} */
168
170
  let vite_config_env;
169
171
 
170
- /** @type {import('types').ManifestData} */
171
- let manifest_data;
172
-
173
172
  /** @type {boolean} */
174
173
  let is_build;
175
174
 
176
175
  /** @type {{ public: Record<string, string>; private: Record<string, string> }} */
177
176
  let env;
178
177
 
179
- /** @type {(() => Promise<void>) | null} */
180
- let finalise = null;
178
+ /** @type {() => Promise<void>} */
179
+ let finalise;
181
180
 
182
181
  const service_worker_entry_file = resolve_entry(kit.files.serviceWorker);
183
182
 
@@ -251,7 +250,7 @@ function kit({ svelte_config }) {
251
250
 
252
251
  if (is_build) {
253
252
  if (!new_config.build) new_config.build = {};
254
- new_config.build.ssr = !secondary_build;
253
+ new_config.build.ssr = !secondary_build_started;
255
254
 
256
255
  new_config.define = {
257
256
  __SVELTEKIT_ADAPTER_NAME__: JSON.stringify(kit.adapter?.name),
@@ -273,6 +272,10 @@ function kit({ svelte_config }) {
273
272
  'esm-env'
274
273
  ]
275
274
  };
275
+
276
+ if (!secondary_build_started) {
277
+ manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data;
278
+ }
276
279
  } else {
277
280
  new_config.define = {
278
281
  __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
@@ -363,7 +366,7 @@ function kit({ svelte_config }) {
363
366
  writeBundle: {
364
367
  sequential: true,
365
368
  async handler(_options) {
366
- if (!secondary_build) return;
369
+ if (vite_config.build.ssr) return;
367
370
 
368
371
  const guard = module_guard(this, {
369
372
  cwd: vite.normalizePath(process.cwd()),
@@ -389,13 +392,11 @@ function kit({ svelte_config }) {
389
392
  * Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file.
390
393
  * @see https://vitejs.dev/guide/api-plugin.html#config
391
394
  */
392
- async config(config, config_env) {
395
+ async config(config) {
393
396
  /** @type {import('vite').UserConfig} */
394
397
  let new_config;
395
398
 
396
399
  if (is_build) {
397
- manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data;
398
-
399
400
  const ssr = /** @type {boolean} */ (config.build?.ssr);
400
401
  const prefix = `${kit.appDir}/immutable`;
401
402
 
@@ -535,10 +536,7 @@ function kit({ svelte_config }) {
535
536
  * Clears the output directories.
536
537
  */
537
538
  buildStart() {
538
- if (secondary_build) return;
539
-
540
- // reset (here, not in `config`, because `build --watch` skips `config`)
541
- finalise = null;
539
+ if (secondary_build_started) return;
542
540
 
543
541
  if (is_build) {
544
542
  if (!vite_config.build.watch) {
@@ -549,7 +547,7 @@ function kit({ svelte_config }) {
549
547
  },
550
548
 
551
549
  generateBundle() {
552
- if (!secondary_build) return;
550
+ if (vite_config.build.ssr) return;
553
551
 
554
552
  this.emitFile({
555
553
  type: 'asset',
@@ -560,14 +558,13 @@ function kit({ svelte_config }) {
560
558
 
561
559
  /**
562
560
  * Vite builds a single bundle. We need three bundles: client, server, and service worker.
563
- * The user's package.json scripts will invoke the Vite CLI to execute the client build. We
564
- * then use this hook to kick off builds for the server and service worker.
561
+ * The user's package.json scripts will invoke the Vite CLI to execute the server build. We
562
+ * then use this hook to kick off builds for the client and service worker.
565
563
  */
566
564
  writeBundle: {
567
565
  sequential: true,
568
566
  async handler(_options) {
569
- if (secondary_build) return; // only run this once
570
- secondary_build = true;
567
+ if (secondary_build_started) return; // only run this once
571
568
 
572
569
  const verbose = vite_config.logLevel === 'info';
573
570
  const log = logger({ verbose });
@@ -596,6 +593,8 @@ function kit({ svelte_config }) {
596
593
  );
597
594
 
598
595
  // first, build server nodes without the client manifest so we can analyse it
596
+ log.info('Analysing routes');
597
+
599
598
  build_server_nodes(out, kit, manifest_data, server_manifest, null, null);
600
599
 
601
600
  const metadata = await analyse({
@@ -603,6 +602,8 @@ function kit({ svelte_config }) {
603
602
  env: { ...env.private, ...env.public }
604
603
  });
605
604
 
605
+ log.info('Building app');
606
+
606
607
  // create client build
607
608
  write_client_manifest(
608
609
  kit,
@@ -611,6 +612,8 @@ function kit({ svelte_config }) {
611
612
  metadata.nodes
612
613
  );
613
614
 
615
+ secondary_build_started = true;
616
+
614
617
  const { output } = /** @type {import('rollup').RollupOutput} */ (
615
618
  await vite.build({
616
619
  configFile: vite_config.configFile,
@@ -649,8 +652,6 @@ function kit({ svelte_config }) {
649
652
  build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, css);
650
653
 
651
654
  // ...and prerender
652
- log.info('Prerendering');
653
-
654
655
  const { prerendered, prerender_map } = await prerender({
655
656
  out,
656
657
  manifest_path,
@@ -696,6 +697,10 @@ function kit({ svelte_config }) {
696
697
  .cyan('npm run preview')} to preview your production build locally.`
697
698
  );
698
699
 
700
+ // avoid making the manifest available to users
701
+ fs.unlinkSync(`${out}/client/${vite_config.build.manifest}`);
702
+ fs.unlinkSync(`${out}/server/${vite_config.build.manifest}`);
703
+
699
704
  if (kit.adapter) {
700
705
  const { adapt } = await import('../../core/adapt/index.js');
701
706
  await adapt(svelte_config, build_data, metadata, prerendered, prerender_map, log);
@@ -708,9 +713,7 @@ function kit({ svelte_config }) {
708
713
  );
709
714
  }
710
715
 
711
- // avoid making the manifest available to users
712
- fs.unlinkSync(`${out}/client/${vite_config.build.manifest}`);
713
- fs.unlinkSync(`${out}/server/${vite_config.build.manifest}`);
716
+ secondary_build_started = false;
714
717
  };
715
718
  }
716
719
  },
@@ -721,7 +724,8 @@ function kit({ svelte_config }) {
721
724
  closeBundle: {
722
725
  sequential: true,
723
726
  async handler() {
724
- finalise?.();
727
+ if (!vite_config.build.ssr) return;
728
+ await finalise();
725
729
  }
726
730
  }
727
731
  };
@@ -1,7 +1,7 @@
1
- import fs from 'fs';
2
- import { join } from 'path';
1
+ import fs from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
3
4
  import sirv from 'sirv';
4
- import { pathToFileURL } from 'url';
5
5
  import { loadEnv, normalizePath } from 'vite';
6
6
  import { getRequest, setResponse } from '../../../exports/node/index.js';
7
7
  import { installPolyfills } from '../../../exports/node/polyfills.js';
@@ -1,4 +1,4 @@
1
- import path from 'path';
1
+ import path from 'node:path';
2
2
  import { loadEnv } from 'vite';
3
3
  import { posixify } from '../../utils/filesystem.js';
4
4
  import { negotiate } from '../../utils/http.js';
@@ -343,7 +343,8 @@ export function create_client({ target, base }) {
343
343
  }
344
344
 
345
345
  if (autoscroll) {
346
- const deep_linked = url.hash && document.querySelector(decodeURIComponent(url.hash));
346
+ const deep_linked =
347
+ url.hash && document.getElementById(decodeURIComponent(url.hash.slice(1)));
347
348
  if (scroll) {
348
349
  scrollTo(scroll.x, scroll.y);
349
350
  } else if (deep_linked) {
@@ -722,23 +723,22 @@ export function create_client({ target, base }) {
722
723
  const url_changed = current.url ? id !== current.url.pathname + current.url.search : false;
723
724
  const route_changed = current.route ? route.id !== current.route.id : false;
724
725
 
725
- const invalid_server_nodes = loaders.reduce((acc, loader, i) => {
726
+ let parent_invalid = false;
727
+ const invalid_server_nodes = loaders.map((loader, i) => {
726
728
  const previous = current.branch[i];
727
729
 
728
730
  const invalid =
729
731
  !!loader?.[0] &&
730
732
  (previous?.loader !== loader[1] ||
731
- has_changed(
732
- acc.some(Boolean),
733
- route_changed,
734
- url_changed,
735
- previous.server?.uses,
736
- params
737
- ));
738
-
739
- acc.push(invalid);
740
- return acc;
741
- }, /** @type {boolean[]} */ ([]));
733
+ has_changed(parent_invalid, route_changed, url_changed, previous.server?.uses, params));
734
+
735
+ if (invalid) {
736
+ // For the next one
737
+ parent_invalid = true;
738
+ }
739
+
740
+ return invalid;
741
+ });
742
742
 
743
743
  if (invalid_server_nodes.some(Boolean)) {
744
744
  try {
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
 
4
4
  /** @param {string} dir */
5
5
  export function mkdirp(dir) {
@@ -75,8 +75,8 @@ export type CSRRoute = {
75
75
  id: string;
76
76
  exec(path: string): undefined | Record<string, string>;
77
77
  errors: Array<CSRPageNodeLoader | undefined>;
78
- layouts: Array<[boolean, CSRPageNodeLoader] | undefined>;
79
- leaf: [boolean, CSRPageNodeLoader];
78
+ layouts: Array<[has_server_load: boolean, node_loader: CSRPageNodeLoader] | undefined>;
79
+ leaf: [has_server_load: boolean, node_loader: CSRPageNodeLoader];
80
80
  };
81
81
 
82
82
  export type GetParams = (match: RegExpExecArray) => Record<string, string>;