@h-ai/cli 1.0.0-beta.17 → 1.0.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ export { generateConfigFile, generateEnvExample, generateProductionEnvironment } from './chunk-7NVRYYHN.js';
3
+ import './chunk-ZSDEVXZ7.js';
4
+ //# sourceMappingURL=cli-config-templates-QG5HOYR5.js.map
5
+ //# sourceMappingURL=cli-config-templates-QG5HOYR5.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"cli-config-templates-MKVYSK3E.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"cli-config-templates-QG5HOYR5.js"}
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- export { generateModuleSkillFile, generateProjectAiSupport, generateSkillFiles, resolveCompatibleSkillNames, resolveSkillNamesForPackages } from './chunk-EWTIVFHN.js';
2
+ export { generateModuleSkillFile, generateProjectAiSupport, generateSkillFiles, resolveCompatibleSkillNames, resolveSkillNamesForPackages } from './chunk-6YZBC5MO.js';
3
3
  import './chunk-ZSDEVXZ7.js';
4
- //# sourceMappingURL=cli-skill-templates-M64VPXZ4.js.map
5
- //# sourceMappingURL=cli-skill-templates-M64VPXZ4.js.map
4
+ //# sourceMappingURL=cli-skill-templates-W4I6ZKYW.js.map
5
+ //# sourceMappingURL=cli-skill-templates-W4I6ZKYW.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"cli-skill-templates-M64VPXZ4.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"cli-skill-templates-W4I6ZKYW.js"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { generateConfigFile, runtimeEnvironmentVariables, renderEnvironment, generateProductionEnvironment, moduleEnvironmentVariables, documentConfig, parameterizeConfig } from './chunk-S2ZP7BHG.js';
3
- import { cliM } from './chunk-EWTIVFHN.js';
2
+ import { generateConfigFile, runtimeEnvironmentVariables, renderEnvironment, generateProductionEnvironment, moduleEnvironmentVariables, documentConfig, parameterizeConfig } from './chunk-7NVRYYHN.js';
3
+ import { cliM } from './chunk-6YZBC5MO.js';
4
4
  import { __commonJS, __export, __toESM } from './chunk-ZSDEVXZ7.js';
5
5
  import process14 from 'process';
6
6
  import { cac } from 'cac';
@@ -4133,7 +4133,7 @@ async function createProject(options) {
4133
4133
  });
4134
4134
  await generateFromTemplates(projectPath, context);
4135
4135
  {
4136
- const { generateConfigFile: generateConfigFile2, generateEnvExample, generateProductionEnvironment: generateProductionEnvironment2 } = await import('./cli-config-templates-MKVYSK3E.js');
4136
+ const { generateConfigFile: generateConfigFile2, generateEnvExample, generateProductionEnvironment: generateProductionEnvironment2 } = await import('./cli-config-templates-QG5HOYR5.js');
4137
4137
  const configs = resolvedOptions.moduleConfigs;
4138
4138
  const isApiWorkspace = resolvedOptions.appType === "api";
4139
4139
  const isFullstack = resolvedOptions.appType === "fullstack";
@@ -4218,7 +4218,7 @@ HAI_CRYPTO_TRANSPORT_SERVERKEYRING='${JSON.stringify(ring)}'
4218
4218
  }
4219
4219
  await fse.writeFile(path2.join(envDirectory, ".env.local"), "# \u672C\u673A\u901A\u7528\u79C1\u6709\u8986\u76D6\uFF0C\u4E0D\u63D0\u4EA4 Git\uFF1B\u521D\u59CB\u5BC6\u7801\u548C\u4F20\u8F93\u5BC6\u94A5\u73AF\u5206\u522B\u4F4D\u4E8E .env.dev.local / .env.test.local / .env.prod.local\u3002\n", { mode: 384 });
4220
4220
  }
4221
- const { generateSkillFiles } = await import('./cli-skill-templates-M64VPXZ4.js');
4221
+ const { generateSkillFiles } = await import('./cli-skill-templates-W4I6ZKYW.js');
4222
4222
  await generateSkillFiles(
4223
4223
  projectPath,
4224
4224
  resolvedOptions.features,
@@ -5199,7 +5199,7 @@ async function addModule(options) {
5199
5199
  }
5200
5200
  const selected = baseDefinition.configKey === "db" ? "db" : moduleName;
5201
5201
  const moduleDef = { ...baseDefinition, deps: resolveFeatureDependencies([selected]).filter((feature) => feature !== selected) };
5202
- const { generateProjectAiSupport, resolveSkillNamesForPackages } = await import('./cli-skill-templates-M64VPXZ4.js');
5202
+ const { generateProjectAiSupport, resolveSkillNamesForPackages } = await import('./cli-skill-templates-W4I6ZKYW.js');
5203
5203
  const allPackages = new Set(moduleDef.packages);
5204
5204
  for (const dep of moduleDef.deps) {
5205
5205
  for (const name of MODULE_MAP[dep]?.packages ?? [])
@@ -25004,6 +25004,13 @@ external_exports.object({
25004
25004
  appVersion: external_exports.string().max(80).regex(/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9a-z-]+(?:\.[0-9a-z-]+)*)?(?:\+[0-9a-z-]+(?:\.[0-9a-z-]+)*)?$/i),
25005
25005
  /** 本次构建标识;同一应用版本允许重复构建。 */
25006
25006
  buildId: external_exports.string().max(128).regex(/^[a-z0-9][\w.+-]*$/i),
25007
+ /** 构建启动时观察到的 Git 来源;历史清单可以省略。 */
25008
+ source: external_exports.object({
25009
+ /** 工程 package.json 所在仓库的提交 SHA;无法确定时为 unknown。 */
25010
+ commit: external_exports.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64}|unknown)$/),
25011
+ /** 工程目录有未提交改动时为 true;无法检查时为 null。 */
25012
+ dirty: external_exports.boolean().nullable()
25013
+ }).optional(),
25007
25014
  /** 只包含所选镜像的构建不能用于首次安装。 */
25008
25015
  partial: external_exports.boolean().default(false),
25009
25016
  /** 是否包含浏览器端;仅构建 serv 时也保留完整工程的 Web 拓扑。 */
@@ -25024,6 +25031,8 @@ external_exports.object({
25024
25031
  imageRef: external_exports.string().regex(/^[a-z0-9][a-z0-9./:_-]*:[a-z0-9_][a-z0-9_.-]*$/).refine((value) => !value.endsWith(":latest")),
25025
25032
  /** tar 内容的 SHA-256,用于部署前校验。 */
25026
25033
  sha256: external_exports.string().regex(/^[a-f0-9]{64}$/),
25034
+ /** 引擎实际构建的镜像 OS/架构;历史清单可以省略。 */
25035
+ platform: external_exports.string().regex(/^[a-z0-9][a-z0-9_.-]*\/[a-z0-9][a-z0-9_.-]*$/).optional(),
25027
25036
  /** 容器内部监听端口;服务器公开端口由部署选择。 */
25028
25037
  containerPort: external_exports.number().int().min(1).max(65535).optional()
25029
25038
  })).min(1).max(2).refine((images) => new Set(images.map((image) => image.name)).size === images.length)
@@ -26956,7 +26965,7 @@ function buildProxyArguments(proxy, runtime, network) {
26956
26965
  }
26957
26966
  return Object.entries(environment).flatMap(([key, value]) => ["--build-arg", `${key}=${value}`]);
26958
26967
  }
26959
- async function preflightDownloadProxy(runtime, proxy) {
26968
+ async function preflightDownloadProxy(runtime, proxy, report = writeCliMessage) {
26960
26969
  const environment = resolveDownloadProxy(proxy);
26961
26970
  for (const value of new Set([environment.HTTP_PROXY, environment.HTTPS_PROXY].filter(Boolean))) {
26962
26971
  const url2 = new URL(value);
@@ -26980,12 +26989,12 @@ async function preflightDownloadProxy(runtime, proxy) {
26980
26989
  for (const candidate of runtime === "auto" ? ["podman", "docker"] : [runtime]) {
26981
26990
  try {
26982
26991
  const data = JSON.parse(execFileSync(candidate, ["info", "--format", "{{json .}}"], { encoding: "utf8", windowsHide: true, timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }));
26983
- writeCliMessage(cliM(candidate === "docker" && (data.HTTPProxy || data.HTTPSProxy) ? "cli_download_engine_proxy_configured" : candidate === "podman" && !data.host?.serviceIsRemote ? "cli_download_engine_proxy_local" : "cli_download_engine_proxy_hint", { params: { runtime: candidate } }));
26992
+ report(cliM(candidate === "docker" && (data.HTTPProxy || data.HTTPSProxy) ? "cli_download_engine_proxy_configured" : candidate === "podman" && !data.host?.serviceIsRemote ? "cli_download_engine_proxy_local" : "cli_download_engine_proxy_hint", { params: { runtime: candidate } }));
26984
26993
  return;
26985
26994
  } catch {
26986
26995
  }
26987
26996
  }
26988
- writeCliMessage(cliM("cli_download_engine_proxy_hint", { params: { runtime } }));
26997
+ report(cliM("cli_download_engine_proxy_hint", { params: { runtime } }));
26989
26998
  }
26990
26999
  function validateDownloadDockerfile(file2, downloads) {
26991
27000
  const content = readFileSync(file2, "utf8");
@@ -27389,7 +27398,7 @@ async function forwardWindowsBuildOutput(source, destination) {
27389
27398
  }
27390
27399
 
27391
27400
  // src/commands/cli-build.ts
27392
- async function run(command, args, cwd, quiet = false, identity, compileEnvironment) {
27401
+ async function run(command, args, cwd, quiet = false, identity, compileEnvironment, progressOnStderr = false) {
27393
27402
  await new Promise((resolve16, reject) => {
27394
27403
  const env = Object.fromEntries(Object.entries(process14.env).filter(([key]) => !/^(?:HAI_|PUBLIC_|VITE_)/.test(key)));
27395
27404
  Object.assign(env, compileEnvironment);
@@ -27406,11 +27415,12 @@ async function run(command, args, cwd, quiet = false, identity, compileEnvironme
27406
27415
  if (env.CI === "1" || env.CI === "0")
27407
27416
  env.CI = env.CI === "1" ? "true" : "false";
27408
27417
  const windowsOutput = !quiet && process14.platform === "win32";
27409
- const child = spawn(command, args, { cwd, env, windowsHide: true, stdio: quiet ? "ignore" : windowsOutput ? ["inherit", "pipe", "pipe"] : "inherit", shell: false });
27418
+ const stdio = quiet ? "ignore" : windowsOutput ? ["inherit", "pipe", "pipe"] : progressOnStderr ? ["inherit", process14.stderr, "inherit"] : "inherit";
27419
+ const child = spawn(command, args, { cwd, env, windowsHide: true, stdio, shell: false });
27410
27420
  let output2 = Promise.resolve();
27411
27421
  if (windowsOutput && child.stdout && child.stderr) {
27412
27422
  output2 = Promise.all([
27413
- forwardWindowsBuildOutput(child.stdout, process14.stdout),
27423
+ forwardWindowsBuildOutput(child.stdout, progressOnStderr ? process14.stderr : process14.stdout),
27414
27424
  forwardWindowsBuildOutput(child.stderr, process14.stderr)
27415
27425
  ]).then(() => void 0);
27416
27426
  void output2.catch(() => child.kill());
@@ -27460,11 +27470,44 @@ function sourceCommit(cwd) {
27460
27470
  const options = { cwd, encoding: "utf8", stdio: "pipe", windowsHide: true };
27461
27471
  execFileSync("git", ["--literal-pathspecs", "ls-files", "--error-unmatch", "--", "package.json"], options);
27462
27472
  const commit = execFileSync("git", ["rev-parse", "HEAD"], options).trim();
27463
- return /^(?:[a-f\d]{40}|[a-f\d]{64})$/i.test(commit) ? commit : "unknown";
27473
+ return /^(?:[a-f\d]{40}|[a-f\d]{64})$/i.test(commit) ? commit.toLowerCase() : "unknown";
27464
27474
  } catch {
27465
27475
  return "unknown";
27466
27476
  }
27467
27477
  }
27478
+ function sourceDirty(cwd, commit) {
27479
+ if (commit === "unknown")
27480
+ return null;
27481
+ try {
27482
+ const status = execFileSync("git", ["--no-optional-locks", "-c", "core.fsmonitor=false", "status", "--porcelain=v2", "--branch", "--untracked-files=normal", "--", "."], {
27483
+ cwd,
27484
+ encoding: "utf8",
27485
+ stdio: "pipe",
27486
+ windowsHide: true,
27487
+ timeout: 15e3
27488
+ }).trim().split(/\r?\n/);
27489
+ if (status[0] !== `# branch.oid ${commit}`)
27490
+ return null;
27491
+ return status.some((line) => !line.startsWith("# "));
27492
+ } catch {
27493
+ return null;
27494
+ }
27495
+ }
27496
+ function imagePlatform(runtime, image, cwd) {
27497
+ try {
27498
+ const platform = execFileSync(runtime, ["image", "inspect", "--format", "{{.Os}}/{{.Architecture}}", image], {
27499
+ cwd,
27500
+ encoding: "utf8",
27501
+ stdio: "pipe",
27502
+ windowsHide: true,
27503
+ timeout: 15e3
27504
+ }).trim();
27505
+ if (/^[a-z0-9][a-z0-9_.-]*\/[a-z0-9][a-z0-9_.-]*$/.test(platform))
27506
+ return platform;
27507
+ } catch {
27508
+ }
27509
+ throw new Error(cliM("cli_build_image_platform_invalid"));
27510
+ }
27468
27511
  async function buildRuntime(cwd, choice) {
27469
27512
  const candidates = choice && choice !== "auto" ? [choice] : ["podman", "docker"];
27470
27513
  if (candidates.every((candidate) => candidate === "podman" || candidate === "docker")) {
@@ -27491,7 +27534,7 @@ async function buildCommand(options) {
27491
27534
  const containerAndroid = target === "app" && options.platform === "android" && options.runtime !== void 0;
27492
27535
  if (target === "app" && options.platform === "ios" && options.runtime !== void 0)
27493
27536
  throw new Error(cliM("cli_build_ios_runtime"));
27494
- if (target !== "image" && (options.images !== void 0 || options.concurrency !== void 0 || options.sqlitePrebuildMirror !== void 0) || target !== "image" && !containerAndroid && (options.runtime !== void 0 || options.network !== void 0 || options.httpProxy === false || options.imageSource !== void 0 || options.imageMirrors !== void 0 || options.npmSource !== void 0 || options.npmRegistry !== void 0 || options.proxyMode !== void 0 || options.proxyUrl !== void 0 || options.proxyBypass !== void 0) || !["desktop", "app"].includes(target) && (options.platform !== void 0 || options.debug !== void 0) || target !== "desktop" && options.arch !== void 0) {
27537
+ if (target !== "image" && (options.images !== void 0 || options.concurrency !== void 0 || options.sqlitePrebuildMirror !== void 0 || options.json) || target !== "image" && !containerAndroid && (options.runtime !== void 0 || options.network !== void 0 || options.httpProxy === false || options.imageSource !== void 0 || options.imageMirrors !== void 0 || options.npmSource !== void 0 || options.npmRegistry !== void 0 || options.proxyMode !== void 0 || options.proxyUrl !== void 0 || options.proxyBypass !== void 0) || !["desktop", "app"].includes(target) && (options.platform !== void 0 || options.debug !== void 0) || target !== "desktop" && options.arch !== void 0) {
27495
27538
  throw new Error(cliM("cli_build_options_invalid"));
27496
27539
  }
27497
27540
  if (target === "compile") {
@@ -27581,17 +27624,18 @@ async function buildCommand(options) {
27581
27624
  if (!existsSync(resolve(cwd, image.dockerfile)))
27582
27625
  throw new Error(cliM("cli_build_dockerfile_missing", { params: { path: image.dockerfile } }));
27583
27626
  }
27584
- const downloads = await resolveBuildDownloads(cwd, options);
27627
+ const { buildId, commit } = identity;
27628
+ const artifact = { version: 4, primaryService: config2.images.some((image) => image.name === "serv") ? "serv" : "web", appVersion, buildId, source: { commit, dirty: sourceDirty(cwd, commit) }, partial: images.length !== config2.images.length, hasWeb: config2.images.some((image) => image.name === "web"), images: [] };
27629
+ const downloads = await resolveBuildDownloads(cwd, options.json ? { ...options, yes: true } : options);
27585
27630
  for (const image of images) validateDownloadDockerfile(resolve(cwd, image.dockerfile), downloads);
27586
27631
  const runtime = await buildRuntime(cwd, options.runtime);
27587
- await preflightDownloadProxy(runtime, downloads.proxy);
27632
+ await preflightDownloadProxy(runtime, downloads.proxy, options.json ? (message) => process14.stderr.write(`${message}
27633
+ `) : void 0);
27588
27634
  if (options.sqlitePrebuildMirror) {
27589
27635
  const url2 = new URL(options.sqlitePrebuildMirror);
27590
27636
  if (!["http:", "https:"].includes(url2.protocol) || url2.username || url2.password || url2.search || url2.hash)
27591
27637
  throw new Error(cliM("cli_build_mirror_invalid"));
27592
27638
  }
27593
- const { buildId, commit } = identity;
27594
- const artifact = { version: 4, primaryService: config2.images.some((image) => image.name === "serv") ? "serv" : "web", appVersion, buildId, partial: images.length !== config2.images.length, hasWeb: config2.images.some((image) => image.name === "web"), images: [] };
27595
27639
  if (webBasePath) {
27596
27640
  artifact.version = 5;
27597
27641
  artifact.webBasePath = webBasePath;
@@ -27604,6 +27648,7 @@ async function buildCommand(options) {
27604
27648
  mkdirSync(parent, { recursive: true });
27605
27649
  const staging = mkdtempSync(join(parent, ".building-"));
27606
27650
  const built = [];
27651
+ const runImage = (args) => run(runtime, args, cwd, false, void 0, void 0, options.json);
27607
27652
  try {
27608
27653
  for (const context of new Set(images.map((image) => resolve(cwd, image.context ?? "."))))
27609
27654
  prepareDependencyInputs(context);
@@ -27643,13 +27688,14 @@ async function buildCommand(options) {
27643
27688
  if (image.name === "web" && compileEnvironment.PUBLIC_BASE_PATH)
27644
27689
  args.push("--build-arg", `PUBLIC_BASE_PATH=${compileEnvironment.PUBLIC_BASE_PATH}`);
27645
27690
  built.push(imageRef);
27646
- await run(runtime, [...args, context], cwd);
27691
+ await runImage([...args, context]);
27692
+ const platform = imagePlatform(runtime, imageRef, cwd);
27647
27693
  const file2 = `${image.name}-${appVersion}.tar`;
27648
- await run(runtime, ["save", ...runtime === "podman" ? ["--format", "docker-archive"] : [], "-o", join(staging, file2), imageRef], cwd);
27694
+ await runImage(["save", ...runtime === "podman" ? ["--format", "docker-archive"] : [], "-o", join(staging, file2), imageRef]);
27649
27695
  const hash2 = createHash("sha256");
27650
27696
  for await (const chunk of createReadStream(join(staging, file2)))
27651
27697
  hash2.update(chunk);
27652
- return { name: image.name, file: file2, imageRef, sha256: hash2.digest("hex"), ...image.containerPort ? { containerPort: image.containerPort } : {} };
27698
+ return { name: image.name, file: file2, imageRef, sha256: hash2.digest("hex"), platform, ...image.containerPort ? { containerPort: image.containerPort } : {} };
27653
27699
  };
27654
27700
  for (let offset = 0; offset < images.length; offset += concurrency) {
27655
27701
  const results = await Promise.allSettled(images.slice(offset, offset + concurrency).map(buildImage));
@@ -27667,7 +27713,12 @@ async function buildCommand(options) {
27667
27713
  writeFileSync(join(parent, `latest-${buildId}`), `${batch}
27668
27714
  `);
27669
27715
  renameSync(join(parent, `latest-${buildId}`), join(parent, "latest"));
27670
- writeCliMessage(cliM("cli_build_ready", { params: { path: output2, runtime } }));
27716
+ if (options.json) {
27717
+ process14.stdout.write(`${JSON.stringify({ schemaVersion: 1, artifactDir: output2, manifestPath: join(output2, "manifest.json"), manifest: artifact })}
27718
+ `);
27719
+ } else {
27720
+ writeCliMessage(cliM("cli_build_ready", { params: { path: output2, runtime } }));
27721
+ }
27671
27722
  } catch (error62) {
27672
27723
  for (const imageRef of built) {
27673
27724
  try {
@@ -29860,7 +29911,7 @@ async function initProject(options) {
29860
29911
  const { project, existing, missing } = result;
29861
29912
  spinner.succeed(cliM("cli_initDetected", { params: { name: chalk.cyan(project.name) } }));
29862
29913
  if (project.isHaiProject) {
29863
- const { generateProjectAiSupport, resolveSkillNamesForPackages } = await import('./cli-skill-templates-M64VPXZ4.js');
29914
+ const { generateProjectAiSupport, resolveSkillNamesForPackages } = await import('./cli-skill-templates-W4I6ZKYW.js');
29864
29915
  const generatedFiles = await generateProjectAiSupport(cwd, resolveSkillNamesForPackages(project.haiPackages), {
29865
29916
  overwriteSkills: false,
29866
29917
  overwriteBridgeFiles: false
@@ -30167,11 +30218,15 @@ cli.command("generate [type] [name]", cliM("cli_help_generate")).option("-w, --w
30167
30218
  process14.exit(1);
30168
30219
  }
30169
30220
  });
30170
- cli.command("build", cliM("cli_help_build")).option("--target <target>", cliM("cli_help_target")).option("--images <names>", cliM("cli_help_images")).option("--concurrency <count>", cliM("cli_help_buildConcurrency")).option("--runtime <runtime>", cliM("cli_help_buildRuntime")).option("--network <network>", cliM("cli_help_buildNetwork")).option("--platform <platform>", cliM("cli_help_platform")).option("--arch <arch>", cliM("cli_help_arch")).option("--debug", cliM("cli_help_buildDebug")).option("--sqlite-prebuild-mirror <url>", cliM("cli_help_sqliteMirror")).option("--no-http-proxy", cliM("cli_help_noHttpProxy")).option("-y, --yes", cliM("cli_help_deployYes")).option("--image-source <source>", cliM("cli_help_imageSource")).option("--image-mirrors <mappings>", cliM("cli_help_imageMirrors")).option("--npm-source <source>", cliM("cli_help_npmSource")).option("--npm-registry <url>", cliM("cli_help_npmRegistry")).option("--proxy-mode <mode>", cliM("cli_help_proxyMode")).option("--proxy-url <url>", cliM("cli_help_proxyUrl")).option("--proxy-bypass <hosts>", cliM("cli_help_proxyBypass")).action(async (options) => {
30221
+ cli.command("build", cliM("cli_help_build")).option("--target <target>", cliM("cli_help_target")).option("--json", cliM("cli_help_buildJson")).option("--images <names>", cliM("cli_help_images")).option("--concurrency <count>", cliM("cli_help_buildConcurrency")).option("--runtime <runtime>", cliM("cli_help_buildRuntime")).option("--network <network>", cliM("cli_help_buildNetwork")).option("--platform <platform>", cliM("cli_help_platform")).option("--arch <arch>", cliM("cli_help_arch")).option("--debug", cliM("cli_help_buildDebug")).option("--sqlite-prebuild-mirror <url>", cliM("cli_help_sqliteMirror")).option("--no-http-proxy", cliM("cli_help_noHttpProxy")).option("-y, --yes", cliM("cli_help_deployYes")).option("--image-source <source>", cliM("cli_help_imageSource")).option("--image-mirrors <mappings>", cliM("cli_help_imageMirrors")).option("--npm-source <source>", cliM("cli_help_npmSource")).option("--npm-registry <url>", cliM("cli_help_npmRegistry")).option("--proxy-mode <mode>", cliM("cli_help_proxyMode")).option("--proxy-url <url>", cliM("cli_help_proxyUrl")).option("--proxy-bypass <hosts>", cliM("cli_help_proxyBypass")).action(async (options) => {
30171
30222
  try {
30172
30223
  await buildCommand(options);
30173
30224
  } catch (error62) {
30174
- writeCliMessage(error62 instanceof Error ? error62.message : String(error62));
30225
+ const message = error62 instanceof Error ? error62.message : String(error62);
30226
+ if (options.json)
30227
+ writeCliError(message);
30228
+ else
30229
+ writeCliMessage(message);
30175
30230
  process14.exitCode = 1;
30176
30231
  }
30177
30232
  });