@fern-api/generator-cli 0.9.45 → 0.9.46

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.
Files changed (2) hide show
  1. package/dist/cli.js +93 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -41656,7 +41656,8 @@ var AutoVersionStep = class extends BaseStep {
41656
41656
  }
41657
41657
  async handleNormalFlow(params) {
41658
41658
  const { prepared, service, language, mappedMagicVersion, previousGenerationSha } = params;
41659
- const rawDiff = this.gitDiff(previousGenerationSha, prepared.currentGenerationSha);
41659
+ const diffBase = this.resolveReachableGenerationBase(previousGenerationSha, prepared.currentGenerationSha);
41660
+ const rawDiff = diffBase != null ? this.safeGitDiff(diffBase, prepared.currentGenerationSha) : "";
41660
41661
  const previousVersion = await this.resolvePreviousVersion({
41661
41662
  service,
41662
41663
  rawDiff,
@@ -42079,6 +42080,97 @@ var AutoVersionStep = class extends BaseStep {
42079
42080
  maxBuffer: 256 * 1024 * 1024
42080
42081
  });
42081
42082
  }
42083
+ /**
42084
+ * Resolves a reachable base commit for the autoversion diff.
42085
+ *
42086
+ * `recordedSha` (the previous generation from replay.lock) is preferred when it exists
42087
+ * in this clone. When it doesn't — e.g. the signed-commit push recreated the
42088
+ * [fern-generated] commit under a new SHA, or the branch was squash-merged — we re-anchor
42089
+ * on the most recent reachable [fern-generated] commit in history. Returns null when no
42090
+ * generation baseline is reachable at all, in which case the caller resolves the previous
42091
+ * version from metadata/git-tags and still rewrites the placeholder.
42092
+ */
42093
+ resolveReachableGenerationBase(recordedSha, currentGenerationSha) {
42094
+ if (this.commitExists(recordedSha)) {
42095
+ return recordedSha;
42096
+ }
42097
+ this.logger.warn(
42098
+ `AutoVersionStep: recorded previous generation ${recordedSha.slice(0, 7)} is unreachable in this clone; deriving the baseline from history.`
42099
+ );
42100
+ const derived = this.findPreviousGenerationFromHistory(currentGenerationSha);
42101
+ if (derived != null) {
42102
+ this.logger.info(`AutoVersionStep: re-anchored autoversion baseline on ${derived.slice(0, 7)}.`);
42103
+ return derived;
42104
+ }
42105
+ this.logger.warn(
42106
+ "AutoVersionStep: no reachable [fern-generated] baseline found; falling back to metadata/git-tags."
42107
+ );
42108
+ return null;
42109
+ }
42110
+ commitExists(sha) {
42111
+ if (!/^[0-9a-f]{7,40}$/.test(sha)) {
42112
+ return false;
42113
+ }
42114
+ try {
42115
+ (0, import_child_process4.execFileSync)("git", ["cat-file", "-e", `${sha}^{commit}`], {
42116
+ cwd: this.outputDir,
42117
+ stdio: "pipe"
42118
+ });
42119
+ return true;
42120
+ } catch {
42121
+ return false;
42122
+ }
42123
+ }
42124
+ /**
42125
+ * Walks first-parent history from the current generation commit and returns the most
42126
+ * recent prior [fern-generated] commit — the reachable equivalent of replay.lock's
42127
+ * recorded baseline. Mirrors @fern-api/replay's `findPreviousGenerationFromHistory`.
42128
+ */
42129
+ findPreviousGenerationFromHistory(currentGenerationSha) {
42130
+ const start = this.commitExists(currentGenerationSha) ? currentGenerationSha : "HEAD";
42131
+ let log;
42132
+ try {
42133
+ log = (0, import_child_process4.execFileSync)("git", ["log", "--first-parent", "--format=%H%x00%s", start], {
42134
+ cwd: this.outputDir,
42135
+ encoding: "utf-8",
42136
+ stdio: "pipe",
42137
+ maxBuffer: 64 * 1024 * 1024
42138
+ });
42139
+ } catch (error) {
42140
+ this.logger.debug(`AutoVersionStep: git log history walk failed (${String(error)}); no baseline derived.`);
42141
+ return null;
42142
+ }
42143
+ for (const line of log.split("\n")) {
42144
+ if (line.trim().length === 0) {
42145
+ continue;
42146
+ }
42147
+ const [sha, subject = ""] = line.split("\0");
42148
+ if (sha == null || sha === currentGenerationSha) {
42149
+ continue;
42150
+ }
42151
+ if (subject.startsWith("[fern-generated]")) {
42152
+ return sha;
42153
+ }
42154
+ }
42155
+ return null;
42156
+ }
42157
+ /**
42158
+ * `gitDiff` that degrades to an empty diff instead of throwing. Both endpoints are
42159
+ * expected to be reachable (the base is resolved via resolveReachableGenerationBase and
42160
+ * `to` is this run's freshly-created HEAD), but we never want a `git diff` failure to
42161
+ * abort autoversion and leave the magic placeholder in the shipped SDK — the empty diff
42162
+ * routes version resolution to baseVersion/metadata/git-tags, which still rewrites it.
42163
+ */
42164
+ safeGitDiff(from, to) {
42165
+ try {
42166
+ return this.gitDiff(from, to);
42167
+ } catch (error) {
42168
+ this.logger.warn(
42169
+ `AutoVersionStep: git diff ${from.slice(0, 7)}..${to.slice(0, 7)} failed (${error instanceof Error ? error.message : String(error)}); proceeding with an empty diff.`
42170
+ );
42171
+ return "";
42172
+ }
42173
+ }
42082
42174
  gitDiff(from, to) {
42083
42175
  return (0, import_child_process4.execFileSync)("git", ["diff", from, to, "--", ".", ":(exclude).fern/metadata.json"], {
42084
42176
  cwd: this.outputDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fern-api/generator-cli",
3
- "version": "0.9.45",
3
+ "version": "0.9.46",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/fern-api/fern.git",