@azure/bicep-rpc-client

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

JSON-RPC implementation for Bicep CLI integration

原始使用文档
文档目录14 节
  1. Getting started
  2. Install the package
  3. Initialize the client
  4. Pin a specific Bicep version
  5. Use an existing Bicep installation
  6. Available operations
  7. compile
  8. compileParams
  9. format
  10. getMetadata
  11. getFileReferences
  12. getDeploymentGraph
  13. getSnapshot
  14. version

Azure Bicep RPC Client

A Node.js library for programmatically interacting with the Bicep CLI via JSON-RPC.

Getting started

Install the package

npm install @azure/bicep-rpc-client

Initialize the client

Bicep.install() downloads the Bicep CLI (if needed) and returns its path. By default, pass a directory such as os.tmpdir() or ~/.bicep as the base path. Then call Bicep.initialize() to open a JSON-RPC connection.

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

Pin a specific Bicep version

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

Use an existing Bicep installation

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

Available operations

All methods are async and communicate with the Bicep CLI over JSON-RPC. Call bicep.dispose() when finished to close the connection.

compile

Compiles a .bicep file into an ARM template JSON string.

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

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

compileParams

Compiles a .bicepparam file into ARM deployment parameters. You can optionally override parameter values.

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
}

format

Formats a Bicep file according to the standard Bicep formatting rules. Requires Bicep CLI 0.37.0 or later.

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

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

getMetadata

Retrieves parameters, outputs, exports, and file-level metadata from a Bicep file.

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}'`);
}

getFileReferences

Returns all file paths referenced by a Bicep file — modules, loaded files, and the file itself.

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

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

getDeploymentGraph

Returns the resource dependency graph for a Bicep file, useful for visualization.

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}`);
}

getSnapshot

Generates a snapshot of a .bicepparam file with Azure deployment context. Requires Bicep CLI 0.36.1 or later.

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

version

Returns the version of the connected 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 implementation for Bicep CLI integration

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