react-native-roku 0.0.0-stage → 0.2.0-preview.3
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 +328 -0
- package/CONTRIBUTING.md +34 -0
- package/LICENSE +21 -0
- package/NOTICE.md +10 -0
- package/README.md +66 -2
- package/bin/react-native-roku.mjs +91 -0
- package/build/assets.cjs +311 -0
- package/build/assets.d.cts +50 -0
- package/build/compatibility.d.mts +40 -0
- package/build/compatibility.mjs +272 -0
- package/build/dev.d.mts +34 -0
- package/build/dev.mjs +297 -0
- package/build/devWorkspace.d.mts +11 -0
- package/build/devWorkspace.mjs +86 -0
- package/build/device.d.mts +47 -0
- package/build/device.mjs +310 -0
- package/build/environment.d.mts +29 -0
- package/build/environment.mjs +144 -0
- package/build/esbuild.d.mts +5 -0
- package/build/esbuild.mjs +118 -0
- package/build/fontVariants.d.mts +27 -0
- package/build/fontVariants.mjs +424 -0
- package/build/frontend.d.mts +52 -0
- package/build/frontend.mjs +75 -0
- package/build/identity.mjs +45 -0
- package/build/index.d.mts +22 -0
- package/build/index.mjs +87 -0
- package/build/intl.mjs +121 -0
- package/build/metro.cjs +38 -0
- package/build/metro.d.cts +37 -0
- package/build/metroFrontend.mjs +222 -0
- package/build/metroMetadata.mjs +119 -0
- package/build/metroModules.mjs +397 -0
- package/build/metroRefresh.d.mts +64 -0
- package/build/metroRefresh.mjs +346 -0
- package/build/metroTransformer.cjs +146 -0
- package/build/nativeTextMemo.mjs +296 -0
- package/build/nativewind.d.mts +9 -0
- package/build/nativewind.mjs +92 -0
- package/build/project.d.mts +111 -0
- package/build/project.mjs +615 -0
- package/build/reactCompiler.mjs +113 -0
- package/build/reactProfile.cjs +35 -0
- package/build/refreshRuntime.mjs +187 -0
- package/build/refreshSourceMap.mjs +53 -0
- package/build/release.mjs +99 -0
- package/build/resolution.d.mts +3 -0
- package/build/resolution.mjs +25 -0
- package/build/surfaces.d.mts +1 -0
- package/build/surfaces.mjs +42 -0
- package/build/testing/node.d.mts +29 -0
- package/build/testing/node.mjs +106 -0
- package/build/yoga.d.mts +8 -0
- package/build/yoga.mjs +186 -0
- package/compatibility/public-api.json +327 -0
- package/compatibility/registry.json +2258 -0
- package/config/release.json +15 -0
- package/config/toolchain.json +34 -0
- package/docs/compatibility.md +813 -0
- package/docs/getting-started.md +460 -0
- package/docs/maintenance.md +368 -0
- package/docs/qualification.md +241 -0
- package/docs/standalone-testing.md +56 -0
- package/examples/hello-roku/README.md +35 -0
- package/examples/hello-roku/package.template.json +31 -0
- package/examples/hello-roku/pnpm-workspace.yaml +11 -0
- package/examples/hello-roku/roku.config.json +22 -0
- package/examples/hello-roku/src/App.tsx +54 -0
- package/examples/hello-roku/src/Catalog.tsx +200 -0
- package/examples/hello-roku/src/assets.d.ts +16 -0
- package/examples/hello-roku/src/catalog-cover.png +0 -0
- package/examples/hello-roku/tsconfig.json +1 -0
- package/examples/hello-roku/tsconfig.react.json +1 -0
- package/native/components/RNRAppControl.brs +215 -0
- package/native/components/RNRAppControl.xml +13 -0
- package/native/components/RNRDeviceFacts.brs +19 -0
- package/native/components/RNRDeviceFacts.xml +9 -0
- package/native/components/RNRDeviceFactsTask.brs +74 -0
- package/native/components/RNRDeviceFactsTask.xml +9 -0
- package/native/components/RNRTextRaster.brs +15 -0
- package/native/components/RNRTextRaster.xml +9 -0
- package/native/components/RNRTextRasterTask.brs +77 -0
- package/native/components/RNRTextRasterTask.xml +9 -0
- package/native/manifest.json +7 -0
- package/package.json +183 -3
- package/src/animation/clock.ts +10 -0
- package/src/animation/derivedValue.ts +163 -0
- package/src/animation/legacyAnimated.ts +255 -0
- package/src/animation/reanimated.ts +243 -0
- package/src/animation/sharedValue.ts +285 -0
- package/src/animation/worklets.ts +23 -0
- package/src/application/AppRegistry.ts +31 -0
- package/src/application/mountApplication.ts +136 -0
- package/src/graphics/BitmapLayer.tsx +68 -0
- package/src/graphics/RoundedBorder.tsx +116 -0
- package/src/graphics/TextRasterCache.ts +259 -0
- package/src/graphics/gradient.ts +37 -0
- package/src/graphics/inlineRaster.ts +85 -0
- package/src/graphics/png.ts +77 -0
- package/src/graphics/rasterPixels.ts +89 -0
- package/src/graphics/surfaces.ts +105 -0
- package/src/graphics/textRaster.types.ts +60 -0
- package/src/graphics/textRasterGeometry.ts +116 -0
- package/src/host/host.types.ts +57 -0
- package/src/index.ts +22 -0
- package/src/interop/nativewind.ts +2 -0
- package/src/layout/FontResources.ts +252 -0
- package/src/layout/affine.ts +89 -0
- package/src/layout/flexLayout.ts +398 -0
- package/src/layout/fontFaces.d.mts +19 -0
- package/src/layout/fontFaces.mjs +85 -0
- package/src/layout/fontVariants.d.mts +2 -0
- package/src/layout/fontVariants.mjs +8 -0
- package/src/layout/inlineParagraph.ts +158 -0
- package/src/layout/inlineText.ts +68 -0
- package/src/layout/layoutReuse.ts +117 -0
- package/src/layout/nativeNodeFields.ts +179 -0
- package/src/layout/preparedFields.ts +78 -0
- package/src/layout/textLayout.ts +138 -0
- package/src/layout/transform.ts +113 -0
- package/src/media/SceneGraphAudio.ts +161 -0
- package/src/media/SceneGraphVideo.ts +167 -0
- package/src/media/audioSession.ts +84 -0
- package/src/media/index.ts +2 -0
- package/src/media/videoErrorDetails.ts +40 -0
- package/src/media/videoSession.ts +136 -0
- package/src/navigation/RouterStore.ts +244 -0
- package/src/navigation/expoRouter.ts +115 -0
- package/src/react-native/NativeInput.ts +494 -0
- package/src/react-native/NativeSystemState.ts +95 -0
- package/src/react-native/accessibility.ts +265 -0
- package/src/react-native/activityIndicator.ts +72 -0
- package/src/react-native/compilerPressable.ts +26 -0
- package/src/react-native/createNativeRoot.ts +2126 -0
- package/src/react-native/directionalFocus.ts +55 -0
- package/src/react-native/environment.ts +275 -0
- package/src/react-native/flatList.ts +1001 -0
- package/src/react-native/flatListViewability.ts +231 -0
- package/src/react-native/focusEvents.ts +85 -0
- package/src/react-native/image.ts +247 -0
- package/src/react-native/index.ts +54 -0
- package/src/react-native/interactionManager.ts +76 -0
- package/src/react-native/keyboard.ts +60 -0
- package/src/react-native/linearGradient.ts +94 -0
- package/src/react-native/modal.tsx +148 -0
- package/src/react-native/nativeHostContext.ts +80 -0
- package/src/react-native/nativeModules.ts +86 -0
- package/src/react-native/nativeRoot.types.ts +22 -0
- package/src/react-native/nativeViewHandle.ts +191 -0
- package/src/react-native/nativewindPressable.ts +38 -0
- package/src/react-native/panResponder.ts +73 -0
- package/src/react-native/primitives.ts +685 -0
- package/src/react-native/safeArea.ts +76 -0
- package/src/react-native/scrollView.ts +289 -0
- package/src/react-native/styleInterop.ts +8 -0
- package/src/react-native/styleSheet.ts +54 -0
- package/src/react-native/textInput.ts +334 -0
- package/src/react-native/unsupported.ts +25 -0
- package/src/renderer/SceneRoot.ts +1006 -0
- package/src/scene/SdkDeviceFacts.ts +151 -0
- package/src/scene/SdkDeviceServices.ts +72 -0
- package/src/scene/SdkSceneGraph.ts +124 -0
- package/src/scene/SdkTextEntry.ts +321 -0
- package/src/scene/SdkTextMetrics.ts +136 -0
- package/src/scene/SdkTextRasterTransport.ts +191 -0
- package/src/scene/SdkWebTransport.ts +122 -0
- package/src/scene/createRokuHost.ts +213 -0
- package/src/scene/sceneGraph.types.ts +38 -0
- package/src/services/DeviceServices.ts +53 -0
- package/src/services/RegistryStorage.ts +85 -0
- package/src/services/RokuKeySession.ts +29 -0
- package/src/services/asyncStorage.ts +23 -0
- package/src/services/base64.ts +52 -0
- package/src/services/crypto.ts +18 -0
- package/src/services/expoConstants.ts +11 -0
- package/src/services/expoLinking.ts +12 -0
- package/src/services/expoStatusBar.ts +4 -0
- package/src/services/installWebRuntime.ts +105 -0
- package/src/services/intlEnglish.ts +54 -0
- package/src/services/languageRuntime.ts +65 -0
- package/src/services/nativeTimers.ts +96 -0
- package/src/services/secureStore.ts +23 -0
- package/src/services/textEntryRequest.ts +22 -0
- package/src/services/utf8.ts +57 -0
- package/src/services/webRuntime.ts +346 -0
- package/src/testing/CanvasResources.ts +141 -0
- package/src/testing/CanvasSceneGraph.ts +496 -0
- package/src/testing/CanvasTextEntry.ts +237 -0
- package/src/testing/PreviewTextObservations.ts +82 -0
- package/src/testing/RecordingSceneGraph.ts +136 -0
- package/src/types/normalize-colors.d.ts +4 -0
- package/src/vector/dynamicSvg.tsx +226 -0
- package/src/vector/svg.ts +222 -0
- package/src/vector/svg.types.ts +4 -0
- package/src/vector/svgElements.ts +58 -0
- package/src/vector/svgKey.d.mts +4 -0
- package/src/vector/svgKey.mjs +16 -0
- package/src/vector/svgPath.ts +157 -0
- package/src/vector/svgPixels.ts +133 -0
- package/tsconfig.consumer.json +29 -0
package/build/dev.d.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
export interface DevState {
|
|
3
|
+
state: string;
|
|
4
|
+
generation: number;
|
|
5
|
+
error: string | null;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
refresh?: import("./metroRefresh.mjs").RokuRefreshPlan;
|
|
8
|
+
metrics: {
|
|
9
|
+
builds: number;
|
|
10
|
+
failures: number;
|
|
11
|
+
lastBuildMs: number | null;
|
|
12
|
+
lastEditToReadyMs: number | null;
|
|
13
|
+
recentBuildMs: number[];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function createRokuDevServer(options: {
|
|
17
|
+
build(context: {
|
|
18
|
+
generation: number;
|
|
19
|
+
}): Promise<
|
|
20
|
+
string | { directory: string; refresh?: import("./metroRefresh.mjs").RokuRefreshPlan }
|
|
21
|
+
>;
|
|
22
|
+
watchPaths?: string[];
|
|
23
|
+
port?: number;
|
|
24
|
+
handleRequest?: (request: IncomingMessage, response: ServerResponse) => boolean;
|
|
25
|
+
debounceMs?: number;
|
|
26
|
+
onBuild?: (state: DevState) => void;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
url: string;
|
|
29
|
+
snapshot(): DevState;
|
|
30
|
+
invalidate(): void;
|
|
31
|
+
rebuild(): Promise<void> | null;
|
|
32
|
+
idle(): Promise<void>;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}>;
|
package/build/dev.mjs
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { watch, readFileSync, existsSync, statSync, realpathSync } from "node:fs";
|
|
4
|
+
import { resolve, extname, sep } from "node:path";
|
|
5
|
+
const mime = {
|
|
6
|
+
".html": "text/html; charset=utf-8",
|
|
7
|
+
".js": "text/javascript",
|
|
8
|
+
".mjs": "text/javascript",
|
|
9
|
+
".map": "application/json",
|
|
10
|
+
".json": "application/json",
|
|
11
|
+
".ttf": "font/ttf",
|
|
12
|
+
".png": "image/png",
|
|
13
|
+
".jpg": "image/jpeg",
|
|
14
|
+
".jpeg": "image/jpeg",
|
|
15
|
+
".mp4": "video/mp4",
|
|
16
|
+
".css": "text/css",
|
|
17
|
+
};
|
|
18
|
+
const ignored = (path) =>
|
|
19
|
+
path
|
|
20
|
+
.split(/[\\/]/)
|
|
21
|
+
.some((part) =>
|
|
22
|
+
[
|
|
23
|
+
"node_modules",
|
|
24
|
+
".git",
|
|
25
|
+
".local",
|
|
26
|
+
".roku",
|
|
27
|
+
"dist",
|
|
28
|
+
"generated",
|
|
29
|
+
".build-state",
|
|
30
|
+
".turbo",
|
|
31
|
+
"coverage",
|
|
32
|
+
].includes(part),
|
|
33
|
+
) || /\.tsbuildinfo$/.test(path);
|
|
34
|
+
function browserClient(generation, sessionId) {
|
|
35
|
+
return `<script>(()=>{
|
|
36
|
+
let initial=${generation},closed=false,latest,queue=Promise.resolve();
|
|
37
|
+
const session=${JSON.stringify(sessionId)},events=new EventSource('/__roku/events');
|
|
38
|
+
function show(message){let panel=document.getElementById('roku-build-status');if(!panel){panel=document.createElement('div');panel.id='roku-build-status';panel.style.cssText='position:fixed;bottom:8px;left:8px;right:8px;padding:8px;background:#202030;color:white;z-index:999999;white-space:pre-wrap;font:13px monospace';document.body.append(panel);}panel.textContent=message||'';panel.hidden=!message;}
|
|
39
|
+
function reload(reason){if(closed)return;console.warn('Roku preview full reload',typeof reason==='string'?reason:'update delivery failed');closed=true;events.close();location.reload();}
|
|
40
|
+
events.onmessage=event=>{
|
|
41
|
+
const value=JSON.parse(event.data);latest=value;
|
|
42
|
+
if(value.state==='error'){show(value.error);return;}
|
|
43
|
+
if(value.state==='building'){show('Rebuilding Roku preview…');return;}
|
|
44
|
+
queue=queue.then(async()=>{
|
|
45
|
+
if(closed)return;
|
|
46
|
+
if(value.sessionId!==session){reload('development server changed');return;}
|
|
47
|
+
if(value.generation===initial)return;
|
|
48
|
+
const runtime=globalThis.__RNR_ROKU_REFRESH__;
|
|
49
|
+
if(value.refresh?.type!=='refresh'||!runtime){reload(value.refresh?.reason||'refresh runtime unavailable');return;}
|
|
50
|
+
const result=await runtime.applyUpdate(value.refresh);
|
|
51
|
+
if(closed||result.type==='retired')return;
|
|
52
|
+
if(result.type==='reload'){reload(result.reason||'refresh lifetime changed');return;}
|
|
53
|
+
initial=value.generation;
|
|
54
|
+
if(latest.state==='ready'&&latest.generation===value.generation)show(result.error);
|
|
55
|
+
}).catch(reload);
|
|
56
|
+
};
|
|
57
|
+
window.addEventListener('pagehide',()=>{closed=true;events.close();},{once:true});
|
|
58
|
+
})();</script>`;
|
|
59
|
+
}
|
|
60
|
+
/** Serial, coalescing development builds. Publication happens only after a complete successful build. */
|
|
61
|
+
export async function createRokuDevServer({
|
|
62
|
+
build,
|
|
63
|
+
watchPaths = [],
|
|
64
|
+
port = 9389,
|
|
65
|
+
handleRequest,
|
|
66
|
+
debounceMs = 120,
|
|
67
|
+
onBuild = () => {},
|
|
68
|
+
}) {
|
|
69
|
+
const clients = new Set(),
|
|
70
|
+
watchers = [];
|
|
71
|
+
let directory = null,
|
|
72
|
+
generation = 0,
|
|
73
|
+
state = "building",
|
|
74
|
+
error = null,
|
|
75
|
+
closed = false,
|
|
76
|
+
pending = false,
|
|
77
|
+
running = null,
|
|
78
|
+
timer;
|
|
79
|
+
let refreshPlan;
|
|
80
|
+
const sessionId = randomUUID();
|
|
81
|
+
let closing;
|
|
82
|
+
const durations = [];
|
|
83
|
+
let builds = 0,
|
|
84
|
+
failures = 0,
|
|
85
|
+
lastBuildMs = null,
|
|
86
|
+
invalidatedAt = null,
|
|
87
|
+
lastEditToReadyMs = null;
|
|
88
|
+
const snapshot = () => ({
|
|
89
|
+
state,
|
|
90
|
+
generation,
|
|
91
|
+
error,
|
|
92
|
+
sessionId,
|
|
93
|
+
...(refreshPlan ? { refresh: refreshPlan } : {}),
|
|
94
|
+
metrics: { builds, failures, lastBuildMs, lastEditToReadyMs, recentBuildMs: [...durations] },
|
|
95
|
+
});
|
|
96
|
+
const publish = () => {
|
|
97
|
+
const value = snapshot();
|
|
98
|
+
onBuild(value);
|
|
99
|
+
for (const client of clients) client.write(`data: ${JSON.stringify(value)}\n\n`);
|
|
100
|
+
};
|
|
101
|
+
const run = () => {
|
|
102
|
+
pending = true;
|
|
103
|
+
if (running || closed) return running;
|
|
104
|
+
running = (async () => {
|
|
105
|
+
while (pending && !closed) {
|
|
106
|
+
pending = false;
|
|
107
|
+
state = "building";
|
|
108
|
+
error = null;
|
|
109
|
+
publish();
|
|
110
|
+
const next = generation + 1;
|
|
111
|
+
const started = performance.now();
|
|
112
|
+
builds++;
|
|
113
|
+
try {
|
|
114
|
+
const result = await build({ generation: next });
|
|
115
|
+
if (closed) break;
|
|
116
|
+
const candidate = resolve(typeof result === "string" ? result : result.directory);
|
|
117
|
+
if (!existsSync(resolve(candidate, "index.html")))
|
|
118
|
+
throw Error("A development build needs index.html");
|
|
119
|
+
if (pending) continue;
|
|
120
|
+
directory = candidate;
|
|
121
|
+
generation = next;
|
|
122
|
+
refreshPlan = typeof result === "string" ? undefined : result.refresh;
|
|
123
|
+
lastBuildMs = Math.round(performance.now() - started);
|
|
124
|
+
durations.push(lastBuildMs);
|
|
125
|
+
if (durations.length > 32) durations.shift();
|
|
126
|
+
lastEditToReadyMs =
|
|
127
|
+
invalidatedAt === null ? null : Math.round(performance.now() - invalidatedAt);
|
|
128
|
+
invalidatedAt = null;
|
|
129
|
+
state = "ready";
|
|
130
|
+
error = null;
|
|
131
|
+
publish();
|
|
132
|
+
} catch (value) {
|
|
133
|
+
if (closed) break;
|
|
134
|
+
state = "error";
|
|
135
|
+
failures++;
|
|
136
|
+
lastBuildMs = Math.round(performance.now() - started);
|
|
137
|
+
error = value instanceof Error ? value.message : String(value);
|
|
138
|
+
publish();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
})().finally(() => {
|
|
142
|
+
running = null;
|
|
143
|
+
});
|
|
144
|
+
return running;
|
|
145
|
+
};
|
|
146
|
+
const invalidate = () => {
|
|
147
|
+
if (closed) return;
|
|
148
|
+
invalidatedAt ??= performance.now();
|
|
149
|
+
pending = true;
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
timer = setTimeout(() => {
|
|
152
|
+
if (pending) void run();
|
|
153
|
+
}, debounceMs);
|
|
154
|
+
};
|
|
155
|
+
const server = createServer((request, response) => {
|
|
156
|
+
const host = request.headers.host,
|
|
157
|
+
local = request.socket.localPort;
|
|
158
|
+
if (
|
|
159
|
+
![`127.0.0.1:${local}`, `localhost:${local}`].includes(host) ||
|
|
160
|
+
(request.headers.origin && request.headers.origin !== `http://${host}`)
|
|
161
|
+
) {
|
|
162
|
+
response.writeHead(403).end("Development origin refused");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const path = decodeURIComponent(new URL(request.url ?? "/", `http://${host}`).pathname);
|
|
167
|
+
if (path === "/__roku/events") {
|
|
168
|
+
response.writeHead(200, {
|
|
169
|
+
"Content-Type": "text/event-stream",
|
|
170
|
+
"Cache-Control": "no-store",
|
|
171
|
+
Connection: "keep-alive",
|
|
172
|
+
});
|
|
173
|
+
response.write(`data: ${JSON.stringify(snapshot())}\n\n`);
|
|
174
|
+
clients.add(response);
|
|
175
|
+
response.on("close", () => clients.delete(response));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (path === "/__roku/status") {
|
|
179
|
+
response
|
|
180
|
+
.writeHead(200, {
|
|
181
|
+
"Content-Type": "application/json",
|
|
182
|
+
"Cache-Control": "no-store",
|
|
183
|
+
})
|
|
184
|
+
.end(JSON.stringify(snapshot()));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (handleRequest?.(request, response)) return;
|
|
188
|
+
if (!directory) {
|
|
189
|
+
response
|
|
190
|
+
.writeHead(200, {
|
|
191
|
+
"Content-Type": "text/html",
|
|
192
|
+
"Cache-Control": "no-store",
|
|
193
|
+
})
|
|
194
|
+
.end(
|
|
195
|
+
'<!doctype html><body style="background:#101014;color:white;font:16px system-ui">Waiting for a successful Roku build.</body>' +
|
|
196
|
+
browserClient(generation, sessionId),
|
|
197
|
+
);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const file = resolve(directory, `.${path === "/" ? "/index.html" : path}`);
|
|
201
|
+
if (
|
|
202
|
+
!file.startsWith(directory + sep) ||
|
|
203
|
+
!existsSync(file) ||
|
|
204
|
+
!statSync(file).isFile() ||
|
|
205
|
+
!realpathSync(file).startsWith(realpathSync(directory) + sep) ||
|
|
206
|
+
path.split("/").some((part) => part.startsWith("."))
|
|
207
|
+
) {
|
|
208
|
+
response.writeHead(404).end("Not found");
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
let content = readFileSync(file);
|
|
212
|
+
if (extname(file) === ".html")
|
|
213
|
+
content = Buffer.from(content.toString() + browserClient(generation, sessionId));
|
|
214
|
+
response
|
|
215
|
+
.writeHead(200, {
|
|
216
|
+
"Content-Type": mime[extname(file)] ?? "application/octet-stream",
|
|
217
|
+
"Cache-Control": "no-store",
|
|
218
|
+
})
|
|
219
|
+
.end(content);
|
|
220
|
+
} catch {
|
|
221
|
+
response.writeHead(400).end("Invalid request");
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
await new Promise((resolve, reject) => {
|
|
225
|
+
server.once("error", reject);
|
|
226
|
+
server.listen(port, "127.0.0.1", resolve);
|
|
227
|
+
});
|
|
228
|
+
try {
|
|
229
|
+
for (const path of watchPaths) {
|
|
230
|
+
if (existsSync(path) && statSync(path).isDirectory()) {
|
|
231
|
+
watchers.push(
|
|
232
|
+
watch(path, { recursive: true }, (_event, file) => {
|
|
233
|
+
if (!file || !ignored(String(file))) invalidate();
|
|
234
|
+
}),
|
|
235
|
+
);
|
|
236
|
+
} else {
|
|
237
|
+
// File-name notifications for an atomic editor replacement can be lost
|
|
238
|
+
// or refer only to the temporary source. Poll the configured file's
|
|
239
|
+
// identity/metadata instead of depending on a directory rename event.
|
|
240
|
+
const signature = () => {
|
|
241
|
+
try {
|
|
242
|
+
const value = statSync(path);
|
|
243
|
+
return `${value.dev}:${value.ino}:${value.size}:${value.mtimeMs}:${value.ctimeMs}`;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
return `unavailable:${error.code ?? "unknown"}`;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
let previous = signature();
|
|
249
|
+
const poll = setInterval(() => {
|
|
250
|
+
const current = signature();
|
|
251
|
+
if (current !== previous) {
|
|
252
|
+
previous = current;
|
|
253
|
+
invalidate();
|
|
254
|
+
}
|
|
255
|
+
}, 100);
|
|
256
|
+
watchers.push({ close: () => clearInterval(poll) });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Watch before compiling so edits during the cold build coalesce into a
|
|
260
|
+
// fresh candidate rather than being lost before the first publication.
|
|
261
|
+
await run();
|
|
262
|
+
} catch (error) {
|
|
263
|
+
closed = true;
|
|
264
|
+
clearTimeout(timer);
|
|
265
|
+
for (const watcher of watchers) watcher.close();
|
|
266
|
+
for (const client of clients) client.end();
|
|
267
|
+
clients.clear();
|
|
268
|
+
server.closeAllConnections();
|
|
269
|
+
await new Promise((resolve) => server.close(resolve));
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
url: `http://127.0.0.1:${server.address().port}`,
|
|
274
|
+
snapshot,
|
|
275
|
+
invalidate,
|
|
276
|
+
rebuild: run,
|
|
277
|
+
async idle() {
|
|
278
|
+
clearTimeout(timer);
|
|
279
|
+
if (pending && !running) await run();
|
|
280
|
+
await running;
|
|
281
|
+
},
|
|
282
|
+
close() {
|
|
283
|
+
if (closing) return closing;
|
|
284
|
+
closed = true;
|
|
285
|
+
closing = (async () => {
|
|
286
|
+
clearTimeout(timer);
|
|
287
|
+
for (const watcher of watchers) watcher.close();
|
|
288
|
+
for (const client of clients) client.end();
|
|
289
|
+
clients.clear();
|
|
290
|
+
server.closeAllConnections();
|
|
291
|
+
await new Promise((resolve) => server.close(resolve));
|
|
292
|
+
await running;
|
|
293
|
+
})();
|
|
294
|
+
return closing;
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function cleanAbandonedDevWorkspaces(parent: string): string[];
|
|
2
|
+
export declare function createRokuDevWorkspace(
|
|
3
|
+
parent: string,
|
|
4
|
+
options?: { label?: string; keep?: number },
|
|
5
|
+
): {
|
|
6
|
+
directory: string;
|
|
7
|
+
abandoned: string[];
|
|
8
|
+
generation(number: number): string;
|
|
9
|
+
publish(generation: number): void;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mkdtempSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
writeFileSync,
|
|
6
|
+
readdirSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
existsSync,
|
|
9
|
+
lstatSync,
|
|
10
|
+
} from "node:fs";
|
|
11
|
+
import { resolve, join } from "node:path";
|
|
12
|
+
import { randomUUID } from "node:crypto";
|
|
13
|
+
const OWNER = "roku-dev-owner.json";
|
|
14
|
+
function owner(directory) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(readFileSync(join(directory, OWNER)));
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function alive(pid) {
|
|
22
|
+
if (!Number.isInteger(pid) || pid <= 0) return true;
|
|
23
|
+
try {
|
|
24
|
+
process.kill(pid, 0);
|
|
25
|
+
return true;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return error.code === "EPERM";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Delete only abandoned directories carrying this tool's ownership manifest. */
|
|
31
|
+
export function cleanAbandonedDevWorkspaces(parent) {
|
|
32
|
+
const removed = [];
|
|
33
|
+
if (!existsSync(parent)) return removed;
|
|
34
|
+
for (const entry of readdirSync(parent, { withFileTypes: true })) {
|
|
35
|
+
if (!entry.isDirectory() || !entry.name.startsWith("roku-dev-")) continue;
|
|
36
|
+
const directory = resolve(parent, entry.name),
|
|
37
|
+
data = owner(directory);
|
|
38
|
+
if (data?.schema !== "react-native-roku-dev-owner/v1" || alive(data.pid)) continue;
|
|
39
|
+
rmSync(directory, { recursive: true, force: true });
|
|
40
|
+
removed.push(entry.name);
|
|
41
|
+
}
|
|
42
|
+
return removed;
|
|
43
|
+
}
|
|
44
|
+
export function createRokuDevWorkspace(parent, { label = "preview", keep = 2 } = {}) {
|
|
45
|
+
if (!Number.isInteger(keep) || keep < 2)
|
|
46
|
+
throw Error("Keep at least two successful development generations");
|
|
47
|
+
mkdirSync(parent, { recursive: true });
|
|
48
|
+
const abandoned = cleanAbandonedDevWorkspaces(parent);
|
|
49
|
+
const directory = mkdtempSync(resolve(parent, "roku-dev-")),
|
|
50
|
+
token = randomUUID();
|
|
51
|
+
writeFileSync(
|
|
52
|
+
join(directory, OWNER),
|
|
53
|
+
JSON.stringify({
|
|
54
|
+
schema: "react-native-roku-dev-owner/v1",
|
|
55
|
+
pid: process.pid,
|
|
56
|
+
token,
|
|
57
|
+
label,
|
|
58
|
+
startedAt: new Date().toISOString(),
|
|
59
|
+
}) + "\n",
|
|
60
|
+
);
|
|
61
|
+
let disposed = false;
|
|
62
|
+
const owns = () => !disposed && owner(directory)?.token === token;
|
|
63
|
+
return {
|
|
64
|
+
directory,
|
|
65
|
+
abandoned,
|
|
66
|
+
generation(number) {
|
|
67
|
+
if (!owns() || !Number.isSafeInteger(number) || number < 1)
|
|
68
|
+
throw Error("Invalid or retired development generation");
|
|
69
|
+
return resolve(directory, String(number));
|
|
70
|
+
},
|
|
71
|
+
publish(generation) {
|
|
72
|
+
if (!owns()) return;
|
|
73
|
+
for (const name of readdirSync(directory)) {
|
|
74
|
+
if (!/^[1-9]\d*$/.test(name) || Number(name) > generation - keep) continue;
|
|
75
|
+
const path = join(directory, name);
|
|
76
|
+
if (lstatSync(path).isSymbolicLink()) continue;
|
|
77
|
+
rmSync(path, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
dispose() {
|
|
81
|
+
if (!owns()) return;
|
|
82
|
+
rmSync(directory, { recursive: true, force: true });
|
|
83
|
+
disposed = true;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare function parseActiveApp(xml: string): { id: string | null; name: string | null };
|
|
2
|
+
export declare function parseMediaPlayer(xml: string): {
|
|
3
|
+
state: string | null;
|
|
4
|
+
error: string | null;
|
|
5
|
+
positionSeconds: number | null;
|
|
6
|
+
durationSeconds: number | null;
|
|
7
|
+
};
|
|
8
|
+
export declare function parseDeviceFacts(xml: string): {
|
|
9
|
+
model: string | null;
|
|
10
|
+
modelName: string | null;
|
|
11
|
+
firmware: string | null;
|
|
12
|
+
developerEnabled: string | null;
|
|
13
|
+
};
|
|
14
|
+
export declare function createRokuDeviceClient(options: {
|
|
15
|
+
host: string;
|
|
16
|
+
ecpPort?: number;
|
|
17
|
+
installerPort?: number;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}): {
|
|
20
|
+
query(name: string): Promise<string>;
|
|
21
|
+
keypress(key: string): Promise<void>;
|
|
22
|
+
launch(): Promise<void>;
|
|
23
|
+
terminate(): Promise<"terminated" | "not-running">;
|
|
24
|
+
appInstalled(expectedName: string): Promise<boolean>;
|
|
25
|
+
screenshot(password: string): Promise<{ data: Buffer; format: string }>;
|
|
26
|
+
};
|
|
27
|
+
export declare function captureRokuDiagnostics(
|
|
28
|
+
host: string,
|
|
29
|
+
options?: { port?: number; maxLines?: number; maxLineLength?: number },
|
|
30
|
+
): {
|
|
31
|
+
ready: Promise<boolean>;
|
|
32
|
+
clear(): void;
|
|
33
|
+
snapshot(): { available: boolean; status: string; droppedLines: number; lines: string[] };
|
|
34
|
+
close(): void;
|
|
35
|
+
};
|
|
36
|
+
export declare function parseRokuHostDiagnostics(lines: string[]): {
|
|
37
|
+
identities: Array<{
|
|
38
|
+
schema: "react-native-roku-build/v1";
|
|
39
|
+
application: string;
|
|
40
|
+
inputFingerprint?: string;
|
|
41
|
+
runtimeSha256?: string;
|
|
42
|
+
frontendGraphSha256?: string;
|
|
43
|
+
}>;
|
|
44
|
+
ready: Record<string, unknown>[];
|
|
45
|
+
memory: Record<string, unknown>[];
|
|
46
|
+
errors: string[];
|
|
47
|
+
};
|