@sveltejs/vite-plugin-svelte 2.0.4 → 2.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.d.ts CHANGED
@@ -158,11 +158,11 @@ interface ExperimentalOptions {
158
158
  */
159
159
  sendWarningsToBrowser?: boolean;
160
160
  /**
161
- * disable svelte compile statistics
161
+ * disable svelte field resolve warnings
162
162
  *
163
163
  * @default false
164
164
  */
165
- disableCompileStats?: 'dev' | 'build' | boolean;
165
+ disableSvelteResolveWarnings?: boolean;
166
166
  }
167
167
  interface InspectorOptions {
168
168
  /**
package/dist/index.js CHANGED
@@ -8,6 +8,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
8
8
 
9
9
  // src/index.ts
10
10
  import fs8 from "fs";
11
+ import { VERSION as svelteVersion } from "svelte/compiler";
12
+ import {
13
+ version as viteVersion
14
+ } from "vite";
11
15
  import { isDepExcluded as isDepExcluded2 } from "vitefu";
12
16
 
13
17
  // src/utils/log.ts
@@ -55,14 +59,19 @@ function setLevel(level) {
55
59
  _log(loggers.error, `invalid log level: ${level} `);
56
60
  }
57
61
  }
58
- function _log(logger, message, payload) {
62
+ function _log(logger, message, payload, namespace) {
59
63
  if (!logger.enabled) {
60
64
  return;
61
65
  }
62
66
  if (logger.isDebug) {
63
- payload !== void 0 ? logger.log(message, payload) : logger.log(message);
67
+ const log2 = namespace ? logger.log.extend(namespace) : logger.log;
68
+ payload !== void 0 ? log2(message, payload) : log2(message);
64
69
  } else {
65
- logger.log(logger.color(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${prefix}] ${message}`));
70
+ logger.log(
71
+ logger.color(
72
+ `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${prefix}${namespace ? `:${namespace}` : ""}] ${message}`
73
+ )
74
+ );
66
75
  if (payload) {
67
76
  logger.log(payload);
68
77
  }
@@ -72,12 +81,12 @@ function createLogger(level) {
72
81
  const logger = loggers[level];
73
82
  const logFn = _log.bind(null, logger);
74
83
  const logged = /* @__PURE__ */ new Set();
75
- const once = function(message, payload) {
76
- if (logged.has(message)) {
84
+ const once = function(message, payload, namespace) {
85
+ if (!logger.enabled || logged.has(message)) {
77
86
  return;
78
87
  }
79
88
  logged.add(message);
80
- logFn.apply(null, [message, payload]);
89
+ logFn.apply(null, [message, payload, namespace]);
81
90
  };
82
91
  Object.defineProperty(logFn, "enabled", {
83
92
  get() {
@@ -181,6 +190,9 @@ function buildExtendedLogMessage(w) {
181
190
  }
182
191
  return parts.join("");
183
192
  }
193
+ function isDebugNamespaceEnabled(namespace) {
194
+ return debug.enabled(`vite:${prefix}:${namespace}`);
195
+ }
184
196
 
185
197
  // src/utils/error.ts
186
198
  function toRollupError(error, options) {
@@ -425,16 +437,48 @@ function addExtraPreprocessors(options, config) {
425
437
 
426
438
  // src/utils/sourcemaps.ts
427
439
  import path2 from "path";
428
- function mapSourcesToRelative(map, filename) {
429
- if (map?.sources) {
430
- map.sources = map.sources.map((s) => {
431
- if (path2.isAbsolute(s)) {
432
- const relative = path2.relative(filename, s);
433
- return relative === "" ? path2.basename(filename) : relative;
434
- } else {
435
- return s;
436
- }
437
- });
440
+ var IS_WINDOWS = process.platform === "win32";
441
+ function mapToRelative(map, filename) {
442
+ if (!map) {
443
+ return;
444
+ }
445
+ const sourceRoot = map.sourceRoot;
446
+ const dirname2 = path2.dirname(filename);
447
+ const toRelative = (s) => {
448
+ if (!s) {
449
+ return s;
450
+ }
451
+ let sourcePath;
452
+ if (s.startsWith("file:///")) {
453
+ sourcePath = s.slice(IS_WINDOWS ? 8 : 7);
454
+ } else if (sourceRoot) {
455
+ const sep = sourceRoot[sourceRoot.length - 1] === "/" || s[0] === "/" ? "" : "/";
456
+ sourcePath = `${sourceRoot}${sep}${s}`;
457
+ } else {
458
+ sourcePath = s;
459
+ }
460
+ return path2.isAbsolute(sourcePath) ? path2.relative(dirname2, sourcePath) : sourcePath;
461
+ };
462
+ if (map.file) {
463
+ map.file = path2.basename(filename);
464
+ }
465
+ if (map.sources) {
466
+ map.sources = map.sources.map(toRelative);
467
+ }
468
+ if (map.sourceRoot) {
469
+ delete map.sourceRoot;
470
+ }
471
+ }
472
+ function removeLangSuffix(map, suffix) {
473
+ if (!map) {
474
+ return;
475
+ }
476
+ const removeSuffix = (s) => s?.endsWith(suffix) ? s.slice(0, -1 * suffix.length) : s;
477
+ if (map.file) {
478
+ map.file = removeSuffix(map.file);
479
+ }
480
+ if (map.sources) {
481
+ map.sources = map.sources.map(removeSuffix);
438
482
  }
439
483
  }
440
484
 
@@ -505,7 +549,7 @@ var _createCompileSvelte = (makeHot) => {
505
549
  compileOptions.sourcemap = preprocessed.map;
506
550
  }
507
551
  if (typeof preprocessed?.map === "object") {
508
- mapSourcesToRelative(preprocessed?.map, filename);
552
+ mapToRelative(preprocessed?.map, filename);
509
553
  }
510
554
  if (raw && svelteRequest.query.type === "preprocessed") {
511
555
  return { preprocessed: preprocessed ?? { code } };
@@ -534,8 +578,8 @@ var _createCompileSvelte = (makeHot) => {
534
578
  if (endStat) {
535
579
  endStat();
536
580
  }
537
- mapSourcesToRelative(compiled.js?.map, filename);
538
- mapSourcesToRelative(compiled.css?.map, filename);
581
+ mapToRelative(compiled.js?.map, filename);
582
+ mapToRelative(compiled.css?.map, filename);
539
583
  if (!raw) {
540
584
  const hasCss = compiled.css?.code?.trim().length > 0;
541
585
  if (emitCss && hasCss) {
@@ -591,7 +635,7 @@ import { createFilter } from "vite";
591
635
  import { normalizePath } from "vite";
592
636
  import * as fs from "fs";
593
637
  var VITE_FS_PREFIX = "/@fs/";
594
- var IS_WINDOWS = process.platform === "win32";
638
+ var IS_WINDOWS2 = process.platform === "win32";
595
639
  var SUPPORTED_COMPILER_OPTIONS = [
596
640
  "generate",
597
641
  "dev",
@@ -636,7 +680,7 @@ function createVirtualImportId(filename, root, type) {
636
680
  if (existsInRoot(filename, root)) {
637
681
  filename = root + filename;
638
682
  } else if (filename.startsWith(VITE_FS_PREFIX)) {
639
- filename = IS_WINDOWS ? filename.slice(VITE_FS_PREFIX.length) : filename.slice(VITE_FS_PREFIX.length - 1);
683
+ filename = IS_WINDOWS2 ? filename.slice(VITE_FS_PREFIX.length) : filename.slice(VITE_FS_PREFIX.length - 1);
640
684
  }
641
685
  return `${filename}?${parts.join("&")}`;
642
686
  }
@@ -814,6 +858,7 @@ var SVELTE_HMR_IMPORTS = [
814
858
  "svelte-hmr"
815
859
  ];
816
860
  var SVELTE_EXPORT_CONDITIONS = ["svelte"];
861
+ var FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE = "https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#conflicts-in-svelte-resolve";
817
862
 
818
863
  // src/utils/options.ts
819
864
  import path5 from "path";
@@ -970,9 +1015,6 @@ function isCommonDepWithoutSvelteField(dependency) {
970
1015
  }
971
1016
 
972
1017
  // src/utils/vite-plugin-svelte-stats.ts
973
- import { findClosestPkgJsonPath } from "vitefu";
974
- import { readFileSync as readFileSync2 } from "fs";
975
- import { dirname } from "path";
976
1018
  import { performance } from "perf_hooks";
977
1019
  import { normalizePath as normalizePath2 } from "vite";
978
1020
  var defaultCollectionOptions = {
@@ -1014,24 +1056,10 @@ function formatPackageStats(pkgStats) {
1014
1056
  ).join("\n");
1015
1057
  return table;
1016
1058
  }
1017
- async function getClosestNamedPackage(file) {
1018
- let name = "$unknown";
1019
- let path10 = await findClosestPkgJsonPath(file, (pkgPath) => {
1020
- const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
1021
- if (pkg.name != null) {
1022
- name = pkg.name;
1023
- return true;
1024
- }
1025
- return false;
1026
- });
1027
- path10 = normalizePath2(dirname(path10 ?? file)) + "/";
1028
- return { name, path: path10 };
1029
- }
1030
1059
  var VitePluginSvelteStats = class {
1031
- constructor() {
1032
- // package directory -> package name
1033
- this._packages = [];
1060
+ constructor(cache) {
1034
1061
  this._collections = [];
1062
+ this._cache = cache;
1035
1063
  }
1036
1064
  startCollection(name, opts) {
1037
1065
  const options = {
@@ -1061,7 +1089,7 @@ var VitePluginSvelteStats = class {
1061
1089
  stats.push(stat);
1062
1090
  if (!hasLoggedProgress && options.logInProgress(collection, now)) {
1063
1091
  hasLoggedProgress = true;
1064
- log.info(`${name} in progress ...`);
1092
+ log.debug(`${name} in progress ...`, void 0, "stats");
1065
1093
  }
1066
1094
  };
1067
1095
  },
@@ -1083,7 +1111,12 @@ var VitePluginSvelteStats = class {
1083
1111
  const logResult = collection.options.logResult(collection);
1084
1112
  if (logResult) {
1085
1113
  await this._aggregateStatsResult(collection);
1086
- log.info(`${collection.name} done.`, formatPackageStats(collection.packageStats));
1114
+ log.debug(
1115
+ `${collection.name} done.
1116
+ ${formatPackageStats(collection.packageStats)}`,
1117
+ void 0,
1118
+ "stats"
1119
+ );
1087
1120
  }
1088
1121
  const index = this._collections.indexOf(collection);
1089
1122
  this._collections.splice(index, 1);
@@ -1098,18 +1131,14 @@ var VitePluginSvelteStats = class {
1098
1131
  collection.finish = () => {
1099
1132
  };
1100
1133
  } catch (e) {
1101
- log.debug.once(`failed to finish stats for ${collection.name}`, e);
1134
+ log.debug.once(`failed to finish stats for ${collection.name}
1135
+ `, e, "stats");
1102
1136
  }
1103
1137
  }
1104
1138
  async _aggregateStatsResult(collection) {
1105
1139
  const stats = collection.stats;
1106
1140
  for (const stat of stats) {
1107
- let pkg = this._packages.find((p) => stat.file.startsWith(p.path));
1108
- if (!pkg) {
1109
- pkg = await getClosestNamedPackage(stat.file);
1110
- this._packages.push(pkg);
1111
- }
1112
- stat.pkg = pkg.name;
1141
+ stat.pkg = (await this._cache.getPackageInfo(stat.file)).name;
1113
1142
  }
1114
1143
  const grouped = {};
1115
1144
  stats.forEach((stat) => {
@@ -1252,7 +1281,7 @@ function mergeConfigs(...configs) {
1252
1281
  }
1253
1282
  return result;
1254
1283
  }
1255
- function resolveOptions(preResolveOptions2, viteConfig) {
1284
+ function resolveOptions(preResolveOptions2, viteConfig, cache) {
1256
1285
  const css = preResolveOptions2.emitCss ? "external" : "injected";
1257
1286
  const defaultOptions = {
1258
1287
  hot: viteConfig.isProduction ? false : {
@@ -1275,11 +1304,8 @@ function resolveOptions(preResolveOptions2, viteConfig) {
1275
1304
  addExtraPreprocessors(merged, viteConfig);
1276
1305
  enforceOptionsForHmr(merged);
1277
1306
  enforceOptionsForProduction(merged);
1278
- const isLogLevelInfo = [void 0, "info"].includes(viteConfig.logLevel);
1279
- const disableCompileStats = merged.experimental?.disableCompileStats;
1280
- const statsEnabled = disableCompileStats !== true && disableCompileStats !== (merged.isBuild ? "build" : "dev");
1281
- if (statsEnabled && isLogLevelInfo) {
1282
- merged.stats = new VitePluginSvelteStats();
1307
+ if (log.debug.enabled && isDebugNamespaceEnabled("stats")) {
1308
+ merged.stats = new VitePluginSvelteStats(cache);
1283
1309
  }
1284
1310
  return merged;
1285
1311
  }
@@ -1649,6 +1675,7 @@ function ensureWatchedFile(watcher, file, root) {
1649
1675
  // src/utils/resolve.ts
1650
1676
  import path7 from "path";
1651
1677
  import { builtinModules } from "module";
1678
+ import { normalizePath as normalizePath4 } from "vite";
1652
1679
  async function resolveViaPackageJsonSvelte(importee, importer, cache) {
1653
1680
  if (importer && isBareImport(importee) && !isNodeInternal(importee) && !isCommonDepWithoutSvelteField(importee)) {
1654
1681
  const cached = cache.getResolvedSvelteField(importee, importer);
@@ -1659,7 +1686,7 @@ async function resolveViaPackageJsonSvelte(importee, importer, cache) {
1659
1686
  if (pkgData) {
1660
1687
  const { pkg, dir } = pkgData;
1661
1688
  if (pkg.svelte) {
1662
- const result = path7.resolve(dir, pkg.svelte);
1689
+ const result = normalizePath4(path7.resolve(dir, pkg.svelte));
1663
1690
  cache.setResolvedSvelteField(importee, importer, result);
1664
1691
  return result;
1665
1692
  }
@@ -1719,19 +1746,19 @@ function generateSvelteMetadata(options) {
1719
1746
  }
1720
1747
 
1721
1748
  // src/ui/inspector/plugin.ts
1722
- import { normalizePath as normalizePath4 } from "vite";
1749
+ import { normalizePath as normalizePath5 } from "vite";
1723
1750
  import path9 from "path";
1724
1751
  import { fileURLToPath } from "url";
1725
1752
  import fs6 from "fs";
1726
1753
 
1727
1754
  // src/ui/inspector/utils.ts
1728
1755
  var FS_PREFIX = `/@fs/`;
1729
- var IS_WINDOWS2 = process.platform === "win32";
1756
+ var IS_WINDOWS3 = process.platform === "win32";
1730
1757
  var queryRE = /\?.*$/s;
1731
1758
  var hashRE = /#.*$/s;
1732
1759
  function idToFile(id) {
1733
1760
  if (id.startsWith(FS_PREFIX)) {
1734
- id = id = id.slice(IS_WINDOWS2 ? FS_PREFIX.length : FS_PREFIX.length - 1);
1761
+ id = id = id.slice(IS_WINDOWS3 ? FS_PREFIX.length : FS_PREFIX.length - 1);
1735
1762
  }
1736
1763
  return id.replace(hashRE, "").replace(queryRE, "");
1737
1764
  }
@@ -1747,7 +1774,7 @@ var defaultInspectorOptions = {
1747
1774
  customStyles: true
1748
1775
  };
1749
1776
  function getInspectorPath() {
1750
- const pluginPath = normalizePath4(path9.dirname(fileURLToPath(import.meta.url)));
1777
+ const pluginPath = normalizePath5(path9.dirname(fileURLToPath(import.meta.url)));
1751
1778
  return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
1752
1779
  }
1753
1780
  function svelteInspector() {
@@ -1837,6 +1864,10 @@ import 'virtual:svelte-inspector-path:load-inspector.js'` };
1837
1864
  }
1838
1865
 
1839
1866
  // src/utils/vite-plugin-svelte-cache.ts
1867
+ import { readFileSync as readFileSync2 } from "fs";
1868
+ import { dirname } from "path";
1869
+ import { findClosestPkgJsonPath } from "vitefu";
1870
+ import { normalizePath as normalizePath6 } from "vite";
1840
1871
  var VitePluginSvelteCache = class {
1841
1872
  constructor() {
1842
1873
  this._css = /* @__PURE__ */ new Map();
@@ -1845,6 +1876,7 @@ var VitePluginSvelteCache = class {
1845
1876
  this._dependants = /* @__PURE__ */ new Map();
1846
1877
  this._resolvedSvelteFields = /* @__PURE__ */ new Map();
1847
1878
  this._errors = /* @__PURE__ */ new Map();
1879
+ this._packageInfos = [];
1848
1880
  }
1849
1881
  update(compileData) {
1850
1882
  this._errors.delete(compileData.normalizedFilename);
@@ -1930,6 +1962,9 @@ var VitePluginSvelteCache = class {
1930
1962
  getResolvedSvelteField(name, importer) {
1931
1963
  return this._resolvedSvelteFields.get(this._getResolvedSvelteFieldKey(name, importer));
1932
1964
  }
1965
+ hasResolvedSvelteField(name, importer) {
1966
+ return this._resolvedSvelteFields.has(this._getResolvedSvelteFieldKey(name, importer));
1967
+ }
1933
1968
  setResolvedSvelteField(importee, importer = void 0, resolvedSvelte) {
1934
1969
  this._resolvedSvelteFields.set(
1935
1970
  this._getResolvedSvelteFieldKey(importee, importer),
@@ -1939,7 +1974,37 @@ var VitePluginSvelteCache = class {
1939
1974
  _getResolvedSvelteFieldKey(importee, importer) {
1940
1975
  return importer ? `${importer} > ${importee}` : importee;
1941
1976
  }
1977
+ async getPackageInfo(file) {
1978
+ let info = this._packageInfos.find((pi) => file.startsWith(pi.path));
1979
+ if (!info) {
1980
+ info = await findPackageInfo(file);
1981
+ this._packageInfos.push(info);
1982
+ }
1983
+ return info;
1984
+ }
1942
1985
  };
1986
+ async function findPackageInfo(file) {
1987
+ const info = {
1988
+ name: "$unknown",
1989
+ version: "0.0.0-unknown",
1990
+ path: "$unknown"
1991
+ };
1992
+ let path10 = await findClosestPkgJsonPath(file, (pkgPath) => {
1993
+ const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
1994
+ if (pkg.name != null) {
1995
+ info.name = pkg.name;
1996
+ if (pkg.version != null) {
1997
+ info.version = pkg.version;
1998
+ }
1999
+ info.svelte = pkg.svelte;
2000
+ return true;
2001
+ }
2002
+ return false;
2003
+ });
2004
+ path10 = normalizePath6(dirname(path10 ?? file)) + "/";
2005
+ info.path = path10;
2006
+ return info;
2007
+ }
1943
2008
 
1944
2009
  // src/utils/load-raw.ts
1945
2010
  import fs7 from "fs";
@@ -2037,6 +2102,7 @@ function toRawExports(object) {
2037
2102
  import { preprocessCSS, resolveConfig, transformWithEsbuild } from "vite";
2038
2103
  var supportedStyleLangs = ["css", "less", "sass", "scss", "styl", "stylus", "postcss", "sss"];
2039
2104
  var supportedScriptLangs = ["ts"];
2105
+ var lang_sep = ".vite-preprocess.";
2040
2106
  function vitePreprocess(opts) {
2041
2107
  const preprocessor = {};
2042
2108
  if (opts?.script !== false) {
@@ -2065,7 +2131,7 @@ function viteScript() {
2065
2131
  }
2066
2132
  }
2067
2133
  });
2068
- mapSourcesToRelative(map, filename);
2134
+ mapToRelative(map, filename);
2069
2135
  return {
2070
2136
  code,
2071
2137
  map
@@ -2093,12 +2159,16 @@ function viteStyle(config = {}) {
2093
2159
  }
2094
2160
  transform = getCssTransformFn(resolvedConfig);
2095
2161
  }
2096
- const moduleId = `${filename}.${lang}`;
2097
- const { code, map } = await transform(content, moduleId);
2098
- mapSourcesToRelative(map, moduleId);
2162
+ const suffix = `${lang_sep}${lang}`;
2163
+ const moduleId = `${filename}${suffix}`;
2164
+ const { code, map, deps } = await transform(content, moduleId);
2165
+ removeLangSuffix(map, suffix);
2166
+ mapToRelative(map, filename);
2167
+ const dependencies = deps ? Array.from(deps).filter((d) => !d.endsWith(suffix)) : void 0;
2099
2168
  return {
2100
2169
  code,
2101
- map: map ?? void 0
2170
+ map: map ?? void 0,
2171
+ dependencies
2102
2172
  };
2103
2173
  };
2104
2174
  style.__resolvedConfig = null;
@@ -2114,6 +2184,8 @@ function isResolvedConfig(config) {
2114
2184
  }
2115
2185
 
2116
2186
  // src/index.ts
2187
+ var isVite4_0 = viteVersion.startsWith("4.0");
2188
+ var isSvelte3 = svelteVersion.startsWith("3");
2117
2189
  function svelte(inlineOptions) {
2118
2190
  if (process.env.DEBUG != null) {
2119
2191
  log.setLevel("debug");
@@ -2125,6 +2197,7 @@ function svelte(inlineOptions) {
2125
2197
  let viteConfig;
2126
2198
  let compileSvelte2;
2127
2199
  let resolvedSvelteSSR;
2200
+ let packagesWithResolveWarnings;
2128
2201
  const api = {};
2129
2202
  const plugins = [
2130
2203
  {
@@ -2144,7 +2217,7 @@ function svelte(inlineOptions) {
2144
2217
  return extraViteConfig;
2145
2218
  },
2146
2219
  async configResolved(config) {
2147
- options = resolveOptions(options, config);
2220
+ options = resolveOptions(options, config, cache);
2148
2221
  patchResolvedViteConfig(config, options);
2149
2222
  requestParser = buildIdParser(options);
2150
2223
  compileSvelte2 = createCompileSvelte(options);
@@ -2153,6 +2226,7 @@ function svelte(inlineOptions) {
2153
2226
  log.debug("resolved options", options);
2154
2227
  },
2155
2228
  async buildStart() {
2229
+ packagesWithResolveWarnings = /* @__PURE__ */ new Set();
2156
2230
  if (!options.prebundleSvelteLibraries)
2157
2231
  return;
2158
2232
  const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
@@ -2195,7 +2269,7 @@ function svelte(inlineOptions) {
2195
2269
  return svelteRequest.cssId;
2196
2270
  }
2197
2271
  }
2198
- if (ssr && importee === "svelte") {
2272
+ if (isVite4_0 && isSvelte3 && ssr && importee === "svelte") {
2199
2273
  if (!resolvedSvelteSSR) {
2200
2274
  resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then(
2201
2275
  (svelteSSR) => {
@@ -2217,13 +2291,31 @@ function svelte(inlineOptions) {
2217
2291
  const isPrebundled = options.prebundleSvelteLibraries && viteConfig.optimizeDeps?.disabled !== true && viteConfig.optimizeDeps?.disabled !== (options.isBuild ? "build" : "dev") && !isDepExcluded2(importee, viteConfig.optimizeDeps?.exclude ?? []);
2218
2292
  if (ssr || scan || !isPrebundled) {
2219
2293
  try {
2294
+ const isFirstResolve = !cache.hasResolvedSvelteField(importee, importer);
2220
2295
  const resolved = await resolveViaPackageJsonSvelte(importee, importer, cache);
2221
- if (resolved) {
2222
- log.debug(
2223
- `resolveId resolved ${resolved} via package.json svelte field of ${importee}`
2296
+ if (isFirstResolve && resolved) {
2297
+ const packageInfo = await cache.getPackageInfo(resolved);
2298
+ const packageVersion = `${packageInfo.name}@${packageInfo.version}`;
2299
+ log.debug.once(
2300
+ `resolveId resolved ${importee} to ${resolved} via package.json svelte field of ${packageVersion}`
2224
2301
  );
2225
- return resolved;
2302
+ try {
2303
+ const viteResolved = (await this.resolve(importee, importer, { ...opts, skipSelf: true }))?.id;
2304
+ if (resolved !== viteResolved) {
2305
+ packagesWithResolveWarnings.add(packageVersion);
2306
+ log.debug.enabled && log.debug.once(
2307
+ `resolve difference for ${packageVersion} ${importee} - svelte: "${resolved}", vite: "${viteResolved}"`
2308
+ );
2309
+ }
2310
+ } catch (e) {
2311
+ packagesWithResolveWarnings.add(packageVersion);
2312
+ log.debug.enabled && log.debug.once(
2313
+ `resolve error for ${packageVersion} ${importee} - svelte: "${resolved}", vite: ERROR`,
2314
+ e
2315
+ );
2316
+ }
2226
2317
  }
2318
+ return resolved;
2227
2319
  } catch (e) {
2228
2320
  log.debug.once(
2229
2321
  `error trying to resolve ${importee} from ${importer} via package.json svelte field `,
@@ -2273,6 +2365,17 @@ function svelte(inlineOptions) {
2273
2365
  },
2274
2366
  async buildEnd() {
2275
2367
  await options.stats?.finishAll();
2368
+ if (!options.experimental?.disableSvelteResolveWarnings && packagesWithResolveWarnings?.size > 0) {
2369
+ log.warn(
2370
+ `WARNING: The following packages use a svelte resolve configuration in package.json that has conflicting results and is going to cause problems future.
2371
+
2372
+ ${[
2373
+ ...packagesWithResolveWarnings
2374
+ ].join("\n")}
2375
+
2376
+ Please see ${FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE} for details.`
2377
+ );
2378
+ }
2276
2379
  }
2277
2380
  }
2278
2381
  ];