@sveltejs/vite-plugin-svelte 1.0.9 → 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.2.3/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,
@@ -415,8 +412,8 @@ function createCompileSvelte(options) {
415
412
  }
416
413
 
417
414
  // src/utils/id.ts
418
- var import_pluginutils = require("@rollup/pluginutils");
419
415
  var import_vite = require("vite");
416
+ var import_vite2 = require("vite");
420
417
  var fs = __toESM(require("fs"), 1);
421
418
  var VITE_FS_PREFIX = "/@fs/";
422
419
  var IS_WINDOWS = process.platform === "win32";
@@ -465,7 +462,7 @@ function parseRequestQuery(rawQuery) {
465
462
  return query;
466
463
  }
467
464
  function normalize(filename, normalizedRoot) {
468
- return stripRoot((0, import_vite.normalizePath)(filename), normalizedRoot);
465
+ return stripRoot((0, import_vite2.normalizePath)(filename), normalizedRoot);
469
466
  }
470
467
  function existsInRoot(filename, root) {
471
468
  if (filename.startsWith(VITE_FS_PREFIX)) {
@@ -477,12 +474,12 @@ function stripRoot(normalizedFilename, normalizedRoot) {
477
474
  return normalizedFilename.startsWith(normalizedRoot + "/") ? normalizedFilename.slice(normalizedRoot.length) : normalizedFilename;
478
475
  }
479
476
  function buildFilter(include, exclude, extensions) {
480
- const rollupFilter = (0, import_pluginutils.createFilter)(include, exclude);
477
+ const rollupFilter = (0, import_vite.createFilter)(include, exclude);
481
478
  return (filename) => rollupFilter(filename) && extensions.some((ext) => filename.endsWith(ext));
482
479
  }
483
480
  function buildIdParser(options) {
484
481
  const { include, exclude, extensions, root } = options;
485
- const normalizedRoot = (0, import_vite.normalizePath)(root);
482
+ const normalizedRoot = (0, import_vite2.normalizePath)(root);
486
483
  const filter = buildFilter(include, exclude, extensions);
487
484
  return (id, ssr, timestamp = Date.now()) => {
488
485
  const { filename, rawQuery } = splitId(id);
@@ -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_vite2 = 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_vite2.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`,
@@ -1162,6 +1155,7 @@ var allowedPluginOptions = /* @__PURE__ */ new Set([
1162
1155
  "hot",
1163
1156
  "ignorePluginPreprocessors",
1164
1157
  "disableDependencyReinclusion",
1158
+ "prebundleSvelteLibraries",
1165
1159
  "experimental"
1166
1160
  ]);
1167
1161
  var knownRootOptions = /* @__PURE__ */ new Set(["extensions", "compilerOptions", "preprocess", "onwarn"]);
@@ -1256,7 +1250,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
1256
1250
  inlineOptions,
1257
1251
  extraOptions
1258
1252
  );
1259
- if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
1253
+ if (svelteConfig?.configFile) {
1260
1254
  merged.configFile = svelteConfig.configFile;
1261
1255
  }
1262
1256
  return merged;
@@ -1271,11 +1265,10 @@ function mergeConfigs(...configs) {
1271
1265
  return result;
1272
1266
  }
1273
1267
  function resolveOptions(preResolveOptions2, viteConfig) {
1274
- var _a;
1275
1268
  const defaultOptions = {
1276
1269
  hot: viteConfig.isProduction ? false : {
1277
1270
  injectCss: !preResolveOptions2.emitCss,
1278
- partialAccept: !!((_a = viteConfig.experimental) == null ? void 0 : _a.hmrPartialAccept)
1271
+ partialAccept: !!viteConfig.experimental?.hmrPartialAccept
1279
1272
  },
1280
1273
  compilerOptions: {
1281
1274
  css: !preResolveOptions2.emitCss,
@@ -1288,6 +1281,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
1288
1281
  };
1289
1282
  const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
1290
1283
  removeIgnoredOptions(merged);
1284
+ handleDeprecatedOptions(merged);
1291
1285
  addSvelteKitOptions(merged);
1292
1286
  addExtraPreprocessors(merged, viteConfig);
1293
1287
  enforceOptionsForHmr(merged);
@@ -1364,9 +1358,8 @@ function removeIgnoredOptions(options) {
1364
1358
  }
1365
1359
  }
1366
1360
  function addSvelteKitOptions(options) {
1367
- var _a;
1368
- if ((options == null ? void 0 : options.kit) != null) {
1369
- 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;
1370
1363
  const hydratable = kit_browser_hydrate !== false;
1371
1364
  if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
1372
1365
  log.warn(
@@ -1377,11 +1370,18 @@ function addSvelteKitOptions(options) {
1377
1370
  options.compilerOptions.hydratable = hydratable;
1378
1371
  }
1379
1372
  }
1373
+ function handleDeprecatedOptions(options) {
1374
+ if (options.experimental?.prebundleSvelteLibraries) {
1375
+ options.prebundleSvelteLibraries = options.experimental?.prebundleSvelteLibraries;
1376
+ log.warn(
1377
+ "experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries"
1378
+ );
1379
+ }
1380
+ }
1380
1381
  function resolveViteRoot(viteConfig) {
1381
1382
  return (0, import_vite3.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
1382
1383
  }
1383
1384
  function buildExtraViteConfig(options, config) {
1384
- var _a, _b;
1385
1385
  const svelteDeps = findRootSvelteDependencies(options.root);
1386
1386
  const extraViteConfig = {
1387
1387
  resolve: {
@@ -1394,7 +1394,7 @@ function buildExtraViteConfig(options, config) {
1394
1394
  options,
1395
1395
  config.optimizeDeps
1396
1396
  );
1397
- if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
1397
+ if (options.prebundleSvelteLibraries) {
1398
1398
  extraViteConfig.optimizeDeps = {
1399
1399
  ...extraViteConfig.optimizeDeps,
1400
1400
  extensions: options.extensions ?? [".svelte"],
@@ -1405,23 +1405,18 @@ function buildExtraViteConfig(options, config) {
1405
1405
  };
1406
1406
  }
1407
1407
  extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
1408
- if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && ((_b = config.experimental) == null ? void 0 : _b.hmrPartialAccept) !== false) {
1408
+ if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && config.experimental?.hmrPartialAccept !== false) {
1409
1409
  log.debug('enabling "experimental.hmrPartialAccept" in vite config');
1410
1410
  extraViteConfig.experimental = { hmrPartialAccept: true };
1411
1411
  }
1412
1412
  return extraViteConfig;
1413
1413
  }
1414
1414
  function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1415
- var _a;
1416
1415
  const include = [];
1417
1416
  const exclude = ["svelte-hmr"];
1418
- const isIncluded = (dep) => {
1419
- var _a2;
1420
- return include.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a2.includes(dep));
1421
- };
1417
+ const isIncluded = (dep) => include.includes(dep) || optimizeDeps?.include?.includes(dep);
1422
1418
  const isExcluded = (dep) => {
1423
- var _a2;
1424
- return exclude.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a2.some((id) => dep === id || id.startsWith(`${dep}/`)));
1419
+ return exclude.includes(dep) || optimizeDeps?.exclude?.some((id) => dep === id || id.startsWith(`${dep}/`));
1425
1420
  };
1426
1421
  if (!isExcluded("svelte")) {
1427
1422
  const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
@@ -1432,7 +1427,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1432
1427
  } else {
1433
1428
  log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
1434
1429
  }
1435
- if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
1430
+ if (options.prebundleSvelteLibraries) {
1436
1431
  return { include, exclude };
1437
1432
  }
1438
1433
  svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
@@ -1459,17 +1454,13 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1459
1454
  return { include, exclude };
1460
1455
  }
1461
1456
  function buildSSROptionsForSvelte(svelteDeps, options, config) {
1462
- var _a, _b;
1463
1457
  const noExternal = [];
1464
- if (!((_b = (_a = config.ssr) == null ? void 0 : _a.external) == null ? void 0 : _b.includes("svelte"))) {
1458
+ if (!config.ssr?.external?.includes("svelte")) {
1465
1459
  noExternal.push("svelte", /^svelte\//);
1466
1460
  }
1467
1461
  noExternal.push(
1468
1462
  ...Array.from(new Set(svelteDeps.map((s) => s.name))).filter(
1469
- (x) => {
1470
- var _a2, _b2;
1471
- return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x));
1472
- }
1463
+ (x) => !config.ssr?.external?.includes(x)
1473
1464
  )
1474
1465
  );
1475
1466
  const ssr = {
@@ -1480,17 +1471,13 @@ function buildSSROptionsForSvelte(svelteDeps, options, config) {
1480
1471
  ssr.external = Array.from(
1481
1472
  new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
1482
1473
  ).filter(
1483
- (dep) => {
1484
- var _a2, _b2;
1485
- return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(dep));
1486
- }
1474
+ (dep) => !ssr.noExternal.includes(dep) && !config.ssr?.external?.includes(dep)
1487
1475
  );
1488
1476
  }
1489
1477
  return ssr;
1490
1478
  }
1491
1479
  function patchResolvedViteConfig(viteConfig, options) {
1492
- var _a, _b;
1493
- 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(
1494
1481
  (plugin) => plugin.name === facadeEsbuildSveltePluginName
1495
1482
  );
1496
1483
  if (facadeEsbuildSveltePlugin) {
@@ -1798,9 +1785,8 @@ function svelteInspector() {
1798
1785
  apply: "serve",
1799
1786
  enforce: "pre",
1800
1787
  configResolved(config) {
1801
- var _a, _b, _c;
1802
1788
  const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
1803
- 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) {
1804
1790
  inspectorOptions = {
1805
1791
  ...defaultInspectorOptions,
1806
1792
  ...vps.api.options.experimental.inspector
@@ -1818,7 +1804,7 @@ function svelteInspector() {
1818
1804
  }
1819
1805
  },
1820
1806
  async resolveId(importee, importer, options) {
1821
- if ((options == null ? void 0 : options.ssr) || disabled) {
1807
+ if (options?.ssr || disabled) {
1822
1808
  return;
1823
1809
  }
1824
1810
  if (importee.startsWith("virtual:svelte-inspector-options")) {
@@ -1830,7 +1816,7 @@ function svelteInspector() {
1830
1816
  }
1831
1817
  },
1832
1818
  async load(id, options) {
1833
- if ((options == null ? void 0 : options.ssr) || disabled) {
1819
+ if (options?.ssr || disabled) {
1834
1820
  return;
1835
1821
  }
1836
1822
  if (id === "virtual:svelte-inspector-options") {
@@ -1845,7 +1831,7 @@ function svelteInspector() {
1845
1831
  }
1846
1832
  },
1847
1833
  transform(code, id, options) {
1848
- if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
1834
+ if (options?.ssr || disabled || !appendTo) {
1849
1835
  return;
1850
1836
  }
1851
1837
  if (id.endsWith(appendTo)) {
@@ -1913,8 +1899,7 @@ function svelte(inlineOptions) {
1913
1899
  log.debug("resolved options", options);
1914
1900
  },
1915
1901
  async buildStart() {
1916
- var _a;
1917
- if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
1902
+ if (!options.prebundleSvelteLibraries)
1918
1903
  return;
1919
1904
  const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
1920
1905
  if (isSvelteMetadataChanged) {
@@ -1926,7 +1911,7 @@ function svelte(inlineOptions) {
1926
1911
  setupWatchers(options, cache, requestParser);
1927
1912
  },
1928
1913
  load(id, opts) {
1929
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1914
+ const ssr = !!opts?.ssr;
1930
1915
  const svelteRequest = requestParser(id, !!ssr);
1931
1916
  if (svelteRequest) {
1932
1917
  const { filename, query } = svelteRequest;
@@ -1944,9 +1929,9 @@ function svelte(inlineOptions) {
1944
1929
  }
1945
1930
  },
1946
1931
  async resolveId(importee, importer, opts) {
1947
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1932
+ const ssr = !!opts?.ssr;
1948
1933
  const svelteRequest = requestParser(importee, ssr);
1949
- if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
1934
+ if (svelteRequest?.query.svelte) {
1950
1935
  if (svelteRequest.query.type === "style") {
1951
1936
  log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
1952
1937
  return svelteRequest.cssId;
@@ -1988,8 +1973,7 @@ function svelte(inlineOptions) {
1988
1973
  }
1989
1974
  },
1990
1975
  async transform(code, id, opts) {
1991
- var _a;
1992
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1976
+ const ssr = !!opts?.ssr;
1993
1977
  const svelteRequest = requestParser(id, ssr);
1994
1978
  if (!svelteRequest || svelteRequest.query.svelte) {
1995
1979
  return;
@@ -2003,7 +1987,7 @@ function svelte(inlineOptions) {
2003
1987
  }
2004
1988
  logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
2005
1989
  cache.update(compileData);
2006
- if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
1990
+ if (compileData.dependencies?.length && options.server) {
2007
1991
  compileData.dependencies.forEach((d) => {
2008
1992
  ensureWatchedFile(options.server.watcher, d, options.root);
2009
1993
  });