@sveltejs/kit 1.0.0-next.394 → 1.0.0-next.397
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/assets/client/start.js +1 -0
- package/assets/env/dynamic/private.js +1 -0
- package/assets/env/dynamic/public.js +1 -0
- package/assets/env-private.js +9 -0
- package/assets/env-public.js +9 -0
- package/assets/server/index.js +4 -1
- package/dist/chunks/filesystem.js +1 -1
- package/dist/chunks/index.js +4 -0
- package/dist/chunks/sync.js +375 -8
- package/dist/chunks/write_tsconfig.js +63 -15
- package/dist/cli.js +5 -4
- package/dist/vite.js +88 -168
- package/package.json +1 -1
- package/types/ambient.d.ts +59 -12
- package/types/index.d.ts +8 -0
- package/types/internal.d.ts +8 -0
package/assets/client/start.js
CHANGED
|
@@ -4,6 +4,7 @@ import { assets, set_paths } from '../paths.js';
|
|
|
4
4
|
import Root from '__GENERATED__/root.svelte';
|
|
5
5
|
import { components, dictionary, matchers } from '__GENERATED__/client-manifest.js';
|
|
6
6
|
import { init } from './singletons.js';
|
|
7
|
+
export { set_public_env } from '../env-public.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {unknown} err
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { env } from '../../env-private.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { env } from '../../env-public.js';
|
package/assets/server/index.js
CHANGED
|
@@ -1474,7 +1474,10 @@ async function render_response({
|
|
|
1474
1474
|
|
|
1475
1475
|
// prettier-ignore
|
|
1476
1476
|
const init_app = `
|
|
1477
|
-
import { start } from ${s(options.prefix + entry.file)};
|
|
1477
|
+
import { set_public_env, start } from ${s(options.prefix + entry.file)};
|
|
1478
|
+
|
|
1479
|
+
set_public_env(${s(options.public_env)});
|
|
1480
|
+
|
|
1478
1481
|
start({
|
|
1479
1482
|
target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode,
|
|
1480
1483
|
paths: ${s(options.paths)},
|
|
@@ -58,7 +58,7 @@ function copy(source, target, opts = {}) {
|
|
|
58
58
|
to,
|
|
59
59
|
data.replace(
|
|
60
60
|
/** @type {RegExp} */ (regex),
|
|
61
|
-
(
|
|
61
|
+
(_match, key) => /** @type {Record<string, string>} */ (opts.replace)[key]
|
|
62
62
|
)
|
|
63
63
|
);
|
|
64
64
|
} else {
|
package/dist/chunks/index.js
CHANGED
|
@@ -232,6 +232,10 @@ const options = object(
|
|
|
232
232
|
(keypath) => `${keypath} has been renamed to config.kit.moduleExtensions`
|
|
233
233
|
),
|
|
234
234
|
|
|
235
|
+
env: object({
|
|
236
|
+
publicPrefix: string('PUBLIC_')
|
|
237
|
+
}),
|
|
238
|
+
|
|
235
239
|
files: object({
|
|
236
240
|
assets: string('static'),
|
|
237
241
|
hooks: string(join('src', 'hooks')),
|
package/dist/chunks/sync.js
CHANGED
|
@@ -3,7 +3,9 @@ import fs__default from 'fs';
|
|
|
3
3
|
import { g as get_runtime_directory } from './utils.js';
|
|
4
4
|
import { p as posixify, c as copy, r as rimraf } from './filesystem.js';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
|
-
import { w as write_if_changed, t as trim, a as write, b as write_tsconfig } from './write_tsconfig.js';
|
|
6
|
+
import { w as write_if_changed, t as trim, a as write, v as valid_identifier, r as reserved, b as write_tsconfig } from './write_tsconfig.js';
|
|
7
|
+
import { $ } from './index.js';
|
|
8
|
+
import { loadEnv, loadConfigFromFile } from 'vite';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @param typeMap [Object] Map of MIME type -> Array[extensions]
|
|
@@ -910,13 +912,374 @@ function write_types(config, manifest_data) {
|
|
|
910
912
|
});
|
|
911
913
|
}
|
|
912
914
|
|
|
913
|
-
/**
|
|
914
|
-
|
|
915
|
+
/**
|
|
916
|
+
* @param {import('vite').ResolvedConfig} config
|
|
917
|
+
* @param {import('vite').ConfigEnv} config_env
|
|
918
|
+
* @return {Promise<import('vite').UserConfig>}
|
|
919
|
+
*/
|
|
920
|
+
async function get_vite_config(config, config_env) {
|
|
921
|
+
const loaded = await loadConfigFromFile(
|
|
922
|
+
config_env,
|
|
923
|
+
config.configFile,
|
|
924
|
+
undefined,
|
|
925
|
+
config.logLevel
|
|
926
|
+
);
|
|
927
|
+
|
|
928
|
+
if (!loaded) {
|
|
929
|
+
throw new Error('Could not load Vite config');
|
|
930
|
+
}
|
|
931
|
+
return { ...loaded.config, mode: config_env.mode };
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* @param {...import('vite').UserConfig} configs
|
|
936
|
+
* @returns {import('vite').UserConfig}
|
|
937
|
+
*/
|
|
938
|
+
function merge_vite_configs(...configs) {
|
|
939
|
+
return deep_merge(
|
|
940
|
+
...configs.map((config) => ({
|
|
941
|
+
...config,
|
|
942
|
+
resolve: {
|
|
943
|
+
...config.resolve,
|
|
944
|
+
alias: normalize_alias(config.resolve?.alias || {})
|
|
945
|
+
}
|
|
946
|
+
}))
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Takes zero or more objects and returns a new object that has all the values
|
|
952
|
+
* deeply merged together. None of the original objects will be mutated at any
|
|
953
|
+
* level, and the returned object will have no references to the original
|
|
954
|
+
* objects at any depth. If there's a conflict the last one wins, except for
|
|
955
|
+
* arrays which will be combined.
|
|
956
|
+
* @param {...Object} objects
|
|
957
|
+
* @returns {Record<string, any>} the merged object
|
|
958
|
+
*/
|
|
959
|
+
function deep_merge(...objects) {
|
|
960
|
+
const result = {};
|
|
961
|
+
/** @type {string[]} */
|
|
962
|
+
objects.forEach((o) => merge_into(result, o));
|
|
963
|
+
return result;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* normalize kit.vite.resolve.alias as an array
|
|
968
|
+
* @param {import('vite').AliasOptions} o
|
|
969
|
+
* @returns {import('vite').Alias[]}
|
|
970
|
+
*/
|
|
971
|
+
function normalize_alias(o) {
|
|
972
|
+
if (Array.isArray(o)) return o;
|
|
973
|
+
return Object.entries(o).map(([find, replacement]) => ({ find, replacement }));
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Merges b into a, recursively, mutating a.
|
|
978
|
+
* @param {Record<string, any>} a
|
|
979
|
+
* @param {Record<string, any>} b
|
|
980
|
+
*/
|
|
981
|
+
function merge_into(a, b) {
|
|
982
|
+
/**
|
|
983
|
+
* Checks for "plain old Javascript object", typically made as an object
|
|
984
|
+
* literal. Excludes Arrays and built-in types like Buffer.
|
|
985
|
+
* @param {any} x
|
|
986
|
+
*/
|
|
987
|
+
const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
|
|
988
|
+
|
|
989
|
+
for (const prop in b) {
|
|
990
|
+
if (is_plain_object(b[prop])) {
|
|
991
|
+
if (!is_plain_object(a[prop])) {
|
|
992
|
+
a[prop] = {};
|
|
993
|
+
}
|
|
994
|
+
merge_into(a[prop], b[prop]);
|
|
995
|
+
} else if (Array.isArray(b[prop])) {
|
|
996
|
+
if (!Array.isArray(a[prop])) {
|
|
997
|
+
a[prop] = [];
|
|
998
|
+
}
|
|
999
|
+
a[prop].push(...b[prop]);
|
|
1000
|
+
} else {
|
|
1001
|
+
a[prop] = b[prop];
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/** @param {import('types').ValidatedKitConfig} config */
|
|
1007
|
+
function get_aliases(config) {
|
|
1008
|
+
/** @type {Record<string, string>} */
|
|
1009
|
+
const alias = {
|
|
1010
|
+
__GENERATED__: path__default.posix.join(config.outDir, 'generated'),
|
|
1011
|
+
|
|
1012
|
+
$app: `${get_runtime_directory(config)}/app`,
|
|
1013
|
+
|
|
1014
|
+
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
1015
|
+
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
1016
|
+
$lib: config.files.lib
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
alias['$env'] = `${get_runtime_directory(config)}/env`;
|
|
1020
|
+
|
|
1021
|
+
for (const [key, value] of Object.entries(config.alias)) {
|
|
1022
|
+
alias[key] = path__default.resolve(value);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
return alias;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
|
|
1030
|
+
* @param {string} entry
|
|
1031
|
+
* @returns {string|null}
|
|
1032
|
+
*/
|
|
1033
|
+
function resolve_entry(entry) {
|
|
1034
|
+
if (fs__default.existsSync(entry)) {
|
|
1035
|
+
const stats = fs__default.statSync(entry);
|
|
1036
|
+
if (stats.isDirectory()) {
|
|
1037
|
+
return resolve_entry(path__default.join(entry, 'index'));
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
return entry;
|
|
1041
|
+
} else {
|
|
1042
|
+
const dir = path__default.dirname(entry);
|
|
1043
|
+
|
|
1044
|
+
if (fs__default.existsSync(dir)) {
|
|
1045
|
+
const base = path__default.basename(entry);
|
|
1046
|
+
const files = fs__default.readdirSync(dir);
|
|
1047
|
+
|
|
1048
|
+
const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
|
|
1049
|
+
|
|
1050
|
+
if (found) return path__default.join(dir, found);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
return null;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* @param {string} str
|
|
1059
|
+
* @param {number} times
|
|
1060
|
+
*/
|
|
1061
|
+
function repeat(str, times) {
|
|
1062
|
+
return new Array(times + 1).join(str);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* Create a formatted error for an illegal import.
|
|
1067
|
+
* @param {Array<{name: string, dynamic: boolean}>} stack
|
|
1068
|
+
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
1069
|
+
*/
|
|
1070
|
+
function format_illegal_import_chain(stack, out_dir) {
|
|
1071
|
+
const app = path__default.join(out_dir, 'runtime/env');
|
|
1072
|
+
|
|
1073
|
+
stack = stack.map((file) => {
|
|
1074
|
+
if (file.name.startsWith(app)) return { ...file, name: file.name.replace(app, '$env') };
|
|
1075
|
+
return { ...file, name: path__default.relative(process.cwd(), file.name) };
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
const pyramid = stack
|
|
1079
|
+
.map(
|
|
1080
|
+
(file, i) =>
|
|
1081
|
+
`${repeat(' ', i * 2)}- ${file.name} ${
|
|
1082
|
+
file.dynamic ? '(imported by parent dynamically)' : ''
|
|
1083
|
+
}`
|
|
1084
|
+
)
|
|
1085
|
+
.join('\n');
|
|
1086
|
+
|
|
1087
|
+
return `Cannot import ${stack.at(-1)?.name} into client-side code:\n${pyramid}`;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Load environment variables from process.env and .env files
|
|
1092
|
+
* @param {string} mode
|
|
1093
|
+
* @param {string} prefix
|
|
1094
|
+
*/
|
|
1095
|
+
function get_env(mode, prefix) {
|
|
1096
|
+
const entries = Object.entries(loadEnv(mode, process.cwd(), ''));
|
|
1097
|
+
|
|
1098
|
+
return {
|
|
1099
|
+
public: Object.fromEntries(entries.filter(([k]) => k.startsWith(prefix))),
|
|
1100
|
+
private: Object.fromEntries(entries.filter(([k]) => !k.startsWith(prefix)))
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
1106
|
+
* @param {import('rollup').ModuleInfo} node
|
|
1107
|
+
* @param {Set<string>} illegal_imports
|
|
1108
|
+
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
1109
|
+
*/
|
|
1110
|
+
function prevent_illegal_rollup_imports(node_getter, node, illegal_imports, out_dir) {
|
|
1111
|
+
const chain = find_illegal_rollup_imports(node_getter, node, false, illegal_imports);
|
|
1112
|
+
if (chain) throw new Error(format_illegal_import_chain(chain, out_dir));
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
1117
|
+
* @param {import('rollup').ModuleInfo} node
|
|
1118
|
+
* @param {boolean} dynamic
|
|
1119
|
+
* @param {Set<string>} illegal_imports
|
|
1120
|
+
* @param {Set<string>} seen
|
|
1121
|
+
* @returns {Array<import('types').ImportNode> | undefined}
|
|
1122
|
+
*/
|
|
1123
|
+
const find_illegal_rollup_imports = (
|
|
1124
|
+
node_getter,
|
|
1125
|
+
node,
|
|
1126
|
+
dynamic,
|
|
1127
|
+
illegal_imports,
|
|
1128
|
+
seen = new Set()
|
|
1129
|
+
) => {
|
|
1130
|
+
if (seen.has(node.id)) return;
|
|
1131
|
+
seen.add(node.id);
|
|
1132
|
+
|
|
1133
|
+
if (illegal_imports.has(node.id)) {
|
|
1134
|
+
return [{ name: node.id, dynamic }];
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
for (const id of node.importedIds) {
|
|
1138
|
+
const child = node_getter(id);
|
|
1139
|
+
const chain =
|
|
1140
|
+
child && find_illegal_rollup_imports(node_getter, child, false, illegal_imports, seen);
|
|
1141
|
+
if (chain) return [{ name: node.id, dynamic }, ...chain];
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
for (const id of node.dynamicallyImportedIds) {
|
|
1145
|
+
const child = node_getter(id);
|
|
1146
|
+
const chain =
|
|
1147
|
+
child && find_illegal_rollup_imports(node_getter, child, true, illegal_imports, seen);
|
|
1148
|
+
if (chain) return [{ name: node.id, dynamic }, ...chain];
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Throw an error if a private module is imported from a client-side node.
|
|
1154
|
+
* @param {import('vite').ModuleNode} node
|
|
1155
|
+
* @param {Set<string>} illegal_imports
|
|
1156
|
+
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
1157
|
+
*/
|
|
1158
|
+
function prevent_illegal_vite_imports(node, illegal_imports, out_dir) {
|
|
1159
|
+
const chain = find_illegal_vite_imports(node, illegal_imports);
|
|
1160
|
+
if (chain) throw new Error(format_illegal_import_chain(chain, out_dir));
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* @param {import('vite').ModuleNode} node
|
|
1165
|
+
* @param {Set<string>} illegal_imports
|
|
1166
|
+
* @param {Set<string>} seen
|
|
1167
|
+
* @returns {Array<import('types').ImportNode> | null}
|
|
1168
|
+
*/
|
|
1169
|
+
function find_illegal_vite_imports(node, illegal_imports, seen = new Set()) {
|
|
1170
|
+
if (!node.id) return null; // TODO when does this happen?
|
|
1171
|
+
|
|
1172
|
+
if (seen.has(node.id)) return null;
|
|
1173
|
+
seen.add(node.id);
|
|
1174
|
+
|
|
1175
|
+
if (node.id && illegal_imports.has(node.id)) {
|
|
1176
|
+
return [{ name: node.id, dynamic: false }];
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
for (const child of node.importedModules) {
|
|
1180
|
+
const chain = child && find_illegal_vite_imports(child, illegal_imports, seen);
|
|
1181
|
+
if (chain) return [{ name: node.id, dynamic: false }, ...chain];
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
return null;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
const autogen_comment = '// this file is generated — do not edit it\n';
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* Writes the existing environment variables in process.env to
|
|
1191
|
+
* $env/static/private and $env/static/public
|
|
1192
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
1193
|
+
* @param {string} mode The Vite mode
|
|
1194
|
+
*/
|
|
1195
|
+
function write_env(config, mode) {
|
|
1196
|
+
const env = get_env(mode, config.env.publicPrefix);
|
|
1197
|
+
|
|
1198
|
+
// TODO when testing src, `$app` points at `src/runtime/app`... will
|
|
1199
|
+
// probably need to fiddle with aliases
|
|
1200
|
+
write_if_changed(
|
|
1201
|
+
path__default.join(config.outDir, 'runtime/env/static/public.js'),
|
|
1202
|
+
create_module('$env/static/public', env.public)
|
|
1203
|
+
);
|
|
1204
|
+
|
|
1205
|
+
write_if_changed(
|
|
1206
|
+
path__default.join(config.outDir, 'runtime/env/static/private.js'),
|
|
1207
|
+
create_module('$env/static/private', env.private)
|
|
1208
|
+
);
|
|
1209
|
+
|
|
1210
|
+
write_if_changed(
|
|
1211
|
+
path__default.join(config.outDir, 'ambient.d.ts'),
|
|
1212
|
+
autogen_comment +
|
|
1213
|
+
create_types('$env/static/public', env.public) +
|
|
1214
|
+
'\n\n' +
|
|
1215
|
+
create_types('$env/static/private', env.private)
|
|
1216
|
+
);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* @param {string} id
|
|
1221
|
+
* @param {Record<string, string>} env
|
|
1222
|
+
* @returns {string}
|
|
1223
|
+
*/
|
|
1224
|
+
function create_module(id, env) {
|
|
1225
|
+
/** @type {string[]} */
|
|
1226
|
+
const declarations = [];
|
|
1227
|
+
|
|
1228
|
+
for (const key in env) {
|
|
1229
|
+
const warning = !valid_identifier.test(key)
|
|
1230
|
+
? 'not a valid identifier'
|
|
1231
|
+
: reserved.has(key)
|
|
1232
|
+
? 'a reserved word'
|
|
1233
|
+
: null;
|
|
1234
|
+
|
|
1235
|
+
if (warning) {
|
|
1236
|
+
console.error(
|
|
1237
|
+
$
|
|
1238
|
+
.bold()
|
|
1239
|
+
.yellow(`Omitting environment variable "${key}" from ${id} as it is ${warning}`)
|
|
1240
|
+
);
|
|
1241
|
+
continue;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
const comment = `/** @type {import('${id}').${key}} */`;
|
|
1245
|
+
const declaration = `export const ${key} = ${JSON.stringify(env[key])};`;
|
|
1246
|
+
|
|
1247
|
+
declarations.push(`${comment}\n${declaration}`);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
return autogen_comment + declarations.join('\n\n');
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* @param {string} id
|
|
1255
|
+
* @param {Record<string, string>} env
|
|
1256
|
+
* @returns {string}
|
|
1257
|
+
*/
|
|
1258
|
+
function create_types(id, env) {
|
|
1259
|
+
const declarations = Object.keys(env)
|
|
1260
|
+
.filter((k) => valid_identifier.test(k))
|
|
1261
|
+
.map((k) => `\texport const ${k}: string;`)
|
|
1262
|
+
.join('\n');
|
|
1263
|
+
|
|
1264
|
+
return `declare module '${id}' {\n${declarations}\n}`;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* Initialize SvelteKit's generated files.
|
|
1269
|
+
* @param {import('types').ValidatedConfig} config
|
|
1270
|
+
* @param {string} mode
|
|
1271
|
+
*/
|
|
1272
|
+
function init(config, mode) {
|
|
915
1273
|
copy_assets(path__default.join(config.kit.outDir, 'runtime'));
|
|
1274
|
+
|
|
916
1275
|
write_tsconfig(config.kit);
|
|
1276
|
+
write_env(config.kit, mode);
|
|
917
1277
|
}
|
|
918
1278
|
|
|
919
|
-
/**
|
|
1279
|
+
/**
|
|
1280
|
+
* Update SvelteKit's generated files.
|
|
1281
|
+
* @param {import('types').ValidatedConfig} config
|
|
1282
|
+
*/
|
|
920
1283
|
function update(config) {
|
|
921
1284
|
const manifest_data = create_manifest_data({ config });
|
|
922
1285
|
|
|
@@ -931,9 +1294,13 @@ function update(config) {
|
|
|
931
1294
|
return { manifest_data };
|
|
932
1295
|
}
|
|
933
1296
|
|
|
934
|
-
/**
|
|
935
|
-
|
|
936
|
-
|
|
1297
|
+
/**
|
|
1298
|
+
* Run sync.init and sync.update in series, returning the result from sync.update.
|
|
1299
|
+
* @param {import('types').ValidatedConfig} config
|
|
1300
|
+
* @param {string} mode The Vite mode
|
|
1301
|
+
*/
|
|
1302
|
+
function all(config, mode) {
|
|
1303
|
+
init(config, mode);
|
|
937
1304
|
return update(config);
|
|
938
1305
|
}
|
|
939
1306
|
|
|
@@ -944,4 +1311,4 @@ var sync = /*#__PURE__*/Object.freeze({
|
|
|
944
1311
|
all: all
|
|
945
1312
|
});
|
|
946
1313
|
|
|
947
|
-
export {
|
|
1314
|
+
export { get_vite_config as a, get_env as b, parse_route_id as c, all as d, prevent_illegal_rollup_imports as e, sync as f, get_aliases as g, init as i, merge_vite_configs as m, prevent_illegal_vite_imports as p, resolve_entry as r, s, update as u };
|
|
@@ -33,6 +33,59 @@ function trim(str) {
|
|
|
33
33
|
return str.replace(pattern, '').trim();
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const reserved = new Set([
|
|
37
|
+
'do',
|
|
38
|
+
'if',
|
|
39
|
+
'in',
|
|
40
|
+
'for',
|
|
41
|
+
'let',
|
|
42
|
+
'new',
|
|
43
|
+
'try',
|
|
44
|
+
'var',
|
|
45
|
+
'case',
|
|
46
|
+
'else',
|
|
47
|
+
'enum',
|
|
48
|
+
'eval',
|
|
49
|
+
'null',
|
|
50
|
+
'this',
|
|
51
|
+
'true',
|
|
52
|
+
'void',
|
|
53
|
+
'with',
|
|
54
|
+
'await',
|
|
55
|
+
'break',
|
|
56
|
+
'catch',
|
|
57
|
+
'class',
|
|
58
|
+
'const',
|
|
59
|
+
'false',
|
|
60
|
+
'super',
|
|
61
|
+
'throw',
|
|
62
|
+
'while',
|
|
63
|
+
'yield',
|
|
64
|
+
'delete',
|
|
65
|
+
'export',
|
|
66
|
+
'import',
|
|
67
|
+
'public',
|
|
68
|
+
'return',
|
|
69
|
+
'static',
|
|
70
|
+
'switch',
|
|
71
|
+
'typeof',
|
|
72
|
+
'default',
|
|
73
|
+
'extends',
|
|
74
|
+
'finally',
|
|
75
|
+
'package',
|
|
76
|
+
'private',
|
|
77
|
+
'continue',
|
|
78
|
+
'debugger',
|
|
79
|
+
'function',
|
|
80
|
+
'arguments',
|
|
81
|
+
'interface',
|
|
82
|
+
'protected',
|
|
83
|
+
'implements',
|
|
84
|
+
'instanceof'
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
const valid_identifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
88
|
+
|
|
36
89
|
/** @param {string} file */
|
|
37
90
|
const exists = (file) => fs__default.existsSync(file) && file;
|
|
38
91
|
|
|
@@ -53,18 +106,13 @@ function write_tsconfig(config, cwd = process.cwd()) {
|
|
|
53
106
|
/** @param {string} file */
|
|
54
107
|
const config_relative = (file) => posixify(path__default.relative(config.outDir, file));
|
|
55
108
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
project_relative(path__default.dirname(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
dirs.forEach((dir) => {
|
|
64
|
-
include.push(config_relative(`${dir}/**/*.js`));
|
|
65
|
-
include.push(config_relative(`${dir}/**/*.ts`));
|
|
66
|
-
include.push(config_relative(`${dir}/**/*.svelte`));
|
|
67
|
-
});
|
|
109
|
+
const include = ['ambient.d.ts'];
|
|
110
|
+
for (const dir of [config.files.routes, config.files.lib]) {
|
|
111
|
+
const relative = project_relative(path__default.dirname(dir));
|
|
112
|
+
include.push(config_relative(`${relative}/**/*.js`));
|
|
113
|
+
include.push(config_relative(`${relative}/**/*.ts`));
|
|
114
|
+
include.push(config_relative(`${relative}/**/*.svelte`));
|
|
115
|
+
}
|
|
68
116
|
|
|
69
117
|
/** @type {Record<string, string[]>} */
|
|
70
118
|
const paths = {};
|
|
@@ -101,13 +149,13 @@ function write_tsconfig(config, cwd = process.cwd()) {
|
|
|
101
149
|
|
|
102
150
|
// This is required for svelte-kit package to work as expected
|
|
103
151
|
// Can be overwritten
|
|
104
|
-
lib: ['esnext', 'DOM'],
|
|
152
|
+
lib: ['esnext', 'DOM', 'DOM.Iterable'],
|
|
105
153
|
moduleResolution: 'node',
|
|
106
154
|
module: 'esnext',
|
|
107
155
|
target: 'esnext'
|
|
108
156
|
},
|
|
109
157
|
include,
|
|
110
|
-
exclude: [config_relative('node_modules/**'), '
|
|
158
|
+
exclude: [config_relative('node_modules/**'), './[!ambient.d.ts]**']
|
|
111
159
|
},
|
|
112
160
|
null,
|
|
113
161
|
'\t'
|
|
@@ -166,4 +214,4 @@ function validate(config, cwd, out, user_file) {
|
|
|
166
214
|
}
|
|
167
215
|
}
|
|
168
216
|
|
|
169
|
-
export { write as a, write_tsconfig as b, trim as t, write_if_changed as w };
|
|
217
|
+
export { write as a, write_tsconfig as b, reserved as r, trim as t, valid_identifier as v, write_if_changed as w };
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ function handle_error(e) {
|
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
22
|
+
const prog = sade('svelte-kit').version('1.0.0-next.397');
|
|
23
23
|
|
|
24
24
|
prog
|
|
25
25
|
.command('package')
|
|
@@ -39,7 +39,8 @@ prog
|
|
|
39
39
|
prog
|
|
40
40
|
.command('sync')
|
|
41
41
|
.describe('Synchronise generated files')
|
|
42
|
-
.
|
|
42
|
+
.option('--mode', 'Specify a mode for loading environment variables', 'development')
|
|
43
|
+
.action(async ({ mode }) => {
|
|
43
44
|
if (!fs__default.existsSync('svelte.config.js')) {
|
|
44
45
|
console.warn('Missing svelte.config.js — skipping');
|
|
45
46
|
return;
|
|
@@ -47,8 +48,8 @@ prog
|
|
|
47
48
|
|
|
48
49
|
try {
|
|
49
50
|
const config = await load_config();
|
|
50
|
-
const sync = await import('./chunks/sync.js').then(function (n) { return n.
|
|
51
|
-
sync.all(config);
|
|
51
|
+
const sync = await import('./chunks/sync.js').then(function (n) { return n.f; });
|
|
52
|
+
sync.all(config, mode);
|
|
52
53
|
} catch (error) {
|
|
53
54
|
handle_error(error);
|
|
54
55
|
}
|
package/dist/vite.js
CHANGED
|
@@ -4,9 +4,9 @@ import path from 'node:path';
|
|
|
4
4
|
import { a as load_template, $, l as load_config } from './chunks/index.js';
|
|
5
5
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
6
6
|
import * as vite from 'vite';
|
|
7
|
-
import {
|
|
7
|
+
import { loadEnv } from 'vite';
|
|
8
8
|
import { p as posixify, m as mkdirp, r as rimraf } from './chunks/filesystem.js';
|
|
9
|
-
import { s, i as init, u as update, p as parse_route_id,
|
|
9
|
+
import { g as get_aliases, r as resolve_entry, s, m as merge_vite_configs, a as get_vite_config, i as init, b as get_env, u as update, p as prevent_illegal_vite_imports, c as parse_route_id, d as all, e as prevent_illegal_rollup_imports } from './chunks/sync.js';
|
|
10
10
|
import * as fs from 'fs';
|
|
11
11
|
import fs__default, { readdirSync, statSync } from 'fs';
|
|
12
12
|
import path__default, { resolve, join, normalize } from 'path';
|
|
@@ -41,145 +41,6 @@ import 'node:util';
|
|
|
41
41
|
import 'node:net';
|
|
42
42
|
import 'crypto';
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* @param {import('vite').ResolvedConfig} config
|
|
46
|
-
* @param {import('vite').ConfigEnv} config_env
|
|
47
|
-
* @return {Promise<import('vite').UserConfig>}
|
|
48
|
-
*/
|
|
49
|
-
async function get_vite_config(config, config_env) {
|
|
50
|
-
const loaded = await loadConfigFromFile(
|
|
51
|
-
config_env,
|
|
52
|
-
config.configFile,
|
|
53
|
-
undefined,
|
|
54
|
-
config.logLevel
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
if (!loaded) {
|
|
58
|
-
throw new Error('Could not load Vite config');
|
|
59
|
-
}
|
|
60
|
-
return { ...loaded.config, mode: config_env.mode };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @param {...import('vite').UserConfig} configs
|
|
65
|
-
* @returns {import('vite').UserConfig}
|
|
66
|
-
*/
|
|
67
|
-
function merge_vite_configs(...configs) {
|
|
68
|
-
return deep_merge(
|
|
69
|
-
...configs.map((config) => ({
|
|
70
|
-
...config,
|
|
71
|
-
resolve: {
|
|
72
|
-
...config.resolve,
|
|
73
|
-
alias: normalize_alias(config.resolve?.alias || {})
|
|
74
|
-
}
|
|
75
|
-
}))
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Takes zero or more objects and returns a new object that has all the values
|
|
81
|
-
* deeply merged together. None of the original objects will be mutated at any
|
|
82
|
-
* level, and the returned object will have no references to the original
|
|
83
|
-
* objects at any depth. If there's a conflict the last one wins, except for
|
|
84
|
-
* arrays which will be combined.
|
|
85
|
-
* @param {...Object} objects
|
|
86
|
-
* @returns {Record<string, any>} the merged object
|
|
87
|
-
*/
|
|
88
|
-
function deep_merge(...objects) {
|
|
89
|
-
const result = {};
|
|
90
|
-
/** @type {string[]} */
|
|
91
|
-
objects.forEach((o) => merge_into(result, o));
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* normalize kit.vite.resolve.alias as an array
|
|
97
|
-
* @param {import('vite').AliasOptions} o
|
|
98
|
-
* @returns {import('vite').Alias[]}
|
|
99
|
-
*/
|
|
100
|
-
function normalize_alias(o) {
|
|
101
|
-
if (Array.isArray(o)) return o;
|
|
102
|
-
return Object.entries(o).map(([find, replacement]) => ({ find, replacement }));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Merges b into a, recursively, mutating a.
|
|
107
|
-
* @param {Record<string, any>} a
|
|
108
|
-
* @param {Record<string, any>} b
|
|
109
|
-
*/
|
|
110
|
-
function merge_into(a, b) {
|
|
111
|
-
/**
|
|
112
|
-
* Checks for "plain old Javascript object", typically made as an object
|
|
113
|
-
* literal. Excludes Arrays and built-in types like Buffer.
|
|
114
|
-
* @param {any} x
|
|
115
|
-
*/
|
|
116
|
-
const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
|
|
117
|
-
|
|
118
|
-
for (const prop in b) {
|
|
119
|
-
if (is_plain_object(b[prop])) {
|
|
120
|
-
if (!is_plain_object(a[prop])) {
|
|
121
|
-
a[prop] = {};
|
|
122
|
-
}
|
|
123
|
-
merge_into(a[prop], b[prop]);
|
|
124
|
-
} else if (Array.isArray(b[prop])) {
|
|
125
|
-
if (!Array.isArray(a[prop])) {
|
|
126
|
-
a[prop] = [];
|
|
127
|
-
}
|
|
128
|
-
a[prop].push(...b[prop]);
|
|
129
|
-
} else {
|
|
130
|
-
a[prop] = b[prop];
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** @param {import('types').ValidatedKitConfig} config */
|
|
136
|
-
function get_aliases(config) {
|
|
137
|
-
/** @type {Record<string, string>} */
|
|
138
|
-
const alias = {
|
|
139
|
-
__GENERATED__: path__default.posix.join(config.outDir, 'generated'),
|
|
140
|
-
$app: `${get_runtime_directory(config)}/app`,
|
|
141
|
-
|
|
142
|
-
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
143
|
-
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
144
|
-
$lib: config.files.lib
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
for (const [key, value] of Object.entries(config.alias)) {
|
|
148
|
-
alias[key] = path__default.resolve(value);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return alias;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
|
|
156
|
-
* @param {string} entry
|
|
157
|
-
* @returns {string|null}
|
|
158
|
-
*/
|
|
159
|
-
function resolve_entry(entry) {
|
|
160
|
-
if (fs__default.existsSync(entry)) {
|
|
161
|
-
const stats = fs__default.statSync(entry);
|
|
162
|
-
if (stats.isDirectory()) {
|
|
163
|
-
return resolve_entry(path__default.join(entry, 'index'));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return entry;
|
|
167
|
-
} else {
|
|
168
|
-
const dir = path__default.dirname(entry);
|
|
169
|
-
|
|
170
|
-
if (fs__default.existsSync(dir)) {
|
|
171
|
-
const base = path__default.basename(entry);
|
|
172
|
-
const files = fs__default.readdirSync(dir);
|
|
173
|
-
|
|
174
|
-
const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
|
|
175
|
-
|
|
176
|
-
if (found) return path__default.join(dir, found);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
44
|
/**
|
|
184
45
|
* @typedef {import('rollup').RollupOutput} RollupOutput
|
|
185
46
|
* @typedef {import('rollup').OutputChunk} OutputChunk
|
|
@@ -360,6 +221,8 @@ import root from '__GENERATED__/root.svelte';
|
|
|
360
221
|
import { respond } from '${runtime}/server/index.js';
|
|
361
222
|
import { set_paths, assets, base } from '${runtime}/paths.js';
|
|
362
223
|
import { set_prerendering } from '${runtime}/env.js';
|
|
224
|
+
import { set_private_env } from '${runtime}/env-private.js';
|
|
225
|
+
import { set_public_env } from '${runtime}/env-public.js';
|
|
363
226
|
|
|
364
227
|
const template = ({ head, body, assets, nonce }) => ${s(template)
|
|
365
228
|
.replace('%sveltekit.head%', '" + head + "')
|
|
@@ -411,6 +274,7 @@ export class Server {
|
|
|
411
274
|
default: ${config.kit.prerender.default},
|
|
412
275
|
enabled: ${config.kit.prerender.enabled}
|
|
413
276
|
},
|
|
277
|
+
public_env: {},
|
|
414
278
|
read,
|
|
415
279
|
root,
|
|
416
280
|
service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
|
|
@@ -421,6 +285,23 @@ export class Server {
|
|
|
421
285
|
};
|
|
422
286
|
}
|
|
423
287
|
|
|
288
|
+
init({ env }) {
|
|
289
|
+
const entries = Object.entries(env);
|
|
290
|
+
|
|
291
|
+
const prv = Object.fromEntries(Object.entries(env).filter(([k]) => !k.startsWith('${
|
|
292
|
+
config.kit.env.publicPrefix
|
|
293
|
+
}')));
|
|
294
|
+
|
|
295
|
+
const pub = Object.fromEntries(Object.entries(env).filter(([k]) => k.startsWith('${
|
|
296
|
+
config.kit.env.publicPrefix
|
|
297
|
+
}')));
|
|
298
|
+
|
|
299
|
+
set_private_env(prv);
|
|
300
|
+
set_public_env(pub);
|
|
301
|
+
|
|
302
|
+
this.options.public_env = pub;
|
|
303
|
+
}
|
|
304
|
+
|
|
424
305
|
async respond(request, options = {}) {
|
|
425
306
|
if (!(request instanceof Request)) {
|
|
426
307
|
throw new Error('The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
|
|
@@ -1376,12 +1257,13 @@ const cwd$1 = process.cwd();
|
|
|
1376
1257
|
* @param {import('vite').ViteDevServer} vite
|
|
1377
1258
|
* @param {import('vite').ResolvedConfig} vite_config
|
|
1378
1259
|
* @param {import('types').ValidatedConfig} svelte_config
|
|
1260
|
+
* @param {Set<string>} illegal_imports
|
|
1379
1261
|
* @return {Promise<Promise<() => void>>}
|
|
1380
1262
|
*/
|
|
1381
|
-
async function dev(vite, vite_config, svelte_config) {
|
|
1263
|
+
async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
1382
1264
|
installPolyfills();
|
|
1383
1265
|
|
|
1384
|
-
init(svelte_config);
|
|
1266
|
+
init(svelte_config, vite_config.mode);
|
|
1385
1267
|
|
|
1386
1268
|
const runtime = get_runtime_prefix(svelte_config.kit);
|
|
1387
1269
|
|
|
@@ -1412,6 +1294,11 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
1412
1294
|
await vite.ssrLoadModule(url)
|
|
1413
1295
|
);
|
|
1414
1296
|
|
|
1297
|
+
const node = await vite.moduleGraph.getModuleByUrl(url);
|
|
1298
|
+
if (!node) throw new Error(`Could not find node for ${url}`);
|
|
1299
|
+
|
|
1300
|
+
prevent_illegal_vite_imports(node, illegal_imports, svelte_config.kit.outDir);
|
|
1301
|
+
|
|
1415
1302
|
return {
|
|
1416
1303
|
module,
|
|
1417
1304
|
index,
|
|
@@ -1420,10 +1307,6 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
1420
1307
|
stylesheets: [],
|
|
1421
1308
|
// in dev we inline all styles to avoid FOUC
|
|
1422
1309
|
inline_styles: async () => {
|
|
1423
|
-
const node = await vite.moduleGraph.getModuleByUrl(url);
|
|
1424
|
-
|
|
1425
|
-
if (!node) throw new Error(`Could not find node for ${url}`);
|
|
1426
|
-
|
|
1427
1310
|
const deps = new Set();
|
|
1428
1311
|
await find_deps(vite, node, deps);
|
|
1429
1312
|
|
|
@@ -1595,6 +1478,17 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
1595
1478
|
);
|
|
1596
1479
|
}
|
|
1597
1480
|
|
|
1481
|
+
const runtime_base = true
|
|
1482
|
+
? `/${posixify(path__default.relative(cwd$1, `${svelte_config.kit.outDir}/runtime`))}`
|
|
1483
|
+
: `/@fs${runtime}`;
|
|
1484
|
+
|
|
1485
|
+
const { set_private_env } = await vite.ssrLoadModule(`${runtime_base}/env-private.js`);
|
|
1486
|
+
const { set_public_env } = await vite.ssrLoadModule(`${runtime_base}/env-public.js`);
|
|
1487
|
+
|
|
1488
|
+
const env = get_env(vite_config.mode, svelte_config.kit.env.publicPrefix);
|
|
1489
|
+
set_private_env(env.private);
|
|
1490
|
+
set_public_env(env.public);
|
|
1491
|
+
|
|
1598
1492
|
/** @type {Partial<import('types').Hooks>} */
|
|
1599
1493
|
const user_hooks = resolve_entry(svelte_config.kit.files.hooks)
|
|
1600
1494
|
? await vite.ssrLoadModule(`/${svelte_config.kit.files.hooks}`)
|
|
@@ -1640,11 +1534,7 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
1640
1534
|
`/${posixify(path__default.relative(cwd$1, `${svelte_config.kit.outDir}/generated/root.svelte`))}`
|
|
1641
1535
|
);
|
|
1642
1536
|
|
|
1643
|
-
const paths = await vite.ssrLoadModule(
|
|
1644
|
-
true
|
|
1645
|
-
? `/${posixify(path__default.relative(cwd$1, `${svelte_config.kit.outDir}/runtime/paths.js`))}`
|
|
1646
|
-
: `/@fs${runtime}/paths.js`
|
|
1647
|
-
);
|
|
1537
|
+
const paths = await vite.ssrLoadModule(`${runtime_base}/paths.js`);
|
|
1648
1538
|
|
|
1649
1539
|
paths.set_paths({
|
|
1650
1540
|
base: svelte_config.kit.paths.base,
|
|
@@ -1703,6 +1593,7 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
1703
1593
|
default: svelte_config.kit.prerender.default,
|
|
1704
1594
|
enabled: svelte_config.kit.prerender.enabled
|
|
1705
1595
|
},
|
|
1596
|
+
public_env: env.public,
|
|
1706
1597
|
read: (file) => fs__default.readFileSync(path__default.join(svelte_config.kit.files.assets, file)),
|
|
1707
1598
|
root,
|
|
1708
1599
|
router: svelte_config.kit.browser.router,
|
|
@@ -1957,20 +1848,22 @@ function generate_manifest({ build_data, relative_path, routes, format = 'esm' }
|
|
|
1957
1848
|
* middlewares: import('connect').Server;
|
|
1958
1849
|
* httpServer: import('http').Server;
|
|
1959
1850
|
* }} vite
|
|
1960
|
-
* @param {import('
|
|
1961
|
-
* @param {'
|
|
1851
|
+
* @param {import('vite').ResolvedConfig} vite_config
|
|
1852
|
+
* @param {import('types').ValidatedConfig} svelte_config
|
|
1962
1853
|
*/
|
|
1963
|
-
async function preview(vite,
|
|
1854
|
+
async function preview(vite, vite_config, svelte_config) {
|
|
1964
1855
|
installPolyfills();
|
|
1965
1856
|
|
|
1966
|
-
const { paths } =
|
|
1857
|
+
const { paths } = svelte_config.kit;
|
|
1967
1858
|
const base = paths.base;
|
|
1968
1859
|
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
|
|
1969
1860
|
|
|
1861
|
+
const protocol = vite_config.preview.https ? 'https' : 'http';
|
|
1862
|
+
|
|
1970
1863
|
const etag = `"${Date.now()}"`;
|
|
1971
1864
|
|
|
1972
|
-
const index_file = join(
|
|
1973
|
-
const manifest_file = join(
|
|
1865
|
+
const index_file = join(svelte_config.kit.outDir, 'output/server/index.js');
|
|
1866
|
+
const manifest_file = join(svelte_config.kit.outDir, 'output/server/manifest.js');
|
|
1974
1867
|
|
|
1975
1868
|
/** @type {import('types').ServerModule} */
|
|
1976
1869
|
const { Server, override } = await import(pathToFileURL(index_file).href);
|
|
@@ -1980,20 +1873,23 @@ async function preview(vite, config, protocol) {
|
|
|
1980
1873
|
paths: { base, assets },
|
|
1981
1874
|
prerendering: false,
|
|
1982
1875
|
protocol,
|
|
1983
|
-
read: (file) => fs__default.readFileSync(join(
|
|
1876
|
+
read: (file) => fs__default.readFileSync(join(svelte_config.kit.files.assets, file))
|
|
1984
1877
|
});
|
|
1985
1878
|
|
|
1986
1879
|
const server = new Server(manifest);
|
|
1880
|
+
server.init({
|
|
1881
|
+
env: loadEnv(vite_config.mode, process.cwd(), '')
|
|
1882
|
+
});
|
|
1987
1883
|
|
|
1988
1884
|
return () => {
|
|
1989
1885
|
// generated client assets and the contents of `static`
|
|
1990
1886
|
vite.middlewares.use(
|
|
1991
1887
|
scoped(
|
|
1992
1888
|
assets,
|
|
1993
|
-
sirv(join(
|
|
1889
|
+
sirv(join(svelte_config.kit.outDir, 'output/client'), {
|
|
1994
1890
|
setHeaders: (res, pathname) => {
|
|
1995
1891
|
// only apply to immutable directory, not e.g. version.json
|
|
1996
|
-
if (pathname.startsWith(`/${
|
|
1892
|
+
if (pathname.startsWith(`/${svelte_config.kit.appDir}/immutable`)) {
|
|
1997
1893
|
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
|
|
1998
1894
|
}
|
|
1999
1895
|
}
|
|
@@ -2015,7 +1911,7 @@ async function preview(vite, config, protocol) {
|
|
|
2015
1911
|
|
|
2016
1912
|
// prerendered dependencies
|
|
2017
1913
|
vite.middlewares.use(
|
|
2018
|
-
scoped(base, mutable(join(
|
|
1914
|
+
scoped(base, mutable(join(svelte_config.kit.outDir, 'output/prerendered/dependencies')))
|
|
2019
1915
|
);
|
|
2020
1916
|
|
|
2021
1917
|
// prerendered pages (we can't just use sirv because we need to
|
|
@@ -2039,7 +1935,7 @@ async function preview(vite, config, protocol) {
|
|
|
2039
1935
|
// only treat this as a page if it doesn't include an extension
|
|
2040
1936
|
if (pathname === '/' || /\/[^./]+\/?$/.test(pathname)) {
|
|
2041
1937
|
const file = join(
|
|
2042
|
-
|
|
1938
|
+
svelte_config.kit.outDir,
|
|
2043
1939
|
'output/prerendered/pages' +
|
|
2044
1940
|
pathname +
|
|
2045
1941
|
(pathname.endsWith('/') ? 'index.html' : '.html')
|
|
@@ -2097,7 +1993,7 @@ const mutable = (dir) =>
|
|
|
2097
1993
|
etag: true,
|
|
2098
1994
|
maxAge: 0
|
|
2099
1995
|
})
|
|
2100
|
-
: (
|
|
1996
|
+
: (_req, _res, next) => next();
|
|
2101
1997
|
|
|
2102
1998
|
/**
|
|
2103
1999
|
* @param {string} scope
|
|
@@ -2205,6 +2101,9 @@ function kit() {
|
|
|
2205
2101
|
/** @type {import('types').BuildData} */
|
|
2206
2102
|
let build_data;
|
|
2207
2103
|
|
|
2104
|
+
/** @type {Set<string>} */
|
|
2105
|
+
let illegal_imports;
|
|
2106
|
+
|
|
2208
2107
|
/** @type {string | undefined} */
|
|
2209
2108
|
let deferred_warning;
|
|
2210
2109
|
|
|
@@ -2291,8 +2190,13 @@ function kit() {
|
|
|
2291
2190
|
client_out_dir: `${svelte_config.kit.outDir}/output/client/`
|
|
2292
2191
|
};
|
|
2293
2192
|
|
|
2193
|
+
illegal_imports = new Set([
|
|
2194
|
+
`${svelte_config.kit.outDir}/runtime/env/dynamic/private.js`,
|
|
2195
|
+
`${svelte_config.kit.outDir}/runtime/env/static/private.js`
|
|
2196
|
+
]);
|
|
2197
|
+
|
|
2294
2198
|
if (is_build) {
|
|
2295
|
-
manifest_data = all(svelte_config).manifest_data;
|
|
2199
|
+
manifest_data = all(svelte_config, config_env.mode).manifest_data;
|
|
2296
2200
|
|
|
2297
2201
|
const new_config = vite_client_build_config();
|
|
2298
2202
|
|
|
@@ -2378,8 +2282,24 @@ function kit() {
|
|
|
2378
2282
|
* then use this hook to kick off builds for the server and service worker.
|
|
2379
2283
|
*/
|
|
2380
2284
|
async writeBundle(_options, bundle) {
|
|
2285
|
+
for (const file of manifest_data.components) {
|
|
2286
|
+
const id = path.resolve(file);
|
|
2287
|
+
const node = this.getModuleInfo(id);
|
|
2288
|
+
|
|
2289
|
+
if (node) {
|
|
2290
|
+
prevent_illegal_rollup_imports(
|
|
2291
|
+
this.getModuleInfo.bind(this),
|
|
2292
|
+
node,
|
|
2293
|
+
illegal_imports,
|
|
2294
|
+
svelte_config.kit.outDir
|
|
2295
|
+
);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2381
2299
|
const verbose = vite_config.logLevel === 'info';
|
|
2382
|
-
log = logger({
|
|
2300
|
+
log = logger({
|
|
2301
|
+
verbose
|
|
2302
|
+
});
|
|
2383
2303
|
|
|
2384
2304
|
fs$1.writeFileSync(
|
|
2385
2305
|
`${paths.client_out_dir}/${svelte_config.kit.appDir}/version.json`,
|
|
@@ -2509,7 +2429,7 @@ function kit() {
|
|
|
2509
2429
|
if (deferred_warning) console.error('\n' + deferred_warning);
|
|
2510
2430
|
};
|
|
2511
2431
|
|
|
2512
|
-
return await dev(vite, vite_config, svelte_config);
|
|
2432
|
+
return await dev(vite, vite_config, svelte_config, illegal_imports);
|
|
2513
2433
|
},
|
|
2514
2434
|
|
|
2515
2435
|
/**
|
|
@@ -2517,7 +2437,7 @@ function kit() {
|
|
|
2517
2437
|
* @see https://vitejs.dev/guide/api-plugin.html#configurepreviewserver
|
|
2518
2438
|
*/
|
|
2519
2439
|
configurePreviewServer(vite) {
|
|
2520
|
-
return preview(vite,
|
|
2440
|
+
return preview(vite, vite_config, svelte_config);
|
|
2521
2441
|
}
|
|
2522
2442
|
};
|
|
2523
2443
|
}
|
package/package.json
CHANGED
package/types/ambient.d.ts
CHANGED
|
@@ -9,13 +9,17 @@
|
|
|
9
9
|
*
|
|
10
10
|
* interface Platform {}
|
|
11
11
|
*
|
|
12
|
+
* interface PrivateEnv {}
|
|
13
|
+
*
|
|
14
|
+
* interface PublicEnv {}
|
|
15
|
+
*
|
|
12
16
|
* interface Session {}
|
|
13
17
|
*
|
|
14
18
|
* interface Stuff {}
|
|
15
19
|
* }
|
|
16
20
|
* ```
|
|
17
21
|
*
|
|
18
|
-
* By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, `session` and `stuff`.
|
|
22
|
+
* By populating these interfaces, you will gain type safety when using `env`, `event.locals`, `event.platform`, `session` and `stuff`.
|
|
19
23
|
*
|
|
20
24
|
* Note that since it's an ambient declaration file, you have to be careful when using `import` statements. Once you add an `import`
|
|
21
25
|
* at the top level, the declaration file is no longer considered ambient and you lose access to these typings in other files.
|
|
@@ -43,22 +47,32 @@
|
|
|
43
47
|
*/
|
|
44
48
|
declare namespace App {
|
|
45
49
|
/**
|
|
46
|
-
* The interface that defines `event.locals`, which can be accessed in [hooks](/docs/hooks) (`handle`, `handleError` and `getSession`) and [endpoints](/docs/routing#endpoints).
|
|
50
|
+
* The interface that defines `event.locals`, which can be accessed in [hooks](https://kit.svelte.dev/docs/hooks) (`handle`, `handleError` and `getSession`) and [endpoints](https://kit.svelte.dev/docs/routing#endpoints).
|
|
47
51
|
*/
|
|
48
52
|
export interface Locals {}
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
|
-
* If your adapter provides [platform-specific context](/docs/adapters#supported-environments-platform-specific-context) via `event.platform`, you can specify it here.
|
|
55
|
+
* If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#supported-environments-platform-specific-context) via `event.platform`, you can specify it here.
|
|
52
56
|
*/
|
|
53
57
|
export interface Platform {}
|
|
54
58
|
|
|
55
59
|
/**
|
|
56
|
-
* The interface that defines
|
|
60
|
+
* The interface that defines the dynamic environment variables exported from '$env/dynamic/private'.
|
|
61
|
+
*/
|
|
62
|
+
export interface PrivateEnv extends Record<string, string> {}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The interface that defines the dynamic environment variables exported from '$env/dynamic/public'.
|
|
66
|
+
*/
|
|
67
|
+
export interface PublicEnv extends Record<string, string> {}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The interface that defines `session`, both as an argument to [`load`](https://kit.svelte.dev/docs/loading) functions and the value of the [session store](https://kit.svelte.dev/docs/modules#$app-stores).
|
|
57
71
|
*/
|
|
58
72
|
export interface Session {}
|
|
59
73
|
|
|
60
74
|
/**
|
|
61
|
-
* The interface that defines `stuff`, as input or output to [`load`](/docs/loading) or as the value of the `stuff` property of the [page store](/docs/modules#$app-stores).
|
|
75
|
+
* The interface that defines `stuff`, as input or output to [`load`](https://kit.svelte.dev/docs/loading) or as the value of the `stuff` property of the [page store](https://kit.svelte.dev/docs/modules#$app-stores).
|
|
62
76
|
*/
|
|
63
77
|
export interface Stuff {}
|
|
64
78
|
}
|
|
@@ -85,6 +99,39 @@ declare module '$app/env' {
|
|
|
85
99
|
export const prerendering: boolean;
|
|
86
100
|
}
|
|
87
101
|
|
|
102
|
+
/**
|
|
103
|
+
* This module provides access to runtime environment variables, as defined by the platform you're running on. For example
|
|
104
|
+
* if you're using [`adapter-node`](https://github.com/sveltejs/kit/tree/master/packages/adapter-node) (or running
|
|
105
|
+
* [`vite preview`](https://kit.svelte.dev/docs/cli)), this is equivalent to `process.env`. This module only includes
|
|
106
|
+
* variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#kit-env-publicprefix).
|
|
107
|
+
*
|
|
108
|
+
* This module cannot be imported into client-side code.
|
|
109
|
+
*
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { env } from '$env/dynamic/private';
|
|
112
|
+
* console.log(env.DEPLOYMENT_SPECIFIC_VARIABLE);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare module '$env/dynamic/private' {
|
|
116
|
+
export let env: App.PrivateEnv;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Similar to [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), but only includes
|
|
121
|
+
* variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#kit-env-publicprefix)
|
|
122
|
+
* (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code
|
|
123
|
+
*
|
|
124
|
+
* Note that public dynamic environment variables must all be sent from the server to the client, causing larger network requests — when possible, use `$env/static/public` instead.
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { env } from '$env/dynamic/public';
|
|
128
|
+
* console.log(env.PUBLIC_DEPLOYMENT_SPECIFIC_VARIABLE);
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare module '$env/dynamic/public' {
|
|
132
|
+
export let env: App.PublicEnv;
|
|
133
|
+
}
|
|
134
|
+
|
|
88
135
|
/**
|
|
89
136
|
* ```ts
|
|
90
137
|
* import {
|
|
@@ -167,11 +214,11 @@ declare module '$app/navigation' {
|
|
|
167
214
|
*/
|
|
168
215
|
declare module '$app/paths' {
|
|
169
216
|
/**
|
|
170
|
-
* A string that matches [`config.kit.paths.base`](/docs/configuration#paths). It must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string.
|
|
217
|
+
* A string that matches [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths). It must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string.
|
|
171
218
|
*/
|
|
172
219
|
export const base: `/${string}`;
|
|
173
220
|
/**
|
|
174
|
-
* An absolute path that matches [`config.kit.paths.assets`](/docs/configuration#paths).
|
|
221
|
+
* An absolute path that matches [`config.kit.paths.assets`](https://kit.svelte.dev/docs/configuration#paths).
|
|
175
222
|
*
|
|
176
223
|
* > If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
|
|
177
224
|
*/
|
|
@@ -213,12 +260,12 @@ declare module '$app/stores' {
|
|
|
213
260
|
*/
|
|
214
261
|
export const navigating: Readable<Navigation | null>;
|
|
215
262
|
/**
|
|
216
|
-
* A writable store whose initial value is whatever was returned from [`getSession`](/docs/hooks#getsession).
|
|
263
|
+
* A writable store whose initial value is whatever was returned from [`getSession`](https://kit.svelte.dev/docs/hooks#getsession).
|
|
217
264
|
* It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself.
|
|
218
265
|
*/
|
|
219
266
|
export const session: Writable<App.Session>;
|
|
220
267
|
/**
|
|
221
|
-
* A readable store whose initial value is `false`. If [`version.pollInterval`](/docs/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update the store value to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
|
|
268
|
+
* A readable store whose initial value is `false`. If [`version.pollInterval`](https://kit.svelte.dev/docs/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update the store value to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
|
|
222
269
|
*/
|
|
223
270
|
export const updated: Readable<boolean> & { check: () => boolean };
|
|
224
271
|
}
|
|
@@ -228,7 +275,7 @@ declare module '$app/stores' {
|
|
|
228
275
|
* import { build, files, prerendered, version } from '$service-worker';
|
|
229
276
|
* ```
|
|
230
277
|
*
|
|
231
|
-
* This module is only available to [service workers](/docs/service-workers).
|
|
278
|
+
* This module is only available to [service workers](https://kit.svelte.dev/docs/service-workers).
|
|
232
279
|
*/
|
|
233
280
|
declare module '$service-worker' {
|
|
234
281
|
/**
|
|
@@ -236,7 +283,7 @@ declare module '$service-worker' {
|
|
|
236
283
|
*/
|
|
237
284
|
export const build: string[];
|
|
238
285
|
/**
|
|
239
|
-
* An array of URL strings representing the files in your static directory, or whatever directory is specified by `config.kit.files.assets`. You can customize which files are included from `static` directory using [`config.kit.serviceWorker.files`](/docs/configuration)
|
|
286
|
+
* An array of URL strings representing the files in your static directory, or whatever directory is specified by `config.kit.files.assets`. You can customize which files are included from `static` directory using [`config.kit.serviceWorker.files`](https://kit.svelte.dev/docs/configuration)
|
|
240
287
|
*/
|
|
241
288
|
export const files: string[];
|
|
242
289
|
/**
|
|
@@ -244,7 +291,7 @@ declare module '$service-worker' {
|
|
|
244
291
|
*/
|
|
245
292
|
export const prerendered: string[];
|
|
246
293
|
/**
|
|
247
|
-
* See [`config.kit.version`](/docs/configuration#version). It's useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches.
|
|
294
|
+
* See [`config.kit.version`](https://kit.svelte.dev/docs/configuration#version). It's useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches.
|
|
248
295
|
*/
|
|
249
296
|
export const version: string;
|
|
250
297
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -102,6 +102,9 @@ export interface KitConfig {
|
|
|
102
102
|
directives?: CspDirectives;
|
|
103
103
|
reportOnly?: CspDirectives;
|
|
104
104
|
};
|
|
105
|
+
env?: {
|
|
106
|
+
publicPrefix: string;
|
|
107
|
+
};
|
|
105
108
|
moduleExtensions?: string[];
|
|
106
109
|
files?: {
|
|
107
110
|
assets?: string;
|
|
@@ -268,9 +271,14 @@ export type ResponseBody = JSONValue | Uint8Array | ReadableStream | Error;
|
|
|
268
271
|
|
|
269
272
|
export class Server {
|
|
270
273
|
constructor(manifest: SSRManifest);
|
|
274
|
+
init(options: ServerInitOptions): void;
|
|
271
275
|
respond(request: Request, options: RequestOptions): Promise<Response>;
|
|
272
276
|
}
|
|
273
277
|
|
|
278
|
+
export interface ServerInitOptions {
|
|
279
|
+
env: Record<string, string>;
|
|
280
|
+
}
|
|
281
|
+
|
|
274
282
|
export interface SSRManifest {
|
|
275
283
|
appDir: string;
|
|
276
284
|
assets: Set<string>;
|
package/types/internal.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
RequestHandler,
|
|
12
12
|
ResolveOptions,
|
|
13
13
|
Server,
|
|
14
|
+
ServerInitOptions,
|
|
14
15
|
SSRManifest
|
|
15
16
|
} from './index.js';
|
|
16
17
|
import {
|
|
@@ -91,7 +92,13 @@ export interface Hooks {
|
|
|
91
92
|
handleError: HandleError;
|
|
92
93
|
}
|
|
93
94
|
|
|
95
|
+
export interface ImportNode {
|
|
96
|
+
name: string;
|
|
97
|
+
dynamic: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
94
100
|
export class InternalServer extends Server {
|
|
101
|
+
init(options: ServerInitOptions): void;
|
|
95
102
|
respond(
|
|
96
103
|
request: Request,
|
|
97
104
|
options: RequestOptions & {
|
|
@@ -249,6 +256,7 @@ export interface SSROptions {
|
|
|
249
256
|
default: boolean;
|
|
250
257
|
enabled: boolean;
|
|
251
258
|
};
|
|
259
|
+
public_env: Record<string, string>;
|
|
252
260
|
read(file: string): Buffer;
|
|
253
261
|
root: SSRComponent['default'];
|
|
254
262
|
router: boolean;
|