Andrey Antukh 1debed7f3c
⬆️ Update dependencies (#13191)
* ⬆️ Update dependencies

* 🐛 Fix CI failures after the dependency update

Both the plugins bundle build and the frontend lint job failed after the
dependency bump. `@penpot/plugin-styles` now resolves to the workspace source,
which lacked the public `styles.css` entry point; add a shim that imports
`src/lib/styles.css` so the linked and published layouts expose the same path.

Stylelint 18 enables three rules that flag existing legacy styles. Disable
them with a TODO until those declarations are cleaned up, keeping this
dependency update free of visual changes.

AI-assisted-by: hy4-flash-free
2026-11-20 09:53:37 +01:00

4.0 KiB

Plugins Architecture and Workflow

plugins/: standalone TypeScript/pnpm workspace for Plugin API packages and sample plugins. Related to, distinct from, frontend CLJS Plugin API runtime.

Layout

  • libs/plugin-types: TypeScript declarations for the public Penpot Plugin API. Type-only package; runtime behavior is implemented elsewhere.
  • libs/plugins-runtime: runtime that loads plugins and exposes/generated API behavior to plugin code.
  • libs/plugins-styles: reusable styling package for plugins. Keep its root styles.css: it imports src/lib/styles.css and mirrors the bundled file tools/scripts/build-css.mjs publishes. When a consumer depends on the same version as this package, pnpm links the source tree instead of the published package, and the documented @penpot/plugin-styles/styles.css import must still resolve.
  • apps/*-plugin: sample/development plugins. apps/e2e: plugin e2e tests.

Dev Workflow

  • From plugins/: install pnpm -r install; runtime dev server pnpm run start or pnpm run start:app:runtime; sample plugin pnpm run start:plugin:<name>; build runtime pnpm run build:runtime; build plugins pnpm run build:plugins; lint pnpm run lint; format pnpm run format:check / pnpm run format; tests pnpm run test; e2e pnpm run test:e2e.
  • If a change affects public Plugin API types or runtime, update plugins/CHANGELOG.md. Prefix type/signature entries with **plugin-types:**; runtime behavior entries with **plugin-runtime:**.
  • Cross-cutting testing principles and anti-patterns: mem:testing.
  • JS Plugin API behavior inside Penpot app: mem:frontend/plugin-api-to-cljs-binding; TS declarations are not runtime code; many API objects are CLJS proxies in frontend/src/app/plugins/*.cljs.

Sandbox and global cleanup

  • src/index.ts calls bootstrapSES() (in src/lib/bootstrap.ts) at module load. If repairIntrinsics throws (e.g. SES 2.2+ rejects a Temporal wrapped by a browser extension), the error is caught, getPluginsRuntimeError() exposes it, and initPluginsRuntime installs no ɵ* globals: the frontend app still boots, plugins and MCP are unavailable in that environment. On failure, Function.prototype.toString has already been replaced but no intrinsics are hardened and no compartment/sandbox is created — never run plugins on that path.
  • The runtime uses SES compartments. Public API return values are passed through ses.safeReturn before crossing back to plugin code.
  • Plugin fetch is sanitized: credentials are omitted and Authorization is blanked. The exposed response only includes ok/status/statusText/url/text/json.
  • Timer callbacks are wrapped to mark plugin-originated errors, and timeout/interval IDs are tracked so plugin close can clear them.
  • Plugin-originated errors are tracked in a WeakMap instead of mutating error objects, because SES can freeze errors.
  • Closing a plugin removes public API keys from the compartment globalThis.

Lifecycle

  • Loading a plugin closes existing non-background plugins and removes them from the runtime registry. Background plugins (allowBackground) keep running and must stay registered: the registry routes their UI postMessage traffic by sender iframe and is what ɵunloadPlugin searches.
  • If sandbox evaluation fails, the runtime marks the error as plugin-originated, closes the plugin, and rethrows.
  • plugin-manager removes event listeners, timers, intervals, and modal state on close, and marks the plugin destroyed. Listener callbacks check that flag because Penpot events can fire after close.

Modal/UI behavior

  • Modal URL preparation differs by manifest version: v1 uses query string parameters, v2 puts parameters in the URL hash.
  • openModal is idempotent for the same iframe source and avoids reopening when the target URL is already displayed.
  • Modal permissions are derived from manifest permissions (allow:downloads, clipboard:read, clipboard:write).
  • resizeModal clamps to at least 200x200 and at most the window minus margins, adjusting transform so the modal remains in the viewport.