@yak-io/nextjs 0.1.1 → 0.1.2
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
|
@@ -169,7 +169,7 @@ Use the CLI when you prefer to pre-compute a manifest at build time. The JSON ma
|
|
|
169
169
|
**Options:**
|
|
170
170
|
- `--app-dir <path>` – Path to Next.js app directory (default: `./src/app`)
|
|
171
171
|
- `--pages-dir <path>` – Path to Next.js pages directory (optional, scanned in addition to app-dir)
|
|
172
|
-
- `--output <path>` – Output file path (default: `./
|
|
172
|
+
- `--output <path>` – Output file path (default: `./yak-routes-manifest.json`)
|
|
173
173
|
|
|
174
174
|
**Examples:**
|
|
175
175
|
```bash
|
|
@@ -197,19 +197,22 @@ Add a `prebuild` script to generate the manifest before Next.js builds:
|
|
|
197
197
|
}
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
This uses the defaults (`./src/app` → `./
|
|
200
|
+
This uses the defaults (`./src/app` → `./yak-routes-manifest.json`). Customize if needed:
|
|
201
201
|
|
|
202
202
|
```json
|
|
203
203
|
{
|
|
204
204
|
"scripts": {
|
|
205
|
-
"prebuild": "yak-nextjs generate-manifest --app-dir ./app --output ./
|
|
205
|
+
"prebuild": "yak-nextjs generate-manifest --app-dir ./app --output ./routes.json"
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
```
|
|
209
209
|
|
|
210
|
+
> **Important:** The manifest must be in the project root (not `public/`). On Vercel and other serverless platforms, files in `public/` are served via CDN and are not available on the function's filesystem.
|
|
211
|
+
|
|
210
212
|
The handler checks these locations automatically:
|
|
211
213
|
1. `./yak-routes-manifest.json`
|
|
212
|
-
2.
|
|
214
|
+
2. `./.next/yak-routes-manifest.json`
|
|
215
|
+
3. `./public/yak-routes-manifest.json` (only works in non-serverless environments)
|
|
213
216
|
|
|
214
217
|
### Alternative: explicit routes
|
|
215
218
|
|
|
@@ -239,7 +242,7 @@ export const { GET, POST } = createNextYakHandler({
|
|
|
239
242
|
`@yak-io/nextjs/server` exports:
|
|
240
243
|
|
|
241
244
|
- `scanRoutes(directory: string, options?: { directoryType?: "app" | "pages" })` – low-level filesystem scanner (useful for precomputing manifests or composing custom sources). Only captures page routes, extracting `title` and `description` from static metadata exports.
|
|
242
|
-
- `loadRouteManifest(path?: string)` – load a pre-built JSON manifest, returns `null` if not found. Checks `./yak-routes-manifest.json
|
|
245
|
+
- `loadRouteManifest(path?: string)` – load a pre-built JSON manifest, returns `null` if not found. Checks `./yak-routes-manifest.json`, `./.next/yak-routes-manifest.json`, and `./public/yak-routes-manifest.json` by default.
|
|
243
246
|
- `loadRoutes(path?: string)` – load routes from a manifest, throws with helpful error if not found.
|
|
244
247
|
- `createNextYakHandler(config)` – unified GET + POST handler (wrapping `createYakHandler`). When `routes`/`getRoutes` are omitted it auto-scans `./src/app` and `./src/pages` (override with `appDir`/`pagesDir`, and narrow results via `routeFilter?: { include?: RegExp[]; exclude?: RegExp[] }`). In production, automatically falls back to pre-built manifests.
|
|
245
248
|
- `createNextYakConfigHandler(config)` – GET-only convenience wrapper.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Options:
|
|
12
12
|
* --app-dir <path> Path to Next.js app directory (default: ./src/app)
|
|
13
13
|
* --pages-dir <path> Path to Next.js pages directory (optional, scanned in addition to app-dir)
|
|
14
|
-
* --output <path> Output file path (default: ./
|
|
14
|
+
* --output <path> Output file path (default: ./yak-routes-manifest.json)
|
|
15
15
|
*/
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=generate-manifest.d.ts.map
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Options:
|
|
12
12
|
* --app-dir <path> Path to Next.js app directory (default: ./src/app)
|
|
13
13
|
* --pages-dir <path> Path to Next.js pages directory (optional, scanned in addition to app-dir)
|
|
14
|
-
* --output <path> Output file path (default: ./
|
|
14
|
+
* --output <path> Output file path (default: ./yak-routes-manifest.json)
|
|
15
15
|
*/
|
|
16
16
|
import * as fs from "node:fs";
|
|
17
17
|
import * as path from "node:path";
|
|
@@ -201,7 +201,7 @@ function parseArgs() {
|
|
|
201
201
|
const args = process.argv.slice(2);
|
|
202
202
|
let appDir = "./src/app";
|
|
203
203
|
let pagesDir = undefined;
|
|
204
|
-
let output = "./
|
|
204
|
+
let output = "./yak-routes-manifest.json";
|
|
205
205
|
let help = false;
|
|
206
206
|
for (let i = 0; i < args.length; i++) {
|
|
207
207
|
const arg = args[i];
|
|
@@ -238,7 +238,7 @@ Usage:
|
|
|
238
238
|
Options:
|
|
239
239
|
--app-dir <path> Path to Next.js app directory (default: ./src/app)
|
|
240
240
|
--pages-dir <path> Path to Next.js pages directory (optional)
|
|
241
|
-
--output <path> Output file path (default: ./
|
|
241
|
+
--output <path> Output file path (default: ./yak-routes-manifest.json)
|
|
242
242
|
--help, -h Show this help message
|
|
243
243
|
|
|
244
244
|
Examples:
|
|
@@ -6,7 +6,7 @@ import type { RouteSourceInput, ToolSourceInput, RouteInfo, RouteManifest, ToolM
|
|
|
6
6
|
* is not available (e.g., Vercel serverless functions).
|
|
7
7
|
*
|
|
8
8
|
* Generate the manifest at build time using:
|
|
9
|
-
* yak-nextjs generate-manifest
|
|
9
|
+
* yak-nextjs generate-manifest
|
|
10
10
|
*
|
|
11
11
|
* @param manifestPath - Path to the manifest JSON file (default: tries common locations)
|
|
12
12
|
* @returns Route manifest or null if not found
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNextYakHandler.d.ts","sourceRoot":"","sources":["../../src/server/createNextYakHandler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,aAAa,EACb,YAAY,EACZ,YAAY,EACb,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"createNextYakHandler.d.ts","sourceRoot":"","sources":["../../src/server/createNextYakHandler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,E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AM,EAAE,0BAA0B,wCAK5E;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IACvC,WAAW,EAAE,YAAY,CAAC;CAC3B,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,yBAAyB,uCAW1E"}
|
|
@@ -3,11 +3,16 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { scanRoutes } from "./scan-routes.js";
|
|
5
5
|
/**
|
|
6
|
-
* Default paths to check for pre-built route manifests
|
|
6
|
+
* Default paths to check for pre-built route manifests.
|
|
7
|
+
*
|
|
8
|
+
* On Vercel/serverless, files in `public/` are served via CDN and NOT available
|
|
9
|
+
* on the function's filesystem. The manifest must be in the project root or
|
|
10
|
+
* another location that gets bundled with the serverless function.
|
|
7
11
|
*/
|
|
8
12
|
const DEFAULT_MANIFEST_PATHS = [
|
|
9
13
|
"./yak-routes-manifest.json",
|
|
10
|
-
"
|
|
14
|
+
"./.next/yak-routes-manifest.json",
|
|
15
|
+
"./public/yak-routes-manifest.json", // Only works in non-serverless environments
|
|
11
16
|
];
|
|
12
17
|
/**
|
|
13
18
|
* Load a pre-built route manifest from disk.
|
|
@@ -16,7 +21,7 @@ const DEFAULT_MANIFEST_PATHS = [
|
|
|
16
21
|
* is not available (e.g., Vercel serverless functions).
|
|
17
22
|
*
|
|
18
23
|
* Generate the manifest at build time using:
|
|
19
|
-
* yak-nextjs generate-manifest
|
|
24
|
+
* yak-nextjs generate-manifest
|
|
20
25
|
*
|
|
21
26
|
* @param manifestPath - Path to the manifest JSON file (default: tries common locations)
|
|
22
27
|
* @returns Route manifest or null if not found
|
|
@@ -48,7 +53,7 @@ export function loadRoutes(manifestPath) {
|
|
|
48
53
|
throw new Error(`Route manifest not found. Checked: ${pathsChecked}\n\n` +
|
|
49
54
|
`In production environments (like Vercel), route scanning requires a pre-built manifest.\n` +
|
|
50
55
|
`Generate it at build time by adding to your build script:\n\n` +
|
|
51
|
-
` yak-nextjs generate-manifest
|
|
56
|
+
` yak-nextjs generate-manifest\n\n` +
|
|
52
57
|
`Or provide routes explicitly in your handler configuration.`);
|
|
53
58
|
}
|
|
54
59
|
return manifest.routes;
|
|
@@ -84,7 +89,7 @@ function tryLoadRoutes(appDir) {
|
|
|
84
89
|
`This typically happens in production (Vercel, etc.) where source files aren't deployed.\n\n` +
|
|
85
90
|
`Solutions:\n` +
|
|
86
91
|
`1. Generate a route manifest at build time:\n` +
|
|
87
|
-
` Add to your build script: yak-nextjs generate-manifest
|
|
92
|
+
` Add to your build script: yak-nextjs generate-manifest\n\n` +
|
|
88
93
|
`2. Provide routes explicitly:\n` +
|
|
89
94
|
` createNextYakHandler({ routes: [...] })\n\n` +
|
|
90
95
|
`3. Use getRoutes callback:\n` +
|