vite-plugin-kiru 0.30.1 → 0.32.0-preview.0

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/server.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import type { Readable } from "node:stream"
2
-
3
1
  export interface SSRHttpResponse {
4
2
  html: string
5
3
  statusCode: number
6
4
  headers: Array<[string, string]>
7
- stream: Readable
5
+ stream: ReadableStream | null
8
6
  }
9
7
 
10
8
  export interface SSRRenderResult {
@@ -13,6 +11,7 @@ export interface SSRRenderResult {
13
11
 
14
12
  export interface ServerRenderOptions {
15
13
  url: string
14
+ context: Kiru.RequestContext
16
15
  }
17
16
 
18
17
  export declare function renderPage(
package/dist/server.js CHANGED
@@ -1,9 +1,6 @@
1
1
  // src/server.ts
2
- import path3 from "node:path";
3
- import fs from "node:fs";
4
-
5
- // src/utils.ts
6
2
  import path2 from "node:path";
3
+ import fs from "node:fs";
7
4
 
8
5
  // ../../node_modules/.pnpm/@isaacs+balanced-match@4.0.1/node_modules/@isaacs/balanced-match/dist/esm/index.js
9
6
  var balanced = (a, b, str) => {
@@ -1557,7 +1554,7 @@ minimatch.Minimatch = Minimatch;
1557
1554
  minimatch.escape = escape;
1558
1555
  minimatch.unescape = unescape;
1559
1556
 
1560
- // ../../node_modules/.pnpm/glob@11.0.3/node_modules/glob/dist/esm/glob.js
1557
+ // ../../node_modules/.pnpm/glob@12.0.0/node_modules/glob/dist/esm/glob.js
1561
1558
  import { fileURLToPath as fileURLToPath2 } from "node:url";
1562
1559
 
1563
1560
  // ../../node_modules/.pnpm/lru-cache@11.2.2/node_modules/lru-cache/dist/esm/index.js
@@ -4111,12 +4108,12 @@ var PathBase = class {
4111
4108
  /**
4112
4109
  * Get the Path object referenced by the string path, resolved from this Path
4113
4110
  */
4114
- resolve(path4) {
4115
- if (!path4) {
4111
+ resolve(path3) {
4112
+ if (!path3) {
4116
4113
  return this;
4117
4114
  }
4118
- const rootPath = this.getRootString(path4);
4119
- const dir = path4.substring(rootPath.length);
4115
+ const rootPath = this.getRootString(path3);
4116
+ const dir = path3.substring(rootPath.length);
4120
4117
  const dirParts = dir.split(this.splitSep);
4121
4118
  const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
4122
4119
  return result;
@@ -4868,8 +4865,8 @@ var PathWin32 = class _PathWin32 extends PathBase {
4868
4865
  /**
4869
4866
  * @internal
4870
4867
  */
4871
- getRootString(path4) {
4872
- return win32.parse(path4).root;
4868
+ getRootString(path3) {
4869
+ return win32.parse(path3).root;
4873
4870
  }
4874
4871
  /**
4875
4872
  * @internal
@@ -4915,8 +4912,8 @@ var PathPosix = class _PathPosix extends PathBase {
4915
4912
  /**
4916
4913
  * @internal
4917
4914
  */
4918
- getRootString(path4) {
4919
- return path4.startsWith("/") ? "/" : "";
4915
+ getRootString(path3) {
4916
+ return path3.startsWith("/") ? "/" : "";
4920
4917
  }
4921
4918
  /**
4922
4919
  * @internal
@@ -5005,11 +5002,11 @@ var PathScurryBase = class {
5005
5002
  /**
5006
5003
  * Get the depth of a provided path, string, or the cwd
5007
5004
  */
5008
- depth(path4 = this.cwd) {
5009
- if (typeof path4 === "string") {
5010
- path4 = this.cwd.resolve(path4);
5005
+ depth(path3 = this.cwd) {
5006
+ if (typeof path3 === "string") {
5007
+ path3 = this.cwd.resolve(path3);
5011
5008
  }
5012
- return path4.depth();
5009
+ return path3.depth();
5013
5010
  }
5014
5011
  /**
5015
5012
  * Return the cache of child entries. Exposed so subclasses can create
@@ -5496,9 +5493,9 @@ var PathScurryBase = class {
5496
5493
  process2();
5497
5494
  return results;
5498
5495
  }
5499
- chdir(path4 = this.cwd) {
5496
+ chdir(path3 = this.cwd) {
5500
5497
  const oldCwd = this.cwd;
5501
- this.cwd = typeof path4 === "string" ? this.cwd.resolve(path4) : path4;
5498
+ this.cwd = typeof path3 === "string" ? this.cwd.resolve(path3) : path3;
5502
5499
  this.cwd[setAsCwd](oldCwd);
5503
5500
  }
5504
5501
  };
@@ -5572,7 +5569,7 @@ var PathScurryDarwin = class extends PathScurryPosix {
5572
5569
  var Path = process.platform === "win32" ? PathWin32 : PathPosix;
5573
5570
  var PathScurry = process.platform === "win32" ? PathScurryWin32 : process.platform === "darwin" ? PathScurryDarwin : PathScurryPosix;
5574
5571
 
5575
- // ../../node_modules/.pnpm/glob@11.0.3/node_modules/glob/dist/esm/pattern.js
5572
+ // ../../node_modules/.pnpm/glob@12.0.0/node_modules/glob/dist/esm/pattern.js
5576
5573
  var isPatternList = (pl) => pl.length >= 1;
5577
5574
  var isGlobList = (gl) => gl.length >= 1;
5578
5575
  var Pattern = class _Pattern {
@@ -5737,7 +5734,7 @@ var Pattern = class _Pattern {
5737
5734
  }
5738
5735
  };
5739
5736
 
5740
- // ../../node_modules/.pnpm/glob@11.0.3/node_modules/glob/dist/esm/ignore.js
5737
+ // ../../node_modules/.pnpm/glob@12.0.0/node_modules/glob/dist/esm/ignore.js
5741
5738
  var defaultPlatform2 = typeof process === "object" && process && typeof process.platform === "string" ? process.platform : "linux";
5742
5739
  var Ignore = class {
5743
5740
  relative;
@@ -5824,7 +5821,7 @@ var Ignore = class {
5824
5821
  }
5825
5822
  };
5826
5823
 
5827
- // ../../node_modules/.pnpm/glob@11.0.3/node_modules/glob/dist/esm/processor.js
5824
+ // ../../node_modules/.pnpm/glob@12.0.0/node_modules/glob/dist/esm/processor.js
5828
5825
  var HasWalkedCache = class _HasWalkedCache {
5829
5826
  store;
5830
5827
  constructor(store = /* @__PURE__ */ new Map()) {
@@ -5854,8 +5851,8 @@ var MatchRecord = class {
5854
5851
  }
5855
5852
  // match, absolute, ifdir
5856
5853
  entries() {
5857
- return [...this.store.entries()].map(([path4, n]) => [
5858
- path4,
5854
+ return [...this.store.entries()].map(([path3, n]) => [
5855
+ path3,
5859
5856
  !!(n & 2),
5860
5857
  !!(n & 1)
5861
5858
  ]);
@@ -6045,7 +6042,7 @@ var Processor = class _Processor {
6045
6042
  }
6046
6043
  };
6047
6044
 
6048
- // ../../node_modules/.pnpm/glob@11.0.3/node_modules/glob/dist/esm/walker.js
6045
+ // ../../node_modules/.pnpm/glob@12.0.0/node_modules/glob/dist/esm/walker.js
6049
6046
  var makeIgnore = (ignore, opts) => typeof ignore === "string" ? new Ignore([ignore], opts) : Array.isArray(ignore) ? new Ignore(ignore, opts) : ignore;
6050
6047
  var GlobUtil = class {
6051
6048
  path;
@@ -6060,9 +6057,9 @@ var GlobUtil = class {
6060
6057
  signal;
6061
6058
  maxDepth;
6062
6059
  includeChildMatches;
6063
- constructor(patterns, path4, opts) {
6060
+ constructor(patterns, path3, opts) {
6064
6061
  this.patterns = patterns;
6065
- this.path = path4;
6062
+ this.path = path3;
6066
6063
  this.opts = opts;
6067
6064
  this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
6068
6065
  this.includeChildMatches = opts.includeChildMatches !== false;
@@ -6081,11 +6078,11 @@ var GlobUtil = class {
6081
6078
  });
6082
6079
  }
6083
6080
  }
6084
- #ignored(path4) {
6085
- return this.seen.has(path4) || !!this.#ignore?.ignored?.(path4);
6081
+ #ignored(path3) {
6082
+ return this.seen.has(path3) || !!this.#ignore?.ignored?.(path3);
6086
6083
  }
6087
- #childrenIgnored(path4) {
6088
- return !!this.#ignore?.childrenIgnored?.(path4);
6084
+ #childrenIgnored(path3) {
6085
+ return !!this.#ignore?.childrenIgnored?.(path3);
6089
6086
  }
6090
6087
  // backpressure mechanism
6091
6088
  pause() {
@@ -6300,8 +6297,8 @@ var GlobUtil = class {
6300
6297
  };
6301
6298
  var GlobWalker = class extends GlobUtil {
6302
6299
  matches = /* @__PURE__ */ new Set();
6303
- constructor(patterns, path4, opts) {
6304
- super(patterns, path4, opts);
6300
+ constructor(patterns, path3, opts) {
6301
+ super(patterns, path3, opts);
6305
6302
  }
6306
6303
  matchEmit(e) {
6307
6304
  this.matches.add(e);
@@ -6338,8 +6335,8 @@ var GlobWalker = class extends GlobUtil {
6338
6335
  };
6339
6336
  var GlobStream = class extends GlobUtil {
6340
6337
  results;
6341
- constructor(patterns, path4, opts) {
6342
- super(patterns, path4, opts);
6338
+ constructor(patterns, path3, opts) {
6339
+ super(patterns, path3, opts);
6343
6340
  this.results = new Minipass({
6344
6341
  signal: this.signal,
6345
6342
  objectMode: true
@@ -6372,7 +6369,7 @@ var GlobStream = class extends GlobUtil {
6372
6369
  }
6373
6370
  };
6374
6371
 
6375
- // ../../node_modules/.pnpm/glob@11.0.3/node_modules/glob/dist/esm/glob.js
6372
+ // ../../node_modules/.pnpm/glob@12.0.0/node_modules/glob/dist/esm/glob.js
6376
6373
  var defaultPlatform3 = typeof process === "object" && process && typeof process.platform === "string" ? process.platform : "linux";
6377
6374
  var Glob = class {
6378
6375
  absolute;
@@ -6572,7 +6569,7 @@ var Glob = class {
6572
6569
  }
6573
6570
  };
6574
6571
 
6575
- // ../../node_modules/.pnpm/glob@11.0.3/node_modules/glob/dist/esm/has-magic.js
6572
+ // ../../node_modules/.pnpm/glob@12.0.0/node_modules/glob/dist/esm/has-magic.js
6576
6573
  var hasMagic = (pattern, options = {}) => {
6577
6574
  if (!Array.isArray(pattern)) {
6578
6575
  pattern = [pattern];
@@ -6584,7 +6581,7 @@ var hasMagic = (pattern, options = {}) => {
6584
6581
  return false;
6585
6582
  };
6586
6583
 
6587
- // ../../node_modules/.pnpm/glob@11.0.3/node_modules/glob/dist/esm/index.js
6584
+ // ../../node_modules/.pnpm/glob@12.0.0/node_modules/glob/dist/esm/index.js
6588
6585
  function globStreamSync(pattern, options = {}) {
6589
6586
  return new Glob(pattern, options).streamSync();
6590
6587
  }
@@ -6660,17 +6657,6 @@ function tEntries(obj) {
6660
6657
  return Object.entries(obj);
6661
6658
  }
6662
6659
 
6663
- // src/utils.ts
6664
- function resolveUserDocument(projectRoot, options) {
6665
- const { dir, document } = options;
6666
- const fp = path2.resolve(projectRoot, dir, document).replace(/\\/g, "/");
6667
- const matches = globSync(fp);
6668
- if (!matches.length) {
6669
- throw new Error(`Document not found at ${fp}`);
6670
- }
6671
- return path2.resolve(projectRoot, matches[0]).replace(/\\/g, "/");
6672
- }
6673
-
6674
6660
  // src/virtual-modules.ts
6675
6661
  var VIRTUAL_ENTRY_CLIENT_ID = "virtual:kiru:entry-client";
6676
6662
 
@@ -6692,15 +6678,14 @@ async function getClientAssets(clientOutDirAbs, manifestPath) {
6692
6678
  let clientEntry = null;
6693
6679
  let manifest = null;
6694
6680
  try {
6695
- const clientManifestPath = path3.resolve(clientOutDirAbs, manifestPath);
6681
+ const clientManifestPath = path2.resolve(clientOutDirAbs, manifestPath);
6696
6682
  if (fs.existsSync(clientManifestPath)) {
6697
6683
  const parsedManifest = JSON.parse(
6698
6684
  fs.readFileSync(clientManifestPath, "utf-8")
6699
6685
  );
6700
6686
  manifest = parsedManifest;
6701
- const clientEntryKey = "virtual:kiru:entry-client";
6702
- if (parsedManifest[clientEntryKey]?.file) {
6703
- clientEntry = parsedManifest[clientEntryKey].file;
6687
+ if (parsedManifest[VIRTUAL_ENTRY_CLIENT_ID]?.file) {
6688
+ clientEntry = parsedManifest[VIRTUAL_ENTRY_CLIENT_ID].file;
6704
6689
  }
6705
6690
  }
6706
6691
  } catch {
@@ -6723,7 +6708,7 @@ function collectCssForModules(manifest, moduleIds, projectRoot) {
6723
6708
  (it.css || []).forEach((c) => cssFiles.add(c));
6724
6709
  (it.imports || []).forEach((imp) => collectCss(imp));
6725
6710
  };
6726
- const entryClientKey = "virtual:kiru:entry-client";
6711
+ const entryClientKey = VIRTUAL_ENTRY_CLIENT_ID;
6727
6712
  if (manifestRef[entryClientKey] && !seen.has(entryClientKey)) {
6728
6713
  collectCss(entryClientKey);
6729
6714
  }
@@ -6749,8 +6734,8 @@ function collectCssForModules(manifest, moduleIds, projectRoot) {
6749
6734
  }
6750
6735
  for (const key in manifestRef) {
6751
6736
  const keyNormalized = key.replace(/\\/g, "/");
6752
- const moduleBaseName = path3.basename(normalizedId);
6753
- const keyBaseName = path3.basename(keyNormalized);
6737
+ const moduleBaseName = path2.basename(normalizedId);
6738
+ const keyBaseName = path2.basename(keyNormalized);
6754
6739
  if ((keyNormalized.endsWith(normalizedId) || normalizedId.endsWith(keyNormalized)) && moduleBaseName === keyBaseName) {
6755
6740
  collectCss(key);
6756
6741
  break;
@@ -6764,16 +6749,12 @@ function collectCssForModules(manifest, moduleIds, projectRoot) {
6764
6749
  return "";
6765
6750
  }
6766
6751
  async function renderPage(options) {
6767
- const { render } = await import("virtual:kiru:entry-server");
6768
- const moduleIds = [];
6752
+ const { render, documentModuleId } = await import("virtual:kiru:entry-server");
6753
+ const moduleIds = [documentModuleId];
6769
6754
  const projectRoot = process.cwd().replace(/\\/g, "/");
6770
- const documentModule = resolveUserDocument(projectRoot, {
6771
- dir: "src/pages",
6772
- document: "document.tsx"
6773
- }).substring(projectRoot.length);
6774
- moduleIds.push(documentModule);
6775
6755
  const { httpResponse } = await render(options.url, {
6776
- registerModule: (moduleId) => {
6756
+ userContext: options.context,
6757
+ registerModule(moduleId) {
6777
6758
  moduleIds.push(moduleId);
6778
6759
  }
6779
6760
  });
@@ -6785,7 +6766,7 @@ async function renderPage(options) {
6785
6766
  const isDevelopment = process.env.NODE_ENV !== "production";
6786
6767
  let html = httpResponse.html;
6787
6768
  if (isDevelopment) {
6788
- const scriptTag = `<script type="module" src="/@id/${VIRTUAL_ENTRY_CLIENT_ID}"></script>`;
6769
+ const scriptTag = `<script type="module" src="/@id/${VIRTUAL_ENTRY_CLIENT_ID}" async></script>`;
6789
6770
  html = html.includes("</body>") ? html.replace("</body>", scriptTag + "</body>") : html + scriptTag;
6790
6771
  const importedModules = /* @__PURE__ */ new Set();
6791
6772
  const seen = /* @__PURE__ */ new Set();
@@ -6799,7 +6780,7 @@ async function renderPage(options) {
6799
6780
  }
6800
6781
  };
6801
6782
  for (const id of moduleIds) {
6802
- const p = path3.join(projectRoot, id).replace(/\\/g, "/");
6783
+ const p = path2.join(projectRoot, id).replace(/\\/g, "/");
6803
6784
  const mod = VITE_DEV_SERVER_INSTANCE.current.moduleGraph.getModuleById(p);
6804
6785
  if (!mod) {
6805
6786
  console.error(`Module not found: ${p}`);
@@ -6819,7 +6800,7 @@ async function renderPage(options) {
6819
6800
  html = html.replace("<head>", "<head>" + stylesheets.join("\n"));
6820
6801
  }
6821
6802
  } else {
6822
- const clientOutDirAbs = path3.resolve(projectRoot, "dist/client");
6803
+ const clientOutDirAbs = path2.resolve(projectRoot, "dist/client");
6823
6804
  const { clientEntry, manifest } = await getClientAssets(
6824
6805
  clientOutDirAbs,
6825
6806
  "vite-manifest.json"
@@ -6831,10 +6812,15 @@ async function renderPage(options) {
6831
6812
  }
6832
6813
  }
6833
6814
  if (clientEntry) {
6834
- const scriptTag = `<script type="module" src="/${clientEntry}"></script>`;
6815
+ const scriptTag = `<script type="module" src="/${clientEntry}" async></script>`;
6835
6816
  html = html.includes("</body>") ? html.replace("</body>", scriptTag + "</body>") : html + scriptTag;
6836
6817
  }
6837
6818
  }
6819
+ const contextString = JSON.stringify(options.context);
6820
+ html = html.replace(
6821
+ "</head>",
6822
+ `<script type="application/json" k-request-context>${contextString}</script></head>`
6823
+ );
6838
6824
  return {
6839
6825
  httpResponse: {
6840
6826
  ...httpResponse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-kiru",
3
- "version": "0.30.1",
3
+ "version": "0.32.0-preview.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -8,8 +8,18 @@
8
8
  "keywords": [],
9
9
  "author": "",
10
10
  "license": "ISC",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./server": {
17
+ "types": "./dist/server.d.ts",
18
+ "default": "./dist/server.js"
19
+ }
20
+ },
11
21
  "peerDependencies": {
12
- "kiru": ">=0.51.8"
22
+ "kiru": ">=0.54.0-preview.0"
13
23
  },
14
24
  "devDependencies": {
15
25
  "@types/node": "^22.17.0",
@@ -18,7 +28,8 @@
18
28
  "tsx": "^4.20.3",
19
29
  "typescript": "^5.9.2",
20
30
  "kiru-devtools-client": "^0.0.0",
21
- "kiru-devtools-host": "^1.0.0"
31
+ "kiru-devtools-host": "^1.0.0",
32
+ "kiru": "^0.54.0-preview.0"
22
33
  },
23
34
  "dependencies": {
24
35
  "glob": "^12.0.0",