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.
- package/CHANGELOG.md +318 -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 +362 -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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { nativeTextMemo } from "./nativeTextMemo.mjs";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { extname, relative, resolve, sep, isAbsolute } from "node:path";
|
|
6
|
+
|
|
7
|
+
export async function usesReactJsxRuntime(configuration) {
|
|
8
|
+
const { jsx, jsxImportSource, tsconfig, tsconfigRaw, absWorkingDir } = configuration;
|
|
9
|
+
if (
|
|
10
|
+
jsx !== "automatic" ||
|
|
11
|
+
(jsxImportSource && jsxImportSource !== "react") ||
|
|
12
|
+
!tsconfig ||
|
|
13
|
+
tsconfigRaw
|
|
14
|
+
)
|
|
15
|
+
return false;
|
|
16
|
+
const { default: ts } = await import("typescript");
|
|
17
|
+
const project = ts.getParsedCommandLineOfConfigFile(
|
|
18
|
+
resolve(absWorkingDir ?? process.cwd(), tsconfig),
|
|
19
|
+
{},
|
|
20
|
+
{
|
|
21
|
+
...ts.sys,
|
|
22
|
+
onUnRecoverableConfigFileDiagnostic() {},
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
return (
|
|
26
|
+
!!project &&
|
|
27
|
+
!project.errors.length &&
|
|
28
|
+
(!project.options.jsxImportSource || project.options.jsxImportSource === "react")
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Compile the consumer's React sources before esbuild lowers JSX. */
|
|
33
|
+
export function appReactCompiler(root, generated, memoText = false) {
|
|
34
|
+
const require = createRequire(resolve(root, "package.json"));
|
|
35
|
+
let babel, compiler;
|
|
36
|
+
try {
|
|
37
|
+
babel = require("@babel/core");
|
|
38
|
+
compiler = require("babel-plugin-react-compiler");
|
|
39
|
+
} catch (cause) {
|
|
40
|
+
throw new Error("Install @babel/core and babel-plugin-react-compiler in the Roku consumer", {
|
|
41
|
+
cause,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const inside = (base, file) => {
|
|
45
|
+
const path = relative(base, file);
|
|
46
|
+
return !isAbsolute(path) && path !== ".." && !path.startsWith(".." + sep);
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
name: "roku-app-react-compiler",
|
|
50
|
+
async setup(builder) {
|
|
51
|
+
const reuseText = memoText && (await usesReactJsxRuntime(builder.initialOptions));
|
|
52
|
+
if (reuseText) {
|
|
53
|
+
builder.onResolve({ filter: /^roku-compiler:pressable$/ }, () => ({
|
|
54
|
+
path: fileURLToPath(new URL("../src/react-native/compilerPressable.ts", import.meta.url)),
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
builder.onLoad({ filter: /\.[cm]?[jt]sx?$/, namespace: "file" }, async ({ path }) => {
|
|
58
|
+
if (
|
|
59
|
+
!inside(root, path) ||
|
|
60
|
+
inside(generated, path) ||
|
|
61
|
+
relative(root, path).split(sep).includes("node_modules")
|
|
62
|
+
)
|
|
63
|
+
return;
|
|
64
|
+
const extension = extname(path);
|
|
65
|
+
const ts = /[.]([cm]?ts|tsx)$/.test(extension);
|
|
66
|
+
const jsx = extension === ".jsx" || extension === ".tsx";
|
|
67
|
+
let compiled = false;
|
|
68
|
+
const source = await readFile(path, "utf8");
|
|
69
|
+
const parseOptions = {
|
|
70
|
+
filename: path,
|
|
71
|
+
configFile: false,
|
|
72
|
+
babelrc: false,
|
|
73
|
+
sourceMaps: "inline",
|
|
74
|
+
parserOpts: { plugins: [...(jsx ? ["jsx"] : []), ...(ts ? ["typescript"] : [])] },
|
|
75
|
+
};
|
|
76
|
+
let result = await babel.transformAsync(source, {
|
|
77
|
+
...parseOptions,
|
|
78
|
+
plugins: [
|
|
79
|
+
[
|
|
80
|
+
compiler,
|
|
81
|
+
{
|
|
82
|
+
target: "19",
|
|
83
|
+
logger: {
|
|
84
|
+
logEvent(_file, event) {
|
|
85
|
+
if (event.kind === "CompileSuccess") compiled = true;
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
if (reuseText && jsx) {
|
|
93
|
+
let changed = false;
|
|
94
|
+
const memo = await babel.transformAsync(compiled ? result.code : source, {
|
|
95
|
+
...parseOptions,
|
|
96
|
+
plugins: [
|
|
97
|
+
(babel) =>
|
|
98
|
+
nativeTextMemo(babel, () => {
|
|
99
|
+
changed = true;
|
|
100
|
+
}),
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
if (changed) {
|
|
104
|
+
result = memo;
|
|
105
|
+
compiled = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (compiled)
|
|
109
|
+
return { contents: result.code, loader: ts ? (jsx ? "tsx" : "ts") : jsx ? "jsx" : "js" };
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** React's public entry wrappers choose one implementation per frontend profile.
|
|
2
|
+
* Metro development keeps conditional requires, so select this reviewed wrapper
|
|
3
|
+
* before dependency collection. Keep source positions and immutable input bytes. */
|
|
4
|
+
exports.prepareReactEntry = function prepareReactEntry(source, filename, development) {
|
|
5
|
+
const entry =
|
|
6
|
+
/(?:^|[/\\])node_modules[/\\]react[/\\](index|jsx-runtime|jsx-dev-runtime|compiler-runtime)\.js$/.exec(
|
|
7
|
+
filename,
|
|
8
|
+
)?.[1];
|
|
9
|
+
if (!entry) return source;
|
|
10
|
+
const base = entry === "index" ? "react" : "react-" + entry;
|
|
11
|
+
const match =
|
|
12
|
+
/^(?<prefix>[\s\S]*?)\bif\s*\(\s*process\.env\.NODE_ENV\s*===\s*(?<envQuote>['"])production\k<envQuote>\s*\)\s*\{\s*(?<production>module\.exports\s*=\s*require\(\s*(?<pq>['"])(?<productionPath>[^'"]+)\k<pq>\s*\)\s*;)\s*\}\s*else\s*\{\s*(?<development>module\.exports\s*=\s*require\(\s*(?<dq>['"])(?<developmentPath>[^'"]+)\k<dq>\s*\)\s*;)\s*\}\s*$/d.exec(
|
|
13
|
+
source,
|
|
14
|
+
);
|
|
15
|
+
const prefix = match?.groups.prefix;
|
|
16
|
+
const header = prefix
|
|
17
|
+
?.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
18
|
+
.replace(/\/\/[^\r\n]*/g, "")
|
|
19
|
+
.trim();
|
|
20
|
+
if (
|
|
21
|
+
!match ||
|
|
22
|
+
!["'use strict';", '"use strict";'].includes(header) ||
|
|
23
|
+
match.groups.productionPath !== `./cjs/${base}.production.js` ||
|
|
24
|
+
match.groups.developmentPath !== `./cjs/${base}.development.js`
|
|
25
|
+
)
|
|
26
|
+
throw Error(`Review the pinned React entry before selecting its profile: ${filename}`);
|
|
27
|
+
const [start, end] = match.indices.groups[development ? "development" : "production"];
|
|
28
|
+
const blank = (value) => value.replace(/[^\r\n]/g, " ");
|
|
29
|
+
return (
|
|
30
|
+
prefix +
|
|
31
|
+
blank(source.slice(prefix.length, start)) +
|
|
32
|
+
source.slice(start, end) +
|
|
33
|
+
blank(source.slice(end))
|
|
34
|
+
);
|
|
35
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/** Browser development mechanics only. React/Metro retain their own caches. */
|
|
2
|
+
export function installRokuRefreshRuntime(Refresh, { sessionId, generation }, global = globalThis) {
|
|
3
|
+
if (global.__RNR_ROKU_REFRESH__) throw Error("A Roku refresh runtime is already installed");
|
|
4
|
+
Refresh.injectIntoGlobalHook(global);
|
|
5
|
+
let bindings,
|
|
6
|
+
application,
|
|
7
|
+
pending,
|
|
8
|
+
disposed = false,
|
|
9
|
+
lastError = null;
|
|
10
|
+
const previousErrors = global.ErrorUtils;
|
|
11
|
+
const hadErrors = Object.hasOwn(global, "ErrorUtils");
|
|
12
|
+
const errorUtils = {
|
|
13
|
+
...previousErrors,
|
|
14
|
+
reportFatalError(error) {
|
|
15
|
+
if (pending) pending.errors.push(error);
|
|
16
|
+
else if (previousErrors?.reportFatalError)
|
|
17
|
+
previousErrors.reportFatalError.call(previousErrors, error);
|
|
18
|
+
else {
|
|
19
|
+
lastError = error?.message ?? String(error);
|
|
20
|
+
// Metro's guard must return normally so it can retire its inGuard flag.
|
|
21
|
+
// Throwing here poisons later optional imports and hot-update recovery.
|
|
22
|
+
if (typeof global.reportError === "function") global.reportError(error);
|
|
23
|
+
else global.console?.error(error);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
global.ErrorUtils = errorUtils;
|
|
28
|
+
let restorePreambleErrors;
|
|
29
|
+
const refresh = {
|
|
30
|
+
createSignatureFunctionForTransform: Refresh.createSignatureFunctionForTransform,
|
|
31
|
+
isLikelyComponentType: Refresh.isLikelyComponentType,
|
|
32
|
+
getFamilyByType: Refresh.getFamilyByType,
|
|
33
|
+
register: Refresh.register,
|
|
34
|
+
performFullRefresh(reason) {
|
|
35
|
+
if (pending) {
|
|
36
|
+
pending.reload = true;
|
|
37
|
+
}
|
|
38
|
+
global.location?.reload();
|
|
39
|
+
},
|
|
40
|
+
performReactRefresh() {
|
|
41
|
+
if (disposed) return;
|
|
42
|
+
try {
|
|
43
|
+
Refresh.performReactRefresh();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
pending?.errors.push(error);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const previousRefresh = global.__ReactRefresh;
|
|
50
|
+
const hadRefresh = Object.hasOwn(global, "__ReactRefresh");
|
|
51
|
+
global.__ReactRefresh = refresh;
|
|
52
|
+
const runtime = {
|
|
53
|
+
attachRuntime(identity, value) {
|
|
54
|
+
if (
|
|
55
|
+
disposed ||
|
|
56
|
+
bindings ||
|
|
57
|
+
identity.sessionId !== sessionId ||
|
|
58
|
+
identity.generation !== generation
|
|
59
|
+
)
|
|
60
|
+
throw Error("Roku refresh runtime identity changed");
|
|
61
|
+
bindings = value;
|
|
62
|
+
// React Native's error-guard is a Metro startup script. It replaces the
|
|
63
|
+
// bootstrap object, so install through its public handler API only after
|
|
64
|
+
// the preamble has finished. Keep its guard/apply/report methods intact.
|
|
65
|
+
const preambleErrors = global.ErrorUtils;
|
|
66
|
+
if (preambleErrors !== errorUtils) {
|
|
67
|
+
if (
|
|
68
|
+
typeof preambleErrors?.getGlobalHandler === "function" &&
|
|
69
|
+
typeof preambleErrors.setGlobalHandler === "function"
|
|
70
|
+
) {
|
|
71
|
+
const previousHandler = preambleErrors.getGlobalHandler();
|
|
72
|
+
const handler = (error) => errorUtils.reportFatalError(error);
|
|
73
|
+
preambleErrors.setGlobalHandler(handler);
|
|
74
|
+
restorePreambleErrors = () => {
|
|
75
|
+
if (
|
|
76
|
+
global.ErrorUtils === preambleErrors &&
|
|
77
|
+
preambleErrors.getGlobalHandler() === handler
|
|
78
|
+
)
|
|
79
|
+
preambleErrors.setGlobalHandler(previousHandler);
|
|
80
|
+
};
|
|
81
|
+
} else {
|
|
82
|
+
const adapted = { ...preambleErrors, reportFatalError: errorUtils.reportFatalError };
|
|
83
|
+
global.ErrorUtils = adapted;
|
|
84
|
+
restorePreambleErrors = () => {
|
|
85
|
+
if (global.ErrorUtils === adapted) global.ErrorUtils = preambleErrors;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
setApplication(value, onRefreshed) {
|
|
91
|
+
application = { whenCommitted: () => value.whenCommitted(), onRefreshed };
|
|
92
|
+
},
|
|
93
|
+
beginPatch(identity) {
|
|
94
|
+
if (
|
|
95
|
+
disposed ||
|
|
96
|
+
!bindings ||
|
|
97
|
+
!application ||
|
|
98
|
+
!pending ||
|
|
99
|
+
identity.sessionId !== sessionId ||
|
|
100
|
+
identity.fromGeneration !== generation ||
|
|
101
|
+
identity.updateId !== pending.updateId ||
|
|
102
|
+
identity.generation !== pending.generation
|
|
103
|
+
)
|
|
104
|
+
throw Error("Stale or unrequested Roku refresh patch");
|
|
105
|
+
return bindings;
|
|
106
|
+
},
|
|
107
|
+
async applyUpdate(update) {
|
|
108
|
+
if (
|
|
109
|
+
disposed ||
|
|
110
|
+
pending ||
|
|
111
|
+
!bindings ||
|
|
112
|
+
!application ||
|
|
113
|
+
update.sessionId !== sessionId ||
|
|
114
|
+
update.fromGeneration !== generation
|
|
115
|
+
)
|
|
116
|
+
return { type: "reload" };
|
|
117
|
+
if (
|
|
118
|
+
!Number.isSafeInteger(update.generation) ||
|
|
119
|
+
update.generation !== generation + 1 ||
|
|
120
|
+
!/^[a-f0-9]{64}$/.test(update.updateId) ||
|
|
121
|
+
!Array.isArray(update.moduleIds) ||
|
|
122
|
+
update.moduleIds.some(
|
|
123
|
+
(id) => !["number", "string"].includes(typeof id) || !bindings.__r.getModules().has(id),
|
|
124
|
+
) ||
|
|
125
|
+
new Set(update.moduleIds).size !== update.moduleIds.length ||
|
|
126
|
+
!Array.isArray(update.paths) ||
|
|
127
|
+
!update.paths.length ||
|
|
128
|
+
new Set(update.paths).size !== update.paths.length ||
|
|
129
|
+
update.paths.some(
|
|
130
|
+
(path) =>
|
|
131
|
+
typeof path !== "string" ||
|
|
132
|
+
!new RegExp("^/refresh/update-" + update.updateId + "-\\d+\\.mjs$").test(path),
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
return { type: "reload" };
|
|
136
|
+
pending = { ...update, errors: [], reload: false };
|
|
137
|
+
let applied = false;
|
|
138
|
+
try {
|
|
139
|
+
const patches = [];
|
|
140
|
+
for (const path of update.paths) patches.push(await import(path));
|
|
141
|
+
if (disposed) return { type: "retired" };
|
|
142
|
+
if (patches.some((patch) => typeof patch.apply !== "function")) return { type: "reload" };
|
|
143
|
+
for (const patch of patches) patch.apply();
|
|
144
|
+
applied = true;
|
|
145
|
+
// All update modules have loaded and all factories have been applied in
|
|
146
|
+
// one synchronous batch. Flush React now, including successful peers
|
|
147
|
+
// of a failed module, before acknowledging the host commit. Metro's
|
|
148
|
+
// later coalescing callback sees no remaining React families to update.
|
|
149
|
+
refresh.performReactRefresh();
|
|
150
|
+
if (disposed) return { type: "retired" };
|
|
151
|
+
if (pending.reload) return { type: "reload" };
|
|
152
|
+
await application?.whenCommitted();
|
|
153
|
+
generation = update.generation;
|
|
154
|
+
lastError =
|
|
155
|
+
pending.errors.map((error) => error?.message ?? String(error)).join("\n") || null;
|
|
156
|
+
if (!lastError) application?.onRefreshed?.();
|
|
157
|
+
return { type: lastError ? "error" : "refreshed", error: lastError };
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (!applied) return { type: "reload", reason: error?.message ?? String(error) };
|
|
160
|
+
generation = update.generation;
|
|
161
|
+
lastError = error?.message ?? String(error);
|
|
162
|
+
return { type: "error", error: lastError };
|
|
163
|
+
} finally {
|
|
164
|
+
pending = null;
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
snapshot() {
|
|
168
|
+
return { sessionId, generation, pending: !!pending, disposed, error: lastError };
|
|
169
|
+
},
|
|
170
|
+
dispose() {
|
|
171
|
+
disposed = true;
|
|
172
|
+
application = bindings = null;
|
|
173
|
+
restorePreambleErrors?.();
|
|
174
|
+
if (global.ErrorUtils === errorUtils) {
|
|
175
|
+
if (hadErrors) global.ErrorUtils = previousErrors;
|
|
176
|
+
else delete global.ErrorUtils;
|
|
177
|
+
}
|
|
178
|
+
if (global.__ReactRefresh === refresh) {
|
|
179
|
+
if (hadRefresh) global.__ReactRefresh = previousRefresh;
|
|
180
|
+
else delete global.__ReactRefresh;
|
|
181
|
+
}
|
|
182
|
+
if (global.__RNR_ROKU_REFRESH__ === runtime) delete global.__RNR_ROKU_REFRESH__;
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
global.__RNR_ROKU_REFRESH__ = runtime;
|
|
186
|
+
return runtime;
|
|
187
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { GenMapping, addMapping, setSourceContent, toEncodedMap } from "@jridgewell/gen-mapping";
|
|
4
|
+
import { TraceMap, eachMapping } from "@jridgewell/trace-mapping";
|
|
5
|
+
|
|
6
|
+
export function refreshSourceMaps(graph) {
|
|
7
|
+
if (!graph.sourceMap) return null;
|
|
8
|
+
const bytes = readFileSync(graph.sourceMap.path);
|
|
9
|
+
if (createHash("sha256").update(bytes).digest("hex") !== graph.sourceMap.sha256)
|
|
10
|
+
throw Error("The Metro refresh source map changed before publication");
|
|
11
|
+
const trace = new TraceMap(JSON.parse(bytes), graph.sourceMap.url);
|
|
12
|
+
const mappings = [];
|
|
13
|
+
eachMapping(trace, (mapping) => mappings.push(mapping));
|
|
14
|
+
return (file, parts) => {
|
|
15
|
+
const result = new GenMapping({ file }),
|
|
16
|
+
used = new Set();
|
|
17
|
+
for (const part of parts) {
|
|
18
|
+
const { startLine, startColumn, endLine, endColumn } = part.module.span;
|
|
19
|
+
for (const mapping of mappings) {
|
|
20
|
+
const line = mapping.generatedLine - 1,
|
|
21
|
+
column = mapping.generatedColumn;
|
|
22
|
+
if (
|
|
23
|
+
line < startLine ||
|
|
24
|
+
line > endLine ||
|
|
25
|
+
(line === startLine && column < startColumn) ||
|
|
26
|
+
(line === endLine && column >= endColumn)
|
|
27
|
+
)
|
|
28
|
+
continue;
|
|
29
|
+
const offset = line - startLine;
|
|
30
|
+
const generated = {
|
|
31
|
+
line: part.line + offset,
|
|
32
|
+
column: column - (offset === 0 ? startColumn : 0),
|
|
33
|
+
};
|
|
34
|
+
if (mapping.source === null) addMapping(result, { generated });
|
|
35
|
+
else {
|
|
36
|
+
used.add(mapping.source);
|
|
37
|
+
addMapping(result, {
|
|
38
|
+
generated,
|
|
39
|
+
original: { line: mapping.originalLine, column: mapping.originalColumn },
|
|
40
|
+
source: mapping.source,
|
|
41
|
+
...(mapping.name === null ? {} : { name: mapping.name }),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const source of used) {
|
|
47
|
+
const index = trace.resolvedSources.indexOf(source);
|
|
48
|
+
if (trace.sourcesContent?.[index] != null)
|
|
49
|
+
setSourceContent(result, source, trace.sourcesContent[index]);
|
|
50
|
+
}
|
|
51
|
+
return JSON.stringify(toEncodedMap(result));
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { toolchain } from "./environment.mjs";
|
|
5
|
+
export function inspectPublicApi(root) {
|
|
6
|
+
const manifest = JSON.parse(readFileSync(resolve(root, "package.json"))),
|
|
7
|
+
catalog = JSON.parse(readFileSync(resolve(root, "compatibility/public-api.json")));
|
|
8
|
+
const failures = [];
|
|
9
|
+
for (const name of new Set([...Object.keys(manifest.exports), ...Object.keys(catalog.exports)])) {
|
|
10
|
+
const entry = catalog.exports[name];
|
|
11
|
+
if (!manifest.exports[name] || !entry) failures.push(`Classify public export ${name}`);
|
|
12
|
+
else if (
|
|
13
|
+
!["application", "advanced-host", "build", "testing", "types", "metadata"].includes(
|
|
14
|
+
entry.audience,
|
|
15
|
+
) ||
|
|
16
|
+
!entry.contract ||
|
|
17
|
+
!existsSync(resolve(root, entry.contract))
|
|
18
|
+
)
|
|
19
|
+
failures.push(`Document public export ${name}`);
|
|
20
|
+
}
|
|
21
|
+
for (const [name, version] of ["dependencies", "devDependencies", "peerDependencies"].flatMap(
|
|
22
|
+
(group) => Object.entries(manifest[group] ?? {}),
|
|
23
|
+
)) {
|
|
24
|
+
const expected =
|
|
25
|
+
toolchain.packages[name] ??
|
|
26
|
+
(name.startsWith("@roku-sdk/") ? toolchain.packages["@roku-sdk/runtime"] : null);
|
|
27
|
+
if (expected && version !== expected)
|
|
28
|
+
failures.push(`Upgrade coordinated cohort ${name}: expected ${expected}, found ${version}`);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
status: failures.length ? "failed" : "passed",
|
|
32
|
+
exports: Object.keys(catalog.exports).length,
|
|
33
|
+
failures,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function inspectRelease(root, { git, tag, workflowRepository } = {}) {
|
|
37
|
+
const manifest = JSON.parse(readFileSync(resolve(root, "package.json"))),
|
|
38
|
+
policy = JSON.parse(readFileSync(resolve(root, "config/release.json"))),
|
|
39
|
+
api = inspectPublicApi(root),
|
|
40
|
+
blockers = [...api.failures];
|
|
41
|
+
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(manifest.version))
|
|
42
|
+
blockers.push("Use an explicit semantic release version");
|
|
43
|
+
if (manifest.private)
|
|
44
|
+
blockers.push(
|
|
45
|
+
"Package is private; publishing is disabled until an explicit public release decision",
|
|
46
|
+
);
|
|
47
|
+
if (manifest.license === "UNLICENSED" || !existsSync(resolve(root, "LICENSE")))
|
|
48
|
+
blockers.push("Public license selection is pending; publishing is disabled");
|
|
49
|
+
const repository = policy.trustedPublisher.repository;
|
|
50
|
+
if (manifest.repository?.url !== `https://github.com/${repository}.git`)
|
|
51
|
+
blockers.push("Package repository must match the configured npm trusted publisher");
|
|
52
|
+
if (workflowRepository !== undefined && workflowRepository !== repository)
|
|
53
|
+
blockers.push("Release workflow must run in the configured npm trusted publisher repository");
|
|
54
|
+
if (policy.distTag && manifest.publishConfig?.tag !== policy.distTag)
|
|
55
|
+
blockers.push(`Release must use the ${policy.distTag} npm dist-tag`);
|
|
56
|
+
if (!readFileSync(resolve(root, "CHANGELOG.md"), "utf8").includes(`## [${manifest.version}]`))
|
|
57
|
+
blockers.push(`Add changelog entry ${manifest.version}`);
|
|
58
|
+
if (!git) {
|
|
59
|
+
const run = (args) => spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
60
|
+
const head = run(["rev-parse", "HEAD"]),
|
|
61
|
+
status = run(["status", "--porcelain"]),
|
|
62
|
+
tags = run(["tag", "--points-at", "HEAD"]);
|
|
63
|
+
git = {
|
|
64
|
+
head: head.status === 0 ? head.stdout.trim() : null,
|
|
65
|
+
clean: status.status === 0 && !status.stdout.trim(),
|
|
66
|
+
tags: tags.status === 0 ? tags.stdout.trim().split("\n") : [],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (!git.head) blockers.push("Release requires an existing source commit");
|
|
70
|
+
if (Number.parseInt(manifest.version, 10) >= 1 && policy.deviceRequiredForStable) {
|
|
71
|
+
let device;
|
|
72
|
+
try {
|
|
73
|
+
device = JSON.parse(readFileSync(resolve(root, "release-evidence/device.json")));
|
|
74
|
+
} catch {}
|
|
75
|
+
if (
|
|
76
|
+
policy.phase !== "qualified" ||
|
|
77
|
+
device?.deviceQualified !== true ||
|
|
78
|
+
device?.sourceCommit !== git.head ||
|
|
79
|
+
!/^[a-f0-9]{64}$/.test(device?.artifactSha256 ?? "")
|
|
80
|
+
)
|
|
81
|
+
blockers.push(
|
|
82
|
+
"Stable release requires explicit qualified policy and source/artifact-attested device evidence",
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (!git.clean) blockers.push("Release requires a clean source tree");
|
|
86
|
+
if (!git.tags.includes(`v${manifest.version}`) || (tag && tag !== `v${manifest.version}`))
|
|
87
|
+
blockers.push(`Release must use tag v${manifest.version} at the source commit`);
|
|
88
|
+
return {
|
|
89
|
+
schema: "react-native-roku-release-readiness/v1",
|
|
90
|
+
ready: !blockers.length,
|
|
91
|
+
publishPerformed: false,
|
|
92
|
+
version: manifest.version,
|
|
93
|
+
license: manifest.license,
|
|
94
|
+
phase: policy.phase,
|
|
95
|
+
blockers,
|
|
96
|
+
api,
|
|
97
|
+
sourceCommit: git.head,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { dirname, extname, resolve } from "node:path";
|
|
3
|
+
const extensions = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".json"];
|
|
4
|
+
export const rokuSourceVariants = Object.freeze([".roku", ".tv", ""]);
|
|
5
|
+
/** Source variants apply to portable app/package source, never unqualified native leaves. */
|
|
6
|
+
export function resolveRokuSource(base) {
|
|
7
|
+
const extension = extname(base);
|
|
8
|
+
if (extension && !extensions.includes(extension)) return null;
|
|
9
|
+
const stem = extensions.includes(extension) ? base.slice(0, -extension.length) : base;
|
|
10
|
+
const suffixes = extensions.includes(extension)
|
|
11
|
+
? [...new Set([extension, ...extensions])]
|
|
12
|
+
: extensions;
|
|
13
|
+
for (const prefix of [stem, resolve(base, "index")])
|
|
14
|
+
for (const variant of rokuSourceVariants)
|
|
15
|
+
for (const suffix of suffixes) {
|
|
16
|
+
const path = prefix + variant + suffix;
|
|
17
|
+
if (existsSync(path) && statSync(path).isFile()) return path;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
export function resolveRokuRelative(importer, specifier) {
|
|
22
|
+
return specifier.startsWith(".")
|
|
23
|
+
? resolveRokuSource(resolve(dirname(importer), specifier))
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildSurfaceAssets(root: string, generated: string): Promise<void>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
export async function buildSurfaceAssets(root, generated) {
|
|
5
|
+
const require = createRequire(resolve(root, "node_modules/@roku-sdk/tooling/package.json")),
|
|
6
|
+
sharp = require("sharp");
|
|
7
|
+
mkdirSync(resolve(generated, "surfaces"), { recursive: true });
|
|
8
|
+
const centers = [
|
|
9
|
+
[256, 256],
|
|
10
|
+
[0, 256],
|
|
11
|
+
[0, 0],
|
|
12
|
+
[256, 0],
|
|
13
|
+
];
|
|
14
|
+
for (let index = 0; index < centers.length; index++) {
|
|
15
|
+
const [cx, cy] = centers[index];
|
|
16
|
+
const source = `<svg xmlns="http://www.w3.org/2000/svg" width="257" height="257"><circle cx="${cx}" cy="${cy}" r="256" fill="white"/></svg>`;
|
|
17
|
+
const { data, info } = await sharp(Buffer.from(source))
|
|
18
|
+
.ensureAlpha()
|
|
19
|
+
.raw()
|
|
20
|
+
.toBuffer({ resolveWithObject: true });
|
|
21
|
+
// MaskGroup repeats edge rows/columns. The inward edges extend opaque
|
|
22
|
+
// half-planes, including the antialiased pixel at circle tangency.
|
|
23
|
+
const column = index === 0 || index === 3 ? 256 : 0,
|
|
24
|
+
row = index < 2 ? 256 : 0;
|
|
25
|
+
for (let pixel = 0; pixel < 257; pixel++)
|
|
26
|
+
for (const [x, y] of [
|
|
27
|
+
[column, pixel],
|
|
28
|
+
[pixel, row],
|
|
29
|
+
])
|
|
30
|
+
data.fill(255, (y * 257 + x) * 4, (y * 257 + x + 1) * 4);
|
|
31
|
+
writeFileSync(
|
|
32
|
+
resolve(generated, `surfaces/corner-${index}.png`),
|
|
33
|
+
await sharp(data, { raw: info }).png().toBuffer(),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
writeFileSync(
|
|
37
|
+
resolve(generated, "surfaceAssets.ts"),
|
|
38
|
+
centers
|
|
39
|
+
.map((_, index) => `import { uri as corner${index} } from "./surfaces/corner-${index}.png";`)
|
|
40
|
+
.join("\n") + "\nexport const cornerMasks = [corner0,corner1,corner2,corner3] as const;\n",
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
createPortableFetch as portableFetch,
|
|
3
|
+
WebTransport,
|
|
4
|
+
} from "../../src/services/webRuntime";
|
|
5
|
+
|
|
6
|
+
export function canvasImageSource<Image extends { src: string | Uint8Array }>(
|
|
7
|
+
image: Image,
|
|
8
|
+
): Image & {
|
|
9
|
+
removeAttribute(name: string): void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function createNodeTextHttp(options: {
|
|
13
|
+
createPortableFetch: typeof portableFetch;
|
|
14
|
+
fetch?: typeof globalThis.fetch;
|
|
15
|
+
redirectModes?: readonly ("follow" | "error")[];
|
|
16
|
+
}): {
|
|
17
|
+
transport: WebTransport;
|
|
18
|
+
fetch: typeof globalThis.fetch;
|
|
19
|
+
whenIdle(): Promise<void>;
|
|
20
|
+
snapshot(): {
|
|
21
|
+
kind: string;
|
|
22
|
+
requests: number;
|
|
23
|
+
active: number;
|
|
24
|
+
forwardingListeners: number;
|
|
25
|
+
aborts: number;
|
|
26
|
+
errors: number;
|
|
27
|
+
deviceQualified: false;
|
|
28
|
+
};
|
|
29
|
+
};
|