@sveltejs/kit 1.0.0-next.397 → 1.0.0-next.398
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 +5 -3
- package/dist/chunks/sync.js +64 -30
- package/dist/cli.js +1 -1
- package/dist/vite.js +9 -4
- package/package.json +1 -1
package/assets/client/start.js
CHANGED
|
@@ -1595,10 +1595,12 @@ function create_client({ target, session, base, trailing_slash }) {
|
|
|
1595
1595
|
const is_svg_a_element = a instanceof SVGAElement;
|
|
1596
1596
|
const url = get_href(a);
|
|
1597
1597
|
|
|
1598
|
-
// Ignore
|
|
1598
|
+
// Ignore non-HTTP URL protocols (e.g. `mailto:`, `tel:`, `myapp:`, etc.)
|
|
1599
1599
|
// MEMO: Without this condition, firefox will open mailer twice.
|
|
1600
|
-
// See:
|
|
1601
|
-
|
|
1600
|
+
// See:
|
|
1601
|
+
// - https://github.com/sveltejs/kit/issues/4045
|
|
1602
|
+
// - https://github.com/sveltejs/kit/issues/5725
|
|
1603
|
+
if (!is_svg_a_element && !(url.protocol === 'https:' || url.protocol === 'http:')) return;
|
|
1602
1604
|
|
|
1603
1605
|
// Ignore if tag has
|
|
1604
1606
|
// 1. 'download' attribute
|
package/dist/chunks/sync.js
CHANGED
|
@@ -5,7 +5,7 @@ import { p as posixify, c as copy, r as rimraf } from './filesystem.js';
|
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
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
7
|
import { $ } from './index.js';
|
|
8
|
-
import { loadEnv, loadConfigFromFile } from 'vite';
|
|
8
|
+
import { loadEnv, normalizePath, loadConfigFromFile } from 'vite';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @param typeMap [Object] Map of MIME type -> Array[extensions]
|
|
@@ -1104,7 +1104,7 @@ function get_env(mode, prefix) {
|
|
|
1104
1104
|
/**
|
|
1105
1105
|
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
1106
1106
|
* @param {import('rollup').ModuleInfo} node
|
|
1107
|
-
* @param {Set<string>} illegal_imports
|
|
1107
|
+
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
1108
1108
|
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
1109
1109
|
*/
|
|
1110
1110
|
function prevent_illegal_rollup_imports(node_getter, node, illegal_imports, out_dir) {
|
|
@@ -1116,9 +1116,9 @@ function prevent_illegal_rollup_imports(node_getter, node, illegal_imports, out_
|
|
|
1116
1116
|
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
1117
1117
|
* @param {import('rollup').ModuleInfo} node
|
|
1118
1118
|
* @param {boolean} dynamic
|
|
1119
|
-
* @param {Set<string>} illegal_imports
|
|
1119
|
+
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
1120
1120
|
* @param {Set<string>} seen
|
|
1121
|
-
* @returns {Array<import('types').ImportNode> |
|
|
1121
|
+
* @returns {Array<import('types').ImportNode> | null}
|
|
1122
1122
|
*/
|
|
1123
1123
|
const find_illegal_rollup_imports = (
|
|
1124
1124
|
node_getter,
|
|
@@ -1127,92 +1127,126 @@ const find_illegal_rollup_imports = (
|
|
|
1127
1127
|
illegal_imports,
|
|
1128
1128
|
seen = new Set()
|
|
1129
1129
|
) => {
|
|
1130
|
-
|
|
1131
|
-
seen.
|
|
1130
|
+
const name = normalizePath(node.id);
|
|
1131
|
+
if (seen.has(name)) return null;
|
|
1132
|
+
seen.add(name);
|
|
1132
1133
|
|
|
1133
|
-
if (illegal_imports.has(
|
|
1134
|
-
return [{ name
|
|
1134
|
+
if (illegal_imports.has(name)) {
|
|
1135
|
+
return [{ name, dynamic }];
|
|
1135
1136
|
}
|
|
1136
1137
|
|
|
1137
1138
|
for (const id of node.importedIds) {
|
|
1138
1139
|
const child = node_getter(id);
|
|
1139
1140
|
const chain =
|
|
1140
1141
|
child && find_illegal_rollup_imports(node_getter, child, false, illegal_imports, seen);
|
|
1141
|
-
if (chain) return [{ name
|
|
1142
|
+
if (chain) return [{ name, dynamic }, ...chain];
|
|
1142
1143
|
}
|
|
1143
1144
|
|
|
1144
1145
|
for (const id of node.dynamicallyImportedIds) {
|
|
1145
1146
|
const child = node_getter(id);
|
|
1146
1147
|
const chain =
|
|
1147
1148
|
child && find_illegal_rollup_imports(node_getter, child, true, illegal_imports, seen);
|
|
1148
|
-
if (chain) return [{ name
|
|
1149
|
+
if (chain) return [{ name, dynamic }, ...chain];
|
|
1149
1150
|
}
|
|
1151
|
+
|
|
1152
|
+
seen.delete(name);
|
|
1153
|
+
return null;
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* Vite does some weird things with import trees in dev
|
|
1158
|
+
* for example, a Tailwind app.css will appear to import
|
|
1159
|
+
* every file in the project. This isn't a problem for
|
|
1160
|
+
* Rollup during build.
|
|
1161
|
+
* @param {Iterable<string>} config_module_types
|
|
1162
|
+
*/
|
|
1163
|
+
const get_module_types = (config_module_types) => {
|
|
1164
|
+
return new Set([
|
|
1165
|
+
'.ts',
|
|
1166
|
+
'.js',
|
|
1167
|
+
'.svelte',
|
|
1168
|
+
'.mts',
|
|
1169
|
+
'.mjs',
|
|
1170
|
+
'.cts',
|
|
1171
|
+
'.cjs',
|
|
1172
|
+
'.svelte.md',
|
|
1173
|
+
'.svx',
|
|
1174
|
+
'.md',
|
|
1175
|
+
...config_module_types
|
|
1176
|
+
]);
|
|
1150
1177
|
};
|
|
1151
1178
|
|
|
1152
1179
|
/**
|
|
1153
1180
|
* Throw an error if a private module is imported from a client-side node.
|
|
1154
1181
|
* @param {import('vite').ModuleNode} node
|
|
1155
|
-
* @param {Set<string>} illegal_imports
|
|
1182
|
+
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
1183
|
+
* @param {Iterable<string>} module_types File extensions to analyze in addition to the defaults: `.ts`, `.js`, etc.
|
|
1156
1184
|
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
1157
1185
|
*/
|
|
1158
|
-
function prevent_illegal_vite_imports(node, illegal_imports, out_dir) {
|
|
1159
|
-
const chain = find_illegal_vite_imports(node, illegal_imports);
|
|
1186
|
+
function prevent_illegal_vite_imports(node, illegal_imports, module_types, out_dir) {
|
|
1187
|
+
const chain = find_illegal_vite_imports(node, illegal_imports, get_module_types(module_types));
|
|
1160
1188
|
if (chain) throw new Error(format_illegal_import_chain(chain, out_dir));
|
|
1161
1189
|
}
|
|
1162
1190
|
|
|
1163
1191
|
/**
|
|
1164
1192
|
* @param {import('vite').ModuleNode} node
|
|
1165
|
-
* @param {Set<string>} illegal_imports
|
|
1193
|
+
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
1194
|
+
* @param {Set<string>} module_types File extensions to analyze: `.ts`, `.js`, etc.
|
|
1166
1195
|
* @param {Set<string>} seen
|
|
1167
1196
|
* @returns {Array<import('types').ImportNode> | null}
|
|
1168
1197
|
*/
|
|
1169
|
-
function find_illegal_vite_imports(node, illegal_imports, seen = new Set()) {
|
|
1198
|
+
function find_illegal_vite_imports(node, illegal_imports, module_types, seen = new Set()) {
|
|
1170
1199
|
if (!node.id) return null; // TODO when does this happen?
|
|
1200
|
+
const name = normalizePath(node.id);
|
|
1171
1201
|
|
|
1172
|
-
if (seen.has(
|
|
1173
|
-
seen.add(
|
|
1202
|
+
if (seen.has(name) || !module_types.has(path__default.extname(name))) return null;
|
|
1203
|
+
seen.add(name);
|
|
1174
1204
|
|
|
1175
|
-
if (
|
|
1176
|
-
return [{ name
|
|
1205
|
+
if (name && illegal_imports.has(name)) {
|
|
1206
|
+
return [{ name, dynamic: false }];
|
|
1177
1207
|
}
|
|
1178
1208
|
|
|
1179
1209
|
for (const child of node.importedModules) {
|
|
1180
|
-
const chain = child && find_illegal_vite_imports(child, illegal_imports, seen);
|
|
1181
|
-
if (chain) return [{ name
|
|
1210
|
+
const chain = child && find_illegal_vite_imports(child, illegal_imports, module_types, seen);
|
|
1211
|
+
if (chain) return [{ name, dynamic: false }, ...chain];
|
|
1182
1212
|
}
|
|
1183
1213
|
|
|
1214
|
+
seen.delete(name);
|
|
1184
1215
|
return null;
|
|
1185
1216
|
}
|
|
1186
1217
|
|
|
1187
1218
|
const autogen_comment = '// this file is generated — do not edit it\n';
|
|
1219
|
+
const types_reference = '/// <reference types="@sveltejs/kit" />\n\n';
|
|
1188
1220
|
|
|
1189
1221
|
/**
|
|
1190
|
-
* Writes
|
|
1222
|
+
* Writes ambient declarations including types reference to @sveltejs/kit,
|
|
1223
|
+
* and the existing environment variables in process.env to
|
|
1191
1224
|
* $env/static/private and $env/static/public
|
|
1192
1225
|
* @param {import('types').ValidatedKitConfig} config
|
|
1193
1226
|
* @param {string} mode The Vite mode
|
|
1194
1227
|
*/
|
|
1195
|
-
function
|
|
1228
|
+
function write_ambient(config, mode) {
|
|
1196
1229
|
const env = get_env(mode, config.env.publicPrefix);
|
|
1197
1230
|
|
|
1198
1231
|
// TODO when testing src, `$app` points at `src/runtime/app`... will
|
|
1199
1232
|
// probably need to fiddle with aliases
|
|
1200
1233
|
write_if_changed(
|
|
1201
1234
|
path__default.join(config.outDir, 'runtime/env/static/public.js'),
|
|
1202
|
-
|
|
1235
|
+
create_env_module('$env/static/public', env.public)
|
|
1203
1236
|
);
|
|
1204
1237
|
|
|
1205
1238
|
write_if_changed(
|
|
1206
1239
|
path__default.join(config.outDir, 'runtime/env/static/private.js'),
|
|
1207
|
-
|
|
1240
|
+
create_env_module('$env/static/private', env.private)
|
|
1208
1241
|
);
|
|
1209
1242
|
|
|
1210
1243
|
write_if_changed(
|
|
1211
1244
|
path__default.join(config.outDir, 'ambient.d.ts'),
|
|
1212
1245
|
autogen_comment +
|
|
1213
|
-
|
|
1246
|
+
types_reference +
|
|
1247
|
+
create_env_types('$env/static/public', env.public) +
|
|
1214
1248
|
'\n\n' +
|
|
1215
|
-
|
|
1249
|
+
create_env_types('$env/static/private', env.private)
|
|
1216
1250
|
);
|
|
1217
1251
|
}
|
|
1218
1252
|
|
|
@@ -1221,7 +1255,7 @@ function write_env(config, mode) {
|
|
|
1221
1255
|
* @param {Record<string, string>} env
|
|
1222
1256
|
* @returns {string}
|
|
1223
1257
|
*/
|
|
1224
|
-
function
|
|
1258
|
+
function create_env_module(id, env) {
|
|
1225
1259
|
/** @type {string[]} */
|
|
1226
1260
|
const declarations = [];
|
|
1227
1261
|
|
|
@@ -1255,7 +1289,7 @@ function create_module(id, env) {
|
|
|
1255
1289
|
* @param {Record<string, string>} env
|
|
1256
1290
|
* @returns {string}
|
|
1257
1291
|
*/
|
|
1258
|
-
function
|
|
1292
|
+
function create_env_types(id, env) {
|
|
1259
1293
|
const declarations = Object.keys(env)
|
|
1260
1294
|
.filter((k) => valid_identifier.test(k))
|
|
1261
1295
|
.map((k) => `\texport const ${k}: string;`)
|
|
@@ -1273,7 +1307,7 @@ function init(config, mode) {
|
|
|
1273
1307
|
copy_assets(path__default.join(config.kit.outDir, 'runtime'));
|
|
1274
1308
|
|
|
1275
1309
|
write_tsconfig(config.kit);
|
|
1276
|
-
|
|
1310
|
+
write_ambient(config.kit, mode);
|
|
1277
1311
|
}
|
|
1278
1312
|
|
|
1279
1313
|
/**
|
package/dist/cli.js
CHANGED
package/dist/vite.js
CHANGED
|
@@ -1297,7 +1297,12 @@ async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
|
1297
1297
|
const node = await vite.moduleGraph.getModuleByUrl(url);
|
|
1298
1298
|
if (!node) throw new Error(`Could not find node for ${url}`);
|
|
1299
1299
|
|
|
1300
|
-
prevent_illegal_vite_imports(
|
|
1300
|
+
prevent_illegal_vite_imports(
|
|
1301
|
+
node,
|
|
1302
|
+
illegal_imports,
|
|
1303
|
+
[...svelte_config.extensions, ...svelte_config.kit.moduleExtensions],
|
|
1304
|
+
svelte_config.kit.outDir
|
|
1305
|
+
);
|
|
1301
1306
|
|
|
1302
1307
|
return {
|
|
1303
1308
|
module,
|
|
@@ -2191,8 +2196,8 @@ function kit() {
|
|
|
2191
2196
|
};
|
|
2192
2197
|
|
|
2193
2198
|
illegal_imports = new Set([
|
|
2194
|
-
`${svelte_config.kit.outDir}/runtime/env/dynamic/private.js
|
|
2195
|
-
`${svelte_config.kit.outDir}/runtime/env/static/private.js`
|
|
2199
|
+
vite.normalizePath(`${svelte_config.kit.outDir}/runtime/env/dynamic/private.js`),
|
|
2200
|
+
vite.normalizePath(`${svelte_config.kit.outDir}/runtime/env/static/private.js`)
|
|
2196
2201
|
]);
|
|
2197
2202
|
|
|
2198
2203
|
if (is_build) {
|
|
@@ -2283,7 +2288,7 @@ function kit() {
|
|
|
2283
2288
|
*/
|
|
2284
2289
|
async writeBundle(_options, bundle) {
|
|
2285
2290
|
for (const file of manifest_data.components) {
|
|
2286
|
-
const id = path.resolve(file);
|
|
2291
|
+
const id = vite.normalizePath(path.resolve(file));
|
|
2287
2292
|
const node = this.getModuleInfo(id);
|
|
2288
2293
|
|
|
2289
2294
|
if (node) {
|