@arkstack/foundry

中文文档
0.22.1发布于 2026/11/05ES Module零依赖近 30 天下载 4202

Extensibility primitives and framework internals for the Arkstack ecosystem.

原始使用文档
文档目录3 节
  1. Installation
  2. Modules
  3. Hook

@arkstack/foundry

Foundry

Extensibility primitives and framework internals for the Arkstack ecosystem. This package provides the tools that shape how Arkstack behaves at runtime. Hooks, lifecycle interception, and utilities designed to extend and adapt the framework without modifying its core.

Installation

pnpm add @arkstack/foundry

Modules

Hook

src/Hook.ts

A global, named hook registry for extending Arkstack internals without modifying core code. Hooks are keyed by name and support positional slots (before, after, or any custom string). There is one registry per process: @arkstack/common re-exports this same Hook.

Hook.on(name, positions)

Registers callbacks for a hook's positions. Registering the same name again merges: only the positions supplied are added or replaced.

import { Hook } from '@arkstack/foundry'

Hook.on('request:handle', {
  before: (ctx) => console.log('before handler'),
  after: (ctx) => console.log('after handler'),
})

Hook.emit(name, pos, ...args)

Calls a position with the given arguments and returns its result: a Promise for an async hook, so it can be awaited. When nothing is registered there it does nothing and returns undefined, so callers need no has() check.

await Hook.emit('request:handle', 'before', ctx)

Hook.get(name, pos?)

Retrieves the full hook object or one position's callback, without calling it.

const hook = Hook.get('request:handle') // IHook | undefined
const before = Hook.get('request:handle', 'before') // function | undefined

Hook.has(name, pos?)

Checks whether a hook (or a specific position within it) exists.

Hook.has('request:handle') // true | false
Hook.has('request:handle', 'after') // true | false

Hook.off(name?, pos?)

Removes a hook or a single position. A hook left with no positions is deleted. Called with no arguments it clears every hook; a name that isn't registered is a no-op.

Hook.off('request:handle', 'before') // removes only the 'before' callback
Hook.off('request:handle') // removes the entire hook
Hook.off() // clears all hooks

Hook.all()

Returns all registered hooks as a plain record.

const hooks = Hook.all()
// { 'request:handle': { before: fn, after: fn } }

Hook.clear()

Clears all registered hooks.

Deprecated aliases

set() → on(), unset() → off(), getAll() → all(). get(name, pos, ...args) with arguments still calls the hook, but use emit(); get() should only retrieve.

版本与发布记录

@arkstack/foundry 共发布 137 个版本,首次发布于 2026/05/28;过去 12 个月发布了 137 个版本。

版本发布日期距今
0.22.1latest2026/11/052 天前
0.22.02026/11/052 天前
0.21.12026/11/052 天前
0.21.02026/10/2810 天前
0.20.22026/10/2315 天前
0.20.12026/10/2117 天前

关于 @arkstack/foundry 的常见问题

@arkstack/foundry 是什么?

Extensibility primitives and framework internals for the Arkstack ecosystem.

如何安装 @arkstack/foundry?

在项目目录运行 npm install @arkstack/foundry,或使用 pnpm add / yarn add / bun add。

@arkstack/foundry 支持 TypeScript 吗?

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

@arkstack/foundry 支持 ESM 还是 CommonJS?

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

@arkstack/foundry 可以商用吗?

@arkstack/foundry 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@arkstack/foundry 的下载量有多少?

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

@arkstack/foundry 还在维护吗?

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