vike-lite 1.18.0 → 1.18.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/vite.mjs +22 -30
- 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) {
|
|
@@ -168,21 +169,24 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
168
169
|
viteConfigRoot = config.root ? path.resolve(config.root) : process.cwd();
|
|
169
170
|
if (isProd && printDependencies) {
|
|
170
171
|
const pkgJsonPath = findPackageJsonPath(viteConfigRoot);
|
|
171
|
-
if (pkgJsonPath) {
|
|
172
|
+
if (pkgJsonPath) try {
|
|
172
173
|
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
173
174
|
projectDependencies = {};
|
|
174
175
|
for (const [k, v] of Object.entries(pkgJson.dependencies || {})) projectDependencies[k] = {
|
|
175
|
-
version: v,
|
|
176
|
+
version: String(v),
|
|
176
177
|
type: ""
|
|
177
178
|
};
|
|
178
|
-
for (const [k, v] of Object.entries(pkgJson.devDependencies || {})) projectDependencies[k] = {
|
|
179
|
-
version: v,
|
|
179
|
+
for (const [k, v] of Object.entries(pkgJson.devDependencies || {})) if (!projectDependencies[k]) projectDependencies[k] = {
|
|
180
|
+
version: String(v),
|
|
180
181
|
type: "dev"
|
|
181
182
|
};
|
|
182
183
|
for (const [k, v] of Object.entries(pkgJson.peerDependencies || {})) if (!projectDependencies[k]) projectDependencies[k] = {
|
|
183
|
-
version: v,
|
|
184
|
+
version: String(v),
|
|
184
185
|
type: "peer"
|
|
185
186
|
};
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.warn(`⚠️ Failed to parse package.json for printDependencies:`, error);
|
|
189
|
+
projectDependencies = null;
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
192
|
const { routes } = generateRoutes(viteConfigRoot, pagesDir);
|
|
@@ -349,35 +353,23 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
349
353
|
},
|
|
350
354
|
generateBundle(_options, bundle) {
|
|
351
355
|
if (!printDependencies || !projectDependencies) return;
|
|
356
|
+
const deps = projectDependencies;
|
|
352
357
|
const usedDeps = /* @__PURE__ */ new Map();
|
|
358
|
+
function recordUsage(pkg, patch) {
|
|
359
|
+
if (!pkg || pkg.startsWith("vike-lite") || !Object.hasOwn(deps, pkg)) return;
|
|
360
|
+
const entry = usedDeps.get(pkg) ?? {
|
|
361
|
+
...deps[pkg],
|
|
362
|
+
isBundled: false,
|
|
363
|
+
isExternal: false
|
|
364
|
+
};
|
|
365
|
+
Object.assign(entry, patch);
|
|
366
|
+
usedDeps.set(pkg, entry);
|
|
367
|
+
}
|
|
353
368
|
for (const chunk of Object.values(bundle)) {
|
|
354
369
|
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
|
-
}
|
|
370
|
+
for (const id of chunk.moduleIds) recordUsage(extractPkgName(id), { isBundled: true });
|
|
380
371
|
}
|
|
372
|
+
for (const id of this.getModuleIds()) if (this.getModuleInfo(id)?.code === null) recordUsage(extractPkgName(id), { isExternal: true });
|
|
381
373
|
const sorted = [...usedDeps.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
382
374
|
const envName = this.environment.name;
|
|
383
375
|
const label = envName === "client" ? "Client" : "Server";
|