@sveltejs/vite-plugin-svelte 1.1.0 → 1.1.1

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/dist/index.cjs CHANGED
@@ -31,7 +31,7 @@ __export(src_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(src_exports);
33
33
 
34
- // ../../node_modules/.pnpm/tsup@6.3.0/node_modules/tsup/assets/cjs_shims.js
34
+ // ../../node_modules/.pnpm/tsup@6.4.0/node_modules/tsup/assets/cjs_shims.js
35
35
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
36
36
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
37
37
 
@@ -127,12 +127,11 @@ var log = {
127
127
  setLevel
128
128
  };
129
129
  function logCompilerWarnings(svelteRequest, warnings, options) {
130
- var _a, _b, _c;
131
130
  const { emitCss, onwarn, isBuild } = options;
132
- const sendViaWS = !isBuild && ((_a = options.experimental) == null ? void 0 : _a.sendWarningsToBrowser);
131
+ const sendViaWS = !isBuild && options.experimental?.sendWarningsToBrowser;
133
132
  let warn = isBuild ? warnBuild : warnDev;
134
133
  const handledByDefaultWarn = [];
135
- const notIgnored = warnings == null ? void 0 : warnings.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
134
+ const notIgnored = warnings?.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
136
135
  const extra = buildExtraWarnings(warnings, isBuild);
137
136
  const allWarnings = [...notIgnored, ...extra];
138
137
  if (sendViaWS) {
@@ -160,7 +159,7 @@ function logCompilerWarnings(svelteRequest, warnings, options) {
160
159
  rawWarnings: warnings
161
160
  };
162
161
  log.debug(`sending svelte:warnings message for ${svelteRequest.normalizedFilename}`);
163
- (_c = (_b = options.server) == null ? void 0 : _b.ws) == null ? void 0 : _c.send("svelte:warnings", message);
162
+ options.server?.ws?.send("svelte:warnings", message);
164
163
  }
165
164
  }
166
165
  function ignoreCompilerWarning(warning, isBuild, emitCss) {
@@ -255,11 +254,11 @@ async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, option
255
254
  return result;
256
255
  }
257
256
  function cssChanged(prev, next) {
258
- return !isCodeEqual(prev == null ? void 0 : prev.code, next == null ? void 0 : next.code);
257
+ return !isCodeEqual(prev?.code, next?.code);
259
258
  }
260
259
  function jsChanged(prev, next, filename) {
261
- const prevJs = prev == null ? void 0 : prev.code;
262
- const nextJs = next == null ? void 0 : next.code;
260
+ const prevJs = prev?.code;
261
+ const nextJs = next?.code;
263
262
  const isStrictEqual = isCodeEqual(prevJs, nextJs);
264
263
  if (isStrictEqual) {
265
264
  return false;
@@ -319,7 +318,6 @@ function toSafe(base64) {
319
318
  // src/utils/compile.ts
320
319
  var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
321
320
  var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequest, code, options) {
322
- var _a, _b, _c;
323
321
  const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
324
322
  const { emitCss = true } = options;
325
323
  const dependencies = [];
@@ -355,11 +353,11 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
355
353
  compileOptions.sourcemap = preprocessed.map;
356
354
  }
357
355
  const finalCode = preprocessed ? preprocessed.code : code;
358
- const dynamicCompileOptions = await ((_b = (_a = options.experimental) == null ? void 0 : _a.dynamicCompileOptions) == null ? void 0 : _b.call(_a, {
356
+ const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
359
357
  filename,
360
358
  code: finalCode,
361
359
  compileOptions
362
- }));
360
+ });
363
361
  if (dynamicCompileOptions && log.debug.enabled) {
364
362
  log.debug(
365
363
  `dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`
@@ -389,18 +387,17 @@ import ${JSON.stringify(cssId)};
389
387
  return {
390
388
  filename,
391
389
  normalizedFilename,
392
- lang: ((_c = code.match(scriptLangRE)) == null ? void 0 : _c[1]) || "js",
390
+ lang: code.match(scriptLangRE)?.[1] || "js",
393
391
  compiled,
394
392
  ssr,
395
393
  dependencies
396
394
  };
397
395
  };
398
396
  function buildMakeHot(options) {
399
- var _a, _b;
400
397
  const needsMakeHot = options.hot !== false && options.isServe && !options.isProduction;
401
398
  if (needsMakeHot) {
402
- const hotApi = (_a = options == null ? void 0 : options.hot) == null ? void 0 : _a.hotApi;
403
- const adapter = (_b = options == null ? void 0 : options.hot) == null ? void 0 : _b.adapter;
399
+ const hotApi = options?.hot?.hotApi;
400
+ const adapter = options?.hot?.adapter;
404
401
  return (0, import_svelte_hmr.createMakeHot)({
405
402
  walk: import_compiler.walk,
406
403
  hotApi,
@@ -493,7 +490,7 @@ function buildIdParser(options) {
493
490
  }
494
491
 
495
492
  // src/utils/options.ts
496
- var import_vite4 = require("vite");
493
+ var import_vite3 = require("vite");
497
494
 
498
495
  // src/utils/load-svelte-config.ts
499
496
  var import_module = require("module");
@@ -512,7 +509,7 @@ var dynamicImportDefault = new Function(
512
509
  'return import(path + "?t=" + timestamp).then(m => m.default)'
513
510
  );
514
511
  async function loadSvelteConfig(viteConfig, inlineOptions) {
515
- if ((inlineOptions == null ? void 0 : inlineOptions.configFile) === false) {
512
+ if (inlineOptions?.configFile === false) {
516
513
  return;
517
514
  }
518
515
  const configFile = findConfigToLoad(viteConfig, inlineOptions);
@@ -561,8 +558,8 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
561
558
  }
562
559
  }
563
560
  function findConfigToLoad(viteConfig, inlineOptions) {
564
- const root = (viteConfig == null ? void 0 : viteConfig.root) || process.cwd();
565
- if (inlineOptions == null ? void 0 : inlineOptions.configFile) {
561
+ const root = viteConfig?.root || process.cwd();
562
+ if (inlineOptions?.configFile) {
566
563
  const abolutePath = import_path.default.isAbsolute(inlineOptions.configFile) ? inlineOptions.configFile : import_path.default.resolve(root, inlineOptions.configFile);
567
564
  if (!import_fs.default.existsSync(abolutePath)) {
568
565
  throw new Error(`failed to find svelte config file ${abolutePath}.`);
@@ -708,8 +705,7 @@ function isSvelteComponentLib(pkg) {
708
705
  return !!pkg.svelte;
709
706
  }
710
707
  function isSvelteLib(pkg) {
711
- var _a, _b;
712
- return !!((_a = pkg.dependencies) == null ? void 0 : _a.svelte) || !!((_b = pkg.peerDependencies) == null ? void 0 : _b.svelte);
708
+ return !!pkg.dependencies?.svelte || !!pkg.peerDependencies?.svelte;
713
709
  }
714
710
  var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
715
711
  "@lukeed/uuid",
@@ -842,8 +838,7 @@ function esbuildSveltePlugin(options) {
842
838
  return {
843
839
  name: "vite-plugin-svelte:optimize-svelte",
844
840
  setup(build) {
845
- var _a;
846
- if ((_a = build.initialOptions.plugins) == null ? void 0 : _a.some((v) => v.name === "vite:dep-scan"))
841
+ if (build.initialOptions.plugins?.some((v) => v.name === "vite:dep-scan"))
847
842
  return;
848
843
  const svelteExtensions = (options.extensions ?? [".svelte"]).map((ext) => ext.slice(1));
849
844
  const svelteFilter = new RegExp(`\\.(` + svelteExtensions.join("|") + `)(\\?.*)?$`);
@@ -860,7 +855,6 @@ function esbuildSveltePlugin(options) {
860
855
  };
861
856
  }
862
857
  async function compileSvelte(options, { filename, code }) {
863
- var _a, _b;
864
858
  const compileOptions = {
865
859
  ...options.compilerOptions,
866
860
  css: true,
@@ -880,11 +874,11 @@ async function compileSvelte(options, { filename, code }) {
880
874
  compileOptions.sourcemap = preprocessed.map;
881
875
  }
882
876
  const finalCode = preprocessed ? preprocessed.code : code;
883
- const dynamicCompileOptions = await ((_b = (_a = options.experimental) == null ? void 0 : _a.dynamicCompileOptions) == null ? void 0 : _b.call(_a, {
877
+ const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
884
878
  filename,
885
879
  code: finalCode,
886
880
  compileOptions
887
- }));
881
+ });
888
882
  if (dynamicCompileOptions && log.debug.enabled) {
889
883
  log.debug(`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`);
890
884
  }
@@ -897,7 +891,7 @@ async function compileSvelte(options, { filename, code }) {
897
891
  }
898
892
 
899
893
  // src/utils/preprocess.ts
900
- var import_vite3 = require("vite");
894
+ var vite = __toESM(require("vite"), 1);
901
895
  var import_magic_string2 = __toESM(require("magic-string"), 1);
902
896
  var import_compiler3 = require("svelte/compiler");
903
897
 
@@ -925,7 +919,7 @@ async function buildMagicString(from, to, options) {
925
919
  const diff = diffs[i];
926
920
  const nextDiff = diffs[i + 1];
927
921
  if (diff[0] === DIFF_DELETE) {
928
- if ((nextDiff == null ? void 0 : nextDiff[0]) === DIFF_INSERT) {
922
+ if (nextDiff?.[0] === DIFF_INSERT) {
929
923
  m.overwrite(pos, pos + diff[1].length, nextDiff[1]);
930
924
  i++;
931
925
  } else {
@@ -958,7 +952,7 @@ function createViteScriptPreprocessor() {
958
952
  const lang = attributes.lang;
959
953
  if (!supportedScriptLangs.includes(lang))
960
954
  return;
961
- const transformResult = await (0, import_vite3.transformWithEsbuild)(content, filename, {
955
+ const transformResult = await vite.transformWithEsbuild(content, filename, {
962
956
  loader: lang,
963
957
  target: "esnext",
964
958
  tsconfigRaw: {
@@ -975,34 +969,39 @@ function createViteScriptPreprocessor() {
975
969
  };
976
970
  }
977
971
  function createViteStylePreprocessor(config) {
978
- const pluginName = "vite:css";
979
- const plugin = config.plugins.find((p) => p.name === pluginName);
980
- if (!plugin) {
981
- throw new Error(`failed to find plugin ${pluginName}`);
982
- }
983
- if (!plugin.transform) {
984
- throw new Error(`plugin ${pluginName} has no transform`);
985
- }
986
- const pluginTransform = plugin.transform.bind(null);
972
+ const transform = getCssTransformFn(config);
987
973
  return async ({ attributes, content, filename = "" }) => {
988
- var _a, _b;
989
974
  const lang = attributes.lang;
990
975
  if (!supportedStyleLangs.includes(lang))
991
976
  return;
992
977
  const moduleId = `${filename}.${lang}`;
993
- const transformResult = await pluginTransform(
994
- content,
995
- moduleId
996
- );
997
- if (((_b = (_a = transformResult.map) == null ? void 0 : _a.sources) == null ? void 0 : _b[0]) === moduleId) {
998
- transformResult.map.sources[0] = import_path3.default.basename(filename);
978
+ const result = await transform(content, moduleId);
979
+ if (result.map?.sources?.[0] === moduleId) {
980
+ result.map.sources[0] = import_path3.default.basename(filename);
999
981
  }
1000
982
  return {
1001
- code: transformResult.code,
1002
- map: transformResult.map ?? void 0
983
+ code: result.code,
984
+ map: result.map ?? void 0
1003
985
  };
1004
986
  };
1005
987
  }
988
+ function getCssTransformFn(config) {
989
+ if (vite.preprocessCSS) {
990
+ return async (code, filename) => {
991
+ return vite.preprocessCSS(code, filename, config);
992
+ };
993
+ } else {
994
+ const pluginName = "vite:css";
995
+ const plugin = config.plugins.find((p) => p.name === pluginName);
996
+ if (!plugin) {
997
+ throw new Error(`failed to find plugin ${pluginName}`);
998
+ }
999
+ if (!plugin.transform) {
1000
+ throw new Error(`plugin ${pluginName} has no transform`);
1001
+ }
1002
+ return plugin.transform.bind(null);
1003
+ }
1004
+ }
1006
1005
  function createVitePreprocessorGroup(config) {
1007
1006
  return {
1008
1007
  markup({ content, filename }) {
@@ -1033,14 +1032,13 @@ function createInjectScopeEverythingRulePreprocessorGroup() {
1033
1032
  };
1034
1033
  }
1035
1034
  function buildExtraPreprocessors(options, config) {
1036
- var _a, _b;
1037
1035
  const prependPreprocessors = [];
1038
1036
  const appendPreprocessors = [];
1039
- if ((_a = options.experimental) == null ? void 0 : _a.useVitePreprocess) {
1037
+ if (options.experimental?.useVitePreprocess) {
1040
1038
  log.debug("adding vite preprocessor");
1041
1039
  prependPreprocessors.push(createVitePreprocessorGroup(config));
1042
1040
  }
1043
- const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p == null ? void 0 : p.sveltePreprocess);
1041
+ const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess);
1044
1042
  if (pluginsWithPreprocessorsDeprecated.length > 0) {
1045
1043
  log.warn(
1046
1044
  `The following plugins use the deprecated 'plugin.sveltePreprocess' field. Please contact their maintainers and ask them to move it to 'plugin.api.sveltePreprocess': ${pluginsWithPreprocessorsDeprecated.map((p) => p.name).join(", ")}`
@@ -1058,13 +1056,10 @@ function buildExtraPreprocessors(options, config) {
1058
1056
  }
1059
1057
  });
1060
1058
  }
1061
- const pluginsWithPreprocessors = config.plugins.filter((p) => {
1062
- var _a2;
1063
- return (_a2 = p == null ? void 0 : p.api) == null ? void 0 : _a2.sveltePreprocess;
1064
- });
1059
+ const pluginsWithPreprocessors = config.plugins.filter((p) => p?.api?.sveltePreprocess);
1065
1060
  const ignored = [], included = [];
1066
1061
  for (const p of pluginsWithPreprocessors) {
1067
- if (options.ignorePluginPreprocessors === true || Array.isArray(options.ignorePluginPreprocessors) && ((_b = options.ignorePluginPreprocessors) == null ? void 0 : _b.includes(p.name))) {
1062
+ if (options.ignorePluginPreprocessors === true || Array.isArray(options.ignorePluginPreprocessors) && options.ignorePluginPreprocessors?.includes(p.name)) {
1068
1063
  ignored.push(p);
1069
1064
  } else {
1070
1065
  included.push(p);
@@ -1087,7 +1082,6 @@ function buildExtraPreprocessors(options, config) {
1087
1082
  return { prependPreprocessors, appendPreprocessors };
1088
1083
  }
1089
1084
  function addExtraPreprocessors(options, config) {
1090
- var _a;
1091
1085
  const { prependPreprocessors, appendPreprocessors } = buildExtraPreprocessors(options, config);
1092
1086
  if (prependPreprocessors.length > 0 || appendPreprocessors.length > 0) {
1093
1087
  if (!options.preprocess) {
@@ -1099,7 +1093,7 @@ function addExtraPreprocessors(options, config) {
1099
1093
  options.preprocess = [...prependPreprocessors, options.preprocess, ...appendPreprocessors];
1100
1094
  }
1101
1095
  }
1102
- const generateMissingSourceMaps = !!((_a = options.experimental) == null ? void 0 : _a.generateMissingPreprocessorSourcemaps);
1096
+ const generateMissingSourceMaps = !!options.experimental?.generateMissingPreprocessorSourcemaps;
1103
1097
  if (options.preprocess && generateMissingSourceMaps) {
1104
1098
  options.preprocess = Array.isArray(options.preprocess) ? options.preprocess.map((p, i) => validateSourceMapOutputWrapper(p, i)) : validateSourceMapOutputWrapper(options.preprocess, 0);
1105
1099
  }
@@ -1108,7 +1102,6 @@ function validateSourceMapOutputWrapper(group, i) {
1108
1102
  const wrapper = {};
1109
1103
  for (const [processorType, processorFn] of Object.entries(group)) {
1110
1104
  wrapper[processorType] = async (options) => {
1111
- var _a;
1112
1105
  const result = await processorFn(options);
1113
1106
  if (result && result.code !== options.content) {
1114
1107
  let invalidMap = false;
@@ -1122,7 +1115,7 @@ function validateSourceMapOutputWrapper(group, i) {
1122
1115
  processor: processorFn.toString()
1123
1116
  }
1124
1117
  );
1125
- } else if (((_a = result.map) == null ? void 0 : _a.mappings) === "") {
1118
+ } else if (result.map?.mappings === "") {
1126
1119
  invalidMap = true;
1127
1120
  log.warn.enabled && log.warn.once(
1128
1121
  `preprocessor at index ${i} returned an invalid empty sourcemap for ${processorType} transform`,
@@ -1257,7 +1250,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
1257
1250
  inlineOptions,
1258
1251
  extraOptions
1259
1252
  );
1260
- if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
1253
+ if (svelteConfig?.configFile) {
1261
1254
  merged.configFile = svelteConfig.configFile;
1262
1255
  }
1263
1256
  return merged;
@@ -1272,11 +1265,10 @@ function mergeConfigs(...configs) {
1272
1265
  return result;
1273
1266
  }
1274
1267
  function resolveOptions(preResolveOptions2, viteConfig) {
1275
- var _a;
1276
1268
  const defaultOptions = {
1277
1269
  hot: viteConfig.isProduction ? false : {
1278
1270
  injectCss: !preResolveOptions2.emitCss,
1279
- partialAccept: !!((_a = viteConfig.experimental) == null ? void 0 : _a.hmrPartialAccept)
1271
+ partialAccept: !!viteConfig.experimental?.hmrPartialAccept
1280
1272
  },
1281
1273
  compilerOptions: {
1282
1274
  css: !preResolveOptions2.emitCss,
@@ -1366,9 +1358,8 @@ function removeIgnoredOptions(options) {
1366
1358
  }
1367
1359
  }
1368
1360
  function addSvelteKitOptions(options) {
1369
- var _a;
1370
- if ((options == null ? void 0 : options.kit) != null) {
1371
- const kit_browser_hydrate = (_a = options.kit.browser) == null ? void 0 : _a.hydrate;
1361
+ if (options?.kit != null) {
1362
+ const kit_browser_hydrate = options.kit.browser?.hydrate;
1372
1363
  const hydratable = kit_browser_hydrate !== false;
1373
1364
  if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
1374
1365
  log.warn(
@@ -1380,19 +1371,17 @@ function addSvelteKitOptions(options) {
1380
1371
  }
1381
1372
  }
1382
1373
  function handleDeprecatedOptions(options) {
1383
- var _a, _b;
1384
- if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
1385
- options.prebundleSvelteLibraries = (_b = options.experimental) == null ? void 0 : _b.prebundleSvelteLibraries;
1374
+ if (options.experimental?.prebundleSvelteLibraries) {
1375
+ options.prebundleSvelteLibraries = options.experimental?.prebundleSvelteLibraries;
1386
1376
  log.warn(
1387
1377
  "experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries"
1388
1378
  );
1389
1379
  }
1390
1380
  }
1391
1381
  function resolveViteRoot(viteConfig) {
1392
- return (0, import_vite4.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
1382
+ return (0, import_vite3.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
1393
1383
  }
1394
1384
  function buildExtraViteConfig(options, config) {
1395
- var _a;
1396
1385
  const svelteDeps = findRootSvelteDependencies(options.root);
1397
1386
  const extraViteConfig = {
1398
1387
  resolve: {
@@ -1416,7 +1405,7 @@ function buildExtraViteConfig(options, config) {
1416
1405
  };
1417
1406
  }
1418
1407
  extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
1419
- if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && ((_a = config.experimental) == null ? void 0 : _a.hmrPartialAccept) !== false) {
1408
+ if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && config.experimental?.hmrPartialAccept !== false) {
1420
1409
  log.debug('enabling "experimental.hmrPartialAccept" in vite config');
1421
1410
  extraViteConfig.experimental = { hmrPartialAccept: true };
1422
1411
  }
@@ -1425,13 +1414,9 @@ function buildExtraViteConfig(options, config) {
1425
1414
  function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1426
1415
  const include = [];
1427
1416
  const exclude = ["svelte-hmr"];
1428
- const isIncluded = (dep) => {
1429
- var _a;
1430
- return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
1431
- };
1417
+ const isIncluded = (dep) => include.includes(dep) || optimizeDeps?.include?.includes(dep);
1432
1418
  const isExcluded = (dep) => {
1433
- var _a;
1434
- return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
1419
+ return exclude.includes(dep) || optimizeDeps?.exclude?.some((id) => dep === id || id.startsWith(`${dep}/`));
1435
1420
  };
1436
1421
  if (!isExcluded("svelte")) {
1437
1422
  const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
@@ -1469,17 +1454,13 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1469
1454
  return { include, exclude };
1470
1455
  }
1471
1456
  function buildSSROptionsForSvelte(svelteDeps, options, config) {
1472
- var _a, _b;
1473
1457
  const noExternal = [];
1474
- if (!((_b = (_a = config.ssr) == null ? void 0 : _a.external) == null ? void 0 : _b.includes("svelte"))) {
1458
+ if (!config.ssr?.external?.includes("svelte")) {
1475
1459
  noExternal.push("svelte", /^svelte\//);
1476
1460
  }
1477
1461
  noExternal.push(
1478
1462
  ...Array.from(new Set(svelteDeps.map((s) => s.name))).filter(
1479
- (x) => {
1480
- var _a2, _b2;
1481
- return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x));
1482
- }
1463
+ (x) => !config.ssr?.external?.includes(x)
1483
1464
  )
1484
1465
  );
1485
1466
  const ssr = {
@@ -1490,17 +1471,13 @@ function buildSSROptionsForSvelte(svelteDeps, options, config) {
1490
1471
  ssr.external = Array.from(
1491
1472
  new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
1492
1473
  ).filter(
1493
- (dep) => {
1494
- var _a2, _b2;
1495
- return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(dep));
1496
- }
1474
+ (dep) => !ssr.noExternal.includes(dep) && !config.ssr?.external?.includes(dep)
1497
1475
  );
1498
1476
  }
1499
1477
  return ssr;
1500
1478
  }
1501
1479
  function patchResolvedViteConfig(viteConfig, options) {
1502
- var _a, _b;
1503
- const facadeEsbuildSveltePlugin = (_b = (_a = viteConfig.optimizeDeps.esbuildOptions) == null ? void 0 : _a.plugins) == null ? void 0 : _b.find(
1480
+ const facadeEsbuildSveltePlugin = viteConfig.optimizeDeps.esbuildOptions?.plugins?.find(
1504
1481
  (plugin) => plugin.name === facadeEsbuildSveltePluginName
1505
1482
  );
1506
1483
  if (facadeEsbuildSveltePlugin) {
@@ -1766,7 +1743,7 @@ function generateSvelteMetadata(options) {
1766
1743
  }
1767
1744
 
1768
1745
  // src/ui/inspector/plugin.ts
1769
- var import_vite5 = require("vite");
1746
+ var import_vite4 = require("vite");
1770
1747
  var import_path8 = __toESM(require("path"), 1);
1771
1748
  var import_url2 = require("url");
1772
1749
  var import_fs6 = __toESM(require("fs"), 1);
@@ -1794,7 +1771,7 @@ var defaultInspectorOptions = {
1794
1771
  customStyles: true
1795
1772
  };
1796
1773
  function getInspectorPath() {
1797
- const pluginPath = (0, import_vite5.normalizePath)(import_path8.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
1774
+ const pluginPath = (0, import_vite4.normalizePath)(import_path8.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
1798
1775
  return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
1799
1776
  }
1800
1777
  function svelteInspector() {
@@ -1808,9 +1785,8 @@ function svelteInspector() {
1808
1785
  apply: "serve",
1809
1786
  enforce: "pre",
1810
1787
  configResolved(config) {
1811
- var _a, _b, _c;
1812
1788
  const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
1813
- if ((_c = (_b = (_a = vps == null ? void 0 : vps.api) == null ? void 0 : _a.options) == null ? void 0 : _b.experimental) == null ? void 0 : _c.inspector) {
1789
+ if (vps?.api?.options?.experimental?.inspector) {
1814
1790
  inspectorOptions = {
1815
1791
  ...defaultInspectorOptions,
1816
1792
  ...vps.api.options.experimental.inspector
@@ -1828,7 +1804,7 @@ function svelteInspector() {
1828
1804
  }
1829
1805
  },
1830
1806
  async resolveId(importee, importer, options) {
1831
- if ((options == null ? void 0 : options.ssr) || disabled) {
1807
+ if (options?.ssr || disabled) {
1832
1808
  return;
1833
1809
  }
1834
1810
  if (importee.startsWith("virtual:svelte-inspector-options")) {
@@ -1840,7 +1816,7 @@ function svelteInspector() {
1840
1816
  }
1841
1817
  },
1842
1818
  async load(id, options) {
1843
- if ((options == null ? void 0 : options.ssr) || disabled) {
1819
+ if (options?.ssr || disabled) {
1844
1820
  return;
1845
1821
  }
1846
1822
  if (id === "virtual:svelte-inspector-options") {
@@ -1855,7 +1831,7 @@ function svelteInspector() {
1855
1831
  }
1856
1832
  },
1857
1833
  transform(code, id, options) {
1858
- if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
1834
+ if (options?.ssr || disabled || !appendTo) {
1859
1835
  return;
1860
1836
  }
1861
1837
  if (id.endsWith(appendTo)) {
@@ -1935,7 +1911,7 @@ function svelte(inlineOptions) {
1935
1911
  setupWatchers(options, cache, requestParser);
1936
1912
  },
1937
1913
  load(id, opts) {
1938
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1914
+ const ssr = !!opts?.ssr;
1939
1915
  const svelteRequest = requestParser(id, !!ssr);
1940
1916
  if (svelteRequest) {
1941
1917
  const { filename, query } = svelteRequest;
@@ -1953,9 +1929,9 @@ function svelte(inlineOptions) {
1953
1929
  }
1954
1930
  },
1955
1931
  async resolveId(importee, importer, opts) {
1956
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1932
+ const ssr = !!opts?.ssr;
1957
1933
  const svelteRequest = requestParser(importee, ssr);
1958
- if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
1934
+ if (svelteRequest?.query.svelte) {
1959
1935
  if (svelteRequest.query.type === "style") {
1960
1936
  log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
1961
1937
  return svelteRequest.cssId;
@@ -1997,8 +1973,7 @@ function svelte(inlineOptions) {
1997
1973
  }
1998
1974
  },
1999
1975
  async transform(code, id, opts) {
2000
- var _a;
2001
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1976
+ const ssr = !!opts?.ssr;
2002
1977
  const svelteRequest = requestParser(id, ssr);
2003
1978
  if (!svelteRequest || svelteRequest.query.svelte) {
2004
1979
  return;
@@ -2012,7 +1987,7 @@ function svelte(inlineOptions) {
2012
1987
  }
2013
1988
  logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
2014
1989
  cache.update(compileData);
2015
- if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
1990
+ if (compileData.dependencies?.length && options.server) {
2016
1991
  compileData.dependencies.forEach((d) => {
2017
1992
  ensureWatchedFile(options.server.watcher, d, options.root);
2018
1993
  });