react-native-gtkx 0.1.0-alpha.4 → 0.2.0-alpha.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 (176) hide show
  1. package/README.md +12 -8
  2. package/dist/adw/index.d.ts +3 -0
  3. package/dist/adw/index.js +41 -0
  4. package/dist/adw/index.js.map +1 -0
  5. package/dist/adw/widgets.generated.d.ts +63 -0
  6. package/dist/adw/widgets.generated.js +125 -0
  7. package/dist/adw/widgets.generated.js.map +1 -0
  8. package/dist/common/content.d.ts +69 -0
  9. package/dist/common/content.js +84 -0
  10. package/dist/common/content.js.map +1 -0
  11. package/dist/common/index.d.ts +3 -0
  12. package/dist/common/index.js +19 -0
  13. package/dist/common/index.js.map +1 -0
  14. package/dist/common/navigation-stack.d.ts +84 -0
  15. package/dist/common/navigation-stack.js +313 -0
  16. package/dist/common/navigation-stack.js.map +1 -0
  17. package/dist/common/widget.d.ts +83 -0
  18. package/dist/common/widget.js +142 -0
  19. package/dist/common/widget.js.map +1 -0
  20. package/dist/components/animated.d.ts +3 -2
  21. package/dist/components/animated.js +85 -66
  22. package/dist/components/animated.js.map +1 -1
  23. package/dist/components/app-registry.d.ts +10 -1
  24. package/dist/components/app-registry.js +8 -3
  25. package/dist/components/app-registry.js.map +1 -1
  26. package/dist/components/pressable.js +105 -12
  27. package/dist/components/pressable.js.map +1 -1
  28. package/dist/components/rect-store.d.ts +11 -1
  29. package/dist/components/rect-store.js +27 -3
  30. package/dist/components/rect-store.js.map +1 -1
  31. package/dist/components/svg/animated-support.d.ts +19 -0
  32. package/dist/components/svg/animated-support.js +64 -0
  33. package/dist/components/svg/animated-support.js.map +1 -0
  34. package/dist/components/svg/context.d.ts +8 -0
  35. package/dist/components/svg/context.js +15 -0
  36. package/dist/components/svg/context.js.map +1 -0
  37. package/dist/components/svg/gradients.d.ts +31 -0
  38. package/dist/components/svg/gradients.js +93 -0
  39. package/dist/components/svg/gradients.js.map +1 -0
  40. package/dist/components/svg/group.d.ts +8 -0
  41. package/dist/components/svg/group.js +30 -0
  42. package/dist/components/svg/group.js.map +1 -0
  43. package/dist/components/svg/index.d.ts +6 -0
  44. package/dist/components/svg/index.js +5 -0
  45. package/dist/components/svg/index.js.map +1 -0
  46. package/dist/components/svg/node.d.ts +7 -0
  47. package/dist/components/svg/node.js +7 -0
  48. package/dist/components/svg/node.js.map +1 -0
  49. package/dist/components/svg/paint.d.ts +24 -0
  50. package/dist/components/svg/paint.js +57 -0
  51. package/dist/components/svg/paint.js.map +1 -0
  52. package/dist/components/svg/shapes.d.ts +47 -0
  53. package/dist/components/svg/shapes.js +51 -0
  54. package/dist/components/svg/shapes.js.map +1 -0
  55. package/dist/components/svg/svg.d.ts +14 -0
  56. package/dist/components/svg/svg.js +48 -0
  57. package/dist/components/svg/svg.js.map +1 -0
  58. package/dist/components/svg/use-shape-node.d.ts +12 -0
  59. package/dist/components/svg/use-shape-node.js +52 -0
  60. package/dist/components/svg/use-shape-node.js.map +1 -0
  61. package/dist/components/text.js +11 -2
  62. package/dist/components/text.js.map +1 -1
  63. package/dist/components/use-layout-child.js +47 -4
  64. package/dist/components/use-layout-child.js.map +1 -1
  65. package/dist/contracts.d.ts +12 -1
  66. package/dist/contracts.js.map +1 -1
  67. package/dist/gtk/index.d.ts +6 -0
  68. package/dist/gtk/index.js +39 -0
  69. package/dist/gtk/index.js.map +1 -0
  70. package/dist/gtk/widgets.generated.d.ts +103 -0
  71. package/dist/gtk/widgets.generated.js +206 -0
  72. package/dist/gtk/widgets.generated.js.map +1 -0
  73. package/dist/gtkx/bridge/index.d.ts +9 -4
  74. package/dist/gtkx/bridge/index.js +40 -4
  75. package/dist/gtkx/bridge/index.js.map +1 -1
  76. package/dist/gtkx/bridge/layout-manager.d.ts +2 -1
  77. package/dist/gtkx/bridge/layout-manager.js +31 -9
  78. package/dist/gtkx/bridge/layout-manager.js.map +1 -1
  79. package/dist/gtkx/bridge/svg-node.d.ts +79 -0
  80. package/dist/gtkx/bridge/svg-node.js +367 -0
  81. package/dist/gtkx/bridge/svg-node.js.map +1 -0
  82. package/dist/gtkx/bridge/use-signal.js +18 -8
  83. package/dist/gtkx/bridge/use-signal.js.map +1 -1
  84. package/dist/gtkx/bridge/widgets.generated.d.ts +2 -0
  85. package/dist/gtkx/bridge/widgets.generated.js +14 -0
  86. package/dist/gtkx/bridge/widgets.generated.js.map +1 -0
  87. package/dist/mcp/bin.d.ts +2 -0
  88. package/dist/mcp/bin.js +17 -0
  89. package/dist/mcp/bin.js.map +1 -0
  90. package/dist/mcp/data/generated.d.ts +1282 -0
  91. package/dist/mcp/data/generated.js +1148 -0
  92. package/dist/mcp/data/generated.js.map +1 -0
  93. package/dist/mcp/index.d.ts +5 -0
  94. package/dist/mcp/index.js +9 -0
  95. package/dist/mcp/index.js.map +1 -0
  96. package/dist/mcp/list.d.ts +4 -0
  97. package/dist/mcp/list.js +56 -0
  98. package/dist/mcp/list.js.map +1 -0
  99. package/dist/mcp/resolve.d.ts +55 -0
  100. package/dist/mcp/resolve.js +151 -0
  101. package/dist/mcp/resolve.js.map +1 -0
  102. package/dist/mcp/search.d.ts +13 -0
  103. package/dist/mcp/search.js +48 -0
  104. package/dist/mcp/search.js.map +1 -0
  105. package/dist/mcp/server.d.ts +7 -0
  106. package/dist/mcp/server.js +135 -0
  107. package/dist/mcp/server.js.map +1 -0
  108. package/dist/mcp/tool.d.ts +21 -0
  109. package/dist/mcp/tool.js +36 -0
  110. package/dist/mcp/tool.js.map +1 -0
  111. package/dist/metro/index.js +10 -0
  112. package/dist/metro/index.js.map +1 -1
  113. package/dist/navigation/index.d.ts +50 -13
  114. package/dist/navigation/index.js +183 -148
  115. package/dist/navigation/index.js.map +1 -1
  116. package/dist/navigation/option-warnings.js +9 -1
  117. package/dist/navigation/option-warnings.js.map +1 -1
  118. package/dist/navigation/sidebar.d.ts +177 -9
  119. package/dist/navigation/sidebar.js +284 -10
  120. package/dist/navigation/sidebar.js.map +1 -1
  121. package/dist/runner/index.d.ts +22 -2
  122. package/dist/runner/index.js +163 -13
  123. package/dist/runner/index.js.map +1 -1
  124. package/dist/sea/assemble.d.ts +29 -0
  125. package/dist/sea/assemble.js +129 -0
  126. package/dist/sea/assemble.js.map +1 -0
  127. package/dist/sea/bundle.d.ts +61 -0
  128. package/dist/sea/bundle.js +202 -0
  129. package/dist/sea/bundle.js.map +1 -0
  130. package/dist/sea/gtkx-config-module.d.ts +18 -0
  131. package/dist/sea/gtkx-config-module.js +67 -0
  132. package/dist/sea/gtkx-config-module.js.map +1 -0
  133. package/dist/sea/native-shim.d.ts +40 -0
  134. package/dist/sea/native-shim.js +121 -0
  135. package/dist/sea/native-shim.js.map +1 -0
  136. package/dist/sea/react-anchor-plugin.d.ts +2 -0
  137. package/dist/sea/react-anchor-plugin.js +30 -0
  138. package/dist/sea/react-anchor-plugin.js.map +1 -0
  139. package/dist/style/index.d.ts +1 -0
  140. package/dist/style/index.js +1 -0
  141. package/dist/style/index.js.map +1 -1
  142. package/dist/style/split-style.js +2 -2
  143. package/dist/style/split-style.js.map +1 -1
  144. package/dist/style/transform.d.ts +22 -0
  145. package/dist/style/transform.js +137 -0
  146. package/dist/style/transform.js.map +1 -0
  147. package/dist/style/visual-css.js +3 -2
  148. package/dist/style/visual-css.js.map +1 -1
  149. package/dist/svg/geometry.d.ts +19 -0
  150. package/dist/svg/geometry.js +80 -0
  151. package/dist/svg/geometry.js.map +1 -0
  152. package/dist/svg/gradient-geometry.d.ts +15 -0
  153. package/dist/svg/gradient-geometry.js +18 -0
  154. package/dist/svg/gradient-geometry.js.map +1 -0
  155. package/dist/svg/transform.d.ts +22 -0
  156. package/dist/svg/transform.js +74 -0
  157. package/dist/svg/transform.js.map +1 -0
  158. package/dist/svg/view-box.d.ts +34 -0
  159. package/dist/svg/view-box.js +108 -0
  160. package/dist/svg/view-box.js.map +1 -0
  161. package/dist/svg-compat/index.d.ts +1 -0
  162. package/dist/svg-compat/index.js +16 -0
  163. package/dist/svg-compat/index.js.map +1 -0
  164. package/dist/testing/index.d.ts +14 -0
  165. package/dist/testing/index.js +14 -0
  166. package/dist/testing/index.js.map +1 -0
  167. package/dist/vite/index.d.ts +7 -3
  168. package/dist/vite/index.js +15 -3
  169. package/dist/vite/index.js.map +1 -1
  170. package/dist/vitest/index.d.ts +52 -0
  171. package/dist/vitest/index.js +58 -0
  172. package/dist/vitest/index.js.map +1 -0
  173. package/dist/vitest/setup.d.ts +4 -0
  174. package/dist/vitest/setup.js +22 -0
  175. package/dist/vitest/setup.js.map +1 -0
  176. package/package.json +47 -8
@@ -0,0 +1,202 @@
1
+ // Bundles a Metro-built react-native-gtkx app (main.jsbundle) into a
2
+ // single CJS file suitable for Node's --experimental-sea-config, undoing
3
+ // exactly the externalization HOST_MODULE_EXTERNALS performs at Metro
4
+ // build time.
5
+ //
6
+ // Design, and where this follows/diverges from gtkx's own tutorial
7
+ // (gtkx-org/gtkx examples/tutorial/scripts/bundle.ts and
8
+ // bundle-postject.ts — read before any of this was written):
9
+ //
10
+ // - Bundling mechanics (bundle → single minified CJS file) and the
11
+ // SEA/postject pipeline itself (./assemble.ts) follow the tutorial
12
+ // closely. The bundler is rolldown rather than the tutorial's esbuild —
13
+ // NOT a preference: rolldown is vite's own engine (vite 8 depends on it
14
+ // outright, esbuild is only an optional peer there), and vite is a hard
15
+ // dependency of @gtkx/cli, which is a hard dependency of this package.
16
+ // So rolldown is already installed for every consumer, and esbuild would
17
+ // have been the one genuinely new bundler in the tree.
18
+ // - Native addon: the tutorial's shim assumes the addon file sits BESIDE
19
+ // the built executable (require resolved from
20
+ // dirname(process.execPath)). That is two files, not one — the actual
21
+ // central design decision this epic exists to make — so this diverges:
22
+ // the addon is embedded IN the artifact (as a SEA asset, or as a base64
23
+ // literal for the --standalone .cjs) and extracted to a per-user cache
24
+ // directory on first run. See ./native-shim.ts's header for the full
25
+ // reasoning.
26
+ // - Metro's externals: the tutorial has no equivalent problem, its source
27
+ // is already a single vite/rollup bundle. Metro deliberately
28
+ // externalizes @gtkx/*, react and yoga-layout (../metro/index.ts,
29
+ // HOST_MODULE_EXTERNALS) so main.jsbundle expects
30
+ // globalThis.__hostModules/__hostRequire to exist before it runs (see
31
+ // ../runner/host.ts). This module is a third host implementation
32
+ // (host.ts and host-dev.ts are the other two — see host-dev.ts's header
33
+ // for why they don't share code) that builds those globals from real,
34
+ // STATICALLY imported modules — every name in HOST_MODULE_EXTERNALS
35
+ // becomes a literal `import * as` statement in the generated entry — so
36
+ // the bundler can inline them instead of the app needing a runtime
37
+ // node_modules to dynamically load them from. gtkx.config.ts is also
38
+ // resolved once here, at bundle time (see ./gtkx-config-module.ts).
39
+ //
40
+ // Not attempted here: the vite path. Investigated, not a drop-in of this
41
+ // same technique — see docs/getting-started.md's "Shipping an app"
42
+ // section for the concrete blocker found empirically while building this:
43
+ // the vite bundle loads the native addon through a DYNAMICALLY obtained
44
+ // require (`createRequire(import.meta.url)("./gtkx.node")`), which a
45
+ // bundler does not intercept the way it intercepts a static import
46
+ // (verified: the resolve hook never fires for it), and which is unlikely
47
+ // to resolve at all once running from inside a real SEA blob, where
48
+ // import.meta.url no longer points at a file with real siblings on disk.
49
+ import { mkdirSync, readdirSync, readFileSync } from "node:fs";
50
+ import { createRequire } from "node:module";
51
+ import { dirname, join } from "node:path";
52
+ import { rolldown } from "rolldown";
53
+ import { HOST_MODULE_EXTERNALS } from "../metro/index.js";
54
+ import { buildGtkxConfigModule, virtualConfigModulePlugin, } from "./gtkx-config-module.js";
55
+ import { NATIVE_ASSET_KEY, nativeAddonShimPlugin, } from "./native-shim.js";
56
+ import { reactAnchorPlugin } from "./react-anchor-plugin.js";
57
+ /**
58
+ * Locates the ONE native addon file npm installed for this machine.
59
+ * @gtkx/native picks exactly one optionalDependency per platform/libc at
60
+ * install time (see @gtkx/native/index.js's NAPI-RS-generated loader) —
61
+ * failing loudly on anything other than exactly one match matters here:
62
+ * silently picking the wrong one would embed an addon for the wrong
63
+ * architecture with no error until the app actually launches.
64
+ */
65
+ export const resolveNativeAddon = (appRoot) => {
66
+ const appRequire = createRequire(join(appRoot, "package.json"));
67
+ const nativePackageJson = appRequire.resolve("@gtkx/native/package.json");
68
+ // .../node_modules/@gtkx/native/package.json -> .../node_modules/@gtkx
69
+ const scopeDir = dirname(dirname(nativePackageJson));
70
+ const candidates = readdirSync(scopeDir, { withFileTypes: true })
71
+ .filter((entry) => entry.isDirectory() && entry.name.startsWith("native-"))
72
+ .flatMap((entry) => {
73
+ const dir = join(scopeDir, entry.name);
74
+ return readdirSync(dir)
75
+ .filter((file) => file.endsWith(".node"))
76
+ .map((file) => join(dir, file));
77
+ });
78
+ const [first, ...rest] = candidates;
79
+ if (!first || rest.length > 0) {
80
+ throw new Error(`expected exactly one @gtkx/native-*/*.node under ${scopeDir}, found ` +
81
+ `${candidates.length} (${candidates.join(", ") || "none"}) — ` +
82
+ "reinstall targeting a single platform.");
83
+ }
84
+ return { path: first, key: NATIVE_ASSET_KEY };
85
+ };
86
+ /**
87
+ * Builds the synthetic SEA entry source: every HOST_MODULE_EXTERNALS name
88
+ * loaded through a dynamic `import()` (mirroring runner/host.ts's own
89
+ * `load()`, which does the same against a real node_modules at runtime),
90
+ * assembled into globalThis.__hostModules, then the jsbundle text executed
91
+ * the same way host.ts does.
92
+ *
93
+ * Dynamic import, not static, throughout: a Node SEA's main script is
94
+ * CommonJS only — confirmed empirically, Node 24 executes the embedded
95
+ * main as CJS regardless of a "type": "module" field in sea-config.json
96
+ * or an .mjs extension — and top-level await is a hard error under a "cjs"
97
+ * output format REGARDLESS of whether the module is reached via a static
98
+ * or dynamic import (the restriction is format-wide, not per-module —
99
+ * verified: switching yoga-layout's static import to a dynamic one alone
100
+ * did not clear the error). yoga-layout's own entry point has exactly this
101
+ * top-level await (it loads its WASM binary asynchronously — see
102
+ * node_modules/yoga-layout/dist/src/index.js: `const Yoga =
103
+ * wrapAssembly(await loadYoga())` at module scope). The actual fix: import
104
+ * "yoga-layout/load" instead, which exports the same `await`, just inside
105
+ * an async FUNCTION (`export async function loadYoga()`), not at the
106
+ * file's top level — bundleable, and awaited here like everything else.
107
+ */
108
+ export const buildEntrySource = (jsbundlePath) => {
109
+ const jsbundleSource = readFileSync(jsbundlePath, "utf8");
110
+ const loadLines = HOST_MODULE_EXTERNALS.map((name) => {
111
+ if (name === "yoga-layout") {
112
+ return [
113
+ ` {`,
114
+ ` const { loadYoga, ...rest } = await import("yoga-layout/load");`,
115
+ ` hostModules["yoga-layout"] = __interopHostModule({ ...rest, default: await loadYoga() });`,
116
+ ` }`,
117
+ ].join("\n");
118
+ }
119
+ return ` hostModules[${JSON.stringify(name)}] = __interopHostModule(await import(${JSON.stringify(name)}));`;
120
+ });
121
+ return [
122
+ `async function __gtkxSeaMain() {`,
123
+ // Mirrors runner/host.ts's `load()` interop: import() handles both ESM
124
+ // and CJS, merge a `default` for Babel's default-import interop when
125
+ // the module has none of its own.
126
+ ` const __interopHostModule = (ns) => {`,
127
+ ` const merged = Object.assign({ __esModule: true }, ns);`,
128
+ ` if (!("default" in ns)) merged.default = ns;`,
129
+ ` return merged;`,
130
+ ` };`,
131
+ ` const hostModules = {};`,
132
+ ...loadLines,
133
+ ` globalThis.__hostModules = hostModules;`,
134
+ // Node builtin proxies resolve lazily through the host's own require —
135
+ // real here, no createRequire indirection needed (see host.ts for why
136
+ // it needs one: this file's import.meta.url is never used for
137
+ // anything relative, only require() of bare/builtin specifiers).
138
+ ` globalThis.__hostRequire = require;`,
139
+ ` require("node:vm").runInThisContext(${JSON.stringify(jsbundleSource)}, { filename: ${JSON.stringify(jsbundlePath)} });`,
140
+ `}`,
141
+ `__gtkxSeaMain().catch((error) => { console.error(error); process.exitCode = 1; });`,
142
+ ].join("\n");
143
+ };
144
+ /**
145
+ * Produces `outFile`, a single CJS file with the jsbundle, its
146
+ * HOST_MODULE_EXTERNALS and gtkx.config.ts's resolved values all inlined,
147
+ * and the native addon import redirected to the SEA-asset extraction
148
+ * shim. Returns the native addon that must be embedded as a SEA asset
149
+ * under {@link NativeAddonAsset.key} for the result to run.
150
+ */
151
+ export const bundleMetroSea = async (options) => {
152
+ const { appRoot, jsbundlePath, outFile } = options;
153
+ const nativeAddonSource = options.nativeAddonSource ?? "sea-asset";
154
+ const configModuleSource = await buildGtkxConfigModule(appRoot);
155
+ const nativeAddon = resolveNativeAddon(appRoot);
156
+ const entrySource = buildEntrySource(jsbundlePath);
157
+ mkdirSync(dirname(outFile), { recursive: true });
158
+ // The entry is given a path inside appRoot that does not exist on disk,
159
+ // rather than a `\0`-prefixed virtual id: every bare specifier it
160
+ // imports (react, @gtkx/*, yoga-layout) must resolve from the app's own
161
+ // node_modules, and a real directory is what makes that happen.
162
+ const entryId = join(appRoot, "__gtkx-sea-entry.js");
163
+ const bundle = await rolldown({
164
+ input: entryId,
165
+ cwd: appRoot,
166
+ platform: "node",
167
+ plugins: [
168
+ {
169
+ name: "gtkx-sea-entry",
170
+ resolveId: (source) => (source === entryId ? entryId : null),
171
+ load: (id) => (id === entryId ? entrySource : null),
172
+ },
173
+ reactAnchorPlugin(appRoot),
174
+ nativeAddonShimPlugin({
175
+ specifier: "@gtkx/native",
176
+ appRoot,
177
+ source: nativeAddonSource,
178
+ assetKey: nativeAddon.key,
179
+ addonBytes: nativeAddonSource === "inline"
180
+ ? readFileSync(nativeAddon.path)
181
+ : undefined,
182
+ }),
183
+ virtualConfigModulePlugin(configModuleSource, appRoot),
184
+ ],
185
+ });
186
+ try {
187
+ await bundle.write({
188
+ file: outFile,
189
+ format: "cjs",
190
+ minify: true,
191
+ // Every HOST_MODULE_EXTERNALS name is reached through a dynamic
192
+ // import; without this each one becomes its own chunk and the
193
+ // "single file" the whole build exists to produce is a directory.
194
+ codeSplitting: false,
195
+ });
196
+ }
197
+ finally {
198
+ await bundle.close();
199
+ }
200
+ return nativeAddon;
201
+ };
202
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../src/sea/bundle.ts"],"names":[],"mappings":"AAAA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,CAAC;YACjB,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,IAAI;YACZ,gEAAgE;YAChE,8DAA8D;YAC9D,kEAAkE;YAClE,aAAa,EAAE,KAAK;SACrB,CAAC,CAAA;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA","sourcesContent":["// Bundles a Metro-built react-native-gtkx app (main.jsbundle) into a\n// single CJS file suitable for Node's --experimental-sea-config, undoing\n// exactly the externalization HOST_MODULE_EXTERNALS performs at Metro\n// build time.\n//\n// Design, and where this follows/diverges from gtkx's own tutorial\n// (gtkx-org/gtkx examples/tutorial/scripts/bundle.ts and\n// bundle-postject.ts — read before any of this was written):\n//\n// - Bundling mechanics (bundle → single minified CJS file) and the\n// SEA/postject pipeline itself (./assemble.ts) follow the tutorial\n// closely. The bundler is rolldown rather than the tutorial's esbuild —\n// NOT a preference: rolldown is vite's own engine (vite 8 depends on it\n// outright, esbuild is only an optional peer there), and vite is a hard\n// dependency of @gtkx/cli, which is a hard dependency of this package.\n// So rolldown is already installed for every consumer, and esbuild would\n// have been the one genuinely new bundler in the tree.\n// - Native addon: the tutorial's shim assumes the addon file sits BESIDE\n// the built executable (require resolved from\n// dirname(process.execPath)). That is two files, not one — the actual\n// central design decision this epic exists to make — so this diverges:\n// the addon is embedded IN the artifact (as a SEA asset, or as a base64\n// literal for the --standalone .cjs) and extracted to a per-user cache\n// directory on first run. See ./native-shim.ts's header for the full\n// reasoning.\n// - Metro's externals: the tutorial has no equivalent problem, its source\n// is already a single vite/rollup bundle. Metro deliberately\n// externalizes @gtkx/*, react and yoga-layout (../metro/index.ts,\n// HOST_MODULE_EXTERNALS) so main.jsbundle expects\n// globalThis.__hostModules/__hostRequire to exist before it runs (see\n// ../runner/host.ts). This module is a third host implementation\n// (host.ts and host-dev.ts are the other two — see host-dev.ts's header\n// for why they don't share code) that builds those globals from real,\n// STATICALLY imported modules — every name in HOST_MODULE_EXTERNALS\n// becomes a literal `import * as` statement in the generated entry — so\n// the bundler can inline them instead of the app needing a runtime\n// node_modules to dynamically load them from. gtkx.config.ts is also\n// resolved once here, at bundle time (see ./gtkx-config-module.ts).\n//\n// Not attempted here: the vite path. Investigated, not a drop-in of this\n// same technique — see docs/getting-started.md's \"Shipping an app\"\n// section for the concrete blocker found empirically while building this:\n// the vite bundle loads the native addon through a DYNAMICALLY obtained\n// require (`createRequire(import.meta.url)(\"./gtkx.node\")`), which a\n// bundler does not intercept the way it intercepts a static import\n// (verified: the resolve hook never fires for it), and which is unlikely\n// to resolve at all once running from inside a real SEA blob, where\n// import.meta.url no longer points at a file with real siblings on disk.\nimport { mkdirSync, readdirSync, readFileSync } from \"node:fs\"\nimport { createRequire } from \"node:module\"\nimport { dirname, join } from \"node:path\"\nimport { rolldown } from \"rolldown\"\nimport { HOST_MODULE_EXTERNALS } from \"../metro/index.js\"\nimport {\n buildGtkxConfigModule,\n virtualConfigModulePlugin,\n} from \"./gtkx-config-module.js\"\nimport {\n NATIVE_ASSET_KEY,\n nativeAddonShimPlugin,\n type NativeAddonSource,\n} from \"./native-shim.js\"\nimport { reactAnchorPlugin } from \"./react-anchor-plugin.js\"\n\nexport type MetroSeaBundleOptions = {\n /** The app root — where gtkx.config.ts lives and package.json resolves\n * HOST_MODULE_EXTERNALS' bare specifiers (react, @gtkx/*, ...) from. */\n appRoot: string\n /** Path to the release jsbundle produced by `build-linux`. */\n jsbundlePath: string\n /** Where to write the bundled CJS entry (e.g. dist/bundle.cjs). */\n outFile: string\n /** Where the native addon's bytes come from at runtime — \"sea-asset\"\n * for a real single executable, \"inline\" for a self-contained .cjs run\n * by a system Node (default: \"sea-asset\"). */\n nativeAddonSource?: NativeAddonSource\n}\n\nexport type NativeAddonAsset = {\n /** Absolute path to the platform's @gtkx/native-<platform>-<libc>.node\n * that npm installed for this machine. */\n path: string\n /** The SEA asset key it must be embedded under. */\n key: string\n}\n\n/**\n * Locates the ONE native addon file npm installed for this machine.\n * @gtkx/native picks exactly one optionalDependency per platform/libc at\n * install time (see @gtkx/native/index.js's NAPI-RS-generated loader) —\n * failing loudly on anything other than exactly one match matters here:\n * silently picking the wrong one would embed an addon for the wrong\n * architecture with no error until the app actually launches.\n */\nexport const resolveNativeAddon = (appRoot: string): NativeAddonAsset => {\n const appRequire = createRequire(join(appRoot, \"package.json\"))\n const nativePackageJson = appRequire.resolve(\"@gtkx/native/package.json\")\n // .../node_modules/@gtkx/native/package.json -> .../node_modules/@gtkx\n const scopeDir = dirname(dirname(nativePackageJson))\n const candidates = readdirSync(scopeDir, { withFileTypes: true })\n .filter((entry) => entry.isDirectory() && entry.name.startsWith(\"native-\"))\n .flatMap((entry) => {\n const dir = join(scopeDir, entry.name)\n return readdirSync(dir)\n .filter((file) => file.endsWith(\".node\"))\n .map((file) => join(dir, file))\n })\n const [first, ...rest] = candidates\n if (!first || rest.length > 0) {\n throw new Error(\n `expected exactly one @gtkx/native-*/*.node under ${scopeDir}, found ` +\n `${candidates.length} (${candidates.join(\", \") || \"none\"}) — ` +\n \"reinstall targeting a single platform.\",\n )\n }\n return { path: first, key: NATIVE_ASSET_KEY }\n}\n\n/**\n * Builds the synthetic SEA entry source: every HOST_MODULE_EXTERNALS name\n * loaded through a dynamic `import()` (mirroring runner/host.ts's own\n * `load()`, which does the same against a real node_modules at runtime),\n * assembled into globalThis.__hostModules, then the jsbundle text executed\n * the same way host.ts does.\n *\n * Dynamic import, not static, throughout: a Node SEA's main script is\n * CommonJS only — confirmed empirically, Node 24 executes the embedded\n * main as CJS regardless of a \"type\": \"module\" field in sea-config.json\n * or an .mjs extension — and top-level await is a hard error under a \"cjs\"\n * output format REGARDLESS of whether the module is reached via a static\n * or dynamic import (the restriction is format-wide, not per-module —\n * verified: switching yoga-layout's static import to a dynamic one alone\n * did not clear the error). yoga-layout's own entry point has exactly this\n * top-level await (it loads its WASM binary asynchronously — see\n * node_modules/yoga-layout/dist/src/index.js: `const Yoga =\n * wrapAssembly(await loadYoga())` at module scope). The actual fix: import\n * \"yoga-layout/load\" instead, which exports the same `await`, just inside\n * an async FUNCTION (`export async function loadYoga()`), not at the\n * file's top level — bundleable, and awaited here like everything else.\n */\nexport const buildEntrySource = (jsbundlePath: string): string => {\n const jsbundleSource = readFileSync(jsbundlePath, \"utf8\")\n const loadLines = HOST_MODULE_EXTERNALS.map((name) => {\n if (name === \"yoga-layout\") {\n return [\n ` {`,\n ` const { loadYoga, ...rest } = await import(\"yoga-layout/load\");`,\n ` hostModules[\"yoga-layout\"] = __interopHostModule({ ...rest, default: await loadYoga() });`,\n ` }`,\n ].join(\"\\n\")\n }\n return ` hostModules[${JSON.stringify(name)}] = __interopHostModule(await import(${JSON.stringify(name)}));`\n })\n return [\n `async function __gtkxSeaMain() {`,\n // Mirrors runner/host.ts's `load()` interop: import() handles both ESM\n // and CJS, merge a `default` for Babel's default-import interop when\n // the module has none of its own.\n ` const __interopHostModule = (ns) => {`,\n ` const merged = Object.assign({ __esModule: true }, ns);`,\n ` if (!(\"default\" in ns)) merged.default = ns;`,\n ` return merged;`,\n ` };`,\n ` const hostModules = {};`,\n ...loadLines,\n ` globalThis.__hostModules = hostModules;`,\n // Node builtin proxies resolve lazily through the host's own require —\n // real here, no createRequire indirection needed (see host.ts for why\n // it needs one: this file's import.meta.url is never used for\n // anything relative, only require() of bare/builtin specifiers).\n ` globalThis.__hostRequire = require;`,\n ` require(\"node:vm\").runInThisContext(${JSON.stringify(jsbundleSource)}, { filename: ${JSON.stringify(jsbundlePath)} });`,\n `}`,\n `__gtkxSeaMain().catch((error) => { console.error(error); process.exitCode = 1; });`,\n ].join(\"\\n\")\n}\n\n/**\n * Produces `outFile`, a single CJS file with the jsbundle, its\n * HOST_MODULE_EXTERNALS and gtkx.config.ts's resolved values all inlined,\n * and the native addon import redirected to the SEA-asset extraction\n * shim. Returns the native addon that must be embedded as a SEA asset\n * under {@link NativeAddonAsset.key} for the result to run.\n */\nexport const bundleMetroSea = async (\n options: MetroSeaBundleOptions,\n): Promise<NativeAddonAsset> => {\n const { appRoot, jsbundlePath, outFile } = options\n const nativeAddonSource = options.nativeAddonSource ?? \"sea-asset\"\n const configModuleSource = await buildGtkxConfigModule(appRoot)\n const nativeAddon = resolveNativeAddon(appRoot)\n const entrySource = buildEntrySource(jsbundlePath)\n\n mkdirSync(dirname(outFile), { recursive: true })\n\n // The entry is given a path inside appRoot that does not exist on disk,\n // rather than a `\\0`-prefixed virtual id: every bare specifier it\n // imports (react, @gtkx/*, yoga-layout) must resolve from the app's own\n // node_modules, and a real directory is what makes that happen.\n const entryId = join(appRoot, \"__gtkx-sea-entry.js\")\n\n const bundle = await rolldown({\n input: entryId,\n cwd: appRoot,\n platform: \"node\",\n plugins: [\n {\n name: \"gtkx-sea-entry\",\n resolveId: (source) => (source === entryId ? entryId : null),\n load: (id) => (id === entryId ? entrySource : null),\n },\n reactAnchorPlugin(appRoot),\n nativeAddonShimPlugin({\n specifier: \"@gtkx/native\",\n appRoot,\n source: nativeAddonSource,\n assetKey: nativeAddon.key,\n addonBytes:\n nativeAddonSource === \"inline\"\n ? readFileSync(nativeAddon.path)\n : undefined,\n }),\n virtualConfigModulePlugin(configModuleSource, appRoot),\n ],\n })\n try {\n await bundle.write({\n file: outFile,\n format: \"cjs\",\n minify: true,\n // Every HOST_MODULE_EXTERNALS name is reached through a dynamic\n // import; without this each one becomes its own chunk and the\n // \"single file\" the whole build exists to produce is a directory.\n codeSplitting: false,\n })\n } finally {\n await bundle.close()\n }\n\n return nativeAddon\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import type { Plugin } from "rolldown";
2
+ export declare const CONFIG_REQUIRED: string;
3
+ /**
4
+ * Loads and validates the app's gtkx.config.ts, returning the source of a
5
+ * virtual:gtkx-config module with the resolved values baked in as literals.
6
+ */
7
+ export declare const buildGtkxConfigModule: (appRoot: string) => Promise<string>;
8
+ /**
9
+ * Resolves the bare "virtual:gtkx-config" specifier @gtkx/react imports to
10
+ * the module source built by {@link buildGtkxConfigModule}, so the bundler
11
+ * can inline it like any other static import — no runtime loader hook
12
+ * needed.
13
+ *
14
+ * The module is given an id inside `appRoot` rather than a `\0`-prefixed
15
+ * virtual one because it re-exports "@gtkx/jsx/metadata": that bare
16
+ * specifier needs a real directory to resolve from.
17
+ */
18
+ export declare const virtualConfigModulePlugin: (moduleSource: string, appRoot: string) => Plugin;
@@ -0,0 +1,67 @@
1
+ // @gtkx/react imports the bare specifier "virtual:gtkx-config" for JSX
2
+ // metadata plus the app's applicationId/userEventSignals/lazy elements.
3
+ // runner/host.ts resolves it at every process start through a loader hook
4
+ // (registerHooks), reading gtkx.config.ts from the current working
5
+ // directory. A SEA has no "app root" to read a config file from at
6
+ // runtime — there is no cwd convention once the app is a single file
7
+ // copied anywhere — so this bakes the same values in at BUILD time
8
+ // instead, the same way the vite path already does (its CLI plugin serves
9
+ // virtual:gtkx-config from the build-time config, never a runtime read).
10
+ //
11
+ // Deliberately duplicated validation logic rather than shared with
12
+ // host.ts: see host-dev.ts's header comment for why the hosts in this
13
+ // package are self-contained twins rather than sharing relative imports —
14
+ // this is a third twin, for the same reason (host.ts must keep resolving
15
+ // its config at runtime for ordinary `run-linux`/installed-app use; this
16
+ // one resolves it once, at bundle time, for the SEA artifact only).
17
+ import { join } from "node:path";
18
+ import { createConfigLoader } from "@gtkx/config/internal";
19
+ export const CONFIG_REQUIRED = "gtkx.config.ts with an applicationId is required in the app root " +
20
+ '(export default defineConfig({ applicationId: "...", libraries: [...] })).';
21
+ /**
22
+ * Loads and validates the app's gtkx.config.ts, returning the source of a
23
+ * virtual:gtkx-config module with the resolved values baked in as literals.
24
+ */
25
+ export const buildGtkxConfigModule = async (appRoot) => {
26
+ const loader = createConfigLoader();
27
+ const config = await loader(appRoot).catch((error) => {
28
+ throw new Error(`${CONFIG_REQUIRED}\n${String(error)}`);
29
+ });
30
+ if (!config.applicationId) {
31
+ throw new Error(CONFIG_REQUIRED);
32
+ }
33
+ // A behaviors module would have to be bundled and merged through
34
+ // @gtkx/react/config; the react-native surface owns element behaviors,
35
+ // so no app declares one — refuse rather than silently drop it (mirrors
36
+ // host.ts's runtime check).
37
+ if (config.elements !== null) {
38
+ throw new Error("gtkx.config.ts `elements.behaviors` is not supported on the linux " +
39
+ "platform — react-native-gtkx owns element behaviors.");
40
+ }
41
+ const lazyElements = Object.fromEntries(config.lazyElements.map((type) => [type, { lazy: true }]));
42
+ return [
43
+ `export * from "@gtkx/jsx/metadata";`,
44
+ `export const applicationId = ${JSON.stringify(config.applicationId)};`,
45
+ `export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,
46
+ `export const elements = ${JSON.stringify(lazyElements)};`,
47
+ ].join("\n");
48
+ };
49
+ /**
50
+ * Resolves the bare "virtual:gtkx-config" specifier @gtkx/react imports to
51
+ * the module source built by {@link buildGtkxConfigModule}, so the bundler
52
+ * can inline it like any other static import — no runtime loader hook
53
+ * needed.
54
+ *
55
+ * The module is given an id inside `appRoot` rather than a `\0`-prefixed
56
+ * virtual one because it re-exports "@gtkx/jsx/metadata": that bare
57
+ * specifier needs a real directory to resolve from.
58
+ */
59
+ export const virtualConfigModulePlugin = (moduleSource, appRoot) => {
60
+ const configId = join(appRoot, "__gtkx-sea-config.js");
61
+ return {
62
+ name: "gtkx-virtual-config",
63
+ resolveId: (source) => (source === "virtual:gtkx-config" ? configId : null),
64
+ load: (id) => (id === configId ? moduleSource : null),
65
+ };
66
+ };
67
+ //# sourceMappingURL=gtkx-config-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gtkx-config-module.js","sourceRoot":"","sources":["../../src/sea/gtkx-config-module.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,wEAAwE;AACxE,0EAA0E;AAC1E,mEAAmE;AACnE,mEAAmE;AACnE,qEAAqE;AACrE,mEAAmE;AACnE,0EAA0E;AAC1E,yEAAyE;AACzE,EAAE;AACF,mEAAmE;AACnE,sEAAsE;AACtE,0EAA0E;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CAAC,YAAY,CAAC,GAAG;KAC3D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,YAAoB,EACpB,OAAe,EACP,EAAE;IACV,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAA;IACtD,OAAO;QACL,IAAI,EAAE,qBAAqB;QAC3B,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,KAAK,qBAAqB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3E,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;KACtD,CAAA;AACH,CAAC,CAAA","sourcesContent":["// @gtkx/react imports the bare specifier \"virtual:gtkx-config\" for JSX\n// metadata plus the app's applicationId/userEventSignals/lazy elements.\n// runner/host.ts resolves it at every process start through a loader hook\n// (registerHooks), reading gtkx.config.ts from the current working\n// directory. A SEA has no \"app root\" to read a config file from at\n// runtime — there is no cwd convention once the app is a single file\n// copied anywhere — so this bakes the same values in at BUILD time\n// instead, the same way the vite path already does (its CLI plugin serves\n// virtual:gtkx-config from the build-time config, never a runtime read).\n//\n// Deliberately duplicated validation logic rather than shared with\n// host.ts: see host-dev.ts's header comment for why the hosts in this\n// package are self-contained twins rather than sharing relative imports —\n// this is a third twin, for the same reason (host.ts must keep resolving\n// its config at runtime for ordinary `run-linux`/installed-app use; this\n// one resolves it once, at bundle time, for the SEA artifact only).\nimport { join } from \"node:path\"\nimport { createConfigLoader } from \"@gtkx/config/internal\"\nimport type { Plugin } from \"rolldown\"\n\nexport const CONFIG_REQUIRED =\n \"gtkx.config.ts with an applicationId is required in the app root \" +\n '(export default defineConfig({ applicationId: \"...\", libraries: [...] })).'\n\n/**\n * Loads and validates the app's gtkx.config.ts, returning the source of a\n * virtual:gtkx-config module with the resolved values baked in as literals.\n */\nexport const buildGtkxConfigModule = async (\n appRoot: string,\n): Promise<string> => {\n const loader = createConfigLoader()\n const config = await loader(appRoot).catch((error: unknown) => {\n throw new Error(`${CONFIG_REQUIRED}\\n${String(error)}`)\n })\n if (!config.applicationId) {\n throw new Error(CONFIG_REQUIRED)\n }\n // A behaviors module would have to be bundled and merged through\n // @gtkx/react/config; the react-native surface owns element behaviors,\n // so no app declares one — refuse rather than silently drop it (mirrors\n // host.ts's runtime check).\n if (config.elements !== null) {\n throw new Error(\n \"gtkx.config.ts `elements.behaviors` is not supported on the linux \" +\n \"platform — react-native-gtkx owns element behaviors.\",\n )\n }\n const lazyElements = Object.fromEntries(\n config.lazyElements.map((type) => [type, { lazy: true }]),\n )\n return [\n `export * from \"@gtkx/jsx/metadata\";`,\n `export const applicationId = ${JSON.stringify(config.applicationId)};`,\n `export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,\n `export const elements = ${JSON.stringify(lazyElements)};`,\n ].join(\"\\n\")\n}\n\n/**\n * Resolves the bare \"virtual:gtkx-config\" specifier @gtkx/react imports to\n * the module source built by {@link buildGtkxConfigModule}, so the bundler\n * can inline it like any other static import — no runtime loader hook\n * needed.\n *\n * The module is given an id inside `appRoot` rather than a `\\0`-prefixed\n * virtual one because it re-exports \"@gtkx/jsx/metadata\": that bare\n * specifier needs a real directory to resolve from.\n */\nexport const virtualConfigModulePlugin = (\n moduleSource: string,\n appRoot: string,\n): Plugin => {\n const configId = join(appRoot, \"__gtkx-sea-config.js\")\n return {\n name: \"gtkx-virtual-config\",\n resolveId: (source) => (source === \"virtual:gtkx-config\" ? configId : null),\n load: (id) => (id === configId ? moduleSource : null),\n }\n}\n"]}
@@ -0,0 +1,40 @@
1
+ import type { Plugin } from "rolldown";
2
+ export declare const NATIVE_ASSET_KEY = "gtkx-native.node";
3
+ /**
4
+ * Where the shim gets the addon's bytes from — the only difference between
5
+ * the two single-file artifacts:
6
+ *
7
+ * - `"sea-asset"`: from the SEA blob, via node:sea. Only works inside a
8
+ * real single executable.
9
+ * - `"inline"`: from a base64 literal in the bundle itself, so the CJS
10
+ * file is self-contained under a plain `node app.cjs` — the same
11
+ * artifact minus the embedded Node runtime. Costs ~4/3 of the addon's
12
+ * size in source text (the addon is ~1.6 MB) and is parsed once at
13
+ * startup; the extraction and dlopen below are shared.
14
+ */
15
+ export type NativeAddonSource = "sea-asset" | "inline";
16
+ export type NativeAddonShimOptions = {
17
+ /** The bare specifier to replace, in practice "@gtkx/native". */
18
+ specifier: string;
19
+ /** The app root — the shim's id lives here, see above. */
20
+ appRoot: string;
21
+ /** Where the addon's bytes come from at runtime. */
22
+ source: NativeAddonSource;
23
+ /** SEA asset key; unused when `source` is "inline". */
24
+ assetKey?: string;
25
+ /** The addon's bytes; required when `source` is "inline". */
26
+ addonBytes?: Buffer;
27
+ };
28
+ /**
29
+ * Intercepts every import/require of `specifier` (an exact bare module
30
+ * specifier, e.g. "@gtkx/native") and replaces it with the extraction shim
31
+ * above. The real module never reaches the bundle graph — only its
32
+ * re-exported surface, loaded from the extracted file at runtime.
33
+ *
34
+ * The shim is given an id inside `appRoot` with a `.cjs` extension rather
35
+ * than a `\0`-prefixed virtual one: the shim IS CommonJS (it assigns
36
+ * `module.exports` so consumers' NAMED imports of the addon still resolve
37
+ * through the bundler's interop), and a real directory is what lets any
38
+ * specifier inside it resolve normally.
39
+ */
40
+ export declare const nativeAddonShimPlugin: (options: NativeAddonShimOptions) => Plugin;
@@ -0,0 +1,121 @@
1
+ // The gtkx native addon (@gtkx/native-<platform>-<libc>, a Rust/NAPI addon
2
+ // loaded through dlopen — see docs/getting-started.md's "Shipping an app"
3
+ // section for the full design reasoning) cannot be embedded as bundled JS:
4
+ // a Node SEA is a V8 code cache blob, and dlopen needs a real file on a
5
+ // real filesystem, not bytes inside the executable.
6
+ //
7
+ // So it has to be carried as bytes and written back to disk before use.
8
+ // This plugin swaps every import of a given specifier (in practice,
9
+ // "@gtkx/native" — see ../sea/bundle.ts) for a shim that does exactly
10
+ // that: extract to a per-user cache directory (content-hash-keyed, so
11
+ // repeat launches reuse the file instead of re-extracting ~1.6 MB every
12
+ // start) and dlopen it from there. Where the bytes come from is the one
13
+ // difference between the two single-file artifacts — Node's SEA "assets"
14
+ // mechanism for the executable, a base64 literal for the standalone .cjs;
15
+ // see {@link NativeAddonSource}.
16
+ //
17
+ // Cache location: XDG_CACHE_HOME (or ~/.cache) first, os.tmpdir() as a
18
+ // fallback for a read-only $HOME. Deliberately NOT the SEA executable's
19
+ // own directory — that may be read-only (a mounted image, a root-owned
20
+ // install under /opt) or simply a different place than where the addon
21
+ // was extracted the first time, if the binary moved. This is the same
22
+ // question gtkx's own tutorial answers by placing the addon BESIDE the
23
+ // executable (dist/gtkx.node next to dist/app) — a real divergence, not an
24
+ // oversight: that keeps two files, which is exactly what this epic set
25
+ // out to stop doing.
26
+ import { join } from "node:path";
27
+ export const NATIVE_ASSET_KEY = "gtkx-native.node";
28
+ const bytesExpression = (source, assetKey) => source === "sea-asset"
29
+ ? `Buffer.from(require("node:sea").getAsset(${JSON.stringify(assetKey)}))`
30
+ : `Buffer.from(__gtkxNativeBase64, "base64")`;
31
+ const shimSource = (source, assetKey, base64) => `
32
+ const { createHash } = require("node:crypto");
33
+ const { mkdirSync, existsSync, writeFileSync, renameSync } = require("node:fs");
34
+ const { join } = require("node:path");
35
+ const os = require("node:os");
36
+ ${source === "inline" ? `const __gtkxNativeBase64 = ${JSON.stringify(base64)};` : ""}
37
+
38
+ const bytes = ${bytesExpression(source, assetKey)};
39
+ const hash = createHash("sha256").update(bytes).digest("hex").slice(0, 16);
40
+ const fileName = "native-" + hash + ".node";
41
+
42
+ const candidateDirs = [
43
+ join(process.env.XDG_CACHE_HOME || join(os.homedir(), ".cache"), "react-native-gtkx-sea"),
44
+ join(os.tmpdir(), "react-native-gtkx-sea"),
45
+ ];
46
+
47
+ let target;
48
+ let lastError;
49
+ for (const dir of candidateDirs) {
50
+ try {
51
+ mkdirSync(dir, { recursive: true });
52
+ const candidate = join(dir, fileName);
53
+ if (!existsSync(candidate)) {
54
+ const tmp = candidate + "." + process.pid + ".tmp";
55
+ writeFileSync(tmp, bytes, { mode: 0o755 });
56
+ renameSync(tmp, candidate);
57
+ }
58
+ target = candidate;
59
+ break;
60
+ } catch (error) {
61
+ lastError = error;
62
+ }
63
+ }
64
+ if (!target) {
65
+ throw new Error(
66
+ "react-native-gtkx: could not extract the native addon to a writable " +
67
+ "cache directory (tried " + candidateDirs.join(", ") + "): " + String(lastError),
68
+ );
69
+ }
70
+
71
+ // Not require(target): the require() available to a SEA's main script is
72
+ // restricted to built-ins and embedded assets (verified — requiring an
73
+ // arbitrary absolute path from here throws ERR_UNKNOWN_BUILTIN_MODULE, the
74
+ // same error Node throws for an unrecognized built-in specifier). That
75
+ // restriction doesn't apply to process.dlopen(), the lower-level
76
+ // primitive require() itself uses for ".node" files (Module._extensions
77
+ // [".node"]) — it works on any real path, which is exactly what makes
78
+ // this shim work at all. The "inline" build could use a plain require()
79
+ // here, but shares dlopen() rather than branching: one code path that is
80
+ // proven by both artifacts beats two, one of which is rarely exercised.
81
+ const nativeModule = { exports: {} };
82
+ process.dlopen(nativeModule, target);
83
+ // The vite path's own build (dist/bundle.js, gtkx's CLI plugin) calls
84
+ // this immediately after loading the addon, before anything else touches
85
+ // it; @gtkx/runtime's compiled JS never calls it itself (confirmed by
86
+ // inspecting its dist — it only re-exports a handful of low-level
87
+ // functions), so ordinary require() of the addon through Node's own
88
+ // napi module registration must be relying on something dlopen() alone
89
+ // does not trigger. Without this call the addon has no thread registered
90
+ // as "the Node environment's owner" and the first GTK-driven callback
91
+ // into JS panics: "the Node environment was accessed from a thread it is
92
+ // not installed on" (reproduced and fixed by adding this line).
93
+ nativeModule.exports.init();
94
+ module.exports = nativeModule.exports;
95
+ `;
96
+ /**
97
+ * Intercepts every import/require of `specifier` (an exact bare module
98
+ * specifier, e.g. "@gtkx/native") and replaces it with the extraction shim
99
+ * above. The real module never reaches the bundle graph — only its
100
+ * re-exported surface, loaded from the extracted file at runtime.
101
+ *
102
+ * The shim is given an id inside `appRoot` with a `.cjs` extension rather
103
+ * than a `\0`-prefixed virtual one: the shim IS CommonJS (it assigns
104
+ * `module.exports` so consumers' NAMED imports of the addon still resolve
105
+ * through the bundler's interop), and a real directory is what lets any
106
+ * specifier inside it resolve normally.
107
+ */
108
+ export const nativeAddonShimPlugin = (options) => {
109
+ const { specifier, appRoot, source } = options;
110
+ if (source === "inline" && !options.addonBytes) {
111
+ throw new Error('the "inline" native addon source needs addonBytes');
112
+ }
113
+ const shimId = join(appRoot, "__gtkx-sea-native-shim.cjs");
114
+ const contents = shimSource(source, options.assetKey ?? NATIVE_ASSET_KEY, options.addonBytes?.toString("base64") ?? "");
115
+ return {
116
+ name: "gtkx-native-addon-shim",
117
+ resolveId: (id) => (id === specifier ? shimId : null),
118
+ load: (id) => (id === shimId ? contents : null),
119
+ };
120
+ };
121
+ //# sourceMappingURL=native-shim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-shim.js","sourceRoot":"","sources":["../../src/sea/native-shim.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,2EAA2E;AAC3E,wEAAwE;AACxE,oDAAoD;AACpD,EAAE;AACF,wEAAwE;AACxE,oEAAoE;AACpE,sEAAsE;AACtE,sEAAsE;AACtE,wEAAwE;AACxE,wEAAwE;AACxE,yEAAyE;AACzE,0EAA0E;AAC1E,iCAAiC;AACjC,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,uEAAuE;AACvE,uEAAuE;AACvE,sEAAsE;AACtE,uEAAuE;AACvE,2EAA2E;AAC3E,uEAAuE;AACvE,qBAAqB;AACrB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAA;AAgBlD,MAAM,eAAe,GAA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CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;KAChD,CAAA;AACH,CAAC,CAAA","sourcesContent":["// The gtkx native addon (@gtkx/native-<platform>-<libc>, a Rust/NAPI addon\n// loaded through dlopen — see docs/getting-started.md's \"Shipping an app\"\n// section for the full design reasoning) cannot be embedded as bundled JS:\n// a Node SEA is a V8 code cache blob, and dlopen needs a real file on a\n// real filesystem, not bytes inside the executable.\n//\n// So it has to be carried as bytes and written back to disk before use.\n// This plugin swaps every import of a given specifier (in practice,\n// \"@gtkx/native\" — see ../sea/bundle.ts) for a shim that does exactly\n// that: extract to a per-user cache directory (content-hash-keyed, so\n// repeat launches reuse the file instead of re-extracting ~1.6 MB every\n// start) and dlopen it from there. Where the bytes come from is the one\n// difference between the two single-file artifacts — Node's SEA \"assets\"\n// mechanism for the executable, a base64 literal for the standalone .cjs;\n// see {@link NativeAddonSource}.\n//\n// Cache location: XDG_CACHE_HOME (or ~/.cache) first, os.tmpdir() as a\n// fallback for a read-only $HOME. Deliberately NOT the SEA executable's\n// own directory — that may be read-only (a mounted image, a root-owned\n// install under /opt) or simply a different place than where the addon\n// was extracted the first time, if the binary moved. This is the same\n// question gtkx's own tutorial answers by placing the addon BESIDE the\n// executable (dist/gtkx.node next to dist/app) — a real divergence, not an\n// oversight: that keeps two files, which is exactly what this epic set\n// out to stop doing.\nimport { join } from \"node:path\"\nimport type { Plugin } from \"rolldown\"\n\nexport const NATIVE_ASSET_KEY = \"gtkx-native.node\"\n\n/**\n * Where the shim gets the addon's bytes from — the only difference between\n * the two single-file artifacts:\n *\n * - `\"sea-asset\"`: from the SEA blob, via node:sea. Only works inside a\n * real single executable.\n * - `\"inline\"`: from a base64 literal in the bundle itself, so the CJS\n * file is self-contained under a plain `node app.cjs` — the same\n * artifact minus the embedded Node runtime. Costs ~4/3 of the addon's\n * size in source text (the addon is ~1.6 MB) and is parsed once at\n * startup; the extraction and dlopen below are shared.\n */\nexport type NativeAddonSource = \"sea-asset\" | \"inline\"\n\nconst bytesExpression = (\n source: NativeAddonSource,\n assetKey: string,\n): string =>\n source === \"sea-asset\"\n ? `Buffer.from(require(\"node:sea\").getAsset(${JSON.stringify(assetKey)}))`\n : `Buffer.from(__gtkxNativeBase64, \"base64\")`\n\nconst shimSource = (\n source: NativeAddonSource,\n assetKey: string,\n base64: string,\n): string => `\nconst { createHash } = require(\"node:crypto\");\nconst { mkdirSync, existsSync, writeFileSync, renameSync } = require(\"node:fs\");\nconst { join } = require(\"node:path\");\nconst os = require(\"node:os\");\n${source === \"inline\" ? `const __gtkxNativeBase64 = ${JSON.stringify(base64)};` : \"\"}\n\nconst bytes = ${bytesExpression(source, assetKey)};\nconst hash = createHash(\"sha256\").update(bytes).digest(\"hex\").slice(0, 16);\nconst fileName = \"native-\" + hash + \".node\";\n\nconst candidateDirs = [\n join(process.env.XDG_CACHE_HOME || join(os.homedir(), \".cache\"), \"react-native-gtkx-sea\"),\n join(os.tmpdir(), \"react-native-gtkx-sea\"),\n];\n\nlet target;\nlet lastError;\nfor (const dir of candidateDirs) {\n try {\n mkdirSync(dir, { recursive: true });\n const candidate = join(dir, fileName);\n if (!existsSync(candidate)) {\n const tmp = candidate + \".\" + process.pid + \".tmp\";\n writeFileSync(tmp, bytes, { mode: 0o755 });\n renameSync(tmp, candidate);\n }\n target = candidate;\n break;\n } catch (error) {\n lastError = error;\n }\n}\nif (!target) {\n throw new Error(\n \"react-native-gtkx: could not extract the native addon to a writable \" +\n \"cache directory (tried \" + candidateDirs.join(\", \") + \"): \" + String(lastError),\n );\n}\n\n// Not require(target): the require() available to a SEA's main script is\n// restricted to built-ins and embedded assets (verified — requiring an\n// arbitrary absolute path from here throws ERR_UNKNOWN_BUILTIN_MODULE, the\n// same error Node throws for an unrecognized built-in specifier). That\n// restriction doesn't apply to process.dlopen(), the lower-level\n// primitive require() itself uses for \".node\" files (Module._extensions\n// [\".node\"]) — it works on any real path, which is exactly what makes\n// this shim work at all. The \"inline\" build could use a plain require()\n// here, but shares dlopen() rather than branching: one code path that is\n// proven by both artifacts beats two, one of which is rarely exercised.\nconst nativeModule = { exports: {} };\nprocess.dlopen(nativeModule, target);\n// The vite path's own build (dist/bundle.js, gtkx's CLI plugin) calls\n// this immediately after loading the addon, before anything else touches\n// it; @gtkx/runtime's compiled JS never calls it itself (confirmed by\n// inspecting its dist — it only re-exports a handful of low-level\n// functions), so ordinary require() of the addon through Node's own\n// napi module registration must be relying on something dlopen() alone\n// does not trigger. Without this call the addon has no thread registered\n// as \"the Node environment's owner\" and the first GTK-driven callback\n// into JS panics: \"the Node environment was accessed from a thread it is\n// not installed on\" (reproduced and fixed by adding this line).\nnativeModule.exports.init();\nmodule.exports = nativeModule.exports;\n`\n\nexport type NativeAddonShimOptions = {\n /** The bare specifier to replace, in practice \"@gtkx/native\". */\n specifier: string\n /** The app root — the shim's id lives here, see above. */\n appRoot: string\n /** Where the addon's bytes come from at runtime. */\n source: NativeAddonSource\n /** SEA asset key; unused when `source` is \"inline\". */\n assetKey?: string\n /** The addon's bytes; required when `source` is \"inline\". */\n addonBytes?: Buffer\n}\n\n/**\n * Intercepts every import/require of `specifier` (an exact bare module\n * specifier, e.g. \"@gtkx/native\") and replaces it with the extraction shim\n * above. The real module never reaches the bundle graph — only its\n * re-exported surface, loaded from the extracted file at runtime.\n *\n * The shim is given an id inside `appRoot` with a `.cjs` extension rather\n * than a `\\0`-prefixed virtual one: the shim IS CommonJS (it assigns\n * `module.exports` so consumers' NAMED imports of the addon still resolve\n * through the bundler's interop), and a real directory is what lets any\n * specifier inside it resolve normally.\n */\nexport const nativeAddonShimPlugin = (\n options: NativeAddonShimOptions,\n): Plugin => {\n const { specifier, appRoot, source } = options\n if (source === \"inline\" && !options.addonBytes) {\n throw new Error('the \"inline\" native addon source needs addonBytes')\n }\n const shimId = join(appRoot, \"__gtkx-sea-native-shim.cjs\")\n const contents = shimSource(\n source,\n options.assetKey ?? NATIVE_ASSET_KEY,\n options.addonBytes?.toString(\"base64\") ?? \"\",\n )\n return {\n name: \"gtkx-native-addon-shim\",\n resolveId: (id) => (id === specifier ? shimId : null),\n load: (id) => (id === shimId ? contents : null),\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "rolldown";
2
+ export declare const reactAnchorPlugin: (appRoot: string) => Plugin;
@@ -0,0 +1,30 @@
1
+ // react (and its jsx runtimes) must resolve to the exact same instance
2
+ // @gtkx/react's reconciler uses — the reconciler and the app share one
3
+ // React, and anchoring resolution at the app's own node_modules can pick
4
+ // up a second copy (npm's peer-dependency auto-install, or a differently
5
+ // hoisted layout). runner/host.ts hits the identical problem and solves it
6
+ // the same way: resolve "react"/"react/jsx-runtime"/"react/jsx-dev-runtime"
7
+ // from @gtkx/react's own location, not the app's.
8
+ //
9
+ // Confirmed necessary empirically, not just by analogy with host.ts:
10
+ // without this plugin the built SEA threw React's "Invalid hook call"
11
+ // (two React module instances in the bundle graph) — the bundler had
12
+ // resolved the entry's top-level `import("react")` from the app root and
13
+ // @gtkx/react's own internal `import "react"` from @gtkx/react's
14
+ // directory, landing on two different files were the two roots not
15
+ // deduplicated to the same node_modules/react.
16
+ import { createRequire } from "node:module";
17
+ const REACT_SPECIFIERS = new Set([
18
+ "react",
19
+ "react/jsx-runtime",
20
+ "react/jsx-dev-runtime",
21
+ ]);
22
+ export const reactAnchorPlugin = (appRoot) => {
23
+ const appRequire = createRequire(`${appRoot}/package.json`);
24
+ const fromGtkxReact = createRequire(appRequire.resolve("@gtkx/react"));
25
+ return {
26
+ name: "gtkx-react-anchor",
27
+ resolveId: (source) => REACT_SPECIFIERS.has(source) ? fromGtkxReact.resolve(source) : null,
28
+ };
29
+ };
30
+ //# sourceMappingURL=react-anchor-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-anchor-plugin.js","sourceRoot":"","sources":["../../src/sea/react-anchor-plugin.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,uEAAuE;AACvE,yEAAyE;AACzE,yEAAyE;AACzE,2EAA2E;AAC3E,4EAA4E;AAC5E,kDAAkD;AAClD,EAAE;AACF,qEAAqE;AACrE,sEAAsE;AACtE,qEAAqE;AACrE,yEAAyE;AACzE,iEAAiE;AACjE,mEAAmE;AACnE,+CAA+C;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAG3C,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,OAAO;IACP,mBAAmB;IACnB,uBAAuB;CACxB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAU,EAAE;IAC3D,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,OAAO,eAAe,CAAC,CAAA;IAC3D,MAAM,aAAa,GAAG,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAA;IACtE,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CACpB,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI;KACtE,CAAA;AACH,CAAC,CAAA","sourcesContent":["// react (and its jsx runtimes) must resolve to the exact same instance\n// @gtkx/react's reconciler uses — the reconciler and the app share one\n// React, and anchoring resolution at the app's own node_modules can pick\n// up a second copy (npm's peer-dependency auto-install, or a differently\n// hoisted layout). runner/host.ts hits the identical problem and solves it\n// the same way: resolve \"react\"/\"react/jsx-runtime\"/\"react/jsx-dev-runtime\"\n// from @gtkx/react's own location, not the app's.\n//\n// Confirmed necessary empirically, not just by analogy with host.ts:\n// without this plugin the built SEA threw React's \"Invalid hook call\"\n// (two React module instances in the bundle graph) — the bundler had\n// resolved the entry's top-level `import(\"react\")` from the app root and\n// @gtkx/react's own internal `import \"react\"` from @gtkx/react's\n// directory, landing on two different files were the two roots not\n// deduplicated to the same node_modules/react.\nimport { createRequire } from \"node:module\"\nimport type { Plugin } from \"rolldown\"\n\nconst REACT_SPECIFIERS = new Set([\n \"react\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n])\n\nexport const reactAnchorPlugin = (appRoot: string): Plugin => {\n const appRequire = createRequire(`${appRoot}/package.json`)\n const fromGtkxReact = createRequire(appRequire.resolve(\"@gtkx/react\"))\n return {\n name: \"gtkx-react-anchor\",\n resolveId: (source) =>\n REACT_SPECIFIERS.has(source) ? fromGtkxReact.resolve(source) : null,\n }\n}\n"]}
@@ -4,4 +4,5 @@ export { createCssRegistry, type CssFn, type CssRegistry } from "./registry";
4
4
  export { splitStyle } from "./split-style";
5
5
  export { absoluteFill, absoluteFillObject, compose, create, flatten, hairlineWidth, StyleSheet, } from "./style-sheet";
6
6
  export { textAlignToLabelProps, type LabelAlignProps, type TextAlign, } from "./text-align";
7
+ export { composeTransform, IDENTITY_TRANSFORM, isIdentityTransform, isTranslationOnly, parseAngle, } from "./transform";
7
8
  export { visualStyleToCss } from "./visual-css";
@@ -10,5 +10,6 @@ export { createCssRegistry } from "./registry";
10
10
  export { splitStyle } from "./split-style";
11
11
  export { absoluteFill, absoluteFillObject, compose, create, flatten, hairlineWidth, StyleSheet, } from "./style-sheet";
12
12
  export { textAlignToLabelProps, } from "./text-align";
13
+ export { composeTransform, IDENTITY_TRANSFORM, isIdentityTransform, isTranslationOnly, parseAngle, } from "./transform";
13
14
  export { visualStyleToCss } from "./visual-css";
14
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/style/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,8CAA8C;AAC9C,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,oEAAoE;AAEpE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAgC,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,OAAO,EACP,aAAa,EACb,UAAU,GACX,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,qBAAqB,GAGtB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA","sourcesContent":["// Style pipeline: StyleSheet → flatten → splitStyle →\n// visualStyleToCss → memoized class registry.\n//\n// Everything exported here is pure (no bridge imports) and unit-testable on\n// any OS. The production registry that talks to the gtkx `css` helper lives\n// in ./registry.gtkx.ts and is imported directly by the components.\n\nexport { parseColor, PlatformColor } from \"./colors\"\nexport { resetDevWarnings } from \"./dev-warning\"\nexport { createCssRegistry, type CssFn, type CssRegistry } from \"./registry\"\nexport { splitStyle } from \"./split-style\"\nexport {\n absoluteFill,\n absoluteFillObject,\n compose,\n create,\n flatten,\n hairlineWidth,\n StyleSheet,\n} from \"./style-sheet\"\nexport {\n textAlignToLabelProps,\n type LabelAlignProps,\n type TextAlign,\n} from \"./text-align\"\nexport { visualStyleToCss } from \"./visual-css\"\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/style/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,8CAA8C;AAC9C,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,oEAAoE;AAEpE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAgC,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,OAAO,EACP,aAAa,EACb,UAAU,GACX,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,qBAAqB,GAGtB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,GACX,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA","sourcesContent":["// Style pipeline: StyleSheet → flatten → splitStyle →\n// visualStyleToCss → memoized class registry.\n//\n// Everything exported here is pure (no bridge imports) and unit-testable on\n// any OS. The production registry that talks to the gtkx `css` helper lives\n// in ./registry.gtkx.ts and is imported directly by the components.\n\nexport { parseColor, PlatformColor } from \"./colors\"\nexport { resetDevWarnings } from \"./dev-warning\"\nexport { createCssRegistry, type CssFn, type CssRegistry } from \"./registry\"\nexport { splitStyle } from \"./split-style\"\nexport {\n absoluteFill,\n absoluteFillObject,\n compose,\n create,\n flatten,\n hairlineWidth,\n StyleSheet,\n} from \"./style-sheet\"\nexport {\n textAlignToLabelProps,\n type LabelAlignProps,\n type TextAlign,\n} from \"./text-align\"\nexport {\n composeTransform,\n IDENTITY_TRANSFORM,\n isIdentityTransform,\n isTranslationOnly,\n parseAngle,\n} from \"./transform\"\nexport { visualStyleToCss } from \"./visual-css\"\n"]}
@@ -47,8 +47,8 @@ const LAYOUT_KEYS = {
47
47
  top: true,
48
48
  width: true,
49
49
  };
50
- // Note: `transform` is visual by contract — it is applied by the layout
51
- // engine through Fixed.Child matrices, not through CSS, and is passed
50
+ // Note: `transform` is visual by contract — it is applied as the
51
+ // GskTransform of the child's allocation, not through CSS, and is passed
52
52
  // through here untouched.
53
53
  const VISUAL_KEYS = {
54
54
  backgroundColor: true,