@azure/bicep-rpc-client

中文文档
0.6.7发布于 2026/10/28MITESM + CJS近 30 天下载 2323

JSON-RPC实施Bicep CLI一体化

中文使用文档
文档目录14 节
  1. 开始
  2. 安装软件包
  3. 初始化客户端
  4. 键入特定的比策版本
  5. 使用现有的 Bicep 安装
  6. 可用业务
  7. 编译
  8. 编译 Params
  9. 格式
  10. 获取元数据
  11. 获取文件参考
  12. 获得部署
  13. 获取图像
  14. 版本

Azure Bicep RPC 客户端

用于程序互动的节点js库 双子CLI 通过JSON-RPC.

开始

安装软件包

npm install @azure/bicep-rpc-client

初始化客户端

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

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();

键入特定的比策版本

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

使用现有的 Bicep 安装

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

可用业务

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

编译

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

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 部署参数。 您可以选择覆盖参数值 .

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 (单位:千美元) 或后会.

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

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

获取元数据

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

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 文件所引用的所有文件路径——模块、已装入的文件和文件本身.

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

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

获得部署

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

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 国家 或后会.

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 版本.

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

版本与发布记录

@azure/bicep-rpc-client 共发布 7 个版本,首次发布于 2026/05/29;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.6.7latest2026/10/2811 天前
0.6.62026/10/2712 天前
0.6.12026/10/2315 天前
0.5.12026/10/2217 天前
0.4.12026/10/061 个月前
0.3.22026/10/031 个月前

关于 @azure/bicep-rpc-client 的常见问题

@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 和提交记录判断。