@genroc/eval-node

中文文档
0.31.0发布于 2026/11/13Apache-2.0ES Module构建来源已验证近 30 天下载 5421

genroc script tasks for Node: the author-time bundler and the queue worker

原始使用文档
文档目录7 节
  1. Quick start
  2. Adding it to an existing project
  3. Writing a script
  4. Running the worker
  5. Errors
  6. Limits
  7. Links

@genroc/eval-node

TypeScript script tasks for genroc. The package provides two binaries:

  • genroc-import: the bundler. genctl runs it on every apply and generate to turn $import: ./script.ts into one typechecked, self-contained module string.
  • genroc-eval-node: the worker. It claims script tasks from genroc's queue and runs each one in a fresh worker thread.

Requires Node 24+. Full guide: TypeScript evaluation.

Quick start

genctl init --eval-node

This scaffolds a project with everything set up: the package, a .genroc that registers the resolver, a tsconfig.json, a reusable script-node child process, and a compose.yaml that runs the worker.

Adding it to an existing project

npm i -D @genroc/eval-node

Register the resolver in the .genroc beside your definitions:

resolvers:
  - name: import
    phase: typed
    ext: [.ts]
    command: [npx, genroc-import]
    types:
      Input: task.action.input.input
      Output: task.action.result

Then reference a script from a task. The simplest way is to spread the script-node child that genctl init --eval-node generates:

- id: greet
  action:
    type: child
    <<: "$process: ./script-node.genroc.yaml"
    input:
      code: "$import: ./greet.ts"
      input: { who: "$: input.who" }
    result_schema:
      type: object
      properties: { greeting: { type: string } }
      required: [greeting]

Writing a script

A script is an ES module. Its default export receives input, and its return value becomes the task result. The function may be async.

import type { Input, Output } from "./greet.genroc";

export default function (input: Input): Output {
  return { greeting: `hello, ${input.who}` };
}
  • genctl generate writes greet.genroc.d.ts beside the script. Input and Output come from the definition, so a mismatch fails the typecheck.
  • genctl apply typechecks and bundles. A type error or a missing default export fails the apply.
  • Imported files and npm packages are inlined into the bundle, so a stored definition never depends on what is installed later. Node builtins (node:fs, …) stay as imports and resolve on the worker.
  • The generated config extends your nearest tsconfig.json. To use Node globals and builtins, add "types": ["node"] to it.

Running the worker

docker run -e GENROC_SERVER=http://host:8448 ghcr.io/genroc/eval-node:latest
# or
GENROC_SERVER=http://localhost:8448 npx genroc-eval-node

The worker connects to genroc, not the other way round, so it only needs outbound access.

envdefault
GENROC_SERVERhttp://localhost:8448the genroc server
GENROC_TOKEN / GENROC_TOKEN_FILE(none)token, or a file holding it, when the server uses --auth
PROCESS / TASKscript-node / eval_nodethe process and task id this worker claims; the defaults are script-node's. Set PROCESS for a renamed copy. Neither may be empty.
CONCURRENCY4scripts run at once
LEASE_MS30000claim lease, renewed every third of it
POLL_MS250idle poll interval
WORKER_IDevaluator-<pid>the claim holder's name

With auth enabled, create a token that has only the worker permission:

genctl token create --perms worker --label evaluator -q

If the token is rejected, the worker exits instead of retrying.

Errors

When a script fails, the worker reports one of five error codes for your on_error rules to match. Retrying does not help with any of them, because the same code fails the same way:

codewhen
threwthe script threw or rejected
timeoutit ran past the task's timeout (5000 ms when the task has none)
compile_errorthe module does not parse, or has no default-export function
nonserializablethe return value cannot be serialized to JSON (a cycle, a BigInt)
exitedthe script called process.exit()

error.data is {name, stack?}. name is the error's class name, so throwing your own class LimitExceeded extends Error {} tells your failures apart; setting e.name overrides it, and a thrown non-Error is Thrown. The stack is mapped back to your source lines.

If the worker itself faults, it releases the task for another worker and reports no error.

The task's timeout is the script's budget, waiting in the queue included. The worker stops the script just before it and answers timeout, so external.timeout means no worker answered at all. With script-node, set it through the timeout_ms input.

Limits

  • Not a sandbox. Scripts have the worker host's filesystem, network and environment. Run only code you trust.
  • Not deterministic. On a retry the script runs again with the real clock and random numbers. Pass any value that must stay stable through input.
  • Memory is not isolated. A script that runs out of memory takes down the whole worker.
  • Run-once is opt-in. If a worker dies mid-script, the task is claimed again and the script runs again. Mark the task only_once if your script has side effects.
  • Inline code needs escaping. When you write code directly in YAML rather than $import, write ${ as $${, because genroc reads ${ as interpolation. Scripts in .ts files need no escaping.

版本与发布记录

@genroc/eval-node 共发布 374 个版本,首次发布于 2026/09/01;过去 12 个月发布了 374 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.31.0latest2026/11/133 天前
0.0.0-edge.c30783fbedge2026/11/133 天前
0.0.0-edge.249fac072026/11/115 天前
0.30.02026/11/115 天前
0.0.0-edge.02055f442026/11/115 天前
0.0.0-edge.2ef1ae242026/10/2620 天前

关于 @genroc/eval-node 的常见问题

@genroc/eval-node 是什么?

genroc script tasks for Node: the author-time bundler and the queue worker

如何安装 @genroc/eval-node?

在项目目录运行 npm install @genroc/eval-node,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 genroc-import、genroc-eval-node,可以用 npx genroc-import 直接运行。

@genroc/eval-node 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/genroc__eval-node 是否存在。

@genroc/eval-node 支持 ESM 还是 CommonJS?

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

@genroc/eval-node 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@genroc/eval-node 可以商用吗?

@genroc/eval-node 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@genroc/eval-node 的下载量有多少?

根据 npm 官方下载统计,@genroc/eval-node 在 2026/10/16 – 2026/11/14 这 30 天内被下载 5,421 次,日均约 181 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@genroc/eval-node 还在维护吗?

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