@fungi.computer/oyster 0.19.25 → 0.19.27

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.
@@ -245,7 +245,7 @@ export class ComputerDO extends NativeComputerDO {
245
245
  return { terminal: "ready" };
246
246
  return {
247
247
  terminal: "missing",
248
- terminalReason: "No Computer runtime is connected. Restart oyster try on a machine with a supported Workspace sandbox.",
248
+ terminalReason: "The local command runner is not connected. Restart oyster try in your terminal.",
249
249
  };
250
250
  }
251
251
  /** Observe an admitted fleet Computer without starting its backend. */
@@ -80,6 +80,7 @@ export type TryEffects = Readonly<{
80
80
  export type Manager = "npm" | "pnpm";
81
81
  /** pnpm when it ran this command (`pnpm dlx`), otherwise npm. */
82
82
  export declare function detectManager(userAgent: string | undefined): "pnpm" | "npm";
83
+ export declare function installTryDependencies(directory: string, manager: Manager, verbose: boolean, signal: AbortSignal): Promise<void>;
83
84
  /**
84
85
  * `wrangler dev` for one local Oyster. The devtools inspector takes a port the
85
86
  * kernel assigns (0): wrangler's default probes 9229 upward and binds it later,
@@ -3,7 +3,7 @@
3
3
  // config this package ships, plus a package.json), installs it with the
4
4
  // caller's package manager, runs `wrangler dev` locally, installs the Hello
5
5
  // App and opens the browser. Running it again in the same directory restarts
6
- // the server without scaffolding again.
6
+ // the server after refreshing the generated project files and dependencies.
7
7
  //
8
8
  // npx @fungi.computer/oyster try [directory] [--port 8787] [--no-open] [--verbose]
9
9
  //
@@ -20,7 +20,7 @@ import { runGit } from "../build/local-build.js";
20
20
  import { CleanupError, stopProcessGroup, awaitCleanup, } from "../build/process-group.js";
21
21
  import { InstallationObservationError } from "../installation-client.js";
22
22
  import { createWriteStream } from "node:fs";
23
- import { copyFile, mkdir, mkdtemp, rename, readdir, rm, readFile, stat, writeFile, } from "node:fs/promises";
23
+ import { mkdir, mkdtemp, rename, readdir, rm, readFile, stat, writeFile, } from "node:fs/promises";
24
24
  import { createServer } from "node:net";
25
25
  import { basename, dirname, delimiter, join, resolve } from "node:path";
26
26
  import process from "node:process";
@@ -39,7 +39,8 @@ const tryHelp = `${tryUsage}
39
39
  Creates ./my-oyster (or <directory>) with a local Oyster, installs it, starts it
40
40
  on http://127.0.0.1:<port> and installs a Hello App from <directory>/hello-app,
41
41
  a git repository you can edit. Commit an edit and run this again, from inside
42
- that directory or by naming it, to restart and reinstall without scaffolding.
42
+ that directory or by naming it, to restart with the current Oyster. Generated
43
+ configuration is refreshed; your app source and owner key are kept.
43
44
  Press Ctrl-C to stop.
44
45
 
45
46
  Options:
@@ -117,7 +118,8 @@ export function createTryCli(args) {
117
118
  function innermostError(cause) {
118
119
  let current = cause instanceof Error ? cause : new Error(String(cause));
119
120
  for (let depth = 0; depth < 10; depth += 1) {
120
- if (!(current.cause instanceof Error))
121
+ // An aggregate has multiple causes; its summary preserves both failures.
122
+ if (current instanceof AggregateError || !(current.cause instanceof Error))
121
123
  break;
122
124
  current = current.cause;
123
125
  }
@@ -195,19 +197,36 @@ const pnpmWorkspace = `allowBuilds:
195
197
  async function exists(path) {
196
198
  return stat(path).then(() => true, () => false);
197
199
  }
200
+ /** Refresh only try-owned configuration; app sources and owner custody stay put. */
201
+ async function refreshProject(directory, own, spec, manager, signal) {
202
+ const examples = join(import.meta.dirname, "../../examples/standalone");
203
+ const files = new Map([
204
+ ["worker.ts", await readFile(join(examples, "worker.ts"), "utf8")],
205
+ [
206
+ "wrangler.jsonc",
207
+ await readFile(join(examples, "wrangler.jsonc"), "utf8"),
208
+ ],
209
+ ["package.json", projectManifest(own, spec)],
210
+ ]);
211
+ if (manager === "pnpm")
212
+ files.set("pnpm-workspace.yaml", pnpmWorkspace);
213
+ for (const [name, content] of files) {
214
+ signal.throwIfAborted();
215
+ const path = join(directory, name);
216
+ if ((await exists(path)) && (await readFile(path, "utf8")) === content)
217
+ continue;
218
+ // Mark before the first change, so an interrupted refresh/install is retried.
219
+ await mkdir(join(directory, ".oyster"), { recursive: true });
220
+ await writeFile(join(directory, pendingInstall), "Dependencies have not finished installing.\n");
221
+ await writeFile(path, content);
222
+ }
223
+ }
198
224
  async function scaffold(directory, own, spec, manager, signal) {
199
225
  signal.throwIfAborted();
200
226
  await mkdir(dirname(directory), { recursive: true });
201
227
  const stage = await mkdtemp(join(dirname(directory), ".oyster-try-"));
202
228
  try {
203
- const examples = join(import.meta.dirname, "../../examples/standalone");
204
- for (const name of ["worker.ts", "wrangler.jsonc"]) {
205
- signal.throwIfAborted();
206
- await copyFile(join(examples, name), join(stage, name));
207
- }
208
- await writeFile(join(stage, "package.json"), projectManifest(own, spec));
209
- if (manager === "pnpm")
210
- await writeFile(join(stage, "pnpm-workspace.yaml"), pnpmWorkspace);
229
+ await refreshProject(stage, own, spec, manager, signal);
211
230
  await writeFile(join(stage, ".gitignore"), ".oyster/\n.wrangler/\nnode_modules/\n.oyster-owner\n");
212
231
  const key = Array.from(randomBytes(24), (byte) => byte.toString(16).padStart(2, "0")).join("");
213
232
  await writeFile(join(stage, ownerKeyFile), key + "\n", {
@@ -270,7 +289,7 @@ function npmFailureCode(output) {
270
289
  return undefined;
271
290
  }
272
291
  }
273
- async function runInstall(directory, manager, verbose, signal) {
292
+ export async function installTryDependencies(directory, manager, verbose, signal) {
274
293
  signal.throwIfAborted();
275
294
  await mkdir(join(directory, ".oyster"), { recursive: true });
276
295
  signal.throwIfAborted();
@@ -284,7 +303,12 @@ async function runInstall(directory, manager, verbose, signal) {
284
303
  ]));
285
304
  const stop = () => awaitCleanup(beginStop());
286
305
  try {
287
- child = spawn(manager, manager === "npm" ? ["install", "--json"] : ["install"], {
306
+ child = spawn(manager,
307
+ // Refresh tag dependencies such as Truffle too: install alone can retain
308
+ // their old locked version even after Oyster itself is upgraded.
309
+ manager === "npm"
310
+ ? ["update", "--no-save", "--json"]
311
+ : ["update", "--no-save"], {
288
312
  cwd: directory,
289
313
  detached: process.platform !== "win32",
290
314
  signal,
@@ -315,7 +339,7 @@ async function runInstall(directory, manager, verbose, signal) {
315
339
  done();
316
340
  else {
317
341
  const errorCode = npmFailureCode(diagnostic);
318
- fail(Object.assign(new Error(`${manager} install failed (${errorCode === undefined ? "" : `${errorCode}; `}exit ${String(code)}).`), { code: errorCode }));
342
+ fail(Object.assign(new Error(`${manager} update failed (${errorCode === undefined ? "" : `${errorCode}; `}exit ${String(code)}).`), { code: errorCode }));
319
343
  }
320
344
  });
321
345
  });
@@ -481,13 +505,17 @@ function startWrangler(input) {
481
505
  : readiness === "exited"
482
506
  ? `Oyster stopped before readiness (${child.signalCode === null ? `exit ${String(child.exitCode)}` : `signal ${child.signalCode}`}).`
483
507
  : "Oyster did not answer within 120 seconds.";
484
- await stop();
485
508
  throw new TryError(diagnostic, `Read ${log} for the server output.`);
486
509
  }
487
510
  return { stop, exited };
488
511
  }
489
512
  catch (cause) {
490
- await stop();
513
+ try {
514
+ await stop();
515
+ }
516
+ catch (cleanup) {
517
+ throw new AggregateError([cause, cleanup], `${innermostError(cause).message} Cleanup also failed: ${innermostError(cleanup).message}`, { cause: cleanup });
518
+ }
491
519
  throw cause;
492
520
  }
493
521
  })();
@@ -520,7 +548,7 @@ function isTryCancellation(cause, signal) {
520
548
  cause instanceof InstallationObservationError));
521
549
  }
522
550
  const realEffects = {
523
- installDependencies: runInstall,
551
+ installDependencies: installTryDependencies,
524
552
  startServer: startWrangler,
525
553
  installHello: installHelloApp,
526
554
  installDesktop: async ({ directory, ...input }) => {
@@ -633,6 +661,10 @@ export async function tryOyster(args, effects = realEffects, ui = createTryCli(a
633
661
  else {
634
662
  key = (await readFile(keyPath, "utf8")).trim();
635
663
  ui.info(`Restarting the Oyster in ${directory}`);
664
+ const manager = (await exists(join(directory, "pnpm-workspace.yaml")))
665
+ ? "pnpm"
666
+ : "npm";
667
+ await task("Refreshing Oyster project", async () => refreshProject(directory, await ownManifest(), values.package, manager, signal));
636
668
  }
637
669
  if (fresh ||
638
670
  (await exists(join(directory, pendingInstall))) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/oyster",
3
- "version": "0.19.25",
3
+ "version": "0.19.27",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Run your own Apps on Cloudflare Workers or celld: installable App Releases, each with its own Durable Object, SQLite database and declared bindings",
6
6
  "type": "module",
@@ -334,7 +334,7 @@
334
334
  "@fungi.computer/burrow": "0.2.1",
335
335
  "@fungi.computer/cairn": "0.1.0",
336
336
  "@fungi.computer/capnweb": "0.12.0-fungi.0",
337
- "@fungi.computer/caps": "0.10.3",
337
+ "@fungi.computer/caps": "0.10.4",
338
338
  "@fungi.computer/carrier": "0.2.4",
339
339
  "@fungi.computer/computer": "0.8.2",
340
340
  "@fungi.computer/computer-contract": "0.1.0",
@@ -346,7 +346,7 @@
346
346
  "@fungi.computer/lantern": "0.4.2",
347
347
  "@fungi.computer/mycelium": "0.3.8",
348
348
  "@fungi.computer/nacre": "0.4.4",
349
- "@fungi.computer/parakeet": "0.11.7",
349
+ "@fungi.computer/parakeet": "0.11.8",
350
350
  "@fungi.computer/puffball": "0.5.5",
351
351
  "@fungi.computer/seam": "0.2.5",
352
352
  "@fungi.computer/shiitake": "0.12.4",