vocs 2.0.13 → 2.0.15
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/dist/internal/mcp-transport.d.ts +1 -1
- package/dist/internal/mcp-transport.d.ts.map +1 -1
- package/dist/internal/mcp-transport.js +20 -24
- package/dist/internal/mcp-transport.js.map +1 -1
- package/dist/internal/mdx.d.ts +6 -0
- package/dist/internal/mdx.d.ts.map +1 -1
- package/dist/internal/mdx.js +61 -18
- package/dist/internal/mdx.js.map +1 -1
- package/dist/internal/search.d.ts +1 -1
- package/dist/internal/search.d.ts.map +1 -1
- package/dist/internal/search.js +12 -5
- package/dist/internal/search.js.map +1 -1
- package/dist/waku/internal/middleware/md-router.d.ts.map +1 -1
- package/dist/waku/internal/middleware/md-router.js +10 -1
- package/dist/waku/internal/middleware/md-router.js.map +1 -1
- package/dist/waku/internal/patches/adapters/node.d.ts.map +1 -1
- package/dist/waku/internal/patches/adapters/node.js +9 -6
- package/dist/waku/internal/patches/adapters/node.js.map +1 -1
- package/dist/waku/internal/vite-plugins.d.ts +7 -5
- package/dist/waku/internal/vite-plugins.d.ts.map +1 -1
- package/dist/waku/internal/vite-plugins.js +20 -108
- package/dist/waku/internal/vite-plugins.js.map +1 -1
- package/dist/waku/vite.js +1 -1
- package/dist/waku/vite.js.map +1 -1
- package/package.json +2 -2
- package/src/internal/mcp-transport.test.ts +132 -0
- package/src/internal/mcp-transport.ts +20 -33
- package/src/internal/mdx.test.ts +83 -0
- package/src/internal/mdx.ts +72 -23
- package/src/internal/search.test.ts +40 -0
- package/src/internal/search.ts +12 -5
- package/src/waku/internal/middleware/md-router.test.ts +85 -0
- package/src/waku/internal/middleware/md-router.ts +11 -1
- package/src/waku/internal/patches/adapters/node.ts +23 -9
- package/src/waku/internal/vite-plugins.ts +21 -118
- package/src/waku/vite.ts +1 -1
- package/src/waku/internal/vite-plugins.test.ts +0 -118
|
@@ -44,6 +44,27 @@ export function buildId(): Plugin {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Keeps `react-server-dom-webpack` bundled in the server environments so Waku's rsdw
|
|
49
|
+
* patch can redirect it to plugin-rsc's vendored build. npm and bun auto-install the
|
|
50
|
+
* peer, which would otherwise load natively with `react` missing the `react-server`
|
|
51
|
+
* condition and crash the dev server.
|
|
52
|
+
*/
|
|
53
|
+
export function rsdwNoExternal(): Plugin {
|
|
54
|
+
const rsdw = 'react-server-dom-webpack'
|
|
55
|
+
return {
|
|
56
|
+
name: 'vocs:rsdw-no-external',
|
|
57
|
+
config() {
|
|
58
|
+
return {
|
|
59
|
+
environments: {
|
|
60
|
+
rsc: { resolve: { noExternal: [rsdw] } },
|
|
61
|
+
ssr: { resolve: { noExternal: [rsdw] } },
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
47
68
|
/**
|
|
48
69
|
* Builds a script to preview the build output.
|
|
49
70
|
*/
|
|
@@ -98,124 +119,6 @@ await import('./serve-node.js');
|
|
|
98
119
|
}
|
|
99
120
|
}
|
|
100
121
|
|
|
101
|
-
const wakuDefineRouterRegex = /[/\\]waku[/\\]dist[/\\]router[/\\]define-router\.js(?:\?.*)?$/
|
|
102
|
-
const wakuRouterClientRegex = /[/\\]waku[/\\]dist[/\\]router[/\\]client\.js(?:\?.*)?$/
|
|
103
|
-
const wakuMinimalClientRegex = /[/\\]waku[/\\]dist[/\\]minimal[/\\]client\.js(?:\?.*)?$/
|
|
104
|
-
|
|
105
|
-
// TODO: Remove these Waku prefetch patches once https://github.com/wakujs/waku/issues/2099 is fixed.
|
|
106
|
-
const wakuRouterPrefetchCodeRegex =
|
|
107
|
-
/Object\.entries\(path2moduleIds\)\.forEach\(\(\[path,\s*ids\]\)=>\{\s*path2idxs\[path\]\s*=\s*ids\.map\(\(id\)=>ids\.indexOf\(id\)\);\s*\}\);/
|
|
108
|
-
|
|
109
|
-
const wakuRouterHmrRefetchCode = ` const refetchRoute = ()=>{
|
|
110
|
-
staticPathSetRef.current.clear();
|
|
111
|
-
cachedIdSetRef.current.clear();
|
|
112
|
-
const rscPath = encodeRoutePath(route.path);
|
|
113
|
-
const rscParams = createRscParams(route.query);
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
115
|
-
refetch(rscPath, rscParams);
|
|
116
|
-
};`
|
|
117
|
-
const wakuRouterHmrRefetchPatchedCode = ` const refetchRoute = ()=>{
|
|
118
|
-
staticPathSetRef.current.clear();
|
|
119
|
-
cachedIdSetRef.current.clear();
|
|
120
|
-
const rscPath = encodeRoutePath(route.path);
|
|
121
|
-
const rscParams = createRscParams(route.query);
|
|
122
|
-
const hmrRefetchEnhancer = (fetchFn)=>(input, init = {})=>{
|
|
123
|
-
init.cache = 'no-store';
|
|
124
|
-
return fetchFn(input, init);
|
|
125
|
-
};
|
|
126
|
-
delete globalThis.__WAKU_PREFETCHED__?.[rscPath];
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
128
|
-
refetch(rscPath, rscParams, (store)=>withEnhanceFetchFn(hmrRefetchEnhancer)(store));
|
|
129
|
-
};`
|
|
130
|
-
|
|
131
|
-
const wakuClientPrefetchKeysCode = `const KEY_RESPONSE = 'r';
|
|
132
|
-
const KEY_CLOSE = 'x';`
|
|
133
|
-
const wakuClientPrefetchKeysPatchedCode = `const KEY_RESPONSE = 'r';
|
|
134
|
-
const KEY_ELEMENTS = 'e';
|
|
135
|
-
const KEY_CLOSE = 'x';`
|
|
136
|
-
|
|
137
|
-
const wakuClientPrefetchElementsCode = ` if (prefetchOnly) {
|
|
138
|
-
prefetched[rscPath] = {
|
|
139
|
-
[KEY_RESPONSE]: responsePromise,
|
|
140
|
-
[KEY_CLIENT_PREFETCHED]: true,
|
|
141
|
-
[KEY_RSC_PARAMS]: rscParams,
|
|
142
|
-
[KEY_TEMPORARY_REFERENCES]: temporaryReferences
|
|
143
|
-
};
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
const elements = createFromFetch(checkStatus(responsePromise), {
|
|
147
|
-
callServer: (funcId, args)=>unstable_callServerRsc(funcId, args, ()=>fetchRscStore),
|
|
148
|
-
debugChannel: debug?.debugChannel,
|
|
149
|
-
temporaryReferences
|
|
150
|
-
});`
|
|
151
|
-
const wakuClientPrefetchElementsPatchedCode = ` const createElements = ()=>createFromFetch(checkStatus(responsePromise), {
|
|
152
|
-
callServer: (funcId, args)=>unstable_callServerRsc(funcId, args, ()=>fetchRscStore),
|
|
153
|
-
debugChannel: debug?.debugChannel,
|
|
154
|
-
temporaryReferences
|
|
155
|
-
});
|
|
156
|
-
if (prefetchOnly) {
|
|
157
|
-
const elements = createElements();
|
|
158
|
-
Promise.resolve(elements).catch(()=>{});
|
|
159
|
-
prefetched[rscPath] = {
|
|
160
|
-
[KEY_RESPONSE]: responsePromise,
|
|
161
|
-
[KEY_ELEMENTS]: elements,
|
|
162
|
-
[KEY_CLIENT_PREFETCHED]: true,
|
|
163
|
-
[KEY_RSC_PARAMS]: rscParams,
|
|
164
|
-
[KEY_TEMPORARY_REFERENCES]: temporaryReferences
|
|
165
|
-
};
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
const elements = prefetchedEntry?.[KEY_ELEMENTS] || createElements();`
|
|
169
|
-
|
|
170
|
-
export function patchRouterPrefetchCode(code: string, id: string) {
|
|
171
|
-
if (!wakuDefineRouterRegex.test(id)) return
|
|
172
|
-
const patched = code.replace(
|
|
173
|
-
wakuRouterPrefetchCodeRegex,
|
|
174
|
-
`Object.entries(path2moduleIds).forEach(([path, pathIds])=>{
|
|
175
|
-
path2idxs[path] = pathIds.map((id)=>ids.indexOf(id));
|
|
176
|
-
});`,
|
|
177
|
-
)
|
|
178
|
-
if (patched === code) return
|
|
179
|
-
return patched
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function patchRouterHmrRefetchCode(code: string, id: string) {
|
|
183
|
-
if (!wakuRouterClientRegex.test(id)) return
|
|
184
|
-
const patched = code.replace(wakuRouterHmrRefetchCode, wakuRouterHmrRefetchPatchedCode)
|
|
185
|
-
if (patched === code) return
|
|
186
|
-
return patched
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function patchClientRscPrefetchCode(code: string, id: string) {
|
|
190
|
-
if (!wakuMinimalClientRegex.test(id)) return
|
|
191
|
-
if (!code.includes(wakuClientPrefetchKeysCode) || !code.includes(wakuClientPrefetchElementsCode))
|
|
192
|
-
return
|
|
193
|
-
const patched = code
|
|
194
|
-
.replace(wakuClientPrefetchKeysCode, wakuClientPrefetchKeysPatchedCode)
|
|
195
|
-
.replace(wakuClientPrefetchElementsCode, wakuClientPrefetchElementsPatchedCode)
|
|
196
|
-
return patched
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export function patchWakuPrefetchCode(code: string, id: string) {
|
|
200
|
-
return (
|
|
201
|
-
patchRouterPrefetchCode(code, id) ??
|
|
202
|
-
patchRouterHmrRefetchCode(code, id) ??
|
|
203
|
-
patchClientRscPrefetchCode(code, id)
|
|
204
|
-
)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export function patchRouterPrefetch(): Plugin {
|
|
208
|
-
return {
|
|
209
|
-
name: 'vocs:patch-router-prefetch',
|
|
210
|
-
enforce: 'pre',
|
|
211
|
-
transform(code, id) {
|
|
212
|
-
const patched = patchWakuPrefetchCode(code, id)
|
|
213
|
-
if (!patched) return null
|
|
214
|
-
return { code: patched, map: null }
|
|
215
|
-
},
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
122
|
export function mdxHmr(): Plugin {
|
|
220
123
|
const virtualModuleId = 'virtual:vocs/mdx-hmr'
|
|
221
124
|
const resolvedVirtualModuleId = `\0${virtualModuleId}`
|
package/src/waku/vite.ts
CHANGED
|
@@ -35,6 +35,7 @@ export async function vocs(options: vocs.Options = {}): Promise<PluginOption[]>
|
|
|
35
35
|
|
|
36
36
|
return [
|
|
37
37
|
vocs_core(),
|
|
38
|
+
Plugins.rsdwNoExternal(),
|
|
38
39
|
Plugins.allowServer(),
|
|
39
40
|
PluginRsc({
|
|
40
41
|
serverHandler: false,
|
|
@@ -50,7 +51,6 @@ export async function vocs(options: vocs.Options = {}): Promise<PluginOption[]>
|
|
|
50
51
|
Plugins.adapterAlias(wakuConfig),
|
|
51
52
|
Plugins.notFound(),
|
|
52
53
|
Plugins.patchRsdw(),
|
|
53
|
-
Plugins.patchRouterPrefetch(),
|
|
54
54
|
Plugins.buildMetadata(wakuConfig),
|
|
55
55
|
Plugins.staticBuild(wakuConfig),
|
|
56
56
|
Plugins.privateDir(wakuConfig),
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
patchClientRscPrefetchCode,
|
|
4
|
-
patchRouterHmrRefetchCode,
|
|
5
|
-
patchRouterPrefetchCode,
|
|
6
|
-
} from './vite-plugins.js'
|
|
7
|
-
|
|
8
|
-
describe('patchRouterPrefetchCode', () => {
|
|
9
|
-
it('maps route module ids through the global module id list', () => {
|
|
10
|
-
const code = `
|
|
11
|
-
const getRouterPrefetchCode = (path2moduleIds)=>{
|
|
12
|
-
const moduleIdSet = new Set();
|
|
13
|
-
Object.values(path2moduleIds).forEach((ids)=>ids.forEach((id)=>moduleIdSet.add(id)));
|
|
14
|
-
const ids = Array.from(moduleIdSet);
|
|
15
|
-
const path2idxs = {};
|
|
16
|
-
Object.entries(path2moduleIds).forEach(([path, ids])=>{
|
|
17
|
-
path2idxs[path] = ids.map((id)=>ids.indexOf(id));
|
|
18
|
-
});
|
|
19
|
-
return \`
|
|
20
|
-
globalThis.__WAKU_ROUTER_PREFETCH__ = (path, callback) => {
|
|
21
|
-
const ids = \${JSON.stringify(ids)};
|
|
22
|
-
const path2idxs = \${JSON.stringify(path2idxs)};
|
|
23
|
-
const key = Object.keys(path2idxs).find((key) => new RegExp(key).test(path));
|
|
24
|
-
for (const idx of path2idxs[key] || []) {
|
|
25
|
-
callback(ids[idx]);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
\`;
|
|
29
|
-
};`
|
|
30
|
-
|
|
31
|
-
const patched = patchRouterPrefetchCode(
|
|
32
|
-
code,
|
|
33
|
-
'/repo/node_modules/waku/dist/router/define-router.js',
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
expect(patched).toContain('pathIds.map((id)=>ids.indexOf(id))')
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('ignores other modules', () => {
|
|
40
|
-
expect(patchRouterPrefetchCode('', '/repo/node_modules/waku/dist/router/client.js')).toBe(
|
|
41
|
-
undefined,
|
|
42
|
-
)
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
describe('patchClientRscPrefetchCode', () => {
|
|
47
|
-
it('decodes and reuses prefetched RSC elements', () => {
|
|
48
|
-
const code = `
|
|
49
|
-
const KEY_RESPONSE = 'r';
|
|
50
|
-
const KEY_CLOSE = 'x';
|
|
51
|
-
const fetchRscInternal = (fetchRscStore, rscPath, rscParams, prefetchOnly)=>{
|
|
52
|
-
const responsePromise = prefetchedEntry ? prefetchedEntry[KEY_RESPONSE] : fetchFn(url);
|
|
53
|
-
if (prefetchOnly) {
|
|
54
|
-
prefetched[rscPath] = {
|
|
55
|
-
[KEY_RESPONSE]: responsePromise,
|
|
56
|
-
[KEY_CLIENT_PREFETCHED]: true,
|
|
57
|
-
[KEY_RSC_PARAMS]: rscParams,
|
|
58
|
-
[KEY_TEMPORARY_REFERENCES]: temporaryReferences
|
|
59
|
-
};
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
const elements = createFromFetch(checkStatus(responsePromise), {
|
|
63
|
-
callServer: (funcId, args)=>unstable_callServerRsc(funcId, args, ()=>fetchRscStore),
|
|
64
|
-
debugChannel: debug?.debugChannel,
|
|
65
|
-
temporaryReferences
|
|
66
|
-
});
|
|
67
|
-
};`
|
|
68
|
-
|
|
69
|
-
const patched = patchClientRscPrefetchCode(
|
|
70
|
-
code,
|
|
71
|
-
'/repo/node_modules/waku/dist/minimal/client.js',
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
expect(patched).toContain("const KEY_ELEMENTS = 'e';")
|
|
75
|
-
expect(patched).toContain('const createElements = ()=>createFromFetch')
|
|
76
|
-
expect(patched).toContain('Promise.resolve(elements).catch(()=>{});')
|
|
77
|
-
expect(patched).toContain('[KEY_ELEMENTS]: elements')
|
|
78
|
-
expect(patched).toContain(
|
|
79
|
-
'const elements = prefetchedEntry?.[KEY_ELEMENTS] || createElements();',
|
|
80
|
-
)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('ignores other modules', () => {
|
|
84
|
-
expect(patchClientRscPrefetchCode('', '/repo/node_modules/waku/dist/router/client.js')).toBe(
|
|
85
|
-
undefined,
|
|
86
|
-
)
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
describe('patchRouterHmrRefetchCode', () => {
|
|
91
|
-
it('bypasses prefetched and browser-cached RSC data during route HMR', () => {
|
|
92
|
-
const code = `
|
|
93
|
-
const InnerRouter = ()=>{
|
|
94
|
-
if (import.meta.hot) {
|
|
95
|
-
const refetchRoute = ()=>{
|
|
96
|
-
staticPathSetRef.current.clear();
|
|
97
|
-
cachedIdSetRef.current.clear();
|
|
98
|
-
const rscPath = encodeRoutePath(route.path);
|
|
99
|
-
const rscParams = createRscParams(route.query);
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
101
|
-
refetch(rscPath, rscParams);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}`
|
|
105
|
-
|
|
106
|
-
const patched = patchRouterHmrRefetchCode(code, '/repo/node_modules/waku/dist/router/client.js')
|
|
107
|
-
|
|
108
|
-
expect(patched).toContain("init.cache = 'no-store';")
|
|
109
|
-
expect(patched).toContain('delete globalThis.__WAKU_PREFETCHED__?.[rscPath];')
|
|
110
|
-
expect(patched).toContain('withEnhanceFetchFn(hmrRefetchEnhancer)')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('ignores other modules', () => {
|
|
114
|
-
expect(
|
|
115
|
-
patchRouterHmrRefetchCode('', '/repo/node_modules/waku/dist/router/define-router.js'),
|
|
116
|
-
).toBe(undefined)
|
|
117
|
-
})
|
|
118
|
-
})
|