@pylonsync/functions 0.3.258 → 0.3.261

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/runtime.ts +22 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/functions",
3
- "version": "0.3.258",
3
+ "version": "0.3.261",
4
4
  "description": "TypeScript function runtime for pylon — defines server-side queries, mutations, and actions.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/runtime.ts CHANGED
@@ -942,12 +942,12 @@ async function main() {
942
942
  (f) => f.endsWith(".ts") || f.endsWith(".js")
943
943
  );
944
944
  } catch {
945
- send({
946
- type: "ready",
947
- functions: [],
948
- error: `Cannot read functions directory: ${fnDir}`,
949
- });
950
- return;
945
+ // No `functions/` directory. Legitimate for a pure-SSR app (file-based
946
+ // `app/**/page.tsx` routes + entity CRUD, no server functions) — the host
947
+ // still spawns this runner to execute SSR renders. Load zero functions and
948
+ // fall through so we send `ready` AND start the reader loop; returning here
949
+ // would leave the runner unable to serve renders (silent 404s).
950
+ files = [];
951
951
  }
952
952
 
953
953
  for (const file of files) {
@@ -989,7 +989,23 @@ async function main() {
989
989
  }));
990
990
  send({ type: "ready", functions });
991
991
 
992
+ // Belt-and-suspenders against orphaning: if the host dies in a way that
993
+ // somehow leaves our stdin open, we'll have been reparented to init
994
+ // (ppid === 1). Notice and exit. Unref'd so it never keeps us alive on its
995
+ // own.
996
+ const orphanWatch = setInterval(() => {
997
+ if (process.ppid === 1) process.exit(0);
998
+ }, 2000);
999
+ if (typeof orphanWatch.unref === "function") orphanWatch.unref();
1000
+
992
1001
  await readerLoop();
1002
+
1003
+ // readerLoop only returns when stdin hits EOF — i.e. the host (the pylon
1004
+ // process that spawned us) is gone. Force-exit. We must NOT rely on the
1005
+ // event loop draining on its own: the stdout writer, keep-alive sockets
1006
+ // from `fetch`, and Bun's own handles keep the process alive, so every
1007
+ // killed `pylon dev` would otherwise orphan its whole bun runner pool.
1008
+ process.exit(0);
993
1009
  }
994
1010
 
995
1011
  main().catch((err) => {