@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 +57 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -40
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/utils/vite-plugin-svelte-stats.ts +50 -39
package/dist/index.js
CHANGED
|
@@ -487,7 +487,7 @@ function buildIdParser(options) {
|
|
|
487
487
|
}
|
|
488
488
|
|
|
489
489
|
// src/utils/options.ts
|
|
490
|
-
import { normalizePath as
|
|
490
|
+
import { normalizePath as normalizePath3 } from "vite";
|
|
491
491
|
|
|
492
492
|
// src/utils/load-svelte-config.ts
|
|
493
493
|
import { createRequire } from "module";
|
|
@@ -1094,7 +1094,9 @@ function isCommonDepWithoutSvelteField(dependency) {
|
|
|
1094
1094
|
// src/utils/vite-plugin-svelte-stats.ts
|
|
1095
1095
|
import { findClosestPkgJsonPath } from "vitefu";
|
|
1096
1096
|
import { readFileSync as readFileSync2 } from "fs";
|
|
1097
|
+
import { dirname } from "path";
|
|
1097
1098
|
import { performance } from "perf_hooks";
|
|
1099
|
+
import { normalizePath as normalizePath2 } from "vite";
|
|
1098
1100
|
var defaultCollectionOptions = {
|
|
1099
1101
|
logInProgress: (c, now) => now - c.collectionStart > 500 && c.stats.length > 1,
|
|
1100
1102
|
logResult: () => true
|
|
@@ -1132,6 +1134,19 @@ function formatPackageStats(pkgStats) {
|
|
|
1132
1134
|
).join("\n");
|
|
1133
1135
|
return table;
|
|
1134
1136
|
}
|
|
1137
|
+
async function getClosestNamedPackage(file) {
|
|
1138
|
+
let name = "$unknown";
|
|
1139
|
+
let path9 = await findClosestPkgJsonPath(file, (pkgPath) => {
|
|
1140
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
1141
|
+
if (pkg.name != null) {
|
|
1142
|
+
name = pkg.name;
|
|
1143
|
+
return true;
|
|
1144
|
+
}
|
|
1145
|
+
return false;
|
|
1146
|
+
});
|
|
1147
|
+
path9 = normalizePath2(dirname(path9 ?? file)) + "/";
|
|
1148
|
+
return { name, path: path9 };
|
|
1149
|
+
}
|
|
1135
1150
|
var VitePluginSvelteStats = class {
|
|
1136
1151
|
constructor() {
|
|
1137
1152
|
this._packages = [];
|
|
@@ -1156,6 +1171,7 @@ var VitePluginSvelteStats = class {
|
|
|
1156
1171
|
if (collection.finished) {
|
|
1157
1172
|
throw new Error("called after finish() has been used");
|
|
1158
1173
|
}
|
|
1174
|
+
file = normalizePath2(file);
|
|
1159
1175
|
const start = performance.now();
|
|
1160
1176
|
const stat = { file, start, end: start };
|
|
1161
1177
|
return () => {
|
|
@@ -1179,50 +1195,40 @@ var VitePluginSvelteStats = class {
|
|
|
1179
1195
|
await Promise.all(this._collections.map((c) => c.finish()));
|
|
1180
1196
|
}
|
|
1181
1197
|
async _finish(collection) {
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
collection.packageStats
|
|
1196
|
-
|
|
1198
|
+
try {
|
|
1199
|
+
collection.finished = true;
|
|
1200
|
+
const now = performance.now();
|
|
1201
|
+
collection.duration = now - collection.collectionStart;
|
|
1202
|
+
const logResult = collection.options.logResult(collection);
|
|
1203
|
+
if (logResult) {
|
|
1204
|
+
await this._aggregateStatsResult(collection);
|
|
1205
|
+
log.info(`${collection.name} done.`, formatPackageStats(collection.packageStats));
|
|
1206
|
+
}
|
|
1207
|
+
const index = this._collections.indexOf(collection);
|
|
1208
|
+
this._collections.splice(index, 1);
|
|
1209
|
+
collection.stats.length = 0;
|
|
1210
|
+
collection.stats = [];
|
|
1211
|
+
if (collection.packageStats) {
|
|
1212
|
+
collection.packageStats.length = 0;
|
|
1213
|
+
collection.packageStats = [];
|
|
1214
|
+
}
|
|
1215
|
+
collection.start = () => () => {
|
|
1216
|
+
};
|
|
1217
|
+
collection.finish = () => {
|
|
1218
|
+
};
|
|
1219
|
+
} catch (e) {
|
|
1220
|
+
log.debug.once(`failed to finish stats for ${collection.name}`, e);
|
|
1197
1221
|
}
|
|
1198
|
-
collection.start = () => () => {
|
|
1199
|
-
};
|
|
1200
|
-
collection.finish = () => {
|
|
1201
|
-
};
|
|
1202
1222
|
}
|
|
1203
1223
|
async _aggregateStatsResult(collection) {
|
|
1204
1224
|
const stats = collection.stats;
|
|
1205
1225
|
for (const stat of stats) {
|
|
1206
1226
|
let pkg = this._packages.find((p) => stat.file.startsWith(p.path));
|
|
1207
1227
|
if (!pkg) {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
let path9 = pkgPath?.replace(/package.json$/, "");
|
|
1211
|
-
let name = JSON.parse(readFileSync2(pkgPath, "utf-8")).name;
|
|
1212
|
-
if (!name) {
|
|
1213
|
-
pkgPath = await findClosestPkgJsonPath(path9);
|
|
1214
|
-
if (pkgPath) {
|
|
1215
|
-
path9 = pkgPath?.replace(/package.json$/, "");
|
|
1216
|
-
name = JSON.parse(readFileSync2(pkgPath, "utf-8")).name;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
if (path9 && name) {
|
|
1220
|
-
pkg = { path: path9, name };
|
|
1221
|
-
this._packages.push(pkg);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1228
|
+
pkg = await getClosestNamedPackage(stat.file);
|
|
1229
|
+
this._packages.push(pkg);
|
|
1224
1230
|
}
|
|
1225
|
-
stat.pkg = pkg
|
|
1231
|
+
stat.pkg = pkg.name;
|
|
1226
1232
|
}
|
|
1227
1233
|
const grouped = {};
|
|
1228
1234
|
stats.forEach((stat) => {
|
|
@@ -1483,7 +1489,7 @@ function handleDeprecatedOptions(options) {
|
|
|
1483
1489
|
}
|
|
1484
1490
|
}
|
|
1485
1491
|
function resolveViteRoot(viteConfig) {
|
|
1486
|
-
return
|
|
1492
|
+
return normalizePath3(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1487
1493
|
}
|
|
1488
1494
|
async function buildExtraViteConfig(options, config) {
|
|
1489
1495
|
const extraViteConfig = {
|
|
@@ -1800,7 +1806,7 @@ function generateSvelteMetadata(options) {
|
|
|
1800
1806
|
}
|
|
1801
1807
|
|
|
1802
1808
|
// src/ui/inspector/plugin.ts
|
|
1803
|
-
import { normalizePath as
|
|
1809
|
+
import { normalizePath as normalizePath4 } from "vite";
|
|
1804
1810
|
import path8 from "path";
|
|
1805
1811
|
import { fileURLToPath } from "url";
|
|
1806
1812
|
import fs6 from "fs";
|
|
@@ -1828,7 +1834,7 @@ var defaultInspectorOptions = {
|
|
|
1828
1834
|
customStyles: true
|
|
1829
1835
|
};
|
|
1830
1836
|
function getInspectorPath() {
|
|
1831
|
-
const pluginPath =
|
|
1837
|
+
const pluginPath = normalizePath4(path8.dirname(fileURLToPath(import.meta.url)));
|
|
1832
1838
|
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
|
|
1833
1839
|
}
|
|
1834
1840
|
function svelteInspector() {
|