@aravindc26/velu 0.12.14 → 0.12.16
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/package.json
CHANGED
|
@@ -1,50 +1,28 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { generateSessionContent } from '@/lib/preview-content';
|
|
5
5
|
import { verifyApiSecret, unauthorizedResponse } from '@/lib/preview-auth';
|
|
6
6
|
|
|
7
|
-
const RELOAD_MARKER = '\n// __RELOAD_TRIGGER__\n';
|
|
8
|
-
|
|
9
7
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Toggle a comment in source.config.ts to force fumadocs-mdx to restart
|
|
9
|
+
* and rescan the content directory. Fire-and-forget — don't wait for completion.
|
|
12
10
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* This is needed because on Cloud Run (gVisor), neither inotify nor chokidar
|
|
12
|
+
* polling reliably detects new files in the content directory.
|
|
15
13
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// fumadocs-mdx to fully re-scan the content directory (even on NFS).
|
|
28
|
-
const content = readFileSync(configPath, 'utf-8');
|
|
29
|
-
const newContent = content.includes(RELOAD_MARKER)
|
|
30
|
-
? content.replace(RELOAD_MARKER, '\n')
|
|
31
|
-
: content + RELOAD_MARKER;
|
|
32
|
-
writeFileSync(configPath, newContent, 'utf-8');
|
|
33
|
-
|
|
34
|
-
console.log('[PREVIEW] Triggered source.config.ts content change, waiting for MDX regeneration...');
|
|
35
|
-
|
|
36
|
-
// Wait for .source directory to be updated (up to 30s)
|
|
37
|
-
for (let i = 0; i < 300; i++) {
|
|
38
|
-
await new Promise((r) => setTimeout(r, 100));
|
|
39
|
-
if (existsSync(sourceDir)) {
|
|
40
|
-
const currentMtime = statSync(sourceDir).mtimeMs;
|
|
41
|
-
if (currentMtime > beforeMtime) {
|
|
42
|
-
console.log(`[PREVIEW] MDX regeneration detected after ${(i + 1) * 100}ms`);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
14
|
+
function triggerMdxRescan(): void {
|
|
15
|
+
try {
|
|
16
|
+
const configPath = resolve(process.cwd(), 'source.config.ts');
|
|
17
|
+
const marker = '\n// __RELOAD__\n';
|
|
18
|
+
const content = readFileSync(configPath, 'utf-8');
|
|
19
|
+
const newContent = content.includes(marker)
|
|
20
|
+
? content.replace(marker, '\n')
|
|
21
|
+
: content + marker;
|
|
22
|
+
writeFileSync(configPath, newContent, 'utf-8');
|
|
23
|
+
} catch (e) {
|
|
24
|
+
console.warn('[PREVIEW] Failed to trigger MDX rescan:', e);
|
|
46
25
|
}
|
|
47
|
-
console.warn('[PREVIEW] MDX regeneration timed out after 30s');
|
|
48
26
|
}
|
|
49
27
|
|
|
50
28
|
export async function POST(
|
|
@@ -58,8 +36,9 @@ export async function POST(
|
|
|
58
36
|
try {
|
|
59
37
|
const result = generateSessionContent(sessionId);
|
|
60
38
|
|
|
61
|
-
//
|
|
62
|
-
|
|
39
|
+
// Fire-and-forget: trigger fumadocs-mdx to discover new content.
|
|
40
|
+
// The subsequent page request will wait for Turbopack recompilation.
|
|
41
|
+
triggerMdxRescan();
|
|
63
42
|
|
|
64
43
|
return Response.json({
|
|
65
44
|
status: 'ready',
|