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

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/lib/index.js CHANGED
@@ -6,6 +6,7 @@ var commander = require('commander');
6
6
  var shelljs = require('shelljs');
7
7
  var fs = require('fs/promises');
8
8
  var rushSdk = require('@rushstack/rush-sdk');
9
+ var minimatch = require('minimatch');
9
10
  var crypto = require('crypto');
10
11
  var semver = require('semver');
11
12
  var chalk = require('chalk');
@@ -236,11 +237,6 @@ const getCurrentCommitHash = async () => {
236
237
  return stdout.trim();
237
238
  };
238
239
 
239
- const isMainBranch = async () => {
240
- const currentBranchName = await getCurrentBranchName();
241
- return currentBranchName === 'main';
242
- };
243
-
244
240
  const getChangedFiles = async () => {
245
241
  const output = await exec('git diff --name-only --diff-filter=ACMR');
246
242
  return serializeFilesName(output.stdout);
@@ -404,10 +400,7 @@ function resolveRegistry(
404
400
  }
405
401
 
406
402
  // 3. 返回 undefined,让 npm 使用自己配置的 registry
407
- logger.info(
408
- `Using npm configured registry (${project.packageName})`,
409
- false,
410
- );
403
+ logger.info(`Using npm configured registry (${project.packageName})`, false);
411
404
  return undefined;
412
405
  }
413
406
 
@@ -535,11 +528,7 @@ const publishPackage = async (
535
528
  // 解析 registry:CLI 参数 > package.json publishConfig > npm 配置
536
529
  const registry = resolveRegistry(project, releaseOptions.registry);
537
530
 
538
- const setToken = `npm config set //bnpm.byted.org/:_authToken ${token}`;
539
- await exec(setToken, {
540
- cwd: project.projectFolder,
541
- });
542
-
531
+ // 使用环境变量传递 authToken,npm 会自动应用到任何 registry
543
532
  const args = [`NODE_AUTH_TOKEN=${token}`, 'npm', 'publish', `--tag ${tag}`];
544
533
  if (dryRun) {
545
534
  args.push('--dry-run');
@@ -587,6 +576,12 @@ const releasePackages = async (
587
576
  );
588
577
  };
589
578
 
579
+ // Copyright (c) 2025 coze-dev
580
+ // SPDX-License-Identifier: MIT
581
+
582
+
583
+
584
+
590
585
  var ReleaseType; (function (ReleaseType) {
591
586
  const ALPHA = 'alpha'; ReleaseType["ALPHA"] = ALPHA;
592
587
  const BETA = 'beta'; ReleaseType["BETA"] = BETA;
@@ -613,6 +608,36 @@ const calReleasePlan = (releaseManifests) => {
613
608
  return ReleaseType.ALPHA;
614
609
  };
615
610
 
611
+ /**
612
+ * Check if a branch name matches any of the allowed patterns.
613
+ * Supports exact matches, glob patterns (using minimatch), and regex patterns.
614
+ *
615
+ * @param branchName - The current branch name
616
+ * @param allowPatterns - Array of patterns (exact strings, glob patterns, or regex strings starting with '/')
617
+ * @returns true if the branch matches any pattern, false otherwise
618
+ */
619
+ const isBranchAllowed = (
620
+ branchName,
621
+ allowPatterns,
622
+ ) =>
623
+ allowPatterns.some(pattern => {
624
+ // Check if it's a regex pattern (enclosed in forward slashes)
625
+ if (pattern.startsWith('/') && pattern.endsWith('/')) {
626
+ const regexPattern = pattern.slice(1, -1);
627
+ try {
628
+ // eslint-disable-next-line security/detect-non-literal-regexp -- User-provided patterns are validated
629
+ const regex = new RegExp(regexPattern);
630
+ return regex.test(branchName);
631
+ } catch (e) {
632
+ // Invalid regex, fall back to exact match
633
+ return pattern === branchName;
634
+ }
635
+ }
636
+
637
+ // Use minimatch for glob patterns and exact matches
638
+ return minimatch.minimatch(branchName, pattern);
639
+ });
640
+
616
641
  const checkReleasePlan = (
617
642
  releaseManifests,
618
643
  branchName,
@@ -621,7 +646,7 @@ const checkReleasePlan = (
621
646
  const releasePlan = calReleasePlan(releaseManifests);
622
647
  if (
623
648
  releasePlan === ReleaseType.LATEST &&
624
- !allowBranches.includes(branchName)
649
+ !isBranchAllowed(branchName, allowBranches)
625
650
  ) {
626
651
  throw new Error(
627
652
  `For LATEST release, should be on one of these branches: ${allowBranches.join(', ')}. Current Branch: ${branchName}`,
@@ -902,19 +927,20 @@ const calculateNewVersion = (
902
927
  return semver.inc(cc, bumpType) || currentVersion;
903
928
  }
904
929
  case BumpType.BETA: {
905
- // 如果当前已经是 beta 版本,增加 beta 版本号
930
+ // If already a beta version, increment beta number
906
931
  if (prerelease[0] === 'beta') {
907
932
  const nextVersion = semver.inc(currentVersion, 'prerelease', 'beta');
908
933
  return nextVersion || currentVersion;
909
934
  }
910
- // 否则基于当前版本创建新的 beta 版本
911
- const baseVersion = `${major}.${minor}.${patch}`;
935
+ // Based on the next patch version to create beta version
936
+ const nextPatch = prerelease.length > 0 ? patch : patch + 1;
937
+ const baseVersion = `${major}.${minor}.${nextPatch}`;
912
938
  return `${baseVersion}-beta.1`;
913
939
  }
914
940
  case BumpType.ALPHA: {
915
- // 否则基于当前版本创建新的 alpha 版本
916
- const baseVersion = `${major}.${minor}.${patch}`;
917
- // 生成随机哈希值
941
+ // Based on the next patch version to create alpha version
942
+ const nextPatch = prerelease.length > 0 ? patch : patch + 1;
943
+ const baseVersion = `${major}.${minor}.${nextPatch}`;
918
944
  return `${baseVersion}-alpha.${sessionId || randomHash(6)}`;
919
945
  }
920
946
  default: {
@@ -1810,8 +1836,10 @@ const applyPublishManifest = async (
1810
1836
  // 2. beta: 本分支直接切换版本号,并发布
1811
1837
  // 3. 正式版本:发起MR,MR 合入 main 后,触发发布
1812
1838
 
1839
+ const SESSION_ID_LENGTH = 6;
1840
+
1813
1841
  const publish = async (options) => {
1814
- const sessionId = randomHash(6);
1842
+ const sessionId = randomHash(SESSION_ID_LENGTH);
1815
1843
  const rushConfiguration = getRushConfiguration$1();
1816
1844
  const rushFolder = rushConfiguration.rushJsonFolder;
1817
1845
  if (
@@ -1842,17 +1870,6 @@ const publish = async (options) => {
1842
1870
  const isBetaPublish = [BumpType.BETA, BumpType.ALPHA].includes(
1843
1871
  bumpPolicy ,
1844
1872
  );
1845
- if (
1846
- process.env.SKIP_BRANCH_CHECK !== 'true' &&
1847
- isBetaPublish === false &&
1848
- (await isMainBranch()) === false
1849
- ) {
1850
- // 只允许在主分支发布
1851
- logger.error(
1852
- 'You are not in main branch, please switch to main branch and try again.',
1853
- );
1854
- return;
1855
- }
1856
1873
 
1857
1874
  const continuePublish = await confirmForPublish(
1858
1875
  publishManifests,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/rush-publish-plugin",
3
- "version": "0.0.5-alpha.bba657",
3
+ "version": "0.0.5-alpha.d99d0c",
4
4
  "description": "rush plugin to generate change log and publish packages",
5
5
  "keywords": [
6
6
  "rush",
@@ -13,6 +13,7 @@
13
13
  "author": "tecvan.fe@gmail.com",
14
14
  "maintainers": [],
15
15
  "main": "./lib/index.js",
16
+ "types": "lib/index.d.ts",
16
17
  "bin": {
17
18
  "rush-publish": "./lib/index.js"
18
19
  },
@@ -36,6 +37,7 @@
36
37
  "conventional-changelog-angular": "^5.0.13",
37
38
  "conventional-commits-parser": "^3.2.4",
38
39
  "dayjs": "^1.11.13",
40
+ "minimatch": "^10.0.0",
39
41
  "open": "~10.1.0",
40
42
  "semver": "^7.7.1",
41
43
  "shelljs": "^0.9.2"
@@ -70,6 +72,5 @@
70
72
  },
71
73
  "main": "./lib/index.js",
72
74
  "types": "lib/index.d.ts"
73
- },
74
- "types": "lib/index.d.ts"
75
+ }
75
76
  }
@@ -1,8 +0,0 @@
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;