Add the versioned plugin SDK package and its release script
The new package packages/plugin-sdk (@runestone/plugin-sdk) is the one source of the public plugin types. It contains PluginApi and its members, the manifest type, API_VERSION, and feature checks (hasFeature, requireFeature, requireFeatures, missingFeatures). It also contains the action icons and the tooltip helper as DOM functions, because RuneStone has no API for them. Menus stay host-drawn through api.ui.showActionMenu, so the SDK contains only the menu types. The SDK uses the Apache License 2.0. The host imports the SDK with relative paths in src/lib/plugins/sdk.ts, src/lib/ui/actionIcons.ts, and src/lib/ui/tooltip.ts. The completion, Git, background, and contribution contract files export the SDK types. The menu files keep their types, because the Terminal plugin keeps copies of them. A unit test makes sure that those types and the SDK types are the same. The menu inventory now scans the SDK source. pnpm sdk:build compiles the SDK to dist/. pnpm release:sdk --version <v> builds it, then commits and tags v<v> in a local clone of the public repository. It never pushes, and it prints the push commands. It stops before a change in these conditions: - The clone is missing, has changes, or is not on a branch. - The tag exists, or the version is not greater than the current version. - The package has no LICENSE file, or the SDK source has changes that are not committed. A failed attempt restores the version and the clone. pnpm check type checks the SDK and the example plugin. The example plugin now has JSDoc types from the SDK. pnpm test covers the feature checks, the host and SDK parity, and the release script with temporary Git repositories. The plugin development, release, development, and completion guides describe the SDK.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
This reference gives the package contract, the build procedure, and the API for RuneStone plugin authors.
|
||||
|
||||
- [Install the SDK](#install-the-sdk)
|
||||
- [Package contract](#package-contract)
|
||||
- [Build and package a plugin](#build-and-package-a-plugin)
|
||||
- [Build examples](#build-examples)
|
||||
@@ -16,11 +17,37 @@ This reference gives the package contract, the build procedure, and the API for
|
||||
- [Git API](#git-api)
|
||||
- [Background API](#background-api)
|
||||
|
||||
## Install the SDK
|
||||
|
||||
The plugin SDK `@runestone/plugin-sdk` gives the API types, the feature checks, and the RuneStone icons and tooltip.
|
||||
Install it in each plugin project from a release tag of its public repository. The SDK is not on the npm registry.
|
||||
|
||||
```sh
|
||||
pnpm add -D "git+https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK.git#v0.1.0"
|
||||
```
|
||||
|
||||
- The repository is public. The installation needs no access token and no `.npmrc` file.
|
||||
- Always give a tag. To change the SDK version, change the tag in `package.json`.
|
||||
- Bundle the SDK helpers into the entry module. A type-only import adds no code.
|
||||
- Do not copy RuneStone source files into a plugin, and do not import them from a RuneStone checkout. Use the SDK types and the host APIs.
|
||||
|
||||
| SDK import | Contents |
|
||||
| --- | --- |
|
||||
| `@runestone/plugin-sdk` | `PluginApi` and its members, `PluginManifest`, `API_VERSION`, and the [feature checks](#compatibility) |
|
||||
| `@runestone/plugin-sdk/icons` | `actionIcons` and `actionIcon(name)`. See [Commands](#commands). |
|
||||
| `@runestone/plugin-sdk/tooltip` | `attachTooltip(element, label)`, the tooltip of RuneStone controls |
|
||||
|
||||
For menus, use `api.ui.showActionMenu`. See [Menus](#menus).
|
||||
The SDK source is `packages/plugin-sdk/` in this repository. For its versions and releases, see [SDK releases](releases.md#sdk-releases).
|
||||
The [SDK README](../packages/plugin-sdk/README.md) has a minimal plugin in TypeScript.
|
||||
|
||||
Example: `fixtures/plugins/workspace-overview/main.js` uses JSDoc types from the SDK and needs no compile step. `pnpm check` checks it with `fixtures/plugins/tsconfig.json`.
|
||||
|
||||
## Package contract
|
||||
|
||||
A plugin is one standard `.zip` file with `plugin.json` at the archive root.
|
||||
All plugins use the same package format and the same install, enable, disable, and removal lifecycle.
|
||||
The interface types are in `src/lib/plugins/sdk.ts`.
|
||||
The manifest type is `PluginManifest` in the [SDK](#install-the-sdk).
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -184,11 +211,18 @@ export function activate(api) {
|
||||
|
||||
Members marked optional can be absent on older RuneStone hosts.
|
||||
Before you call an optional member, make sure that it exists. If the plugin cannot work without it, show an error that tells the user to update RuneStone.
|
||||
The SDK feature checks do this. Their error names each missing feature and tells the user to update RuneStone.
|
||||
|
||||
```js
|
||||
if (!api.workspace.readBytes) throw new Error("Update RuneStone to use this plugin.");
|
||||
```ts
|
||||
import { hasFeature, requireFeature, requireFeatures } from "@runestone/plugin-sdk";
|
||||
|
||||
requireFeatures(api, ["pty", "workspace.readBytes"]);
|
||||
const pty = requireFeature(api, "pty");
|
||||
if (hasFeature(api, "settings.subscribe")) watchSettings();
|
||||
```
|
||||
|
||||
Without the SDK, examine the member directly: `if (!api.workspace.readBytes) throw new Error("Update RuneStone to use this plugin.");`
|
||||
|
||||
Older hosts ignore unknown fields in objects that you pass to the host, such as a view `icon` or `launch` handler.
|
||||
|
||||
### Activation and cleanup
|
||||
@@ -248,7 +282,7 @@ api.registerCommand({ id: "next", title: "Next image", icon: "skip-forward", run
|
||||
| `title` | Required text. |
|
||||
| `run` | Required function. Can return a promise. |
|
||||
| `category` | `"action"` (default) adds the command to the **Commands** menu. `"open"` adds it to the **Plug-in views** menu. |
|
||||
| `icon` | Optional. A name from `src/lib/ui/actionIcons.ts`, such as `play`, `pause`, `skip-forward`, or `refresh`, or a view icon name. |
|
||||
| `icon` | Optional. An `ActionIcon` name from the SDK, such as `play`, `pause`, `skip-forward`, or `refresh`, or a view icon name. |
|
||||
|
||||
Give each command a recognizable icon.
|
||||
|
||||
@@ -298,7 +332,7 @@ RuneStone translates only its own interface. It does not translate plugin text o
|
||||
### Menus
|
||||
|
||||
`ui.showActionMenu({ x, y, items, label?, parent? })` opens the shared action menu at a screen position. It returns `{ close() }`.
|
||||
Each item is `{ label, icon?, shortcut?, run?, children?, disabled?, checked?, radio?, title? }` or `{ separator: true }`. The type is `ActionMenuItem` in `src/lib/ui/actionMenu.ts`.
|
||||
Each item is `{ label, icon?, shortcut?, run?, children?, disabled?, checked?, radio?, title? }` or `{ separator: true }`. The SDK types are `ActionMenuItem` and `ActionMenuOptions`.
|
||||
The menu closes on selection, outside click, resize, window blur, scroll, and plugin shutdown.
|
||||
Use this menu instead of a custom menu. See the [interface design reference](ui-design.md).
|
||||
|
||||
@@ -347,7 +381,7 @@ In `readMany`, one failed file does not stop the other reads. More than 64 paths
|
||||
|
||||
### Contributions
|
||||
|
||||
`contribute(key, value)` registers a host feature. The types are in `src/lib/plugins/contracts.ts`.
|
||||
`contribute(key, value)` registers a host feature. The SDK type is `Contributions`.
|
||||
Only one enabled plugin can own each key. The host removes contributions before cleanup starts.
|
||||
|
||||
| Key | Purpose | Owner |
|
||||
@@ -382,7 +416,7 @@ Their test scripts replace `window.__TAURI_INTERNALS__` with a test double. That
|
||||
|
||||
## Terminal API
|
||||
|
||||
`api.pty` (`version: 1`) starts shells in pseudo terminals. The types are `PtyApi` and `PtySession` in `src/lib/plugins/sdk.ts`.
|
||||
`api.pty` (`version: 1`) starts shells in pseudo terminals. The SDK types are `PtyApi` and `PtySession`.
|
||||
|
||||
| Member | Contract |
|
||||
| --- | --- |
|
||||
@@ -447,7 +481,7 @@ Make the data of a service a documented contract of the provider. Give its name,
|
||||
## Git API
|
||||
|
||||
`api.git` gives Git operations for the active workspace of the window. The host runs the `git` command, one operation at a time.
|
||||
The types are in `src/lib/git/contracts.ts`. Every method checks for plugin shutdown first.
|
||||
The SDK type is `GitApi`. Every method checks for plugin shutdown first.
|
||||
|
||||
| Method | Contract |
|
||||
| --- | --- |
|
||||
|
||||
Reference in New Issue
Block a user