react-native-gtkx 0.4.0-alpha.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apis/host.gtkx.js.map +1 -1
- package/dist/components/modal.d.ts +1 -1
- package/dist/components/modal.js +16 -8
- package/dist/components/modal.js.map +1 -1
- package/dist/gtkx/bridge/adw.js.map +1 -1
- package/dist/gtkx/bridge/core.d.ts +1 -2
- package/dist/gtkx/bridge/core.js +2 -5
- package/dist/gtkx/bridge/core.js.map +1 -1
- package/dist/gtkx/bridge/geometry.js +1 -1
- package/dist/gtkx/bridge/geometry.js.map +1 -1
- package/dist/gtkx/bridge/layout-manager.js +18 -5
- package/dist/gtkx/bridge/layout-manager.js.map +1 -1
- package/dist/gtkx/bridge/slot-portal.js.map +1 -1
- package/dist/gtkx/bridge/svg-node.js +13 -6
- package/dist/gtkx/bridge/svg-node.js.map +1 -1
- package/dist/gtkx/bridge/view-box.js +18 -9
- package/dist/gtkx/bridge/view-box.js.map +1 -1
- package/dist/gtkx/bridge/widgets.generated.adw.js +1 -1
- package/dist/gtkx/bridge/widgets.generated.adw.js.map +1 -1
- package/dist/mcp/data/generated.d.ts +58 -42
- package/dist/mcp/data/generated.js +63 -43
- package/dist/mcp/data/generated.js.map +1 -1
- package/dist/runner/host-dev.js +5 -0
- package/dist/runner/host-dev.js.map +1 -1
- package/dist/runner/host.js +15 -0
- package/dist/runner/host.js.map +1 -1
- package/dist/runner/index.d.ts +27 -0
- package/dist/runner/index.js +206 -1
- package/dist/runner/index.js.map +1 -1
- package/dist/sea/assemble.d.ts +9 -0
- package/dist/sea/assemble.js +16 -3
- package/dist/sea/assemble.js.map +1 -1
- package/dist/sea/bundle.d.ts +37 -2
- package/dist/sea/bundle.js +76 -4
- package/dist/sea/bundle.js.map +1 -1
- package/dist/sea/native-shim.js +1 -1
- package/dist/sea/native-shim.js.map +1 -1
- package/dist/testing/index.js +28 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/vite/index.js +3 -3
- package/dist/vite/index.js.map +1 -1
- package/dist/vitest/index.d.ts +1 -1
- package/dist/vitest/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/gtkx/bridge/use-signal.d.ts +0 -2
- package/dist/gtkx/bridge/use-signal.js +0 -41
- package/dist/gtkx/bridge/use-signal.js.map +0 -1
package/dist/runner/host-dev.js
CHANGED
|
@@ -205,6 +205,11 @@ catch {
|
|
|
205
205
|
if (!response.ok) {
|
|
206
206
|
fail(`Metro returned ${response.status} for the dev bundle:\n${await response.text()}`);
|
|
207
207
|
}
|
|
208
|
+
// 1.2-WORKAROUND(gtk-application-argv): same fix as host.ts — see that
|
|
209
|
+
// file for the full explanation. Here argv[2] is the dev bundle URL, not
|
|
210
|
+
// a file; strip it before the bundle mounts <GtkApplication> and its
|
|
211
|
+
// effect reads process.argv.slice(2) as the GApplication command line.
|
|
212
|
+
process.argv.length = 2;
|
|
208
213
|
vm.runInThisContext(await response.text(), { filename: bundleUrl });
|
|
209
214
|
installDevMenu();
|
|
210
215
|
const HMRClient = fromApp("metro-runtime/src/modules/HMRClient");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-dev.js","sourceRoot":"","sources":["../../src/runner/host-dev.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,uEAAuE;AACvE,oEAAoE;AACpE,0EAA0E;AAC1E,0EAA0E;AAC1E,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,wEAAwE;AACxE,oEAAoE;AACpE,qEAAqE;AACrE,yEAAyE;AACzE,iEAAiE;AACjE,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EACL,qBAAqB,EACrB,8BAA8B,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C,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;IAC1B,OAAO,CAAC,KAAK,CACX,oCAAoC,IAAI,EAAE,IAAI,IAAI,SAAS,OAAO,IAAI,EAAE,OAAO,IAAI,EAAE,EAAE,CACxF,CAAA;AACH,CAAC,CAAC,CAAA;AACF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;IACtB,OAAO,CAAC,IAAI,CACV,0FAA0F,CAC3F,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// The DEV host: fetch the dev bundle from a Metro dev server, execute it,\n// subscribe to HMR updates and let react-refresh re-render through the\n// @gtkx/react reconciler with component state preserved. Spawned by\n// `run-linux --dev` as `node dist/runner/host-dev.js <bundle-url>`; exits\n// with code 65 when a full refresh is required — the supervisor restarts.\n//\n// Division of labor (validated by spike/rn-platform, FINDINGS-dev.md):\n// metro-runtime's dev require scopes the react-refresh registration per\n// module and applies hot updates once global.__ReactRefresh exists; its\n// HMRClient speaks the /hot websocket protocol verbatim over Node's\n// global WebSocket. This file only adds the dev pieces on top of the\n// release host (./host.ts — deliberately self-contained twins: both must\n// stay runnable under bare Node, so they cannot share a relative\n// extensionless import).\nimport { createRequire, registerHooks } from \"node:module\"\nimport { join } from \"node:path\"\nimport { pathToFileURL } from \"node:url\"\nimport vm from \"node:vm\"\nimport {\n HOST_MODULE_EXTERNALS,\n OPTIONAL_HOST_MODULE_EXTERNALS,\n} from \"react-native-gtkx/metro\"\n\ntype HostModule = Record<string, unknown>\n\nconst fail = (message: string): never => {\n console.error(`[react-native-gtkx] ${message}`)\n process.exit(1)\n}\n\nif (typeof registerHooks !== \"function\") {\n fail(\n `Node ${process.version} lacks module.registerHooks — the linux host needs Node >= 24.`,\n )\n}\n\n// react and the reconciler must run their DEV builds for react-refresh.\nprocess.env.NODE_ENV = process.env.NODE_ENV ?? \"development\"\n\nconst bundleUrl = process.argv[2]\nif (!bundleUrl) {\n fail(\"usage: node host-dev.js <metro-dev-bundle-url>\")\n}\n\n// Resolution anchors: react-refresh and metro-runtime ship with the APP's\n// react-native; @gtkx/* resolve as this package's dependencies; react must\n// be the exact instance the reconciler sees (see host.ts).\nconst fromApp = createRequire(join(process.cwd(), \"package.json\"))\nconst fromPackage = createRequire(import.meta.url)\nconst fromGtkxReact = createRequire(fromPackage.resolve(\"@gtkx/react\"))\n\n// --- react-refresh: inject BEFORE @gtkx/react loads (the reconciler\n// registers into the patched devtools hook).\nconst RefreshRuntime = fromApp(\"react-refresh/runtime\") as Record<\n string,\n unknown\n> & { injectIntoGlobalHook(target: unknown): void }\nRefreshRuntime.injectIntoGlobalHook(globalThis)\nglobalThis.$RefreshReg$ = () => {}\nglobalThis.$RefreshSig$ = () => (type: unknown) => type\nglobalThis.__ReactRefresh = {\n ...RefreshRuntime,\n performFullRefresh(reason: string) {\n console.warn(\n `[react-native-gtkx] full refresh required (${reason}) — restarting`,\n )\n process.exit(65)\n },\n}\n\n// --- virtual:gtkx-config (same mechanism and same module shape as the\n// release host — see host.ts for why each export is needed).\nconst CONFIG_REQUIRED =\n \"gtkx.config.ts with an applicationId is required in the app root \" +\n '(export default defineConfig({ applicationId: \"...\", libraries: [...] })).'\nconst { createConfigLoader } = await import(\n pathToFileURL(fromPackage.resolve(\"@gtkx/config/internal\")).href\n)\nconst gtkxConfig = await createConfigLoader()\n .resolve(process.cwd())\n .catch((error: unknown) => fail(`${CONFIG_REQUIRED}\\n${String(error)}`))\nif (!gtkxConfig.applicationId) {\n fail(CONFIG_REQUIRED)\n}\nif (gtkxConfig.elements !== null) {\n fail(\n \"gtkx.config.ts `elements.behaviors` is not supported on the linux \" +\n \"platform — react-native-gtkx owns element behaviors.\",\n )\n}\nconst configModuleUrl = new URL(\"./__virtual-gtkx-config.mjs\", import.meta.url)\n .href\nconst lazyElements = Object.fromEntries(\n gtkxConfig.lazyElements.map((type: string) => [type, { isLazy: true }]),\n)\nconst configModuleSource = [\n `export * from \"@gtkx/jsx/metadata\";`,\n `export const applicationId = ${JSON.stringify(gtkxConfig.applicationId)};`,\n `export const userEventSignals = ${JSON.stringify(gtkxConfig.userEventSignals)};`,\n `export const elements = ${JSON.stringify(lazyElements)};`,\n].join(\"\\n\")\nregisterHooks({\n resolve(specifier, context, nextResolve) {\n if (specifier === \"virtual:gtkx-config\") {\n return { url: configModuleUrl, shortCircuit: true }\n }\n return nextResolve(specifier, context)\n },\n load(url, context, nextLoad) {\n if (url === configModuleUrl) {\n return {\n format: \"module\",\n source: configModuleSource,\n shortCircuit: true,\n }\n }\n return nextLoad(url, context)\n },\n})\n\n// --- host modules (same interop merging as the release host).\nconst resolveExternal = (name: string): string =>\n name === \"react\" || name.startsWith(\"react/\")\n ? fromGtkxReact.resolve(name)\n : fromPackage.resolve(name)\n\nconst load = async (name: string): Promise<HostModule> => {\n const namespace: HostModule = await import(\n pathToFileURL(resolveExternal(name)).href\n )\n const merged: HostModule = { __esModule: true, ...namespace }\n if (!(\"default\" in namespace)) {\n merged.default = namespace\n }\n return merged\n}\n\nglobalThis.__hostModules = {}\nfor (const name of HOST_MODULE_EXTERNALS) {\n try {\n globalThis.__hostModules[name] = await load(name)\n } catch (error) {\n if (OPTIONAL_HOST_MODULE_EXTERNALS.has(name)) {\n // See host.ts's identical guard — expected on the plain-GTK profile.\n continue\n }\n fail(\n `failed to load host module \"${name}\" — is the codegen store in ` +\n `place (npx gtkx codegen) and GTK4/libadwaita installed?\\n${String(error)}`,\n )\n }\n}\nglobalThis.__hostRequire = createRequire(import.meta.url)\n\n// --- Dev Menu (Ctrl+Shift+D, the react-native-windows precedent).\n// Installed before the bundle runs so DevSettings.reload works from app\n// code; the key controller attaches once the app window exists.\nconst requestReload = (reason?: string): never => {\n console.warn(\n `[react-native-gtkx] reload requested${reason ? ` (${reason})` : \"\"} — restarting`,\n )\n return process.exit(65)\n}\nglobalThis.__rnGtkxDevHost = { reload: requestReload }\n\n// Structural slices of the GTK wrappers the menu touches — the host talks\n// to codegen namespaces through __hostModules, untyped by design.\ntype DevMenuWindow = { addController(controller: unknown): void }\ntype DevMenuDialog = {\n setHeading(heading: string): void\n setBody(body: string): void\n addResponse(id: string, label: string): void\n setResponseAppearance(id: string, appearance: unknown): void\n setDefaultResponse(id: string): void\n setCloseResponse(id: string): void\n choose(parent: DevMenuWindow): Promise<string>\n}\n\nconst installDevMenu = (): void => {\n const gtk = globalThis.__hostModules[\"@gtkx/gi/gtk\"] as {\n EventControllerKey: new () => {\n on(signal: string, handler: (...args: unknown[]) => unknown): void\n }\n }\n const gdk = globalThis.__hostModules[\"@gtkx/gi/gdk\"] as {\n ModifierType: { CONTROL_MASK: number; SHIFT_MASK: number }\n }\n const adw = globalThis.__hostModules[\"@gtkx/gi/adw\"] as {\n AlertDialog: new () => DevMenuDialog\n ResponseAppearance: { SUGGESTED: unknown }\n }\n const gio = globalThis.__hostModules[\"@gtkx/gi/gio\"] as {\n Application: {\n getDefault():\n { getActiveWindow?: () => DevMenuWindow | null } | null | undefined\n }\n }\n // GDK keysyms for latin letters equal their ASCII codes.\n const KEY_UPPER_D = 0x44\n const KEY_LOWER_D = 0x64\n\n let menuOpen = false\n const openDevMenu = async (window: DevMenuWindow): Promise<void> => {\n if (menuOpen) {\n return\n }\n menuOpen = true\n try {\n const items = globalThis.__rnGtkxDevMenuItems ?? []\n const dialog = new adw.AlertDialog()\n dialog.setHeading(\"React Native Dev Menu\")\n dialog.setBody(bundleUrl!)\n dialog.addResponse(\"cancel\", \"Cancel\")\n items.forEach((item, index) => {\n dialog.addResponse(`custom-${index}`, item.title)\n })\n dialog.addResponse(\"reload\", \"Reload\")\n dialog.setResponseAppearance(\"reload\", adw.ResponseAppearance.SUGGESTED)\n dialog.setDefaultResponse(\"reload\")\n dialog.setCloseResponse(\"cancel\")\n const response = await dialog.choose(window)\n if (response === \"reload\") {\n requestReload()\n }\n const custom = /^custom-(\\d+)$/.exec(response)\n if (custom) {\n items[Number(custom[1])]?.handler()\n }\n } catch (error) {\n console.error(`[react-native-gtkx] dev menu failed: ${String(error)}`)\n } finally {\n menuOpen = false\n }\n }\n\n const attach = (): void => {\n const window = gio.Application.getDefault()?.getActiveWindow?.()\n if (!window) {\n // The bundle opens the window asynchronously (application activate).\n setTimeout(attach, 200)\n return\n }\n const controller = new gtk.EventControllerKey()\n controller.on(\"key-pressed\", (keyval, _keycode, state) => {\n const modifiers = state as number\n const wanted =\n (modifiers & gdk.ModifierType.CONTROL_MASK) !== 0 &&\n (modifiers & gdk.ModifierType.SHIFT_MASK) !== 0 &&\n (keyval === KEY_UPPER_D || keyval === KEY_LOWER_D)\n if (wanted) {\n void openDevMenu(window)\n return true\n }\n return false\n })\n window.addController(controller)\n console.warn(\"[react-native-gtkx] dev menu ready (Ctrl+Shift+D)\")\n }\n attach()\n}\n\n// --- fetch and run the dev bundle.\nlet response: Response\ntry {\n response = await fetch(bundleUrl!)\n} catch {\n fail(`Metro dev server is not reachable (${bundleUrl}).`)\n throw new Error(\"unreachable\")\n}\nif (!response.ok) {\n fail(\n `Metro returned ${response.status} for the dev bundle:\\n${await response.text()}`,\n )\n}\nvm.runInThisContext(await response.text(), { filename: bundleUrl })\ninstallDevMenu()\n\n// --- HMR: metro-runtime's own client (ships with react-native).\ntype HmrErrorBody = { type?: string; message?: string }\ntype HmrClient = {\n send(message: string): void\n enable(): void\n on(event: string, listener: (body?: HmrErrorBody) => void): void\n}\nconst HMRClient = fromApp(\"metro-runtime/src/modules/HMRClient\") as new (\n url: string,\n) => HmrClient\nconst client = new HMRClient(\n bundleUrl!.replace(/^http/, \"ws\").replace(/\\/[^/]*$/, \"/hot\"),\n)\nclient.send(\n JSON.stringify({ type: \"register-entrypoints\", entryPoints: [bundleUrl] }),\n)\nclient.enable()\nclient.on(\"update-done\", () => {\n console.warn(\"[react-native-gtkx] hot update applied\")\n})\nclient.on(\"error\", (body) => {\n console.error(\n `[react-native-gtkx] Metro error (${body?.type ?? \"unknown\"}):\\n${body?.message ?? \"\"}`,\n )\n})\nclient.on(\"close\", () => {\n console.warn(\n \"[react-native-gtkx] HMR connection closed (the window keeps running without hot updates)\",\n )\n})\n"]}
|
|
1
|
+
{"version":3,"file":"host-dev.js","sourceRoot":"","sources":["../../src/runner/host-dev.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,uEAAuE;AACvE,oEAAoE;AACpE,0EAA0E;AAC1E,0EAA0E;AAC1E,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,wEAAwE;AACxE,oEAAoE;AACpE,qEAAqE;AACrE,yEAAyE;AACzE,iEAAiE;AACjE,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EACL,qBAAqB,EACrB,8BAA8B,GAC/B,MAAM,yBAAyB,CAAA;AAIhC,MAAM,IAAI,GAAG,CAAC,OAAe,EAAS,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAA;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAA;AAED,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE,CAAC;IACxC,IAAI,CACF,QAAQ,OAAO,CAAC,OAAO,gEAAgE,CACxF,CAAA;AACH,CAAC;AAED,wEAAwE;AACxE,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAA;AAE5D,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjC,IAAI,CAAC,SAAS,EAAE,CAAC;IACf,IAAI,CAAC,gDAAgD,CAAC,CAAA;AACxD,CAAC;AAED,0EAA0E;AAC1E,2EAA2E;AAC3E,2DAA2D;AAC3D,MAAM,OAAO,GAAG,aAAa,CAAC,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GAAG,CAAC,CAAA;AACvB,EAAE,CAAC,gBAAgB,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAA;AACnE,cAAc,EAAE,CAAA;AAShB,MAAM,SAAS,GAAG,OAAO,CAAC,qCAAqC,CAEjD,CAAA;AACd,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B,SAAU,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAC9D,CAAA;AACD,MAAM,CAAC,IAAI,CACT,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,WAAW,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAC3E,CAAA;AACD,MAAM,CAAC,MAAM,EAAE,CAAA;AACf,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE;IAC5B,OAAO,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAA;AACxD,CAAC,CAAC,CAAA;AACF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;IAC1B,OAAO,CAAC,KAAK,CACX,oCAAoC,IAAI,EAAE,IAAI,IAAI,SAAS,OAAO,IAAI,EAAE,OAAO,IAAI,EAAE,EAAE,CACxF,CAAA;AACH,CAAC,CAAC,CAAA;AACF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;IACtB,OAAO,CAAC,IAAI,CACV,0FAA0F,CAC3F,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// The DEV host: fetch the dev bundle from a Metro dev server, execute it,\n// subscribe to HMR updates and let react-refresh re-render through the\n// @gtkx/react reconciler with component state preserved. Spawned by\n// `run-linux --dev` as `node dist/runner/host-dev.js <bundle-url>`; exits\n// with code 65 when a full refresh is required — the supervisor restarts.\n//\n// Division of labor (validated by spike/rn-platform, FINDINGS-dev.md):\n// metro-runtime's dev require scopes the react-refresh registration per\n// module and applies hot updates once global.__ReactRefresh exists; its\n// HMRClient speaks the /hot websocket protocol verbatim over Node's\n// global WebSocket. This file only adds the dev pieces on top of the\n// release host (./host.ts — deliberately self-contained twins: both must\n// stay runnable under bare Node, so they cannot share a relative\n// extensionless import).\nimport { createRequire, registerHooks } from \"node:module\"\nimport { join } from \"node:path\"\nimport { pathToFileURL } from \"node:url\"\nimport vm from \"node:vm\"\nimport {\n HOST_MODULE_EXTERNALS,\n OPTIONAL_HOST_MODULE_EXTERNALS,\n} from \"react-native-gtkx/metro\"\n\ntype HostModule = Record<string, unknown>\n\nconst fail = (message: string): never => {\n console.error(`[react-native-gtkx] ${message}`)\n process.exit(1)\n}\n\nif (typeof registerHooks !== \"function\") {\n fail(\n `Node ${process.version} lacks module.registerHooks — the linux host needs Node >= 24.`,\n )\n}\n\n// react and the reconciler must run their DEV builds for react-refresh.\nprocess.env.NODE_ENV = process.env.NODE_ENV ?? \"development\"\n\nconst bundleUrl = process.argv[2]\nif (!bundleUrl) {\n fail(\"usage: node host-dev.js <metro-dev-bundle-url>\")\n}\n\n// Resolution anchors: react-refresh and metro-runtime ship with the APP's\n// react-native; @gtkx/* resolve as this package's dependencies; react must\n// be the exact instance the reconciler sees (see host.ts).\nconst fromApp = createRequire(join(process.cwd(), \"package.json\"))\nconst fromPackage = createRequire(import.meta.url)\nconst fromGtkxReact = createRequire(fromPackage.resolve(\"@gtkx/react\"))\n\n// --- react-refresh: inject BEFORE @gtkx/react loads (the reconciler\n// registers into the patched devtools hook).\nconst RefreshRuntime = fromApp(\"react-refresh/runtime\") as Record<\n string,\n unknown\n> & { injectIntoGlobalHook(target: unknown): void }\nRefreshRuntime.injectIntoGlobalHook(globalThis)\nglobalThis.$RefreshReg$ = () => {}\nglobalThis.$RefreshSig$ = () => (type: unknown) => type\nglobalThis.__ReactRefresh = {\n ...RefreshRuntime,\n performFullRefresh(reason: string) {\n console.warn(\n `[react-native-gtkx] full refresh required (${reason}) — restarting`,\n )\n process.exit(65)\n },\n}\n\n// --- virtual:gtkx-config (same mechanism and same module shape as the\n// release host — see host.ts for why each export is needed).\nconst CONFIG_REQUIRED =\n \"gtkx.config.ts with an applicationId is required in the app root \" +\n '(export default defineConfig({ applicationId: \"...\", libraries: [...] })).'\nconst { createConfigLoader } = await import(\n pathToFileURL(fromPackage.resolve(\"@gtkx/config/internal\")).href\n)\nconst gtkxConfig = await createConfigLoader()\n .resolve(process.cwd())\n .catch((error: unknown) => fail(`${CONFIG_REQUIRED}\\n${String(error)}`))\nif (!gtkxConfig.applicationId) {\n fail(CONFIG_REQUIRED)\n}\nif (gtkxConfig.elements !== null) {\n fail(\n \"gtkx.config.ts `elements.behaviors` is not supported on the linux \" +\n \"platform — react-native-gtkx owns element behaviors.\",\n )\n}\nconst configModuleUrl = new URL(\"./__virtual-gtkx-config.mjs\", import.meta.url)\n .href\nconst lazyElements = Object.fromEntries(\n gtkxConfig.lazyElements.map((type: string) => [type, { isLazy: true }]),\n)\nconst configModuleSource = [\n `export * from \"@gtkx/jsx/metadata\";`,\n `export const applicationId = ${JSON.stringify(gtkxConfig.applicationId)};`,\n `export const userEventSignals = ${JSON.stringify(gtkxConfig.userEventSignals)};`,\n `export const elements = ${JSON.stringify(lazyElements)};`,\n].join(\"\\n\")\nregisterHooks({\n resolve(specifier, context, nextResolve) {\n if (specifier === \"virtual:gtkx-config\") {\n return { url: configModuleUrl, shortCircuit: true }\n }\n return nextResolve(specifier, context)\n },\n load(url, context, nextLoad) {\n if (url === configModuleUrl) {\n return {\n format: \"module\",\n source: configModuleSource,\n shortCircuit: true,\n }\n }\n return nextLoad(url, context)\n },\n})\n\n// --- host modules (same interop merging as the release host).\nconst resolveExternal = (name: string): string =>\n name === \"react\" || name.startsWith(\"react/\")\n ? fromGtkxReact.resolve(name)\n : fromPackage.resolve(name)\n\nconst load = async (name: string): Promise<HostModule> => {\n const namespace: HostModule = await import(\n pathToFileURL(resolveExternal(name)).href\n )\n const merged: HostModule = { __esModule: true, ...namespace }\n if (!(\"default\" in namespace)) {\n merged.default = namespace\n }\n return merged\n}\n\nglobalThis.__hostModules = {}\nfor (const name of HOST_MODULE_EXTERNALS) {\n try {\n globalThis.__hostModules[name] = await load(name)\n } catch (error) {\n if (OPTIONAL_HOST_MODULE_EXTERNALS.has(name)) {\n // See host.ts's identical guard — expected on the plain-GTK profile.\n continue\n }\n fail(\n `failed to load host module \"${name}\" — is the codegen store in ` +\n `place (npx gtkx codegen) and GTK4/libadwaita installed?\\n${String(error)}`,\n )\n }\n}\nglobalThis.__hostRequire = createRequire(import.meta.url)\n\n// --- Dev Menu (Ctrl+Shift+D, the react-native-windows precedent).\n// Installed before the bundle runs so DevSettings.reload works from app\n// code; the key controller attaches once the app window exists.\nconst requestReload = (reason?: string): never => {\n console.warn(\n `[react-native-gtkx] reload requested${reason ? ` (${reason})` : \"\"} — restarting`,\n )\n return process.exit(65)\n}\nglobalThis.__rnGtkxDevHost = { reload: requestReload }\n\n// Structural slices of the GTK wrappers the menu touches — the host talks\n// to codegen namespaces through __hostModules, untyped by design.\ntype DevMenuWindow = { addController(controller: unknown): void }\ntype DevMenuDialog = {\n setHeading(heading: string): void\n setBody(body: string): void\n addResponse(id: string, label: string): void\n setResponseAppearance(id: string, appearance: unknown): void\n setDefaultResponse(id: string): void\n setCloseResponse(id: string): void\n choose(parent: DevMenuWindow): Promise<string>\n}\n\nconst installDevMenu = (): void => {\n const gtk = globalThis.__hostModules[\"@gtkx/gi/gtk\"] as {\n EventControllerKey: new () => {\n on(signal: string, handler: (...args: unknown[]) => unknown): void\n }\n }\n const gdk = globalThis.__hostModules[\"@gtkx/gi/gdk\"] as {\n ModifierType: { CONTROL_MASK: number; SHIFT_MASK: number }\n }\n const adw = globalThis.__hostModules[\"@gtkx/gi/adw\"] as {\n AlertDialog: new () => DevMenuDialog\n ResponseAppearance: { SUGGESTED: unknown }\n }\n const gio = globalThis.__hostModules[\"@gtkx/gi/gio\"] as {\n Application: {\n getDefault():\n { getActiveWindow?: () => DevMenuWindow | null } | null | undefined\n }\n }\n // GDK keysyms for latin letters equal their ASCII codes.\n const KEY_UPPER_D = 0x44\n const KEY_LOWER_D = 0x64\n\n let menuOpen = false\n const openDevMenu = async (window: DevMenuWindow): Promise<void> => {\n if (menuOpen) {\n return\n }\n menuOpen = true\n try {\n const items = globalThis.__rnGtkxDevMenuItems ?? []\n const dialog = new adw.AlertDialog()\n dialog.setHeading(\"React Native Dev Menu\")\n dialog.setBody(bundleUrl!)\n dialog.addResponse(\"cancel\", \"Cancel\")\n items.forEach((item, index) => {\n dialog.addResponse(`custom-${index}`, item.title)\n })\n dialog.addResponse(\"reload\", \"Reload\")\n dialog.setResponseAppearance(\"reload\", adw.ResponseAppearance.SUGGESTED)\n dialog.setDefaultResponse(\"reload\")\n dialog.setCloseResponse(\"cancel\")\n const response = await dialog.choose(window)\n if (response === \"reload\") {\n requestReload()\n }\n const custom = /^custom-(\\d+)$/.exec(response)\n if (custom) {\n items[Number(custom[1])]?.handler()\n }\n } catch (error) {\n console.error(`[react-native-gtkx] dev menu failed: ${String(error)}`)\n } finally {\n menuOpen = false\n }\n }\n\n const attach = (): void => {\n const window = gio.Application.getDefault()?.getActiveWindow?.()\n if (!window) {\n // The bundle opens the window asynchronously (application activate).\n setTimeout(attach, 200)\n return\n }\n const controller = new gtk.EventControllerKey()\n controller.on(\"key-pressed\", (keyval, _keycode, state) => {\n const modifiers = state as number\n const wanted =\n (modifiers & gdk.ModifierType.CONTROL_MASK) !== 0 &&\n (modifiers & gdk.ModifierType.SHIFT_MASK) !== 0 &&\n (keyval === KEY_UPPER_D || keyval === KEY_LOWER_D)\n if (wanted) {\n void openDevMenu(window)\n return true\n }\n return false\n })\n window.addController(controller)\n console.warn(\"[react-native-gtkx] dev menu ready (Ctrl+Shift+D)\")\n }\n attach()\n}\n\n// --- fetch and run the dev bundle.\nlet response: Response\ntry {\n response = await fetch(bundleUrl!)\n} catch {\n fail(`Metro dev server is not reachable (${bundleUrl}).`)\n throw new Error(\"unreachable\")\n}\nif (!response.ok) {\n fail(\n `Metro returned ${response.status} for the dev bundle:\\n${await response.text()}`,\n )\n}\n// 1.2-WORKAROUND(gtk-application-argv): same fix as host.ts — see that\n// file for the full explanation. Here argv[2] is the dev bundle URL, not\n// a file; strip it before the bundle mounts <GtkApplication> and its\n// effect reads process.argv.slice(2) as the GApplication command line.\nprocess.argv.length = 2\nvm.runInThisContext(await response.text(), { filename: bundleUrl })\ninstallDevMenu()\n\n// --- HMR: metro-runtime's own client (ships with react-native).\ntype HmrErrorBody = { type?: string; message?: string }\ntype HmrClient = {\n send(message: string): void\n enable(): void\n on(event: string, listener: (body?: HmrErrorBody) => void): void\n}\nconst HMRClient = fromApp(\"metro-runtime/src/modules/HMRClient\") as new (\n url: string,\n) => HmrClient\nconst client = new HMRClient(\n bundleUrl!.replace(/^http/, \"ws\").replace(/\\/[^/]*$/, \"/hot\"),\n)\nclient.send(\n JSON.stringify({ type: \"register-entrypoints\", entryPoints: [bundleUrl] }),\n)\nclient.enable()\nclient.on(\"update-done\", () => {\n console.warn(\"[react-native-gtkx] hot update applied\")\n})\nclient.on(\"error\", (body) => {\n console.error(\n `[react-native-gtkx] Metro error (${body?.type ?? \"unknown\"}):\\n${body?.message ?? \"\"}`,\n )\n})\nclient.on(\"close\", () => {\n console.warn(\n \"[react-native-gtkx] HMR connection closed (the window keeps running without hot updates)\",\n )\n})\n"]}
|
package/dist/runner/host.js
CHANGED
|
@@ -122,6 +122,21 @@ catch {
|
|
|
122
122
|
fail(`bundle not found at ${bundlePath} — run react-native run-linux.`);
|
|
123
123
|
throw new Error("unreachable");
|
|
124
124
|
}
|
|
125
|
+
// 1.2-WORKAROUND(gtk-application-argv): @gtkx/react's <GtkApplication>
|
|
126
|
+
// now builds the GApplication's own command line from
|
|
127
|
+
// `process.argv.slice(2)` (components/application.js, `runApplication`'s
|
|
128
|
+
// new argv parameter) and hands anything left over to GLib's local
|
|
129
|
+
// command-line handling, which treats stray positionals as files to
|
|
130
|
+
// open. This process's OWN positional argv[2] is our bundle path, not a
|
|
131
|
+
// user-facing argument — left in place it reaches GApplication as a
|
|
132
|
+
// "file" no app declares G_APPLICATION_HANDLES_OPEN for
|
|
133
|
+
// ("GLib-GIO-CRITICAL: This application can not open files"), and the
|
|
134
|
+
// window never activates. Truncate before the bundle (which mounts
|
|
135
|
+
// <GtkApplication> from an effect, so this always runs first) sees it.
|
|
136
|
+
// Removal condition: @gtkx/react exposes a way to pass runApplication's
|
|
137
|
+
// argv explicitly (an `argv` prop on <GtkApplication>, or an
|
|
138
|
+
// options object) instead of always reading process.argv itself.
|
|
139
|
+
process.argv.length = 2;
|
|
125
140
|
// The entry calls AppRegistry.runApplication itself (the react-native-web
|
|
126
141
|
// pattern); the GLib main loop keeps the process alive afterwards.
|
|
127
142
|
vm.runInThisContext(source, { filename: bundlePath });
|
package/dist/runner/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/runner/host.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,gDAAgD;AAChD,yEAAyE;AACzE,iDAAiD;AACjD,EAAE;AACF,0EAA0E;AAC1E,sEAAsE;AACtE,qDAAqD;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EACL,qBAAqB,EACrB,8BAA8B,GAC/B,MAAM,yBAAyB,CAAA;AAIhC,MAAM,IAAI,GAAG,CAAC,OAAe,EAAS,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAA;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAA;AAED,IAAI,OAAO,aAAa,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AY,CAAC,UAAW,EAAE,MAAM,CAAC,CAAA;AAC5C,CAAC;AAAC,MAAM,CAAC;IACP,IAAI,CAAC,uBAAuB,UAAU,gCAAgC,CAAC,CAAA;IACvE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;AAChC,CAAC;AACD,0EAA0E;AAC1E,mEAAmE;AACnE,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAA","sourcesContent":["// The Node+GTK host: executes a Metro jsbundle built for the linux\n// platform. Spawned by the run-linux command as\n// `node dist/runner/host.js <bundle>`; the bundle's externalized proxies\n// (see ../metro) read the modules injected here.\n//\n// This file must stay runnable under BARE Node: no extensionless relative\n// imports — only builtins, bare dependency specifiers and the package\n// self-reference (resolved through the exports map).\nimport { readFileSync } from \"node:fs\"\nimport { createRequire, registerHooks } from \"node:module\"\nimport { pathToFileURL } from \"node:url\"\nimport vm from \"node:vm\"\nimport {\n HOST_MODULE_EXTERNALS,\n OPTIONAL_HOST_MODULE_EXTERNALS,\n} from \"react-native-gtkx/metro\"\n\ntype HostModule = Record<string, unknown>\n\nconst fail = (message: string): never => {\n console.error(`[react-native-gtkx] ${message}`)\n process.exit(1)\n}\n\nif (typeof registerHooks !== \"function\") {\n fail(\n `Node ${process.version} lacks module.registerHooks — the linux host needs Node >= 24.`,\n )\n}\n\n// Resolution anchors. @gtkx/* and @gtkx/config resolve as THIS package's\n// dependencies; react resolves FROM @gtkx/react's real location — the\n// reconciler and the app must share one React instance, and anchoring at\n// the app could pick up a second copy installed by npm peer auto-install.\nconst fromPackage = createRequire(import.meta.url)\nconst fromGtkxReact = createRequire(fromPackage.resolve(\"@gtkx/react\"))\n\nconst resolveExternal = (name: string): string =>\n name === \"react\" || name.startsWith(\"react/\")\n ? fromGtkxReact.resolve(name)\n : fromPackage.resolve(name)\n\n// import() handles both ESM and CJS; merge a `default` for Babel's\n// default-import interop when the module has none of its own.\nconst load = async (name: string): Promise<HostModule> => {\n const namespace: HostModule = await import(\n pathToFileURL(resolveExternal(name)).href\n )\n const merged: HostModule = { __esModule: true, ...namespace }\n if (!(\"default\" in namespace)) {\n merged.default = namespace\n }\n return merged\n}\n\n// @gtkx/react imports `virtual:gtkx-config` — JSX metadata plus the values\n// resolved from gtkx.config.ts (applicationId for the GApplication, the\n// userEventSignals suppressed during commits and the elements config the\n// reconciler registry is primed with). In the vite path the gtkx CLI plugin\n// serves it; replicate it with a loader hook, mirroring @gtkx/config's own\n// renderConfigModule. The fake module URL is anchored inside this package so\n// the re-exported bare specifier resolves through node_modules.\nconst CONFIG_REQUIRED =\n \"gtkx.config.ts with an applicationId is required in the app root \" +\n '(export default defineConfig({ applicationId: \"...\", libraries: [...] })).'\nconst { createConfigLoader } = await import(\"@gtkx/config/internal\")\n// The loader validates the config, so a missing or malformed one throws.\n// rc.3 turned the loader from a bare function into `{ load, resolve }`;\n// `resolve` is the runtime projection this module needs.\nconst gtkxConfig = await createConfigLoader()\n .resolve(process.cwd())\n .catch((error: unknown) => fail(`${CONFIG_REQUIRED}\\n${String(error)}`))\nif (!gtkxConfig.applicationId) {\n fail(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, so no\n// app declares one — refuse rather than silently drop it.\nif (gtkxConfig.elements !== null) {\n fail(\n \"gtkx.config.ts `elements.behaviors` is not supported on the linux \" +\n \"platform — react-native-gtkx owns element behaviors.\",\n )\n}\nconst configModuleUrl = new URL(\"./__virtual-gtkx-config.mjs\", import.meta.url)\n .href\nconst lazyElements = Object.fromEntries(\n gtkxConfig.lazyElements.map((type) => [type, { isLazy: true }]),\n)\nconst configModuleSource = [\n `export * from \"@gtkx/jsx/metadata\";`,\n `export const applicationId = ${JSON.stringify(gtkxConfig.applicationId)};`,\n `export const userEventSignals = ${JSON.stringify(gtkxConfig.userEventSignals)};`,\n `export const elements = ${JSON.stringify(lazyElements)};`,\n].join(\"\\n\")\nregisterHooks({\n resolve(specifier, context, nextResolve) {\n if (specifier === \"virtual:gtkx-config\") {\n return { url: configModuleUrl, shortCircuit: true }\n }\n return nextResolve(specifier, context)\n },\n load(url, context, nextLoad) {\n if (url === configModuleUrl) {\n return {\n format: \"module\",\n source: configModuleSource,\n shortCircuit: true,\n }\n }\n return nextLoad(url, context)\n },\n})\n\nglobalThis.__hostModules = {}\nfor (const name of HOST_MODULE_EXTERNALS) {\n try {\n globalThis.__hostModules[name] = await load(name)\n } catch (error) {\n if (OPTIONAL_HOST_MODULE_EXTERNALS.has(name)) {\n // Expected and fine: this app's gtkx.config.ts never declared the GIR\n // library this module binds (e.g. \"Adw-1\" — the plain-GTK profile,\n // see .claude/epics/adw-optional/001.md). Left unset in\n // __hostModules; a feature that actually needs it throws its own\n // named error when it is reached, not here at startup.\n continue\n }\n fail(\n `failed to load host module \"${name}\" — is the codegen store in ` +\n `place (npx gtkx codegen) and GTK4/libadwaita installed?\\n${String(error)}`,\n )\n }\n}\n// Node builtin proxies resolve lazily through the host's own require.\nglobalThis.__hostRequire = createRequire(import.meta.url)\n\nconst bundlePath = process.argv[2]\nif (!bundlePath) {\n fail(\"usage: node host.js <path/to/main.jsbundle>\")\n}\nlet source: string\ntry {\n source = readFileSync(bundlePath!, \"utf8\")\n} catch {\n fail(`bundle not found at ${bundlePath} — run react-native run-linux.`)\n throw new Error(\"unreachable\")\n}\n// The entry calls AppRegistry.runApplication itself (the react-native-web\n// pattern); the GLib main loop keeps the process alive afterwards.\nvm.runInThisContext(source, { filename: bundlePath })\n"]}
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/runner/host.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,gDAAgD;AAChD,yEAAyE;AACzE,iDAAiD;AACjD,EAAE;AACF,0EAA0E;AAC1E,sEAAsE;AACtE,qDAAqD;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,aAAa,E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,MAAM,CAAC,KAAK,CAAC,EAAE,CAC9E,CAAA;IACH,CAAC;AACH,CAAC;AACD,sEAAsE;AACtE,UAAU,CAAC,aAAa,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAEzD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAClC,IAAI,CAAC,UAAU,EAAE,CAAC;IAChB,IAAI,CAAC,6CAA6C,CAAC,CAAA;AACrD,CAAC;AACD,IAAI,MAAc,CAAA;AAClB,IAAI,CAAC;IACH,MAAM,GAAG,YAAY,CAAC,UAAW,EAAE,MAAM,CAAC,CAAA;AAC5C,CAAC;AAAC,MAAM,CAAC;IACP,IAAI,CAAC,uBAAuB,UAAU,gCAAgC,CAAC,CAAA;IACvE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;AAChC,CAAC;AACD,uEAAuE;AACvE,sDAAsD;AACtD,yEAAyE;AACzE,mEAAmE;AACnE,oEAAoE;AACpE,wEAAwE;AACxE,oEAAoE;AACpE,wDAAwD;AACxD,sEAAsE;AACtE,mEAAmE;AACnE,uEAAuE;AACvE,wEAAwE;AACxE,6DAA6D;AAC7D,iEAAiE;AACjE,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;AACvB,0EAA0E;AAC1E,mEAAmE;AACnE,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAA","sourcesContent":["// The Node+GTK host: executes a Metro jsbundle built for the linux\n// platform. Spawned by the run-linux command as\n// `node dist/runner/host.js <bundle>`; the bundle's externalized proxies\n// (see ../metro) read the modules injected here.\n//\n// This file must stay runnable under BARE Node: no extensionless relative\n// imports — only builtins, bare dependency specifiers and the package\n// self-reference (resolved through the exports map).\nimport { readFileSync } from \"node:fs\"\nimport { createRequire, registerHooks } from \"node:module\"\nimport { pathToFileURL } from \"node:url\"\nimport vm from \"node:vm\"\nimport {\n HOST_MODULE_EXTERNALS,\n OPTIONAL_HOST_MODULE_EXTERNALS,\n} from \"react-native-gtkx/metro\"\n\ntype HostModule = Record<string, unknown>\n\nconst fail = (message: string): never => {\n console.error(`[react-native-gtkx] ${message}`)\n process.exit(1)\n}\n\nif (typeof registerHooks !== \"function\") {\n fail(\n `Node ${process.version} lacks module.registerHooks — the linux host needs Node >= 24.`,\n )\n}\n\n// Resolution anchors. @gtkx/* and @gtkx/config resolve as THIS package's\n// dependencies; react resolves FROM @gtkx/react's real location — the\n// reconciler and the app must share one React instance, and anchoring at\n// the app could pick up a second copy installed by npm peer auto-install.\nconst fromPackage = createRequire(import.meta.url)\nconst fromGtkxReact = createRequire(fromPackage.resolve(\"@gtkx/react\"))\n\nconst resolveExternal = (name: string): string =>\n name === \"react\" || name.startsWith(\"react/\")\n ? fromGtkxReact.resolve(name)\n : fromPackage.resolve(name)\n\n// import() handles both ESM and CJS; merge a `default` for Babel's\n// default-import interop when the module has none of its own.\nconst load = async (name: string): Promise<HostModule> => {\n const namespace: HostModule = await import(\n pathToFileURL(resolveExternal(name)).href\n )\n const merged: HostModule = { __esModule: true, ...namespace }\n if (!(\"default\" in namespace)) {\n merged.default = namespace\n }\n return merged\n}\n\n// @gtkx/react imports `virtual:gtkx-config` — JSX metadata plus the values\n// resolved from gtkx.config.ts (applicationId for the GApplication, the\n// userEventSignals suppressed during commits and the elements config the\n// reconciler registry is primed with). In the vite path the gtkx CLI plugin\n// serves it; replicate it with a loader hook, mirroring @gtkx/config's own\n// renderConfigModule. The fake module URL is anchored inside this package so\n// the re-exported bare specifier resolves through node_modules.\nconst CONFIG_REQUIRED =\n \"gtkx.config.ts with an applicationId is required in the app root \" +\n '(export default defineConfig({ applicationId: \"...\", libraries: [...] })).'\nconst { createConfigLoader } = await import(\"@gtkx/config/internal\")\n// The loader validates the config, so a missing or malformed one throws.\n// rc.3 turned the loader from a bare function into `{ load, resolve }`;\n// `resolve` is the runtime projection this module needs.\nconst gtkxConfig = await createConfigLoader()\n .resolve(process.cwd())\n .catch((error: unknown) => fail(`${CONFIG_REQUIRED}\\n${String(error)}`))\nif (!gtkxConfig.applicationId) {\n fail(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, so no\n// app declares one — refuse rather than silently drop it.\nif (gtkxConfig.elements !== null) {\n fail(\n \"gtkx.config.ts `elements.behaviors` is not supported on the linux \" +\n \"platform — react-native-gtkx owns element behaviors.\",\n )\n}\nconst configModuleUrl = new URL(\"./__virtual-gtkx-config.mjs\", import.meta.url)\n .href\nconst lazyElements = Object.fromEntries(\n gtkxConfig.lazyElements.map((type) => [type, { isLazy: true }]),\n)\nconst configModuleSource = [\n `export * from \"@gtkx/jsx/metadata\";`,\n `export const applicationId = ${JSON.stringify(gtkxConfig.applicationId)};`,\n `export const userEventSignals = ${JSON.stringify(gtkxConfig.userEventSignals)};`,\n `export const elements = ${JSON.stringify(lazyElements)};`,\n].join(\"\\n\")\nregisterHooks({\n resolve(specifier, context, nextResolve) {\n if (specifier === \"virtual:gtkx-config\") {\n return { url: configModuleUrl, shortCircuit: true }\n }\n return nextResolve(specifier, context)\n },\n load(url, context, nextLoad) {\n if (url === configModuleUrl) {\n return {\n format: \"module\",\n source: configModuleSource,\n shortCircuit: true,\n }\n }\n return nextLoad(url, context)\n },\n})\n\nglobalThis.__hostModules = {}\nfor (const name of HOST_MODULE_EXTERNALS) {\n try {\n globalThis.__hostModules[name] = await load(name)\n } catch (error) {\n if (OPTIONAL_HOST_MODULE_EXTERNALS.has(name)) {\n // Expected and fine: this app's gtkx.config.ts never declared the GIR\n // library this module binds (e.g. \"Adw-1\" — the plain-GTK profile,\n // see .claude/epics/adw-optional/001.md). Left unset in\n // __hostModules; a feature that actually needs it throws its own\n // named error when it is reached, not here at startup.\n continue\n }\n fail(\n `failed to load host module \"${name}\" — is the codegen store in ` +\n `place (npx gtkx codegen) and GTK4/libadwaita installed?\\n${String(error)}`,\n )\n }\n}\n// Node builtin proxies resolve lazily through the host's own require.\nglobalThis.__hostRequire = createRequire(import.meta.url)\n\nconst bundlePath = process.argv[2]\nif (!bundlePath) {\n fail(\"usage: node host.js <path/to/main.jsbundle>\")\n}\nlet source: string\ntry {\n source = readFileSync(bundlePath!, \"utf8\")\n} catch {\n fail(`bundle not found at ${bundlePath} — run react-native run-linux.`)\n throw new Error(\"unreachable\")\n}\n// 1.2-WORKAROUND(gtk-application-argv): @gtkx/react's <GtkApplication>\n// now builds the GApplication's own command line from\n// `process.argv.slice(2)` (components/application.js, `runApplication`'s\n// new argv parameter) and hands anything left over to GLib's local\n// command-line handling, which treats stray positionals as files to\n// open. This process's OWN positional argv[2] is our bundle path, not a\n// user-facing argument — left in place it reaches GApplication as a\n// \"file\" no app declares G_APPLICATION_HANDLES_OPEN for\n// (\"GLib-GIO-CRITICAL: This application can not open files\"), and the\n// window never activates. Truncate before the bundle (which mounts\n// <GtkApplication> from an effect, so this always runs first) sees it.\n// Removal condition: @gtkx/react exposes a way to pass runApplication's\n// argv explicitly (an `argv` prop on <GtkApplication>, or an\n// options object) instead of always reading process.argv itself.\nprocess.argv.length = 2\n// The entry calls AppRegistry.runApplication itself (the react-native-web\n// pattern); the GLib main loop keeps the process alive afterwards.\nvm.runInThisContext(source, { filename: bundlePath })\n"]}
|
package/dist/runner/index.d.ts
CHANGED
|
@@ -15,6 +15,20 @@ type BuildLinuxArgs = {
|
|
|
15
15
|
sea?: boolean;
|
|
16
16
|
seaOutput?: string;
|
|
17
17
|
};
|
|
18
|
+
type DeployLinuxArgs = {
|
|
19
|
+
entryFile: string;
|
|
20
|
+
target?: string;
|
|
21
|
+
out?: string;
|
|
22
|
+
printManifests?: boolean;
|
|
23
|
+
skipBuild?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/** Vite's own convention for "this directory is a vite project" — every
|
|
26
|
+
* vite-path example in this repo (gallery, monitor, tasks-app, tasks-nav)
|
|
27
|
+
* has exactly one of these at its root, and no Metro app does (hn-app and
|
|
28
|
+
* rn-app have `metro.config.js` and a root `index.js` instead). Exported so
|
|
29
|
+
* the detection itself is unit-testable without spawning anything. */
|
|
30
|
+
export declare const VITE_CONFIG_CANDIDATES: string[];
|
|
31
|
+
export declare const isViteProject: (root: string) => boolean;
|
|
18
32
|
/** Commands contributed to the RN CLI by the package's react-native.config.js. */
|
|
19
33
|
export declare const commands: ({
|
|
20
34
|
name: string;
|
|
@@ -42,5 +56,18 @@ export declare const commands: ({
|
|
|
42
56
|
default?: undefined;
|
|
43
57
|
})[];
|
|
44
58
|
func: (_argv: string[], config: CliConfig, args: BuildLinuxArgs) => Promise<void>;
|
|
59
|
+
} | {
|
|
60
|
+
name: string;
|
|
61
|
+
description: string;
|
|
62
|
+
options: ({
|
|
63
|
+
name: string;
|
|
64
|
+
description: string;
|
|
65
|
+
default: string;
|
|
66
|
+
} | {
|
|
67
|
+
name: string;
|
|
68
|
+
description: string;
|
|
69
|
+
default?: undefined;
|
|
70
|
+
})[];
|
|
71
|
+
func: (_argv: string[], config: CliConfig, args: DeployLinuxArgs) => Promise<void>;
|
|
45
72
|
})[];
|
|
46
73
|
export {};
|
package/dist/runner/index.js
CHANGED
|
@@ -9,12 +9,16 @@
|
|
|
9
9
|
// Like the hosts, this module must stay runnable under bare Node:
|
|
10
10
|
// builtins and bare specifiers only.
|
|
11
11
|
import { spawn, spawnSync } from "node:child_process";
|
|
12
|
-
import { mkdirSync } from "node:fs";
|
|
12
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { createRequire } from "node:module";
|
|
14
14
|
import { basename, dirname, extname, join } from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
16
|
/** Exit code host-dev.ts uses to request a supervisor restart. */
|
|
17
17
|
const FULL_REFRESH_EXIT_CODE = 65;
|
|
18
|
+
const fail = (message) => {
|
|
19
|
+
console.error(`[react-native-gtkx] ${message}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
};
|
|
18
22
|
const run = (command, args, cwd) => {
|
|
19
23
|
const result = spawnSync(command, args, { cwd, stdio: "inherit" });
|
|
20
24
|
return result.status ?? 1;
|
|
@@ -269,6 +273,179 @@ const buildLinux = async (_argv, config, args) => {
|
|
|
269
273
|
: `[react-native-gtkx] wrote the standalone script to ${seaOutput} ` +
|
|
270
274
|
`(${megabytes} MB — run it with \`node ${seaOutput}\`)`);
|
|
271
275
|
};
|
|
276
|
+
// `deploy-linux`: `npx gtkx deploy` packages a project's `dist/` into
|
|
277
|
+
// .deb/.rpm/.AppImage/.flatpak, but it is vite-shaped by construction — its
|
|
278
|
+
// payload stager (@gtkx/cli's stagePayload) unconditionally requires
|
|
279
|
+
// `dist/bundle.mjs` and copies the rest of `dist/` verbatim, `--skip-build`
|
|
280
|
+
// included. A Metro app never produces that file (Metro externalizes
|
|
281
|
+
// @gtkx/*/react/yoga-layout instead of inlining them — see ../metro's
|
|
282
|
+
// HOST_MODULE_EXTERNALS), so `gtkx deploy` cannot package one on its own.
|
|
283
|
+
// This command is the bridge: on the vite path it is a thin proxy (the app
|
|
284
|
+
// already looks exactly like what `gtkx deploy` expects); on the Metro path
|
|
285
|
+
// it builds a real Metro release, reshapes that build into the same
|
|
286
|
+
// dist/bundle.mjs shape a vite build would have produced, and only then
|
|
287
|
+
// calls into `gtkx deploy --skip-build`.
|
|
288
|
+
//
|
|
289
|
+
// Registered the same way as run-linux/build-linux (react-native.config.js),
|
|
290
|
+
// so the RN CLI exposes it to every app that depends on react-native-gtkx —
|
|
291
|
+
// regardless of which toolchain that particular app actually builds with:
|
|
292
|
+
// `npx react-native config` from a vite-path example already lists
|
|
293
|
+
// run-linux/build-linux today (confirmed against examples/monitor, which has
|
|
294
|
+
// no `react-native` dependency of its own — the command surface comes along
|
|
295
|
+
// because react-native-gtkx is a dependency, and this workspace happens to
|
|
296
|
+
// hoist `react-native` where every example's own `npx` lookup can still find
|
|
297
|
+
// it). So this command has to tell the two toolchains apart itself; neither
|
|
298
|
+
// run-linux nor build-linux do that today (they are Metro-only by
|
|
299
|
+
// construction), so there is no existing helper to reuse — see
|
|
300
|
+
// isViteProject below for the detection this command invents.
|
|
301
|
+
/** Every extension `gtkx.config.ts` is allowed to use (c12's own candidate
|
|
302
|
+
* list, mirrored rather than imported since @gtkx/config does not export
|
|
303
|
+
* it) — used only for the friendlier "you're missing one" error below;
|
|
304
|
+
* @gtkx/config's own loader remains the actual authority. */
|
|
305
|
+
const GTKX_CONFIG_CANDIDATES = ["ts", "js", "mjs", "cjs", "mts", "cts"].map((extension) => `gtkx.config.${extension}`);
|
|
306
|
+
const hasGtkxConfig = (root) => GTKX_CONFIG_CANDIDATES.some((name) => existsSync(join(root, name)));
|
|
307
|
+
/** Vite's own convention for "this directory is a vite project" — every
|
|
308
|
+
* vite-path example in this repo (gallery, monitor, tasks-app, tasks-nav)
|
|
309
|
+
* has exactly one of these at its root, and no Metro app does (hn-app and
|
|
310
|
+
* rn-app have `metro.config.js` and a root `index.js` instead). Exported so
|
|
311
|
+
* the detection itself is unit-testable without spawning anything. */
|
|
312
|
+
export const VITE_CONFIG_CANDIDATES = [
|
|
313
|
+
"vite.config.ts",
|
|
314
|
+
"vite.config.js",
|
|
315
|
+
"vite.config.mjs",
|
|
316
|
+
"vite.config.mts",
|
|
317
|
+
];
|
|
318
|
+
export const isViteProject = (root) => VITE_CONFIG_CANDIDATES.some((name) => existsSync(join(root, name)));
|
|
319
|
+
/** `--target`/`--out`/`--print-manifests` — passed through unchanged to
|
|
320
|
+
* `gtkx deploy` on both paths. `--skip-build` is handled separately by each
|
|
321
|
+
* path below: it means something different on each (see deployLinuxMetro). */
|
|
322
|
+
const commonDeployArgs = (args) => {
|
|
323
|
+
const passthrough = [];
|
|
324
|
+
if (args.target !== undefined) {
|
|
325
|
+
passthrough.push("--target", args.target);
|
|
326
|
+
}
|
|
327
|
+
if (args.out !== undefined) {
|
|
328
|
+
passthrough.push("--out", args.out);
|
|
329
|
+
}
|
|
330
|
+
if (args.printManifests) {
|
|
331
|
+
passthrough.push("--print-manifests");
|
|
332
|
+
}
|
|
333
|
+
return passthrough;
|
|
334
|
+
};
|
|
335
|
+
const runGtkxDeploy = (root, args) => {
|
|
336
|
+
const appRequire = createRequire(join(root, "package.json"));
|
|
337
|
+
return run(process.execPath, [binOf(appRequire, "@gtkx/cli", "gtkx"), "deploy", ...args], root);
|
|
338
|
+
};
|
|
339
|
+
// The vite path IS what `gtkx deploy` already expects — no build of ours to
|
|
340
|
+
// run, no staging to do. A missing gtkx.config.ts or `deploy` block surfaces
|
|
341
|
+
// through gtkx's own error (stdio is inherited below), which already names
|
|
342
|
+
// exactly what to add and where (a ready-to-paste `deploy` block derived
|
|
343
|
+
// from package.json for the latter).
|
|
344
|
+
const deployLinuxVite = (config, args) => {
|
|
345
|
+
const gtkxArgs = [
|
|
346
|
+
...commonDeployArgs(args),
|
|
347
|
+
...(args.skipBuild ? ["--skip-build"] : []),
|
|
348
|
+
];
|
|
349
|
+
process.exit(runGtkxDeploy(config.root, gtkxArgs));
|
|
350
|
+
};
|
|
351
|
+
const DEPLOY_SCRATCH_BUNDLE = "deploy.jsbundle";
|
|
352
|
+
/**
|
|
353
|
+
* Reshapes a Metro build into the one file `gtkx deploy --skip-build`
|
|
354
|
+
* actually checks for (`dist/bundle.mjs`) plus whatever it needs beside it,
|
|
355
|
+
* by reusing --standalone's own bundler rather than inventing a second one:
|
|
356
|
+
* bundleStandalone already produces a single self-contained CJS file with
|
|
357
|
+
* the whole HOST_MODULE_EXTERNALS closure AND the native addon (as a
|
|
358
|
+
* base64 literal, extracted to a per-user cache on first run) inlined — see
|
|
359
|
+
* ../sea/native-shim.ts. That statically satisfies everything a vite build's
|
|
360
|
+
* dist/bundle.mjs would otherwise need a separate dist/gtkx.node for.
|
|
361
|
+
*
|
|
362
|
+
* The one thing it is NOT is an ES module — rolldown emits it as CJS (see
|
|
363
|
+
* ../sea/bundle.ts's header for why: a Node SEA's main script is forced to
|
|
364
|
+
* CJS, and --standalone shares that bundler). `dist/bundle.mjs` cannot just
|
|
365
|
+
* be that file under a different name: Node parses a `.mjs` file as ESM
|
|
366
|
+
* unconditionally, and `module.exports = …`/bare `require(…)` are
|
|
367
|
+
* ReferenceErrors there. So this writes the real artifact under its own
|
|
368
|
+
* name and a two-line ESM shim at dist/bundle.mjs that hands off to it via
|
|
369
|
+
* `createRequire` — synchronous, so no top-level await, and it resolves
|
|
370
|
+
* "./<name>.cjs" from its OWN location (import.meta.url), which is exactly
|
|
371
|
+
* where stagePayload copies it (both files land in the same directory,
|
|
372
|
+
* `lib/<binaryName>/`), regardless of the installed package's cwd.
|
|
373
|
+
*/
|
|
374
|
+
const stageMetroDeployDist = async (root, entryFile) => {
|
|
375
|
+
const scratchDir = join(root, "node_modules", ".react-native-gtkx");
|
|
376
|
+
mkdirSync(scratchDir, { recursive: true });
|
|
377
|
+
const jsbundlePath = join(scratchDir, DEPLOY_SCRATCH_BUNDLE);
|
|
378
|
+
bundle(root, entryFile, jsbundlePath);
|
|
379
|
+
const distDir = join(root, "dist");
|
|
380
|
+
// Cleared, not merged into: gtkx deploy stages every file it finds under
|
|
381
|
+
// dist/ (barring an icons/ dir and its own build metadata), so a stale
|
|
382
|
+
// main.jsbundle or a previous run's artifacts left over from a plain
|
|
383
|
+
// `build-linux` would otherwise ship inside the package too.
|
|
384
|
+
rmSync(distDir, { recursive: true, force: true });
|
|
385
|
+
mkdirSync(distDir, { recursive: true });
|
|
386
|
+
const name = appBinaryName(root);
|
|
387
|
+
const standaloneOutput = join(distDir, `${name}.cjs`);
|
|
388
|
+
const { bundleStandalone } = await import("../sea/assemble.js");
|
|
389
|
+
await bundleStandalone({
|
|
390
|
+
appRoot: root,
|
|
391
|
+
jsbundlePath,
|
|
392
|
+
outFile: standaloneOutput,
|
|
393
|
+
// gtkx deploy's third-party-notices step reads dist/gtkx-packages.json
|
|
394
|
+
// unconditionally (--skip-build included) — see bundleStandalone's own
|
|
395
|
+
// comment for why this is the one flag deploy-linux passes that
|
|
396
|
+
// build-linux --standalone never does.
|
|
397
|
+
shouldWritePackageManifest: true,
|
|
398
|
+
});
|
|
399
|
+
writeFileSync(join(distDir, "bundle.mjs"), [
|
|
400
|
+
"// Generated by `react-native deploy-linux` — do not edit by hand.",
|
|
401
|
+
"// gtkx deploy's payload stager only recognizes a vite-shaped",
|
|
402
|
+
`// dist/bundle.mjs; this hands off to the real Metro-built artifact`,
|
|
403
|
+
`// next to it (${name}.cjs, which inlines the whole runtime closure`,
|
|
404
|
+
"// and the native addon — see stageMetroDeployDist in",
|
|
405
|
+
"// react-native-gtkx/runner for the full explanation).",
|
|
406
|
+
'import { createRequire } from "node:module"',
|
|
407
|
+
"",
|
|
408
|
+
`createRequire(import.meta.url)(${JSON.stringify(`./${name}.cjs`)})`,
|
|
409
|
+
"",
|
|
410
|
+
].join("\n"));
|
|
411
|
+
console.warn(`[react-native-gtkx] staged a vite-shaped dist/ at ${distDir}`);
|
|
412
|
+
return distDir;
|
|
413
|
+
};
|
|
414
|
+
const deployLinuxMetro = async (config, args) => {
|
|
415
|
+
const root = config.root;
|
|
416
|
+
if (!hasGtkxConfig(root)) {
|
|
417
|
+
fail(`no gtkx.config.ts found at ${root} — deploy-linux needs one on the ` +
|
|
418
|
+
"Metro path too (the same file the codegen store already " +
|
|
419
|
+
"requires), exporting a `deploy` block from defineConfig(). See " +
|
|
420
|
+
"docs/guide/packaging.md.");
|
|
421
|
+
}
|
|
422
|
+
const distBundle = join(root, "dist", "bundle.mjs");
|
|
423
|
+
if (args.skipBuild) {
|
|
424
|
+
if (!existsSync(distBundle)) {
|
|
425
|
+
fail(`--skip-build was given but ${distBundle} does not exist yet — ` +
|
|
426
|
+
"run deploy-linux without --skip-build at least once first.");
|
|
427
|
+
}
|
|
428
|
+
console.warn("[react-native-gtkx] --skip-build: reusing the already-staged dist/");
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
await ensureCodegenStore(root);
|
|
432
|
+
await stageMetroDeployDist(root, args.entryFile);
|
|
433
|
+
}
|
|
434
|
+
// gtkx deploy's own entry resolution runs unconditionally (even with
|
|
435
|
+
// --skip-build), and its default (src/index.{tsx,jsx,ts,js}) is the vite
|
|
436
|
+
// convention, not Metro's — pass the Metro entry file through explicitly
|
|
437
|
+
// so it resolves, even though the value itself goes unused once staging
|
|
438
|
+
// is skipped.
|
|
439
|
+
const gtkxArgs = ["--skip-build", ...commonDeployArgs(args), args.entryFile];
|
|
440
|
+
process.exit(runGtkxDeploy(root, gtkxArgs));
|
|
441
|
+
};
|
|
442
|
+
const deployLinux = async (_argv, config, args) => {
|
|
443
|
+
if (isViteProject(config.root)) {
|
|
444
|
+
deployLinuxVite(config, args);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
await deployLinuxMetro(config, args);
|
|
448
|
+
};
|
|
272
449
|
/** Commands contributed to the RN CLI by the package's react-native.config.js. */
|
|
273
450
|
export const commands = [
|
|
274
451
|
{
|
|
@@ -331,5 +508,33 @@ export const commands = [
|
|
|
331
508
|
],
|
|
332
509
|
func: buildLinux,
|
|
333
510
|
},
|
|
511
|
+
{
|
|
512
|
+
name: "deploy-linux",
|
|
513
|
+
description: "Package the app for distribution (.deb/.rpm/.AppImage/.flatpak) — vite path proxies `gtkx deploy`, Metro path builds and stages first",
|
|
514
|
+
options: [
|
|
515
|
+
{
|
|
516
|
+
name: "--entry-file <path>",
|
|
517
|
+
description: "Path to the app entry file (Metro path only)",
|
|
518
|
+
default: "index.js",
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: "--target <formats>",
|
|
522
|
+
description: "Comma-separated package formats to build (deb, rpm, appimage, flatpak)",
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: "--out <path>",
|
|
526
|
+
description: "Output directory relative to the project root (default: build)",
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
name: "--print-manifests",
|
|
530
|
+
description: "Write the generated desktop-entry/AppStream metadata, then stop without packaging",
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
name: "--skip-build",
|
|
534
|
+
description: "Package the already-staged dist/ instead of rebuilding (vite: passed through to `gtkx deploy`; Metro: also skips this command's own staging)",
|
|
535
|
+
},
|
|
536
|
+
],
|
|
537
|
+
func: deployLinux,
|
|
538
|
+
},
|
|
334
539
|
];
|
|
335
540
|
//# sourceMappingURL=index.js.map
|