@sproutboat/runtime 0.33.0 → 0.34.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.
- package/CHANGELOG.md +11 -0
- package/package.json +1 -1
- package/src/native-fetch-prelude.js +497 -11
- package/src/source.ts +12 -2
- package/src/transport-embedded.js +639 -0
- package/test/native-websockets-outbound.ts +244 -0
- package/test/native-websockets.ts +86 -3
package/src/source.ts
CHANGED
|
@@ -10,7 +10,7 @@ const alwaysForbidden: Array<[RegExp, string]> = [
|
|
|
10
10
|
[/^\s*import\s/m, "an import survived bundling — only static imports can be resolved at build time"],
|
|
11
11
|
[/\bimport\s*\(/, "dynamic import() is not supported: nothing can resolve it at build time"],
|
|
12
12
|
[/\brequire\s*\(/, "CommonJS require is not supported"],
|
|
13
|
-
[/\
|
|
13
|
+
[/\bXMLHttpRequest\s*\(/, "XMLHttpRequest is not supported"],
|
|
14
14
|
// baronunread/sproutboat#132 — a bare identifier match flags a *local*
|
|
15
15
|
// `function process()` as readily as the global: zod v4 declares exactly
|
|
16
16
|
// that (its internal `process(schema, ctx)`), so importing zod alone used
|
|
@@ -27,7 +27,10 @@ const alwaysForbidden: Array<[RegExp, string]> = [
|
|
|
27
27
|
[/['"`]node:/, "Node, Bun, and Deno APIs are not supported"],
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
/** `new WebSocket(url)` connects out from this compatibility date (earlier, only WebSocketPair makes one). */
|
|
31
|
+
export const OUTBOUND_WEBSOCKET_DATE = "2026-11-01";
|
|
32
|
+
|
|
33
|
+
export function validateHttpSyncSource(module: string, compatibilityDate?: string): SourceValidation {
|
|
31
34
|
// `cloudflare:workers` is the one import allowed past bundling: the compiler turns it
|
|
32
35
|
// into globals the same way (see inlineWorkersImports).
|
|
33
36
|
const source = inlineWorkersImports(module);
|
|
@@ -46,5 +49,12 @@ export function validateHttpSyncSource(module: string): SourceValidation {
|
|
|
46
49
|
);
|
|
47
50
|
}
|
|
48
51
|
for (const [pattern, message] of alwaysForbidden) if (pattern.test(source)) errors.push(message);
|
|
52
|
+
if (
|
|
53
|
+
/\bWebSocket\s*\(/.test(source) &&
|
|
54
|
+
!(compatibilityDate !== undefined && compatibilityDate >= OUTBOUND_WEBSOCKET_DATE)
|
|
55
|
+
)
|
|
56
|
+
errors.push(
|
|
57
|
+
`WebSocket() needs compatibility_date ${OUTBOUND_WEBSOCKET_DATE} or later (earlier dates have WebSocketPair only)`,
|
|
58
|
+
);
|
|
49
59
|
return errors.length ? { ok: false, errors } : { ok: true };
|
|
50
60
|
}
|