@ucdjs/release-scripts 0.1.0-beta.10 → 0.1.0-beta.11

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/dist/index.d.mts CHANGED
@@ -101,10 +101,16 @@ declare function publish(_options: PublishOptions): void;
101
101
  //#endregion
102
102
  //#region src/release.d.ts
103
103
  interface ReleaseOptions extends SharedOptions {
104
- /**
105
- * Branch name for the release PR (defaults to "release/next")
106
- */
107
- releaseBranch?: string;
104
+ branch?: {
105
+ /**
106
+ * Branch name for the release PR (defaults to "release/next")
107
+ */
108
+ release?: string;
109
+ /**
110
+ * Default branch name (e.g., "main")
111
+ */
112
+ default?: string;
113
+ };
108
114
  /**
109
115
  * Whether to perform a dry run (no changes pushed or PR created)
110
116
  * @default false
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as Eta } from "./eta-Boh7yPZi.mjs";
2
+ import farver from "farver";
2
3
  import { getCommits } from "commit-parser";
3
4
  import process from "node:process";
4
- import farver from "farver";
5
5
  import { exec } from "tinyexec";
6
6
  import { dedent } from "@luxass/utils";
7
7
  import { join } from "node:path";
@@ -380,6 +380,15 @@ async function pushBranch(branch, workspaceRoot, options) {
380
380
  exitWithError(`Failed to push branch: ${branch}`, `Make sure you have permission to push to the remote repository`);
381
381
  }
382
382
  }
383
+ async function getDefaultBranch() {
384
+ try {
385
+ const match = (await run("git", ["symbolic-ref", "refs/remotes/origin/HEAD"], { nodeOptions: { stdio: "pipe" } })).stdout.trim().match(/^refs\/remotes\/origin\/(.+)$/);
386
+ if (match && match[1]) return match[1];
387
+ return "main";
388
+ } catch {
389
+ return "main";
390
+ }
391
+ }
383
392
 
384
393
  //#endregion
385
394
  //#region src/github.ts
@@ -828,7 +837,9 @@ function shouldIncludePackage(pkg, options) {
828
837
  async function release(options) {
829
838
  const normalizedOptions = normalizeSharedOptions(options);
830
839
  normalizedOptions.dryRun ??= false;
831
- normalizedOptions.releaseBranch ??= "release/next";
840
+ normalizedOptions.branch ??= {};
841
+ normalizedOptions.branch.release ??= "release/next";
842
+ normalizedOptions.branch.default = await getDefaultBranch();
832
843
  normalizedOptions.safeguards ??= true;
833
844
  globalOptions.dryRun = normalizedOptions.dryRun;
834
845
  const workspaceRoot = normalizedOptions.workspaceRoot;
@@ -842,33 +853,34 @@ async function release(options) {
842
853
  if (versionUpdates.length === 0) logger.warn("No packages have changes requiring a release");
843
854
  const allUpdates = createDependentUpdates(buildPackageDependencyGraph(workspacePackages), workspacePackages, versionUpdates);
844
855
  const currentBranch = await getCurrentBranch(workspaceRoot);
856
+ if (currentBranch !== normalizedOptions.branch.default) exitWithError(`Current branch is '${currentBranch}'. Please switch to the default branch '${normalizedOptions.branch.default}' before proceeding.`, `git checkout ${normalizedOptions.branch.default}`);
845
857
  const existingPullRequest = await getExistingPullRequest({
846
858
  owner: normalizedOptions.owner,
847
859
  repo: normalizedOptions.repo,
848
- branch: normalizedOptions.releaseBranch,
860
+ branch: normalizedOptions.branch.release,
849
861
  githubToken: normalizedOptions.githubToken
850
862
  });
851
863
  const prExists = !!existingPullRequest;
852
864
  if (prExists) logger.log("Existing pull request found:", existingPullRequest.html_url);
853
865
  else logger.log("No existing pull request found, will create new one");
854
- const branchExists = await doesBranchExist(normalizedOptions.releaseBranch, workspaceRoot);
866
+ const branchExists = await doesBranchExist(normalizedOptions.branch.release, workspaceRoot);
855
867
  if (!branchExists) {
856
- logger.log("Creating release branch:", normalizedOptions.releaseBranch);
857
- await createBranch(normalizedOptions.releaseBranch, currentBranch, workspaceRoot);
868
+ logger.log("Creating release branch:", normalizedOptions.branch.release);
869
+ await createBranch(normalizedOptions.branch.release, normalizedOptions.branch.default, workspaceRoot);
858
870
  }
859
- if (!await checkoutBranch(normalizedOptions.releaseBranch, workspaceRoot)) throw new Error(`Failed to checkout branch: ${normalizedOptions.releaseBranch}`);
871
+ if (!await checkoutBranch(normalizedOptions.branch.release, workspaceRoot)) throw new Error(`Failed to checkout branch: ${normalizedOptions.branch.release}`);
860
872
  if (branchExists) {
861
873
  logger.log("Pulling latest changes from remote");
862
- if (!await pullLatestChanges(normalizedOptions.releaseBranch, workspaceRoot)) logger.log("Warning: Failed to pull latest changes, continuing anyway");
874
+ if (!await pullLatestChanges(normalizedOptions.branch.release, workspaceRoot)) logger.log("Warning: Failed to pull latest changes, continuing anyway");
863
875
  }
864
- logger.log("Rebasing release branch onto", currentBranch);
865
- await rebaseBranch(currentBranch, workspaceRoot);
876
+ logger.log("Rebasing release branch onto", normalizedOptions.branch.default);
877
+ await rebaseBranch(normalizedOptions.branch.default, workspaceRoot);
866
878
  await updateAllPackageJsonFiles(allUpdates);
867
879
  const hasCommitted = await commitChanges("chore: update release versions", workspaceRoot);
868
- const isBranchAhead = await isBranchAheadOfRemote(normalizedOptions.releaseBranch, workspaceRoot);
880
+ const isBranchAhead = await isBranchAheadOfRemote(normalizedOptions.branch.release, workspaceRoot);
869
881
  if (!hasCommitted && !isBranchAhead) {
870
882
  logger.log("No changes to commit and branch is in sync with remote");
871
- await checkoutBranch(currentBranch, workspaceRoot);
883
+ await checkoutBranch(normalizedOptions.branch.default, workspaceRoot);
872
884
  if (prExists) {
873
885
  logger.log("No updates needed, PR is already up to date");
874
886
  return {
@@ -882,7 +894,7 @@ async function release(options) {
882
894
  }
883
895
  }
884
896
  logger.log("Pushing changes to remote");
885
- await pushBranch(normalizedOptions.releaseBranch, workspaceRoot, { forceWithLease: true });
897
+ await pushBranch(normalizedOptions.branch.release, workspaceRoot, { forceWithLease: true });
886
898
  const prTitle = existingPullRequest?.title || options.pullRequest?.title || "chore: update package versions";
887
899
  const prBody = generatePullRequestBody(allUpdates, options.pullRequest?.body);
888
900
  const pullRequest = await upsertPullRequest({
@@ -891,12 +903,16 @@ async function release(options) {
891
903
  pullNumber: existingPullRequest?.number,
892
904
  title: prTitle,
893
905
  body: prBody,
894
- head: normalizedOptions.releaseBranch,
895
- base: currentBranch,
906
+ head: normalizedOptions.branch.release,
907
+ base: normalizedOptions.branch.default,
896
908
  githubToken: normalizedOptions.githubToken
897
909
  });
898
910
  logger.log(prExists ? "Updated pull request:" : "Created pull request:", pullRequest?.html_url);
899
- await checkoutBranch(currentBranch, workspaceRoot);
911
+ await checkoutBranch(normalizedOptions.branch.default, workspaceRoot);
912
+ if (pullRequest?.html_url) {
913
+ logger.info();
914
+ logger.info(`${farver.green("✓")} Pull request ${prExists ? "updated" : "created"}: ${farver.cyan(pullRequest.html_url)}`);
915
+ }
900
916
  return {
901
917
  updates: allUpdates,
902
918
  prUrl: pullRequest?.html_url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucdjs/release-scripts",
3
- "version": "0.1.0-beta.10",
3
+ "version": "0.1.0-beta.11",
4
4
  "description": "@ucdjs release scripts",
5
5
  "type": "module",
6
6
  "license": "MIT",