react-native-gtkx 0.4.0-alpha.2 → 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.
Files changed (63) hide show
  1. package/README.md +35 -96
  2. package/dist/adw/index.js +3 -2
  3. package/dist/adw/index.js.map +1 -1
  4. package/dist/apis/host.gtkx.js.map +1 -1
  5. package/dist/components/modal.d.ts +1 -1
  6. package/dist/components/modal.js +16 -8
  7. package/dist/components/modal.js.map +1 -1
  8. package/dist/dnd/gtk-controllers.js +1 -1
  9. package/dist/dnd/gtk-controllers.js.map +1 -1
  10. package/dist/gtk/index.js +4 -3
  11. package/dist/gtk/index.js.map +1 -1
  12. package/dist/gtkx/bridge/adw.js +1 -1
  13. package/dist/gtkx/bridge/adw.js.map +1 -1
  14. package/dist/gtkx/bridge/core.d.ts +1 -2
  15. package/dist/gtkx/bridge/core.js +2 -5
  16. package/dist/gtkx/bridge/core.js.map +1 -1
  17. package/dist/gtkx/bridge/geometry.js +1 -1
  18. package/dist/gtkx/bridge/geometry.js.map +1 -1
  19. package/dist/gtkx/bridge/layout-manager.js +18 -5
  20. package/dist/gtkx/bridge/layout-manager.js.map +1 -1
  21. package/dist/gtkx/bridge/slot-portal.js.map +1 -1
  22. package/dist/gtkx/bridge/svg-node.js +13 -6
  23. package/dist/gtkx/bridge/svg-node.js.map +1 -1
  24. package/dist/gtkx/bridge/view-box.js +19 -10
  25. package/dist/gtkx/bridge/view-box.js.map +1 -1
  26. package/dist/gtkx/bridge/widgets.generated.adw.js +1 -1
  27. package/dist/gtkx/bridge/widgets.generated.adw.js.map +1 -1
  28. package/dist/mcp/bin.js +1 -1
  29. package/dist/mcp/bin.js.map +1 -1
  30. package/dist/mcp/data/generated.d.ts +860 -531
  31. package/dist/mcp/data/generated.js +952 -538
  32. package/dist/mcp/data/generated.js.map +1 -1
  33. package/dist/mcp/resolve.d.ts +2 -2
  34. package/dist/mcp/resolve.js +2 -2
  35. package/dist/mcp/resolve.js.map +1 -1
  36. package/dist/mcp/server.js +2 -2
  37. package/dist/mcp/server.js.map +1 -1
  38. package/dist/runner/host-dev.js +5 -0
  39. package/dist/runner/host-dev.js.map +1 -1
  40. package/dist/runner/host.js +15 -0
  41. package/dist/runner/host.js.map +1 -1
  42. package/dist/runner/index.d.ts +27 -0
  43. package/dist/runner/index.js +206 -1
  44. package/dist/runner/index.js.map +1 -1
  45. package/dist/sea/assemble.d.ts +9 -0
  46. package/dist/sea/assemble.js +16 -3
  47. package/dist/sea/assemble.js.map +1 -1
  48. package/dist/sea/bundle.d.ts +37 -2
  49. package/dist/sea/bundle.js +77 -5
  50. package/dist/sea/bundle.js.map +1 -1
  51. package/dist/sea/native-shim.js +4 -3
  52. package/dist/sea/native-shim.js.map +1 -1
  53. package/dist/testing/index.js +28 -0
  54. package/dist/testing/index.js.map +1 -1
  55. package/dist/vite/index.js +3 -3
  56. package/dist/vite/index.js.map +1 -1
  57. package/dist/vitest/index.d.ts +2 -2
  58. package/dist/vitest/index.js +1 -1
  59. package/dist/vitest/index.js.map +1 -1
  60. package/package.json +9 -9
  61. package/dist/gtkx/bridge/use-signal.d.ts +0 -2
  62. package/dist/gtkx/bridge/use-signal.js +0 -41
  63. package/dist/gtkx/bridge/use-signal.js.map +0 -1
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runner/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,2EAA2E;AAC3E,yEAAyE;AACzE,uEAA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;gBACvB,WAAW,EAAE,8CAA8C;aAC5D;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,WAAW,EACT,oFAAoF;aACvF;YACD;gBACE,IAAI,EAAE,iBAAiB;gBACvB,WAAW,EAAE,iDAAiD;aAC/D;SACF;QACD,IAAI,EAAE,QAAQ;KACf;IACD;QACE,IAAI,EAAE,aAAa;QACnB,WAAW,EACT,uFAAuF;QACzF,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,qBAAqB;gBAC3B,WAAW,EAAE,4BAA4B;gBACzC,OAAO,EAAE,UAAU;aACpB;YACD;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,WAAW,EACT,mEAAmE;aACtE;YACD;gBACE,IAAI,EAAE,cAAc;gBACpB,WAAW,EACT,iEAAiE;oBACjE,8CAA8C;aACjD;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,WAAW,EACT,kEAAkE;oBAClE,2DAA2D;oBAC3D,wCAAwC;aAC3C;YACD;gBACE,IAAI,EAAE,qBAAqB;gBAC3B,WAAW,EACT,mDAAmD;oBACnD,sCAAsC;aACzC;SACF;QACD,IAAI,EAAE,UAAU;KACjB;CACF,CAAA","sourcesContent":["// The `run-linux` CLI command (registered through the package's\n// react-native.config.js, the react-native-windows model): ensure the gtkx\n// codegen store, then either build a release jsbundle with Metro and run\n// it in the Node+GTK host (./host.ts), or — with --dev — start/reuse a\n// Metro dev server and supervise the DEV host (./host-dev.ts): Fast\n// Refresh applies edits to the live window, and a full-refresh request\n// (exit code 65) restarts the host process.\n//\n// Like the hosts, this module must stay runnable under bare Node:\n// builtins and bare specifiers only.\nimport { spawn, spawnSync, type ChildProcess } from \"node:child_process\"\nimport { mkdirSync } from \"node:fs\"\nimport { createRequire } from \"node:module\"\nimport { basename, dirname, extname, join } from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\n\ntype CliConfig = { root: string }\ntype RunLinuxArgs = {\n entryFile: string\n bundleOutput?: string\n skipBundling?: boolean\n dev?: boolean\n port?: string\n}\ntype BuildLinuxArgs = {\n entryFile: string\n bundleOutput?: string\n standalone?: boolean\n sea?: boolean\n seaOutput?: string\n}\n\n/** Exit code host-dev.ts uses to request a supervisor restart. */\nconst FULL_REFRESH_EXIT_CODE = 65\n\nconst run = (command: string, args: string[], cwd: string): number => {\n const result = spawnSync(command, args, { cwd, stdio: \"inherit\" })\n return result.status ?? 1\n}\n\n/** Resolve an executable script shipped by a dependency's bin field. */\nconst binOf = (\n requireFrom: NodeJS.Require,\n packageName: string,\n binName: string,\n): string => {\n const packageJsonPath = requireFrom.resolve(`${packageName}/package.json`)\n const manifest = requireFrom(`${packageName}/package.json`) as {\n bin?: string | Record<string, string>\n }\n const bin =\n typeof manifest.bin === \"string\" ? manifest.bin : manifest.bin?.[binName]\n if (!bin) {\n throw new Error(`${packageName} does not expose a \"${binName}\" binary`)\n }\n return join(dirname(packageJsonPath), bin)\n}\n\ntype PackageManifest = { version: string; exports?: Record<string, unknown> }\n\n/** The `@gtkx/react` subpath exports (its own `exports` map, minus `.` and `./package.json`). */\nconst reactSubexportsOf = (manifest: PackageManifest): string[] =>\n Object.keys(manifest.exports ?? {})\n .filter((key) => key.startsWith(\"./\") && key !== \"./package.json\")\n .map((key) => key.slice(2))\n\n// @gtkx/cli is meant for apps: its `codegen` command resolves gtkx.config.ts\n// from a cwd and trusts a freshness stamp, which is what the retired rc.2-era\n// workaround this replaced was dodging (running from a reconstructed \"project that owns\n// the hosting node_modules\" purely to keep that cwd resolution honest — see\n// gtkx-org/gtkx#468, #470). A library generating bindings on a consumer's\n// behalf should use the programmatic @gtkx/codegen API instead: it takes the\n// GIR libraries and store paths directly, so there is no cwd to get wrong and\n// no stamp to misread — and it runs its own fingerprint-based freshness\n// check in-process, so a missing/pruned store is regenerated rather than\n// misreported as \"up to date\".\n//\n// `root` (the app's real project root, resolved by the react-native CLI, not\n// us) is the right place to resolve gtkx.config.ts from, but NOT necessarily\n// where @gtkx/* actually lives on disk: in a workspace, npm hoists them to an\n// ancestor's node_modules, so `root/node_modules` can be a directory with no\n// @gtkx/* in it at all (confirmed against this repo's own examples/, which\n// are workspace members with nothing hoisted locally). The store — and the\n// @gtkx/gi and @gtkx/jsx links every other @gtkx/* package resolves through\n// its OWN up-the-tree lookup — must live in whichever node_modules actually\n// hosts @gtkx/runtime, so that's resolved rather than assumed.\nconst ensureCodegenStore = async (root: string): Promise<void> => {\n console.warn(\"[react-native-gtkx] ensuring gtkx codegen store…\")\n try {\n const [{ runCodegen, resolveGirPath, resolveLibraries }, { loadConfig }] =\n await Promise.all([import(\"@gtkx/codegen\"), import(\"@gtkx/config\")])\n const { config } = await loadConfig(root)\n if (config.codegen === false) {\n console.warn(\n \"[react-native-gtkx] codegen: disabled for this project (gtkx.config.ts)\",\n )\n return\n }\n const girPath = resolveGirPath(config.girPath)\n const libraries = resolveLibraries(config.libraries, girPath)\n const appRequire = createRequire(join(root, \"package.json\"))\n const runtimePackageJsonPath = appRequire.resolve(\n \"@gtkx/runtime/package.json\",\n )\n const nodeModules = dirname(dirname(dirname(runtimePackageJsonPath)))\n const runtime = appRequire(runtimePackageJsonPath) as PackageManifest\n const react = appRequire(\"@gtkx/react/package.json\") as PackageManifest\n const result = await runCodegen({\n libraries,\n girPath,\n gi: {\n storeDir: join(nodeModules, \".gtkx\", \"gi\"),\n linkDir: join(nodeModules, \"@gtkx\", \"gi\"),\n version: runtime.version,\n },\n jsx: {\n storeDir: join(nodeModules, \".gtkx\", \"jsx\"),\n linkDir: join(nodeModules, \"@gtkx\", \"jsx\"),\n version: react.version,\n },\n reactSubexports: reactSubexportsOf(react),\n })\n console.warn(\n result.isRegenerated\n ? \"[react-native-gtkx] codegen: regenerated stale bindings\"\n : \"[react-native-gtkx] codegen: bindings up to date\",\n )\n } catch (error) {\n console.error(\n \"[react-native-gtkx] gtkx codegen failed — are GTK4/libadwaita \" +\n \"development files installed?\",\n )\n console.error(error)\n process.exit(1)\n }\n}\n\nconst bundle = (root: string, entryFile: string, output: string): void => {\n const appRequire = createRequire(join(root, \"package.json\"))\n const status = run(\n process.execPath,\n [\n binOf(appRequire, \"react-native\", \"react-native\"),\n \"bundle\",\n \"--platform\",\n \"linux\",\n \"--dev\",\n \"false\",\n \"--entry-file\",\n entryFile,\n \"--bundle-output\",\n output,\n ],\n root,\n )\n if (status !== 0) {\n process.exit(status)\n }\n}\n\nconst isMetroRunning = async (server: string): Promise<boolean> => {\n try {\n const response = await fetch(`${server}/status`)\n return (await response.text()).includes(\"packager-status:running\")\n } catch {\n return false\n }\n}\n\nconst waitForMetro = async (server: string): Promise<void> => {\n for (let attempt = 0; attempt < 120; attempt += 1) {\n if (await isMetroRunning(server)) {\n return\n }\n await new Promise((resolve) => setTimeout(resolve, 500))\n }\n console.error(\n `[react-native-gtkx] Metro dev server never came up (${server}).`,\n )\n process.exit(1)\n}\n\nlet activeHost: ChildProcess | null = null\n\nconst spawnHost = (\n script: string,\n argument: string,\n cwd: string,\n): Promise<number> =>\n new Promise((resolve) => {\n // join over `new URL(script, import.meta.url)`: the global URL and the\n // node:url URL come from different type copies when the dependency tree\n // splits @types/node, and the two structurally diverge.\n const hostPath = join(dirname(fileURLToPath(import.meta.url)), script)\n const child = spawn(process.execPath, [hostPath, argument], {\n cwd,\n stdio: \"inherit\",\n })\n activeHost = child\n child.on(\"exit\", (code) => {\n activeHost = null\n resolve(code ?? 1)\n })\n })\n\nconst runLinuxDev = async (\n config: CliConfig,\n args: RunLinuxArgs,\n): Promise<never> => {\n const port = args.port ?? \"8081\"\n const server = `http://localhost:${port}`\n let metro: ChildProcess | null = null\n if (await isMetroRunning(server)) {\n console.warn(\n `[react-native-gtkx] reusing the Metro dev server at ${server}`,\n )\n } else {\n console.warn(\n `[react-native-gtkx] starting the Metro dev server at ${server}…`,\n )\n const appRequire = createRequire(join(config.root, \"package.json\"))\n metro = spawn(\n process.execPath,\n [\n binOf(appRequire, \"react-native\", \"react-native\"),\n \"start\",\n \"--port\",\n port,\n ],\n { cwd: config.root, stdio: \"inherit\" },\n )\n await waitForMetro(server)\n }\n const entry = basename(args.entryFile, extname(args.entryFile))\n const bundleUrl = `${server}/${entry}.bundle?platform=linux&dev=true&minify=false`\n const shutdown = (code: number): never => {\n activeHost?.kill()\n metro?.kill()\n process.exit(code)\n }\n process.on(\"SIGINT\", () => shutdown(0))\n process.on(\"SIGTERM\", () => shutdown(0))\n // Supervisor: a full-refresh request restarts the host with the window\n // reopening on the fresh bundle; any other exit ends the session.\n for (;;) {\n const code = await spawnHost(\"./host-dev.js\", bundleUrl, config.root)\n if (code !== FULL_REFRESH_EXIT_CODE) {\n shutdown(code)\n }\n console.warn(\"[react-native-gtkx] restarting the app after a full refresh…\")\n }\n}\n\nconst runLinux = async (\n _argv: string[],\n config: CliConfig,\n args: RunLinuxArgs,\n): Promise<void> => {\n await ensureCodegenStore(config.root)\n if (args.dev) {\n await runLinuxDev(config, args)\n return\n }\n const output =\n args.bundleOutput ??\n join(config.root, \"node_modules\", \".react-native-gtkx\", \"main.jsbundle\")\n if (!args.skipBundling) {\n mkdirSync(dirname(output), { recursive: true })\n bundle(config.root, args.entryFile, output)\n }\n const status = await spawnHost(\"./host.js\", output, config.root)\n process.exit(status)\n}\n\n/**\n * The executable name a `--sea` build defaults to: the app's package name\n * without its scope, so the artifact is `dist/hn-app`, not `dist/app`.\n */\nconst appBinaryName = (root: string): string => {\n try {\n const manifest = createRequire(join(root, \"package.json\"))(\n \"./package.json\",\n ) as { name?: string }\n const name = manifest.name?.split(\"/\").pop()\n return name && /^[\\w.-]+$/.test(name) ? name : \"app\"\n } catch {\n return \"app\"\n }\n}\n\n// The android/ios counterpart to run-linux's dev-only bundling: bundle for\n// distribution and stop, the way a release APK/IPA build does not launch\n// the app it produces. Deliberately skips ensureCodegenStore() — codegen\n// generates the @gtkx/gi bindings host.js imports to talk to GTK at RUN\n// time; bundling never touches them (Metro only reads/transforms JS, and\n// the GTK/react/yoga modules are proxied rather than imported — see\n// ../metro's HOST_MODULE_EXTERNALS). A machine that only builds never needs\n// GTK dev headers installed.\n//\n// --standalone and --sea are the exception: both inline\n// \"virtual:gtkx-config\", which re-exports @gtkx/jsx/metadata — a codegen\n// product — so they DO need the store, and therefore GTK dev headers.\n// Only those paths ensure it.\n//\n// The three artifacts, cheapest to heaviest, are deliberately one command\n// with flags rather than three commands: they share the Metro bundle step,\n// and the choice between them is a distribution question, not a different\n// build.\n// (default) main.jsbundle + a runtime node_modules + a system node\n// --standalone one .cjs file, no node_modules, + a system node\n// --sea one executable, nothing preinstalled at all\nconst buildLinux = async (\n _argv: string[],\n config: CliConfig,\n args: BuildLinuxArgs,\n): Promise<void> => {\n if (args.sea || args.standalone) {\n await ensureCodegenStore(config.root)\n }\n const output = args.bundleOutput ?? join(config.root, \"dist\", \"main.jsbundle\")\n mkdirSync(dirname(output), { recursive: true })\n bundle(config.root, args.entryFile, output)\n console.warn(`[react-native-gtkx] wrote the release bundle to ${output}`)\n if (!args.sea && !args.standalone) {\n return\n }\n const name = appBinaryName(config.root)\n const seaOutput =\n args.seaOutput ?? join(config.root, \"dist\", args.sea ? name : `${name}.cjs`)\n // Dynamically imported so the bundler is never loaded on the ordinary\n // jsbundle path.\n const { assembleSea, bundleStandalone } = await import(\"../sea/assemble.js\")\n const bytes = args.sea\n ? await assembleSea({\n appRoot: config.root,\n jsbundlePath: output,\n outFile: seaOutput,\n })\n : await bundleStandalone({\n appRoot: config.root,\n jsbundlePath: output,\n outFile: seaOutput,\n })\n const megabytes = (bytes / 1024 / 1024).toFixed(0)\n console.warn(\n args.sea\n ? `[react-native-gtkx] wrote the single executable to ${seaOutput} ` +\n `(${megabytes} MB — Node itself is most of it)`\n : `[react-native-gtkx] wrote the standalone script to ${seaOutput} ` +\n `(${megabytes} MB — run it with \\`node ${seaOutput}\\`)`,\n )\n}\n\n/** Commands contributed to the RN CLI by the package's react-native.config.js. */\nexport const commands = [\n {\n name: \"run-linux\",\n description:\n \"Bundle the app with Metro for the linux platform and run it in the Node+GTK host\",\n options: [\n {\n name: \"--entry-file <path>\",\n description: \"Path to the app entry file\",\n default: \"index.js\",\n },\n {\n name: \"--bundle-output <path>\",\n description:\n \"Where to write the jsbundle (default: node_modules/.react-native-gtkx/main.jsbundle)\",\n },\n {\n name: \"--skip-bundling\",\n description: \"Reuse the existing bundle at --bundle-output\",\n },\n {\n name: \"--dev\",\n description:\n \"Development mode: Metro dev server + Fast Refresh (edits apply to the live window)\",\n },\n {\n name: \"--port <number>\",\n description: \"Metro dev server port for --dev (default: 8081)\",\n },\n ],\n func: runLinux,\n },\n {\n name: \"build-linux\",\n description:\n \"Bundle the app with Metro for the linux platform for distribution, without running it\",\n options: [\n {\n name: \"--entry-file <path>\",\n description: \"Path to the app entry file\",\n default: \"index.js\",\n },\n {\n name: \"--bundle-output <path>\",\n description:\n \"Where to write the release jsbundle (default: dist/main.jsbundle)\",\n },\n {\n name: \"--standalone\",\n description:\n \"Also produce one self-contained .cjs — no node_modules, run it \" +\n \"with a system node (dist/<package name>.cjs)\",\n },\n {\n name: \"--sea\",\n description:\n \"Also produce a single executable (Node SEA): one file that runs \" +\n \"with no node_modules and no system Node — at the cost of \" +\n \"carrying a whole Node binary (~120 MB)\",\n },\n {\n name: \"--sea-output <path>\",\n description:\n \"Where to write the --sea / --standalone artifact \" +\n \"(default: dist/<package name>[.cjs])\",\n },\n ],\n func: buildLinux,\n },\n]\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runner/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,2EAA2E;AAC3E,yEAAyE;AACzE,uEAAuE;AACvE,oEAAoE;AACpE,uEAAuE;AACvE,4CAA4C;AAC5C,EAAE;AACF,kEAAkE;AAClE,qCAAqC;AACrC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAqB,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3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,mFAAmF;aACtF;YACD;gBACE,IAAI,EAAE,cAAc;gBACpB,WAAW,EACT,8IAA8I;aACjJ;SACF;QACD,IAAI,EAAE,WAAW;KAClB;CACF,CAAA","sourcesContent":["// The `run-linux` CLI command (registered through the package's\n// react-native.config.js, the react-native-windows model): ensure the gtkx\n// codegen store, then either build a release jsbundle with Metro and run\n// it in the Node+GTK host (./host.ts), or — with --dev — start/reuse a\n// Metro dev server and supervise the DEV host (./host-dev.ts): Fast\n// Refresh applies edits to the live window, and a full-refresh request\n// (exit code 65) restarts the host process.\n//\n// Like the hosts, this module must stay runnable under bare Node:\n// builtins and bare specifiers only.\nimport { spawn, spawnSync, type ChildProcess } from \"node:child_process\"\nimport { existsSync, mkdirSync, rmSync, writeFileSync } from \"node:fs\"\nimport { createRequire } from \"node:module\"\nimport { basename, dirname, extname, join } from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\n\ntype CliConfig = { root: string }\ntype RunLinuxArgs = {\n entryFile: string\n bundleOutput?: string\n skipBundling?: boolean\n dev?: boolean\n port?: string\n}\ntype BuildLinuxArgs = {\n entryFile: string\n bundleOutput?: string\n standalone?: boolean\n sea?: boolean\n seaOutput?: string\n}\ntype DeployLinuxArgs = {\n entryFile: string\n target?: string\n out?: string\n printManifests?: boolean\n skipBuild?: boolean\n}\n\n/** Exit code host-dev.ts uses to request a supervisor restart. */\nconst FULL_REFRESH_EXIT_CODE = 65\n\nconst fail = (message: string): never => {\n console.error(`[react-native-gtkx] ${message}`)\n process.exit(1)\n}\n\nconst run = (command: string, args: string[], cwd: string): number => {\n const result = spawnSync(command, args, { cwd, stdio: \"inherit\" })\n return result.status ?? 1\n}\n\n/** Resolve an executable script shipped by a dependency's bin field. */\nconst binOf = (\n requireFrom: NodeJS.Require,\n packageName: string,\n binName: string,\n): string => {\n const packageJsonPath = requireFrom.resolve(`${packageName}/package.json`)\n const manifest = requireFrom(`${packageName}/package.json`) as {\n bin?: string | Record<string, string>\n }\n const bin =\n typeof manifest.bin === \"string\" ? manifest.bin : manifest.bin?.[binName]\n if (!bin) {\n throw new Error(`${packageName} does not expose a \"${binName}\" binary`)\n }\n return join(dirname(packageJsonPath), bin)\n}\n\ntype PackageManifest = { version: string; exports?: Record<string, unknown> }\n\n/** The `@gtkx/react` subpath exports (its own `exports` map, minus `.` and `./package.json`). */\nconst reactSubexportsOf = (manifest: PackageManifest): string[] =>\n Object.keys(manifest.exports ?? {})\n .filter((key) => key.startsWith(\"./\") && key !== \"./package.json\")\n .map((key) => key.slice(2))\n\n// @gtkx/cli is meant for apps: its `codegen` command resolves gtkx.config.ts\n// from a cwd and trusts a freshness stamp, which is what the retired rc.2-era\n// workaround this replaced was dodging (running from a reconstructed \"project that owns\n// the hosting node_modules\" purely to keep that cwd resolution honest — see\n// gtkx-org/gtkx#468, #470). A library generating bindings on a consumer's\n// behalf should use the programmatic @gtkx/codegen API instead: it takes the\n// GIR libraries and store paths directly, so there is no cwd to get wrong and\n// no stamp to misread — and it runs its own fingerprint-based freshness\n// check in-process, so a missing/pruned store is regenerated rather than\n// misreported as \"up to date\".\n//\n// `root` (the app's real project root, resolved by the react-native CLI, not\n// us) is the right place to resolve gtkx.config.ts from, but NOT necessarily\n// where @gtkx/* actually lives on disk: in a workspace, npm hoists them to an\n// ancestor's node_modules, so `root/node_modules` can be a directory with no\n// @gtkx/* in it at all (confirmed against this repo's own examples/, which\n// are workspace members with nothing hoisted locally). The store — and the\n// @gtkx/gi and @gtkx/jsx links every other @gtkx/* package resolves through\n// its OWN up-the-tree lookup — must live in whichever node_modules actually\n// hosts @gtkx/runtime, so that's resolved rather than assumed.\nconst ensureCodegenStore = async (root: string): Promise<void> => {\n console.warn(\"[react-native-gtkx] ensuring gtkx codegen store…\")\n try {\n const [{ runCodegen, resolveGirPath, resolveLibraries }, { loadConfig }] =\n await Promise.all([import(\"@gtkx/codegen\"), import(\"@gtkx/config\")])\n const { config } = await loadConfig(root)\n if (config.codegen === false) {\n console.warn(\n \"[react-native-gtkx] codegen: disabled for this project (gtkx.config.ts)\",\n )\n return\n }\n const girPath = resolveGirPath(config.girPath)\n const libraries = resolveLibraries(config.libraries, girPath)\n const appRequire = createRequire(join(root, \"package.json\"))\n const runtimePackageJsonPath = appRequire.resolve(\n \"@gtkx/runtime/package.json\",\n )\n const nodeModules = dirname(dirname(dirname(runtimePackageJsonPath)))\n const runtime = appRequire(runtimePackageJsonPath) as PackageManifest\n const react = appRequire(\"@gtkx/react/package.json\") as PackageManifest\n const result = await runCodegen({\n libraries,\n girPath,\n gi: {\n storeDir: join(nodeModules, \".gtkx\", \"gi\"),\n linkDir: join(nodeModules, \"@gtkx\", \"gi\"),\n version: runtime.version,\n },\n jsx: {\n storeDir: join(nodeModules, \".gtkx\", \"jsx\"),\n linkDir: join(nodeModules, \"@gtkx\", \"jsx\"),\n version: react.version,\n },\n reactSubexports: reactSubexportsOf(react),\n })\n console.warn(\n result.isRegenerated\n ? \"[react-native-gtkx] codegen: regenerated stale bindings\"\n : \"[react-native-gtkx] codegen: bindings up to date\",\n )\n } catch (error) {\n console.error(\n \"[react-native-gtkx] gtkx codegen failed — are GTK4/libadwaita \" +\n \"development files installed?\",\n )\n console.error(error)\n process.exit(1)\n }\n}\n\nconst bundle = (root: string, entryFile: string, output: string): void => {\n const appRequire = createRequire(join(root, \"package.json\"))\n const status = run(\n process.execPath,\n [\n binOf(appRequire, \"react-native\", \"react-native\"),\n \"bundle\",\n \"--platform\",\n \"linux\",\n \"--dev\",\n \"false\",\n \"--entry-file\",\n entryFile,\n \"--bundle-output\",\n output,\n ],\n root,\n )\n if (status !== 0) {\n process.exit(status)\n }\n}\n\nconst isMetroRunning = async (server: string): Promise<boolean> => {\n try {\n const response = await fetch(`${server}/status`)\n return (await response.text()).includes(\"packager-status:running\")\n } catch {\n return false\n }\n}\n\nconst waitForMetro = async (server: string): Promise<void> => {\n for (let attempt = 0; attempt < 120; attempt += 1) {\n if (await isMetroRunning(server)) {\n return\n }\n await new Promise((resolve) => setTimeout(resolve, 500))\n }\n console.error(\n `[react-native-gtkx] Metro dev server never came up (${server}).`,\n )\n process.exit(1)\n}\n\nlet activeHost: ChildProcess | null = null\n\nconst spawnHost = (\n script: string,\n argument: string,\n cwd: string,\n): Promise<number> =>\n new Promise((resolve) => {\n // join over `new URL(script, import.meta.url)`: the global URL and the\n // node:url URL come from different type copies when the dependency tree\n // splits @types/node, and the two structurally diverge.\n const hostPath = join(dirname(fileURLToPath(import.meta.url)), script)\n const child = spawn(process.execPath, [hostPath, argument], {\n cwd,\n stdio: \"inherit\",\n })\n activeHost = child\n child.on(\"exit\", (code) => {\n activeHost = null\n resolve(code ?? 1)\n })\n })\n\nconst runLinuxDev = async (\n config: CliConfig,\n args: RunLinuxArgs,\n): Promise<never> => {\n const port = args.port ?? \"8081\"\n const server = `http://localhost:${port}`\n let metro: ChildProcess | null = null\n if (await isMetroRunning(server)) {\n console.warn(\n `[react-native-gtkx] reusing the Metro dev server at ${server}`,\n )\n } else {\n console.warn(\n `[react-native-gtkx] starting the Metro dev server at ${server}…`,\n )\n const appRequire = createRequire(join(config.root, \"package.json\"))\n metro = spawn(\n process.execPath,\n [\n binOf(appRequire, \"react-native\", \"react-native\"),\n \"start\",\n \"--port\",\n port,\n ],\n { cwd: config.root, stdio: \"inherit\" },\n )\n await waitForMetro(server)\n }\n const entry = basename(args.entryFile, extname(args.entryFile))\n const bundleUrl = `${server}/${entry}.bundle?platform=linux&dev=true&minify=false`\n const shutdown = (code: number): never => {\n activeHost?.kill()\n metro?.kill()\n process.exit(code)\n }\n process.on(\"SIGINT\", () => shutdown(0))\n process.on(\"SIGTERM\", () => shutdown(0))\n // Supervisor: a full-refresh request restarts the host with the window\n // reopening on the fresh bundle; any other exit ends the session.\n for (;;) {\n const code = await spawnHost(\"./host-dev.js\", bundleUrl, config.root)\n if (code !== FULL_REFRESH_EXIT_CODE) {\n shutdown(code)\n }\n console.warn(\"[react-native-gtkx] restarting the app after a full refresh…\")\n }\n}\n\nconst runLinux = async (\n _argv: string[],\n config: CliConfig,\n args: RunLinuxArgs,\n): Promise<void> => {\n await ensureCodegenStore(config.root)\n if (args.dev) {\n await runLinuxDev(config, args)\n return\n }\n const output =\n args.bundleOutput ??\n join(config.root, \"node_modules\", \".react-native-gtkx\", \"main.jsbundle\")\n if (!args.skipBundling) {\n mkdirSync(dirname(output), { recursive: true })\n bundle(config.root, args.entryFile, output)\n }\n const status = await spawnHost(\"./host.js\", output, config.root)\n process.exit(status)\n}\n\n/**\n * The executable name a `--sea` build defaults to: the app's package name\n * without its scope, so the artifact is `dist/hn-app`, not `dist/app`.\n */\nconst appBinaryName = (root: string): string => {\n try {\n const manifest = createRequire(join(root, \"package.json\"))(\n \"./package.json\",\n ) as { name?: string }\n const name = manifest.name?.split(\"/\").pop()\n return name && /^[\\w.-]+$/.test(name) ? name : \"app\"\n } catch {\n return \"app\"\n }\n}\n\n// The android/ios counterpart to run-linux's dev-only bundling: bundle for\n// distribution and stop, the way a release APK/IPA build does not launch\n// the app it produces. Deliberately skips ensureCodegenStore() — codegen\n// generates the @gtkx/gi bindings host.js imports to talk to GTK at RUN\n// time; bundling never touches them (Metro only reads/transforms JS, and\n// the GTK/react/yoga modules are proxied rather than imported — see\n// ../metro's HOST_MODULE_EXTERNALS). A machine that only builds never needs\n// GTK dev headers installed.\n//\n// --standalone and --sea are the exception: both inline\n// \"virtual:gtkx-config\", which re-exports @gtkx/jsx/metadata — a codegen\n// product — so they DO need the store, and therefore GTK dev headers.\n// Only those paths ensure it.\n//\n// The three artifacts, cheapest to heaviest, are deliberately one command\n// with flags rather than three commands: they share the Metro bundle step,\n// and the choice between them is a distribution question, not a different\n// build.\n// (default) main.jsbundle + a runtime node_modules + a system node\n// --standalone one .cjs file, no node_modules, + a system node\n// --sea one executable, nothing preinstalled at all\nconst buildLinux = async (\n _argv: string[],\n config: CliConfig,\n args: BuildLinuxArgs,\n): Promise<void> => {\n if (args.sea || args.standalone) {\n await ensureCodegenStore(config.root)\n }\n const output = args.bundleOutput ?? join(config.root, \"dist\", \"main.jsbundle\")\n mkdirSync(dirname(output), { recursive: true })\n bundle(config.root, args.entryFile, output)\n console.warn(`[react-native-gtkx] wrote the release bundle to ${output}`)\n if (!args.sea && !args.standalone) {\n return\n }\n const name = appBinaryName(config.root)\n const seaOutput =\n args.seaOutput ?? join(config.root, \"dist\", args.sea ? name : `${name}.cjs`)\n // Dynamically imported so the bundler is never loaded on the ordinary\n // jsbundle path.\n const { assembleSea, bundleStandalone } = await import(\"../sea/assemble.js\")\n const bytes = args.sea\n ? await assembleSea({\n appRoot: config.root,\n jsbundlePath: output,\n outFile: seaOutput,\n })\n : await bundleStandalone({\n appRoot: config.root,\n jsbundlePath: output,\n outFile: seaOutput,\n })\n const megabytes = (bytes / 1024 / 1024).toFixed(0)\n console.warn(\n args.sea\n ? `[react-native-gtkx] wrote the single executable to ${seaOutput} ` +\n `(${megabytes} MB — Node itself is most of it)`\n : `[react-native-gtkx] wrote the standalone script to ${seaOutput} ` +\n `(${megabytes} MB — run it with \\`node ${seaOutput}\\`)`,\n )\n}\n\n// `deploy-linux`: `npx gtkx deploy` packages a project's `dist/` into\n// .deb/.rpm/.AppImage/.flatpak, but it is vite-shaped by construction — its\n// payload stager (@gtkx/cli's stagePayload) unconditionally requires\n// `dist/bundle.mjs` and copies the rest of `dist/` verbatim, `--skip-build`\n// included. A Metro app never produces that file (Metro externalizes\n// @gtkx/*/react/yoga-layout instead of inlining them — see ../metro's\n// HOST_MODULE_EXTERNALS), so `gtkx deploy` cannot package one on its own.\n// This command is the bridge: on the vite path it is a thin proxy (the app\n// already looks exactly like what `gtkx deploy` expects); on the Metro path\n// it builds a real Metro release, reshapes that build into the same\n// dist/bundle.mjs shape a vite build would have produced, and only then\n// calls into `gtkx deploy --skip-build`.\n//\n// Registered the same way as run-linux/build-linux (react-native.config.js),\n// so the RN CLI exposes it to every app that depends on react-native-gtkx —\n// regardless of which toolchain that particular app actually builds with:\n// `npx react-native config` from a vite-path example already lists\n// run-linux/build-linux today (confirmed against examples/monitor, which has\n// no `react-native` dependency of its own — the command surface comes along\n// because react-native-gtkx is a dependency, and this workspace happens to\n// hoist `react-native` where every example's own `npx` lookup can still find\n// it). So this command has to tell the two toolchains apart itself; neither\n// run-linux nor build-linux do that today (they are Metro-only by\n// construction), so there is no existing helper to reuse — see\n// isViteProject below for the detection this command invents.\n\n/** Every extension `gtkx.config.ts` is allowed to use (c12's own candidate\n * list, mirrored rather than imported since @gtkx/config does not export\n * it) — used only for the friendlier \"you're missing one\" error below;\n * @gtkx/config's own loader remains the actual authority. */\nconst GTKX_CONFIG_CANDIDATES = [\"ts\", \"js\", \"mjs\", \"cjs\", \"mts\", \"cts\"].map(\n (extension) => `gtkx.config.${extension}`,\n)\n\nconst hasGtkxConfig = (root: string): boolean =>\n GTKX_CONFIG_CANDIDATES.some((name) => existsSync(join(root, name)))\n\n/** Vite's own convention for \"this directory is a vite project\" — every\n * vite-path example in this repo (gallery, monitor, tasks-app, tasks-nav)\n * has exactly one of these at its root, and no Metro app does (hn-app and\n * rn-app have `metro.config.js` and a root `index.js` instead). Exported so\n * the detection itself is unit-testable without spawning anything. */\nexport const VITE_CONFIG_CANDIDATES = [\n \"vite.config.ts\",\n \"vite.config.js\",\n \"vite.config.mjs\",\n \"vite.config.mts\",\n]\n\nexport const isViteProject = (root: string): boolean =>\n VITE_CONFIG_CANDIDATES.some((name) => existsSync(join(root, name)))\n\n/** `--target`/`--out`/`--print-manifests` — passed through unchanged to\n * `gtkx deploy` on both paths. `--skip-build` is handled separately by each\n * path below: it means something different on each (see deployLinuxMetro). */\nconst commonDeployArgs = (args: DeployLinuxArgs): string[] => {\n const passthrough: string[] = []\n if (args.target !== undefined) {\n passthrough.push(\"--target\", args.target)\n }\n if (args.out !== undefined) {\n passthrough.push(\"--out\", args.out)\n }\n if (args.printManifests) {\n passthrough.push(\"--print-manifests\")\n }\n return passthrough\n}\n\nconst runGtkxDeploy = (root: string, args: string[]): number => {\n const appRequire = createRequire(join(root, \"package.json\"))\n return run(\n process.execPath,\n [binOf(appRequire, \"@gtkx/cli\", \"gtkx\"), \"deploy\", ...args],\n root,\n )\n}\n\n// The vite path IS what `gtkx deploy` already expects — no build of ours to\n// run, no staging to do. A missing gtkx.config.ts or `deploy` block surfaces\n// through gtkx's own error (stdio is inherited below), which already names\n// exactly what to add and where (a ready-to-paste `deploy` block derived\n// from package.json for the latter).\nconst deployLinuxVite = (config: CliConfig, args: DeployLinuxArgs): void => {\n const gtkxArgs = [\n ...commonDeployArgs(args),\n ...(args.skipBuild ? [\"--skip-build\"] : []),\n ]\n process.exit(runGtkxDeploy(config.root, gtkxArgs))\n}\n\nconst DEPLOY_SCRATCH_BUNDLE = \"deploy.jsbundle\"\n\n/**\n * Reshapes a Metro build into the one file `gtkx deploy --skip-build`\n * actually checks for (`dist/bundle.mjs`) plus whatever it needs beside it,\n * by reusing --standalone's own bundler rather than inventing a second one:\n * bundleStandalone already produces a single self-contained CJS file with\n * the whole HOST_MODULE_EXTERNALS closure AND the native addon (as a\n * base64 literal, extracted to a per-user cache on first run) inlined — see\n * ../sea/native-shim.ts. That statically satisfies everything a vite build's\n * dist/bundle.mjs would otherwise need a separate dist/gtkx.node for.\n *\n * The one thing it is NOT is an ES module — rolldown emits it as CJS (see\n * ../sea/bundle.ts's header for why: a Node SEA's main script is forced to\n * CJS, and --standalone shares that bundler). `dist/bundle.mjs` cannot just\n * be that file under a different name: Node parses a `.mjs` file as ESM\n * unconditionally, and `module.exports = …`/bare `require(…)` are\n * ReferenceErrors there. So this writes the real artifact under its own\n * name and a two-line ESM shim at dist/bundle.mjs that hands off to it via\n * `createRequire` — synchronous, so no top-level await, and it resolves\n * \"./<name>.cjs\" from its OWN location (import.meta.url), which is exactly\n * where stagePayload copies it (both files land in the same directory,\n * `lib/<binaryName>/`), regardless of the installed package's cwd.\n */\nconst stageMetroDeployDist = async (\n root: string,\n entryFile: string,\n): Promise<string> => {\n const scratchDir = join(root, \"node_modules\", \".react-native-gtkx\")\n mkdirSync(scratchDir, { recursive: true })\n const jsbundlePath = join(scratchDir, DEPLOY_SCRATCH_BUNDLE)\n bundle(root, entryFile, jsbundlePath)\n\n const distDir = join(root, \"dist\")\n // Cleared, not merged into: gtkx deploy stages every file it finds under\n // dist/ (barring an icons/ dir and its own build metadata), so a stale\n // main.jsbundle or a previous run's artifacts left over from a plain\n // `build-linux` would otherwise ship inside the package too.\n rmSync(distDir, { recursive: true, force: true })\n mkdirSync(distDir, { recursive: true })\n\n const name = appBinaryName(root)\n const standaloneOutput = join(distDir, `${name}.cjs`)\n const { bundleStandalone } = await import(\"../sea/assemble.js\")\n await bundleStandalone({\n appRoot: root,\n jsbundlePath,\n outFile: standaloneOutput,\n // gtkx deploy's third-party-notices step reads dist/gtkx-packages.json\n // unconditionally (--skip-build included) — see bundleStandalone's own\n // comment for why this is the one flag deploy-linux passes that\n // build-linux --standalone never does.\n shouldWritePackageManifest: true,\n })\n\n writeFileSync(\n join(distDir, \"bundle.mjs\"),\n [\n \"// Generated by `react-native deploy-linux` — do not edit by hand.\",\n \"// gtkx deploy's payload stager only recognizes a vite-shaped\",\n `// dist/bundle.mjs; this hands off to the real Metro-built artifact`,\n `// next to it (${name}.cjs, which inlines the whole runtime closure`,\n \"// and the native addon — see stageMetroDeployDist in\",\n \"// react-native-gtkx/runner for the full explanation).\",\n 'import { createRequire } from \"node:module\"',\n \"\",\n `createRequire(import.meta.url)(${JSON.stringify(`./${name}.cjs`)})`,\n \"\",\n ].join(\"\\n\"),\n )\n console.warn(`[react-native-gtkx] staged a vite-shaped dist/ at ${distDir}`)\n return distDir\n}\n\nconst deployLinuxMetro = async (\n config: CliConfig,\n args: DeployLinuxArgs,\n): Promise<void> => {\n const root = config.root\n if (!hasGtkxConfig(root)) {\n fail(\n `no gtkx.config.ts found at ${root} — deploy-linux needs one on the ` +\n \"Metro path too (the same file the codegen store already \" +\n \"requires), exporting a `deploy` block from defineConfig(). See \" +\n \"docs/guide/packaging.md.\",\n )\n }\n\n const distBundle = join(root, \"dist\", \"bundle.mjs\")\n if (args.skipBuild) {\n if (!existsSync(distBundle)) {\n fail(\n `--skip-build was given but ${distBundle} does not exist yet — ` +\n \"run deploy-linux without --skip-build at least once first.\",\n )\n }\n console.warn(\n \"[react-native-gtkx] --skip-build: reusing the already-staged dist/\",\n )\n } else {\n await ensureCodegenStore(root)\n await stageMetroDeployDist(root, args.entryFile)\n }\n\n // gtkx deploy's own entry resolution runs unconditionally (even with\n // --skip-build), and its default (src/index.{tsx,jsx,ts,js}) is the vite\n // convention, not Metro's — pass the Metro entry file through explicitly\n // so it resolves, even though the value itself goes unused once staging\n // is skipped.\n const gtkxArgs = [\"--skip-build\", ...commonDeployArgs(args), args.entryFile]\n process.exit(runGtkxDeploy(root, gtkxArgs))\n}\n\nconst deployLinux = async (\n _argv: string[],\n config: CliConfig,\n args: DeployLinuxArgs,\n): Promise<void> => {\n if (isViteProject(config.root)) {\n deployLinuxVite(config, args)\n return\n }\n await deployLinuxMetro(config, args)\n}\n\n/** Commands contributed to the RN CLI by the package's react-native.config.js. */\nexport const commands = [\n {\n name: \"run-linux\",\n description:\n \"Bundle the app with Metro for the linux platform and run it in the Node+GTK host\",\n options: [\n {\n name: \"--entry-file <path>\",\n description: \"Path to the app entry file\",\n default: \"index.js\",\n },\n {\n name: \"--bundle-output <path>\",\n description:\n \"Where to write the jsbundle (default: node_modules/.react-native-gtkx/main.jsbundle)\",\n },\n {\n name: \"--skip-bundling\",\n description: \"Reuse the existing bundle at --bundle-output\",\n },\n {\n name: \"--dev\",\n description:\n \"Development mode: Metro dev server + Fast Refresh (edits apply to the live window)\",\n },\n {\n name: \"--port <number>\",\n description: \"Metro dev server port for --dev (default: 8081)\",\n },\n ],\n func: runLinux,\n },\n {\n name: \"build-linux\",\n description:\n \"Bundle the app with Metro for the linux platform for distribution, without running it\",\n options: [\n {\n name: \"--entry-file <path>\",\n description: \"Path to the app entry file\",\n default: \"index.js\",\n },\n {\n name: \"--bundle-output <path>\",\n description:\n \"Where to write the release jsbundle (default: dist/main.jsbundle)\",\n },\n {\n name: \"--standalone\",\n description:\n \"Also produce one self-contained .cjs — no node_modules, run it \" +\n \"with a system node (dist/<package name>.cjs)\",\n },\n {\n name: \"--sea\",\n description:\n \"Also produce a single executable (Node SEA): one file that runs \" +\n \"with no node_modules and no system Node — at the cost of \" +\n \"carrying a whole Node binary (~120 MB)\",\n },\n {\n name: \"--sea-output <path>\",\n description:\n \"Where to write the --sea / --standalone artifact \" +\n \"(default: dist/<package name>[.cjs])\",\n },\n ],\n func: buildLinux,\n },\n {\n name: \"deploy-linux\",\n description:\n \"Package the app for distribution (.deb/.rpm/.AppImage/.flatpak) — vite path proxies `gtkx deploy`, Metro path builds and stages first\",\n options: [\n {\n name: \"--entry-file <path>\",\n description: \"Path to the app entry file (Metro path only)\",\n default: \"index.js\",\n },\n {\n name: \"--target <formats>\",\n description:\n \"Comma-separated package formats to build (deb, rpm, appimage, flatpak)\",\n },\n {\n name: \"--out <path>\",\n description:\n \"Output directory relative to the project root (default: build)\",\n },\n {\n name: \"--print-manifests\",\n description:\n \"Write the generated desktop-entry/AppStream metadata, then stop without packaging\",\n },\n {\n name: \"--skip-build\",\n description:\n \"Package the already-staged dist/ instead of rebuilding (vite: passed through to `gtkx deploy`; Metro: also skips this command's own staging)\",\n },\n ],\n func: deployLinux,\n },\n]\n"]}
@@ -15,11 +15,20 @@ export type AssembleSeaOptions = {
15
15
  * system `node`. Everything the SEA is except the embedded Node runtime —
16
16
  * so ~120 MB smaller, at the cost of a `nodejs` dependency to declare.
17
17
  * Returns its size in bytes.
18
+ *
19
+ * `shouldWritePackageManifest` is for deploy-linux's own Metro-path staging
20
+ * (../runner/index.ts): `gtkx deploy` requires a `gtkx-packages.json` inside
21
+ * `dist/` before it will package anything, vite-built or not (its
22
+ * third-party-notices step reads it unconditionally, --skip-build included)
23
+ * — writing it here, from the real module graph this bundling step just
24
+ * produced, is cheap and accurate; an ordinary `build-linux --standalone`
25
+ * has no use for it, so it stays off by default.
18
26
  */
19
27
  export declare const bundleStandalone: (options: {
20
28
  appRoot: string;
21
29
  jsbundlePath: string;
22
30
  outFile: string;
31
+ shouldWritePackageManifest?: boolean;
23
32
  }) => Promise<number>;
24
33
  /**
25
34
  * Produces a single executable at {@link AssembleSeaOptions.outFile} and
@@ -16,7 +16,7 @@
16
16
  import { spawnSync } from "node:child_process";
17
17
  import { chmodSync, copyFileSync, mkdirSync, statSync, writeFileSync, } from "node:fs";
18
18
  import { dirname, join } from "node:path";
19
- import { bundleMetroSea } from "./bundle.js";
19
+ import { BUNDLED_PACKAGES_FILENAME, bundleMetroSea, collectBundledPackages, renderBundledPackagesManifest, } from "./bundle.js";
20
20
  /** The fuse postject looks for inside the node binary to place the blob. */
21
21
  const SENTINEL_FUSE = "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2";
22
22
  /** Pinned: postject has no stable release, and the SEA docs name this one. */
@@ -64,17 +64,30 @@ const stripSymbols = (file) => {
64
64
  * system `node`. Everything the SEA is except the embedded Node runtime —
65
65
  * so ~120 MB smaller, at the cost of a `nodejs` dependency to declare.
66
66
  * Returns its size in bytes.
67
+ *
68
+ * `shouldWritePackageManifest` is for deploy-linux's own Metro-path staging
69
+ * (../runner/index.ts): `gtkx deploy` requires a `gtkx-packages.json` inside
70
+ * `dist/` before it will package anything, vite-built or not (its
71
+ * third-party-notices step reads it unconditionally, --skip-build included)
72
+ * — writing it here, from the real module graph this bundling step just
73
+ * produced, is cheap and accurate; an ordinary `build-linux --standalone`
74
+ * has no use for it, so it stays off by default.
67
75
  */
68
76
  export const bundleStandalone = async (options) => {
69
77
  const { appRoot, jsbundlePath, outFile } = options;
70
78
  mkdirSync(dirname(outFile), { recursive: true });
71
79
  console.warn("[react-native-gtkx] bundling a standalone script…");
72
- await bundleMetroSea({
80
+ const { moduleIds } = await bundleMetroSea({
73
81
  appRoot,
74
82
  jsbundlePath,
75
83
  outFile,
76
84
  nativeAddonSource: "inline",
77
85
  });
86
+ if (options.shouldWritePackageManifest) {
87
+ const distDir = dirname(outFile);
88
+ const packages = collectBundledPackages(moduleIds, distDir);
89
+ writeFileSync(join(distDir, BUNDLED_PACKAGES_FILENAME), renderBundledPackagesManifest(packages));
90
+ }
78
91
  return statSync(outFile).size;
79
92
  };
80
93
  /**
@@ -89,7 +102,7 @@ export const assembleSea = async (options) => {
89
102
  mkdirSync(dirname(outFile), { recursive: true });
90
103
  console.warn("[react-native-gtkx] bundling for a single executable…");
91
104
  const bundlePath = join(workDir, "sea-bundle.cjs");
92
- const nativeAddon = await bundleMetroSea({
105
+ const { nativeAddon } = await bundleMetroSea({
93
106
  appRoot,
94
107
  jsbundlePath,
95
108
  outFile: bundlePath,
@@ -1 +1 @@
1
- {"version":3,"file":"assemble.js","sourceRoot":"","sources":["../../src/sea/assemble.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,0EAA0E;AAC1E,wEAAwE;AACxE,wDAAwD;AACxD,EAAE;AACF,wEAAwE;AACxE,0EAA0E;AAC1E,2CAA2C;AAC3C,EAAE;AACF,yEAAyE;AACzE,mEAAmE;AACnE,gDAAgD;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EACL,SAAS,EACT,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,4EAA4E;AAC5E,MAAM,aAAa,GAAG,gDAAgD,CAAA;AAEtE,8EAA8E;AAC9E,MAAM,QAAQ,GAAG,wBAAwB,CAAA;AAczC,MAAM,GAAG,GAAG,CAAC,OAAe,EAAE,IAAc,EAAQ,EAAE;IACpD,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,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EAAE,WAAW,CAAC,IAAI,EAAE;KAChD,EACD,IAAI,EACJ,CAAC,CACF,IAAI,CACN,CAAA;IAED,OAAO,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAA;IAC5D,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,2BAA2B,EAAE,UAAU,CAAC,CAAC,CAAA;IAEhE,OAAO,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAA;IAC5D,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACvC,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAClC,qEAAqE;QACrE,qEAAqE;QACrE,GAAG,CAAC,UAAU,EAAE,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,CAAA;IAClD,CAAC;IACD,YAAY,CAAC,OAAO,CAAC,CAAA;IAErB,OAAO,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAA;IAC3D,GAAG,CAAC,KAAK,EAAE;QACT,OAAO;QACP,kBAAkB;QAClB,QAAQ;QACR,OAAO;QACP,eAAe;QACf,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC;QAC9B,iBAAiB;QACjB,aAAa;KACd,CAAC,CAAA;IAEF,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACzB,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,CAAA;AAC/B,CAAC,CAAA","sourcesContent":["// Turns a Metro-built app into ONE executable file: bundle everything into\n// a CJS entry (./bundle.ts), generate a SEA blob from it, then inject that\n// blob into a copy of the `node` binary. This is the whole of what \"SEA\"\n// means — Node's Single Executable Application format is literally a copy\n// of the node binary with a V8 code-cache blob appended, which is why the\n// result necessarily carries Node's own weight (~117 MB on linux-arm64,\n// against <7 MB for the app code and its native addon).\n//\n// Follows gtkx's own tutorial (gtkx-org/gtkx examples/tutorial/scripts/\n// build-sea.sh) for these mechanics; ./bundle.ts's header documents where\n// the bundling half deliberately diverges.\n//\n// Kept out of ../runner/index.ts and reached through a dynamic import so\n// the bundler is only loaded when a SEA is actually asked for; the\n// ordinary `build-linux` path never touches it.\nimport { spawnSync } from \"node:child_process\"\nimport {\n chmodSync,\n copyFileSync,\n mkdirSync,\n statSync,\n writeFileSync,\n} from \"node:fs\"\nimport { dirname, join } from \"node:path\"\nimport { bundleMetroSea } from \"./bundle.js\"\n\n/** The fuse postject looks for inside the node binary to place the blob. */\nconst SENTINEL_FUSE = \"NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2\"\n\n/** Pinned: postject has no stable release, and the SEA docs name this one. */\nconst POSTJECT = \"postject@1.0.0-alpha.6\"\n\nexport type AssembleSeaOptions = {\n /** The app root — where gtkx.config.ts and package.json live. */\n appRoot: string\n /** The release jsbundle `build-linux` just wrote. */\n jsbundlePath: string\n /** Where the finished executable is written. */\n outFile: string\n /** Scratch directory for the intermediate CJS bundle, the SEA config and\n * the prep blob (default: alongside the jsbundle). */\n workDir?: string\n}\n\nconst run = (command: string, args: string[]): void => {\n const result = spawnSync(command, args, { stdio: \"inherit\" })\n if (result.error) {\n throw result.error\n }\n if (result.status !== 0) {\n throw new Error(`${command} ${args.join(\" \")} exited with ${result.status}`)\n }\n}\n\n/**\n * Drops the debug symbols from the copied Node binary. Worth a step of its\n * own because the saving is not marginal: the `node` binary distributed by\n * NodeSource for Ubuntu ships `with debug_info, not stripped` — measured at\n * 117 MB, and 98 MB after `strip --strip-all`. Nothing in a SEA needs those\n * symbols; the only cost is that a crash inside Node's own C++ produces an\n * unsymbolicated backtrace.\n *\n * Runs BEFORE postject, never after: `--strip-all` removes non-allocated\n * sections, which is exactly what the injected NODE_SEA_BLOB is.\n *\n * Best-effort — a build machine without binutils still produces a working\n * (larger) executable rather than failing, so this cannot become a new\n * install requirement for a build that worked yesterday.\n */\nconst stripSymbols = (file: string): void => {\n const before = statSync(file).size\n const result = spawnSync(\"strip\", [\"--strip-all\", file], {\n stdio: [\"ignore\", \"ignore\", \"pipe\"],\n })\n if (result.error || result.status !== 0) {\n console.warn(\n \"[react-native-gtkx] skipped stripping symbols (no usable `strip`) — \" +\n \"the executable will be tens of MB larger than it needs to be\",\n )\n return\n }\n const saved = (before - statSync(file).size) / 1024 / 1024\n console.warn(\n `[react-native-gtkx] stripped debug symbols (-${saved.toFixed(0)} MB)`,\n )\n}\n\n/**\n * Produces the middle artifact: one self-contained CJS file with the app,\n * its whole node_modules closure and the native addon inlined, run by a\n * system `node`. Everything the SEA is except the embedded Node runtime —\n * so ~120 MB smaller, at the cost of a `nodejs` dependency to declare.\n * Returns its size in bytes.\n */\nexport const bundleStandalone = async (options: {\n appRoot: string\n jsbundlePath: string\n outFile: string\n}): Promise<number> => {\n const { appRoot, jsbundlePath, outFile } = options\n mkdirSync(dirname(outFile), { recursive: true })\n console.warn(\"[react-native-gtkx] bundling a standalone script…\")\n await bundleMetroSea({\n appRoot,\n jsbundlePath,\n outFile,\n nativeAddonSource: \"inline\",\n })\n return statSync(outFile).size\n}\n\n/**\n * Produces a single executable at {@link AssembleSeaOptions.outFile} and\n * returns its size in bytes. Requires network access on first run unless\n * postject is already in the npx cache.\n */\nexport const assembleSea = async (\n options: AssembleSeaOptions,\n): Promise<number> => {\n const { appRoot, jsbundlePath, outFile } = options\n const workDir = options.workDir ?? dirname(jsbundlePath)\n mkdirSync(workDir, { recursive: true })\n mkdirSync(dirname(outFile), { recursive: true })\n\n console.warn(\"[react-native-gtkx] bundling for a single executable…\")\n const bundlePath = join(workDir, \"sea-bundle.cjs\")\n const nativeAddon = await bundleMetroSea({\n appRoot,\n jsbundlePath,\n outFile: bundlePath,\n })\n console.warn(`[react-native-gtkx] native addon: ${nativeAddon.path}`)\n\n const configPath = join(workDir, \"sea-config.json\")\n writeFileSync(\n configPath,\n `${JSON.stringify(\n {\n main: bundlePath,\n output: join(workDir, \"sea-prep.blob\"),\n disableExperimentalSEAWarning: true,\n assets: { [nativeAddon.key]: nativeAddon.path },\n },\n null,\n 2,\n )}\\n`,\n )\n\n console.warn(\"[react-native-gtkx] generating the SEA blob…\")\n run(process.execPath, [\"--experimental-sea-config\", configPath])\n\n console.warn(\"[react-native-gtkx] copying the node binary…\")\n copyFileSync(process.execPath, outFile)\n if (process.platform === \"darwin\") {\n // The copy inherits a signature that no longer matches once the blob\n // is injected; macOS refuses to exec it until the signature is gone.\n run(\"codesign\", [\"--remove-signature\", outFile])\n }\n stripSymbols(outFile)\n\n console.warn(\"[react-native-gtkx] injecting the SEA blob…\")\n run(\"npx\", [\n \"--yes\",\n \"--ignore-scripts\",\n POSTJECT,\n outFile,\n \"NODE_SEA_BLOB\",\n join(workDir, \"sea-prep.blob\"),\n \"--sentinel-fuse\",\n SENTINEL_FUSE,\n ])\n\n chmodSync(outFile, 0o755)\n return statSync(outFile).size\n}\n"]}
1
+ {"version":3,"file":"assemble.js","sourceRoot":"","sources":["../../src/sea/assemble.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,0EAA0E;AAC1E,wEAAwE;AACxE,wDAAwD;AACxD,EAAE;AACF,wEAAwE;AACxE,0EAA0E;AAC1E,2CAA2C;AAC3C,EAAE;AACF,yEAAyE;AACzE,mEAAmE;AACnE,gDAAgD;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EACL,SAAS,EACT,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EACL,yBAAyB,EACzB,cAAc,EACd,sBAAsB,EACtB,6BAA6B,GAC9B,MAAM,aAAa,CAAA;AAEpB,4EAA4E;AAC5E,MAAM,aAAa,GAAG,gDAAgD,CAAA;AAEtE,8EAA8E;AAC9E,MAAM,QAAQ,GAAG,wBAAwB,CAAA;AAczC,MAAM,GAAG,GAAG,CAAC,OAAe,EAAE,IAAc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AE,KAAK,CAAC,CAAA;IACzB,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,CAAA;AAC/B,CAAC,CAAA","sourcesContent":["// Turns a Metro-built app into ONE executable file: bundle everything into\n// a CJS entry (./bundle.ts), generate a SEA blob from it, then inject that\n// blob into a copy of the `node` binary. This is the whole of what \"SEA\"\n// means — Node's Single Executable Application format is literally a copy\n// of the node binary with a V8 code-cache blob appended, which is why the\n// result necessarily carries Node's own weight (~117 MB on linux-arm64,\n// against <7 MB for the app code and its native addon).\n//\n// Follows gtkx's own tutorial (gtkx-org/gtkx examples/tutorial/scripts/\n// build-sea.sh) for these mechanics; ./bundle.ts's header documents where\n// the bundling half deliberately diverges.\n//\n// Kept out of ../runner/index.ts and reached through a dynamic import so\n// the bundler is only loaded when a SEA is actually asked for; the\n// ordinary `build-linux` path never touches it.\nimport { spawnSync } from \"node:child_process\"\nimport {\n chmodSync,\n copyFileSync,\n mkdirSync,\n statSync,\n writeFileSync,\n} from \"node:fs\"\nimport { dirname, join } from \"node:path\"\nimport {\n BUNDLED_PACKAGES_FILENAME,\n bundleMetroSea,\n collectBundledPackages,\n renderBundledPackagesManifest,\n} from \"./bundle.js\"\n\n/** The fuse postject looks for inside the node binary to place the blob. */\nconst SENTINEL_FUSE = \"NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2\"\n\n/** Pinned: postject has no stable release, and the SEA docs name this one. */\nconst POSTJECT = \"postject@1.0.0-alpha.6\"\n\nexport type AssembleSeaOptions = {\n /** The app root — where gtkx.config.ts and package.json live. */\n appRoot: string\n /** The release jsbundle `build-linux` just wrote. */\n jsbundlePath: string\n /** Where the finished executable is written. */\n outFile: string\n /** Scratch directory for the intermediate CJS bundle, the SEA config and\n * the prep blob (default: alongside the jsbundle). */\n workDir?: string\n}\n\nconst run = (command: string, args: string[]): void => {\n const result = spawnSync(command, args, { stdio: \"inherit\" })\n if (result.error) {\n throw result.error\n }\n if (result.status !== 0) {\n throw new Error(`${command} ${args.join(\" \")} exited with ${result.status}`)\n }\n}\n\n/**\n * Drops the debug symbols from the copied Node binary. Worth a step of its\n * own because the saving is not marginal: the `node` binary distributed by\n * NodeSource for Ubuntu ships `with debug_info, not stripped` — measured at\n * 117 MB, and 98 MB after `strip --strip-all`. Nothing in a SEA needs those\n * symbols; the only cost is that a crash inside Node's own C++ produces an\n * unsymbolicated backtrace.\n *\n * Runs BEFORE postject, never after: `--strip-all` removes non-allocated\n * sections, which is exactly what the injected NODE_SEA_BLOB is.\n *\n * Best-effort — a build machine without binutils still produces a working\n * (larger) executable rather than failing, so this cannot become a new\n * install requirement for a build that worked yesterday.\n */\nconst stripSymbols = (file: string): void => {\n const before = statSync(file).size\n const result = spawnSync(\"strip\", [\"--strip-all\", file], {\n stdio: [\"ignore\", \"ignore\", \"pipe\"],\n })\n if (result.error || result.status !== 0) {\n console.warn(\n \"[react-native-gtkx] skipped stripping symbols (no usable `strip`) — \" +\n \"the executable will be tens of MB larger than it needs to be\",\n )\n return\n }\n const saved = (before - statSync(file).size) / 1024 / 1024\n console.warn(\n `[react-native-gtkx] stripped debug symbols (-${saved.toFixed(0)} MB)`,\n )\n}\n\n/**\n * Produces the middle artifact: one self-contained CJS file with the app,\n * its whole node_modules closure and the native addon inlined, run by a\n * system `node`. Everything the SEA is except the embedded Node runtime —\n * so ~120 MB smaller, at the cost of a `nodejs` dependency to declare.\n * Returns its size in bytes.\n *\n * `shouldWritePackageManifest` is for deploy-linux's own Metro-path staging\n * (../runner/index.ts): `gtkx deploy` requires a `gtkx-packages.json` inside\n * `dist/` before it will package anything, vite-built or not (its\n * third-party-notices step reads it unconditionally, --skip-build included)\n * — writing it here, from the real module graph this bundling step just\n * produced, is cheap and accurate; an ordinary `build-linux --standalone`\n * has no use for it, so it stays off by default.\n */\nexport const bundleStandalone = async (options: {\n appRoot: string\n jsbundlePath: string\n outFile: string\n shouldWritePackageManifest?: boolean\n}): Promise<number> => {\n const { appRoot, jsbundlePath, outFile } = options\n mkdirSync(dirname(outFile), { recursive: true })\n console.warn(\"[react-native-gtkx] bundling a standalone script…\")\n const { moduleIds } = await bundleMetroSea({\n appRoot,\n jsbundlePath,\n outFile,\n nativeAddonSource: \"inline\",\n })\n if (options.shouldWritePackageManifest) {\n const distDir = dirname(outFile)\n const packages = collectBundledPackages(moduleIds, distDir)\n writeFileSync(\n join(distDir, BUNDLED_PACKAGES_FILENAME),\n renderBundledPackagesManifest(packages),\n )\n }\n return statSync(outFile).size\n}\n\n/**\n * Produces a single executable at {@link AssembleSeaOptions.outFile} and\n * returns its size in bytes. Requires network access on first run unless\n * postject is already in the npx cache.\n */\nexport const assembleSea = async (\n options: AssembleSeaOptions,\n): Promise<number> => {\n const { appRoot, jsbundlePath, outFile } = options\n const workDir = options.workDir ?? dirname(jsbundlePath)\n mkdirSync(workDir, { recursive: true })\n mkdirSync(dirname(outFile), { recursive: true })\n\n console.warn(\"[react-native-gtkx] bundling for a single executable…\")\n const bundlePath = join(workDir, \"sea-bundle.cjs\")\n const { nativeAddon } = await bundleMetroSea({\n appRoot,\n jsbundlePath,\n outFile: bundlePath,\n })\n console.warn(`[react-native-gtkx] native addon: ${nativeAddon.path}`)\n\n const configPath = join(workDir, \"sea-config.json\")\n writeFileSync(\n configPath,\n `${JSON.stringify(\n {\n main: bundlePath,\n output: join(workDir, \"sea-prep.blob\"),\n disableExperimentalSEAWarning: true,\n assets: { [nativeAddon.key]: nativeAddon.path },\n },\n null,\n 2,\n )}\\n`,\n )\n\n console.warn(\"[react-native-gtkx] generating the SEA blob…\")\n run(process.execPath, [\"--experimental-sea-config\", configPath])\n\n console.warn(\"[react-native-gtkx] copying the node binary…\")\n copyFileSync(process.execPath, outFile)\n if (process.platform === \"darwin\") {\n // The copy inherits a signature that no longer matches once the blob\n // is injected; macOS refuses to exec it until the signature is gone.\n run(\"codesign\", [\"--remove-signature\", outFile])\n }\n stripSymbols(outFile)\n\n console.warn(\"[react-native-gtkx] injecting the SEA blob…\")\n run(\"npx\", [\n \"--yes\",\n \"--ignore-scripts\",\n POSTJECT,\n outFile,\n \"NODE_SEA_BLOB\",\n join(workDir, \"sea-prep.blob\"),\n \"--sentinel-fuse\",\n SENTINEL_FUSE,\n ])\n\n chmodSync(outFile, 0o755)\n return statSync(outFile).size\n}\n"]}
@@ -28,6 +28,35 @@ export type NativeAddonAsset = {
28
28
  * architecture with no error until the app actually launches.
29
29
  */
30
30
  export declare const resolveNativeAddon: (appRoot: string) => NativeAddonAsset;
31
+ /** One entry of the "which real npm package does this bundled code come
32
+ * from" manifest — see {@link collectBundledPackages}. */
33
+ export type BundledPackageRecord = {
34
+ name: string;
35
+ version: string | null;
36
+ /** Relative to whatever directory the manifest itself is written into. */
37
+ dir: string;
38
+ };
39
+ /** The exact filename `gtkx deploy`'s third-party-notices step reads —
40
+ * @gtkx/cli's own `gtkx:bundled-packages` vite plugin writes it as a build
41
+ * artifact of `gtkx build`, but is not part of @gtkx/cli's public API, so
42
+ * the name is duplicated here rather than imported (see
43
+ * @gtkx/cli/src/vite-plugins/bundled-packages.ts and
44
+ * src/deploy/notices/packages.ts for the two ends this mirrors). */
45
+ export declare const BUNDLED_PACKAGES_FILENAME = "gtkx-packages.json";
46
+ /**
47
+ * Mirrors @gtkx/cli's own `gtkx:bundled-packages` vite plugin: for every
48
+ * real module id rolldown pulled into the bundle, records which real npm
49
+ * package it came from (name/version, deduped, plus the package's real
50
+ * directory so `gtkx deploy`'s third-party-notices step can still read its
51
+ * LICENSE/copyright text later — same as it does for a vite build). `gtkx
52
+ * deploy --skip-build` requires this file to exist under `dist/` regardless
53
+ * of toolchain (its own build-skip check runs after this one), so the
54
+ * Metro deploy path needs a real, non-empty answer here, not a stub.
55
+ */
56
+ export declare const collectBundledPackages: (moduleIds: string[], distDir: string) => BundledPackageRecord[];
57
+ /** Renders {@link collectBundledPackages}' output in the exact shape
58
+ * @gtkx/cli's notice-reading side parses (`{ packages: [...] }`). */
59
+ export declare const renderBundledPackagesManifest: (packages: BundledPackageRecord[]) => string;
31
60
  /**
32
61
  * Builds the synthetic SEA entry source: every HOST_MODULE_EXTERNALS name
33
62
  * loaded through a dynamic `import()` (mirroring runner/host.ts's own
@@ -56,6 +85,12 @@ export declare const buildEntrySource: (jsbundlePath: string) => string;
56
85
  * HOST_MODULE_EXTERNALS and gtkx.config.ts's resolved values all inlined,
57
86
  * and the native addon import redirected to the SEA-asset extraction
58
87
  * shim. Returns the native addon that must be embedded as a SEA asset
59
- * under {@link NativeAddonAsset.key} for the result to run.
88
+ * under {@link NativeAddonAsset.key} for the result to run, plus the real
89
+ * module ids rolldown pulled into the bundle — {@link collectBundledPackages}
90
+ * turns those into the third-party-notices manifest a deploy needs (the
91
+ * ordinary --sea/--standalone paths ignore this half of the result).
60
92
  */
61
- export declare const bundleMetroSea: (options: MetroSeaBundleOptions) => Promise<NativeAddonAsset>;
93
+ export declare const bundleMetroSea: (options: MetroSeaBundleOptions) => Promise<{
94
+ nativeAddon: NativeAddonAsset;
95
+ moduleIds: string[];
96
+ }>;