@sveltejs/vite-plugin-svelte 1.3.0 → 1.3.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
@@ -516,7 +516,7 @@ function buildIdParser(options) {
516
516
  }
517
517
 
518
518
  // src/utils/options.ts
519
- var import_vite3 = require("vite");
519
+ var import_vite4 = require("vite");
520
520
 
521
521
  // src/utils/load-svelte-config.ts
522
522
  var import_module = require("module");
@@ -627,7 +627,7 @@ var SVELTE_HMR_IMPORTS = [
627
627
  var SVELTE_EXPORT_CONDITIONS = ["svelte"];
628
628
 
629
629
  // src/utils/options.ts
630
- var import_path4 = __toESM(require("path"), 1);
630
+ var import_path5 = __toESM(require("path"), 1);
631
631
 
632
632
  // src/utils/esbuild.ts
633
633
  var import_fs2 = require("fs");
@@ -1117,7 +1117,9 @@ function isCommonDepWithoutSvelteField(dependency) {
1117
1117
  // src/utils/vite-plugin-svelte-stats.ts
1118
1118
  var import_vitefu2 = require("vitefu");
1119
1119
  var import_fs3 = require("fs");
1120
+ var import_path4 = require("path");
1120
1121
  var import_perf_hooks = require("perf_hooks");
1122
+ var import_vite3 = require("vite");
1121
1123
  var defaultCollectionOptions = {
1122
1124
  logInProgress: (c, now) => now - c.collectionStart > 500 && c.stats.length > 1,
1123
1125
  logResult: () => true
@@ -1155,6 +1157,19 @@ function formatPackageStats(pkgStats) {
1155
1157
  ).join("\n");
1156
1158
  return table;
1157
1159
  }
1160
+ async function getClosestNamedPackage(file) {
1161
+ let name = "$unknown";
1162
+ let path9 = await (0, import_vitefu2.findClosestPkgJsonPath)(file, (pkgPath) => {
1163
+ const pkg = JSON.parse((0, import_fs3.readFileSync)(pkgPath, "utf-8"));
1164
+ if (pkg.name != null) {
1165
+ name = pkg.name;
1166
+ return true;
1167
+ }
1168
+ return false;
1169
+ });
1170
+ path9 = (0, import_vite3.normalizePath)((0, import_path4.dirname)(path9 ?? file)) + "/";
1171
+ return { name, path: path9 };
1172
+ }
1158
1173
  var VitePluginSvelteStats = class {
1159
1174
  constructor() {
1160
1175
  this._packages = [];
@@ -1179,6 +1194,7 @@ var VitePluginSvelteStats = class {
1179
1194
  if (collection.finished) {
1180
1195
  throw new Error("called after finish() has been used");
1181
1196
  }
1197
+ file = (0, import_vite3.normalizePath)(file);
1182
1198
  const start = import_perf_hooks.performance.now();
1183
1199
  const stat = { file, start, end: start };
1184
1200
  return () => {
@@ -1202,50 +1218,40 @@ var VitePluginSvelteStats = class {
1202
1218
  await Promise.all(this._collections.map((c) => c.finish()));
1203
1219
  }
1204
1220
  async _finish(collection) {
1205
- collection.finished = true;
1206
- const now = import_perf_hooks.performance.now();
1207
- collection.duration = now - collection.collectionStart;
1208
- const logResult = collection.options.logResult(collection);
1209
- if (logResult) {
1210
- await this._aggregateStatsResult(collection);
1211
- log.info(`${collection.name} done.`, formatPackageStats(collection.packageStats));
1212
- }
1213
- const index = this._collections.indexOf(collection);
1214
- this._collections.splice(index, 1);
1215
- collection.stats.length = 0;
1216
- collection.stats = [];
1217
- if (collection.packageStats) {
1218
- collection.packageStats.length = 0;
1219
- collection.packageStats = [];
1221
+ try {
1222
+ collection.finished = true;
1223
+ const now = import_perf_hooks.performance.now();
1224
+ collection.duration = now - collection.collectionStart;
1225
+ const logResult = collection.options.logResult(collection);
1226
+ if (logResult) {
1227
+ await this._aggregateStatsResult(collection);
1228
+ log.info(`${collection.name} done.`, formatPackageStats(collection.packageStats));
1229
+ }
1230
+ const index = this._collections.indexOf(collection);
1231
+ this._collections.splice(index, 1);
1232
+ collection.stats.length = 0;
1233
+ collection.stats = [];
1234
+ if (collection.packageStats) {
1235
+ collection.packageStats.length = 0;
1236
+ collection.packageStats = [];
1237
+ }
1238
+ collection.start = () => () => {
1239
+ };
1240
+ collection.finish = () => {
1241
+ };
1242
+ } catch (e) {
1243
+ log.debug.once(`failed to finish stats for ${collection.name}`, e);
1220
1244
  }
1221
- collection.start = () => () => {
1222
- };
1223
- collection.finish = () => {
1224
- };
1225
1245
  }
1226
1246
  async _aggregateStatsResult(collection) {
1227
1247
  const stats = collection.stats;
1228
1248
  for (const stat of stats) {
1229
1249
  let pkg = this._packages.find((p) => stat.file.startsWith(p.path));
1230
1250
  if (!pkg) {
1231
- let pkgPath = await (0, import_vitefu2.findClosestPkgJsonPath)(stat.file);
1232
- if (pkgPath) {
1233
- let path9 = pkgPath?.replace(/package.json$/, "");
1234
- let name = JSON.parse((0, import_fs3.readFileSync)(pkgPath, "utf-8")).name;
1235
- if (!name) {
1236
- pkgPath = await (0, import_vitefu2.findClosestPkgJsonPath)(path9);
1237
- if (pkgPath) {
1238
- path9 = pkgPath?.replace(/package.json$/, "");
1239
- name = JSON.parse((0, import_fs3.readFileSync)(pkgPath, "utf-8")).name;
1240
- }
1241
- }
1242
- if (path9 && name) {
1243
- pkg = { path: path9, name };
1244
- this._packages.push(pkg);
1245
- }
1246
- }
1251
+ pkg = await getClosestNamedPackage(stat.file);
1252
+ this._packages.push(pkg);
1247
1253
  }
1248
- stat.pkg = pkg?.name ?? "$unknown";
1254
+ stat.pkg = pkg.name;
1249
1255
  }
1250
1256
  const grouped = {};
1251
1257
  stats.forEach((stat) => {
@@ -1506,7 +1512,7 @@ function handleDeprecatedOptions(options) {
1506
1512
  }
1507
1513
  }
1508
1514
  function resolveViteRoot(viteConfig) {
1509
- return (0, import_vite3.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
1515
+ return (0, import_vite4.normalizePath)(viteConfig.root ? import_path5.default.resolve(viteConfig.root) : process.cwd());
1510
1516
  }
1511
1517
  async function buildExtraViteConfig(options, config) {
1512
1518
  const extraViteConfig = {
@@ -1673,7 +1679,7 @@ function patchResolvedViteConfig(viteConfig, options) {
1673
1679
 
1674
1680
  // src/utils/watch.ts
1675
1681
  var import_fs4 = __toESM(require("fs"), 1);
1676
- var import_path5 = __toESM(require("path"), 1);
1682
+ var import_path6 = __toESM(require("path"), 1);
1677
1683
  function setupWatchers(options, cache, requestParser) {
1678
1684
  const { server, configFile: svelteConfigFile } = options;
1679
1685
  if (!server) {
@@ -1720,7 +1726,7 @@ function setupWatchers(options, cache, requestParser) {
1720
1726
  unlink: [removeUnlinkedFromCache, emitChangeEventOnDependants]
1721
1727
  };
1722
1728
  if (svelteConfigFile !== false) {
1723
- const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path5.default.join(root, cfg));
1729
+ const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path6.default.join(root, cfg));
1724
1730
  const restartOnConfigAdd = (filename) => {
1725
1731
  if (possibleSvelteConfigs.includes(filename)) {
1726
1732
  triggerViteRestart(filename);
@@ -1746,12 +1752,12 @@ function setupWatchers(options, cache, requestParser) {
1746
1752
  }
1747
1753
  function ensureWatchedFile(watcher, file, root) {
1748
1754
  if (file && !file.startsWith(root + "/") && !file.includes("\0") && import_fs4.default.existsSync(file)) {
1749
- watcher.add(import_path5.default.resolve(file));
1755
+ watcher.add(import_path6.default.resolve(file));
1750
1756
  }
1751
1757
  }
1752
1758
 
1753
1759
  // src/utils/resolve.ts
1754
- var import_path6 = __toESM(require("path"), 1);
1760
+ var import_path7 = __toESM(require("path"), 1);
1755
1761
  var import_module2 = require("module");
1756
1762
  async function resolveViaPackageJsonSvelte(importee, importer, cache) {
1757
1763
  if (importer && isBareImport(importee) && !isNodeInternal(importee) && !isCommonDepWithoutSvelteField(importee)) {
@@ -1763,7 +1769,7 @@ async function resolveViaPackageJsonSvelte(importee, importer, cache) {
1763
1769
  if (pkgData) {
1764
1770
  const { pkg, dir } = pkgData;
1765
1771
  if (pkg.svelte) {
1766
- const result = import_path6.default.resolve(dir, pkg.svelte);
1772
+ const result = import_path7.default.resolve(dir, pkg.svelte);
1767
1773
  cache.setResolvedSvelteField(importee, importer, result);
1768
1774
  return result;
1769
1775
  }
@@ -1774,7 +1780,7 @@ function isNodeInternal(importee) {
1774
1780
  return importee.startsWith("node:") || import_module2.builtinModules.includes(importee);
1775
1781
  }
1776
1782
  function isBareImport(importee) {
1777
- if (!importee || importee[0] === "." || importee[0] === "\0" || importee.includes(":") || import_path6.default.isAbsolute(importee)) {
1783
+ if (!importee || importee[0] === "." || importee[0] === "\0" || importee.includes(":") || import_path7.default.isAbsolute(importee)) {
1778
1784
  return false;
1779
1785
  }
1780
1786
  const parts = importee.split("/");
@@ -1790,7 +1796,7 @@ function isBareImport(importee) {
1790
1796
 
1791
1797
  // src/utils/optimizer.ts
1792
1798
  var import_fs5 = require("fs");
1793
- var import_path7 = __toESM(require("path"), 1);
1799
+ var import_path8 = __toESM(require("path"), 1);
1794
1800
  var PREBUNDLE_SENSITIVE_OPTIONS = [
1795
1801
  "compilerOptions",
1796
1802
  "configFile",
@@ -1801,7 +1807,7 @@ var PREBUNDLE_SENSITIVE_OPTIONS = [
1801
1807
  ];
1802
1808
  async function saveSvelteMetadata(cacheDir, options) {
1803
1809
  const svelteMetadata = generateSvelteMetadata(options);
1804
- const svelteMetadataPath = import_path7.default.resolve(cacheDir, "_svelte_metadata.json");
1810
+ const svelteMetadataPath = import_path8.default.resolve(cacheDir, "_svelte_metadata.json");
1805
1811
  const currentSvelteMetadata = JSON.stringify(svelteMetadata, (_, value) => {
1806
1812
  return typeof value === "function" ? value.toString() : value;
1807
1813
  });
@@ -1823,8 +1829,8 @@ function generateSvelteMetadata(options) {
1823
1829
  }
1824
1830
 
1825
1831
  // src/ui/inspector/plugin.ts
1826
- var import_vite4 = require("vite");
1827
- var import_path8 = __toESM(require("path"), 1);
1832
+ var import_vite5 = require("vite");
1833
+ var import_path9 = __toESM(require("path"), 1);
1828
1834
  var import_url2 = require("url");
1829
1835
  var import_fs6 = __toESM(require("fs"), 1);
1830
1836
 
@@ -1851,7 +1857,7 @@ var defaultInspectorOptions = {
1851
1857
  customStyles: true
1852
1858
  };
1853
1859
  function getInspectorPath() {
1854
- const pluginPath = (0, import_vite4.normalizePath)(import_path8.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
1860
+ const pluginPath = (0, import_vite5.normalizePath)(import_path9.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
1855
1861
  return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
1856
1862
  }
1857
1863
  function svelteInspector() {
@@ -1877,7 +1883,7 @@ function svelteInspector() {
1877
1883
  disabled = true;
1878
1884
  } else {
1879
1885
  if (vps.api.options.kit && !inspectorOptions.appendTo) {
1880
- const out_dir = import_path8.default.basename(vps.api.options.kit.outDir || ".svelte-kit");
1886
+ const out_dir = import_path9.default.basename(vps.api.options.kit.outDir || ".svelte-kit");
1881
1887
  inspectorOptions.appendTo = `${out_dir}/generated/root.svelte`;
1882
1888
  }
1883
1889
  appendTo = inspectorOptions.appendTo;