@coze-arch/rush-publish-plugin 0.0.5-alpha.a5f14f → 0.0.5-alpha.bba657

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.
@@ -1,2 +1,2 @@
1
- import { type ReleaseOptions, type ReleaseManifest } from './types';
1
+ import { type ReleaseManifest, type ReleaseOptions } from './types';
2
2
  export declare const releasePackages: (releaseManifests: ReleaseManifest[], releaseOptions: ReleaseOptions) => Promise<void>;
@@ -2,7 +2,7 @@ import { type RushConfigurationProject } from '@rushstack/rush-sdk';
2
2
  export interface ReleaseOptions {
3
3
  commit?: string;
4
4
  dryRun?: boolean;
5
- registry: string;
5
+ registry?: string;
6
6
  packages?: PackageToPublish[];
7
7
  allowBranches?: string[];
8
8
  }
@@ -1,7 +1,3 @@
1
- /**
2
- * 默认的 NPM registry 地址
3
- */
4
- export declare const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
5
1
  /**
6
2
  * 默认的 Git 分支名前缀
7
3
  */
package/lib/index.js CHANGED
@@ -148,11 +148,6 @@ const logger = {
148
148
  // Copyright (c) 2025 coze-dev
149
149
  // SPDX-License-Identifier: MIT
150
150
 
151
- /**
152
- * 默认的 NPM registry 地址
153
- */
154
- const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
155
-
156
151
  /**
157
152
  * 默认的 Git 分支名前缀
158
153
  */
@@ -360,6 +355,62 @@ const buildMergeRequestUrl = (
360
355
  return null;
361
356
  };
362
357
 
358
+ function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
359
+
360
+ /**
361
+ * package.json 的类型定义
362
+ */
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+ /**
372
+ * 解析发布 registry 的优先级:
373
+ * 1. 命令行参数 --registry (最高优先级)
374
+ * 2. package.json 中的 publishConfig.registry
375
+ * 3. 使用 npm 配置的默认 registry (不传 --registry 参数)
376
+ *
377
+ * @param project - Rush 项目配置
378
+ * @param registryFromCli - 命令行参数传入的 registry
379
+ * @returns 解析后的 registry URL,如果为 undefined 则使用 npm 默认配置
380
+ */
381
+ function resolveRegistry(
382
+ project,
383
+ registryFromCli,
384
+ ) {
385
+ // 1. 优先使用命令行参数
386
+ if (registryFromCli) {
387
+ logger.info(
388
+ `Using registry from CLI: ${registryFromCli} (${project.packageName})`,
389
+ false,
390
+ );
391
+ return registryFromCli;
392
+ }
393
+
394
+ // 2. 尝试读取 package.json 中的 publishConfig.registry
395
+ const packageJson = project.packageJson ;
396
+ const registryFromPackageJson = _optionalChain$3([packageJson, 'access', _ => _.publishConfig, 'optionalAccess', _2 => _2.registry]);
397
+
398
+ if (registryFromPackageJson) {
399
+ logger.info(
400
+ `Using registry from publishConfig: ${registryFromPackageJson} (${project.packageName})`,
401
+ false,
402
+ );
403
+ return registryFromPackageJson;
404
+ }
405
+
406
+ // 3. 返回 undefined,让 npm 使用自己配置的 registry
407
+ logger.info(
408
+ `Using npm configured registry (${project.packageName})`,
409
+ false,
410
+ );
411
+ return undefined;
412
+ }
413
+
363
414
  // Copyright (c) 2025 coze-dev
364
415
  // SPDX-License-Identifier: MIT
365
416
 
@@ -472,7 +523,7 @@ const publishPackage = async (
472
523
  project,
473
524
  releaseOptions,
474
525
  ) => {
475
- const { dryRun, registry } = releaseOptions;
526
+ const { dryRun } = releaseOptions;
476
527
  const token = process.env.NPM_AUTH_TOKEN;
477
528
  const { version } = project.packageJson;
478
529
  const tag = version.includes('alpha')
@@ -480,6 +531,10 @@ const publishPackage = async (
480
531
  : version.includes('beta')
481
532
  ? 'beta'
482
533
  : 'latest';
534
+
535
+ // 解析 registry:CLI 参数 > package.json publishConfig > npm 配置
536
+ const registry = resolveRegistry(project, releaseOptions.registry);
537
+
483
538
  const setToken = `npm config set //bnpm.byted.org/:_authToken ${token}`;
484
539
  await exec(setToken, {
485
540
  cwd: project.projectFolder,
@@ -489,6 +544,7 @@ const publishPackage = async (
489
544
  if (dryRun) {
490
545
  args.push('--dry-run');
491
546
  }
547
+ // 只有明确指定了 registry 才传递参数,否则使用 npm 配置的默认值
492
548
  if (registry) {
493
549
  args.push(`--registry=${registry}`);
494
550
  }
@@ -708,8 +764,7 @@ const installAction$2 = (program) => {
708
764
  .option('--dry-run', '是否只执行不真实发布', false)
709
765
  .option(
710
766
  '-r, --registry <string>',
711
- `发布到的 registry (默认: ${DEFAULT_NPM_REGISTRY})`,
712
- DEFAULT_NPM_REGISTRY,
767
+ '发布到的 registry (优先级: CLI参数 > package.json publishConfig.registry > npm config)',
713
768
  )
714
769
  .option(
715
770
  '--allow-branches <branches...>',
@@ -1382,7 +1437,7 @@ const confirmForPublish = async (
1382
1437
  if (_optionalChain$1([options, 'optionalAccess', _ => _.isReleaseMode])) {
1383
1438
  logger.info('', false);
1384
1439
  logger.warn(chalk.yellow.bold('⚠️ Release Mode Enabled:'), false);
1385
- const registryMsg = ` Packages will be published directly to: ${chalk.bold(options.registry || 'default registry')}`;
1440
+ const registryMsg = ` Packages will be published directly to: ${chalk.bold(options.registry || 'npm configured registry')}`;
1386
1441
  logger.warn(chalk.yellow(registryMsg), false);
1387
1442
  }
1388
1443
 
@@ -1804,7 +1859,7 @@ const publish = async (options) => {
1804
1859
  !!options.dryRun,
1805
1860
  {
1806
1861
  isReleaseMode: !!options.release,
1807
- registry: options.registry || DEFAULT_NPM_REGISTRY,
1862
+ registry: options.registry,
1808
1863
  },
1809
1864
  );
1810
1865
 
@@ -1840,13 +1895,16 @@ const publish = async (options) => {
1840
1895
  // Release 模式:直接发布
1841
1896
  logger.info('Running in direct release mode...');
1842
1897
  logger.info('Starting package release...');
1843
- const registry = options.registry || DEFAULT_NPM_REGISTRY;
1844
1898
  // 将 PublishManifest[] 转换为 PackageToPublish[]
1845
1899
  const packages = publishManifests.map(manifest => ({
1846
1900
  packageName: manifest.project.packageName,
1847
1901
  version: manifest.newVersion,
1848
1902
  }));
1849
- await release({ dryRun: !!options.dryRun, registry, packages });
1903
+ await release({
1904
+ dryRun: !!options.dryRun,
1905
+ registry: options.registry,
1906
+ packages,
1907
+ });
1850
1908
  } else {
1851
1909
  // 普通模式:创建并推送发布分支
1852
1910
  await pushToRemote({
@@ -1903,8 +1961,7 @@ const installAction$1 = (program) => {
1903
1961
  )
1904
1962
  .option(
1905
1963
  '--registry <url>',
1906
- `NPM registry URL (default: ${DEFAULT_NPM_REGISTRY})`,
1907
- DEFAULT_NPM_REGISTRY,
1964
+ 'NPM registry URL (优先级: CLI参数 > package.json publishConfig.registry > npm config)',
1908
1965
  )
1909
1966
  .action(async (options) => {
1910
1967
  try {
@@ -0,0 +1,12 @@
1
+ import { type RushConfigurationProject } from '@rushstack/rush-sdk';
2
+ /**
3
+ * 解析发布 registry 的优先级:
4
+ * 1. 命令行参数 --registry (最高优先级)
5
+ * 2. package.json 中的 publishConfig.registry
6
+ * 3. 使用 npm 配置的默认 registry (不传 --registry 参数)
7
+ *
8
+ * @param project - Rush 项目配置
9
+ * @param registryFromCli - 命令行参数传入的 registry
10
+ * @returns 解析后的 registry URL,如果为 undefined 则使用 npm 默认配置
11
+ */
12
+ export declare function resolveRegistry(project: RushConfigurationProject, registryFromCli?: string): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/rush-publish-plugin",
3
- "version": "0.0.5-alpha.a5f14f",
3
+ "version": "0.0.5-alpha.bba657",
4
4
  "description": "rush plugin to generate change log and publish packages",
5
5
  "keywords": [
6
6
  "rush",