Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-beds-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: don't bundle `@sveltejs/kit`
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default [
'packages/kit/test/build-errors/**/*',
'packages/kit/test/prerendering/**/*',
'packages/package/test/errors/**/*',
'packages/package/test/fixtures/**/*'
'packages/package/test/fixtures/**/*',
'packages/test-redirect-importer/index.js'
]
}
];
7 changes: 5 additions & 2 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"mrmime": "^2.0.0",
"sade": "^1.8.1",
"set-cookie-parser": "^2.6.0",
"sirv": "^3.0.0",
"vitefu": "^1.0.6"
"sirv": "^3.0.0"
},
"devDependencies": {
"@playwright/test": "catalog:",
Expand Down Expand Up @@ -84,6 +83,10 @@
"types": "./types/index.d.ts",
"import": "./src/exports/index.js"
},
"./internal": {
"types": "./types/index.d.ts",
"import": "./src/exports/internal/index.js"
},
"./node": {
"types": "./types/index.d.ts",
"import": "./src/exports/node/index.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpError, Redirect, ActionFailure } from '../runtime/control.js';
import { HttpError, Redirect, ActionFailure } from './internal/index.js';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

import { BROWSER, DEV } from 'esm-env';
import {
add_data_suffix,
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/node/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createReadStream } from 'node:fs';
import { Readable } from 'node:stream';
import * as set_cookie_parser from 'set-cookie-parser';
import { SvelteKitError } from '../../runtime/control.js';
import { SvelteKitError } from '../internal/index.js';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be the package import rather than relative?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't really matter as long as you don't use relative imports between bundled and unbundled modules


/**
* @param {import('http').IncomingMessage} req
Expand Down
33 changes: 2 additions & 31 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
} from './module_ids.js';
import { import_peer } from '../../utils/import.js';
import { compact } from '../../utils/array.js';
import { crawlFrameworkPkgs } from 'vitefu';

const cwd = process.cwd();

Expand Down Expand Up @@ -229,7 +228,7 @@ async function kit({ svelte_config }) {
* Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file.
* @see https://vitejs.dev/guide/api-plugin.html#config
*/
async config(config, config_env) {
config(config, config_env) {
initial_config = config;
vite_config_env = config_env;
is_build = config_env.command === 'build';
Expand All @@ -252,20 +251,6 @@ async function kit({ svelte_config }) {

const generated = path.posix.join(kit.outDir, 'generated');

const packages_depending_on_svelte_kit = (
await crawlFrameworkPkgs({
root: cwd,
isBuild: is_build,
viteUserConfig: config,
isSemiFrameworkPkgByJson: (pkg_json) => {
return (
!!pkg_json.dependencies?.['@sveltejs/kit'] ||
!!pkg_json.peerDependencies?.['@sveltejs/kit']
);
}
})
).ssr.noExternal;

// dev and preview config can be shared
/** @type {import('vite').UserConfig} */
const new_config = {
Expand Down Expand Up @@ -299,7 +284,6 @@ async function kit({ svelte_config }) {
`!${kit.files.routes}/**/+*server.*`
],
exclude: [
'@sveltejs/kit',
// exclude kit features so that libraries using them work even when they are prebundled
// this does not affect app code, just handling of imported libraries that use $app or $env
'$app',
Expand All @@ -313,20 +297,7 @@ async function kit({ svelte_config }) {
// that bundle later on from resolving the export conditions incorrectly
// and for example include browser-only code in the server output
// because they for example use esbuild.build with `platform: 'browser'`
'esm-env',
// We need this for two reasons:
// 1. Without this, `@sveltejs/kit` imports are kept as-is in the server output,
// and that causes modules and therefore classes like `Redirect` to be imported twice
// under different IDs, which breaks a bunch of stuff because of failing instanceof checks.
// 2. Vitest bypasses Vite when loading external modules, so we bundle
// when it is detected to keep our virtual modules working.
// See https://github.com/sveltejs/kit/pull/9172
// and https://vitest.dev/config/#deps-registernodeloader
'@sveltejs/kit',
// We need to bundle any packages depending on @sveltejs/kit so that
// everyone uses the same instances of classes such as `Redirect`
// which we use in `instanceof` checks
...packages_depending_on_svelte_kit
'esm-env'
]
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BROWSER, DEV } from 'esm-env';
import * as svelte from 'svelte';
import { HttpError, Redirect, SvelteKitError } from '@sveltejs/kit/internal';
const { onMount, tick } = svelte;
// Svelte 4 and under don't have `untrack`, so we have to fallback if `untrack` is not exported
const untrack = svelte.untrack ?? ((value) => value());
Expand Down Expand Up @@ -38,7 +39,6 @@ import {
} from './constants.js';
import { validate_page_exports } from '../../utils/exports.js';
import { compact } from '../../utils/array.js';
import { HttpError, Redirect, SvelteKitError } from '../control.js';
import { INVALIDATED_PARAM, TRAILING_SLASH_PARAM, validate_depends } from '../shared.js';
import { get_message, get_status } from '../../utils/error.js';
import { writable } from 'svelte/store';
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/cookie.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, expect, test } from 'vitest';
import { domain_matches, path_matches, get_cookies } from './cookie.js';
import { installPolyfills } from '../../exports/node/polyfills.js';
import { installPolyfills } from '@sveltejs/kit/node/polyfills';

installPolyfills();

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/server/data/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HttpError, SvelteKitError, Redirect } from '../../control.js';
import { text } from '@sveltejs/kit';
import { HttpError, SvelteKitError, Redirect } from '@sveltejs/kit/internal';
import { normalize_error } from '../../../utils/error.js';
import { once } from '../../../utils/functions.js';
import { load_server_data } from '../page/load_data.js';
import { clarify_devalue_error, handle_error_and_jsonify, serialize_uses } from '../utils.js';
import { normalize_path } from '../../../utils/url.js';
import { text } from '../../../exports/index.js';
import * as devalue from 'devalue';
import { create_async_iterator } from '../../../utils/streaming.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/endpoint.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Redirect } from '@sveltejs/kit/internal';
import { ENDPOINT_METHODS, PAGE_METHODS } from '../../constants.js';
import { negotiate } from '../../utils/http.js';
import { with_event } from '../app/server/event.js';
import { Redirect } from '../control.js';
import { method_not_allowed } from './utils.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/server/page/actions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as devalue from 'devalue';
import { DEV } from 'esm-env';
import { json } from '../../../exports/index.js';
import { json } from '@sveltejs/kit';
import { HttpError, Redirect, ActionFailure, SvelteKitError } from '@sveltejs/kit/internal';
import { get_status, normalize_error } from '../../../utils/error.js';
import { is_form_content_type, negotiate } from '../../../utils/http.js';
import { HttpError, Redirect, ActionFailure, SvelteKitError } from '../../control.js';
import { handle_error_and_jsonify } from '../utils.js';
import { with_event } from '../../app/server/event.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/server/page/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { text } from '../../../exports/index.js';
import { text } from '@sveltejs/kit';
import { Redirect } from '@sveltejs/kit/internal';
import { compact } from '../../../utils/array.js';
import { get_status, normalize_error } from '../../../utils/error.js';
import { add_data_suffix } from '../../pathname.js';
import { Redirect } from '../../control.js';
import { redirect_response, static_error_page, handle_error_and_jsonify } from '../utils.js';
import {
handle_action_json_request,
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as devalue from 'devalue';
import { readable, writable } from 'svelte/store';
import { DEV } from 'esm-env';
import { text } from '@sveltejs/kit';
import * as paths from '__sveltekit/paths';
import { hash } from '../../hash.js';
import { serialize_data } from './serialize_data.js';
Expand All @@ -9,7 +10,6 @@ import { Csp } from './csp.js';
import { uneval_action_response } from './actions.js';
import { clarify_devalue_error, handle_error_and_jsonify, serialize_uses } from '../utils.js';
import { public_env, safe_public_env } from '../../shared-server.js';
import { text } from '../../../exports/index.js';
import { create_async_iterator } from '../../../utils/streaming.js';
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
import { SCHEME } from '../../../utils/url.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/respond_with_error.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Redirect } from '@sveltejs/kit/internal';
import { render_response } from './render.js';
import { load_data, load_server_data } from './load_data.js';
import { handle_error_and_jsonify, static_error_page, redirect_response } from '../utils.js';
import { Redirect } from '../../control.js';
import { get_status } from '../../../utils/error.js';
import { PageNodes } from '../../../utils/page_nodes.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/server_routing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { base, assets, relative } from '__sveltekit/paths';
import { text } from '../../../exports/index.js';
import { text } from '@sveltejs/kit';
import { s } from '../../../utils/misc.js';
import { exec } from '../../../utils/routing.js';
import { decode_params } from '../../../utils/url.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/server/respond.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { DEV } from 'esm-env';
import { json, text } from '@sveltejs/kit';
import { HttpError, Redirect, SvelteKitError } from '@sveltejs/kit/internal';
import { base, app_dir } from '__sveltekit/paths';
import { is_endpoint_request, render_endpoint } from './endpoint.js';
import { render_page } from './page/index.js';
Expand All @@ -17,9 +19,7 @@ import { redirect_json_response, render_data } from './data/index.js';
import { add_cookies_to_headers, get_cookies } from './cookie.js';
import { create_fetch } from './fetch.js';
import { PageNodes } from '../../utils/page_nodes.js';
import { HttpError, Redirect, SvelteKitError } from '../control.js';
import { validate_server_exports } from '../../utils/exports.js';
import { json, text } from '../../exports/index.js';
import { action_json_redirect, is_action_json_request } from './page/actions.js';
import { INVALIDATED_PARAM, TRAILING_SLASH_PARAM } from '../shared.js';
import { get_public_env } from './env_module.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/server/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DEV } from 'esm-env';
import { json, text } from '../../exports/index.js';
import { json, text } from '@sveltejs/kit';
import { HttpError } from '@sveltejs/kit/internal';
import { coalesce_to_error, get_message, get_status } from '../../utils/error.js';
import { negotiate } from '../../utils/http.js';
import { HttpError } from '../control.js';
import { fix_stack_trace } from '../shared-server.js';
import { ENDPOINT_METHODS } from '../../constants.js';
import { escape_html } from '../../utils/escape.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/utils/error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpError, SvelteKitError } from '../runtime/control.js';
import { HttpError, SvelteKitError } from '@sveltejs/kit/internal';

/**
* @param {unknown} err
Expand All @@ -18,7 +18,7 @@ export function coalesce_to_error(err) {
* @param {unknown} error
*/
export function normalize_error(error) {
return /** @type {import('../runtime/control.js').Redirect | HttpError | SvelteKitError | Error} */ (
return /** @type {import('../exports/internal/index.js').Redirect | HttpError | SvelteKitError | Error} */ (
error
);
}
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion packages/kit/test/apps/basics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"cross-env": "catalog:",
"svelte": "^5.23.1",
"svelte-check": "^4.1.1",
"redirect-pkg": "file:./_test_dependencies/redirect-pkg",
"test-redirect-importer": "workspace:*",
"typescript": "^5.5.4",
"vite": "catalog:"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { authenticate } from 'redirect-pkg';
import { authenticate } from 'test-redirect-importer';

export function load() {
authenticate('/redirect/c');
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"paths": {
"@sveltejs/kit": ["./src/exports/public.d.ts"],
"@sveltejs/kit/node": ["./src/exports/node/index.js"],
"@sveltejs/kit/node/polyfills": ["./src/exports/node/polyfills.js"],
"@sveltejs/kit/internal": ["./src/exports/internal/index.js"],
// internal use only
"types": ["./src/types/internal.d.ts"]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { redirect } from '@sveltejs/kit';

// This exists to check that an external package importing `redirect`
// will get something that satisfies the relevant `instanceof` checks

/**
* @param {string} redirectUrl
* @returns {never}
Expand Down
12 changes: 12 additions & 0 deletions packages/test-redirect-importer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "test-redirect-importer",
"version": "0.0.1",
"private": true,
"type": "module",
"exports": {
".": "./index.js"
},
"dependencies": {
"@sveltejs/kit": "workspace:*"
}
}
Loading
Loading