@sveltejs/kit 1.0.0-next.396 → 1.0.0-next.399

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.
@@ -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 if url does not have origin (e.g. `mailto:`, `tel:`.)
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: https://github.com/sveltejs/kit/issues/4045
1601
- if (!is_svg_a_element && url.origin === 'null') return;
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
@@ -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> | undefined}
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
- if (seen.has(node.id)) return;
1131
- seen.add(node.id);
1130
+ const name = normalizePath(node.id);
1131
+ if (seen.has(name)) return null;
1132
+ seen.add(name);
1132
1133
 
1133
- if (illegal_imports.has(node.id)) {
1134
- return [{ name: node.id, dynamic }];
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: node.id, dynamic }, ...chain];
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: node.id, dynamic }, ...chain];
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(node.id)) return null;
1173
- seen.add(node.id);
1202
+ if (seen.has(name) || !module_types.has(path__default.extname(name))) return null;
1203
+ seen.add(name);
1174
1204
 
1175
- if (node.id && illegal_imports.has(node.id)) {
1176
- return [{ name: node.id, dynamic: false }];
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: node.id, dynamic: false }, ...chain];
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 the existing environment variables in process.env to
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 write_env(config, mode) {
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
- create_module('$env/static/public', env.public)
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
- create_module('$env/static/private', env.private)
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
- create_types('$env/static/public', env.public) +
1246
+ types_reference +
1247
+ create_env_types('$env/static/public', env.public) +
1214
1248
  '\n\n' +
1215
- create_types('$env/static/private', env.private)
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 create_module(id, env) {
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 create_types(id, env) {
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
- write_env(config.kit, mode);
1310
+ write_ambient(config.kit, mode);
1277
1311
  }
1278
1312
 
1279
1313
  /**
@@ -149,7 +149,7 @@ function write_tsconfig(config, cwd = process.cwd()) {
149
149
 
150
150
  // This is required for svelte-kit package to work as expected
151
151
  // Can be overwritten
152
- lib: ['esnext', 'DOM'],
152
+ lib: ['esnext', 'DOM', 'DOM.Iterable'],
153
153
  moduleResolution: 'node',
154
154
  module: 'esnext',
155
155
  target: 'esnext'
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import fs__default from 'fs';
2
+ import path__default from 'path';
2
3
  import { l as load_config, $ } from './chunks/index.js';
3
4
  import sade from 'sade';
4
5
  import { c as coalesce_to_error } from './chunks/error.js';
5
- import 'path';
6
6
  import 'url';
7
7
 
8
8
  /** @param {unknown} e */
@@ -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.396');
22
+ const prog = sade('svelte-kit').version('1.0.0-next.399');
23
23
 
24
24
  prog
25
25
  .command('package')
@@ -41,13 +41,30 @@ prog
41
41
  .describe('Synchronise generated files')
42
42
  .option('--mode', 'Specify a mode for loading environment variables', 'development')
43
43
  .action(async ({ mode }) => {
44
- if (!fs__default.existsSync('svelte.config.js')) {
45
- console.warn('Missing svelte.config.js — skipping');
44
+ const event = process.env.npm_lifecycle_event;
45
+
46
+ // TODO remove for 1.0
47
+ if (event === 'prepare') {
48
+ const pkg = JSON.parse(fs__default.readFileSync('package.json', 'utf8'));
49
+ const message =
50
+ pkg.scripts.prepare === 'svelte-kit sync'
51
+ ? `\`svelte-kit sync\` now runs on "postinstall" — please remove the "prepare" script from your package.json\n`
52
+ : `\`svelte-kit sync\` now runs on "postinstall" — please remove it from your "prepare" script\n`;
53
+
54
+ console.error($.bold().red(message));
55
+ return;
56
+ }
57
+
58
+ const cwd = event === 'postinstall' ? process.env.INIT_CWD ?? '' : process.cwd();
59
+
60
+ const svelte_config_file = path__default.join(cwd, 'svelte.config.js');
61
+ if (!fs__default.existsSync(svelte_config_file)) {
62
+ console.warn(`Missing ${svelte_config_file} — skipping`);
46
63
  return;
47
64
  }
48
65
 
49
66
  try {
50
- const config = await load_config();
67
+ const config = await load_config({ cwd });
51
68
  const sync = await import('./chunks/sync.js').then(function (n) { return n.f; });
52
69
  sync.all(config, mode);
53
70
  } catch (error) {
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(node, illegal_imports, svelte_config.kit.outDir);
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,
@@ -1478,11 +1483,6 @@ async function dev(vite, vite_config, svelte_config, illegal_imports) {
1478
1483
  );
1479
1484
  }
1480
1485
 
1481
- /** @type {Partial<import('types').Hooks>} */
1482
- const user_hooks = resolve_entry(svelte_config.kit.files.hooks)
1483
- ? await vite.ssrLoadModule(`/${svelte_config.kit.files.hooks}`)
1484
- : {};
1485
-
1486
1486
  const runtime_base = true
1487
1487
  ? `/${posixify(path__default.relative(cwd$1, `${svelte_config.kit.outDir}/runtime`))}`
1488
1488
  : `/@fs${runtime}`;
@@ -1494,6 +1494,11 @@ async function dev(vite, vite_config, svelte_config, illegal_imports) {
1494
1494
  set_private_env(env.private);
1495
1495
  set_public_env(env.public);
1496
1496
 
1497
+ /** @type {Partial<import('types').Hooks>} */
1498
+ const user_hooks = resolve_entry(svelte_config.kit.files.hooks)
1499
+ ? await vite.ssrLoadModule(`/${svelte_config.kit.files.hooks}`)
1500
+ : {};
1501
+
1497
1502
  const handle = user_hooks.handle || (({ event, resolve }) => resolve(event));
1498
1503
 
1499
1504
  /** @type {import('types').Hooks} */
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.396",
3
+ "version": "1.0.0-next.399",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -20,7 +20,7 @@
20
20
  "@types/connect": "^3.4.35",
21
21
  "@types/cookie": "^0.5.1",
22
22
  "@types/marked": "^4.0.3",
23
- "@types/mime": "^2.0.3",
23
+ "@types/mime": "^3.0.0",
24
24
  "@types/node": "^16.11.36",
25
25
  "@types/sade": "^1.7.4",
26
26
  "@types/set-cookie-parser": "^2.4.2",
@@ -93,6 +93,7 @@
93
93
  "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\" -i packaging",
94
94
  "test:typings": "tsc --project test/typings",
95
95
  "test:packaging": "uvu src/packaging \"(spec\\.js|test[\\\\/]index\\.js)\"",
96
- "types": "node scripts/extract-types.js"
96
+ "types": "node scripts/extract-types.js",
97
+ "postinstall": "node svelte-kit.js sync"
97
98
  }
98
99
  }
package/svelte-kit.js CHANGED
@@ -1,2 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import './dist/cli.js';
2
+ import fs from 'fs';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ // in our own CI, and when deploying directly from this monorepo,
6
+ // the `dist` directory will not exist yet
7
+ if (fs.existsSync(fileURLToPath(new URL('./dist', import.meta.url)))) {
8
+ import('./dist/cli.js');
9
+ } else {
10
+ console.error('Run "pnpm build" and try running this command again');
11
+ }