react-native-roku 0.0.0-stage → 0.2.0-preview.1

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.
Files changed (200) hide show
  1. package/CHANGELOG.md +318 -0
  2. package/CONTRIBUTING.md +34 -0
  3. package/LICENSE +21 -0
  4. package/NOTICE.md +10 -0
  5. package/README.md +66 -2
  6. package/bin/react-native-roku.mjs +91 -0
  7. package/build/assets.cjs +311 -0
  8. package/build/assets.d.cts +50 -0
  9. package/build/compatibility.d.mts +40 -0
  10. package/build/compatibility.mjs +272 -0
  11. package/build/dev.d.mts +34 -0
  12. package/build/dev.mjs +297 -0
  13. package/build/devWorkspace.d.mts +11 -0
  14. package/build/devWorkspace.mjs +86 -0
  15. package/build/device.d.mts +47 -0
  16. package/build/device.mjs +310 -0
  17. package/build/environment.d.mts +29 -0
  18. package/build/environment.mjs +144 -0
  19. package/build/esbuild.d.mts +5 -0
  20. package/build/esbuild.mjs +118 -0
  21. package/build/fontVariants.d.mts +27 -0
  22. package/build/fontVariants.mjs +424 -0
  23. package/build/frontend.d.mts +52 -0
  24. package/build/frontend.mjs +75 -0
  25. package/build/identity.mjs +45 -0
  26. package/build/index.d.mts +22 -0
  27. package/build/index.mjs +87 -0
  28. package/build/intl.mjs +121 -0
  29. package/build/metro.cjs +38 -0
  30. package/build/metro.d.cts +37 -0
  31. package/build/metroFrontend.mjs +222 -0
  32. package/build/metroMetadata.mjs +119 -0
  33. package/build/metroModules.mjs +397 -0
  34. package/build/metroRefresh.d.mts +64 -0
  35. package/build/metroRefresh.mjs +346 -0
  36. package/build/metroTransformer.cjs +146 -0
  37. package/build/nativeTextMemo.mjs +296 -0
  38. package/build/nativewind.d.mts +9 -0
  39. package/build/nativewind.mjs +92 -0
  40. package/build/project.d.mts +111 -0
  41. package/build/project.mjs +615 -0
  42. package/build/reactCompiler.mjs +113 -0
  43. package/build/reactProfile.cjs +35 -0
  44. package/build/refreshRuntime.mjs +187 -0
  45. package/build/refreshSourceMap.mjs +53 -0
  46. package/build/release.mjs +99 -0
  47. package/build/resolution.d.mts +3 -0
  48. package/build/resolution.mjs +25 -0
  49. package/build/surfaces.d.mts +1 -0
  50. package/build/surfaces.mjs +42 -0
  51. package/build/testing/node.d.mts +29 -0
  52. package/build/testing/node.mjs +106 -0
  53. package/build/yoga.d.mts +8 -0
  54. package/build/yoga.mjs +186 -0
  55. package/compatibility/public-api.json +327 -0
  56. package/compatibility/registry.json +2258 -0
  57. package/config/release.json +15 -0
  58. package/config/toolchain.json +34 -0
  59. package/docs/compatibility.md +813 -0
  60. package/docs/getting-started.md +460 -0
  61. package/docs/maintenance.md +362 -0
  62. package/docs/qualification.md +241 -0
  63. package/docs/standalone-testing.md +56 -0
  64. package/examples/hello-roku/README.md +35 -0
  65. package/examples/hello-roku/package.template.json +31 -0
  66. package/examples/hello-roku/pnpm-workspace.yaml +11 -0
  67. package/examples/hello-roku/roku.config.json +22 -0
  68. package/examples/hello-roku/src/App.tsx +54 -0
  69. package/examples/hello-roku/src/Catalog.tsx +200 -0
  70. package/examples/hello-roku/src/assets.d.ts +16 -0
  71. package/examples/hello-roku/src/catalog-cover.png +0 -0
  72. package/examples/hello-roku/tsconfig.json +1 -0
  73. package/examples/hello-roku/tsconfig.react.json +1 -0
  74. package/native/components/RNRAppControl.brs +215 -0
  75. package/native/components/RNRAppControl.xml +13 -0
  76. package/native/components/RNRDeviceFacts.brs +19 -0
  77. package/native/components/RNRDeviceFacts.xml +9 -0
  78. package/native/components/RNRDeviceFactsTask.brs +74 -0
  79. package/native/components/RNRDeviceFactsTask.xml +9 -0
  80. package/native/components/RNRTextRaster.brs +15 -0
  81. package/native/components/RNRTextRaster.xml +9 -0
  82. package/native/components/RNRTextRasterTask.brs +77 -0
  83. package/native/components/RNRTextRasterTask.xml +9 -0
  84. package/native/manifest.json +7 -0
  85. package/package.json +183 -3
  86. package/src/animation/clock.ts +10 -0
  87. package/src/animation/derivedValue.ts +163 -0
  88. package/src/animation/legacyAnimated.ts +255 -0
  89. package/src/animation/reanimated.ts +243 -0
  90. package/src/animation/sharedValue.ts +285 -0
  91. package/src/animation/worklets.ts +23 -0
  92. package/src/application/AppRegistry.ts +31 -0
  93. package/src/application/mountApplication.ts +136 -0
  94. package/src/graphics/BitmapLayer.tsx +68 -0
  95. package/src/graphics/RoundedBorder.tsx +116 -0
  96. package/src/graphics/TextRasterCache.ts +259 -0
  97. package/src/graphics/gradient.ts +37 -0
  98. package/src/graphics/inlineRaster.ts +85 -0
  99. package/src/graphics/png.ts +77 -0
  100. package/src/graphics/rasterPixels.ts +89 -0
  101. package/src/graphics/surfaces.ts +105 -0
  102. package/src/graphics/textRaster.types.ts +60 -0
  103. package/src/graphics/textRasterGeometry.ts +116 -0
  104. package/src/host/host.types.ts +57 -0
  105. package/src/index.ts +22 -0
  106. package/src/interop/nativewind.ts +2 -0
  107. package/src/layout/FontResources.ts +252 -0
  108. package/src/layout/affine.ts +89 -0
  109. package/src/layout/flexLayout.ts +398 -0
  110. package/src/layout/fontFaces.d.mts +19 -0
  111. package/src/layout/fontFaces.mjs +85 -0
  112. package/src/layout/fontVariants.d.mts +2 -0
  113. package/src/layout/fontVariants.mjs +8 -0
  114. package/src/layout/inlineParagraph.ts +158 -0
  115. package/src/layout/inlineText.ts +68 -0
  116. package/src/layout/layoutReuse.ts +117 -0
  117. package/src/layout/nativeNodeFields.ts +179 -0
  118. package/src/layout/preparedFields.ts +78 -0
  119. package/src/layout/textLayout.ts +138 -0
  120. package/src/layout/transform.ts +113 -0
  121. package/src/media/SceneGraphAudio.ts +161 -0
  122. package/src/media/SceneGraphVideo.ts +167 -0
  123. package/src/media/audioSession.ts +84 -0
  124. package/src/media/index.ts +2 -0
  125. package/src/media/videoErrorDetails.ts +40 -0
  126. package/src/media/videoSession.ts +136 -0
  127. package/src/navigation/RouterStore.ts +244 -0
  128. package/src/navigation/expoRouter.ts +115 -0
  129. package/src/react-native/NativeInput.ts +494 -0
  130. package/src/react-native/NativeSystemState.ts +95 -0
  131. package/src/react-native/accessibility.ts +265 -0
  132. package/src/react-native/activityIndicator.ts +72 -0
  133. package/src/react-native/compilerPressable.ts +26 -0
  134. package/src/react-native/createNativeRoot.ts +2126 -0
  135. package/src/react-native/directionalFocus.ts +55 -0
  136. package/src/react-native/environment.ts +275 -0
  137. package/src/react-native/flatList.ts +1001 -0
  138. package/src/react-native/flatListViewability.ts +231 -0
  139. package/src/react-native/focusEvents.ts +85 -0
  140. package/src/react-native/image.ts +247 -0
  141. package/src/react-native/index.ts +54 -0
  142. package/src/react-native/interactionManager.ts +76 -0
  143. package/src/react-native/keyboard.ts +60 -0
  144. package/src/react-native/linearGradient.ts +94 -0
  145. package/src/react-native/modal.tsx +148 -0
  146. package/src/react-native/nativeHostContext.ts +80 -0
  147. package/src/react-native/nativeModules.ts +86 -0
  148. package/src/react-native/nativeRoot.types.ts +22 -0
  149. package/src/react-native/nativeViewHandle.ts +191 -0
  150. package/src/react-native/nativewindPressable.ts +38 -0
  151. package/src/react-native/panResponder.ts +73 -0
  152. package/src/react-native/primitives.ts +685 -0
  153. package/src/react-native/safeArea.ts +76 -0
  154. package/src/react-native/scrollView.ts +289 -0
  155. package/src/react-native/styleInterop.ts +8 -0
  156. package/src/react-native/styleSheet.ts +54 -0
  157. package/src/react-native/textInput.ts +334 -0
  158. package/src/react-native/unsupported.ts +25 -0
  159. package/src/renderer/SceneRoot.ts +1006 -0
  160. package/src/scene/SdkDeviceFacts.ts +151 -0
  161. package/src/scene/SdkDeviceServices.ts +72 -0
  162. package/src/scene/SdkSceneGraph.ts +124 -0
  163. package/src/scene/SdkTextEntry.ts +321 -0
  164. package/src/scene/SdkTextMetrics.ts +136 -0
  165. package/src/scene/SdkTextRasterTransport.ts +191 -0
  166. package/src/scene/SdkWebTransport.ts +122 -0
  167. package/src/scene/createRokuHost.ts +213 -0
  168. package/src/scene/sceneGraph.types.ts +38 -0
  169. package/src/services/DeviceServices.ts +53 -0
  170. package/src/services/RegistryStorage.ts +85 -0
  171. package/src/services/RokuKeySession.ts +29 -0
  172. package/src/services/asyncStorage.ts +23 -0
  173. package/src/services/base64.ts +52 -0
  174. package/src/services/crypto.ts +18 -0
  175. package/src/services/expoConstants.ts +11 -0
  176. package/src/services/expoLinking.ts +12 -0
  177. package/src/services/expoStatusBar.ts +4 -0
  178. package/src/services/installWebRuntime.ts +105 -0
  179. package/src/services/intlEnglish.ts +54 -0
  180. package/src/services/languageRuntime.ts +65 -0
  181. package/src/services/nativeTimers.ts +96 -0
  182. package/src/services/secureStore.ts +23 -0
  183. package/src/services/textEntryRequest.ts +22 -0
  184. package/src/services/utf8.ts +57 -0
  185. package/src/services/webRuntime.ts +346 -0
  186. package/src/testing/CanvasResources.ts +141 -0
  187. package/src/testing/CanvasSceneGraph.ts +496 -0
  188. package/src/testing/CanvasTextEntry.ts +237 -0
  189. package/src/testing/PreviewTextObservations.ts +82 -0
  190. package/src/testing/RecordingSceneGraph.ts +136 -0
  191. package/src/types/normalize-colors.d.ts +4 -0
  192. package/src/vector/dynamicSvg.tsx +226 -0
  193. package/src/vector/svg.ts +222 -0
  194. package/src/vector/svg.types.ts +4 -0
  195. package/src/vector/svgElements.ts +58 -0
  196. package/src/vector/svgKey.d.mts +4 -0
  197. package/src/vector/svgKey.mjs +16 -0
  198. package/src/vector/svgPath.ts +157 -0
  199. package/src/vector/svgPixels.ts +133 -0
  200. package/tsconfig.consumer.json +29 -0
@@ -0,0 +1,310 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { createConnection } from "node:net";
3
+ import { StringDecoder } from "node:string_decoder";
4
+ import { isRokuDiagnosticError } from "./identity.mjs";
5
+ export { parseRokuHostDiagnostics } from "./identity.mjs";
6
+ const xmlText = (xml, name) =>
7
+ new RegExp(`<${name}(?:\\s[^>]*)?>([^<]*)</${name}>`, "i").exec(xml)?.[1]?.trim() ?? null;
8
+ const attribute = (text, name) => new RegExp(`\\b${name}="([^"]*)"`, "i").exec(text)?.[1] ?? null;
9
+ export function parseActiveApp(xml) {
10
+ const element = /<app\b[^>]*>([^<]*)<\/app>/.exec(xml);
11
+ return element
12
+ ? { id: attribute(element[0], "id"), name: element[1].trim() }
13
+ : { id: null, name: null };
14
+ }
15
+ export function parseMediaPlayer(xml) {
16
+ const player = /<player\b[^>]*>/.exec(xml)?.[0] ?? "";
17
+ const seconds = (value) => {
18
+ if (!value) return null;
19
+ const number = parseFloat(value);
20
+ return Number.isFinite(number) ? number / (value.includes("ms") ? 1000 : 1) : null;
21
+ };
22
+ return {
23
+ state: attribute(player, "state"),
24
+ error: attribute(player, "error"),
25
+ positionSeconds: seconds(xmlText(xml, "position")),
26
+ durationSeconds: seconds(xmlText(xml, "duration")),
27
+ };
28
+ }
29
+ export function parseDeviceFacts(xml) {
30
+ return {
31
+ model: xmlText(xml, "model-number"),
32
+ modelName: xmlText(xml, "model-name"),
33
+ firmware: xmlText(xml, "software-version"),
34
+ developerEnabled: xmlText(xml, "developer-enabled"),
35
+ };
36
+ }
37
+ export function createRokuDeviceClient({
38
+ host,
39
+ ecpPort = 8060,
40
+ installerPort = 80,
41
+ timeoutMs = 5000,
42
+ }) {
43
+ if (
44
+ typeof host !== "string" ||
45
+ !/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9.-]*[a-zA-Z0-9])?)$/.test(host) ||
46
+ host.includes("..")
47
+ )
48
+ throw Error(
49
+ "Choose a device IPv4 address or hostname without a URL, credentials, path or port",
50
+ );
51
+ const origin = `http://${host}:${ecpPort}`,
52
+ installer = `http://${host}:${installerPort}`;
53
+ const request = async (path, { method = "GET", headers, body, base = origin } = {}) => {
54
+ const result = await fetch(new URL(path, base), {
55
+ method,
56
+ headers,
57
+ body,
58
+ redirect: "error",
59
+ signal: AbortSignal.timeout(timeoutMs),
60
+ });
61
+ if (!result.ok) throw Error(`Roku ${method} ${path} returned ${result.status}`);
62
+ return result;
63
+ };
64
+ const query = async (name) => {
65
+ if (!/^[a-z0-9/-]+(?:\?[a-z0-9_=&]+)?$/i.test(name) || name.toLowerCase().includes("registry"))
66
+ throw Error("Unsupported diagnostic query");
67
+ return (await request("/query/" + name)).text();
68
+ };
69
+ const keypress = async (key) => {
70
+ if (
71
+ ![
72
+ "Up",
73
+ "Down",
74
+ "Left",
75
+ "Right",
76
+ "Select",
77
+ "Back",
78
+ "Home",
79
+ "Play",
80
+ "Rev",
81
+ "Fwd",
82
+ "Info",
83
+ ].includes(key)
84
+ )
85
+ throw Error("Unsupported qualification key");
86
+ await request("/keypress/" + key, { method: "POST" });
87
+ };
88
+ async function digest(path, options, password) {
89
+ const url = new URL(path, installer);
90
+ const challenge = await fetch(url, {
91
+ ...options,
92
+ redirect: "error",
93
+ signal: AbortSignal.timeout(timeoutMs),
94
+ });
95
+ if (challenge.ok) return challenge;
96
+ if (challenge.status !== 401)
97
+ throw Error(`Developer screenshot endpoint returned ${challenge.status}`);
98
+ const header = challenge.headers.get("www-authenticate") ?? "";
99
+ const fields = Object.fromEntries(
100
+ [...header.matchAll(/([a-z]+)=(?:"([^"]*)"|([^, ]+))/gi)].map((match) => [
101
+ match[1].toLowerCase(),
102
+ match[2] ?? match[3],
103
+ ]),
104
+ );
105
+ if (
106
+ !/^Digest /i.test(header) ||
107
+ !fields.realm ||
108
+ !fields.nonce ||
109
+ !["MD5", "SHA-256"].includes(fields.algorithm ?? "MD5") ||
110
+ !fields.qop
111
+ ?.split(",")
112
+ .map((value) => value.trim())
113
+ .includes("auth")
114
+ )
115
+ throw Error("Unsupported developer authentication challenge");
116
+ const algorithm = (fields.algorithm ?? "MD5").toLowerCase().replace("-", ""),
117
+ hash = (value) => createHash(algorithm).update(value).digest("hex"),
118
+ username = "rokudev",
119
+ cnonce = randomBytes(12).toString("hex"),
120
+ nc = "00000001",
121
+ uri = url.pathname + url.search,
122
+ method = options.method ?? "GET";
123
+ const response = hash(
124
+ `${hash(`${username}:${fields.realm}:${password}`)}:${fields.nonce}:${nc}:${cnonce}:auth:${hash(`${method}:${uri}`)}`,
125
+ );
126
+ const quote = (value) =>
127
+ '"' + String(value).replaceAll("\\", "\\\\").replaceAll('"', '\\"') + '"';
128
+ const authorization =
129
+ "Digest " +
130
+ Object.entries({
131
+ username,
132
+ realm: fields.realm,
133
+ nonce: fields.nonce,
134
+ uri,
135
+ response,
136
+ algorithm: fields.algorithm ?? "MD5",
137
+ qop: "auth",
138
+ nc,
139
+ cnonce,
140
+ ...(fields.opaque ? { opaque: fields.opaque } : {}),
141
+ })
142
+ .map(
143
+ ([name, value]) =>
144
+ `${name}=${["algorithm", "qop", "nc"].includes(name) ? value : quote(value)}`,
145
+ )
146
+ .join(", ");
147
+ const result = await fetch(url, {
148
+ ...options,
149
+ headers: { ...options.headers, Authorization: authorization },
150
+ redirect: "error",
151
+ signal: AbortSignal.timeout(timeoutMs),
152
+ });
153
+ if (!result.ok)
154
+ throw Error(`Developer screenshot authentication/request failed (${result.status})`);
155
+ return result;
156
+ }
157
+ async function screenshot(password) {
158
+ if (!password)
159
+ throw Error("Set ROKU_DEV_PASSWORD in the environment to collect a developer screenshot");
160
+ const form = new FormData();
161
+ form.append("mysubmit", "Screenshot");
162
+ form.append("archive", "");
163
+ form.append("passwd", "");
164
+ const html = await (
165
+ await digest("/plugin_inspect", { method: "POST", body: form }, password)
166
+ ).text();
167
+ const match = /<img\s+src="(pkgs\/dev\.(?:jpg|png)(?:\?[^"<>]*)?)"/i.exec(html);
168
+ if (!match)
169
+ throw Error(
170
+ "Developer installer returned no screenshot; keep the sideloaded app in the foreground",
171
+ );
172
+ const data = Buffer.from(await (await digest("/" + match[1], {}, password)).arrayBuffer());
173
+ const format = data.subarray(0, 4).equals(Buffer.from([137, 80, 78, 71]))
174
+ ? "png"
175
+ : data.subarray(0, 3).equals(Buffer.from([255, 216, 255]))
176
+ ? "jpg"
177
+ : null;
178
+ if (!format) throw Error("Developer installer returned non-image screenshot data");
179
+ return { data, format };
180
+ }
181
+ return {
182
+ query,
183
+ keypress,
184
+ screenshot,
185
+ launch: async () => {
186
+ await request("/launch/dev", { method: "POST" });
187
+ },
188
+ terminate: async () => {
189
+ const result = await fetch(new URL("/exit-app/dev/true", origin), {
190
+ method: "POST",
191
+ redirect: "error",
192
+ signal: AbortSignal.timeout(timeoutMs),
193
+ });
194
+ if (!result.ok && result.status !== 404)
195
+ throw Error(`Roku cold-start termination returned ${result.status}`);
196
+ return result.status === 404 ? "not-running" : "terminated";
197
+ },
198
+ appInstalled: async (expectedName) => {
199
+ const xml = await query("apps");
200
+ return [...xml.matchAll(/<app\b[^>]*>([^<]*)<\/app>/g)].some(
201
+ (match) => attribute(match[0], "id") === "dev" && match[1].trim() === expectedName,
202
+ );
203
+ },
204
+ };
205
+ }
206
+ /** Only diagnostic-prefixed lines are retained. Arbitrary application logs are not collected. */
207
+ export function captureRokuDiagnostics(
208
+ host,
209
+ { port = 8085, maxLines = 2000, maxLineLength = 8192 } = {},
210
+ ) {
211
+ if (
212
+ !Number.isInteger(maxLines) ||
213
+ maxLines < 1 ||
214
+ maxLines > 10000 ||
215
+ !Number.isInteger(maxLineLength) ||
216
+ maxLineLength < 256 ||
217
+ maxLineLength > 16384
218
+ )
219
+ throw Error("Choose bounded diagnostic line and buffer limits");
220
+ const lines = [];
221
+ let decoder = new StringDecoder("utf8");
222
+ let pending = "",
223
+ available = false,
224
+ status = "connecting",
225
+ discarded = false,
226
+ droppedLines = 0,
227
+ settle;
228
+ const ready = new Promise((resolve) => {
229
+ settle = resolve;
230
+ });
231
+ const retain = (value) => {
232
+ const line = value.replace(/\r/g, "").replace(/\u001b\[[0-9;]*[A-Za-z]/g, "");
233
+ if (!line.includes("RNR_") && !isRokuDiagnosticError(line)) return;
234
+ lines.push(
235
+ line
236
+ .replace(/Bearer\s+\S+/gi, "Bearer [redacted]")
237
+ .replace(
238
+ /((?:token|password|authorization|cookie|secret)["']?\s*[=:]\s*)("(?:\\.|[^"])*"|'[^']*'|[^,\s}]+)/gi,
239
+ "$1[redacted]",
240
+ )
241
+ .replace(/https?:\/\/[^\s"']+/gi, "[url omitted]"),
242
+ );
243
+ if (lines.length > maxLines) {
244
+ lines.shift();
245
+ droppedLines++;
246
+ }
247
+ };
248
+ const flush = () => {
249
+ if (!discarded && pending) retain(pending);
250
+ pending = "";
251
+ discarded = false;
252
+ };
253
+ const socket = createConnection({ host, port });
254
+ socket.setTimeout(5000, () => {
255
+ status = "timed-out";
256
+ settle(false);
257
+ socket.destroy();
258
+ });
259
+ socket.on("connect", () => {
260
+ available = true;
261
+ status = "connected";
262
+ settle(true);
263
+ socket.setTimeout(0);
264
+ });
265
+ socket.on("error", () => {
266
+ status = "error";
267
+ settle(false);
268
+ });
269
+ socket.on("close", () => {
270
+ flush();
271
+ if (status === "connected" || status === "connecting") status = "closed";
272
+ settle(false);
273
+ });
274
+ socket.on("data", (data) => {
275
+ const complete = decoder.write(data).split("\n");
276
+ for (let index = 0; index < complete.length; index++) {
277
+ const part = complete[index];
278
+ if (!discarded && pending.length + part.length <= maxLineLength) pending += part;
279
+ else {
280
+ if (!discarded) droppedLines++;
281
+ discarded = true;
282
+ pending = "";
283
+ }
284
+ if (index === complete.length - 1) break;
285
+ const line = pending;
286
+ pending = "";
287
+ if (discarded) {
288
+ discarded = false;
289
+ continue;
290
+ }
291
+ retain(line);
292
+ }
293
+ });
294
+ return {
295
+ ready,
296
+ clear: () => {
297
+ lines.length = 0;
298
+ pending = "";
299
+ discarded = false;
300
+ droppedLines = 0;
301
+ decoder = new StringDecoder("utf8");
302
+ },
303
+ snapshot: () => ({ available, status, droppedLines, lines: [...lines] }),
304
+ close: () => {
305
+ flush();
306
+ settle(false);
307
+ socket.destroy();
308
+ },
309
+ };
310
+ }
@@ -0,0 +1,29 @@
1
+ export declare const toolchain: {
2
+ node: { minimum: string; major: number };
3
+ pnpm: string;
4
+ packages: Record<string, string>;
5
+ optionalPackages: { metro: Record<string, string> };
6
+ groups: Record<string, string[]>;
7
+ };
8
+ export type RokuBuildProfile = "production" | "development";
9
+ export declare function rokuBuildProfile(name?: RokuBuildProfile): {
10
+ readonly name: RokuBuildProfile;
11
+ readonly development: boolean;
12
+ readonly defines: Readonly<Record<string, string>>;
13
+ };
14
+ export declare function supportedNode(version?: string): boolean;
15
+ export declare function executable(path: string): boolean;
16
+ export declare function findCommand(name: string): string | null;
17
+ export declare function findChromium(): string | null;
18
+ export declare function installedPackage(
19
+ root: string,
20
+ name: string,
21
+ ): { name: string; version: string };
22
+ export declare function doctorEnvironment(
23
+ root?: string,
24
+ options?: { browser?: boolean },
25
+ ): {
26
+ status: string;
27
+ checks: Array<{ name: string; status: string; message?: string }>;
28
+ deviceQualified: boolean;
29
+ };
@@ -0,0 +1,144 @@
1
+ import { readFileSync, existsSync, accessSync, constants } from "node:fs";
2
+ import { resolve, dirname, delimiter } from "node:path";
3
+ import { createRequire } from "node:module";
4
+ import { spawnSync } from "node:child_process";
5
+
6
+ export const toolchain = Object.freeze(
7
+ JSON.parse(readFileSync(new URL("../config/toolchain.json", import.meta.url))),
8
+ );
9
+ const buildProfiles = Object.freeze(
10
+ Object.fromEntries(
11
+ ["production", "development"].map((name) => [
12
+ name,
13
+ Object.freeze({
14
+ name,
15
+ development: name === "development",
16
+ defines: Object.freeze({
17
+ global: "globalThis",
18
+ __DEV__: JSON.stringify(name === "development"),
19
+ "process.env.NODE_ENV": JSON.stringify(name),
20
+ "process.env": JSON.stringify({ NODE_ENV: name }),
21
+ }),
22
+ }),
23
+ ]),
24
+ ),
25
+ );
26
+ /** React compilation profile; channel identity and deployment remain consumer policy. */
27
+ export function rokuBuildProfile(name = "production") {
28
+ if (typeof name !== "string" || !Object.hasOwn(buildProfiles, name))
29
+ throw Error("Choose Roku profile production or development");
30
+ return buildProfiles[name];
31
+ }
32
+ export function supportedNode(version = process.versions.node) {
33
+ const parts = version.replace(/^v/, "").split(".").map(Number);
34
+ const floor = toolchain.node.minimum.split(".").map(Number);
35
+ return (
36
+ parts.length === 3 &&
37
+ parts.every(Number.isInteger) &&
38
+ parts[0] === toolchain.node.major &&
39
+ (parts[1] > floor[1] || (parts[1] === floor[1] && parts[2] >= floor[2]))
40
+ );
41
+ }
42
+ export function executable(path) {
43
+ try {
44
+ accessSync(path, constants.X_OK);
45
+ return true;
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+ export function findCommand(name) {
51
+ return (
52
+ (process.env.PATH ?? "")
53
+ .split(delimiter)
54
+ .map((directory) => resolve(directory, name))
55
+ .find(executable) ?? null
56
+ );
57
+ }
58
+ export function findChromium() {
59
+ const explicit = process.env.ROKU_TEST_CHROMIUM;
60
+ if (explicit) return executable(explicit) ? explicit : null;
61
+ return (
62
+ [
63
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
64
+ "/usr/bin/chromium",
65
+ "/usr/bin/chromium-browser",
66
+ "/usr/bin/google-chrome",
67
+ findCommand("google-chrome"),
68
+ findCommand("chromium"),
69
+ ].find((path) => path && executable(path)) ?? null
70
+ );
71
+ }
72
+ export function installedPackage(root, name) {
73
+ const require = createRequire(resolve(root, "package.json"));
74
+ let path;
75
+ try {
76
+ path = require.resolve(`${name}/package.json`);
77
+ } catch {
78
+ // Some SDK packages expose only subpaths, with neither a root entry nor
79
+ // package.json exported. Read metadata through Node's package search paths.
80
+ for (const directory of require.resolve.paths(name) ?? []) {
81
+ const candidate = resolve(directory, name, "package.json");
82
+ if (existsSync(candidate)) {
83
+ path = candidate;
84
+ break;
85
+ }
86
+ }
87
+ if (path) return JSON.parse(readFileSync(path));
88
+ let directory = dirname(require.resolve(name));
89
+ while (directory !== dirname(directory)) {
90
+ const candidate = resolve(directory, "package.json");
91
+ if (existsSync(candidate) && JSON.parse(readFileSync(candidate)).name === name) {
92
+ path = candidate;
93
+ break;
94
+ }
95
+ directory = dirname(directory);
96
+ }
97
+ }
98
+ if (!path) throw Error(`Cannot locate ${name}`);
99
+ return JSON.parse(readFileSync(path));
100
+ }
101
+ export function doctorEnvironment(root = process.cwd(), { browser = true } = {}) {
102
+ const checks = [];
103
+ const check = (name, work) => {
104
+ try {
105
+ const message = work();
106
+ checks.push({ name, status: "passed", ...(message ? { message } : {}) });
107
+ } catch (error) {
108
+ checks.push({ name, status: "failed", message: error.message });
109
+ }
110
+ };
111
+ check("Node", () => {
112
+ if (!supportedNode())
113
+ throw Error(`Use Node >=${toolchain.node.minimum} <25; found ${process.versions.node}`);
114
+ });
115
+ check("host OS", () => {
116
+ if (!["darwin", "linux"].includes(process.platform))
117
+ throw Error("Build/development qualification supports macOS and Linux");
118
+ });
119
+ check("pnpm", () => {
120
+ const result = spawnSync("pnpm", ["--version"], { encoding: "utf8", timeout: 10000 });
121
+ if (result.status !== 0 || result.stdout.trim() !== toolchain.pnpm)
122
+ throw Error(`Use pnpm ${toolchain.pnpm}`);
123
+ });
124
+ for (const name of ["zip", "unzip", "tar"])
125
+ check(name, () => {
126
+ if (!findCommand(name)) throw Error(`Install ${name} and add it to PATH`);
127
+ });
128
+ if (browser)
129
+ check("Chromium", () => {
130
+ const path = findChromium();
131
+ if (!path) throw Error("Install Chrome/Chromium or set ROKU_TEST_CHROMIUM to its executable");
132
+ return path;
133
+ });
134
+ for (const [name, version] of Object.entries(toolchain.packages))
135
+ check(name, () => {
136
+ if (installedPackage(root, name).version !== version)
137
+ throw Error(`Expected ${name}@${version}; reinstall the pinned graph`);
138
+ });
139
+ return {
140
+ status: checks.every((value) => value.status === "passed") ? "passed" : "failed",
141
+ checks,
142
+ deviceQualified: false,
143
+ };
144
+ }
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from "esbuild";
2
+ export declare function rokuPlugin(options?: {
3
+ root?: string;
4
+ generatedDirectory?: string;
5
+ }): Plugin;
@@ -0,0 +1,118 @@
1
+ import { resolveRokuRelative } from "./resolution.mjs";
2
+ import { createRequire } from "node:module";
3
+ import { readFileSync } from "node:fs";
4
+ import { resolve } from "node:path";
5
+ import { resolveAdapter, resolveRuntime } from "./index.mjs";
6
+ import { prepareHermesYoga } from "./yoga.mjs";
7
+ import { prepareIntlDataModules } from "./intl.mjs";
8
+ import {
9
+ nativewindLeaf,
10
+ prepareNativewindInterop,
11
+ prepareNativewindPreferences,
12
+ prepareNativewindInputState,
13
+ } from "./nativewind.mjs";
14
+
15
+ /** Frontend-only platform resolution. Keep SDK anchor code in its own SDK stage. */
16
+ export function rokuPlugin({ root = process.cwd(), generatedDirectory } = {}) {
17
+ const require = createRequire(resolve(root, "package.json"));
18
+ return {
19
+ name: "react-native-roku",
20
+ setup(builder) {
21
+ const builtinResolution = {};
22
+ builder.initialOptions.mainFields ??= ["module", "main"];
23
+ builder.initialOptions.conditions ??= ["roku", "import", "default"];
24
+ builder.onLoad(
25
+ { filter: /@formatjs[/\\]intl-collator[/\\](?:index|polyfill(?:-force)?)\.js$/ },
26
+ (args) => ({
27
+ loader: "js",
28
+ contents: prepareIntlDataModules(args.path, generatedDirectory).contents,
29
+ resolveDir: resolve(args.path, ".."),
30
+ }),
31
+ );
32
+ builder.onLoad({ filter: /@rn-primitives[/\\]portal[/\\]dist[/\\]index\.mjs$/ }, (args) => ({
33
+ loader: "jsx",
34
+ contents: readFileSync(args.path, "utf8"),
35
+ }));
36
+ builder.onLoad(
37
+ {
38
+ filter: /react-native-css-interop[/\\]dist[/\\]runtime[/\\]native[/\\]api\.js$/,
39
+ },
40
+ (args) => ({
41
+ loader: "js",
42
+ contents: prepareNativewindInterop(
43
+ readFileSync(args.path, "utf8"),
44
+ resolveRuntime("interop/nativewind"),
45
+ ),
46
+ }),
47
+ );
48
+ builder.onLoad(
49
+ {
50
+ filter:
51
+ /react-native-css-interop[/\\]dist[/\\]runtime[/\\]native[/\\]native-interop\.js$/,
52
+ },
53
+ (args) => ({
54
+ loader: "js",
55
+ contents: prepareNativewindInputState(readFileSync(args.path, "utf8")),
56
+ }),
57
+ );
58
+ builder.onLoad(
59
+ {
60
+ filter:
61
+ /react-native-css-interop[/\\]dist[/\\]runtime[/\\]native[/\\]appearance-observables\.js$/,
62
+ },
63
+ (args) => ({
64
+ loader: "js",
65
+ contents: prepareNativewindPreferences(readFileSync(args.path, "utf8")),
66
+ }),
67
+ );
68
+ builder.onLoad(
69
+ {
70
+ filter: /yoga-layout-prebuilt[/\\]yoga-layout[/\\]build[/\\]Release[/\\]nbind\.js$/,
71
+ },
72
+ (args) => ({
73
+ loader: "js",
74
+ contents: prepareHermesYoga(args.path).contents,
75
+ }),
76
+ );
77
+ builder.onResolve({ filter: /.*/ }, async (args) => {
78
+ if (args.pluginData === builtinResolution) return;
79
+ const adapter = resolveAdapter(args.path);
80
+ if (adapter) return { path: adapter };
81
+ if (args.path === "react" || args.path.startsWith("react/"))
82
+ return { path: require.resolve(args.path) };
83
+ const leaf = nativewindLeaf(args.path, args.importer, require);
84
+ if (leaf) return { path: leaf };
85
+ if (args.path.startsWith("react-native/"))
86
+ return {
87
+ errors: [
88
+ {
89
+ text: `Private React Native import needs an explicit Roku adapter: ${args.path} (from ${args.importer})`,
90
+ },
91
+ ],
92
+ };
93
+ if (args.path.startsWith("@roku-sdk/"))
94
+ return {
95
+ errors: [
96
+ {
97
+ text: `SDK mechanics belong in the bootstrap, not the React frontend: ${args.path}`,
98
+ },
99
+ ],
100
+ };
101
+ if (args.importer) {
102
+ const selected = resolveRokuRelative(args.importer, args.path);
103
+ if (selected) {
104
+ // Preserve package sideEffects metadata when selecting a source
105
+ // variant. Returning only a path retains every re-exported icon.
106
+ const resolved = await builder.resolve(selected, {
107
+ kind: args.kind,
108
+ resolveDir: args.resolveDir,
109
+ pluginData: builtinResolution,
110
+ });
111
+ return { ...resolved, pluginData: args.pluginData };
112
+ }
113
+ }
114
+ return undefined;
115
+ });
116
+ },
117
+ };
118
+ }
@@ -0,0 +1,27 @@
1
+ import type { FontFamilyGroups } from "../src/layout/fontFaces.mjs";
2
+ export declare function deriveTabularFont(input: Uint8Array): {
3
+ bytes: Uint8Array;
4
+ family: string;
5
+ sourceSha256: string;
6
+ digitAdvance: number;
7
+ characters: number;
8
+ };
9
+ export declare function prepareRokuFontAssets(options: {
10
+ assets: Readonly<Record<string, string>>;
11
+ families?: FontFamilyGroups;
12
+ variants?: readonly "tabular-nums"[];
13
+ outputDirectory: string;
14
+ }): {
15
+ assets: Record<string, string>;
16
+ families: FontFamilyGroups;
17
+ faces: Array<{
18
+ family: string;
19
+ fontFamily?: string;
20
+ path: string;
21
+ sha256: string;
22
+ sourceSha256: string;
23
+ features: string[];
24
+ digitAdvance?: number;
25
+ characters?: number;
26
+ }>;
27
+ };