@sveltejs/kit 3.0.0-next.23 → 3.0.0-next.25
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 +51 -8
- package/src/cli.js +3 -3
- package/src/constants.js +19 -1
- package/src/core/adapt/builder.js +3 -5
- package/src/core/env.js +137 -182
- package/src/core/postbuild/analyse.js +9 -4
- package/src/core/postbuild/prerender.js +5 -6
- package/src/core/sync/create_manifest_data/index.js +29 -33
- package/src/core/sync/sync.js +23 -40
- package/src/core/sync/write_app_manifest.js +83 -0
- package/src/core/sync/write_client_manifest.js +6 -4
- package/src/core/sync/write_server.js +12 -22
- package/src/core/sync/write_types/index.js +2 -2
- package/src/core/utils.js +10 -28
- package/src/exports/adapter.js +22 -0
- package/src/exports/hooks/public.d.ts +9 -1
- package/src/exports/node/index.js +77 -5
- package/src/exports/public.d.ts +1 -1
- package/src/exports/vite/build/build_server.js +3 -3
- package/src/exports/vite/build/service-worker.js +98 -0
- package/src/exports/vite/build/utils.js +48 -4
- package/src/exports/vite/dev/index.js +28 -25
- package/src/exports/vite/index.js +94 -747
- package/src/exports/vite/module_ids.js +1 -11
- package/src/exports/vite/plugins/env-vars.js +159 -0
- package/src/exports/vite/plugins/guard.js +205 -0
- package/src/exports/vite/preview/index.js +6 -4
- package/src/exports/vite/utils.js +99 -4
- package/src/runtime/app/env/{types.d.ts → client.js} +9 -4
- package/src/runtime/app/env/index.js +1 -2
- package/src/runtime/app/env/private/index.js +1 -0
- package/src/runtime/app/env/public/client.js +1 -1
- package/src/runtime/app/env/public/server.js +1 -1
- package/src/runtime/app/env/{internal.js → server.js} +4 -4
- package/src/runtime/app/forms/client.js +263 -0
- package/src/runtime/app/forms/index.js +1 -263
- package/src/runtime/app/forms/public.d.ts +1 -1
- package/src/runtime/app/forms/server.js +6 -0
- package/src/runtime/app/forms/shared.js +34 -0
- package/src/runtime/app/manifest/index.js +1 -1
- package/src/runtime/app/navigation/client.js +15 -0
- package/src/runtime/app/navigation/index.js +1 -15
- package/src/runtime/app/navigation/public.d.ts +1 -1
- package/src/runtime/app/navigation/server.js +15 -0
- package/src/runtime/app/paths/server.js +1 -1
- package/src/runtime/app/server/remote/form.js +11 -1
- package/src/runtime/app/server/remote/prerender.js +1 -2
- package/src/runtime/app/server/remote/query.js +3 -3
- package/src/runtime/app/state/client.svelte.js +207 -0
- package/src/runtime/app/state/index.js +1 -66
- package/src/runtime/app/state/public.d.ts +1 -1
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client.js +210 -278
- package/src/runtime/client/fetcher.js +18 -8
- package/src/runtime/client/remote-functions/form.svelte.js +9 -6
- package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query-live/iterator.js +1 -1
- package/src/runtime/client/remote-functions/shared.svelte.js +2 -2
- package/src/runtime/client/snapshots.js +1 -3
- package/src/runtime/client/stream.js +27 -20
- package/src/runtime/client/utils.js +7 -3
- package/src/runtime/components/root.svelte +5 -5
- package/src/runtime/env/dynamic/private.js +1 -1
- package/src/runtime/env/static/private.js +1 -1
- package/src/runtime/error-chain.js +54 -0
- package/src/runtime/form-utils.js +55 -87
- package/src/runtime/invalid-import.js +1 -0
- package/src/runtime/props.svelte.js +1 -1
- package/src/runtime/server/data/index.js +12 -27
- package/src/runtime/server/endpoint.js +8 -3
- package/src/runtime/server/env_module.js +1 -1
- package/src/runtime/server/errors.js +9 -12
- package/src/runtime/server/fetch.js +14 -16
- package/src/runtime/server/index.js +30 -27
- package/src/runtime/server/internal.js +34 -4
- package/src/runtime/server/page/actions.js +77 -124
- package/src/runtime/server/page/data_serializer.js +6 -10
- package/src/runtime/server/page/index.js +45 -82
- package/src/runtime/server/page/render.js +34 -52
- package/src/runtime/server/page/respond_with_error.js +7 -9
- package/src/runtime/server/remote-functions.js +138 -166
- package/src/runtime/server/respond.js +75 -30
- package/src/runtime/server/state.js +1 -0
- package/src/runtime/server/utils.js +0 -7
- package/src/runtime/utils.js +41 -0
- package/src/telemetry.js +1 -33
- package/src/types/ambient-private.d.ts +9 -17
- package/src/types/global-private.d.ts +8 -0
- package/src/types/internal.d.ts +27 -15
- package/src/types/private.d.ts +1 -1
- package/src/utils/exports.js +1 -0
- package/src/utils/filesystem.js +10 -22
- package/src/utils/functions.js +10 -0
- package/src/utils/routing.js +0 -11
- package/src/utils/streaming.js +5 -15
- package/src/utils/url.js +0 -11
- package/src/version.js +1 -1
- package/types/index.d.ts +54 -29
- package/types/index.d.ts.map +10 -5
- package/src/runtime/app/env/private.js +0 -1
- package/src/runtime/app/env/standard-schema.d.ts +0 -0
- package/src/runtime/app/state/client.js +0 -63
- package/src/runtime/client/state.svelte.js +0 -98
- package/src/runtime/server/ambient.d.ts +0 -4
- package/src/utils/path.js +0 -23
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
2
|
import { posixify } from '../../utils/os.js';
|
|
3
3
|
|
|
4
|
-
export const sveltekit_env = '\0virtual:__sveltekit/env';
|
|
5
|
-
export const sveltekit_env_public_client = '\0virtual:__sveltekit/env/public/client';
|
|
6
|
-
export const sveltekit_env_public_server = '\0virtual:__sveltekit/env/public/server';
|
|
7
|
-
export const sveltekit_env_private = '\0virtual:__sveltekit/env/private';
|
|
8
|
-
export const sveltekit_env_service_worker = '\0virtual:__sveltekit/env/service-worker';
|
|
9
|
-
export const sveltekit_server = '\0virtual:__sveltekit/server';
|
|
10
|
-
export const service_worker = '\0virtual:service-worker';
|
|
11
|
-
|
|
12
|
-
export const sveltekit_manifest_data = '\0virtual:__sveltekit/manifest-data';
|
|
13
|
-
|
|
14
4
|
export const app_server = posixify(
|
|
15
5
|
fileURLToPath(new URL('../../runtime/app/server/index.js', import.meta.url))
|
|
16
6
|
);
|
|
17
7
|
|
|
18
8
|
export const app_env_private = posixify(
|
|
19
|
-
fileURLToPath(new URL('../../runtime/app/env/private.js', import.meta.url))
|
|
9
|
+
fileURLToPath(new URL('../../runtime/app/env/private/index.js', import.meta.url))
|
|
20
10
|
);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/** @import { Plugin, ResolvedConfig } from 'vite' */
|
|
2
|
+
/** @import { EnvVarConfig } from '@sveltejs/kit/env' */
|
|
3
|
+
/** @import { ValidatedConfig } from 'types' */
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { exactRegex } from '@rolldown/pluginutils';
|
|
6
|
+
import * as sync from '../../../core/sync/sync.js';
|
|
7
|
+
import { create_env_modules, resolve_env_entry } from '../../../core/env.js';
|
|
8
|
+
import { import_peer } from '../../../utils/import.js';
|
|
9
|
+
import { write_if_changed } from '../../../core/sync/utils.js';
|
|
10
|
+
import { posixify } from '../../../utils/os.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generate (and, in dev, maintain) the `${outDir}/generated/{build,dev}/env` modules
|
|
14
|
+
* derived from `src/env.ts`
|
|
15
|
+
*
|
|
16
|
+
* @param {ValidatedConfig} config
|
|
17
|
+
* @param {(variables: Record<string, EnvVarConfig<any>> | null) => void} callback
|
|
18
|
+
* @returns {Plugin}
|
|
19
|
+
*/
|
|
20
|
+
export function plugin_env_vars(config, callback) {
|
|
21
|
+
/** @type {string} */
|
|
22
|
+
let dir;
|
|
23
|
+
|
|
24
|
+
/** @type {Record<string, any>} */
|
|
25
|
+
let env;
|
|
26
|
+
|
|
27
|
+
/** @type {ResolvedConfig} */
|
|
28
|
+
let resolved_config;
|
|
29
|
+
|
|
30
|
+
/** @type {string | null} */
|
|
31
|
+
let resolved_entry = null;
|
|
32
|
+
|
|
33
|
+
/** @type {Set<string>} */
|
|
34
|
+
let deps = new Set();
|
|
35
|
+
|
|
36
|
+
let is_build = false;
|
|
37
|
+
|
|
38
|
+
/** @type {Promise<void> | undefined} */
|
|
39
|
+
let generated;
|
|
40
|
+
|
|
41
|
+
async function generate() {
|
|
42
|
+
const synced = await sync.env(
|
|
43
|
+
config,
|
|
44
|
+
resolved_entry,
|
|
45
|
+
resolved_config.root,
|
|
46
|
+
resolved_config.mode
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
deps = synced.deps;
|
|
50
|
+
|
|
51
|
+
const vars = synced.variables;
|
|
52
|
+
callback(vars);
|
|
53
|
+
|
|
54
|
+
const modules = create_env_modules(
|
|
55
|
+
config,
|
|
56
|
+
vars,
|
|
57
|
+
env,
|
|
58
|
+
dir,
|
|
59
|
+
resolved_entry && posixify(path.relative(dir, resolved_entry)),
|
|
60
|
+
!is_build
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
for (const [file, code] of Object.entries(modules)) {
|
|
64
|
+
write_if_changed(`${dir}/${file}`, code);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
name: 'vite-plugin-sveltekit-env-vars',
|
|
70
|
+
|
|
71
|
+
async configResolved(c) {
|
|
72
|
+
resolved_config = c;
|
|
73
|
+
|
|
74
|
+
const vite = await import_peer('vite', c.root);
|
|
75
|
+
env = vite.loadEnv(c.mode, path.resolve(c.root, config.env.dir), '');
|
|
76
|
+
|
|
77
|
+
is_build = c.command === 'build';
|
|
78
|
+
|
|
79
|
+
dir = posixify(
|
|
80
|
+
path.resolve(c.root, config.outDir, `generated/${is_build ? 'build' : 'dev'}/env`)
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
async buildStart() {
|
|
85
|
+
// runs once via the memo — per-process, whichever environment starts first
|
|
86
|
+
// (environment names vary by adapter), and never in the postbuild forks,
|
|
87
|
+
// which resolve the config without building
|
|
88
|
+
await (generated ??= (async () => {
|
|
89
|
+
resolved_entry = resolve_env_entry(config, resolved_config.root);
|
|
90
|
+
await generate();
|
|
91
|
+
})());
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
configureServer(server) {
|
|
95
|
+
// `handleHotUpdate` only fires for `change` events on files Vite already knows about,
|
|
96
|
+
// so it doesn't cover the env entry being created or deleted while the dev server is
|
|
97
|
+
// running. Watch for those events explicitly, re-resolve the entry, regenerate the
|
|
98
|
+
// modules and trigger a full reload (mirroring the previous behaviour).
|
|
99
|
+
const on_entry_add_unlink = async (/** @type {string} */ file) => {
|
|
100
|
+
const resolved = resolve_env_entry(config, resolved_config.root);
|
|
101
|
+
|
|
102
|
+
if (file === resolved_entry || file === resolved) {
|
|
103
|
+
resolved_entry = resolved;
|
|
104
|
+
await generate();
|
|
105
|
+
server.hot.send({ type: 'full-reload' });
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
server.watcher.on('add', on_entry_add_unlink);
|
|
110
|
+
server.watcher.on('unlink', on_entry_add_unlink);
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
async handleHotUpdate(update) {
|
|
114
|
+
if (!deps.has(update.file)) return;
|
|
115
|
+
await generate();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {() => string | null} get_service_worker_entry_file
|
|
122
|
+
* @returns {Plugin}
|
|
123
|
+
*/
|
|
124
|
+
export function plugin_service_worker_env_vars(get_service_worker_entry_file) {
|
|
125
|
+
/** @type {string | null} */
|
|
126
|
+
let service_worker_entry_file;
|
|
127
|
+
|
|
128
|
+
/** @satisfies {Plugin} */
|
|
129
|
+
const plugin = {
|
|
130
|
+
name: 'vite-plugin-sveltekit-service-worker-env',
|
|
131
|
+
configResolved() {
|
|
132
|
+
service_worker_entry_file = get_service_worker_entry_file();
|
|
133
|
+
|
|
134
|
+
if (service_worker_entry_file) {
|
|
135
|
+
plugin.transform.filter = {
|
|
136
|
+
id: exactRegex(service_worker_entry_file)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
applyToEnvironment(environment) {
|
|
141
|
+
return !!service_worker_entry_file && environment.config.consumer === 'client';
|
|
142
|
+
},
|
|
143
|
+
transform: {
|
|
144
|
+
filter: {},
|
|
145
|
+
handler(code) {
|
|
146
|
+
// prepend the service worker with an import that configures
|
|
147
|
+
// `env`, in case `$app/env/public` is imported. In production
|
|
148
|
+
// this is required: dynamic public env vars aren't known at
|
|
149
|
+
// build time, so `env.js` is loaded at runtime. In dev, the
|
|
150
|
+
// imported module just inlines the current values instead.
|
|
151
|
+
return {
|
|
152
|
+
code: `import '<sveltekit:generated>/env/service-worker.js';\n${code}`
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return plugin;
|
|
159
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/** @import { TopLevelFilterExpression } from '@rolldown/pluginutils' */
|
|
2
|
+
/** @import { ManifestData, ValidatedConfig } from 'types' */
|
|
3
|
+
/** @import { Plugin } from 'vite' */
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { and, exactRegex, importerId, include, not } from '@rolldown/pluginutils';
|
|
6
|
+
import { app_env_private, app_server } from '../module_ids.js';
|
|
7
|
+
import {
|
|
8
|
+
error_for_missing_config,
|
|
9
|
+
normalize_id,
|
|
10
|
+
remote_module_pattern,
|
|
11
|
+
server_only_directory_pattern,
|
|
12
|
+
server_only_module_pattern
|
|
13
|
+
} from '../utils.js';
|
|
14
|
+
import { stackless } from '../../../utils/error.js';
|
|
15
|
+
import { posixify } from '../../../utils/os.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Ensures that client-side code can't accidentally import server-side code,
|
|
19
|
+
* whether in `*.server.js` files, `$app/server`, any `/server/` directory, or `$app/env/private`
|
|
20
|
+
* @param {ValidatedConfig} kit
|
|
21
|
+
* @param {() => { vite: typeof import('vite'); root: string; normalized_aliases: Array<{ alias: string, path: string }>; service_worker_entry_file: string | null; }} get_config
|
|
22
|
+
* @param {() => ManifestData} get_manifest_data
|
|
23
|
+
* @returns {Plugin}
|
|
24
|
+
*/
|
|
25
|
+
export function plugin_guard(kit, get_config, get_manifest_data) {
|
|
26
|
+
/** @type {string} */
|
|
27
|
+
let root;
|
|
28
|
+
|
|
29
|
+
/** @type {string} */
|
|
30
|
+
let normalized_cwd;
|
|
31
|
+
/** @type {Array<{ alias: string, path: string }>} */
|
|
32
|
+
let normalized_aliases;
|
|
33
|
+
/** @type {string} */
|
|
34
|
+
let normalized_node_modules;
|
|
35
|
+
/** @type {string} */
|
|
36
|
+
let normalized_routes;
|
|
37
|
+
/** @type {string} */
|
|
38
|
+
let normalized_assets;
|
|
39
|
+
|
|
40
|
+
/** @type {string | null} */
|
|
41
|
+
let service_worker_entry_file;
|
|
42
|
+
|
|
43
|
+
/** @type {Map<string, Set<string>>} */
|
|
44
|
+
const import_map = new Map();
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
name: 'vite-plugin-sveltekit-guard',
|
|
48
|
+
|
|
49
|
+
// Run this plugin before built-in resolution, so that relative imports
|
|
50
|
+
// are added to the module graph
|
|
51
|
+
enforce: 'pre',
|
|
52
|
+
|
|
53
|
+
configResolved() {
|
|
54
|
+
/** @type {typeof import('vite')} */
|
|
55
|
+
let vite;
|
|
56
|
+
({ vite, root, normalized_aliases, service_worker_entry_file } = get_config());
|
|
57
|
+
|
|
58
|
+
normalized_cwd = vite.normalizePath(root);
|
|
59
|
+
normalized_node_modules = vite.normalizePath(path.resolve(root, 'node_modules'));
|
|
60
|
+
normalized_routes = vite.normalizePath(path.resolve(root, kit.files.routes));
|
|
61
|
+
normalized_assets = vite.normalizePath(path.resolve(root, kit.files.assets));
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
applyToEnvironment(environment) {
|
|
65
|
+
// the import map is only read for client-side violations in `load`, so skip other environments
|
|
66
|
+
return environment.config.consumer === 'client';
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
resolveId: {
|
|
70
|
+
// composable filters are not accepted type-wise but still work during build
|
|
71
|
+
// see https://github.com/vitejs/rolldown-vite/issues/605
|
|
72
|
+
filter: /** @type {any} */ (
|
|
73
|
+
/** @satisfies {TopLevelFilterExpression[]} */ ([
|
|
74
|
+
include(and(importerId(/.+/), not(importerId(/index\.html$/))))
|
|
75
|
+
])
|
|
76
|
+
),
|
|
77
|
+
async handler(id, importer, options) {
|
|
78
|
+
// composable filters only work during build so we still need this guard for dev
|
|
79
|
+
// see https://github.com/vitejs/rolldown-vite/issues/605
|
|
80
|
+
if (importer && !importer.endsWith('index.html')) {
|
|
81
|
+
const resolved = await this.resolve(id, importer, { ...options, skipSelf: true });
|
|
82
|
+
|
|
83
|
+
if (resolved) {
|
|
84
|
+
const normalized = normalize_id(resolved.id, normalized_aliases, normalized_cwd);
|
|
85
|
+
|
|
86
|
+
let importers = import_map.get(normalized);
|
|
87
|
+
|
|
88
|
+
if (!importers) {
|
|
89
|
+
importers = new Set();
|
|
90
|
+
import_map.set(normalized, importers);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
importers.add(normalize_id(importer, normalized_aliases, normalized_cwd));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
load: {
|
|
100
|
+
filter: {
|
|
101
|
+
id: [
|
|
102
|
+
exactRegex(app_server),
|
|
103
|
+
exactRegex(app_env_private),
|
|
104
|
+
server_only_module_pattern,
|
|
105
|
+
server_only_directory_pattern
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
handler(id) {
|
|
109
|
+
const normalized = normalize_id(id, normalized_aliases, normalized_cwd);
|
|
110
|
+
|
|
111
|
+
let is_server_only = normalized === '$app/env/private' || normalized === '$app/server';
|
|
112
|
+
|
|
113
|
+
// skip .server.js files outside the cwd or in node_modules, as the filename might not mean 'server-only module' in this context
|
|
114
|
+
if (id.startsWith(normalized_cwd) && !id.startsWith(normalized_node_modules)) {
|
|
115
|
+
// e.g. `server.ts` or `foo.server.ts`
|
|
116
|
+
is_server_only ||= server_only_module_pattern.test(id);
|
|
117
|
+
|
|
118
|
+
// e.g. `server/foo.ts`, unless in `src/routes` or `static`
|
|
119
|
+
is_server_only ||=
|
|
120
|
+
server_only_directory_pattern.test(id) &&
|
|
121
|
+
!id.startsWith(normalized_routes + '/') &&
|
|
122
|
+
!id.startsWith(normalized_assets + '/');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!is_server_only) return;
|
|
126
|
+
|
|
127
|
+
const manifest_data = get_manifest_data();
|
|
128
|
+
|
|
129
|
+
/** @type {Set<string>} */
|
|
130
|
+
const entrypoints = new Set();
|
|
131
|
+
for (const node of manifest_data.nodes) {
|
|
132
|
+
if (node.component) entrypoints.add(node.component);
|
|
133
|
+
if (node.universal) entrypoints.add(node.universal);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (manifest_data.hooks.client) entrypoints.add(manifest_data.hooks.client);
|
|
137
|
+
if (manifest_data.hooks.universal) entrypoints.add(manifest_data.hooks.universal);
|
|
138
|
+
|
|
139
|
+
if (service_worker_entry_file) {
|
|
140
|
+
entrypoints.add(posixify(path.relative(root, service_worker_entry_file)));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Walk up the import graph from the server-only module, looking for a chain
|
|
144
|
+
// that leads back to a client entrypoint. We search all candidates (not just
|
|
145
|
+
// the first) because a module can be imported by both server and client code,
|
|
146
|
+
// and a greedy first-match could follow a server-only branch that never
|
|
147
|
+
// reaches an entrypoint — see https://github.com/sveltejs/kit/issues/16232
|
|
148
|
+
/** @type {Set<string>} */
|
|
149
|
+
const visited = new Set([normalized]);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param {string} current
|
|
153
|
+
* @param {string[]} chain
|
|
154
|
+
* @returns {string[] | null}
|
|
155
|
+
*/
|
|
156
|
+
function find_chain(current, chain) {
|
|
157
|
+
const importers = import_map.get(current);
|
|
158
|
+
if (!importers) return null;
|
|
159
|
+
|
|
160
|
+
for (const importer of importers) {
|
|
161
|
+
if (visited.has(importer)) continue;
|
|
162
|
+
visited.add(importer);
|
|
163
|
+
|
|
164
|
+
const next_chain = [...chain, importer];
|
|
165
|
+
if (entrypoints.has(importer)) {
|
|
166
|
+
return next_chain;
|
|
167
|
+
}
|
|
168
|
+
const result = find_chain(importer, next_chain);
|
|
169
|
+
if (result) return result;
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const chain = find_chain(normalized, [normalized]);
|
|
175
|
+
|
|
176
|
+
if (chain) {
|
|
177
|
+
if (chain.some((id) => remote_module_pattern.test(id))) {
|
|
178
|
+
error_for_missing_config('remote functions', 'experimental.remoteFunctions', 'true');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const pyramid = chain
|
|
182
|
+
.reverse()
|
|
183
|
+
.map((id, i) => {
|
|
184
|
+
return `${' '.repeat(i + 1)}${id}`;
|
|
185
|
+
})
|
|
186
|
+
.join(' imports\n');
|
|
187
|
+
|
|
188
|
+
let message = `Cannot import ${normalized} into code that runs in the browser, as this could leak sensitive information.`;
|
|
189
|
+
message += `\n\n${pyramid}`;
|
|
190
|
+
message += `\n\nIf you're only using the import as a type, change it to \`import type\`.`;
|
|
191
|
+
|
|
192
|
+
throw stackless(message);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// No chain from this server-only module to a client entrypoint was found —
|
|
196
|
+
// the module is only imported from server code, which is valid.
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
// avoid watch mode rebuilds using stale import map data
|
|
201
|
+
buildEnd() {
|
|
202
|
+
import_map.clear();
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
@@ -9,6 +9,7 @@ import sirv from 'sirv';
|
|
|
9
9
|
import { loadEnv, normalizePath } from 'vite';
|
|
10
10
|
import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js';
|
|
11
11
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
12
|
+
import { relative_pathname } from '../../../utils/url.js';
|
|
12
13
|
import { is_chrome_devtools_request, not_found } from '../utils.js';
|
|
13
14
|
import { stackless } from '../../../utils/error.js';
|
|
14
15
|
|
|
@@ -176,9 +177,9 @@ export async function preview(vite, vite_config, svelte_config) {
|
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
if (redirect) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
location: redirect
|
|
180
|
+
res.writeHead(308, {
|
|
181
|
+
// relative so (possibly invisible) path prefixes are preserved
|
|
182
|
+
location: relative_pathname(pathname, redirect) + search
|
|
182
183
|
});
|
|
183
184
|
|
|
184
185
|
res.end();
|
|
@@ -206,7 +207,8 @@ export async function preview(vite, vite_config, svelte_config) {
|
|
|
206
207
|
|
|
207
208
|
const request = getRequest({
|
|
208
209
|
base: `${protocol}://${host}`,
|
|
209
|
-
request: req
|
|
210
|
+
request: req,
|
|
211
|
+
response: res
|
|
210
212
|
});
|
|
211
213
|
|
|
212
214
|
setResponse(
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
/** @import { UserConfig } from 'vite' */
|
|
2
|
+
/** @import { EnforcedConfig } from './types.js' */
|
|
1
3
|
import fs from 'node:fs';
|
|
2
4
|
import path from 'node:path';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import { styleText } from 'node:util';
|
|
3
7
|
import { posixify } from '../../utils/os.js';
|
|
4
8
|
import { negotiate } from '../../utils/http.js';
|
|
5
9
|
import { escape_html } from '../../utils/escape.js';
|
|
6
10
|
import { escape_for_regexp } from '../../utils/regex.js';
|
|
7
11
|
import { stackless } from '../../utils/error.js';
|
|
8
12
|
import { dedent } from '../../core/sync/utils.js';
|
|
9
|
-
import { app_server, app_env_private
|
|
13
|
+
import { app_server, app_env_private } from './module_ids.js';
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Transforms alias to a valid vite.resolve.alias array.
|
|
@@ -119,7 +123,7 @@ export function normalize_id(id, aliases, cwd) {
|
|
|
119
123
|
return '$app/server';
|
|
120
124
|
}
|
|
121
125
|
|
|
122
|
-
if (id === app_env_private
|
|
126
|
+
if (id === app_env_private) {
|
|
123
127
|
return '$app/env/private';
|
|
124
128
|
}
|
|
125
129
|
|
|
@@ -191,8 +195,6 @@ function can_export_remote_module(directory) {
|
|
|
191
195
|
export const server_only_module_pattern = /[/.]server\.[^/]+$/;
|
|
192
196
|
export const server_only_directory_pattern = /\/server\//;
|
|
193
197
|
|
|
194
|
-
export const strip_virtual_prefix = /** @param {string} id */ (id) => id.replace('\0virtual:', '');
|
|
195
|
-
|
|
196
198
|
/**
|
|
197
199
|
* For `error_for_missing_config('remote functions', 'experimental.remoteFunctions', 'true')`,
|
|
198
200
|
* returns:
|
|
@@ -229,3 +231,96 @@ export function error_for_missing_config(feature_name, path, value) {
|
|
|
229
231
|
`
|
|
230
232
|
);
|
|
231
233
|
}
|
|
234
|
+
|
|
235
|
+
/** @type {EnforcedConfig} */
|
|
236
|
+
export const enforced_config = {
|
|
237
|
+
appType: true,
|
|
238
|
+
base: true,
|
|
239
|
+
build: {
|
|
240
|
+
cssCodeSplit: true,
|
|
241
|
+
emptyOutDir: true,
|
|
242
|
+
lib: {
|
|
243
|
+
entry: true,
|
|
244
|
+
name: true,
|
|
245
|
+
formats: true
|
|
246
|
+
},
|
|
247
|
+
manifest: true,
|
|
248
|
+
outDir: true,
|
|
249
|
+
rolldownOptions: {
|
|
250
|
+
input: true,
|
|
251
|
+
output: {
|
|
252
|
+
format: true,
|
|
253
|
+
entryFileNames: true,
|
|
254
|
+
chunkFileNames: true,
|
|
255
|
+
assetFileNames: true
|
|
256
|
+
},
|
|
257
|
+
preserveEntrySignatures: true
|
|
258
|
+
},
|
|
259
|
+
ssr: true
|
|
260
|
+
},
|
|
261
|
+
publicDir: true,
|
|
262
|
+
resolve: {
|
|
263
|
+
alias: {
|
|
264
|
+
$app: true,
|
|
265
|
+
$env: true,
|
|
266
|
+
'<sveltekit:generated>': true
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @param {UserConfig} config
|
|
273
|
+
* @param {UserConfig} resolved_config
|
|
274
|
+
*/
|
|
275
|
+
export function warn_overridden_config(config, resolved_config) {
|
|
276
|
+
const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);
|
|
277
|
+
|
|
278
|
+
if (overridden.length > 0) {
|
|
279
|
+
console.error(
|
|
280
|
+
styleText(
|
|
281
|
+
['bold', 'red'],
|
|
282
|
+
'The following Vite config options will be overridden by SvelteKit:'
|
|
283
|
+
) + overridden.map((key) => `\n - ${key}`).join('')
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* @param {Record<string, any>} config
|
|
290
|
+
* @param {Record<string, any>} resolved_config
|
|
291
|
+
* @param {EnforcedConfig} enforced_config
|
|
292
|
+
* @param {string} path
|
|
293
|
+
* @param {string[]} out used locally to compute the return value
|
|
294
|
+
*/
|
|
295
|
+
export function find_overridden_config(config, resolved_config, enforced_config, path, out) {
|
|
296
|
+
if (config == null || resolved_config == null) {
|
|
297
|
+
return out;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
for (const key in enforced_config) {
|
|
301
|
+
if (typeof config === 'object' && key in config && key in resolved_config) {
|
|
302
|
+
const enforced = enforced_config[key];
|
|
303
|
+
const resolved = resolved_config[key];
|
|
304
|
+
|
|
305
|
+
if (enforced === true) {
|
|
306
|
+
if (comparable(config[key]) !== comparable(resolved)) {
|
|
307
|
+
out.push(path + key);
|
|
308
|
+
}
|
|
309
|
+
} else {
|
|
310
|
+
find_overridden_config(config[key], resolved, enforced, path + key + '.', out);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Normalizes a config value for comparison, since Windows paths may use backslashes
|
|
319
|
+
* and differ in casing (e.g. the drive letter) depending on where they came from.
|
|
320
|
+
* @param {any} value
|
|
321
|
+
*/
|
|
322
|
+
export function comparable(value) {
|
|
323
|
+
if (typeof value !== 'string') return value;
|
|
324
|
+
const normalized = posixify(value);
|
|
325
|
+
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
326
|
+
}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
import { payload } from '../../client/payload.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* `true` if the app is running in the browser.
|
|
5
|
+
* @type {boolean}
|
|
3
6
|
*/
|
|
4
|
-
export const browser
|
|
7
|
+
export const browser = true;
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
|
|
11
|
+
* @type {boolean}
|
|
8
12
|
*/
|
|
9
|
-
export const dev
|
|
13
|
+
export const dev = __SVELTEKIT_DEV__;
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* SvelteKit analyses your app during the `build` step by running it. During this process, `building` is `true`. This also applies during prerendering.
|
|
17
|
+
* @type {boolean}
|
|
13
18
|
*/
|
|
14
|
-
export const building
|
|
19
|
+
export const building = false;
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
22
|
* The value of `config.version.name`.
|
|
18
23
|
*/
|
|
19
|
-
export const version
|
|
24
|
+
export const version = payload.version;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { building, version } from './internal.js';
|
|
1
|
+
export { browser, dev, building, version } from '#app/env';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '<sveltekit:generated>/env/private/server.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from '<sveltekit:generated>/env/public/client.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from '<sveltekit:generated>/env/public/server.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const version = BROWSER ? payload.version : __SVELTEKIT_APP_VERSION__;
|
|
1
|
+
export const browser = false;
|
|
2
|
+
export const dev = __SVELTEKIT_DEV__;
|
|
3
|
+
export const version = __SVELTEKIT_APP_VERSION__;
|
|
5
4
|
export let building = false;
|
|
5
|
+
|
|
6
6
|
export let prerendering = false;
|
|
7
7
|
|
|
8
8
|
export function set_building() {
|