# @azure/bicep-rpc-client 中文文档

规范地址：https://npmcn.com/package/%40azure/bicep-rpc-client/

版本：0\.6\.7
npm 元数据更新时间：2026-10-27T20:50:58.747Z
中文译文更新时间：2026-11-07T21:56:22.900Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40azure/bicep-rpc-client
原文对照：https://npmcn.com/package/%40azure/bicep-rpc-client/?lang=original
项目主页：https://github.com/Azure/bicep-deploy#readme
源码仓库：https://github.com/Azure/bicep-deploy

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

- 包体积（解压后）：70.8 kB，19 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- Node.js 要求：\>=20
- 运行依赖：2 个
- 首次发布：2026-05-28T19:10:07.706Z
- 最新版本发布：2026-10-27T20:50:58.473Z
- 近 30 天下载量：2323（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 7 个）

## 中文简介

JSON-RPC实施Bicep CLI一体化

## 安装

```sh
npm install @azure/bicep-rpc-client
```

也可以使用：`pnpm add @azure/bicep-rpc-client`、`yarn add @azure/bicep-rpc-client`、`bun add @azure/bicep-rpc-client`

## README

# Azure Bicep RPC 客户端

用于程序互动的节点js库 [双子CLI](https://github.com/Azure/bicep) 通过JSON-RPC.

## 开始

### 安装软件包

```bash
npm install @azure/bicep-rpc-client
```

### 初始化客户端

`Bicep.install()` 下载 Bicep CLI(如果需要)并返回其路径。 默认情况下, 通过一个目录, 如 `os.tmpdir()` 或者说 `~/.bicep` 作为基础路径。 那就打电话 `Bicep.initialize()` 打开 JSON-RPC 连接.

```typescript
import os from 'os';
import { Bicep } from '@azure/bicep-rpc-client';

const bicepPath = await Bicep.install(os.tmpdir());
const bicep = await Bicep.initialize(bicepPath);

// ... use bicep ...

bicep.dispose();
```

### 键入特定的比策版本

```typescript
const bicepPath = await Bicep.install(os.tmpdir(), '0.38.5');
```

### 使用现有的 Bicep 安装

```typescript
const bicep = await Bicep.initialize('/usr/local/bin/bicep');
```

## 可用业务

所有的方法都是同Bicep CLI在JSON-RPC上进行协同并交流. 打电话 `bicep.dispose()` 当关闭连接时.

### 编译

编译 a `.bicep` 文件为 ARM 模板 JSON 字符串.

```typescript
const result = await bicep.compile({ path: './main.bicep' });

if (result.success) {
  // result.contents contains the ARM template JSON
  console.log(result.contents);
}
```

### 编译 Params

编译 a `.bicepparam` 输入 ARM 部署参数。 您可以选择覆盖参数值 .

```typescript
const result = await bicep.compileParams({
  path: './main.bicepparam',
  parameterOverrides: {},
});

if (result.success) {
  console.log(result.parameters); // ARM parameters JSON
  console.log(result.template);   // ARM template JSON (if resolvable)
  // result.templateSpecId is set when the params file references a template spec
}
```

### 格式

按照标准Bicep格式化规则格式化 Bicep 文件。 需要双子CLI **0.37.0 (单位:千美元)** 或后会.

```typescript
const result = await bicep.format({ path: './main.bicep' });

fs.writeFileSync('./main.bicep', result.contents);
```

### 获取元数据

从 Bicep 文件获取参数、输出、导出和文件级元数据.

```typescript
const result = await bicep.getMetadata({ path: './main.bicep' });

for (const param of result.parameters) {
  console.log(`param ${param.name}: ${param.type?.name} — ${param.description}`);
}

for (const output of result.outputs) {
  console.log(`output ${output.name}: ${output.type?.name}`);
}

for (const exp of result.exports) {
  console.log(`@export() ${exp.kind} ${exp.name}`);
}

for (const meta of result.metadata) {
  console.log(`metadata ${meta.name} = '${meta.value}'`);
}
```

### 获取文件参考

返回 Bicep 文件所引用的所有文件路径——模块、已装入的文件和文件本身.

```typescript
const result = await bicep.getFileReferences({ path: './main.bicep' });

for (const filePath of result.filePaths) {
  console.log(filePath);
}
```

### 获得部署

返回 Bicep 文件的资源依赖图,用于可视化.

```typescript
const result = await bicep.getDeploymentGraph({ path: './main.bicep' });

for (const node of result.nodes) {
  const existing = node.isExisting ? ' (existing)' : '';
  console.log(`  ${node.name}: ${node.type}${existing}`);
}

for (const edge of result.edges) {
  console.log(`  ${edge.source} -> ${edge.target}`);
}
```

### 获取图像

生成一个快照 `.bicepparam` 带有 Azure 部署上下文的文件。 需要双子CLI **0.36.1 国家** 或后会.

```typescript
const result = await bicep.getSnapshot({
  path: './main.bicepparam',
  metadata: {
    tenantId: undefined,
    subscriptionId: '00000000-0000-0000-0000-000000000000',
    resourceGroup: 'my-rg',
    location: 'eastus',
    deploymentName: 'my-deployment',
  },
  externalInputs: undefined,
});

console.log(result.snapshot);
```

### 版本

返回连接的 Bicep CLI 版本.

```typescript
const ver = await bicep.version();
console.log(`Bicep CLI version: ${ver}`);
```

## 常见问题

### @azure/bicep-rpc-client 是什么？

JSON-RPC实施Bicep CLI一体化

### 如何安装 @azure/bicep-rpc-client？

在项目目录运行 npm install @azure/bicep-rpc-client，或使用 pnpm add / yarn add / bun add。

### @azure/bicep-rpc-client 支持 TypeScript 吗？

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

### @azure/bicep-rpc-client 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @azure/bicep-rpc-client 需要什么版本的 Node\.js？

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

### @azure/bicep-rpc-client 可以商用吗？

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

### @azure/bicep-rpc-client 的下载量有多少？

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

### @azure/bicep-rpc-client 还在维护吗？

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

