bun-plugin-stx 0.2.857 → 0.2.858

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.
@@ -1,7 +1,8 @@
1
1
  // @bun
2
2
  // src/index.ts
3
+ import fs2 from "fs";
3
4
  import path2 from "path";
4
- import { buildWebComponents, cacheTemplate, checkCache, classifyAllScripts, defaultConfig, extractVariables, loadStxConfig, processClientScript, processDirectives, readMarkdownFile } from "@stacksjs/stx";
5
+ import { buildWebComponents, cacheTemplate, checkCache, classifyAllScripts, defaultConfig, extractVariables, loadStxConfig, processClientScript, processDirectives, readMarkdownFile, withinBundlerCallback } from "@stacksjs/stx";
5
6
 
6
7
  // src/watch.ts
7
8
  import fs from "fs";
@@ -372,7 +373,7 @@ export { content as default };
372
373
  };
373
374
  }
374
375
  });
375
- build.onLoad({ filter: /\.stx$/ }, async ({ path: filePath }) => {
376
+ const renderStxFile = async (filePath) => {
376
377
  try {
377
378
  const dependencies = new Set;
378
379
  if (options.cache && options.cachePath) {
@@ -458,6 +459,35 @@ ${scriptsHtml}`;
458
459
  loader: "html"
459
460
  };
460
461
  }
462
+ };
463
+ const prerendered = new Map;
464
+ const entryKey = (file) => {
465
+ const absolute = path2.resolve(file);
466
+ try {
467
+ return fs2.realpathSync(absolute);
468
+ } catch {
469
+ return absolute;
470
+ }
471
+ };
472
+ build.onStart(async () => {
473
+ prerendered.clear();
474
+ for (const entry of build.config.entrypoints ?? []) {
475
+ if (typeof entry !== "string" || !entry.endsWith(".stx"))
476
+ continue;
477
+ const file = path2.resolve(entry);
478
+ if (!fs2.existsSync(file))
479
+ continue;
480
+ prerendered.set(entryKey(file), await renderStxFile(file));
481
+ }
482
+ });
483
+ build.onLoad({ filter: /\.stx$/ }, async ({ path: filePath }) => {
484
+ const key = entryKey(filePath);
485
+ const ready = prerendered.get(key);
486
+ if (ready) {
487
+ prerendered.delete(key);
488
+ return ready;
489
+ }
490
+ return withinBundlerCallback(() => renderStxFile(filePath));
461
491
  });
462
492
  }
463
493
  };
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  createRoute2,
9
9
  readMarkdownFile2,
10
10
  src_default
11
- } from "./chunk-18kmm7vg.js";
11
+ } from "./chunk-xmy0ax0w.js";
12
12
  export {
13
13
  createMiddleware2 as createMiddleware,
14
14
  createRoute2 as createRoute,
package/dist/preload.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  src_default
4
- } from "./chunk-18kmm7vg.js";
4
+ } from "./chunk-xmy0ax0w.js";
5
5
 
6
6
  // src/preload.ts
7
7
  var {plugin } = globalThis.Bun;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.857",
4
+ "version": "0.2.858",
5
5
  "description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -74,7 +74,7 @@
74
74
  "typecheck": "bun tsc --noEmit"
75
75
  },
76
76
  "dependencies": {
77
- "@stacksjs/stx": "0.2.857",
78
- "stx-router": "0.2.857"
77
+ "@stacksjs/stx": "0.2.858",
78
+ "stx-router": "0.2.858"
79
79
  }
80
80
  }