vite-plugin-kiru 0.29.5 → 0.29.7

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 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 path7 from "node:path";
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,49 @@ function tEntries(obj) {
2171
2171
  // src/config.ts
2172
2172
  import path2 from "node:path";
2173
2173
 
2174
- // src/virtual-modules.ts
2174
+ // src/utils.ts
2175
2175
  import path from "node:path";
2176
2176
  import fs2 from "node:fs";
2177
+ function createLogger(state) {
2178
+ return (...data) => {
2179
+ if (!state.loggingEnabled) return;
2180
+ console.log(ANSI.cyan("[vite-plugin-kiru]"), ...data);
2181
+ };
2182
+ }
2183
+ function resolveUserDocument(projectRoot, ssgOptions) {
2184
+ const { dir, document } = ssgOptions;
2185
+ const fp = path.resolve(projectRoot, dir, document);
2186
+ const res = fs2.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
2216
  function createVirtualModules(projectRoot, ssgOptions) {
2181
- function resolveUserDocument2() {
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
- }
2187
2217
  function createRoutesModule() {
2188
2218
  const { dir, baseUrl, page, layout, transition } = ssgOptions;
2189
2219
  return `
@@ -2201,7 +2231,7 @@ export { dir, baseUrl, pages, layouts, transition }
2201
2231
  `;
2202
2232
  }
2203
2233
  function createEntryServerModule() {
2204
- const userDoc = resolveUserDocument2();
2234
+ const userDoc = resolveUserDocument(projectRoot, ssgOptions);
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 "${resolveUserDocument2()}"
2257
+ import "${resolveUserDocument(projectRoot, ssgOptions)}"
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 = (path8, line) => `vscode://file/${path8}:${line}`;
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;
@@ -4447,12 +4477,12 @@ var Mime = class {
4447
4477
  }
4448
4478
  return this;
4449
4479
  }
4450
- getType(path8) {
4451
- if (typeof path8 !== "string")
4480
+ getType(path7) {
4481
+ if (typeof path7 !== "string")
4452
4482
  return null;
4453
- const last = path8.replace(/^.*[/\\]/s, "").toLowerCase();
4483
+ const last = path7.replace(/^.*[/\\]/s, "").toLowerCase();
4454
4484
  const ext = last.replace(/^.*\./s, "").toLowerCase();
4455
- const hasPath = last.length < path8.length;
4485
+ const hasPath = last.length < path7.length;
4456
4486
  const hasDot = ext.length < last.length - 1;
4457
4487
  if (!hasDot && hasPath)
4458
4488
  return null;
@@ -4623,44 +4653,22 @@ async function getClientAssets(clientOutDirAbs, manifestPath) {
4623
4653
  }
4624
4654
  return { clientEntry };
4625
4655
  }
4626
- function collectCssForModules(manifest, moduleIds, projectRoot, log) {
4656
+ function collectCssForModules(manifest, moduleIds, projectRoot) {
4627
4657
  const seen = /* @__PURE__ */ new Set();
4628
4658
  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
4659
  const collectCss = (key) => {
4637
4660
  if (seen.has(key)) return;
4638
4661
  seen.add(key);
4639
4662
  const it = manifest[key];
4640
4663
  if (!it) {
4641
- if (log)
4642
- log(ANSI.yellow("[SSG CSS]"), ` Key not found in manifest: ${key}`);
4643
4664
  return;
4644
4665
  }
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
4666
  ;
4658
4667
  (it.css || []).forEach((c) => cssFiles.add(c));
4659
4668
  (it.imports || []).forEach((imp) => collectCss(imp));
4660
4669
  };
4661
4670
  const entryClientKey = "virtual:kiru:entry-client";
4662
4671
  if (manifest[entryClientKey] && !seen.has(entryClientKey)) {
4663
- if (log) log(ANSI.yellow("[SSG CSS]"), `Including entry client CSS`);
4664
4672
  collectCss(entryClientKey);
4665
4673
  }
4666
4674
  for (const moduleId of moduleIds) {
@@ -4671,27 +4679,16 @@ function collectCssForModules(manifest, moduleIds, projectRoot, log) {
4671
4679
  if (normalizedId.startsWith("/")) {
4672
4680
  normalizedId = normalizedId.substring(1);
4673
4681
  }
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
4682
  if (manifest[normalizedId]) {
4680
- if (log) log(ANSI.green("[SSG CSS]"), ` \u2713 Found as: ${normalizedId}`);
4681
4683
  collectCss(normalizedId);
4682
- found = true;
4683
4684
  continue;
4684
4685
  }
4685
4686
  if (manifest["/" + normalizedId]) {
4686
- if (log) log(ANSI.green("[SSG CSS]"), ` \u2713 Found as: /${normalizedId}`);
4687
4687
  collectCss("/" + normalizedId);
4688
- found = true;
4689
4688
  continue;
4690
4689
  }
4691
4690
  if (manifest[moduleId]) {
4692
- if (log) log(ANSI.green("[SSG CSS]"), ` \u2713 Found as: ${moduleId}`);
4693
4691
  collectCss(moduleId);
4694
- found = true;
4695
4692
  continue;
4696
4693
  }
4697
4694
  for (const key in manifest) {
@@ -4699,33 +4696,15 @@ function collectCssForModules(manifest, moduleIds, projectRoot, log) {
4699
4696
  const moduleBaseName = path5.basename(normalizedId);
4700
4697
  const keyBaseName = path5.basename(keyNormalized);
4701
4698
  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
4699
  collectCss(key);
4705
- found = true;
4706
4700
  break;
4707
4701
  }
4708
4702
  }
4709
- if (!found && log) {
4710
- log(
4711
- ANSI.red("[SSG CSS]"),
4712
- ` \u2717 Module not found in manifest: ${moduleId}`
4713
- );
4714
- }
4715
4703
  }
4716
4704
  if (cssFiles.size) {
4717
4705
  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
4706
  return links;
4725
4707
  }
4726
- if (log) {
4727
- log(ANSI.yellow("[SSG CSS]"), "No CSS files collected");
4728
- }
4729
4708
  return "";
4730
4709
  }
4731
4710
  function findClientEntry(dir) {
@@ -4750,16 +4729,9 @@ async function renderRoute(state, mod, route, srcFilePath, clientEntry, manifest
4750
4729
  );
4751
4730
  const documentModuleId = documentPath.replace(/\\/g, "/");
4752
4731
  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
4732
  const ctx = {
4758
4733
  registerModule: (moduleId) => {
4759
4734
  moduleIds.push(moduleId);
4760
- if (state.loggingEnabled) {
4761
- log(ANSI.cyan("[SSG]"), ` Registered module: ${moduleId}`);
4762
- }
4763
4735
  },
4764
4736
  registerPreloadedPageProps: (props) => {
4765
4737
  ;
@@ -4768,17 +4740,10 @@ async function renderRoute(state, mod, route, srcFilePath, clientEntry, manifest
4768
4740
  };
4769
4741
  const result = await mod.render(route, ctx);
4770
4742
  let html = result.body;
4771
- if (state.loggingEnabled) {
4772
- log(ANSI.cyan("[SSG]"), ` Total modules tracked: ${moduleIds.length}`);
4773
- }
4743
+ log(ANSI.cyan("[SSG]"), ` Total modules tracked: ${moduleIds.length}`);
4774
4744
  let cssLinks = "";
4775
4745
  if (manifest) {
4776
- cssLinks = collectCssForModules(
4777
- manifest,
4778
- moduleIds,
4779
- projectRoot,
4780
- state.loggingEnabled ? log : void 0
4781
- );
4746
+ cssLinks = collectCssForModules(manifest, moduleIds, projectRoot);
4782
4747
  }
4783
4748
  if (clientEntry) {
4784
4749
  const scriptTag = `<script type="module" src="/${clientEntry}"></script>`;
@@ -4854,35 +4819,6 @@ ${code}`, "utf-8");
4854
4819
  }
4855
4820
  }
4856
4821
 
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
- function shouldTransformFile(id, state) {
4873
- if (id.startsWith("\0") || id.startsWith("vite:") || id.includes("/node_modules/")) {
4874
- return false;
4875
- }
4876
- if (!/\.[cm]?[jt]sx?$/.test(id)) {
4877
- return false;
4878
- }
4879
- const filePath = path6.resolve(id).replace(/\\/g, "/");
4880
- const isIncludedByUser = state.includedPaths.some(
4881
- (p) => filePath.startsWith(p)
4882
- );
4883
- return isIncludedByUser || filePath.startsWith(state.projectRoot);
4884
- }
4885
-
4886
4822
  // src/index.ts
4887
4823
  import { build } from "vite";
4888
4824
  function kiru(opts = {}) {
@@ -4942,8 +4878,8 @@ function kiru(opts = {}) {
4942
4878
  server.middlewares.use(async (req, res, next) => {
4943
4879
  try {
4944
4880
  const url = req.originalUrl || req.url || "/";
4945
- const filePath = path7.join(state.baseOutDir, "client", url);
4946
- const extName = path7.extname(filePath);
4881
+ const filePath = path6.join(state.baseOutDir, "client", url);
4882
+ const extName = path6.extname(filePath);
4947
4883
  if (extName && extName !== ".html") {
4948
4884
  return next();
4949
4885
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-kiru",
3
- "version": "0.29.5",
3
+ "version": "0.29.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -17,8 +17,8 @@
17
17
  "rollup": "^4.46.2",
18
18
  "tsx": "^4.20.3",
19
19
  "typescript": "^5.9.2",
20
- "kiru-devtools-host": "^1.0.0",
21
- "kiru-devtools-client": "^0.0.0"
20
+ "kiru-devtools-client": "^0.0.0",
21
+ "kiru-devtools-host": "^1.0.0"
22
22
  },
23
23
  "dependencies": {
24
24
  "magic-string": "^0.30.17",