vike-lite 1.17.4 → 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 +26 -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);
|
|
@@ -194,6 +198,10 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
194
198
|
const pagesDirTest = new RegExp(String.raw`[\\/]${escapedPagesDir}[\\/]`);
|
|
195
199
|
return {
|
|
196
200
|
appType: "custom",
|
|
201
|
+
builder: { async buildApp(builder) {
|
|
202
|
+
await builder.build(builder.environments.client);
|
|
203
|
+
await builder.build(builder.environments.ssr);
|
|
204
|
+
} },
|
|
197
205
|
ssr: { noExternal: [/^vike-lite(?:$|-)/] },
|
|
198
206
|
environments: {
|
|
199
207
|
client: { build: {
|
|
@@ -345,35 +353,23 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
345
353
|
},
|
|
346
354
|
generateBundle(_options, bundle) {
|
|
347
355
|
if (!printDependencies || !projectDependencies) return;
|
|
356
|
+
const deps = projectDependencies;
|
|
348
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
|
+
}
|
|
349
368
|
for (const chunk of Object.values(bundle)) {
|
|
350
369
|
if (chunk.type !== "chunk") continue;
|
|
351
|
-
for (const id of chunk.moduleIds) {
|
|
352
|
-
const pkg = extractPkgName(id);
|
|
353
|
-
if (pkg && !pkg.startsWith("vike-lite") && Object.hasOwn(projectDependencies, pkg)) {
|
|
354
|
-
const entry = usedDeps.get(pkg) ?? {
|
|
355
|
-
...projectDependencies[pkg],
|
|
356
|
-
isBundled: false,
|
|
357
|
-
isExternal: false
|
|
358
|
-
};
|
|
359
|
-
entry.isBundled = true;
|
|
360
|
-
usedDeps.set(pkg, entry);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
for (const imp of [...chunk.imports, ...chunk.dynamicImports]) {
|
|
364
|
-
if (bundle[imp]) continue;
|
|
365
|
-
const pkg = extractPkgName(imp);
|
|
366
|
-
if (pkg && !pkg.startsWith("vike-lite") && Object.hasOwn(projectDependencies, pkg)) {
|
|
367
|
-
const entry = usedDeps.get(pkg) ?? {
|
|
368
|
-
...projectDependencies[pkg],
|
|
369
|
-
isBundled: false,
|
|
370
|
-
isExternal: false
|
|
371
|
-
};
|
|
372
|
-
entry.isExternal = true;
|
|
373
|
-
usedDeps.set(pkg, entry);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
370
|
+
for (const id of chunk.moduleIds) recordUsage(extractPkgName(id), { isBundled: true });
|
|
376
371
|
}
|
|
372
|
+
for (const id of this.getModuleIds()) if (this.getModuleInfo(id)?.code === null) recordUsage(extractPkgName(id), { isExternal: true });
|
|
377
373
|
const sorted = [...usedDeps.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
378
374
|
const envName = this.environment.name;
|
|
379
375
|
const label = envName === "client" ? "Client" : "Server";
|