vike-lite 1.18.0 → 1.18.2
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/vite.mjs +38 -37
- package/package.json +1 -1
package/dist/vite.mjs
CHANGED
|
@@ -122,6 +122,7 @@ function findPackageJsonPath(startDir) {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
function extractPkgName(id) {
|
|
125
|
+
if (id.startsWith("\0")) return null;
|
|
125
126
|
const normalized = id.replaceAll("\\", "/");
|
|
126
127
|
const matches = [...normalized.matchAll(/(?:node_modules|\.yarn(?:\/__virtual__)?)\/(@[^/]+\/[^/]+|[^/]+)/g)];
|
|
127
128
|
if (matches.length > 0) {
|
|
@@ -143,6 +144,7 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
143
144
|
let hasAnyPrerender;
|
|
144
145
|
let baseUrl;
|
|
145
146
|
let projectDependencies = null;
|
|
147
|
+
const bundleReports = {};
|
|
146
148
|
const VIRTUAL = {
|
|
147
149
|
routes: "virtual:vike-lite/routes",
|
|
148
150
|
manifest: "virtual:vike-lite/client-manifest",
|
|
@@ -168,21 +170,24 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
168
170
|
viteConfigRoot = config.root ? path.resolve(config.root) : process.cwd();
|
|
169
171
|
if (isProd && printDependencies) {
|
|
170
172
|
const pkgJsonPath = findPackageJsonPath(viteConfigRoot);
|
|
171
|
-
if (pkgJsonPath) {
|
|
173
|
+
if (pkgJsonPath) try {
|
|
172
174
|
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
173
175
|
projectDependencies = {};
|
|
174
176
|
for (const [k, v] of Object.entries(pkgJson.dependencies || {})) projectDependencies[k] = {
|
|
175
|
-
version: v,
|
|
177
|
+
version: String(v),
|
|
176
178
|
type: ""
|
|
177
179
|
};
|
|
178
|
-
for (const [k, v] of Object.entries(pkgJson.devDependencies || {})) projectDependencies[k] = {
|
|
179
|
-
version: v,
|
|
180
|
+
for (const [k, v] of Object.entries(pkgJson.devDependencies || {})) if (!projectDependencies[k]) projectDependencies[k] = {
|
|
181
|
+
version: String(v),
|
|
180
182
|
type: "dev"
|
|
181
183
|
};
|
|
182
184
|
for (const [k, v] of Object.entries(pkgJson.peerDependencies || {})) if (!projectDependencies[k]) projectDependencies[k] = {
|
|
183
|
-
version: v,
|
|
185
|
+
version: String(v),
|
|
184
186
|
type: "peer"
|
|
185
187
|
};
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.warn(`⚠️ Failed to parse package.json for printDependencies:`, error);
|
|
190
|
+
projectDependencies = null;
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
193
|
const { routes } = generateRoutes(viteConfigRoot, pagesDir);
|
|
@@ -349,39 +354,27 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
349
354
|
},
|
|
350
355
|
generateBundle(_options, bundle) {
|
|
351
356
|
if (!printDependencies || !projectDependencies) return;
|
|
357
|
+
const deps = projectDependencies;
|
|
352
358
|
const usedDeps = /* @__PURE__ */ new Map();
|
|
359
|
+
function recordUsage(pkg, patch) {
|
|
360
|
+
if (!pkg || pkg.startsWith("vike-lite") || !Object.hasOwn(deps, pkg)) return;
|
|
361
|
+
const entry = usedDeps.get(pkg) ?? {
|
|
362
|
+
...deps[pkg],
|
|
363
|
+
isBundled: false,
|
|
364
|
+
isExternal: false
|
|
365
|
+
};
|
|
366
|
+
Object.assign(entry, patch);
|
|
367
|
+
usedDeps.set(pkg, entry);
|
|
368
|
+
}
|
|
353
369
|
for (const chunk of Object.values(bundle)) {
|
|
354
370
|
if (chunk.type !== "chunk") continue;
|
|
355
|
-
for (const id of chunk.moduleIds) {
|
|
356
|
-
const pkg = extractPkgName(id);
|
|
357
|
-
if (pkg && !pkg.startsWith("vike-lite") && Object.hasOwn(projectDependencies, pkg)) {
|
|
358
|
-
const entry = usedDeps.get(pkg) ?? {
|
|
359
|
-
...projectDependencies[pkg],
|
|
360
|
-
isBundled: false,
|
|
361
|
-
isExternal: false
|
|
362
|
-
};
|
|
363
|
-
entry.isBundled = true;
|
|
364
|
-
usedDeps.set(pkg, entry);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
for (const imp of [...chunk.imports, ...chunk.dynamicImports]) {
|
|
368
|
-
if (bundle[imp]) continue;
|
|
369
|
-
const pkg = extractPkgName(imp);
|
|
370
|
-
if (pkg && !pkg.startsWith("vike-lite") && Object.hasOwn(projectDependencies, pkg)) {
|
|
371
|
-
const entry = usedDeps.get(pkg) ?? {
|
|
372
|
-
...projectDependencies[pkg],
|
|
373
|
-
isBundled: false,
|
|
374
|
-
isExternal: false
|
|
375
|
-
};
|
|
376
|
-
entry.isExternal = true;
|
|
377
|
-
usedDeps.set(pkg, entry);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
371
|
+
for (const id of chunk.moduleIds) recordUsage(extractPkgName(id), { isBundled: true });
|
|
380
372
|
}
|
|
381
|
-
const
|
|
373
|
+
for (const id of this.getModuleIds()) if (this.getModuleInfo(id)?.code === null) recordUsage(extractPkgName(id), { isExternal: true });
|
|
382
374
|
const envName = this.environment.name;
|
|
383
|
-
|
|
384
|
-
|
|
375
|
+
bundleReports[envName] = usedDeps;
|
|
376
|
+
const sorted = [...usedDeps.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
377
|
+
console.log(`\n📦 [${envName === "client" ? "Client" : "Server"} bundle] ${sorted.length} dependencies used from package.json:`);
|
|
385
378
|
if (sorted.length === 0) console.log(" (None)");
|
|
386
379
|
else for (const [name, info] of sorted) {
|
|
387
380
|
const typeTag = info.type ? ` \u{1B}[33m[${info.type}]\u{1B}[0m` : "";
|
|
@@ -390,12 +383,20 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
390
383
|
}
|
|
391
384
|
const suggestions = [];
|
|
392
385
|
for (const [name, info] of sorted) if (envName === "ssr" && info.isExternal && info.type === "dev") suggestions.push(`\u{1B}[31m🚨 ${name}\u{1B}[0m is externalized by the server but listed as a \u{1B}[33mdevDependency\u{1B}[0m. Move it to \u{1B}[32mdependencies\u{1B}[0m to prevent production crashes.`);
|
|
393
|
-
|
|
394
|
-
const
|
|
395
|
-
|
|
386
|
+
if (envName === "ssr") {
|
|
387
|
+
const clientDeps = bundleReports.client;
|
|
388
|
+
const allNames = /* @__PURE__ */ new Set([...clientDeps?.keys() ?? [], ...usedDeps.keys()]);
|
|
389
|
+
for (const name of allNames) {
|
|
390
|
+
const meta = deps[name];
|
|
391
|
+
if (!meta || meta.type !== "") continue;
|
|
392
|
+
const c = clientDeps?.get(name);
|
|
393
|
+
const s = usedDeps.get(name);
|
|
394
|
+
const externalAnywhere = c?.isExternal || s?.isExternal;
|
|
395
|
+
if ((c || s) && !externalAnywhere) suggestions.push(`\u{1B}[34m💡 ${name}\u{1B}[0m is fully bundled (or unused) in both client and server — never externalized. Safe to move to \u{1B}[33mdevDependencies\u{1B}[0m.`);
|
|
396
|
+
}
|
|
396
397
|
}
|
|
397
398
|
if (suggestions.length > 0) {
|
|
398
|
-
console.log(`\n \u{1B}[
|
|
399
|
+
console.log(`\n \u{1B}[1mSuggestions:\u{1B}[0m`);
|
|
399
400
|
for (const s of suggestions) console.log(` ${s}`);
|
|
400
401
|
}
|
|
401
402
|
},
|