bun-plugin-stx 0.2.317 → 0.2.318

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.
@@ -205,10 +205,25 @@ class Router {
205
205
  this.pagesDirs = rawDirs.map((d) => path4.resolve(baseDir, d));
206
206
  this.pagesDir = this.pagesDirs[0];
207
207
  const extensions = config.extensions || [".stx"];
208
+ const canonical = (entry) => {
209
+ const resolved = path4.resolve(baseDir, entry);
210
+ try {
211
+ return fs3.realpathSync(resolved);
212
+ } catch {
213
+ return resolved;
214
+ }
215
+ };
216
+ const excluded = (config.exclude ?? []).filter((entry) => typeof entry === "string" && entry.trim() !== "").map(canonical);
217
+ const isExcluded = (file) => {
218
+ if (excluded.length === 0)
219
+ return false;
220
+ const real = canonical(file);
221
+ return excluded.some((root) => real === root || real.startsWith(`${root}${path4.sep}`));
222
+ };
208
223
  const seenPatterns = new Set;
209
224
  this.routes = [];
210
225
  for (const dir of this.pagesDirs) {
211
- const files = scanDirectory(dir, extensions);
226
+ const files = scanDirectory(dir, extensions).filter((file) => !isExcluded(file));
212
227
  const localPatterns = new Map;
213
228
  for (const filePath of files) {
214
229
  const pattern = filePathToPattern(filePath, dir);
package/dist/serve.d.ts CHANGED
@@ -175,6 +175,14 @@ export declare function boundedCache<T>(limit: number): {
175
175
  clear: () => void
176
176
  readonly size: number
177
177
  };
178
+ /**
179
+ * A predicate over discovered page files for {@link ServeOptions.exclude}.
180
+ *
181
+ * Paths are compared resolved, because patterns and exclusions reach serve()
182
+ * spelled however the caller built them - relative, absolute, with a trailing
183
+ * slash - and a spelling mismatch must not quietly put a page back.
184
+ */
185
+ export declare function pageExcluder(exclude: readonly string[] | undefined, cwd?: string): (file: string) => boolean;
178
186
  export declare function resolveServeOpenUrl(port: number, openPath?: string): string;
179
187
  /**
180
188
  * Did rendering fail?
@@ -271,6 +279,7 @@ export declare interface ServeRequestContext {
271
279
  }
272
280
  export declare interface ServeOptions {
273
281
  patterns: string[]
282
+ exclude?: string[]
274
283
  port?: number
275
284
  openPath?: string
276
285
  componentsDir?: string
package/dist/serve.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  // src/serve.ts
11
11
  var {serve: bunServe, Glob } = globalThis.Bun;
12
- import { existsSync as existsSync2, watch as fsWatch, statSync as statSync3 } from "fs";
12
+ import { existsSync as existsSync2, watch as fsWatch, realpathSync, statSync as statSync3 } from "fs";
13
13
  import nodeFs from "fs/promises";
14
14
  import nodePath from "path";
15
15
  import process19 from "process";
@@ -9084,6 +9084,23 @@ function boundedCache(limit) {
9084
9084
  }
9085
9085
  };
9086
9086
  }
9087
+ function pageExcluder(exclude, cwd = process19.cwd()) {
9088
+ const canonical = (entry) => {
9089
+ const resolved = nodePath.resolve(cwd, entry);
9090
+ try {
9091
+ return realpathSync(resolved);
9092
+ } catch {
9093
+ return resolved;
9094
+ }
9095
+ };
9096
+ const roots = (exclude ?? []).filter((entry) => typeof entry === "string" && entry.trim() !== "").map(canonical);
9097
+ if (roots.length === 0)
9098
+ return () => false;
9099
+ return (file) => {
9100
+ const resolved = canonical(file);
9101
+ return roots.some((root) => resolved === root || resolved.startsWith(`${root}${nodePath.sep}`));
9102
+ };
9103
+ }
9087
9104
  function resolveServeOpenUrl(port, openPath = "/") {
9088
9105
  const baseUrl = `http://localhost:${port}`;
9089
9106
  try {
@@ -9267,6 +9284,7 @@ After installing: bun add bun-plugin-stx`);
9267
9284
  throw new Error("No file patterns provided");
9268
9285
  }
9269
9286
  let sourceFiles = null;
9287
+ const isExcludedPage = pageExcluder(options.exclude);
9270
9288
  let discoveredPagePaths = null;
9271
9289
  let assetsInitialized = false;
9272
9290
  const htmlCache = new Map;
@@ -9718,19 +9736,20 @@ function __stxOverlay(errs){
9718
9736
  console.error(`Error processing pattern "${pattern}":`, error);
9719
9737
  }
9720
9738
  }
9721
- sourceFiles = files;
9722
- rebuildDiscoveredPagePaths(files);
9739
+ const kept = files.filter((f) => !isExcludedPage(f));
9740
+ sourceFiles = kept;
9741
+ rebuildDiscoveredPagePaths(kept);
9723
9742
  pageMiddlewareByPath.clear();
9724
9743
  pageMiddlewarePatterns.length = 0;
9725
- await Promise.all(files.map((f) => detectPageMiddleware(f)));
9744
+ await Promise.all(kept.map((f) => detectPageMiddleware(f)));
9726
9745
  try {
9727
- const { Router } = await import("./chunk-9gb1t22q.js");
9746
+ const { Router } = await import("./chunk-37vp8yms.js");
9728
9747
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9729
- const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName() });
9748
+ const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName(), exclude: options.exclude });
9730
9749
  if (!options.quiet)
9731
9750
  console.log(`[stx] Generated ${router.routes.length} routes \u2192 ${nodePath.join(stateDirName(), "routes.ts")}`);
9732
9751
  } catch (e) {}
9733
- return files;
9752
+ return kept;
9734
9753
  }
9735
9754
  async function ensureAssets() {
9736
9755
  if (assetsInitialized)
@@ -11185,6 +11204,7 @@ export {
11185
11204
  render404Page,
11186
11205
  publicFileExists,
11187
11206
  projectUsesImageBuiltins,
11207
+ pageExcluder,
11188
11208
  isStaticAssetPath,
11189
11209
  isRenderableCacheCandidate,
11190
11210
  isRenderFailure,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.317",
4
+ "version": "0.2.318",
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",