@pracht/vite-plugin 0.11.1 → 0.12.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.
@@ -1,6 +1,9 @@
1
+ import { PAGES_APP_CONFIG_EXPORTS, findOwningPagesShell, pagesShellName } from "@pracht/capabilities/static";
2
+
1
3
  //#region src/pages-router.d.ts
2
4
  interface ScannedPage {
3
5
  absolutePath: string;
6
+ capabilities: string[];
4
7
  relativePath: string;
5
8
  routePath: string;
6
9
  isIndex: boolean;
@@ -8,6 +11,7 @@ interface ScannedPage {
8
11
  isDynamic: boolean;
9
12
  renderMode?: string;
10
13
  hydrationMode?: string;
14
+ streaming?: boolean;
11
15
  revalidateSeconds?: number;
12
16
  hasRevalidateExport?: boolean;
13
17
  hasLoader?: boolean;
@@ -18,14 +22,114 @@ interface PagesRouterOptions {
18
22
  pagesDir: string;
19
23
  pagesDefaultRender?: string;
20
24
  additionalExtensions?: readonly string[];
25
+ /**
26
+ * Absolute path of the capabilities directory. Every module in it is
27
+ * registered as a capability. Defaults to `<pagesDir>/../capabilities`, the
28
+ * `src/pages` + `src/capabilities` layout the plugin defaults to; pass `null`
29
+ * to register none.
30
+ */
31
+ capabilitiesDir?: string | null;
21
32
  }
33
+ declare const GENERATED_PAGES_MANIFEST_MARKER = "Auto-generated from pages/ directory by @pracht/vite-plugin.";
34
+ declare const GENERATED_PAGES_LAYOUT_EXPORT = "__PRACHT_EJECTED_PAGES_LAYOUT__";
35
+ /**
36
+ * The root-level `_middleware.{ts,tsx,js,jsx}` file of a pages directory, or
37
+ * null when the app has none. Fails loudly on every shape that would
38
+ * otherwise fail open: a nested `_middleware` file, a `_middleware/`
39
+ * directory, any exact `_middleware` basename using an extension the runtime
40
+ * registry cannot load (all unsupported — they would be silently ignored while
41
+ * looking like an auth gate), and multiple root files competing for the same
42
+ * registration.
43
+ */
44
+ declare function findPagesMiddlewareFile(pagesDir: string, _additionalExtensions?: readonly string[]): string | null;
45
+ /** A discovered `_app` shell and the registration it owns. */
46
+ interface PagesAppShell {
47
+ absolutePath: string;
48
+ /** Posix directory of the shell relative to the pages directory; `""` at the root. */
49
+ directory: string;
50
+ /** Registered shell name: `pages` at the root, `pages:blog` for `blog/_app.tsx`. */
51
+ name: string;
52
+ }
53
+ /** The registered shell name for an `_app` in `directory` (posix, `""` at the root). */
54
+ /**
55
+ * Every `_app` shell in a pages directory, deepest first.
56
+ *
57
+ * An `_app` in a subdirectory owns the routes in that subtree: like a group's
58
+ * `shell` in an explicit manifest, the nearest one wins and REPLACES the
59
+ * parent rather than rendering inside it — `resolveApp()` gives every route
60
+ * exactly one shell, so file-system nesting cannot mean something the manifest
61
+ * router cannot express.
62
+ *
63
+ * Two `_app` files in the same directory are rejected: they compete for one
64
+ * registration, and picking either silently drops the other's `head()` and
65
+ * `headers()` from every route below.
66
+ */
67
+ declare function findPagesAppShellFiles(pagesDir: string, shellExtensions: ReadonlySet<string>): PagesAppShell[];
68
+ /**
69
+ * The app-level config file of a pages directory: `_app.config.ts` at the
70
+ * pages root.
71
+ *
72
+ * Named after the shell it configures, because that is what it is — the
73
+ * app-level knobs a manifest passes to `defineApp()` that no single route
74
+ * owns. It is root-only for the same reason `_middleware` is: `agents` and
75
+ * `constraints` are app-wide, so a per-directory copy would look scoped while
76
+ * being ignored.
77
+ */
78
+ declare const PAGES_APP_CONFIG_BASENAME = "_app.config";
79
+ /**
80
+ * The `defineApp` keys a pages app may set from `_app.config.ts`.
81
+ *
82
+ * Deliberately server-only keys. `notFound` is not one of them: the client
83
+ * router reads `app.notFound`, so accepting it here would pull this module —
84
+ * and its Web Bot Auth keys — into the browser bundle. `pages/404.tsx` is
85
+ * already the file convention for it.
86
+ */
87
+ interface PagesAppConfig {
88
+ absolutePath: string;
89
+ /** The subset of PAGES_APP_CONFIG_EXPORTS the module actually exports. */
90
+ exports: string[];
91
+ }
92
+ /**
93
+ * The root-level `_app.config.{ts,tsx,js,jsx}` of a pages directory, or null
94
+ * when the app has none.
95
+ *
96
+ * Fails closed on every shape that would otherwise leave an app looking
97
+ * configured while nothing is registered: a nested file, an unsupported
98
+ * extension, duplicates, a module that exports none of the supported keys, and
99
+ * a value `export *` whose names cannot be known without loading the module.
100
+ */
101
+ declare function findPagesAppConfigFile(pagesDir: string): PagesAppConfig | null;
102
+ /** A capability module auto-discovered from the capabilities directory. */
103
+ interface PagesCapability {
104
+ absolutePath: string;
105
+ name: string;
106
+ }
107
+ /**
108
+ * Every capability module in `capabilitiesDir`, keyed by the name it registers
109
+ * under.
110
+ *
111
+ * The pages router has no `capabilities` registry, so the directory *is* the
112
+ * registry: one module per capability, named by `defineCapability({ name })`
113
+ * or by its file stem. That keeps registration explicit — a file has to be in
114
+ * `src/capabilities/` to be reachable — without inventing a second place to
115
+ * repeat the name.
116
+ */
117
+ declare function findPagesCapabilityFiles(capabilitiesDir: string): PagesCapability[];
22
118
  declare function scanPagesDirectory(pagesDir: string, additionalExtensions?: readonly string[]): ScannedPage[];
23
119
  declare function filePathToRoutePath(relativePath: string): string;
24
120
  declare function sortRoutes(pages: ScannedPage[]): ScannedPage[];
25
121
  declare function generatePagesManifestSource(pages: ScannedPage[], options: PagesRouterOptions & {
122
+ /** Project-root-relative capabilities prefix (e.g. `/src/capabilities`). */capabilitiesDirPrefix?: string;
26
123
  pagesDirPrefix?: string;
124
+ referenceBaseDir?: string;
125
+ /**
126
+ * `"client"` omits the keys only the server reads (`agents`,
127
+ * `constraints`) and the `_app.config.ts` import that supplies them, so
128
+ * that module and everything it imports stay out of browser bundles.
129
+ */
130
+ target?: "server" | "client";
27
131
  useImportSyntax?: boolean;
28
132
  }): string;
29
133
  declare function generateRoutesFile(pagesDir: string, outputPath: string, options: PagesRouterOptions): void;
30
134
  //#endregion
31
- export { PagesRouterOptions, ScannedPage, filePathToRoutePath, generatePagesManifestSource, generateRoutesFile, scanPagesDirectory, sortRoutes };
135
+ export { GENERATED_PAGES_LAYOUT_EXPORT, GENERATED_PAGES_MANIFEST_MARKER, PAGES_APP_CONFIG_BASENAME, PAGES_APP_CONFIG_EXPORTS, PagesAppConfig, PagesAppShell, PagesCapability, PagesRouterOptions, ScannedPage, filePathToRoutePath, findOwningPagesShell, findPagesAppConfigFile, findPagesAppShellFiles, findPagesCapabilityFiles, findPagesMiddlewareFile, generatePagesManifestSource, generateRoutesFile, pagesShellName, scanPagesDirectory, sortRoutes };
@@ -1,2 +1,2 @@
1
- import { a as sortRoutes, i as scanPagesDirectory, n as generatePagesManifestSource, r as generateRoutesFile, t as filePathToRoutePath } from "./pages-router-MA9rOl88.mjs";
2
- export { filePathToRoutePath, generatePagesManifestSource, generateRoutesFile, scanPagesDirectory, sortRoutes };
1
+ import { a as filePathToRoutePath, c as findPagesAppShellFiles, d as generatePagesManifestSource, f as generateRoutesFile, h as sortRoutes, i as PAGES_APP_CONFIG_EXPORTS, l as findPagesCapabilityFiles, m as scanPagesDirectory, n as GENERATED_PAGES_MANIFEST_MARKER, o as findOwningPagesShell, p as pagesShellName, r as PAGES_APP_CONFIG_BASENAME, s as findPagesAppConfigFile, t as GENERATED_PAGES_LAYOUT_EXPORT, u as findPagesMiddlewareFile } from "./pages-router-BI34Cani.mjs";
2
+ export { GENERATED_PAGES_LAYOUT_EXPORT, GENERATED_PAGES_MANIFEST_MARKER, PAGES_APP_CONFIG_BASENAME, PAGES_APP_CONFIG_EXPORTS, filePathToRoutePath, findOwningPagesShell, findPagesAppConfigFile, findPagesAppShellFiles, findPagesCapabilityFiles, findPagesMiddlewareFile, generatePagesManifestSource, generateRoutesFile, pagesShellName, scanPagesDirectory, sortRoutes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pracht/vite-plugin",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "Vite plugin for Pracht apps with virtual modules, dev SSR, prerendering, route inspection, and multi-adapter builds.",
5
5
  "keywords": [
6
6
  "pracht",
@@ -42,6 +42,9 @@
42
42
  "types": "./virtual.d.ts"
43
43
  }
44
44
  },
45
+ "engines": {
46
+ "node": ">=22.18"
47
+ },
45
48
  "publishConfig": {
46
49
  "provenance": true
47
50
  },
@@ -50,10 +53,10 @@
50
53
  "@preact/preset-vite": "^2.10.5",
51
54
  "@prefresh/vite": "^2.0.0",
52
55
  "es-module-lexer": "^1.7.0",
53
- "@pracht/adapter-node": "0.4.2",
54
- "@pracht/capabilities": "0.3.0",
55
- "@pracht/core": "0.16.0",
56
- "@pracht/preact-ssr-precompile": "0.1.3"
56
+ "@pracht/adapter-node": "0.4.3",
57
+ "@pracht/capabilities": "0.4.0",
58
+ "@pracht/preact-ssr-precompile": "0.1.4",
59
+ "@pracht/core": "0.17.0"
57
60
  },
58
61
  "peerDependencies": {
59
62
  "vite": "^8.0.0"
package/virtual.d.ts CHANGED
@@ -243,8 +243,8 @@ declare module "virtual:pracht/capabilities" {
243
243
  }
244
244
 
245
245
  declare module "virtual:pracht/webmcp" {
246
- /** Registers WebMCP page tools; returns false when the API is unavailable. */
247
- export function registerPrachtWebmcpTools(): boolean;
246
+ /** Replaces the active route's WebMCP page tools; returns false when the API is unavailable. */
247
+ export function registerPrachtWebmcpTools(capabilities: readonly string[]): boolean;
248
248
  }
249
249
 
250
250
  // Preserve the ambient declaration shipped with Pracht's compatibility-level