@coze-arch/rush-publish-plugin 0.0.5-alpha.0f1107 → 0.0.5-alpha.e7fa7b

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.
package/command-line.json CHANGED
@@ -106,6 +106,22 @@
106
106
  "associatedCommands": ["pub"],
107
107
  "required": false
108
108
  },
109
+ {
110
+ "parameterKind": "string",
111
+ "longName": "--branch-prefix",
112
+ "description": "Git branch name prefix (default: 'release')",
113
+ "argumentName": "BRANCH_PREFIX",
114
+ "associatedCommands": ["pub"],
115
+ "required": false
116
+ },
117
+ {
118
+ "parameterKind": "flag",
119
+ "longName": "--release",
120
+ "shortName": "-l",
121
+ "description": "Directly publish packages (only for alpha/beta versions)",
122
+ "associatedCommands": ["pub"],
123
+ "required": false
124
+ },
109
125
  {
110
126
  "parameterKind": "flag",
111
127
  "longName": "--amend-commit",
@@ -141,8 +157,8 @@
141
157
  "argumentName": "REGISTRY",
142
158
  "longName": "--registry",
143
159
  "shortName": "-r",
144
- "description": "Registry",
145
- "associatedCommands": ["release"]
160
+ "description": "NPM registry URL (default: https://registry.npmjs.org)",
161
+ "associatedCommands": ["release", "pub"]
146
162
  }
147
163
  ]
148
164
  }
@@ -1,2 +1,6 @@
1
1
  import { type PublishManifest } from './types';
2
- export declare const confirmForPublish: (publishManifest: PublishManifest[], dryRun: boolean) => Promise<boolean>;
2
+ export interface ConfirmForPublishOptions {
3
+ isReleaseMode?: boolean;
4
+ registry?: string;
5
+ }
6
+ export declare const confirmForPublish: (publishManifest: PublishManifest[], dryRun: boolean, options?: ConfirmForPublishOptions) => Promise<boolean>;
@@ -1,14 +1,10 @@
1
- import { type PublishManifest } from './types';
2
1
  export declare function createAndPushBranch(branchName: string, cwd: string): Promise<void>;
3
2
  interface CommitChangesOptions {
4
- sessionId: string;
5
3
  files: string[];
6
4
  cwd: string;
7
- publishManifests: PublishManifest[];
8
5
  branchName: string;
9
- createTags: boolean;
10
6
  }
11
- export declare function commitChanges({ sessionId, files, cwd, publishManifests, branchName, createTags, }: CommitChangesOptions): Promise<{
7
+ export declare function commitChanges({ files, cwd, branchName, }: CommitChangesOptions): Promise<{
12
8
  effects: string[];
13
9
  branchName: string;
14
10
  }>;
@@ -8,6 +8,7 @@ interface PushToRemoteOptions {
8
8
  skipCommit: boolean;
9
9
  skipPush: boolean;
10
10
  repoUrl: string;
11
+ branchPrefix?: string;
11
12
  }
12
13
  export declare const pushToRemote: (options: PushToRemoteOptions) => Promise<void>;
13
14
  export {};
@@ -16,6 +16,9 @@ export interface PublishOptions {
16
16
  skipCommit?: boolean;
17
17
  skipPush?: boolean;
18
18
  repoUrl: string;
19
+ branchPrefix?: string;
20
+ release?: boolean;
21
+ registry?: string;
19
22
  }
20
23
  export interface PublishManifest {
21
24
  project: RushConfigurationProject;
@@ -1,8 +1,9 @@
1
1
  import { type RushConfigurationProject } from '@rushstack/rush-sdk';
2
2
  export interface ReleaseOptions {
3
- commit: string;
3
+ commit?: string;
4
4
  dryRun?: boolean;
5
5
  registry: string;
6
+ packages?: PackageToPublish[];
6
7
  }
7
8
  export interface PackageToPublish {
8
9
  packageName: string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 默认的 NPM registry 地址
3
+ */
4
+ export declare const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
5
+ /**
6
+ * 默认的 Git 分支名前缀
7
+ */
8
+ export declare const DEFAULT_BRANCH_PREFIX = "bump";
package/lib/index.js CHANGED
@@ -148,6 +148,19 @@ 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
+ /**
157
+ * 默认的 Git 分支名前缀
158
+ */
159
+ const DEFAULT_BRANCH_PREFIX = 'bump';
160
+
161
+ // Copyright (c) 2025 coze-dev
162
+ // SPDX-License-Identifier: MIT
163
+
151
164
 
152
165
 
153
166
 
@@ -214,6 +227,15 @@ const getCurrentBranchName = async () => {
214
227
  return stdout.trim();
215
228
  };
216
229
 
230
+ /**
231
+ * 获取当前 commit hash
232
+ * @returns commit hash
233
+ */
234
+ const getCurrentCommitHash = async () => {
235
+ const { stdout } = await exec('git rev-parse HEAD');
236
+ return stdout.trim();
237
+ };
238
+
217
239
  const isMainBranch = async () => {
218
240
  const currentBranchName = await getCurrentBranchName();
219
241
  return currentBranchName === 'main';
@@ -369,7 +391,12 @@ const publishPackage = async (
369
391
  : version.includes('beta')
370
392
  ? 'beta'
371
393
  : 'latest';
372
- const args = [`NPM_AUTH_TOKEN=${token}`, 'npm', 'publish', `--tag ${tag}`];
394
+ const setToken = `npm config set //bnpm.byted.org/:_authToken ${token}`;
395
+ await exec(setToken, {
396
+ cwd: project.projectFolder,
397
+ });
398
+
399
+ const args = [`NODE_AUTH_TOKEN=${token}`, 'npm', 'publish', `--tag ${tag}`];
373
400
  if (dryRun) {
374
401
  args.push('--dry-run');
375
402
  }
@@ -519,10 +546,27 @@ const getPackagesToPublish = async (
519
546
 
520
547
 
521
548
  async function release(options) {
522
- const { commit, dryRun = false, registry } = options;
549
+ const { dryRun = false, registry, packages } = options;
550
+ let { commit } = options;
551
+ const hasPassedCommit = !!options.commit;
523
552
 
524
553
  // 1. 获取需要发布的包列表
525
- const packagesToPublish = await getPackagesToPublish(commit);
554
+ let packagesToPublish;
555
+ if (packages) {
556
+ // 直接使用传入的包列表
557
+ packagesToPublish = packages;
558
+ logger.info('Using provided package list');
559
+ } else {
560
+ // 从 git tags 获取包列表
561
+ if (!hasPassedCommit) {
562
+ commit = await getCurrentCommitHash();
563
+ logger.info('Using current commit');
564
+ }
565
+ // 此时 commit 必定有值(要么传入了,要么刚获取了)
566
+ const commitHash = commit ;
567
+ packagesToPublish = await getPackagesToPublish(commitHash);
568
+ }
569
+
526
570
  if (packagesToPublish.length === 0) {
527
571
  logger.warn('No packages to publish');
528
572
  return;
@@ -539,7 +583,15 @@ async function release(options) {
539
583
  );
540
584
  const branchName = await getCurrentBranchName();
541
585
  checkReleasePlan(releaseManifests, branchName);
542
- await exec(`git checkout ${commit}`);
586
+
587
+ // 只有在指定了 commit 且与当前 HEAD 不同时才切换
588
+ if (hasPassedCommit) {
589
+ const currentHead = await getCurrentCommitHash();
590
+ if (currentHead !== commit) {
591
+ logger.info(`Checking out commit: ${commit}`);
592
+ await exec(`git checkout ${commit}`);
593
+ }
594
+ }
543
595
 
544
596
  await releasePackages(releaseManifests, { dryRun, registry });
545
597
  logger.success('All packages published successfully!');
@@ -555,18 +607,15 @@ const installAction$2 = (program) => {
555
607
  program
556
608
  .command('release')
557
609
  .description('Release packages based on git tags.')
558
- .requiredOption('--commit <string>', '需要执行发布的 commit id')
610
+ .option('--commit <string>', '需要执行发布的 commit id (默认使用当前 HEAD)')
559
611
  .option('--dry-run', '是否只执行不真实发布', false)
560
612
  .option(
561
613
  '-r, --registry <string>',
562
- '发布到的 registry',
563
- 'https://registry.npmjs.org',
614
+ `发布到的 registry (默认: ${DEFAULT_NPM_REGISTRY})`,
615
+ DEFAULT_NPM_REGISTRY,
564
616
  )
565
617
  .action(async (options) => {
566
618
  try {
567
- if (!options.commit) {
568
- throw new Error('请提供需要发布的 commit id');
569
- }
570
619
  if (!process.env.NPM_AUTH_TOKEN) {
571
620
  throw new Error('请设置 NPM_AUTH_TOKEN 环境变量');
572
621
  }
@@ -805,31 +854,15 @@ const generatePublishManifest = async (
805
854
 
806
855
 
807
856
 
808
-
809
-
810
-
811
857
  async function commitChanges({
812
- sessionId,
813
858
  files,
814
859
  cwd,
815
- publishManifests,
816
860
  branchName,
817
- createTags,
818
861
  }) {
819
862
  await exec(`git add ${files.join(' ')}`, { cwd });
820
863
  await exec(`git commit -m "chore: Publish ${branchName}" -n`, { cwd });
821
864
 
822
- let tags = [];
823
- if (createTags) {
824
- tags = publishManifests.map(
825
- m => `v/${m.project.packageName}@${m.newVersion}`,
826
- );
827
- await exec(
828
- tags.map(tag => `git tag -a ${tag} -m "Bump type ${tag}"`).join(' && '),
829
- { cwd },
830
- );
831
- }
832
- return { effects: [...tags, branchName], branchName };
865
+ return { effects: [branchName], branchName };
833
866
  }
834
867
 
835
868
 
@@ -859,16 +892,17 @@ async function push({ refs, cwd, repoUrl }) {
859
892
 
860
893
 
861
894
 
895
+
862
896
  const pushToRemote = async (options) => {
863
897
  const {
864
898
  sessionId,
865
899
  changedFiles,
866
900
  cwd,
867
- publishManifests,
868
901
  bumpPolicy,
869
902
  skipCommit,
870
903
  skipPush,
871
904
  repoUrl,
905
+ branchPrefix = 'release',
872
906
  } = options;
873
907
  if (skipCommit) {
874
908
  return;
@@ -882,7 +916,7 @@ const pushToRemote = async (options) => {
882
916
  branchName = await getCurrentBranchName();
883
917
  } else {
884
918
  const date = dayjs().format('YYYYMMDD');
885
- branchName = `release/${date}-${sessionId}`;
919
+ branchName = `${branchPrefix}/${date}-${sessionId}`;
886
920
  await exec(`git checkout -b ${branchName}`, { cwd });
887
921
  }
888
922
  const isTestPublish = [BumpType.ALPHA, BumpType.BETA].includes(
@@ -891,13 +925,9 @@ const pushToRemote = async (options) => {
891
925
 
892
926
  // 4. 创建并推送发布分支
893
927
  const { effects } = await commitChanges({
894
- sessionId,
895
928
  files: changedFiles,
896
929
  cwd,
897
- publishManifests,
898
930
  branchName,
899
- // 只有 alpha、beta 需要创建 tag,正式发布会在 .github/workflows/common-pr-checks.yml 创建并发布tag
900
- createTags: isTestPublish,
901
931
  });
902
932
  if (skipPush) {
903
933
  return;
@@ -1034,7 +1064,7 @@ const lookupOnly = (packageName) => {
1034
1064
  return projects[0];
1035
1065
  };
1036
1066
 
1037
- function _optionalChain$1(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; }
1067
+ function _optionalChain$2(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; }
1038
1068
 
1039
1069
 
1040
1070
 
@@ -1088,7 +1118,7 @@ const retrievePackages = (
1088
1118
 
1089
1119
  const validateAndGetPackages = (options) => {
1090
1120
  const retrievePatterns = Object.values(RetrievePattern);
1091
- if (retrievePatterns.every(pattern => (_optionalChain$1([options, 'access', _ => _[pattern], 'optionalAccess', _2 => _2.length]) || 0) <= 0)) {
1121
+ if (retrievePatterns.every(pattern => (_optionalChain$2([options, 'access', _ => _[pattern], 'optionalAccess', _2 => _2.length]) || 0) <= 0)) {
1092
1122
  throw new Error('No packages to publish');
1093
1123
  }
1094
1124
  const res = retrievePatterns.reduce((acc, pattern) => {
@@ -1114,8 +1144,11 @@ const validateAndGetPackages = (options) => {
1114
1144
  return result;
1115
1145
  };
1116
1146
 
1117
- // Copyright (c) 2025 coze-dev
1118
- // SPDX-License-Identifier: MIT
1147
+ function _optionalChain$1(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; }// Copyright (c) 2025 coze-dev
1148
+
1149
+
1150
+
1151
+
1119
1152
 
1120
1153
 
1121
1154
 
@@ -1123,20 +1156,33 @@ const validateAndGetPackages = (options) => {
1123
1156
  const confirmForPublish = async (
1124
1157
  publishManifest,
1125
1158
  dryRun,
1159
+ options,
1126
1160
  ) => {
1127
- console.log(chalk.gray('Will publish the following packages:'));
1161
+ logger.info(chalk.gray('Will publish the following packages:'), false);
1128
1162
  publishManifest.forEach(manifest => {
1129
- const msg = `${manifest.project.packageName}: ${chalk.bgGreen(`${manifest.currentVersion} -> ${chalk.bold(manifest.newVersion)}`)}`;
1130
- console.log(`- ${msg}`);
1163
+ const versionChange = `${manifest.currentVersion} -> ${chalk.bold(manifest.newVersion)}`;
1164
+ const msg = `${manifest.project.packageName}: ${chalk.bgGreen(versionChange)}`;
1165
+ logger.info(`- ${msg}`, false);
1131
1166
  });
1167
+
1168
+ // Release 模式的额外提示
1169
+ if (_optionalChain$1([options, 'optionalAccess', _ => _.isReleaseMode])) {
1170
+ logger.info('', false);
1171
+ logger.warn(chalk.yellow.bold('⚠️ Release Mode Enabled:'), false);
1172
+ const registryMsg = ` Packages will be published directly to: ${chalk.bold(options.registry || 'default registry')}`;
1173
+ logger.warn(chalk.yellow(registryMsg), false);
1174
+ }
1175
+
1132
1176
  if (dryRun) {
1133
1177
  return false;
1134
1178
  }
1135
1179
 
1136
- console.log('\n');
1180
+ logger.info('', false);
1137
1181
  try {
1138
1182
  const result = await prompts.confirm({
1139
- message: 'Are you sure to publish?',
1183
+ message: _optionalChain$1([options, 'optionalAccess', _2 => _2.isReleaseMode])
1184
+ ? 'Are you sure to publish directly?'
1185
+ : 'Are you sure to publish?',
1140
1186
  default: true,
1141
1187
  });
1142
1188
  return result;
@@ -1500,7 +1546,10 @@ const publish = async (options) => {
1500
1546
  const sessionId = randomHash(6);
1501
1547
  const rushConfiguration = getRushConfiguration$1();
1502
1548
  const rushFolder = rushConfiguration.rushJsonFolder;
1503
- if (process.env.SKIP_UNCOMMITTED_CHECK !== 'true') {
1549
+ if (
1550
+ process.env.SKIP_UNCOMMITTED_CHECK !== 'true' &&
1551
+ options.release !== true
1552
+ ) {
1504
1553
  await ensureNotUncommittedChanges();
1505
1554
  }
1506
1555
 
@@ -1536,6 +1585,10 @@ const publish = async (options) => {
1536
1585
  const continuePublish = await confirmForPublish(
1537
1586
  publishManifests,
1538
1587
  !!options.dryRun,
1588
+ {
1589
+ isReleaseMode: !!options.release,
1590
+ registry: options.registry || DEFAULT_NPM_REGISTRY,
1591
+ },
1539
1592
  );
1540
1593
 
1541
1594
  if (!continuePublish) {
@@ -1551,17 +1604,46 @@ const publish = async (options) => {
1551
1604
  await Promise.all(postHandles.map(handle => handle(publishManifests)))
1552
1605
  ).flat();
1553
1606
 
1554
- // 4. 创建并推送发布分支
1555
- await pushToRemote({
1556
- publishManifests,
1557
- bumpPolicy: bumpPolicy ,
1558
- sessionId,
1559
- changedFiles,
1560
- cwd: rushFolder,
1561
- skipCommit: !!options.skipCommit,
1562
- skipPush: !!options.skipPush,
1563
- repoUrl: options.repoUrl,
1564
- });
1607
+ // 4. 创建并推送发布分支 或 直接发布
1608
+ let shouldRelease = false;
1609
+ if (options.release) {
1610
+ // 验证 release 模式的前置条件
1611
+ if (isBetaPublish === false) {
1612
+ logger.error(
1613
+ 'Direct release (--release) is only allowed for alpha or beta versions.',
1614
+ );
1615
+ logger.error(`Current bump type is: ${bumpPolicy}`);
1616
+ logger.warn('Falling back to normal publish mode...');
1617
+ } else {
1618
+ shouldRelease = true;
1619
+ }
1620
+ }
1621
+
1622
+ if (shouldRelease) {
1623
+ // Release 模式:直接发布
1624
+ logger.info('Running in direct release mode...');
1625
+ logger.info('Starting package release...');
1626
+ const registry = options.registry || DEFAULT_NPM_REGISTRY;
1627
+ // 将 PublishManifest[] 转换为 PackageToPublish[]
1628
+ const packages = publishManifests.map(manifest => ({
1629
+ packageName: manifest.project.packageName,
1630
+ version: manifest.newVersion,
1631
+ }));
1632
+ await release({ dryRun: !!options.dryRun, registry, packages });
1633
+ } else {
1634
+ // 普通模式:创建并推送发布分支
1635
+ await pushToRemote({
1636
+ bumpPolicy: bumpPolicy ,
1637
+ sessionId,
1638
+ changedFiles,
1639
+ cwd: rushFolder,
1640
+ skipCommit: !!options.skipCommit,
1641
+ skipPush: !!options.skipPush,
1642
+ repoUrl: options.repoUrl,
1643
+ branchPrefix: options.branchPrefix,
1644
+ });
1645
+ }
1646
+
1565
1647
  logger.success('Publish success.');
1566
1648
  };
1567
1649
 
@@ -1592,6 +1674,21 @@ const installAction$1 = (program) => {
1592
1674
  'Git repository URL (e.g. git@github.com:coze-dev/coze-js.git)',
1593
1675
  undefined,
1594
1676
  )
1677
+ .option(
1678
+ '--branch-prefix <prefix>',
1679
+ `Git branch name prefix (default: ${DEFAULT_BRANCH_PREFIX})`,
1680
+ DEFAULT_BRANCH_PREFIX,
1681
+ )
1682
+ .option(
1683
+ '-l, --release',
1684
+ 'Directly publish packages (only for alpha/beta versions)',
1685
+ false,
1686
+ )
1687
+ .option(
1688
+ '--registry <url>',
1689
+ `NPM registry URL (default: ${DEFAULT_NPM_REGISTRY})`,
1690
+ DEFAULT_NPM_REGISTRY,
1691
+ )
1595
1692
  .action(async (options) => {
1596
1693
  try {
1597
1694
  const repoUrl = options.repoUrl || (await getCurrentOrigin());
@@ -1599,8 +1696,9 @@ const installAction$1 = (program) => {
1599
1696
  throw new Error('Git repository URL is required');
1600
1697
  }
1601
1698
  if (!GIT_REPO_URL_REGEX.test(repoUrl)) {
1699
+ const expectedFormat = 'git@github.com:${org}/${repo}.git';
1602
1700
  throw new Error(
1603
- `Invalid git repository URL: ${repoUrl}, it should be follow the format: git@github.com:\${org}/\${repo}.git`,
1701
+ `Invalid git repository URL: ${repoUrl}, it should follow the format: ${expectedFormat}`,
1604
1702
  );
1605
1703
  }
1606
1704
  const normalizeOptions = {
@@ -0,0 +1,8 @@
1
+ export interface IPublishPluginConfig {
2
+ branchPrefix?: string;
3
+ }
4
+ /**
5
+ * Read plugin configuration from common/config/rush-plugins/@coze-arch/rush-publish-plugin.json
6
+ * @returns Plugin configuration object
7
+ */
8
+ export declare function getPluginConfig(): IPublishPluginConfig;
@@ -4,6 +4,11 @@ export declare const getChangedFilesFromCached: () => Promise<string[]>;
4
4
  * @returns string
5
5
  */
6
6
  export declare const getCurrentBranchName: () => Promise<string>;
7
+ /**
8
+ * 获取当前 commit hash
9
+ * @returns commit hash
10
+ */
11
+ export declare const getCurrentCommitHash: () => Promise<string>;
7
12
  export declare const isMainBranch: () => Promise<boolean>;
8
13
  export declare const getChangedFiles: () => Promise<string[]>;
9
14
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/rush-publish-plugin",
3
- "version": "0.0.5-alpha.0f1107",
3
+ "version": "0.0.5-alpha.e7fa7b",
4
4
  "description": "rush plugin to generate change log and publish packages",
5
5
  "keywords": [
6
6
  "rush",