myphp-runtime

中文文档
1.161.0发布于 2026/11/04MITTypeScriptES Module零依赖构建来源已验证

Typed access to the MyPHP runtime in the pages of MyPHP desktop apps

原始使用文档

myphp-runtime

Typed access to the runtime of MyPHP apps, for their web frontends.

MyPHP injects its runtime into every page of an app as window.myphp. This package gives it types and imports. The client that myphp generate writes for your bound PHP services is built on it, so you mostly use that:

import { Greeter, events } from "./myphp"; // generated

const greeting = await Greeter.greet("Ada");
events.tick.on((time) => console.log(time));

Install it from npm, npm install myphp-runtime, or depend on it from the MyPHP the app runs on, "myphp-runtime": "file:<MyPHP>/packages/runtime", as myphp init -template web writes it. Its modules are TypeScript, which Vite and Bun take as they are.

Use the package directly for the window and the platform:

import { currentWindow, isCallError, isMyPHP, runtime } from "myphp-runtime";

if (isMyPHP() && runtime().platform === "darwin") {
  document.body.classList.add("mac");
}
await currentWindow.toggleMaximize();

A PHP method that streams values through a MyPHP\Channel parameter takes a Channel in its place:

import { Channel } from "myphp-runtime";

const lines = new Channel<string>();
const done = Shell.tail("ls -R", lines);
for await (const line of lines) console.log(line);
await done;

A PHP method that throws rejects with a CallError (see isCallError). Outside a MyPHP window, e.g. when the dev server is opened in a browser, calls reject and isMyPHP() is false.

myphp-runtime/i18n formats the messages of the app's catalogs in its pages, as MyPHP\Message does in PHP: messages of ICU MessageFormat, with the plural rules, numbers and dates of Intl. myphp generate writes a typed module of the catalogs next to the client (locales.ts) on top of it:

import { messages } from "./locales"; // generated

status.textContent = messages.filesSelected(3); // "3 files selected"

formatMessage(locale, message, args) formats a message of your own.

版本与发布记录

myphp-runtime 共发布 110 个版本,首次发布于 2026/10/26;过去 12 个月发布了 110 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.161.0latest2026/11/04今天
1.160.02026/11/04今天
1.159.02026/11/041 天前
1.146.02026/11/023 天前
1.145.02026/11/013 天前
1.143.02026/11/013 天前

关于 myphp-runtime 的常见问题

myphp-runtime 是什么?

Typed access to the MyPHP runtime in the pages of MyPHP desktop apps

如何安装 myphp-runtime?

在项目目录运行 npm install myphp-runtime,或使用 pnpm add / yarn add / bun add。

myphp-runtime 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

myphp-runtime 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

myphp-runtime 可以商用吗?

myphp-runtime 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

myphp-runtime 还在维护吗?

最新版本 1.161.0 发布于 2026/11/04(今天);至今共发布 110 个版本,其中过去 12 个月发布了 110 个;首次发布于 2026/10/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。