@ipab/cli 0.1.0-rc.0 → 0.1.0-rc.10
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 +230 -7
- package/dist/app-authoring.d.ts +16 -2
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +151 -66
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-definition.d.ts +52 -63
- package/dist/app-definition.d.ts.map +1 -1
- package/dist/app-definition.js +33 -44
- 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 +15 -45
- 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 +8 -21
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +35 -54
- 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 +5 -32
- 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 +2009 -308
- 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 +9 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +164 -23
- 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 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +56 -2
- 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 +684 -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 -1
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +125 -4
- 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 +18 -20
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +146 -126
- 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 -9
- package/dist/source-bundle.d.ts.map +1 -1
- package/dist/source-bundle.js +17 -13
- 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 +128 -16
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +506 -94
- 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 +469 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +4708 -0
- package/dist/swarm.js.map +1 -0
- package/dist/template-definition.d.ts +45 -67
- package/dist/template-definition.d.ts.map +1 -1
- package/dist/template-definition.js +35 -49
- 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 +18 -11
- package/src/app-authoring.ts +254 -88
- package/src/app-definition.ts +33 -45
- package/src/app-prebuild.ts +61 -0
- package/src/app-templates.ts +28 -71
- package/src/assembly.ts +185 -0
- package/src/authoring.ts +63 -72
- package/src/builtins.ts +7 -38
- package/src/bundled-skills.ts +60 -0
- package/src/cli.ts +2500 -376
- package/src/config-secret.ts +14 -0
- package/src/config.ts +215 -26
- package/src/content-provider.ts +299 -0
- package/src/context-types.ts +11 -0
- package/src/context.ts +100 -2
- package/src/daemon-ui.ts +812 -0
- package/src/daemon.ts +386 -0
- package/src/doctor.ts +1082 -0
- package/src/errors.ts +1 -25
- package/src/get.ts +90 -0
- package/src/history.ts +5 -15
- package/src/host-error.ts +26 -0
- package/src/identity.ts +175 -0
- package/src/ipc.ts +161 -4
- 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 +190 -142
- 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 -3
- 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 -14
- 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 +782 -116
- 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 +7051 -0
- package/src/template-definition.ts +35 -49
- 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,
|
|
@@ -41,28 +56,18 @@ export async function initApp(
|
|
|
41
56
|
parameters?: readonly string[];
|
|
42
57
|
} = {},
|
|
43
58
|
) {
|
|
44
|
-
if (
|
|
45
|
-
!/^[a-z0-9][a-z0-9._-]*$/.test(name) ||
|
|
46
|
-
name.length > 214 ||
|
|
47
|
-
["node_modules", "favicon.ico"].includes(name)
|
|
48
|
-
)
|
|
49
|
-
throw new HostError(
|
|
50
|
-
"App NAME must be an unscoped lowercase npm package name.",
|
|
51
|
-
);
|
|
52
59
|
const { files, cid: templateCid } = await appTemplate(
|
|
53
60
|
options.template ?? "node",
|
|
54
61
|
name,
|
|
55
62
|
options,
|
|
56
63
|
);
|
|
57
|
-
const schemaCid = (await builtinAppSchema()).cid.toString();
|
|
58
64
|
const root = await scaffoldFiles(directory, files, options);
|
|
59
65
|
return {
|
|
60
|
-
kind: "
|
|
66
|
+
kind: "project-init" as const,
|
|
61
67
|
directory: root,
|
|
62
68
|
name,
|
|
63
69
|
template: options.template ?? "node",
|
|
64
70
|
templateCid,
|
|
65
|
-
schemaCid,
|
|
66
71
|
files: [...files.keys()],
|
|
67
72
|
};
|
|
68
73
|
}
|
|
@@ -197,6 +202,9 @@ export async function buildApp(
|
|
|
197
202
|
outputDir?: string;
|
|
198
203
|
replace?: boolean;
|
|
199
204
|
includeSource?: boolean;
|
|
205
|
+
/** Exact types from an author's Open App definition; exclusive with config paths. */
|
|
206
|
+
supportedTypes?: readonly BundleType[];
|
|
207
|
+
preparedDirectory?: string;
|
|
200
208
|
} = {},
|
|
201
209
|
): Promise<
|
|
202
210
|
Omit<BuildResult, "kind"> & {
|
|
@@ -337,11 +345,23 @@ export async function buildApp(
|
|
|
337
345
|
throw new HostError(
|
|
338
346
|
"App metadata cannot override the generated source declaration.",
|
|
339
347
|
);
|
|
340
|
-
|
|
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
|
+
);
|
|
341
361
|
const description = appDescription({
|
|
342
362
|
...defaults,
|
|
343
363
|
...overrides,
|
|
344
|
-
entry:
|
|
364
|
+
entry: "resources/app.cjs",
|
|
345
365
|
...(supportedSchemas ? { supportedSchemas: supportedSchemasPath } : {}),
|
|
346
366
|
});
|
|
347
367
|
if (description.icon !== undefined) {
|
|
@@ -422,7 +442,6 @@ export async function buildApp(
|
|
|
422
442
|
options.signal?.throwIfAborted();
|
|
423
443
|
const stage = await mkdtemp(join(root, ".ipab-app-"));
|
|
424
444
|
try {
|
|
425
|
-
const { build } = await import("esbuild");
|
|
426
445
|
const bundleStage = join(stage, "bundle");
|
|
427
446
|
const input = prebuild ? join(stage, "input") : root;
|
|
428
447
|
if (prebuild) {
|
|
@@ -433,56 +452,13 @@ export async function buildApp(
|
|
|
433
452
|
const prebuiltSource = prebuild
|
|
434
453
|
? await readBytes(inputTree, entry, 8 * 1024 * 1024, options)
|
|
435
454
|
: undefined;
|
|
436
|
-
if (prebuiltSource) {
|
|
437
|
-
try {
|
|
438
|
-
const source = new TextDecoder("utf-8", { fatal: true }).decode(
|
|
439
|
-
prebuiltSource,
|
|
440
|
-
);
|
|
441
|
-
compileFunction(source.replace(/^#![^\r\n]*/, ""), [
|
|
442
|
-
"exports",
|
|
443
|
-
"require",
|
|
444
|
-
"module",
|
|
445
|
-
"__filename",
|
|
446
|
-
"__dirname",
|
|
447
|
-
]);
|
|
448
|
-
} catch (cause) {
|
|
449
|
-
const error = new HostError(
|
|
450
|
-
"Prebuilt App entry must be valid Node CommonJS; it is packaged without transformation.",
|
|
451
|
-
);
|
|
452
|
-
error.cause = cause;
|
|
453
|
-
throw error;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
455
|
await mkdir(join(bundleStage, "resources"), { recursive: true });
|
|
457
|
-
const program = await
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
format: "cjs",
|
|
464
|
-
target: "node22.15",
|
|
465
|
-
packages: prebuild ? "external" : "bundle",
|
|
466
|
-
metafile: true,
|
|
467
|
-
write: false,
|
|
468
|
-
logLevel: "silent",
|
|
469
|
-
logOverride: {
|
|
470
|
-
"unsupported-dynamic-import": "error",
|
|
471
|
-
"unsupported-require-call": "error",
|
|
472
|
-
"indirect-require": "error",
|
|
473
|
-
},
|
|
474
|
-
});
|
|
475
|
-
if (
|
|
476
|
-
program.outputFiles.length !== 1 ||
|
|
477
|
-
program.outputFiles[0]!.contents.length > 8 * 1024 * 1024 ||
|
|
478
|
-
(prebuild && Object.keys(program.metafile.inputs).length !== 1) ||
|
|
479
|
-
Object.values(program.metafile.outputs).some((file) =>
|
|
480
|
-
file.imports.some((item) => item.external && !isBuiltin(item.path)),
|
|
481
|
-
)
|
|
482
|
-
)
|
|
483
|
-
throw new HostError(
|
|
484
|
-
"App must bundle into one self-contained .cjs of at most 8 MiB; only Node builtins may remain external.",
|
|
485
|
-
);
|
|
456
|
+
const program = await compileAppProgram(
|
|
457
|
+
input,
|
|
458
|
+
entry,
|
|
459
|
+
join(bundleStage, "resources", "app.cjs"),
|
|
460
|
+
prebuiltSource,
|
|
461
|
+
);
|
|
486
462
|
if (sourceFiles && !prebuild)
|
|
487
463
|
for (const path of Object.keys(program.metafile.inputs))
|
|
488
464
|
if (
|
|
@@ -500,10 +476,27 @@ export async function buildApp(
|
|
|
500
476
|
flag: "wx",
|
|
501
477
|
signal: options.signal,
|
|
502
478
|
});
|
|
503
|
-
await writeFile(
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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
|
+
);
|
|
507
500
|
if (supportedSchemas)
|
|
508
501
|
await writeFile(
|
|
509
502
|
join(bundleStage, ...supportedSchemasPath.split("/")),
|
|
@@ -515,7 +508,19 @@ export async function buildApp(
|
|
|
515
508
|
if (++resourceCount > 4096)
|
|
516
509
|
throw new HostError("App resource file count exceeds 4096.");
|
|
517
510
|
relativePath(path);
|
|
518
|
-
if (
|
|
511
|
+
if (
|
|
512
|
+
path
|
|
513
|
+
.split("/")
|
|
514
|
+
.some(
|
|
515
|
+
(part, index, parts) =>
|
|
516
|
+
part.startsWith(".") &&
|
|
517
|
+
!(
|
|
518
|
+
[".bundle.yaml", ".bundle-type.yaml"].includes(part) &&
|
|
519
|
+
index === parts.length - 1 &&
|
|
520
|
+
index > 0
|
|
521
|
+
),
|
|
522
|
+
)
|
|
523
|
+
)
|
|
519
524
|
throw new HostError("Hidden prebuilt resources are not supported.");
|
|
520
525
|
const bytes = await readBytes(inputTree, path, 16 * 1024 * 1024, options);
|
|
521
526
|
const target = join(bundleStage, "resources", ...path.split("/"));
|
|
@@ -571,24 +576,100 @@ export async function buildApp(
|
|
|
571
576
|
}),
|
|
572
577
|
{ flag: "wx", signal: options.signal },
|
|
573
578
|
);
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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
|
+
});
|
|
578
608
|
try {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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,
|
|
588
656
|
options,
|
|
589
657
|
),
|
|
590
|
-
|
|
591
|
-
|
|
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
|
+
}
|
|
592
673
|
return {
|
|
593
674
|
kind: "app-bundle",
|
|
594
675
|
cid: encoded.cid.toString(),
|
|
@@ -612,3 +693,88 @@ export async function buildApp(
|
|
|
612
693
|
await rm(stage, { recursive: true, force: true });
|
|
613
694
|
}
|
|
614
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,52 +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
|
-
name: "
|
|
19
|
-
version: "
|
|
20
|
-
description: "",
|
|
21
|
-
entry: "
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
author: {
|
|
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: {
|
|
41
40
|
type: "object",
|
|
42
41
|
additionalProperties: false,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
license: { type: "string" },
|
|
47
|
-
icon: { type: "string" },
|
|
48
|
-
i18n: {
|
|
49
|
-
type: "object",
|
|
50
|
-
additionalProperties: {
|
|
51
|
-
type: "object",
|
|
52
|
-
additionalProperties: false,
|
|
53
|
-
properties: {
|
|
54
|
-
name: { type: "string" },
|
|
55
|
-
description: { type: "string" },
|
|
56
|
-
},
|
|
42
|
+
properties: {
|
|
43
|
+
name: { type: "string" },
|
|
44
|
+
description: { type: "string" },
|
|
57
45
|
},
|
|
58
46
|
},
|
|
59
47
|
},
|
|
@@ -63,7 +51,7 @@ export const appSchema = {
|
|
|
63
51
|
|
|
64
52
|
// This is the canonical full definition, not a separate identity for the alias.
|
|
65
53
|
export const appSchemaCid = CID.parse(
|
|
66
|
-
"
|
|
54
|
+
"bafyreifualoac4ddlzl63jlfstz4xsq75cai5t6ywu3j3khhyukoccmybm",
|
|
67
55
|
);
|
|
68
56
|
export const builtinTypes: ReadonlyMap<string, string> = new Map([
|
|
69
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 }[];
|