@sveltejs/vite-plugin-svelte 1.1.0 → 1.2.0

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.js CHANGED
@@ -8,6 +8,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
8
8
 
9
9
  // src/index.ts
10
10
  import fs8 from "fs";
11
+ import { isDepExcluded as isDepExcluded2 } from "vitefu";
11
12
 
12
13
  // src/utils/log.ts
13
14
  import { cyan, yellow, red } from "kleur/colors";
@@ -98,12 +99,11 @@ var log = {
98
99
  setLevel
99
100
  };
100
101
  function logCompilerWarnings(svelteRequest, warnings, options) {
101
- var _a, _b, _c;
102
102
  const { emitCss, onwarn, isBuild } = options;
103
- const sendViaWS = !isBuild && ((_a = options.experimental) == null ? void 0 : _a.sendWarningsToBrowser);
103
+ const sendViaWS = !isBuild && options.experimental?.sendWarningsToBrowser;
104
104
  let warn = isBuild ? warnBuild : warnDev;
105
105
  const handledByDefaultWarn = [];
106
- const notIgnored = warnings == null ? void 0 : warnings.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
106
+ const notIgnored = warnings?.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
107
107
  const extra = buildExtraWarnings(warnings, isBuild);
108
108
  const allWarnings = [...notIgnored, ...extra];
109
109
  if (sendViaWS) {
@@ -131,7 +131,7 @@ function logCompilerWarnings(svelteRequest, warnings, options) {
131
131
  rawWarnings: warnings
132
132
  };
133
133
  log.debug(`sending svelte:warnings message for ${svelteRequest.normalizedFilename}`);
134
- (_c = (_b = options.server) == null ? void 0 : _b.ws) == null ? void 0 : _c.send("svelte:warnings", message);
134
+ options.server?.ws?.send("svelte:warnings", message);
135
135
  }
136
136
  }
137
137
  function ignoreCompilerWarning(warning, isBuild, emitCss) {
@@ -226,11 +226,11 @@ async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, option
226
226
  return result;
227
227
  }
228
228
  function cssChanged(prev, next) {
229
- return !isCodeEqual(prev == null ? void 0 : prev.code, next == null ? void 0 : next.code);
229
+ return !isCodeEqual(prev?.code, next?.code);
230
230
  }
231
231
  function jsChanged(prev, next, filename) {
232
- const prevJs = prev == null ? void 0 : prev.code;
233
- const nextJs = next == null ? void 0 : next.code;
232
+ const prevJs = prev?.code;
233
+ const nextJs = next?.code;
234
234
  const isStrictEqual = isCodeEqual(prevJs, nextJs);
235
235
  if (isStrictEqual) {
236
236
  return false;
@@ -290,7 +290,6 @@ function toSafe(base64) {
290
290
  // src/utils/compile.ts
291
291
  var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
292
292
  var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequest, code, options) {
293
- var _a, _b, _c;
294
293
  const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
295
294
  const { emitCss = true } = options;
296
295
  const dependencies = [];
@@ -326,11 +325,11 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
326
325
  compileOptions.sourcemap = preprocessed.map;
327
326
  }
328
327
  const finalCode = preprocessed ? preprocessed.code : code;
329
- const dynamicCompileOptions = await ((_b = (_a = options.experimental) == null ? void 0 : _a.dynamicCompileOptions) == null ? void 0 : _b.call(_a, {
328
+ const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
330
329
  filename,
331
330
  code: finalCode,
332
331
  compileOptions
333
- }));
332
+ });
334
333
  if (dynamicCompileOptions && log.debug.enabled) {
335
334
  log.debug(
336
335
  `dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`
@@ -341,7 +340,8 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
341
340
  ...dynamicCompileOptions
342
341
  } : compileOptions;
343
342
  const compiled = compile(finalCode, finalCompileOptions);
344
- if (emitCss && compiled.css.code) {
343
+ const hasCss = compiled.css?.code?.trim().length > 0;
344
+ if (emitCss && hasCss) {
345
345
  compiled.js.code += `
346
346
  import ${JSON.stringify(cssId)};
347
347
  `;
@@ -350,7 +350,7 @@ import ${JSON.stringify(cssId)};
350
350
  compiled.js.code = makeHot({
351
351
  id: filename,
352
352
  compiledCode: compiled.js.code,
353
- hotOptions: options.hot,
353
+ hotOptions: { ...options.hot, injectCss: options.hot?.injectCss === true && hasCss },
354
354
  compiled,
355
355
  originalCode: code,
356
356
  compileOptions: finalCompileOptions
@@ -360,18 +360,17 @@ import ${JSON.stringify(cssId)};
360
360
  return {
361
361
  filename,
362
362
  normalizedFilename,
363
- lang: ((_c = code.match(scriptLangRE)) == null ? void 0 : _c[1]) || "js",
363
+ lang: code.match(scriptLangRE)?.[1] || "js",
364
364
  compiled,
365
365
  ssr,
366
366
  dependencies
367
367
  };
368
368
  };
369
369
  function buildMakeHot(options) {
370
- var _a, _b;
371
370
  const needsMakeHot = options.hot !== false && options.isServe && !options.isProduction;
372
371
  if (needsMakeHot) {
373
- const hotApi = (_a = options == null ? void 0 : options.hot) == null ? void 0 : _a.hotApi;
374
- const adapter = (_b = options == null ? void 0 : options.hot) == null ? void 0 : _b.adapter;
372
+ const hotApi = options?.hot?.hotApi;
373
+ const adapter = options?.hot?.adapter;
375
374
  return createMakeHot({
376
375
  walk,
377
376
  hotApi,
@@ -464,9 +463,7 @@ function buildIdParser(options) {
464
463
  }
465
464
 
466
465
  // src/utils/options.ts
467
- import {
468
- normalizePath as normalizePath2
469
- } from "vite";
466
+ import { normalizePath as normalizePath2 } from "vite";
470
467
 
471
468
  // src/utils/load-svelte-config.ts
472
469
  import { createRequire } from "module";
@@ -485,7 +482,7 @@ var dynamicImportDefault = new Function(
485
482
  'return import(path + "?t=" + timestamp).then(m => m.default)'
486
483
  );
487
484
  async function loadSvelteConfig(viteConfig, inlineOptions) {
488
- if ((inlineOptions == null ? void 0 : inlineOptions.configFile) === false) {
485
+ if (inlineOptions?.configFile === false) {
489
486
  return;
490
487
  }
491
488
  const configFile = findConfigToLoad(viteConfig, inlineOptions);
@@ -534,8 +531,8 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
534
531
  }
535
532
  }
536
533
  function findConfigToLoad(viteConfig, inlineOptions) {
537
- const root = (viteConfig == null ? void 0 : viteConfig.root) || process.cwd();
538
- if (inlineOptions == null ? void 0 : inlineOptions.configFile) {
534
+ const root = viteConfig?.root || process.cwd();
535
+ if (inlineOptions?.configFile) {
539
536
  const abolutePath = path.isAbsolute(inlineOptions.configFile) ? inlineOptions.configFile : path.resolve(root, inlineOptions.configFile);
540
537
  if (!fs2.existsSync(abolutePath)) {
541
538
  throw new Error(`failed to find svelte config file ${abolutePath}.`);
@@ -578,182 +575,8 @@ var SVELTE_HMR_IMPORTS = [
578
575
  // src/utils/options.ts
579
576
  import path4 from "path";
580
577
 
581
- // src/utils/dependencies.ts
582
- import path2 from "path";
583
- import fs3 from "fs";
584
- import { createRequire as createRequire2 } from "module";
585
- function findRootSvelteDependencies(root, cwdFallback = true) {
586
- log.debug(`findSvelteDependencies: searching svelte dependencies in ${root}`);
587
- const pkgFile = path2.join(root, "package.json");
588
- if (!fs3.existsSync(pkgFile)) {
589
- if (cwdFallback) {
590
- const cwd = process.cwd();
591
- if (root !== cwd) {
592
- log.debug(`no package.json found in vite root ${root}`);
593
- return findRootSvelteDependencies(cwd, false);
594
- }
595
- }
596
- log.warn(`no package.json found, findRootSvelteDependencies failed`);
597
- return [];
598
- }
599
- const pkg = parsePkg(root);
600
- if (!pkg) {
601
- return [];
602
- }
603
- const deps = [
604
- ...Object.keys(pkg.dependencies || {}),
605
- ...Object.keys(pkg.devDependencies || {})
606
- ].filter((dep) => !is_common_without_svelte_field(dep));
607
- return getSvelteDependencies(deps, root);
608
- }
609
- function getSvelteDependencies(deps, pkgDir, path9 = []) {
610
- const result = [];
611
- const localRequire = createRequire2(`${pkgDir}/package.json`);
612
- const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
613
- for (const { pkg, dir } of resolvedDeps) {
614
- const type = getSvelteDependencyType(pkg);
615
- if (!type)
616
- continue;
617
- result.push({ name: pkg.name, type, pkg, dir, path: path9 });
618
- if (type === "component-library" && pkg.dependencies) {
619
- let dependencyNames = Object.keys(pkg.dependencies);
620
- const circular = dependencyNames.filter((name) => path9.includes(name));
621
- if (circular.length > 0) {
622
- log.warn.enabled && log.warn(
623
- `skipping circular svelte dependencies in automated vite optimizeDeps handling`,
624
- circular.map((x) => path9.concat(x).join(">"))
625
- );
626
- dependencyNames = dependencyNames.filter((name) => !path9.includes(name));
627
- }
628
- if (path9.length === 3) {
629
- log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`);
630
- }
631
- result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name)));
632
- }
633
- }
634
- return result;
635
- }
636
- function resolveDependencyData(dep, localRequire) {
637
- try {
638
- const pkgJson = `${dep}/package.json`;
639
- const pkg = localRequire(pkgJson);
640
- const dir = path2.dirname(localRequire.resolve(pkgJson));
641
- return { dir, pkg };
642
- } catch (e) {
643
- log.debug.once(`dependency ${dep} does not export package.json`, e);
644
- try {
645
- let dir = path2.dirname(localRequire.resolve(dep));
646
- while (dir) {
647
- const pkg = parsePkg(dir, true);
648
- if (pkg && pkg.name === dep) {
649
- return { dir, pkg };
650
- }
651
- const parent = path2.dirname(dir);
652
- if (parent === dir) {
653
- break;
654
- }
655
- dir = parent;
656
- }
657
- } catch (e2) {
658
- log.debug.once(`error while trying to find package.json of ${dep}`, e2);
659
- }
660
- }
661
- log.debug.once(`failed to resolve ${dep}`);
662
- }
663
- function parsePkg(dir, silent = false) {
664
- const pkgFile = path2.join(dir, "package.json");
665
- try {
666
- return JSON.parse(fs3.readFileSync(pkgFile, "utf-8"));
667
- } catch (e) {
668
- !silent && log.warn.enabled && log.warn(`failed to parse ${pkgFile}`, e);
669
- }
670
- }
671
- function getSvelteDependencyType(pkg) {
672
- if (isSvelteComponentLib(pkg)) {
673
- return "component-library";
674
- } else if (isSvelteLib(pkg)) {
675
- return "js-library";
676
- } else {
677
- return void 0;
678
- }
679
- }
680
- function isSvelteComponentLib(pkg) {
681
- return !!pkg.svelte;
682
- }
683
- function isSvelteLib(pkg) {
684
- var _a, _b;
685
- return !!((_a = pkg.dependencies) == null ? void 0 : _a.svelte) || !!((_b = pkg.peerDependencies) == null ? void 0 : _b.svelte);
686
- }
687
- var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
688
- "@lukeed/uuid",
689
- "@playwright/test",
690
- "@sveltejs/vite-plugin-svelte",
691
- "@sveltejs/kit",
692
- "autoprefixer",
693
- "cookie",
694
- "dotenv",
695
- "esbuild",
696
- "eslint",
697
- "jest",
698
- "mdsvex",
699
- "playwright",
700
- "postcss",
701
- "prettier",
702
- "svelte",
703
- "svelte-check",
704
- "svelte-hmr",
705
- "svelte-preprocess",
706
- "tslib",
707
- "typescript",
708
- "vite",
709
- "vitest",
710
- "__vite-browser-external"
711
- ];
712
- var COMMON_PREFIXES_WITHOUT_SVELTE_FIELD = [
713
- "@fontsource/",
714
- "@postcss-plugins/",
715
- "@rollup/",
716
- "@sveltejs/adapter-",
717
- "@types/",
718
- "@typescript-eslint/",
719
- "eslint-",
720
- "jest-",
721
- "postcss-plugin-",
722
- "prettier-plugin-",
723
- "rollup-plugin-",
724
- "vite-plugin-"
725
- ];
726
- function is_common_without_svelte_field(dependency) {
727
- return COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD.includes(dependency) || COMMON_PREFIXES_WITHOUT_SVELTE_FIELD.some(
728
- (prefix2) => prefix2.startsWith("@") ? dependency.startsWith(prefix2) : dependency.substring(dependency.lastIndexOf("/") + 1).startsWith(prefix2)
729
- );
730
- }
731
- function needsOptimization(dep, localRequire) {
732
- const depData = resolveDependencyData(dep, localRequire);
733
- if (!depData)
734
- return false;
735
- const pkg = depData.pkg;
736
- const hasEsmFields = pkg.module || pkg.exports;
737
- if (hasEsmFields)
738
- return false;
739
- if (pkg.main) {
740
- const entryExt = path2.extname(pkg.main);
741
- return !entryExt || entryExt === ".js" || entryExt === ".cjs";
742
- } else {
743
- try {
744
- localRequire.resolve(`${dep}/index.js`);
745
- return true;
746
- } catch {
747
- return false;
748
- }
749
- }
750
- }
751
-
752
- // src/utils/options.ts
753
- import { createRequire as createRequire3 } from "module";
754
-
755
578
  // src/utils/esbuild.ts
756
- import { promises as fs4 } from "fs";
579
+ import { promises as fs3 } from "fs";
757
580
  import { compile as compile2, preprocess as preprocess2 } from "svelte/compiler";
758
581
 
759
582
  // src/utils/error.ts
@@ -809,19 +632,49 @@ function formatFrameForVite(frame) {
809
632
  return frame.split("\n").map((line) => line.match(/^\s+\^/) ? " " + line : " " + line.replace(":", " | ")).join("\n");
810
633
  }
811
634
 
635
+ // src/utils/svelte-version.ts
636
+ import { VERSION } from "svelte/compiler";
637
+ var svelteVersion = parseVersion(VERSION);
638
+ function parseVersion(version) {
639
+ const segments = version.split(".", 3).map((s) => parseInt(s, 10));
640
+ while (segments.length < 3) {
641
+ segments.push(0);
642
+ }
643
+ return segments;
644
+ }
645
+ function compareToSvelte(version) {
646
+ const parsedVersion = parseVersion(version);
647
+ for (let i = 0; i < svelteVersion.length; i++) {
648
+ const a = parsedVersion[i];
649
+ const b = svelteVersion[i];
650
+ if (a === b) {
651
+ continue;
652
+ } else if (a > b) {
653
+ return 1;
654
+ } else {
655
+ return -1;
656
+ }
657
+ }
658
+ return 0;
659
+ }
660
+ function atLeastSvelte(version) {
661
+ const result = compareToSvelte(version) <= 0;
662
+ return result;
663
+ }
664
+
812
665
  // src/utils/esbuild.ts
666
+ var isCssString = atLeastSvelte("3.53.0");
813
667
  var facadeEsbuildSveltePluginName = "vite-plugin-svelte:facade";
814
668
  function esbuildSveltePlugin(options) {
815
669
  return {
816
670
  name: "vite-plugin-svelte:optimize-svelte",
817
671
  setup(build) {
818
- var _a;
819
- if ((_a = build.initialOptions.plugins) == null ? void 0 : _a.some((v) => v.name === "vite:dep-scan"))
672
+ if (build.initialOptions.plugins?.some((v) => v.name === "vite:dep-scan"))
820
673
  return;
821
674
  const svelteExtensions = (options.extensions ?? [".svelte"]).map((ext) => ext.slice(1));
822
675
  const svelteFilter = new RegExp(`\\.(` + svelteExtensions.join("|") + `)(\\?.*)?$`);
823
676
  build.onLoad({ filter: svelteFilter }, async ({ path: filename }) => {
824
- const code = await fs4.readFile(filename, "utf8");
677
+ const code = await fs3.readFile(filename, "utf8");
825
678
  try {
826
679
  const contents = await compileSvelte(options, { filename, code });
827
680
  return { contents };
@@ -833,10 +686,13 @@ function esbuildSveltePlugin(options) {
833
686
  };
834
687
  }
835
688
  async function compileSvelte(options, { filename, code }) {
836
- var _a, _b;
689
+ let css = options.compilerOptions.css;
690
+ if (css !== "none") {
691
+ css = isCssString ? "injected" : true;
692
+ }
837
693
  const compileOptions = {
838
694
  ...options.compilerOptions,
839
- css: true,
695
+ css,
840
696
  filename,
841
697
  format: "esm",
842
698
  generate: "dom"
@@ -853,11 +709,11 @@ async function compileSvelte(options, { filename, code }) {
853
709
  compileOptions.sourcemap = preprocessed.map;
854
710
  }
855
711
  const finalCode = preprocessed ? preprocessed.code : code;
856
- const dynamicCompileOptions = await ((_b = (_a = options.experimental) == null ? void 0 : _a.dynamicCompileOptions) == null ? void 0 : _b.call(_a, {
712
+ const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
857
713
  filename,
858
714
  code: finalCode,
859
715
  compileOptions
860
- }));
716
+ });
861
717
  if (dynamicCompileOptions && log.debug.enabled) {
862
718
  log.debug(`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`);
863
719
  }
@@ -870,9 +726,7 @@ async function compileSvelte(options, { filename, code }) {
870
726
  }
871
727
 
872
728
  // src/utils/preprocess.ts
873
- import {
874
- transformWithEsbuild
875
- } from "vite";
729
+ import * as vite from "vite";
876
730
  import MagicString2 from "magic-string";
877
731
  import { preprocess as preprocess3 } from "svelte/compiler";
878
732
 
@@ -900,7 +754,7 @@ async function buildMagicString(from, to, options) {
900
754
  const diff = diffs[i];
901
755
  const nextDiff = diffs[i + 1];
902
756
  if (diff[0] === DIFF_DELETE) {
903
- if ((nextDiff == null ? void 0 : nextDiff[0]) === DIFF_INSERT) {
757
+ if (nextDiff?.[0] === DIFF_INSERT) {
904
758
  m.overwrite(pos, pos + diff[1].length, nextDiff[1]);
905
759
  i++;
906
760
  } else {
@@ -925,7 +779,7 @@ async function buildSourceMap(from, to, filename) {
925
779
  }
926
780
 
927
781
  // src/utils/preprocess.ts
928
- import path3 from "path";
782
+ import path2 from "path";
929
783
  var supportedStyleLangs = ["css", "less", "sass", "scss", "styl", "stylus", "postcss"];
930
784
  var supportedScriptLangs = ["ts"];
931
785
  function createViteScriptPreprocessor() {
@@ -933,7 +787,7 @@ function createViteScriptPreprocessor() {
933
787
  const lang = attributes.lang;
934
788
  if (!supportedScriptLangs.includes(lang))
935
789
  return;
936
- const transformResult = await transformWithEsbuild(content, filename, {
790
+ const transformResult = await vite.transformWithEsbuild(content, filename, {
937
791
  loader: lang,
938
792
  target: "esnext",
939
793
  tsconfigRaw: {
@@ -950,34 +804,39 @@ function createViteScriptPreprocessor() {
950
804
  };
951
805
  }
952
806
  function createViteStylePreprocessor(config) {
953
- const pluginName = "vite:css";
954
- const plugin = config.plugins.find((p) => p.name === pluginName);
955
- if (!plugin) {
956
- throw new Error(`failed to find plugin ${pluginName}`);
957
- }
958
- if (!plugin.transform) {
959
- throw new Error(`plugin ${pluginName} has no transform`);
960
- }
961
- const pluginTransform = plugin.transform.bind(null);
807
+ const transform = getCssTransformFn(config);
962
808
  return async ({ attributes, content, filename = "" }) => {
963
- var _a, _b;
964
809
  const lang = attributes.lang;
965
810
  if (!supportedStyleLangs.includes(lang))
966
811
  return;
967
812
  const moduleId = `${filename}.${lang}`;
968
- const transformResult = await pluginTransform(
969
- content,
970
- moduleId
971
- );
972
- if (((_b = (_a = transformResult.map) == null ? void 0 : _a.sources) == null ? void 0 : _b[0]) === moduleId) {
973
- transformResult.map.sources[0] = path3.basename(filename);
813
+ const result = await transform(content, moduleId);
814
+ if (result.map?.sources?.[0] === moduleId) {
815
+ result.map.sources[0] = path2.basename(filename);
974
816
  }
975
817
  return {
976
- code: transformResult.code,
977
- map: transformResult.map ?? void 0
818
+ code: result.code,
819
+ map: result.map ?? void 0
978
820
  };
979
821
  };
980
822
  }
823
+ function getCssTransformFn(config) {
824
+ if (vite.preprocessCSS) {
825
+ return async (code, filename) => {
826
+ return vite.preprocessCSS(code, filename, config);
827
+ };
828
+ } else {
829
+ const pluginName = "vite:css";
830
+ const plugin = config.plugins.find((p) => p.name === pluginName);
831
+ if (!plugin) {
832
+ throw new Error(`failed to find plugin ${pluginName}`);
833
+ }
834
+ if (!plugin.transform) {
835
+ throw new Error(`plugin ${pluginName} has no transform`);
836
+ }
837
+ return plugin.transform.bind(null);
838
+ }
839
+ }
981
840
  function createVitePreprocessorGroup(config) {
982
841
  return {
983
842
  markup({ content, filename }) {
@@ -1000,7 +859,7 @@ function createInjectScopeEverythingRulePreprocessorGroup() {
1000
859
  return {
1001
860
  code: s.toString(),
1002
861
  map: s.generateDecodedMap({
1003
- source: filename ? path3.basename(filename) : void 0,
862
+ source: filename ? path2.basename(filename) : void 0,
1004
863
  hires: true
1005
864
  })
1006
865
  };
@@ -1008,14 +867,13 @@ function createInjectScopeEverythingRulePreprocessorGroup() {
1008
867
  };
1009
868
  }
1010
869
  function buildExtraPreprocessors(options, config) {
1011
- var _a, _b;
1012
870
  const prependPreprocessors = [];
1013
871
  const appendPreprocessors = [];
1014
- if ((_a = options.experimental) == null ? void 0 : _a.useVitePreprocess) {
872
+ if (options.experimental?.useVitePreprocess) {
1015
873
  log.debug("adding vite preprocessor");
1016
874
  prependPreprocessors.push(createVitePreprocessorGroup(config));
1017
875
  }
1018
- const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p == null ? void 0 : p.sveltePreprocess);
876
+ const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess);
1019
877
  if (pluginsWithPreprocessorsDeprecated.length > 0) {
1020
878
  log.warn(
1021
879
  `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(", ")}`
@@ -1033,13 +891,10 @@ function buildExtraPreprocessors(options, config) {
1033
891
  }
1034
892
  });
1035
893
  }
1036
- const pluginsWithPreprocessors = config.plugins.filter((p) => {
1037
- var _a2;
1038
- return (_a2 = p == null ? void 0 : p.api) == null ? void 0 : _a2.sveltePreprocess;
1039
- });
894
+ const pluginsWithPreprocessors = config.plugins.filter((p) => p?.api?.sveltePreprocess);
1040
895
  const ignored = [], included = [];
1041
896
  for (const p of pluginsWithPreprocessors) {
1042
- if (options.ignorePluginPreprocessors === true || Array.isArray(options.ignorePluginPreprocessors) && ((_b = options.ignorePluginPreprocessors) == null ? void 0 : _b.includes(p.name))) {
897
+ if (options.ignorePluginPreprocessors === true || Array.isArray(options.ignorePluginPreprocessors) && options.ignorePluginPreprocessors?.includes(p.name)) {
1043
898
  ignored.push(p);
1044
899
  } else {
1045
900
  included.push(p);
@@ -1062,7 +917,6 @@ function buildExtraPreprocessors(options, config) {
1062
917
  return { prependPreprocessors, appendPreprocessors };
1063
918
  }
1064
919
  function addExtraPreprocessors(options, config) {
1065
- var _a;
1066
920
  const { prependPreprocessors, appendPreprocessors } = buildExtraPreprocessors(options, config);
1067
921
  if (prependPreprocessors.length > 0 || appendPreprocessors.length > 0) {
1068
922
  if (!options.preprocess) {
@@ -1074,7 +928,7 @@ function addExtraPreprocessors(options, config) {
1074
928
  options.preprocess = [...prependPreprocessors, options.preprocess, ...appendPreprocessors];
1075
929
  }
1076
930
  }
1077
- const generateMissingSourceMaps = !!((_a = options.experimental) == null ? void 0 : _a.generateMissingPreprocessorSourcemaps);
931
+ const generateMissingSourceMaps = !!options.experimental?.generateMissingPreprocessorSourcemaps;
1078
932
  if (options.preprocess && generateMissingSourceMaps) {
1079
933
  options.preprocess = Array.isArray(options.preprocess) ? options.preprocess.map((p, i) => validateSourceMapOutputWrapper(p, i)) : validateSourceMapOutputWrapper(options.preprocess, 0);
1080
934
  }
@@ -1083,7 +937,6 @@ function validateSourceMapOutputWrapper(group, i) {
1083
937
  const wrapper = {};
1084
938
  for (const [processorType, processorFn] of Object.entries(group)) {
1085
939
  wrapper[processorType] = async (options) => {
1086
- var _a;
1087
940
  const result = await processorFn(options);
1088
941
  if (result && result.code !== options.content) {
1089
942
  let invalidMap = false;
@@ -1097,7 +950,7 @@ function validateSourceMapOutputWrapper(group, i) {
1097
950
  processor: processorFn.toString()
1098
951
  }
1099
952
  );
1100
- } else if (((_a = result.map) == null ? void 0 : _a.mappings) === "") {
953
+ } else if (result.map?.mappings === "") {
1101
954
  invalidMap = true;
1102
955
  log.warn.enabled && log.warn.once(
1103
956
  `preprocessor at index ${i} returned an invalid empty sourcemap for ${processorType} transform`,
@@ -1130,6 +983,78 @@ function validateSourceMapOutputWrapper(group, i) {
1130
983
 
1131
984
  // src/utils/options.ts
1132
985
  import deepmerge from "deepmerge";
986
+ import {
987
+ crawlFrameworkPkgs,
988
+ isDepExcluded,
989
+ isDepExternaled,
990
+ isDepIncluded,
991
+ isDepNoExternaled
992
+ } from "vitefu";
993
+
994
+ // src/utils/dependencies.ts
995
+ import path3 from "path";
996
+ import fs4 from "fs/promises";
997
+ import { findDepPkgJsonPath } from "vitefu";
998
+ async function resolveDependencyData(dep, parent) {
999
+ const depDataPath = await findDepPkgJsonPath(dep, parent);
1000
+ if (!depDataPath)
1001
+ return void 0;
1002
+ try {
1003
+ return {
1004
+ dir: path3.dirname(depDataPath),
1005
+ pkg: JSON.parse(await fs4.readFile(depDataPath, "utf-8"))
1006
+ };
1007
+ } catch {
1008
+ return void 0;
1009
+ }
1010
+ }
1011
+ var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
1012
+ "@lukeed/uuid",
1013
+ "@playwright/test",
1014
+ "@sveltejs/vite-plugin-svelte",
1015
+ "@sveltejs/kit",
1016
+ "autoprefixer",
1017
+ "cookie",
1018
+ "dotenv",
1019
+ "esbuild",
1020
+ "eslint",
1021
+ "jest",
1022
+ "mdsvex",
1023
+ "playwright",
1024
+ "postcss",
1025
+ "prettier",
1026
+ "svelte",
1027
+ "svelte-check",
1028
+ "svelte-hmr",
1029
+ "svelte-preprocess",
1030
+ "tslib",
1031
+ "typescript",
1032
+ "vite",
1033
+ "vitest",
1034
+ "__vite-browser-external"
1035
+ ];
1036
+ var COMMON_PREFIXES_WITHOUT_SVELTE_FIELD = [
1037
+ "@fontsource/",
1038
+ "@postcss-plugins/",
1039
+ "@rollup/",
1040
+ "@sveltejs/adapter-",
1041
+ "@types/",
1042
+ "@typescript-eslint/",
1043
+ "eslint-",
1044
+ "jest-",
1045
+ "postcss-plugin-",
1046
+ "prettier-plugin-",
1047
+ "rollup-plugin-",
1048
+ "vite-plugin-"
1049
+ ];
1050
+ function isCommonDepWithoutSvelteField(dependency) {
1051
+ return COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD.includes(dependency) || COMMON_PREFIXES_WITHOUT_SVELTE_FIELD.some(
1052
+ (prefix2) => prefix2.startsWith("@") ? dependency.startsWith(prefix2) : dependency.substring(dependency.lastIndexOf("/") + 1).startsWith(prefix2)
1053
+ );
1054
+ }
1055
+
1056
+ // src/utils/options.ts
1057
+ var cssAsString = atLeastSvelte("3.53.0");
1133
1058
  var allowedPluginOptions = /* @__PURE__ */ new Set([
1134
1059
  "include",
1135
1060
  "exclude",
@@ -1232,7 +1157,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
1232
1157
  inlineOptions,
1233
1158
  extraOptions
1234
1159
  );
1235
- if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
1160
+ if (svelteConfig?.configFile) {
1236
1161
  merged.configFile = svelteConfig.configFile;
1237
1162
  }
1238
1163
  return merged;
@@ -1247,14 +1172,14 @@ function mergeConfigs(...configs) {
1247
1172
  return result;
1248
1173
  }
1249
1174
  function resolveOptions(preResolveOptions2, viteConfig) {
1250
- var _a;
1175
+ const css = cssAsString ? preResolveOptions2.emitCss ? "external" : "injected" : !preResolveOptions2.emitCss;
1251
1176
  const defaultOptions = {
1252
1177
  hot: viteConfig.isProduction ? false : {
1253
- injectCss: !preResolveOptions2.emitCss,
1254
- partialAccept: !!((_a = viteConfig.experimental) == null ? void 0 : _a.hmrPartialAccept)
1178
+ injectCss: css === true || css === "injected",
1179
+ partialAccept: !!viteConfig.experimental?.hmrPartialAccept
1255
1180
  },
1256
1181
  compilerOptions: {
1257
- css: !preResolveOptions2.emitCss,
1182
+ css,
1258
1183
  dev: !viteConfig.isProduction
1259
1184
  }
1260
1185
  };
@@ -1282,11 +1207,13 @@ function enforceOptionsForHmr(options) {
1282
1207
  log.warn("hmr and emitCss are enabled but hot.injectCss is true, forcing it to false");
1283
1208
  options.hot.injectCss = false;
1284
1209
  }
1285
- if (options.compilerOptions.css) {
1210
+ const css = options.compilerOptions.css;
1211
+ if (css === true || css === "injected") {
1212
+ const forcedCss = cssAsString ? "external" : false;
1286
1213
  log.warn(
1287
- "hmr and emitCss are enabled but compilerOptions.css is true, forcing it to false"
1214
+ `hmr and emitCss are enabled but compilerOptions.css is ${css}, forcing it to ${forcedCss}`
1288
1215
  );
1289
- options.compilerOptions.css = false;
1216
+ options.compilerOptions.css = forcedCss;
1290
1217
  }
1291
1218
  } else {
1292
1219
  if (options.hot === true || !options.hot.injectCss) {
@@ -1299,11 +1226,13 @@ function enforceOptionsForHmr(options) {
1299
1226
  options.hot.injectCss = true;
1300
1227
  }
1301
1228
  }
1302
- if (!options.compilerOptions.css) {
1229
+ const css = options.compilerOptions.css;
1230
+ if (!(css === true || css === "injected")) {
1231
+ const forcedCss = cssAsString ? "injected" : true;
1303
1232
  log.warn(
1304
- "hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to true"
1233
+ `hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to ${forcedCss}`
1305
1234
  );
1306
- options.compilerOptions.css = true;
1235
+ options.compilerOptions.css = forcedCss;
1307
1236
  }
1308
1237
  }
1309
1238
  }
@@ -1341,23 +1270,14 @@ function removeIgnoredOptions(options) {
1341
1270
  }
1342
1271
  }
1343
1272
  function addSvelteKitOptions(options) {
1344
- var _a;
1345
- if ((options == null ? void 0 : options.kit) != null) {
1346
- const kit_browser_hydrate = (_a = options.kit.browser) == null ? void 0 : _a.hydrate;
1347
- const hydratable = kit_browser_hydrate !== false;
1348
- if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
1349
- log.warn(
1350
- `Conflicting values "compilerOptions.hydratable: ${options.compilerOptions.hydratable}" and "kit.browser.hydrate: ${kit_browser_hydrate}" in your svelte config. You should remove "compilerOptions.hydratable".`
1351
- );
1352
- }
1353
- log.debug(`Setting compilerOptions.hydratable: ${hydratable} for SvelteKit`);
1354
- options.compilerOptions.hydratable = hydratable;
1273
+ if (options?.kit != null && options.compilerOptions.hydratable == null) {
1274
+ log.debug(`Setting compilerOptions.hydratable = true for SvelteKit`);
1275
+ options.compilerOptions.hydratable = true;
1355
1276
  }
1356
1277
  }
1357
1278
  function handleDeprecatedOptions(options) {
1358
- var _a, _b;
1359
- if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
1360
- options.prebundleSvelteLibraries = (_b = options.experimental) == null ? void 0 : _b.prebundleSvelteLibraries;
1279
+ if (options.experimental?.prebundleSvelteLibraries) {
1280
+ options.prebundleSvelteLibraries = options.experimental?.prebundleSvelteLibraries;
1361
1281
  log.warn(
1362
1282
  "experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries"
1363
1283
  );
@@ -1366,116 +1286,121 @@ function handleDeprecatedOptions(options) {
1366
1286
  function resolveViteRoot(viteConfig) {
1367
1287
  return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
1368
1288
  }
1369
- function buildExtraViteConfig(options, config) {
1370
- var _a;
1371
- const svelteDeps = findRootSvelteDependencies(options.root);
1289
+ async function buildExtraViteConfig(options, config) {
1372
1290
  const extraViteConfig = {
1373
1291
  resolve: {
1374
1292
  mainFields: [...SVELTE_RESOLVE_MAIN_FIELDS],
1375
1293
  dedupe: [...SVELTE_IMPORTS, ...SVELTE_HMR_IMPORTS]
1376
1294
  }
1377
1295
  };
1378
- extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(
1379
- svelteDeps,
1380
- options,
1381
- config.optimizeDeps
1382
- );
1296
+ const extraSvelteConfig = buildExtraConfigForSvelte(config);
1297
+ const extraDepsConfig = await buildExtraConfigForDependencies(options, config);
1298
+ extraViteConfig.optimizeDeps = {
1299
+ include: [
1300
+ ...extraSvelteConfig.optimizeDeps.include,
1301
+ ...extraDepsConfig.optimizeDeps.include.filter(
1302
+ (dep) => !isDepExcluded(dep, extraSvelteConfig.optimizeDeps.exclude)
1303
+ )
1304
+ ],
1305
+ exclude: [
1306
+ ...extraSvelteConfig.optimizeDeps.exclude,
1307
+ ...extraDepsConfig.optimizeDeps.exclude.filter(
1308
+ (dep) => !isDepIncluded(dep, extraSvelteConfig.optimizeDeps.include)
1309
+ )
1310
+ ]
1311
+ };
1312
+ extraViteConfig.ssr = {
1313
+ external: [
1314
+ ...extraSvelteConfig.ssr.external,
1315
+ ...extraDepsConfig.ssr.external.filter(
1316
+ (dep) => !isDepNoExternaled(dep, extraSvelteConfig.ssr.noExternal)
1317
+ )
1318
+ ],
1319
+ noExternal: [
1320
+ ...extraSvelteConfig.ssr.noExternal,
1321
+ ...extraDepsConfig.ssr.noExternal.filter(
1322
+ (dep) => !isDepExternaled(dep, extraSvelteConfig.ssr.external)
1323
+ )
1324
+ ]
1325
+ };
1383
1326
  if (options.prebundleSvelteLibraries) {
1384
- extraViteConfig.optimizeDeps = {
1385
- ...extraViteConfig.optimizeDeps,
1386
- extensions: options.extensions ?? [".svelte"],
1387
- esbuildOptions: {
1388
- plugins: [{ name: facadeEsbuildSveltePluginName, setup: () => {
1389
- } }]
1390
- }
1327
+ extraViteConfig.optimizeDeps.extensions = options.extensions ?? [".svelte"];
1328
+ extraViteConfig.optimizeDeps.esbuildOptions = {
1329
+ plugins: [{ name: facadeEsbuildSveltePluginName, setup: () => {
1330
+ } }]
1391
1331
  };
1392
1332
  }
1393
- extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
1394
- if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && ((_a = config.experimental) == null ? void 0 : _a.hmrPartialAccept) !== false) {
1333
+ if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && config.experimental?.hmrPartialAccept !== false) {
1395
1334
  log.debug('enabling "experimental.hmrPartialAccept" in vite config');
1396
1335
  extraViteConfig.experimental = { hmrPartialAccept: true };
1397
1336
  }
1398
1337
  return extraViteConfig;
1399
1338
  }
1400
- function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1339
+ async function buildExtraConfigForDependencies(options, config) {
1340
+ const depsConfig = await crawlFrameworkPkgs({
1341
+ root: options.root,
1342
+ isBuild: options.isBuild,
1343
+ viteUserConfig: config,
1344
+ isFrameworkPkgByJson(pkgJson) {
1345
+ return !!pkgJson.svelte;
1346
+ },
1347
+ isSemiFrameworkPkgByJson(pkgJson) {
1348
+ return !!pkgJson.dependencies?.svelte || !!pkgJson.peerDependencies?.svelte;
1349
+ },
1350
+ isFrameworkPkgByName(pkgName) {
1351
+ const isNotSveltePackage = isCommonDepWithoutSvelteField(pkgName);
1352
+ if (isNotSveltePackage) {
1353
+ return false;
1354
+ } else {
1355
+ return void 0;
1356
+ }
1357
+ }
1358
+ });
1359
+ log.debug("extra config for dependencies generated by vitefu", depsConfig);
1360
+ if (options.prebundleSvelteLibraries) {
1361
+ depsConfig.optimizeDeps.exclude = [];
1362
+ const userExclude = config.optimizeDeps?.exclude;
1363
+ depsConfig.optimizeDeps.include = !userExclude ? [] : depsConfig.optimizeDeps.include.filter((dep) => {
1364
+ return dep.includes(">") && dep.split(">").slice(0, -1).some((d) => isDepExcluded(d.trim(), userExclude));
1365
+ });
1366
+ }
1367
+ if (options.disableDependencyReinclusion === true) {
1368
+ depsConfig.optimizeDeps.include = depsConfig.optimizeDeps.include.filter(
1369
+ (dep) => !dep.includes(">")
1370
+ );
1371
+ } else if (Array.isArray(options.disableDependencyReinclusion)) {
1372
+ const disabledDeps = options.disableDependencyReinclusion;
1373
+ depsConfig.optimizeDeps.include = depsConfig.optimizeDeps.include.filter((dep) => {
1374
+ if (!dep.includes(">"))
1375
+ return true;
1376
+ const trimDep = dep.replace(/\s+/g, "");
1377
+ return disabledDeps.some((disabled) => trimDep.includes(`${disabled}>`));
1378
+ });
1379
+ }
1380
+ log.debug("post-processed extra config for dependencies", depsConfig);
1381
+ return depsConfig;
1382
+ }
1383
+ function buildExtraConfigForSvelte(config) {
1401
1384
  const include = [];
1402
1385
  const exclude = ["svelte-hmr"];
1403
- const isIncluded = (dep) => {
1404
- var _a;
1405
- return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
1406
- };
1407
- const isExcluded = (dep) => {
1408
- var _a;
1409
- return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
1410
- };
1411
- if (!isExcluded("svelte")) {
1386
+ if (!isDepExcluded("svelte", config.optimizeDeps?.exclude ?? [])) {
1412
1387
  const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
1413
1388
  log.debug(
1414
1389
  `adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(", ")} `
1415
1390
  );
1416
- include.push(...svelteImportsToInclude.filter((x) => !isIncluded(x)));
1391
+ include.push(...svelteImportsToInclude);
1417
1392
  } else {
1418
1393
  log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
1419
1394
  }
1420
- if (options.prebundleSvelteLibraries) {
1421
- return { include, exclude };
1422
- }
1423
- svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
1424
- const svelteDepsToExclude = Array.from(new Set(svelteDeps.map((dep) => dep.name))).filter(
1425
- (dep) => !isIncluded(dep)
1426
- );
1427
- log.debug(`automatically excluding found svelte dependencies: ${svelteDepsToExclude.join(", ")}`);
1428
- exclude.push(...svelteDepsToExclude.filter((x) => !isExcluded(x)));
1429
- if (options.disableDependencyReinclusion !== true) {
1430
- const disabledReinclusions = options.disableDependencyReinclusion || [];
1431
- if (disabledReinclusions.length > 0) {
1432
- log.debug(`not reincluding transitive dependencies of`, disabledReinclusions);
1433
- }
1434
- const transitiveDepsToInclude = svelteDeps.filter((dep) => !disabledReinclusions.includes(dep.name) && isExcluded(dep.name)).flatMap((dep) => {
1435
- const localRequire = createRequire3(`${dep.dir}/package.json`);
1436
- return Object.keys(dep.pkg.dependencies || {}).filter((depOfDep) => !isExcluded(depOfDep) && needsOptimization(depOfDep, localRequire)).map((depOfDep) => dep.path.concat(dep.name, depOfDep).join(" > "));
1437
- });
1438
- log.debug(
1439
- `reincluding transitive dependencies of excluded svelte dependencies`,
1440
- transitiveDepsToInclude
1441
- );
1442
- include.push(...transitiveDepsToInclude);
1443
- }
1444
- return { include, exclude };
1445
- }
1446
- function buildSSROptionsForSvelte(svelteDeps, options, config) {
1447
- var _a, _b;
1448
1395
  const noExternal = [];
1449
- if (!((_b = (_a = config.ssr) == null ? void 0 : _a.external) == null ? void 0 : _b.includes("svelte"))) {
1396
+ const external = [];
1397
+ if (!isDepExternaled("svelte", config.ssr?.external ?? [])) {
1450
1398
  noExternal.push("svelte", /^svelte\//);
1451
1399
  }
1452
- noExternal.push(
1453
- ...Array.from(new Set(svelteDeps.map((s) => s.name))).filter(
1454
- (x) => {
1455
- var _a2, _b2;
1456
- return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x));
1457
- }
1458
- )
1459
- );
1460
- const ssr = {
1461
- noExternal,
1462
- external: []
1463
- };
1464
- if (options.isServe) {
1465
- ssr.external = Array.from(
1466
- new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
1467
- ).filter(
1468
- (dep) => {
1469
- var _a2, _b2;
1470
- return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(dep));
1471
- }
1472
- );
1473
- }
1474
- return ssr;
1400
+ return { optimizeDeps: { include, exclude }, ssr: { noExternal, external } };
1475
1401
  }
1476
1402
  function patchResolvedViteConfig(viteConfig, options) {
1477
- var _a, _b;
1478
- const facadeEsbuildSveltePlugin = (_b = (_a = viteConfig.optimizeDeps.esbuildOptions) == null ? void 0 : _a.plugins) == null ? void 0 : _b.find(
1403
+ const facadeEsbuildSveltePlugin = viteConfig.optimizeDeps.esbuildOptions?.plugins?.find(
1479
1404
  (plugin) => plugin.name === facadeEsbuildSveltePluginName
1480
1405
  );
1481
1406
  if (facadeEsbuildSveltePlugin) {
@@ -1669,15 +1594,14 @@ function ensureWatchedFile(watcher, file, root) {
1669
1594
 
1670
1595
  // src/utils/resolve.ts
1671
1596
  import path6 from "path";
1672
- import { builtinModules, createRequire as createRequire4 } from "module";
1673
- function resolveViaPackageJsonSvelte(importee, importer, cache) {
1674
- if (importer && isBareImport(importee) && !isNodeInternal(importee) && !is_common_without_svelte_field(importee)) {
1597
+ import { builtinModules } from "module";
1598
+ async function resolveViaPackageJsonSvelte(importee, importer, cache) {
1599
+ if (importer && isBareImport(importee) && !isNodeInternal(importee) && !isCommonDepWithoutSvelteField(importee)) {
1675
1600
  const cached = cache.getResolvedSvelteField(importee, importer);
1676
1601
  if (cached) {
1677
1602
  return cached;
1678
1603
  }
1679
- const localRequire = createRequire4(importer);
1680
- const pkgData = resolveDependencyData(importee, localRequire);
1604
+ const pkgData = await resolveDependencyData(importee, importer);
1681
1605
  if (pkgData) {
1682
1606
  const { pkg, dir } = pkgData;
1683
1607
  if (pkg.svelte) {
@@ -1783,9 +1707,8 @@ function svelteInspector() {
1783
1707
  apply: "serve",
1784
1708
  enforce: "pre",
1785
1709
  configResolved(config) {
1786
- var _a, _b, _c;
1787
1710
  const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
1788
- 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) {
1711
+ if (vps?.api?.options?.experimental?.inspector) {
1789
1712
  inspectorOptions = {
1790
1713
  ...defaultInspectorOptions,
1791
1714
  ...vps.api.options.experimental.inspector
@@ -1803,7 +1726,7 @@ function svelteInspector() {
1803
1726
  }
1804
1727
  },
1805
1728
  async resolveId(importee, importer, options) {
1806
- if ((options == null ? void 0 : options.ssr) || disabled) {
1729
+ if (options?.ssr || disabled) {
1807
1730
  return;
1808
1731
  }
1809
1732
  if (importee.startsWith("virtual:svelte-inspector-options")) {
@@ -1815,7 +1738,7 @@ function svelteInspector() {
1815
1738
  }
1816
1739
  },
1817
1740
  async load(id, options) {
1818
- if ((options == null ? void 0 : options.ssr) || disabled) {
1741
+ if (options?.ssr || disabled) {
1819
1742
  return;
1820
1743
  }
1821
1744
  if (id === "virtual:svelte-inspector-options") {
@@ -1830,7 +1753,7 @@ function svelteInspector() {
1830
1753
  }
1831
1754
  },
1832
1755
  transform(code, id, options) {
1833
- if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
1756
+ if (options?.ssr || disabled || !appendTo) {
1834
1757
  return;
1835
1758
  }
1836
1759
  if (id.endsWith(appendTo)) {
@@ -1884,7 +1807,7 @@ function svelte(inlineOptions) {
1884
1807
  log.setLevel(config.logLevel);
1885
1808
  }
1886
1809
  options = await preResolveOptions(inlineOptions, config, configEnv);
1887
- const extraViteConfig = buildExtraViteConfig(options, config);
1810
+ const extraViteConfig = await buildExtraViteConfig(options, config);
1888
1811
  log.debug("additional vite config", extraViteConfig);
1889
1812
  return extraViteConfig;
1890
1813
  },
@@ -1910,7 +1833,7 @@ function svelte(inlineOptions) {
1910
1833
  setupWatchers(options, cache, requestParser);
1911
1834
  },
1912
1835
  load(id, opts) {
1913
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1836
+ const ssr = !!opts?.ssr;
1914
1837
  const svelteRequest = requestParser(id, !!ssr);
1915
1838
  if (svelteRequest) {
1916
1839
  const { filename, query } = svelteRequest;
@@ -1928,9 +1851,9 @@ function svelte(inlineOptions) {
1928
1851
  }
1929
1852
  },
1930
1853
  async resolveId(importee, importer, opts) {
1931
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1854
+ const ssr = !!opts?.ssr;
1932
1855
  const svelteRequest = requestParser(importee, ssr);
1933
- if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
1856
+ if (svelteRequest?.query.svelte) {
1934
1857
  if (svelteRequest.query.type === "style") {
1935
1858
  log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
1936
1859
  return svelteRequest.cssId;
@@ -1956,24 +1879,27 @@ function svelte(inlineOptions) {
1956
1879
  }
1957
1880
  return resolvedSvelteSSR;
1958
1881
  }
1959
- try {
1960
- const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
1961
- if (resolved) {
1962
- log.debug(
1963
- `resolveId resolved ${resolved} via package.json svelte field of ${importee}`
1882
+ const scan = !!opts?.scan;
1883
+ const isPrebundled = options.prebundleSvelteLibraries && viteConfig.optimizeDeps?.disabled !== true && viteConfig.optimizeDeps?.disabled !== (options.isBuild ? "build" : "dev") && !isDepExcluded2(importee, viteConfig.optimizeDeps?.exclude ?? []);
1884
+ if (ssr || scan || !isPrebundled) {
1885
+ try {
1886
+ const resolved = await resolveViaPackageJsonSvelte(importee, importer, cache);
1887
+ if (resolved) {
1888
+ log.debug(
1889
+ `resolveId resolved ${resolved} via package.json svelte field of ${importee}`
1890
+ );
1891
+ return resolved;
1892
+ }
1893
+ } catch (e) {
1894
+ log.debug.once(
1895
+ `error trying to resolve ${importee} from ${importer} via package.json svelte field `,
1896
+ e
1964
1897
  );
1965
- return resolved;
1966
1898
  }
1967
- } catch (e) {
1968
- log.debug.once(
1969
- `error trying to resolve ${importee} from ${importer} via package.json svelte field `,
1970
- e
1971
- );
1972
1899
  }
1973
1900
  },
1974
1901
  async transform(code, id, opts) {
1975
- var _a;
1976
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1902
+ const ssr = !!opts?.ssr;
1977
1903
  const svelteRequest = requestParser(id, ssr);
1978
1904
  if (!svelteRequest || svelteRequest.query.svelte) {
1979
1905
  return;
@@ -1987,7 +1913,7 @@ function svelte(inlineOptions) {
1987
1913
  }
1988
1914
  logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
1989
1915
  cache.update(compileData);
1990
- if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
1916
+ if (compileData.dependencies?.length && options.server) {
1991
1917
  compileData.dependencies.forEach((d) => {
1992
1918
  ensureWatchedFile(options.server.watcher, d, options.root);
1993
1919
  });