@ipab/cli 0.1.0-rc.1 → 0.1.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -9
- package/dist/app-authoring.d.ts +15 -0
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +144 -58
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-definition.d.ts +52 -57
- package/dist/app-definition.d.ts.map +1 -1
- package/dist/app-definition.js +33 -38
- package/dist/app-definition.js.map +1 -1
- package/dist/app-prebuild.d.ts +18 -0
- package/dist/app-prebuild.d.ts.map +1 -1
- package/dist/app-prebuild.js +46 -0
- package/dist/app-prebuild.js.map +1 -1
- package/dist/app-templates.d.ts +0 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +8 -46
- package/dist/app-templates.js.map +1 -1
- package/dist/assembly.d.ts +7 -0
- package/dist/assembly.d.ts.map +1 -0
- package/dist/assembly.js +130 -0
- package/dist/assembly.js.map +1 -0
- package/dist/authoring.d.ts +7 -8
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +59 -16
- package/dist/authoring.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +1 -23
- package/dist/builtins.js.map +1 -1
- package/dist/bundled-skills.d.ts +14 -0
- package/dist/bundled-skills.d.ts.map +1 -0
- package/dist/bundled-skills.js +34 -0
- package/dist/bundled-skills.js.map +1 -0
- package/dist/cli.d.ts +8 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1967 -258
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.d.ts +3 -0
- package/dist/config-secret.d.ts.map +1 -0
- package/dist/config-secret.js +12 -0
- package/dist/config-secret.js.map +1 -0
- package/dist/config.d.ts +11 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +166 -8
- package/dist/config.js.map +1 -1
- package/dist/content-provider.d.ts +32 -0
- package/dist/content-provider.d.ts.map +1 -0
- package/dist/content-provider.js +222 -0
- package/dist/content-provider.js.map +1 -0
- package/dist/context-types.d.ts +12 -0
- package/dist/context-types.d.ts.map +1 -0
- package/dist/context-types.js +2 -0
- package/dist/context-types.js.map +1 -0
- package/dist/context.d.ts +26 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +54 -10
- package/dist/context.js.map +1 -1
- package/dist/daemon-ui.d.ts +93 -0
- package/dist/daemon-ui.d.ts.map +1 -0
- package/dist/daemon-ui.js +713 -0
- package/dist/daemon-ui.js.map +1 -0
- package/dist/daemon.d.ts +21 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +317 -0
- package/dist/daemon.js.map +1 -0
- package/dist/doctor.d.ts +32 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +688 -0
- package/dist/doctor.js.map +1 -0
- package/dist/errors.d.ts +1 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -20
- package/dist/errors.js.map +1 -1
- package/dist/get.d.ts +3 -0
- package/dist/get.d.ts.map +1 -0
- package/dist/get.js +80 -0
- package/dist/get.js.map +1 -0
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +6 -14
- package/dist/history.js.map +1 -1
- package/dist/host-error.d.ts +9 -0
- package/dist/host-error.d.ts.map +1 -0
- package/dist/host-error.js +21 -0
- package/dist/host-error.js.map +1 -0
- package/dist/identity.d.ts +16 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +119 -0
- package/dist/identity.js.map +1 -0
- package/dist/ipc.d.ts +5 -2
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +124 -12
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.d.ts +26 -0
- package/dist/kubo-install.d.ts.map +1 -0
- package/dist/kubo-install.js +724 -0
- package/dist/kubo-install.js.map +1 -0
- package/dist/kubo-peering.d.ts +11 -0
- package/dist/kubo-peering.d.ts.map +1 -0
- package/dist/kubo-peering.js +93 -0
- package/dist/kubo-peering.js.map +1 -0
- package/dist/kubo-peers.d.ts +12 -0
- package/dist/kubo-peers.d.ts.map +1 -0
- package/dist/kubo-peers.js +119 -0
- package/dist/kubo-peers.js.map +1 -0
- package/dist/kubo-release.d.ts +22 -0
- package/dist/kubo-release.d.ts.map +1 -0
- package/dist/kubo-release.js +176 -0
- package/dist/kubo-release.js.map +1 -0
- package/dist/kubo-topology.d.ts +19 -0
- package/dist/kubo-topology.d.ts.map +1 -0
- package/dist/kubo-topology.js +113 -0
- package/dist/kubo-topology.js.map +1 -0
- package/dist/kubo.d.ts +85 -0
- package/dist/kubo.d.ts.map +1 -0
- package/dist/kubo.js +755 -0
- package/dist/kubo.js.map +1 -0
- package/dist/pins.d.ts +16 -18
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +144 -106
- package/dist/pins.js.map +1 -1
- package/dist/pivot-rpc.d.ts +62 -0
- package/dist/pivot-rpc.d.ts.map +1 -0
- package/dist/pivot-rpc.js +407 -0
- package/dist/pivot-rpc.js.map +1 -0
- package/dist/pivot-service.d.ts +16 -0
- package/dist/pivot-service.d.ts.map +1 -0
- package/dist/pivot-service.js +50 -0
- package/dist/pivot-service.js.map +1 -0
- package/dist/publish-source.d.ts +3 -0
- package/dist/publish-source.d.ts.map +1 -0
- package/dist/publish-source.js +85 -0
- package/dist/publish-source.js.map +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +9 -4
- package/dist/runtime.js.map +1 -1
- package/dist/search-index.d.ts +64 -0
- package/dist/search-index.d.ts.map +1 -0
- package/dist/search-index.js +409 -0
- package/dist/search-index.js.map +1 -0
- package/dist/search-service.d.ts +23 -0
- package/dist/search-service.d.ts.map +1 -0
- package/dist/search-service.js +116 -0
- package/dist/search-service.js.map +1 -0
- package/dist/skill-definition.d.ts +6 -0
- package/dist/skill-definition.d.ts.map +1 -0
- package/dist/skill-definition.js +38 -0
- package/dist/skill-definition.js.map +1 -0
- package/dist/skill-source.d.ts +9 -0
- package/dist/skill-source.d.ts.map +1 -0
- package/dist/skill-source.js +24 -0
- package/dist/skill-source.js.map +1 -0
- package/dist/skills.d.ts +104 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +894 -0
- package/dist/skills.js.map +1 -0
- package/dist/source-bundle.d.ts +3 -8
- package/dist/source-bundle.d.ts.map +1 -1
- package/dist/source-bundle.js +17 -12
- package/dist/source-bundle.js.map +1 -1
- package/dist/space-path.d.ts +3 -0
- package/dist/space-path.d.ts.map +1 -0
- package/dist/space-path.js +17 -0
- package/dist/space-path.js.map +1 -0
- package/dist/space.d.ts +16 -4
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +170 -24
- package/dist/space.js.map +1 -1
- package/dist/state-storage-windows.d.ts +2 -0
- package/dist/state-storage-windows.d.ts.map +1 -0
- package/dist/state-storage-windows.js +114 -0
- package/dist/state-storage-windows.js.map +1 -0
- package/dist/state-storage.d.ts +5 -0
- package/dist/state-storage.d.ts.map +1 -0
- package/dist/state-storage.js +333 -0
- package/dist/state-storage.js.map +1 -0
- package/dist/state.d.ts +135 -13
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +577 -92
- package/dist/state.js.map +1 -1
- package/dist/swarm-envelope.d.ts +57 -0
- package/dist/swarm-envelope.d.ts.map +1 -0
- package/dist/swarm-envelope.js +299 -0
- package/dist/swarm-envelope.js.map +1 -0
- package/dist/swarm-files.d.ts +6 -0
- package/dist/swarm-files.d.ts.map +1 -0
- package/dist/swarm-files.js +116 -0
- package/dist/swarm-files.js.map +1 -0
- package/dist/swarm-meta.d.ts +15 -0
- package/dist/swarm-meta.d.ts.map +1 -0
- package/dist/swarm-meta.js +68 -0
- package/dist/swarm-meta.js.map +1 -0
- package/dist/swarm-observations.d.ts +40 -0
- package/dist/swarm-observations.d.ts.map +1 -0
- package/dist/swarm-observations.js +271 -0
- package/dist/swarm-observations.js.map +1 -0
- package/dist/swarm.d.ts +537 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +4991 -0
- package/dist/swarm.js.map +1 -0
- package/dist/template-definition.d.ts +47 -52
- package/dist/template-definition.d.ts.map +1 -1
- package/dist/template-definition.js +36 -41
- package/dist/template-definition.js.map +1 -1
- package/dist/template-paths.d.ts +7 -0
- package/dist/template-paths.d.ts.map +1 -0
- package/dist/template-paths.js +23 -0
- package/dist/template-paths.js.map +1 -0
- package/dist/template-presentation.d.ts +20 -0
- package/dist/template-presentation.d.ts.map +1 -0
- package/dist/template-presentation.js +133 -0
- package/dist/template-presentation.js.map +1 -0
- package/dist/template-source.d.ts +4 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +11 -4
- package/dist/template-source.js.map +1 -1
- package/dist/templates.d.ts +11 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +53 -0
- package/dist/templates.js.map +1 -0
- package/dist/unixfs-tree.d.ts +67 -0
- package/dist/unixfs-tree.d.ts.map +1 -0
- package/dist/unixfs-tree.js +329 -0
- package/dist/unixfs-tree.js.map +1 -0
- package/package.json +14 -7
- package/src/app-authoring.ts +240 -76
- package/src/app-definition.ts +33 -39
- package/src/app-prebuild.ts +61 -0
- package/src/app-templates.ts +17 -73
- package/src/assembly.ts +185 -0
- package/src/authoring.ts +99 -18
- package/src/builtins.ts +2 -27
- package/src/bundled-skills.ts +60 -0
- package/src/cli.ts +2461 -323
- package/src/config-secret.ts +14 -0
- package/src/config.ts +214 -8
- package/src/content-provider.ts +299 -0
- package/src/context-types.ts +11 -0
- package/src/context.ts +98 -10
- package/src/daemon-ui.ts +812 -0
- package/src/daemon.ts +386 -0
- package/src/doctor.ts +1092 -0
- package/src/errors.ts +1 -25
- package/src/get.ts +91 -0
- package/src/history.ts +5 -15
- package/src/host-error.ts +26 -0
- package/src/identity.ts +175 -0
- package/src/ipc.ts +160 -11
- package/src/kubo-install.ts +936 -0
- package/src/kubo-peering.ts +126 -0
- package/src/kubo-peers.ts +144 -0
- package/src/kubo-release.ts +230 -0
- package/src/kubo-topology.ts +148 -0
- package/src/kubo.ts +1088 -0
- package/src/pins.ts +188 -126
- package/src/pivot-rpc.ts +601 -0
- package/src/pivot-service.ts +87 -0
- package/src/publish-source.ts +103 -0
- package/src/runtime.ts +16 -4
- package/src/search-index.ts +560 -0
- package/src/search-service.ts +152 -0
- package/src/skill-definition.ts +53 -0
- package/src/skill-source.ts +29 -0
- package/src/skills.ts +1236 -0
- package/src/source-bundle.ts +26 -13
- package/src/space-path.ts +30 -0
- package/src/space.ts +230 -42
- package/src/state-storage-windows.ts +134 -0
- package/src/state-storage.ts +378 -0
- package/src/state.ts +875 -108
- package/src/swarm-envelope.ts +461 -0
- package/src/swarm-files.ts +126 -0
- package/src/swarm-meta.ts +98 -0
- package/src/swarm-observations.ts +393 -0
- package/src/swarm.ts +7392 -0
- package/src/template-definition.ts +36 -41
- package/src/template-paths.ts +43 -0
- package/src/template-presentation.ts +151 -0
- package/src/template-source.ts +19 -5
- package/src/templates.ts +77 -0
- package/src/unixfs-tree.ts +401 -0
package/src/app-authoring.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { lstat, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
basename,
|
|
5
|
+
dirname,
|
|
6
|
+
isAbsolute,
|
|
7
|
+
join,
|
|
8
|
+
relative,
|
|
9
|
+
resolve,
|
|
10
|
+
sep,
|
|
11
|
+
} from "node:path";
|
|
5
12
|
import { StringDecoder } from "node:string_decoder";
|
|
6
|
-
import { compileFunction } from "node:vm";
|
|
7
13
|
import { stringify } from "yaml";
|
|
8
|
-
import { parseData } from "@ipab/bundle";
|
|
14
|
+
import { parseData, type BundleType } from "@ipab/bundle";
|
|
9
15
|
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
10
16
|
import { encodeBundleCar, memoryTree, readBytes } from "@ipab/bundle-builder";
|
|
11
17
|
import {
|
|
12
18
|
writeCar,
|
|
13
19
|
outputAvailable,
|
|
20
|
+
readCar,
|
|
14
21
|
scaffoldFiles,
|
|
15
22
|
nodeError,
|
|
16
23
|
type AuthoringOptions,
|
|
@@ -28,10 +35,18 @@ import {
|
|
|
28
35
|
builtinAppSchema,
|
|
29
36
|
} from "./app-definition.js";
|
|
30
37
|
import { appTemplate } from "./app-templates.js";
|
|
31
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
buildChain,
|
|
40
|
+
compileAppProgram,
|
|
41
|
+
projectBuild,
|
|
42
|
+
runPrebuild,
|
|
43
|
+
} from "./app-prebuild.js";
|
|
32
44
|
import { captureSource, sourceFingerprint } from "./source-bundle.js";
|
|
45
|
+
export { appSchema } from "./app-definition.js";
|
|
33
46
|
|
|
34
47
|
const json = (value: unknown) => `${JSON.stringify(value, null, 2)}\n`;
|
|
48
|
+
const sourceTarget = "source";
|
|
49
|
+
const sourceCarInput = "source.car";
|
|
35
50
|
|
|
36
51
|
export async function initApp(
|
|
37
52
|
name: string,
|
|
@@ -187,6 +202,9 @@ export async function buildApp(
|
|
|
187
202
|
outputDir?: string;
|
|
188
203
|
replace?: boolean;
|
|
189
204
|
includeSource?: boolean;
|
|
205
|
+
/** Exact types from an author's Open App definition; exclusive with config paths. */
|
|
206
|
+
supportedTypes?: readonly BundleType[];
|
|
207
|
+
preparedDirectory?: string;
|
|
190
208
|
} = {},
|
|
191
209
|
): Promise<
|
|
192
210
|
Omit<BuildResult, "kind"> & {
|
|
@@ -327,7 +345,19 @@ export async function buildApp(
|
|
|
327
345
|
throw new HostError(
|
|
328
346
|
"App metadata cannot override the generated source declaration.",
|
|
329
347
|
);
|
|
330
|
-
|
|
348
|
+
if (options.supportedTypes && schemas.size)
|
|
349
|
+
throw new HostError(
|
|
350
|
+
"Use either supportedTypes or supportedSchemas paths, not both.",
|
|
351
|
+
);
|
|
352
|
+
const declared = options.supportedTypes?.map(
|
|
353
|
+
(type, index) =>
|
|
354
|
+
[`schemas/${index}.json`, new TextEncoder().encode(json(type))] as const,
|
|
355
|
+
);
|
|
356
|
+
const supportedSchemas = await buildSupportedSchemas(
|
|
357
|
+
declared ? memoryTree(new Map(declared)) : tree,
|
|
358
|
+
declared ? new Set(declared.map(([path]) => path)) : schemas,
|
|
359
|
+
options,
|
|
360
|
+
);
|
|
331
361
|
const description = appDescription({
|
|
332
362
|
...defaults,
|
|
333
363
|
...overrides,
|
|
@@ -412,7 +442,6 @@ export async function buildApp(
|
|
|
412
442
|
options.signal?.throwIfAborted();
|
|
413
443
|
const stage = await mkdtemp(join(root, ".ipab-app-"));
|
|
414
444
|
try {
|
|
415
|
-
const { build } = await import("esbuild");
|
|
416
445
|
const bundleStage = join(stage, "bundle");
|
|
417
446
|
const input = prebuild ? join(stage, "input") : root;
|
|
418
447
|
if (prebuild) {
|
|
@@ -423,56 +452,13 @@ export async function buildApp(
|
|
|
423
452
|
const prebuiltSource = prebuild
|
|
424
453
|
? await readBytes(inputTree, entry, 8 * 1024 * 1024, options)
|
|
425
454
|
: undefined;
|
|
426
|
-
if (prebuiltSource) {
|
|
427
|
-
try {
|
|
428
|
-
const source = new TextDecoder("utf-8", { fatal: true }).decode(
|
|
429
|
-
prebuiltSource,
|
|
430
|
-
);
|
|
431
|
-
compileFunction(source.replace(/^#![^\r\n]*/, ""), [
|
|
432
|
-
"exports",
|
|
433
|
-
"require",
|
|
434
|
-
"module",
|
|
435
|
-
"__filename",
|
|
436
|
-
"__dirname",
|
|
437
|
-
]);
|
|
438
|
-
} catch (cause) {
|
|
439
|
-
const error = new HostError(
|
|
440
|
-
"Prebuilt App entry must be valid Node CommonJS; it is packaged without transformation.",
|
|
441
|
-
);
|
|
442
|
-
error.cause = cause;
|
|
443
|
-
throw error;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
455
|
await mkdir(join(bundleStage, "resources"), { recursive: true });
|
|
447
|
-
const program = await
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
format: "cjs",
|
|
454
|
-
target: "node22.15",
|
|
455
|
-
packages: prebuild ? "external" : "bundle",
|
|
456
|
-
metafile: true,
|
|
457
|
-
write: false,
|
|
458
|
-
logLevel: "silent",
|
|
459
|
-
logOverride: {
|
|
460
|
-
"unsupported-dynamic-import": "error",
|
|
461
|
-
"unsupported-require-call": "error",
|
|
462
|
-
"indirect-require": "error",
|
|
463
|
-
},
|
|
464
|
-
});
|
|
465
|
-
if (
|
|
466
|
-
program.outputFiles.length !== 1 ||
|
|
467
|
-
program.outputFiles[0]!.contents.length > 8 * 1024 * 1024 ||
|
|
468
|
-
(prebuild && Object.keys(program.metafile.inputs).length !== 1) ||
|
|
469
|
-
Object.values(program.metafile.outputs).some((file) =>
|
|
470
|
-
file.imports.some((item) => item.external && !isBuiltin(item.path)),
|
|
471
|
-
)
|
|
472
|
-
)
|
|
473
|
-
throw new HostError(
|
|
474
|
-
"App must bundle into one self-contained .cjs of at most 8 MiB; only Node builtins may remain external.",
|
|
475
|
-
);
|
|
456
|
+
const program = await compileAppProgram(
|
|
457
|
+
input,
|
|
458
|
+
entry,
|
|
459
|
+
join(bundleStage, "resources", "app.cjs"),
|
|
460
|
+
prebuiltSource,
|
|
461
|
+
);
|
|
476
462
|
if (sourceFiles && !prebuild)
|
|
477
463
|
for (const path of Object.keys(program.metafile.inputs))
|
|
478
464
|
if (
|
|
@@ -490,10 +476,27 @@ export async function buildApp(
|
|
|
490
476
|
flag: "wx",
|
|
491
477
|
signal: options.signal,
|
|
492
478
|
});
|
|
493
|
-
await writeFile(
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
479
|
+
await writeFile(
|
|
480
|
+
join(bundleStage, ".bundle.yaml"),
|
|
481
|
+
stringify({
|
|
482
|
+
title: description.name,
|
|
483
|
+
description: description.description,
|
|
484
|
+
entry: "app.json",
|
|
485
|
+
type: ".bundle-type.yaml",
|
|
486
|
+
}),
|
|
487
|
+
{
|
|
488
|
+
flag: "wx",
|
|
489
|
+
signal: options.signal,
|
|
490
|
+
},
|
|
491
|
+
);
|
|
492
|
+
await writeFile(
|
|
493
|
+
join(bundleStage, ".bundle-type.yaml"),
|
|
494
|
+
stringify(appSchema),
|
|
495
|
+
{
|
|
496
|
+
flag: "wx",
|
|
497
|
+
signal: options.signal,
|
|
498
|
+
},
|
|
499
|
+
);
|
|
497
500
|
if (supportedSchemas)
|
|
498
501
|
await writeFile(
|
|
499
502
|
join(bundleStage, ...supportedSchemasPath.split("/")),
|
|
@@ -512,7 +515,7 @@ export async function buildApp(
|
|
|
512
515
|
(part, index, parts) =>
|
|
513
516
|
part.startsWith(".") &&
|
|
514
517
|
!(
|
|
515
|
-
|
|
518
|
+
[".bundle.yaml", ".bundle-type.yaml"].includes(part) &&
|
|
516
519
|
index === parts.length - 1 &&
|
|
517
520
|
index > 0
|
|
518
521
|
),
|
|
@@ -573,24 +576,100 @@ export async function buildApp(
|
|
|
573
576
|
}),
|
|
574
577
|
{ flag: "wx", signal: options.signal },
|
|
575
578
|
);
|
|
576
|
-
const
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
579
|
+
const source = encodedSource
|
|
580
|
+
? {
|
|
581
|
+
cid: encodedSource.cid.toString(),
|
|
582
|
+
schemaCid: encodedSource.schema.cid.toString(),
|
|
583
|
+
output: sourceOutput,
|
|
584
|
+
bytes: await writeCar(
|
|
585
|
+
encodedSource,
|
|
586
|
+
sourceOutput,
|
|
587
|
+
Boolean(options.replace),
|
|
588
|
+
options,
|
|
589
|
+
),
|
|
590
|
+
}
|
|
591
|
+
: undefined;
|
|
592
|
+
const sourceCar = source
|
|
593
|
+
? await readCar(source.output, options)
|
|
594
|
+
: undefined;
|
|
595
|
+
const encoded = await encodeBundleCar(await filesystemTree(bundleStage), {
|
|
596
|
+
...options,
|
|
597
|
+
imports:
|
|
598
|
+
encodedSource && sourceCar
|
|
599
|
+
? [
|
|
600
|
+
{
|
|
601
|
+
path: sourceTarget,
|
|
602
|
+
cid: encodedSource.cid,
|
|
603
|
+
resolveCid: sourceCar.resolveCid,
|
|
604
|
+
},
|
|
605
|
+
]
|
|
606
|
+
: [],
|
|
607
|
+
});
|
|
580
608
|
try {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
609
|
+
if (options.preparedDirectory) {
|
|
610
|
+
const preparedFiles = new Map<string, Uint8Array>();
|
|
611
|
+
const preparedTree = await filesystemTree(bundleStage);
|
|
612
|
+
const collect = async (path: string): Promise<void> => {
|
|
613
|
+
for (const item of await preparedTree.list(path, options)) {
|
|
614
|
+
const child = path ? `${path}/${item.name}` : item.name;
|
|
615
|
+
if (item.kind === "directory") await collect(child);
|
|
616
|
+
else
|
|
617
|
+
preparedFiles.set(
|
|
618
|
+
child,
|
|
619
|
+
await readBytes(
|
|
620
|
+
preparedTree,
|
|
621
|
+
child,
|
|
622
|
+
16 * 1024 * 1024,
|
|
623
|
+
options,
|
|
624
|
+
),
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
await collect("");
|
|
629
|
+
preparedFiles.set(
|
|
630
|
+
"ipab.build.yaml",
|
|
631
|
+
new TextEncoder().encode(
|
|
632
|
+
stringify({
|
|
633
|
+
version: 1,
|
|
634
|
+
files: [...preparedFiles.keys()]
|
|
635
|
+
.filter((path) => path !== ".bundle.yaml")
|
|
636
|
+
.map((path) => ({ source: path, target: path })),
|
|
637
|
+
imports: source
|
|
638
|
+
? [
|
|
639
|
+
{
|
|
640
|
+
cid: source.cid,
|
|
641
|
+
target: sourceTarget,
|
|
642
|
+
car: sourceCarInput,
|
|
643
|
+
},
|
|
644
|
+
]
|
|
645
|
+
: [],
|
|
646
|
+
}),
|
|
647
|
+
),
|
|
648
|
+
);
|
|
649
|
+
if (source)
|
|
650
|
+
preparedFiles.set(
|
|
651
|
+
sourceCarInput,
|
|
652
|
+
await readBytes(
|
|
653
|
+
await filesystemTree(dirname(source.output)),
|
|
654
|
+
basename(source.output),
|
|
655
|
+
source.bytes,
|
|
590
656
|
options,
|
|
591
657
|
),
|
|
592
|
-
|
|
593
|
-
|
|
658
|
+
);
|
|
659
|
+
await scaffoldFiles(
|
|
660
|
+
options.preparedDirectory,
|
|
661
|
+
preparedFiles,
|
|
662
|
+
options,
|
|
663
|
+
);
|
|
664
|
+
return {
|
|
665
|
+
kind: "app-bundle",
|
|
666
|
+
cid: encoded.cid.toString(),
|
|
667
|
+
schemaCid: encoded.schema.cid.toString(),
|
|
668
|
+
output,
|
|
669
|
+
bytes: 0,
|
|
670
|
+
...(source ? { source } : {}),
|
|
671
|
+
};
|
|
672
|
+
}
|
|
594
673
|
return {
|
|
595
674
|
kind: "app-bundle",
|
|
596
675
|
cid: encoded.cid.toString(),
|
|
@@ -614,3 +693,88 @@ export async function buildApp(
|
|
|
614
693
|
await rm(stage, { recursive: true, force: true });
|
|
615
694
|
}
|
|
616
695
|
}
|
|
696
|
+
|
|
697
|
+
/** Explicit project tool. The root CLI build never calls this helper. */
|
|
698
|
+
export async function prepareApp(
|
|
699
|
+
directory = ".",
|
|
700
|
+
options: AuthoringOptions & {
|
|
701
|
+
replace?: boolean;
|
|
702
|
+
includeSource?: boolean;
|
|
703
|
+
/** Exact types from an author's Open App definition; exclusive with config paths. */
|
|
704
|
+
supportedTypes?: readonly BundleType[];
|
|
705
|
+
} = {},
|
|
706
|
+
) {
|
|
707
|
+
const root = resolve(directory);
|
|
708
|
+
const prepared = join(root, "dist", "prepared-app");
|
|
709
|
+
try {
|
|
710
|
+
const stat = await lstat(prepared);
|
|
711
|
+
if (stat.isSymbolicLink() || !stat.isDirectory() || !options.replace)
|
|
712
|
+
throw new HostError(
|
|
713
|
+
"Prepared output exists; explicit replacement requires a regular generated directory.",
|
|
714
|
+
);
|
|
715
|
+
const tree = await filesystemTree(prepared);
|
|
716
|
+
const recipe = object(
|
|
717
|
+
parseData(
|
|
718
|
+
await readBytes(tree, "ipab.build.yaml", 64 * 1024),
|
|
719
|
+
"application/yaml",
|
|
720
|
+
),
|
|
721
|
+
"prepared recipe",
|
|
722
|
+
);
|
|
723
|
+
if (
|
|
724
|
+
recipe.version !== 1 ||
|
|
725
|
+
!Array.isArray(recipe.files) ||
|
|
726
|
+
!Array.isArray(recipe.imports) ||
|
|
727
|
+
recipe.imports.length > 1
|
|
728
|
+
)
|
|
729
|
+
throw new HostError(
|
|
730
|
+
"Existing prepared output is not owned by the App preparation tool.",
|
|
731
|
+
);
|
|
732
|
+
const allowed = new Set([
|
|
733
|
+
".bundle.yaml",
|
|
734
|
+
"ipab.build.yaml",
|
|
735
|
+
...recipe.files.map((item: unknown) => {
|
|
736
|
+
const mapping = object(item, "prepared mapping");
|
|
737
|
+
if (
|
|
738
|
+
typeof mapping.source !== "string" ||
|
|
739
|
+
mapping.source !== mapping.target
|
|
740
|
+
)
|
|
741
|
+
throw new HostError("Existing prepared mapping is not generated.");
|
|
742
|
+
return relativePath(mapping.source);
|
|
743
|
+
}),
|
|
744
|
+
]);
|
|
745
|
+
if (recipe.imports.length) {
|
|
746
|
+
const sourceImport = object(recipe.imports[0], "prepared source import");
|
|
747
|
+
if (
|
|
748
|
+
sourceImport.target !== sourceTarget ||
|
|
749
|
+
sourceImport.car !== sourceCarInput ||
|
|
750
|
+
typeof sourceImport.cid !== "string"
|
|
751
|
+
)
|
|
752
|
+
throw new HostError(
|
|
753
|
+
"Existing prepared source import is not generated.",
|
|
754
|
+
);
|
|
755
|
+
allowed.add(sourceCarInput);
|
|
756
|
+
}
|
|
757
|
+
const verify = async (path: string): Promise<void> => {
|
|
758
|
+
for (const item of await tree.list(path)) {
|
|
759
|
+
const child = path ? `${path}/${item.name}` : item.name;
|
|
760
|
+
if (item.kind === "directory") await verify(child);
|
|
761
|
+
else if (!allowed.has(child))
|
|
762
|
+
throw new HostError(
|
|
763
|
+
"Prepared output contains custom files; choose a new output rather than deleting them.",
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
await verify("");
|
|
768
|
+
await rm(prepared, { recursive: true });
|
|
769
|
+
} catch (cause) {
|
|
770
|
+
if (!nodeError(cause, "ENOENT")) throw cause;
|
|
771
|
+
}
|
|
772
|
+
const result = await buildApp(root, {
|
|
773
|
+
...options,
|
|
774
|
+
preparedDirectory: prepared,
|
|
775
|
+
});
|
|
776
|
+
return {
|
|
777
|
+
directory: prepared,
|
|
778
|
+
...(result.source ? { source: result.source } : {}),
|
|
779
|
+
};
|
|
780
|
+
}
|
package/src/app-definition.ts
CHANGED
|
@@ -8,46 +8,40 @@ import {
|
|
|
8
8
|
|
|
9
9
|
export const appBuiltinAlias = "builtin:node-app.v1";
|
|
10
10
|
export const appSchema = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type: "
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
contentType: "application/json",
|
|
12
|
+
schema: {
|
|
13
|
+
$id: "urn:ipab:node-app.v1",
|
|
14
|
+
type: "object",
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
required: ["name", "version", "entry"],
|
|
17
|
+
properties: {
|
|
18
|
+
name: { type: "string" },
|
|
19
|
+
version: { type: "string" },
|
|
20
|
+
description: { type: "string" },
|
|
21
|
+
entry: { type: "string" },
|
|
22
|
+
source: {
|
|
23
|
+
type: "object",
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
required: ["cid"],
|
|
26
|
+
properties: { cid: { type: "string" } },
|
|
27
|
+
},
|
|
28
|
+
supportedSchemas: { type: "string" },
|
|
29
|
+
author: {
|
|
30
|
+
type: "object",
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
required: ["name"],
|
|
33
|
+
properties: { name: { type: "string" }, email: { type: "string" } },
|
|
34
|
+
},
|
|
35
|
+
license: { type: "string" },
|
|
36
|
+
icon: { type: "string" },
|
|
37
|
+
i18n: {
|
|
38
|
+
type: "object",
|
|
39
|
+
additionalProperties: {
|
|
35
40
|
type: "object",
|
|
36
41
|
additionalProperties: false,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
license: { type: "string" },
|
|
41
|
-
icon: { type: "string" },
|
|
42
|
-
i18n: {
|
|
43
|
-
type: "object",
|
|
44
|
-
additionalProperties: {
|
|
45
|
-
type: "object",
|
|
46
|
-
additionalProperties: false,
|
|
47
|
-
properties: {
|
|
48
|
-
name: { type: "string" },
|
|
49
|
-
description: { type: "string" },
|
|
50
|
-
},
|
|
42
|
+
properties: {
|
|
43
|
+
name: { type: "string" },
|
|
44
|
+
description: { type: "string" },
|
|
51
45
|
},
|
|
52
46
|
},
|
|
53
47
|
},
|
|
@@ -57,7 +51,7 @@ export const appSchema = {
|
|
|
57
51
|
|
|
58
52
|
// This is the canonical full definition, not a separate identity for the alias.
|
|
59
53
|
export const appSchemaCid = CID.parse(
|
|
60
|
-
"
|
|
54
|
+
"bafyreifualoac4ddlzl63jlfstz4xsq75cai5t6ywu3j3khhyukoccmybm",
|
|
61
55
|
);
|
|
62
56
|
export const builtinTypes: ReadonlyMap<string, string> = new Map([
|
|
63
57
|
[appBuiltinAlias, appSchemaCid.toString()],
|
package/src/app-prebuild.ts
CHANGED
|
@@ -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 }[];
|
package/src/app-templates.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
1
|
import { resolve } from "node:path";
|
|
3
|
-
import { lstat
|
|
2
|
+
import { lstat } from "node:fs/promises";
|
|
4
3
|
import { Liquid, type Template } from "liquidjs";
|
|
4
|
+
import { parseBundleManifest } from "@ipab/bundle";
|
|
5
5
|
import {
|
|
6
6
|
listTree,
|
|
7
7
|
readBytes,
|
|
8
8
|
type ReadonlyFileTree,
|
|
9
|
+
type TreeEntry,
|
|
9
10
|
} from "@ipab/bundle-builder";
|
|
10
11
|
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
11
12
|
import { HostError, object } from "./errors.js";
|
|
@@ -15,14 +16,10 @@ import {
|
|
|
15
16
|
templateDefinition,
|
|
16
17
|
templateParameters,
|
|
17
18
|
} from "./template-definition.js";
|
|
18
|
-
import {
|
|
19
|
+
import { templateSource } from "./template-source.js";
|
|
20
|
+
import { addTemplateOutputPath, templateOutputPath } from "./template-paths.js";
|
|
19
21
|
import { nodeError } from "./authoring.js";
|
|
20
22
|
|
|
21
|
-
export const builtinTemplateNames = new Map([
|
|
22
|
-
["builtin:template.node", "node"],
|
|
23
|
-
["builtin:template.web-app", "web-app"],
|
|
24
|
-
] as const);
|
|
25
|
-
|
|
26
23
|
function appName(name: string) {
|
|
27
24
|
if (
|
|
28
25
|
!/^[a-z0-9][a-z0-9._-]*$/.test(name) ||
|
|
@@ -248,11 +245,18 @@ export async function renderTemplate(
|
|
|
248
245
|
options: AuthoringOptions & { parameters?: readonly string[] },
|
|
249
246
|
) {
|
|
250
247
|
const definition = templateDefinition(
|
|
251
|
-
await readBytes(
|
|
248
|
+
await readBytes(
|
|
249
|
+
tree,
|
|
250
|
+
parseBundleManifest(
|
|
251
|
+
await readBytes(tree, ".bundle.yaml", 1024 * 1024, options),
|
|
252
|
+
).entry,
|
|
253
|
+
64 * 1024,
|
|
254
|
+
options,
|
|
255
|
+
),
|
|
252
256
|
);
|
|
253
257
|
const values = templateParameters(definition, name, options.parameters);
|
|
254
258
|
const files = new Map<string, string | Uint8Array>();
|
|
255
|
-
const paths = new Map<string,
|
|
259
|
+
const paths = new Map<string, TreeEntry["kind"]>();
|
|
256
260
|
let count = 0,
|
|
257
261
|
total = 0;
|
|
258
262
|
const collect = async (directory: string, depth: number): Promise<void> => {
|
|
@@ -262,35 +266,8 @@ export async function renderTemplate(
|
|
|
262
266
|
if (++count > 256)
|
|
263
267
|
throw new HostError("Template exceeds 256 project paths.");
|
|
264
268
|
const source = `${directory}/${entry.name}`;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const rendered = entry.kind === "file" && original.endsWith(".liquid");
|
|
268
|
-
const target = relativePath(
|
|
269
|
-
rendered ? original.slice(0, -".liquid".length) : original,
|
|
270
|
-
);
|
|
271
|
-
if (
|
|
272
|
-
target
|
|
273
|
-
.split("/")
|
|
274
|
-
.some(
|
|
275
|
-
(part) =>
|
|
276
|
-
["node_modules", ".git", "dist"].includes(part.toLowerCase()) ||
|
|
277
|
-
/^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\.|$)/i.test(part),
|
|
278
|
-
)
|
|
279
|
-
)
|
|
280
|
-
throw new HostError(`Unsafe template output path: ${target}.`);
|
|
281
|
-
const key = target.toLowerCase();
|
|
282
|
-
if (
|
|
283
|
-
paths.has(key) ||
|
|
284
|
-
[...paths].some(
|
|
285
|
-
([existing, kind]) =>
|
|
286
|
-
(kind === "file" && key.startsWith(`${existing}/`)) ||
|
|
287
|
-
(entry.kind === "file" && existing.startsWith(`${key}/`)),
|
|
288
|
-
)
|
|
289
|
-
)
|
|
290
|
-
throw new HostError(
|
|
291
|
-
`Duplicate or overlapping template output path: ${target}.`,
|
|
292
|
-
);
|
|
293
|
-
paths.set(key, entry.kind);
|
|
269
|
+
const { target, rendered } = templateOutputPath(source, entry.kind);
|
|
270
|
+
addTemplateOutputPath(paths, target, entry.kind);
|
|
294
271
|
if (entry.kind === "directory") {
|
|
295
272
|
await collect(source, depth + 1);
|
|
296
273
|
continue;
|
|
@@ -325,39 +302,6 @@ export async function appTemplate(
|
|
|
325
302
|
options: AuthoringOptions & { parameters?: readonly string[] },
|
|
326
303
|
): Promise<{ files: Map<string, string | Uint8Array>; cid: string | null }> {
|
|
327
304
|
options.signal?.throwIfAborted();
|
|
328
|
-
for (const [alias, name] of builtinTemplateNames)
|
|
329
|
-
if (selector === alias) selector = name;
|
|
330
|
-
if (selector === "node" || selector === "web-app") {
|
|
331
|
-
appName(name);
|
|
332
|
-
const loaded = await builtinTemplateSource(selector, options);
|
|
333
|
-
const parameters = [...(options.parameters ?? [])];
|
|
334
|
-
if (
|
|
335
|
-
selector === "web-app" &&
|
|
336
|
-
!parameters.some((value) => value.startsWith("webAppDependency="))
|
|
337
|
-
) {
|
|
338
|
-
const framework = object(
|
|
339
|
-
JSON.parse(
|
|
340
|
-
await readFile(
|
|
341
|
-
fileURLToPath(import.meta.resolve("@ipab/web-app/package.json")),
|
|
342
|
-
"utf8",
|
|
343
|
-
),
|
|
344
|
-
) as unknown,
|
|
345
|
-
"Web App framework package",
|
|
346
|
-
);
|
|
347
|
-
if (typeof framework.version !== "string" || !framework.version.trim())
|
|
348
|
-
throw new HostError(
|
|
349
|
-
"Web App framework package is missing its version.",
|
|
350
|
-
);
|
|
351
|
-
parameters.push(`webAppDependency=${framework.version}`);
|
|
352
|
-
}
|
|
353
|
-
return {
|
|
354
|
-
files: await renderTemplate(loaded.tree, name, {
|
|
355
|
-
...options,
|
|
356
|
-
parameters,
|
|
357
|
-
}),
|
|
358
|
-
cid: loaded.cid,
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
305
|
let legacy = false;
|
|
362
306
|
try {
|
|
363
307
|
await lstat(resolve(selector, ".bundle.yaml"));
|
|
@@ -388,7 +332,7 @@ export async function appTemplate(
|
|
|
388
332
|
} catch (error) {
|
|
389
333
|
if (nodeError(error, "ENOENT"))
|
|
390
334
|
throw new HostError(
|
|
391
|
-
`Unknown template "${selector}". Use
|
|
335
|
+
`Unknown template "${selector}". Use a Swarm template selector, valid Bundle directory, single-root CAR, exact CID or IPAB URI. Builtin templates and local aliases are unsupported.`,
|
|
392
336
|
);
|
|
393
337
|
throw error;
|
|
394
338
|
}
|