# @hapipal/hpal-debug 中文文档

规范地址：https://npmcn.com/package/%40hapipal/hpal-debug/

版本：2\.1\.0
npm 元数据更新时间：2022-11-28T04:20:06.201Z
中文译文更新时间：2026-11-17T18:19:16.719Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40hapipal/hpal-debug
原文对照：https://npmcn.com/package/%40hapipal/hpal-debug/?lang=original
项目主页：https://github.com/hapipal/hpal-debug#readme
源码仓库：https://github.com/hapipal/hpal-debug

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：36.2 kB，9 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=12
- 运行依赖：4 个
- peer 依赖：@hapi/hapi \>=19 \<22，joi \>=17 \<18
- 首次发布：2021-01-05T21:07:17.820Z
- 最新版本发布：2022-11-28T04:20:06.120Z
- 近 30 天下载量：4634（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

hpal CLI 调试工具

## 安装

```sh
npm install @hapipal/hpal-debug
```

也可以使用：`pnpm add @hapipal/hpal-debug`、`yarn add @hapipal/hpal-debug`、`bun add @hapipal/hpal-debug`

## README

# hpal 调试

happijs 调试工具 [hpal CLI (英语)](https://github.com/hapipal/hpal)

[![Build Status](https://travis-ci.com/hapipal/hpal-debug.svg?branch=main)](https://travis-ci.com/hapipal/hpal-debug) [![Coverage Status](https://coveralls.io/repos/hapipal/hpal-debug/badge.svg?branch=main&service=github)](https://coveralls.io/github/hapipal/hpal-debug?branch=main)

主维护者 - [变形常春藤](https://github.com/devinivy)

`hpal-debug` 是为了帮助你,

-   :ant: 在一个整洁,自定义的表格中显示您的路线信息.
    
    > `hpal run debug:routes --show cors`
    
-   : beetle: 使用您的 hopi 服务器, [模型](https://github.com/hapipal/schwifty), (中文(简体) ), [服务](https://github.com/hapipal/schmervice)等,通过REPL进行互动.
    
    > `hpal run debug:repl`
    
-   : bug: 从命令行切入您的路由而无需重新启动您的服务器 .
    
    > `hpal run debug:curl post /user --name Pal -v`
    

## 安装

> 如果你开始 [朋友锅炉板](https://github.com/hapipal/boilerplate),那么你的项目已经设置了 hpal -debug!

1.  从 npm 安装 hpal- debug 包作为 dev 依赖 .
    
    ```sh
    npm install --save-dev @hapipal/hpal-debug
    ```
    
2.  在您的服务器上注册 hpal-debug 作为 hopi 插件 .
    
    ```js
    await server.register(require('@hapipal/hpal-debug'));
    ```
    
3.  保证 `server.js` 或者说 `server/index.js` 导出一个名为函数的函数 `deployment` 返回您配置的 hopi 服务器 .
    
    下面是一个非常简单的锅炉平板代码的例子,用来配置一个popi服务器服务器,而不一定是"生产准备". 对于更完整的设置,考虑使用 [朋友锅炉板](https://github.com/hapipal/boilerplate),或查看其方法 [这里](https://github.com/hapipal/boilerplate/blob/pal/server/index.js)。 。 。 .
    
    ```js
    // server.js
    
    'use strict';
    
    const Hapi = require('hapi');
    const AppPlugin = require('./app');
    
    // hpal will look for and use exports.deployment()
    // as defined below to obtain a hapi server
    
    exports.deployment = async ({ start } = {}) => {
    
        const server = Hapi.server();
    
        // Assuming your application (its routes, etc.) live in a plugin
        await server.register(AppPlugin);
    
        if (process.env.NODE_ENV !== 'production') {
            await server.register(require('@hapipal/hpal-debug'));
        }
    
        if (start) {
            await server.start();
            console.log(`Server started at ${server.info.uri}`);
        }
    
        return server;
    };
    
    // Start the server only when this file is
    // run directly from the CLI, i.e. "node ./server"
    
    if (!module.parent) {
        exports.deployment({ start: true });
    }
    ```
    

就这样! 现在 hpal-debug 命令应该可以通过 [hpal CLI (英语)](https://github.com/hapipal/hpal)。一个简单的检查hpal-debug正确设置的方法就是输出一个漂亮的显示您的路由表,

```sh
npx hpal run debug:routes
```

## 使用量

> hpal-debug 用于 hopi v19+ 和 nodejs v12+ ()_下级支持参见 v1_) (中文(简体) ).

### 图标

#### `hpal run debug:routes`

> ```
> hpal run debug:routes [<route-identifier>] --hide <column-name> --show <column-name>
>   e.g. hpal run debug:routes --show cors
> ```

此命令输出您服务器路由表的清晰显示 .

为了显示单一路线, 您可以指定 `<route-identifier>` 作为路由标识(例如:. `user-create`),路线方法和路径(例如. `post /users`),或路由路径(例如. `/users`方法默认为 `get`) (中文(简体) ).

可能使用 `-H` `--hide` 财务报告和审定财务报表 `-s` `--show` 分别为旗帜。 使用多回旗来隐藏或显示多回列. 以下为可用列列表.

`method` `path` `id` `plugin` `vhost` `auth` `cors` `tags` `description`

这个 `-r` `--raw` 旗帜将输出一个最小格式的表格,由标签字符分隔出列。 非TTY使用自动默认为原始输出.

这些选项的概要可随 `-h` `--help` 旗帜.

#### `hpal run debug:repl`

> ```
> hpal run debug:repl
> ```

此命令在您初始化后启动一个全功能的交互式 REPL `server` 在背景方面。 你的服务器的每一个方法,属性, [轻而易举](https://github.com/hapipal/schwifty) 模型,以及 [缩写](https://github.com/hapipal/schmervice) 此外,还直接提供方便服务。 下 [掌声](https://github.com/hapipal/hpal) v2 您可以使用顶级 `await`。您也可以使用 `hpal run debug`。 。 。 .

##### 示例

```js
$ hpal run debug:repl

hpal> server.info                 // you can always use the server directly
{ created: 1527567336111,
  started: 0,
  host: 'your-computer.local',
  ...
hpal>                             // or you can omit the "server." for public properties and methods...
hpal>
hpal> info.uri                    // at what URI would I access my server?
'http://your-computer.local'
hpal> Object.keys(registrations)  // what plugins are registered?
[ '@hapipal/hpal-debug', 'my-app' ]
hpal> table().length              // how many routes are defined?
12
hpal> !!match('get', '/my/user')  // does this route exist?
true
hpal> .exit
```

#### `hpal run debug:curl`

> ```
> hpal run debug:curl <route-identifier> [<route-parameters>] --data <raw-payload> --header <header-info> --raw --verbose
>   e.g. hpal run debug:curl post /users --firstName Paldo -v
> ```

此命令向一个路由提出请求并显示结果 。 值得注意的是,您不需要运行中的服务器来测试您的路径 `hpal run debug:curl`来啊!

需要您通过指定一个 `<route-identifier>` 作为路由标识(例如:. `user-create`),路线方法和路径(例如. `post /users`),或路由路径(例如. `/users`方法默认为 `get`) (中文(简体) ).

您可以指定任何有效载荷、查询或路径参数为 `<route-parameters>` 旗帜或 `<route-identifier>`通过 JOI 验证使用的任何参数 [`route.options.validate`](https://hapi.dev/api/#route.options.validate) 拥有命令行旗。 例如,带有 id 的路由 `user-update`方法 `patch`路径 `/user/{id}` 验证 `id` 路径参数和 a `hometown` 使用下列命令可以击中有效载荷参数,

```sh
hpal run debug:curl patch /user/42 --hometown "Buenos Aires"

# or

hpal run debug:curl user-update --id 42 --hometown "Buenos Aires"
```

也可以指定被嵌入的参数。 如果前一示例中的路径验证了该形式的有效载荷 `{ user: { hometown } }`,人们可能会使用以下命令之一,

```sh
hpal run debug:curl user-update --id 42 --user-hometown "Buenos Aires"

# or

hpal run debug:curl user-update --id 42 --user '{ "hometown": "Buenos Aires" }'
```

这个 `-d` `--data` 可使用旗帜指定请求的有效载荷为生字符串.

这个 `-H` `--header` 标记可以用于在格式中指定请求头 `header-name: header value`。此旗帜可能多次用于设置多条标题.

这个 `-r` `--raw` 财务报告和审定财务报表 `-v` `--verbose` 旗帜会影响命令的输出,并且可以互相并用或单独使用. 这个 `-r` `--raw` 旗帜确保所有输出未格式化,而 `-v` `--verbose` 旗帜显示有关请求和响应的信息,包括时间、请求的有效载荷、请求头、响应头、状态代码和响应有效载荷。 非TTY使用自动默认为原始输出.

这些选项的概要可随 `-h` `--help` 旗帜.

##### 示例

```
$ hpal run debug:curl /user -v

get /user (30ms)

request headers
───────────────────────────────────────────────────────────────────
 user-agent    shot
 host          your-computer.local:0

response headers
───────────────────────────────────────────────────────────────────
 content-type      application/json; charset=utf-8
 vary              origin
 cache-control     no-cache
 content-length    55
 accept-ranges     bytes

result (200 ok)
───────────────────────────────────────────────────────────────────
{
  id: 42,
  firstName: 'Paldo',
  hometown: 'Buenos Aires'
}
```

## 常见问题

### @hapipal/hpal-debug 是什么？

hpal CLI 调试工具

### 如何安装 @hapipal/hpal-debug？

在项目目录运行 npm install @hapipal/hpal-debug，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@hapi/hapi（\>=19 \<22）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @hapipal/hpal-debug 支持 TypeScript 吗？

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

### @hapipal/hpal-debug 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @hapipal/hpal-debug 需要什么版本的 Node\.js？

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

### @hapipal/hpal-debug 可以商用吗？

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

### @hapipal/hpal-debug 的下载量有多少？

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

### @hapipal/hpal-debug 还在维护吗？

最新版本 2\.1\.0 发布于 2022/11/28（3 年前）；至今共发布 2 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/01/06。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

