Skip to content

AI-native design editor. Open-source Figma alternative.

build(cloud): publish @open-pencil/cloud to npm (#1496)

Danila Poyarkov7f04678fad13
diff --git a/.github/workflows/feedback.yml b/.github/workflows/feedback.yml
index b5d31c001..b1afff2fa 100644
--- a/.github/workflows/feedback.yml
+++ b/.github/workflows/feedback.yml
@@ -5,6 +5,9 @@ on:
branches: [master]
paths:
- packages/feedback/**
+ # The waitlist's email layout, which Cloud's email module shares with the Worker.
+ - packages/cloud/src/email/**
+ - packages/cloud/src/contract/**
# The metrics dashboard page the Worker serves under /admin. Its bundle is built from the
# app's src/ (views, components, theme, styles, and the build target in
# src/app/shell/support) and this package, so any change there redeploys it.
diff --git a/bun.lock b/bun.lock
index 9cf511272..2d56b2ac1 100644
--- a/bun.lock
+++ b/bun.lock
@@ -210,22 +210,27 @@
},
"packages/cloud": {
"name": "@open-pencil/cloud",
- "version": "0.15.1",
+ "version": "0.16.0",
+ "bin": {
+ "openpencil-cloud": "./dist/bin/server.mjs",
+ "openpencil-ai-relay": "./dist/bin/ai-relay.mjs",
+ },
"dependencies": {
"@aws-sdk/client-s3": "^3.1149.0",
"@aws-sdk/s3-request-presigner": "^3.1149.0",
+ "@better-auth/core": "1.7.7",
"@better-auth/passkey": "1.7.7",
"@better-auth/utils": "0.4.2",
"@hono/node-server": "^1.19.17",
"@internationalized/date": "^3.12.3",
"@noble/hashes": "^2.4.0",
- "@open-pencil/feedback": "workspace:*",
"@open-pencil/scene-graph": "workspace:*",
"@openfeature/server-sdk": "^1.23.0",
"@vue-email/components": "^0.0.21",
"@vue-email/render": "^0.0.9",
"better-auth": "1.7.7",
"bowser": "^2.14.1",
+ "dedent": "^1.7.2",
"es-toolkit": "^1.52.0",
"fflate": "^0.8.3",
"hono": "^4.13.13",
@@ -452,6 +457,7 @@
"version": "0.16.0",
"dependencies": {
"@internationalized/date": "^3.12.3",
+ "@open-pencil/cloud": "workspace:*",
"@open-pencil/scene-graph": "workspace:*",
"@vue-email/components": "^0.0.21",
"@vue-email/render": "^0.0.9",
diff --git a/changes/1496/added.md b/changes/1496/added.md
new file mode 100644
index 000000000..39a5e85f7
--- /dev/null
+++ b/changes/1496/added.md
@@ -0,0 +1 @@
+- Self-hosted OpenPencil Cloud installs from npm: `npm install -g @open-pencil/cloud` provides the `openpencil-cloud` server and the `openpencil-ai-relay` AI relay commands.
diff --git a/knip.json b/knip.json
index aa2fabc0f..0a86b8135 100644
--- a/knip.json
+++ b/knip.json
@@ -5,7 +5,10 @@
"**/dist/**",
"**/node_modules/**"
],
- "ignoreWorkspaces": ["packages/acp", "packages/demos"],
+ "ignoreWorkspaces": [
+ "packages/acp",
+ "packages/demos"
+ ],
"ignoreUnresolved": [
"~icons/*",
"#app-public/*",
@@ -14,5 +17,15 @@
"/src/app/tabs/index.ts",
"#core/*"
],
- "ignoreBinaries": ["figma-use", "identify", "magick", "open", "osascript"]
+ "ignoreDependencies": [
+ "cloudflare",
+ "@better-auth/core"
+ ],
+ "ignoreBinaries": [
+ "figma-use",
+ "identify",
+ "magick",
+ "open",
+ "osascript"
+ ]
}
diff --git a/packages/cloud/AGENTS.md b/packages/cloud/AGENTS.md
index a3a1dfa1e..7579faed2 100644
--- a/packages/cloud/AGENTS.md
+++ b/packages/cloud/AGENTS.md
@@ -6,6 +6,8 @@ Optional, self-hostable backend; the design is in `packages/docs/development/clo
- Consumers import the `contract`, `client`, `email`, `server`, and `runtime/node` subpaths; browser code imports only `contract` and `client`, which stay on the browser baseline (`tests/app/shell/support/baseline.test.ts`, `compat/compat` in `oxlint.json`).
- `src/server` receives its database, object store, auth adapter, and delivery through injection and never imports `pg`, opens listeners, runs migrations, or starts timers; runtimes under `src/runtime/` own those (`src/runtime/node/server.ts`).
+- The package is published to npm; a directory imported as `#cloud/<dir>` is listed in `imports` in `package.json`, since the wildcard there names `.ts` files (`bun run check:packages`).
+- `@better-auth/core` is pinned to the `better-auth` version though nothing imports it: `@better-auth/passkey` accepts any later core, whose exact `@better-fetch/fetch` differs from its own, and npm then never finishes installing the package (`bun run test:packages`).
- Runtime code runs on Node 22 and Bun alike: serve HTTP through `@hono/node-server`, not `Bun.serve` or other `Bun.*` APIs (`tsdown.standalone.config.ts` targets `node22`).
## Data and security
diff --git a/packages/cloud/NOTICE b/packages/cloud/NOTICE
index d56010be4..7eb10eef3 100644
--- a/packages/cloud/NOTICE
+++ b/packages/cloud/NOTICE
@@ -3,4 +3,5 @@ Copyright 2026 Danila Poyarkov and OpenPencil contributors
This product is licensed under the Apache License, Version 2.0 (see LICENSE),
except src/contract and src/client, the protocol the editor and other clients
-speak, which are under the MIT License (see ../../LICENSE).
+speak, which are under the MIT License (see LICENSE-MIT in the published package, or
+LICENSE at the repository root).
diff --git a/packages/cloud/README.md b/packages/cloud/README.md
index 3e3d9ee47..6adc36fa9 100644
--- a/packages/cloud/README.md
+++ b/packages/cloud/README.md
@@ -17,11 +17,11 @@ local-first and works without it.
The Node runtime reads one deployment TOML file named by `OPENPENCIL_CLOUD_CONFIG` and resolves
secrets from the environment. Start from
[`deploy/openpencil-cloud.example.toml`](./deploy/openpencil-cloud.example.toml), then build and run
-the self-contained server on Node 22 or later:
+the server on Node 22 or later, installed from npm or built from a checkout:
```sh
-bun --filter @open-pencil/cloud build:standalone
-bun --filter @open-pencil/cloud start
+npx -p @open-pencil/cloud openpencil-cloud # openpencil-ai-relay runs the AI relay
+bun --filter @open-pencil/cloud build:standalone && bun --filter @open-pencil/cloud start
```
The server migrates the database before it accepts requests. The
diff --git a/packages/cloud/package.json b/packages/cloud/package.json
index 968ca8855..8c4e783b8 100644
--- a/packages/cloud/package.json
+++ b/packages/cloud/package.json
@@ -1,32 +1,65 @@
{
"name": "@open-pencil/cloud",
- "version": "0.15.1",
- "private": true,
+ "version": "0.16.0",
+ "description": "Self-hostable OpenPencil Cloud: accounts, workspaces, document revisions, sharing, collaboration, and the AI relay, for Node and Cloudflare Workers.",
"license": "Apache-2.0 AND MIT",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/open-pencil/open-pencil.git",
+ "directory": "packages/cloud"
+ },
+ "bin": {
+ "openpencil-ai-relay": "./dist/bin/ai-relay.mjs",
+ "openpencil-cloud": "./dist/bin/server.mjs"
+ },
"files": [
- "dist"
+ "dist",
+ "src",
+ "NOTICE",
+ "README.md"
],
"type": "module",
"sideEffects": false,
"imports": {
- "#cloud/*": {
- "types": "./src/*",
- "bun": "./src/*",
- "default": "./dist/*"
- },
+ "#cloud/admin": "./src/admin/index.ts",
+ "#cloud/ai-relay": "./src/ai-relay/index.ts",
+ "#cloud/client": "./src/client/index.ts",
+ "#cloud/contract": "./src/contract/index.ts",
+ "#cloud/email": "./src/email/index.ts",
+ "#cloud/runtime/cloudflare": "./src/runtime/cloudflare/index.ts",
+ "#cloud/runtime/node": "./src/runtime/node/index.ts",
+ "#cloud/server": "./src/server/index.ts",
+ "#cloud/server/ai": "./src/server/ai/index.ts",
+ "#cloud/server/api": "./src/server/api/index.ts",
+ "#cloud/server/auth": "./src/server/auth/index.ts",
+ "#cloud/server/cleanup": "./src/server/cleanup/index.ts",
+ "#cloud/server/collaboration": "./src/server/collaboration/index.ts",
+ "#cloud/server/config": "./src/server/config/index.ts",
+ "#cloud/server/db": "./src/server/db/index.ts",
+ "#cloud/server/documents": "./src/server/documents/index.ts",
+ "#cloud/server/documents/versions": "./src/server/documents/versions/index.ts",
+ "#cloud/server/email": "./src/server/email/index.ts",
+ "#cloud/server/internal": "./src/server/internal/index.ts",
+ "#cloud/server/invitations": "./src/server/invitations/index.ts",
+ "#cloud/server/objects": "./src/server/objects/index.ts",
+ "#cloud/server/pictures": "./src/server/pictures/index.ts",
+ "#cloud/server/policy": "./src/server/policy/index.ts",
+ "#cloud/server/quota": "./src/server/quota/index.ts",
+ "#cloud/server/rate-limit": "./src/server/rate-limit/index.ts",
+ "#cloud/server/sharing": "./src/server/sharing/index.ts",
+ "#cloud/server/workspaces": "./src/server/workspaces/index.ts",
+ "#cloud/*": "./src/*.ts",
"#cloud-tests/*": "./tests/*.ts"
},
"exports": {
"./contract": {
"types": "./dist/contract.d.ts",
- "openpencil-source": "./src/contract/index.ts",
"bun": "./src/contract/index.ts",
"import": "./dist/contract.js",
"default": "./dist/contract.js"
},
"./client": {
"types": "./dist/client.d.ts",
- "openpencil-source": "./src/client/index.ts",
"bun": "./src/client/index.ts",
"import": "./dist/client.js",
"default": "./dist/client.js"
@@ -50,6 +83,10 @@
"default": "./dist/server.js"
}
},
+ "publishConfig": {
+ "access": "public",
+ "provenance": true
+ },
"scripts": {
"build": "bunx tsdown --config tsdown.config.ts",
"build:standalone": "bunx tsdown --config tsdown.standalone.config.ts",
@@ -73,18 +110,19 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.1149.0",
"@aws-sdk/s3-request-presigner": "^3.1149.0",
+ "@better-auth/core": "1.7.7",
"@better-auth/passkey": "1.7.7",
"@better-auth/utils": "0.4.2",
"@hono/node-server": "^1.19.17",
"@internationalized/date": "^3.12.3",
"@noble/hashes": "^2.4.0",
- "@open-pencil/feedback": "workspace:*",
"@open-pencil/scene-graph": "workspace:*",
"@openfeature/server-sdk": "^1.23.0",
"@vue-email/components": "^0.0.21",
"@vue-email/render": "^0.0.9",
"better-auth": "1.7.7",
"bowser": "^2.14.1",
+ "dedent": "^1.7.2",
"es-toolkit": "^1.52.0",
"fflate": "^0.8.3",
"hono": "^4.13.13",
@@ -117,5 +155,8 @@
},
"optionalDependencies": {
"pg": "^8.23.0"
+ },
+ "engines": {
+ "node": ">=22"
}
}
diff --git a/packages/cloud/src/email/index.ts b/packages/cloud/src/email/index.ts
index ab55d5ffd..47bf3d0be 100644
--- a/packages/cloud/src/email/index.ts
+++ b/packages/cloud/src/email/index.ts
@@ -1,4 +1,5 @@
export { renderTransactionalEmail } from './render'
+export { emailLayout, type EmailLayoutProps } from './templates/brand'
export { transactionalEmailContentSchema } from './schema'
export type {
AdminEnrollmentNotificationPayload,
diff --git a/packages/feedback/src/waitlist/email/layout.ts b/packages/cloud/src/email/templates/brand.ts
similarity index 100%
rename from packages/feedback/src/waitlist/email/layout.ts
rename to packages/cloud/src/email/templates/brand.ts
diff --git a/packages/cloud/src/email/templates/layout.ts b/packages/cloud/src/email/templates/layout.ts
index 4beb61bd9..577981313 100644
--- a/packages/cloud/src/email/templates/layout.ts
+++ b/packages/cloud/src/email/templates/layout.ts
@@ -1,6 +1,6 @@
import type { VNode } from 'vue'
-import { emailLayout } from '@open-pencil/feedback/email'
+import { emailLayout } from './brand'
export type TransactionalEmailLayout = {
preview: string
diff --git a/packages/cloud/src/runtime/node/ai-relay/main.ts b/packages/cloud/src/runtime/node/ai-relay/main.ts
index db98c9ec6..e62090775 100644
--- a/packages/cloud/src/runtime/node/ai-relay/main.ts
+++ b/packages/cloud/src/runtime/node/ai-relay/main.ts
@@ -1,5 +1,21 @@
+#!/usr/bin/env node
+import dedent from 'dedent'
+
import { startNodeAIRelay } from './server'
+if (process.argv.includes('--help') || process.argv.includes('-h')) {
+ console.log(dedent`
+ Usage: openpencil-ai-relay
+
+ Runs the reference AI service for a self-hosted OpenPencil Cloud. Settings come from the
+ environment:
+ OPENPENCIL_AI_RELAY_CONFIG the relay TOML file (required)
+ PORT, HOST where to listen (default 8788 on 0.0.0.0)
+ plus the secrets the TOML names. See https://openpencil.dev/reference/self-hosting-cloud
+ `)
+ process.exit(0)
+}
+
const relay = await startNodeAIRelay()
console.log(`OpenPencil AI relay listening on ${relay.url}`)
diff --git a/packages/cloud/src/runtime/node/main.ts b/packages/cloud/src/runtime/node/main.ts
index 3a3c76a37..3ca6cd6fb 100644
--- a/packages/cloud/src/runtime/node/main.ts
+++ b/packages/cloud/src/runtime/node/main.ts
@@ -1,5 +1,21 @@
+#!/usr/bin/env node
+import dedent from 'dedent'
+
import { startNodeCloudServer } from './server'
+if (process.argv.includes('--help') || process.argv.includes('-h')) {
+ console.log(dedent`
+ Usage: openpencil-cloud
+
+ Runs OpenPencil Cloud. Settings come from the environment:
+ OPENPENCIL_CLOUD_CONFIG the deployment TOML file (required)
+ OPENPENCIL_CLOUD_SITE_DIR the editor and portal build to serve
+ PORT, HOST where to listen (default 8787 on 0.0.0.0)
+ plus the secrets the TOML names. See https://openpencil.dev/reference/self-hosting-cloud
+ `)
+ process.exit(0)
+}
+
const cloud = await startNodeCloudServer()
console.log(`OpenPencil Cloud listening on ${cloud.url}`)
diff --git a/packages/cloud/tsdown.config.ts b/packages/cloud/tsdown.config.ts
index 75aa8d696..5a1995c86 100644
--- a/packages/cloud/tsdown.config.ts
+++ b/packages/cloud/tsdown.config.ts
@@ -8,11 +8,7 @@ const shared = {
outDir: './dist',
treeshake: { moduleSideEffects: false },
outputOptions: { minifyInternalExports: false },
- deps: {
- neverBundle: [/^node:/],
- // Dependencies stay imports, except the shared email layout, which ships as source.
- alwaysBundle: [/^@open-pencil\/feedback\//]
- }
+ deps: { neverBundle: [/^node:/] }
}
export default defineConfig([
@@ -43,7 +39,12 @@ export default defineConfig([
{
...shared,
name: 'node',
- entry: { 'runtime-node': './src/runtime/node/index.ts' },
+ entry: {
+ 'runtime-node': './src/runtime/node/index.ts',
+ // The package's commands, `openpencil-cloud` and `openpencil-ai-relay`.
+ 'bin/server': './src/runtime/node/main.ts',
+ 'bin/ai-relay': './src/runtime/node/ai-relay/main.ts'
+ },
platform: 'node',
clean: false
}
diff --git a/packages/docs/reference/self-hosting-cloud.md b/packages/docs/reference/self-hosting-cloud.md
index ffbc154a9..3a9452cb5 100644
--- a/packages/docs/reference/self-hosting-cloud.md
+++ b/packages/docs/reference/self-hosting-cloud.md
@@ -7,7 +7,18 @@ description: Run your own OpenPencil Cloud server with PostgreSQL and an S3-comp
OpenPencil Cloud is one Node 22+ process in front of PostgreSQL 15 or later and an S3-compatible object store, with optional SMTP for email. The same process serves the API, the collaboration relay, the editor, and the server's own pages for signing in, account security, and administration. It also runs on [Cloudflare Workers](#cloudflare-workers) with the same configuration. People connect to it from the editor as described in [OpenPencil Cloud](/user-guide/openpencil-cloud).
-## Build
+## Install
+
+The server is published to npm as `@open-pencil/cloud`, released with the editor, and runs on Node 22 or later:
+
+```sh
+npm install -g @open-pencil/cloud
+openpencil-cloud --help
+```
+
+The package is the server only. The editor and the server's own pages are a separate build, `dist-cloud/`, made from a checkout as below; without it the server runs its API alone.
+
+## Build from source
From a checkout of the repository:
@@ -19,7 +30,7 @@ bun run build:cloud # writes dist-cloud/: the edito
bun --filter @open-pencil/cloud build:standalone # writes packages/cloud/dist-standalone/
```
-`dist-standalone/` bundles the server's dependencies, so copy the whole directory, together with `dist-cloud/`, to a host that has Node but no `node_modules`. Start the server with `node dist-standalone/server.mjs`.
+`dist-standalone/` bundles the server's dependencies, so copy the whole directory, together with `dist-cloud/`, to a host that has Node but no `node_modules`. Start the server with `node dist-standalone/server.mjs`, or with `openpencil-cloud` when it is installed from npm.
## Configure
@@ -32,7 +43,7 @@ Settings live in a TOML file; environment variables supply secrets and tell the
- `OPENPENCIL_CLOUD_CONFIG`: the path to the TOML file;
- `OPENPENCIL_CLOUD_SITE_DIR`: the path to `dist-cloud/`. Without it the server still runs its API, but the editor and the sign-in, account, and administration pages answer 404, and it warns at startup;
- the secrets the TOML names, by default `DATABASE_URL`, `BETTER_AUTH_SECRET`, `S3_ACCESS_KEY_ID`, and `S3_SECRET_ACCESS_KEY`, plus `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `APPLE_PRIVATE_KEY`, `S3_SESSION_TOKEN`, `OPENPENCIL_CLOUD_SMTP_USER`, and `OPENPENCIL_CLOUD_SMTP_PASSWORD` when their sections are enabled.
-3. Start the server with the environment loaded, for example `node --env-file=.env dist-standalone/server.mjs`.
+3. Start the server with the environment loaded, for example `node --env-file=.env dist-standalone/server.mjs`, or, installed from npm, `node --env-file=.env "$(command -v openpencil-cloud)"`.
Use `{ from_env = "CUSTOM_NAME" }` in the TOML to read a secret from a different variable. A missing required secret stops startup and names the variable without printing a value.
@@ -95,7 +106,7 @@ Cloud does not run models itself. It advertises an AI service and signs short-li
1. Create a P-256 signing key, `openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256`, and pass the PEM in `OPENPENCIL_CLOUD_AI_SIGNING_KEY`. Cloud refuses to start with a key it cannot sign with.
2. Add `[ai] endpoint` to the Cloud TOML with the relay's address, and enable `[entitlements.ai]`, optionally with a `monthly_credit_allowance`; without one, the relay does not limit spend. With entitlements from the database, set them per workspace with the `entitlements` command instead.
3. Copy [`openpencil-ai-relay.example.toml`](https://github.com/open-pencil/open-pencil/blob/master/packages/cloud/deploy/openpencil-ai-relay.example.toml), set `relay.cloud_url` to Cloud's `public_url`, `allowed_origins` to the browser editors, and list the models with their credit prices.
-4. Start it with `OPENPENCIL_AI_RELAY_CONFIG`, `OPENPENCIL_AI_RELAY_UPSTREAM_KEY`, and `DATABASE_URL` set: `node --env-file=.env dist-standalone/ai-relay.mjs`. It listens on `PORT` (default `8788`) and can share Cloud's database, keeping its own tables and migration history.
+4. Start it with `OPENPENCIL_AI_RELAY_CONFIG`, `OPENPENCIL_AI_RELAY_UPSTREAM_KEY`, and `DATABASE_URL` set: `node --env-file=.env dist-standalone/ai-relay.mjs`, or `openpencil-ai-relay` from the npm package. It listens on `PORT` (default `8788`) and can share Cloud's database, keeping its own tables and migration history.
The relay charges a request once the upstream reports its usage, and admits one while the workspace has credits left, so requests already in flight can overdraw the month's allowance by what they cost; `relay.max_concurrent_requests` bounds them. A workspace's allowance renews at the start of each UTC month. The editor's chat shows how many credits are left, and once they run out it says when the allowance renews and asks members to contact you; with no `[billing]` table it offers nothing to buy. It refuses a model request larger than `relay.max_request_bytes` (16 MiB by default) before reading it all. Choose an upstream that reports token usage: a request it reports none for is logged as an error and not charged.
diff --git a/packages/feedback/package.json b/packages/feedback/package.json
index 313619320..57dd0bf11 100644
--- a/packages/feedback/package.json
+++ b/packages/feedback/package.json
@@ -11,8 +11,7 @@
},
"exports": {
"./contract": "./src/contract/index.ts",
- "./client": "./src/client.ts",
- "./email": "./src/waitlist/email/layout.ts"
+ "./client": "./src/client.ts"
},
"scripts": {
"dev": "wrangler dev",
@@ -23,6 +22,7 @@
},
"dependencies": {
"@internationalized/date": "^3.12.3",
+ "@open-pencil/cloud": "workspace:*",
"@open-pencil/scene-graph": "workspace:*",
"@vue-email/components": "^0.0.21",
"@vue-email/render": "^0.0.9",
diff --git a/packages/feedback/src/waitlist/email/confirmation.ts b/packages/feedback/src/waitlist/email/confirmation.ts
index da7e31742..948a98b9d 100644
--- a/packages/feedback/src/waitlist/email/confirmation.ts
+++ b/packages/feedback/src/waitlist/email/confirmation.ts
@@ -1,7 +1,7 @@
import { render } from '@vue-email/render'
import { defineComponent } from 'vue'
-import { emailLayout } from './layout'
+import { emailLayout } from '@open-pencil/cloud/email'
const ConfirmationEmail = defineComponent({
props: {
diff --git a/packages/feedback/tsconfig.json b/packages/feedback/tsconfig.json
index 05e282a69..f5e90bdc0 100644
--- a/packages/feedback/tsconfig.json
+++ b/packages/feedback/tsconfig.json
@@ -12,7 +12,9 @@
"types": ["@cloudflare/workers-types"],
"paths": {
"#feedback/*": ["./src/*"],
- "@open-pencil/scene-graph/random": ["../scene-graph/src/random.ts"]
+ "@open-pencil/scene-graph/random": ["../scene-graph/src/random.ts"],
+ "@open-pencil/cloud/email": ["../cloud/src/email/index.ts"],
+ "#cloud/*": ["../cloud/src/*"]
}
},
"include": ["src/**/*.ts", "worker-configuration.d.ts"]
diff --git a/packages/feedback/tsconfig.tests.json b/packages/feedback/tsconfig.tests.json
index c5d87cdfc..37ba0cdf3 100644
--- a/packages/feedback/tsconfig.tests.json
+++ b/packages/feedback/tsconfig.tests.json
@@ -5,7 +5,9 @@
"paths": {
"#feedback/*": ["./src/*"],
"#feedback-tests/*": ["./tests/*"],
- "@open-pencil/scene-graph/random": ["../scene-graph/src/random.ts"]
+ "@open-pencil/scene-graph/random": ["../scene-graph/src/random.ts"],
+ "@open-pencil/cloud/email": ["../cloud/src/email/index.ts"],
+ "#cloud/*": ["../cloud/src/*"]
}
},
"include": ["src/**/*.ts", "tests/**/*.ts", "worker-configuration.d.ts"]
diff --git a/tools/checks/package-quality/src/smoke/runtime.ts b/tools/checks/package-quality/src/smoke/runtime.ts
index a0b435ed5..92972af12 100644
--- a/tools/checks/package-quality/src/smoke/runtime.ts
+++ b/tools/checks/package-quality/src/smoke/runtime.ts
@@ -67,7 +67,13 @@ export async function verifyRuntimeScenarios(
export async function verifyPackageBinaries(consumerDirectory: string): Promise<void> {
const binaryDirectory = join(consumerDirectory, 'node_modules', '.bin')
- const binaries = ['openpencil', 'openpencil-mcp', 'openpencil-mcp-http']
+ const binaries = [
+ 'openpencil',
+ 'openpencil-mcp',
+ 'openpencil-mcp-http',
+ 'openpencil-cloud',
+ 'openpencil-ai-relay'
+ ]
for (const runtime of RUNTIMES) {
for (const binary of binaries) {
await runCommand({
diff --git a/tools/checks/package-quality/src/smoke/scenarios.ts b/tools/checks/package-quality/src/smoke/scenarios.ts
index 2b65ef10e..be9b38457 100644
--- a/tools/checks/package-quality/src/smoke/scenarios.ts
+++ b/tools/checks/package-quality/src/smoke/scenarios.ts
@@ -60,6 +60,10 @@ export const runtimeScenarios: RuntimeScenario[] = [
name: 'DOM/CSS JSX runtime',
code: "const { jsx, jsxToDesignDocument } = await import('@open-pencil/dom-css/jsx-runtime'); const document = await jsxToDesignDocument(jsx('section', { class: 'card', style: { width: '120px' }, children: 'OpenPencil' })); const node = document.children[0]; if (node?.type !== 'element' || node.inlineStyle?.width !== '120px') throw new Error('DOM/CSS JSX runtime failed')"
},
+ {
+ name: 'Cloud contract',
+ code: "const { CLOUD_AI_TOKEN_AUDIENCE, aiWalletSchema } = await import('@open-pencil/cloud/contract'); const { safeParse } = await import('valibot'); if (CLOUD_AI_TOKEN_AUDIENCE !== 'openpencil-ai' || !safeParse(aiWalletSchema, { balance: 5, buckets: [] }).success) throw new Error('Cloud contract smoke failed')"
+ },
{
name: 'XPath query',
code: "const { SceneGraph } = await import('@open-pencil/scene-graph'); const { FigmaAPI } = await import('@open-pencil/core/figma-api'); const { matchByXPath, queryByXPath } = await import('@open-pencil/core/xpath'); const graph = new SceneGraph(); new FigmaAPI(graph).createRectangle(); const found = await queryByXPath(graph, '//RECTANGLE'); if (found.length !== 1 || !(await matchByXPath(graph, '@width > 0', found[0]))) throw new Error('XPath query smoke failed')"
diff --git a/tools/release/package-artifacts/src/manifest/schema.ts b/tools/release/package-artifacts/src/manifest/schema.ts
index 461c3b19f..06a317aca 100644
--- a/tools/release/package-artifacts/src/manifest/schema.ts
+++ b/tools/release/package-artifacts/src/manifest/schema.ts
@@ -25,6 +25,8 @@ export const packageManifestSchema = v.looseObject({
name: nonemptySchema,
version: nonemptySchema,
private: v.optional(v.boolean()),
+ /** An SPDX expression, such as `Apache-2.0 AND MIT`. */
+ license: v.optional(nonemptySchema),
files: v.optional(v.array(nonemptySchema)),
main: v.optional(nonemptySchema),
types: v.optional(nonemptySchema),
diff --git a/tools/release/release-packages/src/publish-dirs.ts b/tools/release/release-packages/src/publish-dirs.ts
index da58c12d6..c726caaca 100644
--- a/tools/release/release-packages/src/publish-dirs.ts
+++ b/tools/release/release-packages/src/publish-dirs.ts
@@ -38,6 +38,13 @@ const PACKAGE_FIELDS = [
] as const satisfies ReadonlyArray<keyof PackageManifest>
const PUBLISH_CONFIG_FIELDS = new Set(['access', 'provenance', 'registry'])
const LICENSE_FILE = 'LICENSE'
+/** The repository's MIT text, for a package under its own license that is MIT in part. */
+const MIT_LICENSE_FILE = 'LICENSE-MIT'
+/**
+ * `MIT` or `MIT+` as a whole SPDX identifier in a license expression, in any case as SPDX allows,
+ * and not the start of another identifier such as `MIT-0`.
+ */
+const MIT_IDENTIFIER = /(?:^|[\s(])MIT\+?(?:$|[\s)])/i
export function publishPackageJSON(source: PackageManifest, coreVersion: string): PackageManifest {
if (source.publishConfig) {
@@ -126,10 +133,17 @@ export async function preparePublishDirectories(
await cp(join(sourceDir, relativePath), destination, { dereference: false })
}
- if (!hasOwnLicense) await cp(rootLicense, join(destinationDir, LICENSE_FILE))
-
const packageJSON = await readPackageManifest(join(sourceDir, 'package.json'))
const publishJSON = publishPackageJSON(packageJSON, options.coreVersion)
+ if (!hasOwnLicense) await cp(rootLicense, join(destinationDir, LICENSE_FILE))
+ else if (MIT_IDENTIFIER.test(packageJSON.license ?? '') && existsSync(rootLicense)) {
+ await cp(rootLicense, join(destinationDir, MIT_LICENSE_FILE))
+ // npm packs LICENSE by itself but not LICENSE-MIT, so a `files` list has to name it.
+ if (publishJSON.files && !publishJSON.files.includes(MIT_LICENSE_FILE)) {
+ publishJSON.files = [...publishJSON.files, MIT_LICENSE_FILE]
+ }
+ }
+
await writeFile(
join(destinationDir, 'package.json'),
`${JSON.stringify(publishJSON, null, 2)}\n`
diff --git a/tools/release/release-packages/tests/publish-dirs.test.ts b/tools/release/release-packages/tests/publish-dirs.test.ts
index 3f5426b3e..d8d545d40 100644
--- a/tools/release/release-packages/tests/publish-dirs.test.ts
+++ b/tools/release/release-packages/tests/publish-dirs.test.ts
@@ -1,15 +1,20 @@
import { describe, expect, test } from 'bun:test'
+import { existsSync } from 'node:fs'
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import {
discoverPublishPackages,
+ npmPackFileList,
preparePublishDirectories,
publishPackageJSON
} from '#release/publish-dirs'
-async function fixtureRoot({ rootLicense = true } = {}) {
+async function fixtureRoot({
+ rootLicense = true,
+ license
+}: { rootLicense?: boolean; license?: string } = {}) {
const root = join(tmpdir(), `open-pencil-release-packages-${crypto.randomUUID()}`)
await mkdir(join(root, 'packages/example/dist'), { recursive: true })
await writeFile(join(root, 'packages/example/dist/index.js'), 'export {}\n')
@@ -22,6 +27,7 @@ async function fixtureRoot({ rootLicense = true } = {}) {
{
name: '@open-pencil/example',
version: '1.0.0',
+ ...(license ? { license } : {}),
files: ['dist', 'README.md'],
scripts: { build: 'tsdown' },
dependencies: { '@open-pencil/core': 'workspace:*', zod: '^4.0.0' },
@@ -128,6 +134,45 @@ describe('preparePublishDirectories', () => {
})
}, 30_000)
+ test.each(['Apache-2.0 AND MIT', '(mit AND Apache-2.0)', 'Apache-2.0 OR MIT+'])(
+ 'ships the repository’s MIT text beside a package’s own license when it is MIT in part: %s',
+ async (license) => {
+ const root = await fixtureRoot({ license })
+ await writeFile(join(root, 'packages/example/LICENSE'), 'apache license\n')
+ const outRoot = join(root, '.publish')
+
+ await preparePublishDirectories({
+ coreVersion: '0.13.2',
+ outRoot,
+ packages: await discoverPublishPackages(root),
+ root
+ })
+
+ expect(await readFile(join(outRoot, 'example/LICENSE'), 'utf8')).toBe('apache license\n')
+ expect(await readFile(join(outRoot, 'example/LICENSE-MIT'), 'utf8')).toBe('root license\n')
+ // Packed from the prepared directory, as releases are, both license texts ship.
+ expect(await npmPackFileList(join(outRoot, 'example'))).toEqual(
+ expect.arrayContaining(['LICENSE', 'LICENSE-MIT'])
+ )
+ },
+ 30_000
+ )
+
+ test('ships no MIT text beside a license that only resembles it, such as MIT-0', async () => {
+ const root = await fixtureRoot({ license: 'MIT-0' })
+ await writeFile(join(root, 'packages/example/LICENSE'), 'mit-0 license\n')
+ const outRoot = join(root, '.publish')
+
+ await preparePublishDirectories({
+ coreVersion: '0.13.2',
+ outRoot,
+ packages: await discoverPublishPackages(root),
+ root
+ })
+
+ expect(existsSync(join(outRoot, 'example/LICENSE-MIT'))).toBe(false)
+ }, 30_000)
+
test('refuses to prepare a package without any license text before packing', async () => {
const root = await fixtureRoot({ rootLicense: false })