vite-plugin-kiru 0.29.6 → 0.29.8
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/README.md +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +78 -147
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ kiru({
|
|
|
48
48
|
app: {
|
|
49
49
|
baseUrl: "/", // Base URL for the app
|
|
50
50
|
dir: "src/pages", // Directory containing pages
|
|
51
|
-
document: "document.tsx", // Document component file
|
|
51
|
+
document: "document.{tsx,jsx}", // Document component file
|
|
52
52
|
page: "index.{tsx,jsx}", // Page component pattern
|
|
53
53
|
layout: "layout.{tsx,jsx}", // Layout component pattern
|
|
54
54
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface SSGOptions {
|
|
|
23
23
|
dir?: string
|
|
24
24
|
/**
|
|
25
25
|
* The name of the document component
|
|
26
|
-
* @default "document.tsx"
|
|
26
|
+
* @default "document.{tsx,jsx}"
|
|
27
27
|
*/
|
|
28
28
|
document?: string
|
|
29
29
|
/**
|
|
@@ -100,7 +100,7 @@ export interface KiruPluginOptions {
|
|
|
100
100
|
* ```ts
|
|
101
101
|
* ssg: {
|
|
102
102
|
* dir: "./src/app",
|
|
103
|
-
* document: "document.tsx",
|
|
103
|
+
* document: "document.{tsx,jsx}",
|
|
104
104
|
* page: "index.{tsx,jsx}",
|
|
105
105
|
* layout: "layout.{tsx,jsx}",
|
|
106
106
|
* transition: true
|
package/dist/index.js
CHANGED
|
@@ -1716,7 +1716,7 @@ var require_magic_string_cjs = __commonJS({
|
|
|
1716
1716
|
});
|
|
1717
1717
|
|
|
1718
1718
|
// src/index.ts
|
|
1719
|
-
import
|
|
1719
|
+
import path6 from "node:path";
|
|
1720
1720
|
|
|
1721
1721
|
// src/codegen/shared.ts
|
|
1722
1722
|
var import_magic_string = __toESM(require_magic_string_cjs(), 1);
|
|
@@ -2171,19 +2171,50 @@ function tEntries(obj) {
|
|
|
2171
2171
|
// src/config.ts
|
|
2172
2172
|
import path2 from "node:path";
|
|
2173
2173
|
|
|
2174
|
-
// src/
|
|
2174
|
+
// src/utils.ts
|
|
2175
2175
|
import path from "node:path";
|
|
2176
|
-
|
|
2176
|
+
function createLogger(state) {
|
|
2177
|
+
return (...data) => {
|
|
2178
|
+
if (!state.loggingEnabled) return;
|
|
2179
|
+
console.log(ANSI.cyan("[vite-plugin-kiru]"), ...data);
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
async function resolveUserDocument(projectRoot, ssgOptions) {
|
|
2183
|
+
const { dir, document } = ssgOptions;
|
|
2184
|
+
const fp = path.resolve(projectRoot, dir, document);
|
|
2185
|
+
const { globSync } = await import("node:fs");
|
|
2186
|
+
const res = globSync(fp);
|
|
2187
|
+
if (res.length) return res[0].replace(/\\/g, "/");
|
|
2188
|
+
throw new Error(`Document not found at ${fp}`);
|
|
2189
|
+
}
|
|
2190
|
+
var TRANSFORMABLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
2191
|
+
".tsx",
|
|
2192
|
+
".jsx",
|
|
2193
|
+
".ts",
|
|
2194
|
+
".js",
|
|
2195
|
+
".mjs",
|
|
2196
|
+
".mts",
|
|
2197
|
+
".md",
|
|
2198
|
+
".mdx"
|
|
2199
|
+
]);
|
|
2200
|
+
function shouldTransformFile(id, state) {
|
|
2201
|
+
if (id[0] === "\0" || id.startsWith("vite:") || id.includes("/node_modules/")) {
|
|
2202
|
+
return false;
|
|
2203
|
+
}
|
|
2204
|
+
const filePath = path.resolve(id).replace(/\\/g, "/");
|
|
2205
|
+
const isIncludedByUser = state.includedPaths.some(
|
|
2206
|
+
(p) => filePath.startsWith(p)
|
|
2207
|
+
);
|
|
2208
|
+
const isWithinProject = filePath.startsWith(state.projectRoot);
|
|
2209
|
+
return (isWithinProject || isIncludedByUser) && TRANSFORMABLE_EXTENSIONS.has(path.extname(filePath));
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// src/virtual-modules.ts
|
|
2177
2213
|
var VIRTUAL_ROUTES_ID = "virtual:kiru:routes";
|
|
2178
2214
|
var VIRTUAL_ENTRY_SERVER_ID = "virtual:kiru:entry-server";
|
|
2179
2215
|
var VIRTUAL_ENTRY_CLIENT_ID = "virtual:kiru:entry-client";
|
|
2180
|
-
function createVirtualModules(projectRoot, ssgOptions) {
|
|
2181
|
-
|
|
2182
|
-
const { dir, document } = ssgOptions;
|
|
2183
|
-
const fp = path.resolve(projectRoot, dir, document);
|
|
2184
|
-
if (fs2.existsSync(fp)) return fp.replace(/\\/g, "/");
|
|
2185
|
-
throw new Error(`Document not found at ${fp}`);
|
|
2186
|
-
}
|
|
2216
|
+
async function createVirtualModules(projectRoot, ssgOptions) {
|
|
2217
|
+
const userDoc = await resolveUserDocument(projectRoot, ssgOptions);
|
|
2187
2218
|
function createRoutesModule() {
|
|
2188
2219
|
const { dir, baseUrl, page, layout, transition } = ssgOptions;
|
|
2189
2220
|
return `
|
|
@@ -2201,7 +2232,6 @@ export { dir, baseUrl, pages, layouts, transition }
|
|
|
2201
2232
|
`;
|
|
2202
2233
|
}
|
|
2203
2234
|
function createEntryServerModule() {
|
|
2204
|
-
const userDoc = resolveUserDocument2();
|
|
2205
2235
|
return `
|
|
2206
2236
|
import {
|
|
2207
2237
|
render as kiruServerRender,
|
|
@@ -2224,7 +2254,7 @@ export async function generateStaticPaths() {
|
|
|
2224
2254
|
return `
|
|
2225
2255
|
import { initClient } from "kiru/router/client"
|
|
2226
2256
|
import { dir, baseUrl, pages, layouts, transition } from "${VIRTUAL_ROUTES_ID}"
|
|
2227
|
-
import "${
|
|
2257
|
+
import "${userDoc}"
|
|
2228
2258
|
|
|
2229
2259
|
initClient({ dir, baseUrl, pages, layouts, transition })
|
|
2230
2260
|
`;
|
|
@@ -2248,7 +2278,7 @@ var defaultEsBuildOptions = {
|
|
|
2248
2278
|
var defaultSSGOptions = {
|
|
2249
2279
|
baseUrl: "/",
|
|
2250
2280
|
dir: "src/pages",
|
|
2251
|
-
document: "document.tsx",
|
|
2281
|
+
document: "document.{tsx,jsx}",
|
|
2252
2282
|
page: "index.{tsx,jsx}",
|
|
2253
2283
|
layout: "layout.{tsx,jsx}",
|
|
2254
2284
|
transition: false,
|
|
@@ -2257,7 +2287,7 @@ var defaultSSGOptions = {
|
|
|
2257
2287
|
}
|
|
2258
2288
|
};
|
|
2259
2289
|
function createPluginState(opts = {}) {
|
|
2260
|
-
let fileLinkFormatter = (
|
|
2290
|
+
let fileLinkFormatter = (path7, line) => `vscode://file/${path7}:${line}`;
|
|
2261
2291
|
let dtClientPathname = "/__devtools__";
|
|
2262
2292
|
if (typeof opts.devtools === "object") {
|
|
2263
2293
|
dtClientPathname = opts.devtools.dtClientPathname ?? dtClientPathname;
|
|
@@ -3257,7 +3287,9 @@ async function handleSSR(server, url, projectRoot, resolveUserDocument2) {
|
|
|
3257
3287
|
VIRTUAL_ENTRY_SERVER_ID
|
|
3258
3288
|
);
|
|
3259
3289
|
const moduleIds = [];
|
|
3260
|
-
const documentModule = resolveUserDocument2().substring(
|
|
3290
|
+
const documentModule = (await resolveUserDocument2()).substring(
|
|
3291
|
+
projectRoot.length
|
|
3292
|
+
);
|
|
3261
3293
|
moduleIds.push(documentModule);
|
|
3262
3294
|
const ctx = {
|
|
3263
3295
|
registerModule: (moduleId) => {
|
|
@@ -3309,7 +3341,7 @@ async function handleSSR(server, url, projectRoot, resolveUserDocument2) {
|
|
|
3309
3341
|
|
|
3310
3342
|
// src/preview-server.ts
|
|
3311
3343
|
import { resolve } from "node:path";
|
|
3312
|
-
import
|
|
3344
|
+
import fs2 from "node:fs";
|
|
3313
3345
|
import path4 from "node:path";
|
|
3314
3346
|
|
|
3315
3347
|
// ../../node_modules/.pnpm/mime@4.1.0/node_modules/mime/dist/types/other.js
|
|
@@ -4447,12 +4479,12 @@ var Mime = class {
|
|
|
4447
4479
|
}
|
|
4448
4480
|
return this;
|
|
4449
4481
|
}
|
|
4450
|
-
getType(
|
|
4451
|
-
if (typeof
|
|
4482
|
+
getType(path7) {
|
|
4483
|
+
if (typeof path7 !== "string")
|
|
4452
4484
|
return null;
|
|
4453
|
-
const last =
|
|
4485
|
+
const last = path7.replace(/^.*[/\\]/s, "").toLowerCase();
|
|
4454
4486
|
const ext = last.replace(/^.*\./s, "").toLowerCase();
|
|
4455
|
-
const hasPath = last.length <
|
|
4487
|
+
const hasPath = last.length < path7.length;
|
|
4456
4488
|
const hasDot = ext.length < last.length - 1;
|
|
4457
4489
|
if (!hasDot && hasPath)
|
|
4458
4490
|
return null;
|
|
@@ -4508,11 +4540,11 @@ function createPreviewMiddleware(projectRoot, baseOutDir) {
|
|
|
4508
4540
|
}
|
|
4509
4541
|
if (!path4.extname(filePath) && !url.endsWith("/")) {
|
|
4510
4542
|
const htmlCandidate = filePath + ".html";
|
|
4511
|
-
if (
|
|
4543
|
+
if (fs2.existsSync(htmlCandidate)) {
|
|
4512
4544
|
filePath = htmlCandidate;
|
|
4513
4545
|
}
|
|
4514
4546
|
}
|
|
4515
|
-
if (!
|
|
4547
|
+
if (!fs2.existsSync(filePath)) {
|
|
4516
4548
|
const normalizedUrl = url.replace(/\/$/, "") || "/";
|
|
4517
4549
|
const urlSegments = normalizedUrl.split("/").filter(Boolean);
|
|
4518
4550
|
let found404 = false;
|
|
@@ -4523,7 +4555,7 @@ function createPreviewMiddleware(projectRoot, baseOutDir) {
|
|
|
4523
4555
|
clientOutDir,
|
|
4524
4556
|
fourOhFourPath + ".html"
|
|
4525
4557
|
);
|
|
4526
|
-
if (
|
|
4558
|
+
if (fs2.existsSync(fourOhFourFilePath)) {
|
|
4527
4559
|
filePath = fourOhFourFilePath;
|
|
4528
4560
|
found404 = true;
|
|
4529
4561
|
break;
|
|
@@ -4536,7 +4568,7 @@ function createPreviewMiddleware(projectRoot, baseOutDir) {
|
|
|
4536
4568
|
}
|
|
4537
4569
|
}
|
|
4538
4570
|
const type = src_default.getType(filePath) ?? "application/octet-stream";
|
|
4539
|
-
const content =
|
|
4571
|
+
const content = fs2.readFileSync(filePath);
|
|
4540
4572
|
const is404Page = filePath.includes("/404.html");
|
|
4541
4573
|
res.statusCode = is404Page ? 404 : 200;
|
|
4542
4574
|
res.setHeader("Content-Type", type);
|
|
@@ -4549,7 +4581,7 @@ function createPreviewMiddleware(projectRoot, baseOutDir) {
|
|
|
4549
4581
|
|
|
4550
4582
|
// src/ssg.ts
|
|
4551
4583
|
import path5 from "node:path";
|
|
4552
|
-
import
|
|
4584
|
+
import fs3 from "node:fs";
|
|
4553
4585
|
import { pathToFileURL } from "node:url";
|
|
4554
4586
|
async function generateStaticSite(state, outputOptions, bundle, log) {
|
|
4555
4587
|
const { projectRoot, baseOutDir, manifestPath } = state;
|
|
@@ -4565,9 +4597,9 @@ async function generateStaticSite(state, outputOptions, bundle, log) {
|
|
|
4565
4597
|
const { clientEntry } = await getClientAssets(clientOutDirAbs, manifestPath);
|
|
4566
4598
|
let manifest = null;
|
|
4567
4599
|
const clientManifestPath = path5.resolve(clientOutDirAbs, manifestPath);
|
|
4568
|
-
if (
|
|
4600
|
+
if (fs3.existsSync(clientManifestPath)) {
|
|
4569
4601
|
try {
|
|
4570
|
-
manifest = JSON.parse(
|
|
4602
|
+
manifest = JSON.parse(fs3.readFileSync(clientManifestPath, "utf-8"));
|
|
4571
4603
|
} catch {
|
|
4572
4604
|
}
|
|
4573
4605
|
}
|
|
@@ -4598,8 +4630,8 @@ async function generateStaticSite(state, outputOptions, bundle, log) {
|
|
|
4598
4630
|
);
|
|
4599
4631
|
const filePath = getOutputPath(clientOutDirAbs, route);
|
|
4600
4632
|
log(ANSI.cyan("[SSG]"), "write:", ANSI.black(filePath));
|
|
4601
|
-
|
|
4602
|
-
|
|
4633
|
+
fs3.mkdirSync(path5.dirname(filePath), { recursive: true });
|
|
4634
|
+
fs3.writeFileSync(filePath, html, "utf-8");
|
|
4603
4635
|
})
|
|
4604
4636
|
);
|
|
4605
4637
|
}
|
|
@@ -4609,8 +4641,8 @@ async function getClientAssets(clientOutDirAbs, manifestPath) {
|
|
|
4609
4641
|
let clientEntry = null;
|
|
4610
4642
|
try {
|
|
4611
4643
|
const clientManifestPath = path5.resolve(clientOutDirAbs, manifestPath);
|
|
4612
|
-
if (
|
|
4613
|
-
const manifest = JSON.parse(
|
|
4644
|
+
if (fs3.existsSync(clientManifestPath)) {
|
|
4645
|
+
const manifest = JSON.parse(fs3.readFileSync(clientManifestPath, "utf-8"));
|
|
4614
4646
|
const clientEntryKey = "virtual:kiru:entry-client";
|
|
4615
4647
|
if (manifest[clientEntryKey]?.file) {
|
|
4616
4648
|
clientEntry = manifest[clientEntryKey].file;
|
|
@@ -4623,44 +4655,22 @@ async function getClientAssets(clientOutDirAbs, manifestPath) {
|
|
|
4623
4655
|
}
|
|
4624
4656
|
return { clientEntry };
|
|
4625
4657
|
}
|
|
4626
|
-
function collectCssForModules(manifest, moduleIds, projectRoot
|
|
4658
|
+
function collectCssForModules(manifest, moduleIds, projectRoot) {
|
|
4627
4659
|
const seen = /* @__PURE__ */ new Set();
|
|
4628
4660
|
const cssFiles = /* @__PURE__ */ new Set();
|
|
4629
|
-
if (log) {
|
|
4630
|
-
log(
|
|
4631
|
-
ANSI.yellow("[SSG CSS]"),
|
|
4632
|
-
`Collecting CSS for ${moduleIds.length} modules:`
|
|
4633
|
-
);
|
|
4634
|
-
moduleIds.forEach((id) => log(ANSI.yellow("[SSG CSS]"), ` - ${id}`));
|
|
4635
|
-
}
|
|
4636
4661
|
const collectCss = (key) => {
|
|
4637
4662
|
if (seen.has(key)) return;
|
|
4638
4663
|
seen.add(key);
|
|
4639
4664
|
const it = manifest[key];
|
|
4640
4665
|
if (!it) {
|
|
4641
|
-
if (log)
|
|
4642
|
-
log(ANSI.yellow("[SSG CSS]"), ` Key not found in manifest: ${key}`);
|
|
4643
4666
|
return;
|
|
4644
4667
|
}
|
|
4645
|
-
if (log) {
|
|
4646
|
-
log(ANSI.yellow("[SSG CSS]"), ` Processing manifest key: ${key}`);
|
|
4647
|
-
if (it.css && it.css.length > 0) {
|
|
4648
|
-
log(ANSI.yellow("[SSG CSS]"), ` Found CSS: ${it.css.join(", ")}`);
|
|
4649
|
-
}
|
|
4650
|
-
if (it.imports && it.imports.length > 0) {
|
|
4651
|
-
log(
|
|
4652
|
-
ANSI.yellow("[SSG CSS]"),
|
|
4653
|
-
` Found imports: ${it.imports.length} imports`
|
|
4654
|
-
);
|
|
4655
|
-
}
|
|
4656
|
-
}
|
|
4657
4668
|
;
|
|
4658
4669
|
(it.css || []).forEach((c) => cssFiles.add(c));
|
|
4659
4670
|
(it.imports || []).forEach((imp) => collectCss(imp));
|
|
4660
4671
|
};
|
|
4661
4672
|
const entryClientKey = "virtual:kiru:entry-client";
|
|
4662
4673
|
if (manifest[entryClientKey] && !seen.has(entryClientKey)) {
|
|
4663
|
-
if (log) log(ANSI.yellow("[SSG CSS]"), `Including entry client CSS`);
|
|
4664
4674
|
collectCss(entryClientKey);
|
|
4665
4675
|
}
|
|
4666
4676
|
for (const moduleId of moduleIds) {
|
|
@@ -4671,27 +4681,16 @@ function collectCssForModules(manifest, moduleIds, projectRoot, log) {
|
|
|
4671
4681
|
if (normalizedId.startsWith("/")) {
|
|
4672
4682
|
normalizedId = normalizedId.substring(1);
|
|
4673
4683
|
}
|
|
4674
|
-
if (log) {
|
|
4675
|
-
log(ANSI.yellow("[SSG CSS]"), `Looking for module: ${moduleId}`);
|
|
4676
|
-
log(ANSI.yellow("[SSG CSS]"), ` Normalized: ${normalizedId}`);
|
|
4677
|
-
}
|
|
4678
|
-
let found = false;
|
|
4679
4684
|
if (manifest[normalizedId]) {
|
|
4680
|
-
if (log) log(ANSI.green("[SSG CSS]"), ` \u2713 Found as: ${normalizedId}`);
|
|
4681
4685
|
collectCss(normalizedId);
|
|
4682
|
-
found = true;
|
|
4683
4686
|
continue;
|
|
4684
4687
|
}
|
|
4685
4688
|
if (manifest["/" + normalizedId]) {
|
|
4686
|
-
if (log) log(ANSI.green("[SSG CSS]"), ` \u2713 Found as: /${normalizedId}`);
|
|
4687
4689
|
collectCss("/" + normalizedId);
|
|
4688
|
-
found = true;
|
|
4689
4690
|
continue;
|
|
4690
4691
|
}
|
|
4691
4692
|
if (manifest[moduleId]) {
|
|
4692
|
-
if (log) log(ANSI.green("[SSG CSS]"), ` \u2713 Found as: ${moduleId}`);
|
|
4693
4693
|
collectCss(moduleId);
|
|
4694
|
-
found = true;
|
|
4695
4694
|
continue;
|
|
4696
4695
|
}
|
|
4697
4696
|
for (const key in manifest) {
|
|
@@ -4699,43 +4698,25 @@ function collectCssForModules(manifest, moduleIds, projectRoot, log) {
|
|
|
4699
4698
|
const moduleBaseName = path5.basename(normalizedId);
|
|
4700
4699
|
const keyBaseName = path5.basename(keyNormalized);
|
|
4701
4700
|
if ((keyNormalized.endsWith(normalizedId) || normalizedId.endsWith(keyNormalized)) && moduleBaseName === keyBaseName) {
|
|
4702
|
-
if (log)
|
|
4703
|
-
log(ANSI.green("[SSG CSS]"), ` \u2713 Found by basename match: ${key}`);
|
|
4704
4701
|
collectCss(key);
|
|
4705
|
-
found = true;
|
|
4706
4702
|
break;
|
|
4707
4703
|
}
|
|
4708
4704
|
}
|
|
4709
|
-
if (!found && log) {
|
|
4710
|
-
log(
|
|
4711
|
-
ANSI.red("[SSG CSS]"),
|
|
4712
|
-
` \u2717 Module not found in manifest: ${moduleId}`
|
|
4713
|
-
);
|
|
4714
|
-
}
|
|
4715
4705
|
}
|
|
4716
4706
|
if (cssFiles.size) {
|
|
4717
4707
|
const links = Array.from(cssFiles).map((f) => `<link rel="stylesheet" type="text/css" href="/${f}">`).join("");
|
|
4718
|
-
if (log) {
|
|
4719
|
-
log(ANSI.green("[SSG CSS]"), `Collected ${cssFiles.size} CSS file(s):`);
|
|
4720
|
-
Array.from(cssFiles).forEach(
|
|
4721
|
-
(f) => log(ANSI.green("[SSG CSS]"), ` - ${f}`)
|
|
4722
|
-
);
|
|
4723
|
-
}
|
|
4724
4708
|
return links;
|
|
4725
4709
|
}
|
|
4726
|
-
if (log) {
|
|
4727
|
-
log(ANSI.yellow("[SSG CSS]"), "No CSS files collected");
|
|
4728
|
-
}
|
|
4729
4710
|
return "";
|
|
4730
4711
|
}
|
|
4731
4712
|
function findClientEntry(dir) {
|
|
4732
|
-
if (!
|
|
4733
|
-
const top =
|
|
4713
|
+
if (!fs3.existsSync(dir)) return null;
|
|
4714
|
+
const top = fs3.readdirSync(dir);
|
|
4734
4715
|
const topJs = top.find((f) => f.endsWith(".js"));
|
|
4735
4716
|
if (topJs) return topJs;
|
|
4736
4717
|
const assetsDir = path5.join(dir, "assets");
|
|
4737
|
-
if (
|
|
4738
|
-
const assetJs =
|
|
4718
|
+
if (fs3.existsSync(assetsDir)) {
|
|
4719
|
+
const assetJs = fs3.readdirSync(assetsDir).find((f) => f.endsWith(".js"));
|
|
4739
4720
|
return assetJs ? `assets/${assetJs}` : null;
|
|
4740
4721
|
}
|
|
4741
4722
|
return null;
|
|
@@ -4750,16 +4731,9 @@ async function renderRoute(state, mod, route, srcFilePath, clientEntry, manifest
|
|
|
4750
4731
|
);
|
|
4751
4732
|
const documentModuleId = documentPath.replace(/\\/g, "/");
|
|
4752
4733
|
moduleIds.push(documentModuleId);
|
|
4753
|
-
if (state.loggingEnabled) {
|
|
4754
|
-
log(ANSI.cyan("[SSG]"), `Rendering route: ${route}`);
|
|
4755
|
-
log(ANSI.cyan("[SSG]"), ` Document module: ${documentModuleId}`);
|
|
4756
|
-
}
|
|
4757
4734
|
const ctx = {
|
|
4758
4735
|
registerModule: (moduleId) => {
|
|
4759
4736
|
moduleIds.push(moduleId);
|
|
4760
|
-
if (state.loggingEnabled) {
|
|
4761
|
-
log(ANSI.cyan("[SSG]"), ` Registered module: ${moduleId}`);
|
|
4762
|
-
}
|
|
4763
4737
|
},
|
|
4764
4738
|
registerPreloadedPageProps: (props) => {
|
|
4765
4739
|
;
|
|
@@ -4768,17 +4742,10 @@ async function renderRoute(state, mod, route, srcFilePath, clientEntry, manifest
|
|
|
4768
4742
|
};
|
|
4769
4743
|
const result = await mod.render(route, ctx);
|
|
4770
4744
|
let html = result.body;
|
|
4771
|
-
|
|
4772
|
-
log(ANSI.cyan("[SSG]"), ` Total modules tracked: ${moduleIds.length}`);
|
|
4773
|
-
}
|
|
4745
|
+
log(ANSI.cyan("[SSG]"), ` Total modules tracked: ${moduleIds.length}`);
|
|
4774
4746
|
let cssLinks = "";
|
|
4775
4747
|
if (manifest) {
|
|
4776
|
-
cssLinks = collectCssForModules(
|
|
4777
|
-
manifest,
|
|
4778
|
-
moduleIds,
|
|
4779
|
-
projectRoot,
|
|
4780
|
-
state.loggingEnabled ? log : void 0
|
|
4781
|
-
);
|
|
4748
|
+
cssLinks = collectCssForModules(manifest, moduleIds, projectRoot);
|
|
4782
4749
|
}
|
|
4783
4750
|
if (clientEntry) {
|
|
4784
4751
|
const scriptTag = `<script type="module" src="/${clientEntry}"></script>`;
|
|
@@ -4807,7 +4774,7 @@ async function appendStaticPropsToClientModules(state, clientOutDirAbs, log) {
|
|
|
4807
4774
|
try {
|
|
4808
4775
|
log(ANSI.cyan("[SSG]"), "Starting static props collection...");
|
|
4809
4776
|
const clientManifestPath = path5.resolve(clientOutDirAbs, manifestPath);
|
|
4810
|
-
if (!
|
|
4777
|
+
if (!fs3.existsSync(clientManifestPath)) {
|
|
4811
4778
|
log(
|
|
4812
4779
|
ANSI.yellow("[SSG]"),
|
|
4813
4780
|
"Client manifest not found, skipping static props"
|
|
@@ -4815,11 +4782,12 @@ async function appendStaticPropsToClientModules(state, clientOutDirAbs, log) {
|
|
|
4815
4782
|
return;
|
|
4816
4783
|
}
|
|
4817
4784
|
log(ANSI.cyan("[SSG]"), "Found client manifest at:", clientManifestPath);
|
|
4785
|
+
const { globSync } = await import("node:fs");
|
|
4818
4786
|
const srcPages = globSync(`${ssgOptions.dir}/**/${ssgOptions.page}`, {
|
|
4819
4787
|
cwd: projectRoot
|
|
4820
4788
|
}).map((s) => s.replace(/\\/g, "/"));
|
|
4821
4789
|
const manifest = JSON.parse(
|
|
4822
|
-
|
|
4790
|
+
fs3.readFileSync(clientManifestPath, "utf-8")
|
|
4823
4791
|
);
|
|
4824
4792
|
log(
|
|
4825
4793
|
ANSI.cyan("[SSG]"),
|
|
@@ -4844,7 +4812,7 @@ async function appendStaticPropsToClientModules(state, clientOutDirAbs, log) {
|
|
|
4844
4812
|
const code = `export const __KIRU_STATIC_PROPS__ = ${JSON.stringify(
|
|
4845
4813
|
staticProps
|
|
4846
4814
|
)};`;
|
|
4847
|
-
|
|
4815
|
+
fs3.appendFileSync(filePath, `
|
|
4848
4816
|
${code}`, "utf-8");
|
|
4849
4817
|
log(ANSI.cyan("[SSG]"), "Added static props to:", chunk.file);
|
|
4850
4818
|
})
|
|
@@ -4854,43 +4822,6 @@ ${code}`, "utf-8");
|
|
|
4854
4822
|
}
|
|
4855
4823
|
}
|
|
4856
4824
|
|
|
4857
|
-
// src/utils.ts
|
|
4858
|
-
import path6 from "node:path";
|
|
4859
|
-
import fs5 from "node:fs";
|
|
4860
|
-
function createLogger(state) {
|
|
4861
|
-
return (...data) => {
|
|
4862
|
-
if (!state.loggingEnabled) return;
|
|
4863
|
-
console.log(ANSI.cyan("[vite-plugin-kiru]"), ...data);
|
|
4864
|
-
};
|
|
4865
|
-
}
|
|
4866
|
-
function resolveUserDocument(projectRoot, ssgOptions) {
|
|
4867
|
-
const { dir, document } = ssgOptions;
|
|
4868
|
-
const fp = path6.resolve(projectRoot, dir, document);
|
|
4869
|
-
if (fs5.existsSync(fp)) return fp.replace(/\\/g, "/");
|
|
4870
|
-
throw new Error(`Document not found at ${fp}`);
|
|
4871
|
-
}
|
|
4872
|
-
var TRANSFORMABLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
4873
|
-
".tsx",
|
|
4874
|
-
".jsx",
|
|
4875
|
-
".ts",
|
|
4876
|
-
".js",
|
|
4877
|
-
".mjs",
|
|
4878
|
-
".mts",
|
|
4879
|
-
".md",
|
|
4880
|
-
".mdx"
|
|
4881
|
-
]);
|
|
4882
|
-
function shouldTransformFile(id, state) {
|
|
4883
|
-
if (id[0] === "\0" || id.startsWith("vite:") || id.includes("/node_modules/")) {
|
|
4884
|
-
return false;
|
|
4885
|
-
}
|
|
4886
|
-
const filePath = path6.resolve(id).replace(/\\/g, "/");
|
|
4887
|
-
const isIncludedByUser = state.includedPaths.some(
|
|
4888
|
-
(p) => filePath.startsWith(p)
|
|
4889
|
-
);
|
|
4890
|
-
const isWithinProject = filePath.startsWith(state.projectRoot);
|
|
4891
|
-
return (isWithinProject || isIncludedByUser) && TRANSFORMABLE_EXTENSIONS.has(path6.extname(filePath));
|
|
4892
|
-
}
|
|
4893
|
-
|
|
4894
4825
|
// src/index.ts
|
|
4895
4826
|
import { build } from "vite";
|
|
4896
4827
|
function kiru(opts = {}) {
|
|
@@ -4904,12 +4835,12 @@ function kiru(opts = {}) {
|
|
|
4904
4835
|
inlineConfig = config;
|
|
4905
4836
|
return createViteConfig(config, opts);
|
|
4906
4837
|
},
|
|
4907
|
-
configResolved(config) {
|
|
4838
|
+
async configResolved(config) {
|
|
4908
4839
|
const initialState = createPluginState(opts);
|
|
4909
4840
|
state = updatePluginState(initialState, config, opts);
|
|
4910
4841
|
log = createLogger(state);
|
|
4911
4842
|
if (state.ssgOptions) {
|
|
4912
|
-
virtualModules = createVirtualModules(
|
|
4843
|
+
virtualModules = await createVirtualModules(
|
|
4913
4844
|
state.projectRoot,
|
|
4914
4845
|
state.ssgOptions
|
|
4915
4846
|
);
|
|
@@ -4950,8 +4881,8 @@ function kiru(opts = {}) {
|
|
|
4950
4881
|
server.middlewares.use(async (req, res, next) => {
|
|
4951
4882
|
try {
|
|
4952
4883
|
const url = req.originalUrl || req.url || "/";
|
|
4953
|
-
const filePath =
|
|
4954
|
-
const extName =
|
|
4884
|
+
const filePath = path6.join(state.baseOutDir, "client", url);
|
|
4885
|
+
const extName = path6.extname(filePath);
|
|
4955
4886
|
if (extName && extName !== ".html") {
|
|
4956
4887
|
return next();
|
|
4957
4888
|
}
|