@collective-intelligence/cli 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,62 @@
1
+ import { NodePath } from "@effect/platform-node";
2
+ import * as Data from "effect/Data";
3
+ import * as Effect from "effect/Effect";
4
+ import { flow } from "effect/Function";
5
+ import * as Path from "effect/Path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { createServer } from "vite";
8
+ import {
9
+ workspaceSourceResolve,
10
+ workspaceSourceSsrResolve
11
+ } from "./workspace-source-condition";
12
+
13
+ class PackageDeclarationError extends Data.TaggedError("PackageDeclarationError") {
14
+ }
15
+ const path = Effect.runSync(Effect.provide(Path.Path, NodePath.layer)), isRecord = (value) => value !== null && typeof value === "object", isPackageDefinition = (value) => {
16
+ if (!isRecord(value) || !isRecord(value.manifest))
17
+ return !1;
18
+ return value.manifest.apiVersion === "v4" && typeof value.manifest.fqn === "string" && Array.isArray(value.components) && (value.hostedContributions === void 0 || Array.isArray(value.hostedContributions)) && Array.isArray(value.schemaSidecars);
19
+ }, normalizePackageDefinition = (definition, packageLoader) => ({
20
+ ...definition,
21
+ hostedContributions: definition.hostedContributions ?? [],
22
+ ...packageLoader === void 0 ? void 0 : { packageLoader }
23
+ }), isPackageLoader = (value) => typeof value === "function", packageLoaderMap = (loaders, definitions) => {
24
+ if (loaders === void 0)
25
+ return;
26
+ const fqns = definitions.map(({ manifest }) => manifest.fqn);
27
+ if (!isRecord(loaders))
28
+ throw TypeError("Declaration packageLoaders must be an object");
29
+ const entries = Object.entries(loaders);
30
+ if (entries.length !== fqns.length || !fqns.every((fqn) => Object.hasOwn(loaders, fqn)) || !entries.every(([, loader]) => isPackageLoader(loader)))
31
+ throw TypeError(`Declaration packageLoaders must map exactly the declared packages (${fqns.join(", ")}) to lazy import functions`);
32
+ return new Map(entries.flatMap(([fqn, loader]) => isPackageLoader(loader) ? [[fqn, loader]] : []));
33
+ }, declarationSpecifier = (specifier) => {
34
+ if (specifier.startsWith("data:") || specifier.startsWith("file:") || specifier.startsWith("http:") || specifier.startsWith("https:") || !specifier.startsWith(".") && !specifier.startsWith("/"))
35
+ return specifier;
36
+ return pathToFileURL(path.resolve(process.cwd(), specifier)).href;
37
+ }, normalizeModuleDeclarations = (loaded) => {
38
+ const exported = loaded.packageDefinitions ?? loaded.packageDefinition ?? loaded.default, candidate = isRecord(exported) && "default" in exported ? exported.default : exported, values = Array.isArray(candidate) ? candidate : [candidate];
39
+ if (values.length === 0 || !values.every(isPackageDefinition))
40
+ throw TypeError(`Declaration module must export a PackageDefinition or PackageDefinition array; received ${JSON.stringify(candidate)}`);
41
+ const loaders = packageLoaderMap(loaded.packageLoaders, values);
42
+ return values.map((definition) => normalizePackageDefinition(definition, loaders?.get(definition.manifest.fqn)));
43
+ };
44
+ export const loadPackageDeclarations = flow((specifier) => Effect.tryPromise(() => import(declarationSpecifier(specifier))).pipe(Effect.map((loaded) => isRecord(loaded) ? loaded : void 0), Effect.flatMap((loaded) => loaded === void 0 ? Effect.fail(new PackageDeclarationError({
45
+ message: "Declaration module did not expose module exports"
46
+ })) : Effect.succeed(normalizeModuleDeclarations(loaded)))), Effect.runPromise), loadFreshPackageDeclarations = flow((specifier) => {
47
+ const resolved = declarationSpecifier(specifier);
48
+ if (!resolved.startsWith("file:"))
49
+ return Effect.promise(() => loadPackageDeclarations(resolved));
50
+ const sourcePath = fileURLToPath(resolved), root = path.dirname(sourcePath);
51
+ return Effect.acquireUseRelease(Effect.tryPromise(() => createServer({
52
+ appType: "custom",
53
+ configFile: !1,
54
+ logLevel: "silent",
55
+ resolve: workspaceSourceResolve(process.execArgv),
56
+ root,
57
+ server: { middlewareMode: !0 },
58
+ ssr: workspaceSourceSsrResolve(process.execArgv)
59
+ })), (server) => Effect.tryPromise(() => server.ssrLoadModule(`/${encodeURIComponent(path.basename(sourcePath))}`)).pipe(Effect.flatMap((loaded) => isRecord(loaded) ? Effect.succeed(normalizeModuleDeclarations(loaded)) : Effect.fail(new PackageDeclarationError({
60
+ message: "Declaration module did not expose module exports"
61
+ })))), (server) => Effect.promise(() => server.close()));
62
+ }, Effect.runPromise);
@@ -0,0 +1,20 @@
1
+ export const WORKSPACE_SOURCE_CONDITION = "ci-source";
2
+ const conditionsFromArgument = (argument, nextArgument) => {
3
+ if (argument === "--conditions")
4
+ return nextArgument === void 0 ? [] : nextArgument.split(",");
5
+ if (argument.startsWith("--conditions="))
6
+ return argument.slice(13).split(",");
7
+ return [];
8
+ };
9
+ export const workspaceSourceConditions = (execArgv) => {
10
+ for (const [index, argument] of execArgv.entries())
11
+ if (conditionsFromArgument(argument, execArgv[index + 1]).includes(WORKSPACE_SOURCE_CONDITION))
12
+ return [WORKSPACE_SOURCE_CONDITION];
13
+ return [];
14
+ }, workspaceSourceResolve = (execArgv) => {
15
+ const conditions = workspaceSourceConditions(execArgv);
16
+ return conditions.length > 0 ? { conditions: [...conditions] } : {};
17
+ }, workspaceSourceSsrResolve = (execArgv) => {
18
+ const conditions = workspaceSourceConditions(execArgv);
19
+ return conditions.length > 0 ? { resolve: { conditions: [...conditions] } } : {};
20
+ };
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@collective-intelligence/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Distributable command-line tooling for Collective Intelligence Extension Packages.",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "bin": {
10
+ "ci": "./dist/cli.js"
11
+ },
12
+ "dependencies": {
13
+ "@collective-intelligence/extensions-sdk-backend": "0.1.0",
14
+ "@module-federation/vite": "1.23.2",
15
+ "@vitejs/plugin-react": "6.0.5",
16
+ "acorn": "8.18.0",
17
+ "es-module-lexer": "2.3.2",
18
+ "magic-string": "0.30.21",
19
+ "vite": "8.2.1"
20
+ },
21
+ "scripts": {
22
+ "build": "bun tools/build.ts",
23
+ "start": "bun --conditions=ci-source src/main.ts",
24
+ "test": "bun --conditions=ci-source --bun ./node_modules/.bin/vitest run",
25
+ "test:pack": "bun run build && bun tools/test-pack.ts",
26
+ "format": "oxfmt --write .",
27
+ "format:check": "oxfmt --check .",
28
+ "format:check:staged": "oxfmt --check",
29
+ "lint": "node \"../../../.agents/scripts/managed-lint-runner.mjs\" --scope \"packages/public/cli\"",
30
+ "lint:staged": "oxlint --no-error-on-unmatched-pattern",
31
+ "prepack": "bun run build",
32
+ "type-check": "tsc --noEmit"
33
+ },
34
+ "devDependencies": {
35
+ "@collective-intelligence/extensions-sdk": "0.1.0",
36
+ "@effect/eslint-plugin": "latest",
37
+ "@effect/platform-node": "4.0.1",
38
+ "@effect/tsgo": "0.48.1",
39
+ "@effect/vitest": "4.0.1",
40
+ "@jridgewell/trace-mapping": "0.3.31",
41
+ "@oxlint/plugins": "1.85.0",
42
+ "@platform/integrations": "workspace:*",
43
+ "@types/bun": "1.3.14",
44
+ "@types/react": "^19.2.14",
45
+ "@typescript-eslint/utils": "8.22.0",
46
+ "effect": "4.0.1",
47
+ "eslint": "9.39.5",
48
+ "eslint-plugin-react-you-might-not-need-an-effect": "1.0.2",
49
+ "oxfmt": "0.66.0",
50
+ "oxlint": "1.82.0",
51
+ "oxlint-tsgolint": "7.0.2001",
52
+ "react": "^19.2.8",
53
+ "typescript": "7.0.2",
54
+ "ultracite": "7.10.7",
55
+ "vitest": "5.0.2"
56
+ }
57
+ }