@ipab/cli 0.1.0-rc.7 → 0.1.0-rc.8

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 (95) hide show
  1. package/README.md +24 -1
  2. package/dist/app-authoring.d.ts.map +1 -1
  3. package/dist/app-authoring.js +2 -44
  4. package/dist/app-authoring.js.map +1 -1
  5. package/dist/app-prebuild.d.ts +18 -0
  6. package/dist/app-prebuild.d.ts.map +1 -1
  7. package/dist/app-prebuild.js +46 -0
  8. package/dist/app-prebuild.js.map +1 -1
  9. package/dist/builtins/skill.ipab.car +0 -0
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +290 -152
  12. package/dist/cli.js.map +1 -1
  13. package/dist/config.d.ts +1 -1
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/config.js +9 -4
  16. package/dist/config.js.map +1 -1
  17. package/dist/context.d.ts +4 -0
  18. package/dist/context.d.ts.map +1 -1
  19. package/dist/context.js +11 -2
  20. package/dist/context.js.map +1 -1
  21. package/dist/errors.d.ts +1 -8
  22. package/dist/errors.d.ts.map +1 -1
  23. package/dist/errors.js +1 -20
  24. package/dist/errors.js.map +1 -1
  25. package/dist/host-error.d.ts +9 -0
  26. package/dist/host-error.d.ts.map +1 -0
  27. package/dist/host-error.js +21 -0
  28. package/dist/host-error.js.map +1 -0
  29. package/dist/ipc.d.ts.map +1 -1
  30. package/dist/ipc.js +17 -0
  31. package/dist/ipc.js.map +1 -1
  32. package/dist/kubo-install.js +1 -1
  33. package/dist/kubo-install.js.map +1 -1
  34. package/dist/kubo-peers.d.ts.map +1 -1
  35. package/dist/kubo-peers.js +2 -1
  36. package/dist/kubo-peers.js.map +1 -1
  37. package/dist/kubo-topology.d.ts +19 -0
  38. package/dist/kubo-topology.d.ts.map +1 -0
  39. package/dist/kubo-topology.js +105 -0
  40. package/dist/kubo-topology.js.map +1 -0
  41. package/dist/kubo.d.ts +10 -0
  42. package/dist/kubo.d.ts.map +1 -1
  43. package/dist/kubo.js +96 -15
  44. package/dist/kubo.js.map +1 -1
  45. package/dist/space-path.d.ts +3 -0
  46. package/dist/space-path.d.ts.map +1 -0
  47. package/dist/space-path.js +17 -0
  48. package/dist/space-path.js.map +1 -0
  49. package/dist/space.d.ts +1 -2
  50. package/dist/space.d.ts.map +1 -1
  51. package/dist/space.js +2 -15
  52. package/dist/space.js.map +1 -1
  53. package/dist/state-storage.js +1 -1
  54. package/dist/state-storage.js.map +1 -1
  55. package/dist/state.d.ts +2 -0
  56. package/dist/state.d.ts.map +1 -1
  57. package/dist/state.js +31 -12
  58. package/dist/state.js.map +1 -1
  59. package/dist/swarm-files.d.ts +1 -1
  60. package/dist/swarm-files.d.ts.map +1 -1
  61. package/dist/swarm-files.js +2 -2
  62. package/dist/swarm-files.js.map +1 -1
  63. package/dist/swarm-meta.d.ts +1 -4
  64. package/dist/swarm-meta.d.ts.map +1 -1
  65. package/dist/swarm-meta.js +3 -34
  66. package/dist/swarm-meta.js.map +1 -1
  67. package/dist/swarm-observations.d.ts +40 -0
  68. package/dist/swarm-observations.d.ts.map +1 -0
  69. package/dist/swarm-observations.js +262 -0
  70. package/dist/swarm-observations.js.map +1 -0
  71. package/dist/swarm.d.ts +119 -6
  72. package/dist/swarm.d.ts.map +1 -1
  73. package/dist/swarm.js +662 -80
  74. package/dist/swarm.js.map +1 -1
  75. package/package.json +4 -4
  76. package/src/app-authoring.ts +12 -53
  77. package/src/app-prebuild.ts +61 -0
  78. package/src/cli.ts +370 -190
  79. package/src/config.ts +12 -4
  80. package/src/context.ts +15 -2
  81. package/src/errors.ts +1 -25
  82. package/src/host-error.ts +26 -0
  83. package/src/ipc.ts +19 -0
  84. package/src/kubo-install.ts +1 -1
  85. package/src/kubo-peers.ts +2 -3
  86. package/src/kubo-topology.ts +135 -0
  87. package/src/kubo.ts +134 -25
  88. package/src/space-path.ts +30 -0
  89. package/src/space.ts +2 -28
  90. package/src/state-storage.ts +1 -1
  91. package/src/state.ts +37 -12
  92. package/src/swarm-files.ts +2 -1
  93. package/src/swarm-meta.ts +15 -34
  94. package/src/swarm-observations.ts +374 -0
  95. package/src/swarm.ts +942 -91
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ipab/cli",
3
- "version": "0.1.0-rc.7",
3
+ "version": "0.1.0-rc.8",
4
4
  "private": false,
5
5
  "description": "Node subprocess IPAB host.",
6
6
  "type": "module",
@@ -44,11 +44,11 @@
44
44
  "liquidjs": "10.30.1",
45
45
  "@ipab/web-app": "0.1.0-rc.4",
46
46
  "esbuild": "0.28.2",
47
- "@ipab/bundle-builder": "0.1.0-rc.7",
47
+ "@ipab/bundle-builder": "0.1.0-rc.8",
48
48
  "@ipld/car": "5.4.6",
49
49
  "@ipld/dag-pb": "4.2.0",
50
- "@ipab/bundle": "0.1.0-rc.7",
51
- "@ipab/ipfs-store": "0.1.0-rc.3",
50
+ "@ipab/bundle": "0.1.0-rc.8",
51
+ "@ipab/ipfs-store": "0.1.0-rc.4",
52
52
  "ipfs-unixfs": "13.1.2",
53
53
  "ipfs-unixfs-importer": "17.1.1",
54
54
  "multiformats": "14.0.5",
@@ -1,6 +1,5 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { lstat, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
3
- import { isBuiltin } from "node:module";
4
3
  import {
5
4
  basename,
6
5
  dirname,
@@ -11,7 +10,6 @@ import {
11
10
  sep,
12
11
  } from "node:path";
13
12
  import { StringDecoder } from "node:string_decoder";
14
- import { compileFunction } from "node:vm";
15
13
  import { stringify } from "yaml";
16
14
  import { parseData, type BundleType } from "@ipab/bundle";
17
15
  import { filesystemTree } from "@ipab/bundle-builder/node";
@@ -37,7 +35,12 @@ import {
37
35
  builtinAppSchema,
38
36
  } from "./app-definition.js";
39
37
  import { appTemplate } from "./app-templates.js";
40
- import { buildChain, projectBuild, runPrebuild } from "./app-prebuild.js";
38
+ import {
39
+ buildChain,
40
+ compileAppProgram,
41
+ projectBuild,
42
+ runPrebuild,
43
+ } from "./app-prebuild.js";
41
44
  import { captureSource, sourceFingerprint } from "./source-bundle.js";
42
45
  export { appSchema } from "./app-definition.js";
43
46
 
@@ -439,7 +442,6 @@ export async function buildApp(
439
442
  options.signal?.throwIfAborted();
440
443
  const stage = await mkdtemp(join(root, ".ipab-app-"));
441
444
  try {
442
- const { build } = await import("esbuild");
443
445
  const bundleStage = join(stage, "bundle");
444
446
  const input = prebuild ? join(stage, "input") : root;
445
447
  if (prebuild) {
@@ -450,56 +452,13 @@ export async function buildApp(
450
452
  const prebuiltSource = prebuild
451
453
  ? await readBytes(inputTree, entry, 8 * 1024 * 1024, options)
452
454
  : undefined;
453
- if (prebuiltSource) {
454
- try {
455
- const source = new TextDecoder("utf-8", { fatal: true }).decode(
456
- prebuiltSource,
457
- );
458
- compileFunction(source.replace(/^#![^\r\n]*/, ""), [
459
- "exports",
460
- "require",
461
- "module",
462
- "__filename",
463
- "__dirname",
464
- ]);
465
- } catch (cause) {
466
- const error = new HostError(
467
- "Prebuilt App entry must be valid Node CommonJS; it is packaged without transformation.",
468
- );
469
- error.cause = cause;
470
- throw error;
471
- }
472
- }
473
455
  await mkdir(join(bundleStage, "resources"), { recursive: true });
474
- const program = await build({
475
- absWorkingDir: input,
476
- entryPoints: [entry],
477
- outfile: join(bundleStage, "resources", "app.cjs"),
478
- bundle: true,
479
- platform: "node",
480
- format: "cjs",
481
- target: "node22.15",
482
- packages: prebuild ? "external" : "bundle",
483
- metafile: true,
484
- write: false,
485
- logLevel: "silent",
486
- logOverride: {
487
- "unsupported-dynamic-import": "error",
488
- "unsupported-require-call": "error",
489
- "indirect-require": "error",
490
- },
491
- });
492
- if (
493
- program.outputFiles.length !== 1 ||
494
- program.outputFiles[0]!.contents.length > 8 * 1024 * 1024 ||
495
- (prebuild && Object.keys(program.metafile.inputs).length !== 1) ||
496
- Object.values(program.metafile.outputs).some((file) =>
497
- file.imports.some((item) => item.external && !isBuiltin(item.path)),
498
- )
499
- )
500
- throw new HostError(
501
- "App must bundle into one self-contained .cjs of at most 8 MiB; only Node builtins may remain external.",
502
- );
456
+ const program = await compileAppProgram(
457
+ input,
458
+ entry,
459
+ join(bundleStage, "resources", "app.cjs"),
460
+ prebuiltSource,
461
+ );
503
462
  if (sourceFiles && !prebuild)
504
463
  for (const path of Object.keys(program.metafile.inputs))
505
464
  if (
@@ -3,10 +3,71 @@ import { lstat, readFile, realpath } from "node:fs/promises";
3
3
  import { basename, delimiter, dirname, join, resolve } from "node:path";
4
4
  import { promisify } from "node:util";
5
5
  import { StringDecoder } from "node:string_decoder";
6
+ import { isBuiltin } from "node:module";
7
+ import { compileFunction } from "node:vm";
6
8
  import { HostError, object } from "./errors.js";
7
9
  import { nodeError, type AuthoringOptions } from "./authoring.js";
8
10
  import { relativePath } from "./space.js";
9
11
 
12
+ export async function compileAppProgram(
13
+ input: string,
14
+ entry: string,
15
+ outfile: string,
16
+ prebuiltSource?: Uint8Array,
17
+ ) {
18
+ if (prebuiltSource) {
19
+ try {
20
+ const source = new TextDecoder("utf-8", { fatal: true }).decode(
21
+ prebuiltSource,
22
+ );
23
+ compileFunction(source.replace(/^#![^\r\n]*/, ""), [
24
+ "exports",
25
+ "require",
26
+ "module",
27
+ "__filename",
28
+ "__dirname",
29
+ ]);
30
+ } catch (cause) {
31
+ const error = new HostError(
32
+ "Prebuilt App entry must be valid Node CommonJS; it is packaged without transformation.",
33
+ );
34
+ error.cause = cause;
35
+ throw error;
36
+ }
37
+ }
38
+ const { build } = await import("esbuild");
39
+ const program = await build({
40
+ absWorkingDir: input,
41
+ entryPoints: [entry],
42
+ outfile,
43
+ bundle: true,
44
+ platform: "node",
45
+ format: "cjs",
46
+ target: "node22.15",
47
+ packages: prebuiltSource ? "external" : "bundle",
48
+ metafile: true,
49
+ write: false,
50
+ logLevel: "silent",
51
+ logOverride: {
52
+ "unsupported-dynamic-import": "error",
53
+ "unsupported-require-call": "error",
54
+ "indirect-require": "error",
55
+ },
56
+ });
57
+ if (
58
+ program.outputFiles.length !== 1 ||
59
+ program.outputFiles[0]!.contents.length > 8 * 1024 * 1024 ||
60
+ (prebuiltSource && Object.keys(program.metafile.inputs).length !== 1) ||
61
+ Object.values(program.metafile.outputs).some((file) =>
62
+ file.imports.some((item) => item.external && !isBuiltin(item.path)),
63
+ )
64
+ )
65
+ throw new HostError(
66
+ "App must bundle into one self-contained .cjs of at most 8 MiB; only Node builtins may remain external.",
67
+ );
68
+ return program;
69
+ }
70
+
10
71
  export interface ProjectBuild {
11
72
  strategy: "ipab-prebuild";
12
73
  typecheck: { config: string; entry: string }[];