@fern-api/generator-cli 0.9.53 → 0.9.54

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 +58 -13
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -41843,11 +41843,20 @@ var SEMVER_PATTERN = /^(v)?(\d+)\.(\d+)\.(\d+)(?:-([\w.-]+))?(?:\+([\w.-]+))?$/;
41843
41843
  function isValidSemver(version2) {
41844
41844
  return SEMVER_PATTERN.test(version2);
41845
41845
  }
41846
+ function isPlaceholderVersion(version2) {
41847
+ const withoutPrefix = version2.startsWith("v") ? version2.slice(1) : version2;
41848
+ return withoutPrefix === MAGIC_VERSION || withoutPrefix.startsWith(`${MAGIC_VERSION}.`) || withoutPrefix === MAGIC_VERSION_PYTHON || withoutPrefix.startsWith(`${MAGIC_VERSION_PYTHON}.`);
41849
+ }
41846
41850
  function incrementVersion(currentVersion, versionBump) {
41847
41851
  const matcher = currentVersion.match(SEMVER_PATTERN);
41848
41852
  if (!matcher) {
41849
41853
  throw new AutoVersioningException("Invalid semantic version format: " + currentVersion);
41850
41854
  }
41855
+ if (isPlaceholderVersion(currentVersion)) {
41856
+ throw new AutoVersioningException(
41857
+ "Refusing to increment the magic placeholder version: " + currentVersion + ". A real previous version must be resolved first."
41858
+ );
41859
+ }
41851
41860
  const prefix = matcher[1] ?? "";
41852
41861
  const versionWithoutPrefix = currentVersion.slice(prefix.length);
41853
41862
  const preRelease = matcher[5];
@@ -41918,7 +41927,8 @@ var AutoVersionStep = class extends BaseStep {
41918
41927
  }
41919
41928
  async handleFirstGeneration(params) {
41920
41929
  const { service, language, mappedMagicVersion, commit } = params;
41921
- const initialVersion = this.config.baseVersion ?? (mappedMagicVersion.startsWith("v") ? "v0.0.1" : "0.0.1");
41930
+ const configuredBaseVersion = this.usableVersion(this.config.baseVersion, "baseVersion");
41931
+ const initialVersion = configuredBaseVersion ?? (mappedMagicVersion.startsWith("v") ? "v0.0.1" : "0.0.1");
41922
41932
  if (!isValidSemver(initialVersion)) {
41923
41933
  const errorMessage = `AutoVersionStep: baseVersion ${JSON.stringify(initialVersion)} is not a valid semver string (expected e.g. "1.2.3" or "v1.2.3"). Refusing to run.`;
41924
41934
  this.logger.error(errorMessage);
@@ -42252,14 +42262,18 @@ var AutoVersionStep = class extends BaseStep {
42252
42262
  */
42253
42263
  async resolvePreviousVersionNonReplay(params) {
42254
42264
  const { service, rawDiff, mappedMagicVersion, baseVersion } = params;
42255
- if (baseVersion != null && isValidSemver(baseVersion)) {
42265
+ const usableBaseVersion = this.usableVersion(baseVersion, "baseVersion");
42266
+ if (usableBaseVersion != null && isValidSemver(usableBaseVersion)) {
42256
42267
  this.logger.debug(
42257
- `AutoVersionStep (non-replay): previous version from pipeline baseVersion: ${baseVersion}`
42268
+ `AutoVersionStep (non-replay): previous version from pipeline baseVersion: ${usableBaseVersion}`
42258
42269
  );
42259
- return this.normalizeVersionPrefix(baseVersion, mappedMagicVersion);
42270
+ return this.normalizeVersionPrefix(usableBaseVersion, mappedMagicVersion);
42260
42271
  }
42261
42272
  try {
42262
- const extracted = service.extractPreviousVersion(rawDiff, mappedMagicVersion);
42273
+ const extracted = this.usableVersion(
42274
+ service.extractPreviousVersion(rawDiff, mappedMagicVersion) ?? void 0,
42275
+ "diff"
42276
+ );
42263
42277
  if (extracted != null) {
42264
42278
  this.logger.debug(`AutoVersionStep (non-replay): previous version from diff: ${extracted}`);
42265
42279
  return extracted;
@@ -42270,12 +42284,15 @@ var AutoVersionStep = class extends BaseStep {
42270
42284
  }
42271
42285
  this.logger.info("AutoVersionStep (non-replay): magic version not in diff; trying metadata + git tags.");
42272
42286
  }
42273
- const metadataVersion = this.readVersionFromMetadataAtHead();
42287
+ const metadataVersion = this.usableVersion(this.readVersionFromMetadataAtHead(), "metadata.json");
42274
42288
  if (metadataVersion != null) {
42275
42289
  return this.normalizeVersionPrefix(metadataVersion, mappedMagicVersion);
42276
42290
  }
42277
42291
  try {
42278
- const tagVersion = await service.getLatestVersionFromGitTags(this.outputDir);
42292
+ const tagVersion = this.usableVersion(
42293
+ await service.getLatestVersionFromGitTags(this.outputDir) ?? void 0,
42294
+ "git tags"
42295
+ );
42279
42296
  if (tagVersion != null) {
42280
42297
  return this.normalizeVersionPrefix(tagVersion, mappedMagicVersion);
42281
42298
  }
@@ -42286,12 +42303,16 @@ var AutoVersionStep = class extends BaseStep {
42286
42303
  }
42287
42304
  async resolvePreviousVersion(params) {
42288
42305
  const { service, rawDiff, mappedMagicVersion, baseVersion } = params;
42289
- if (baseVersion != null && isValidSemver(baseVersion)) {
42290
- this.logger.debug(`AutoVersionStep: previous version from pipeline baseVersion: ${baseVersion}`);
42291
- return this.normalizeVersionPrefix(baseVersion, mappedMagicVersion);
42306
+ const usableBaseVersion = this.usableVersion(baseVersion, "baseVersion");
42307
+ if (usableBaseVersion != null && isValidSemver(usableBaseVersion)) {
42308
+ this.logger.debug(`AutoVersionStep: previous version from pipeline baseVersion: ${usableBaseVersion}`);
42309
+ return this.normalizeVersionPrefix(usableBaseVersion, mappedMagicVersion);
42292
42310
  }
42293
42311
  try {
42294
- const extracted = service.extractPreviousVersion(rawDiff, mappedMagicVersion);
42312
+ const extracted = this.usableVersion(
42313
+ service.extractPreviousVersion(rawDiff, mappedMagicVersion) ?? void 0,
42314
+ "diff"
42315
+ );
42295
42316
  if (extracted != null) {
42296
42317
  this.logger.debug(`AutoVersionStep: previous version from diff: ${extracted}`);
42297
42318
  return extracted;
@@ -42302,12 +42323,15 @@ var AutoVersionStep = class extends BaseStep {
42302
42323
  }
42303
42324
  this.logger.info("AutoVersionStep: magic version not found in diff; falling back to metadata + git tags.");
42304
42325
  }
42305
- const metadataVersion = await this.readVersionFromMetadata();
42326
+ const metadataVersion = this.usableVersion(await this.readVersionFromMetadata(), "metadata.json");
42306
42327
  if (metadataVersion != null) {
42307
42328
  return this.normalizeVersionPrefix(metadataVersion, mappedMagicVersion);
42308
42329
  }
42309
42330
  try {
42310
- const tagVersion = await service.getLatestVersionFromGitTags(this.outputDir);
42331
+ const tagVersion = this.usableVersion(
42332
+ await service.getLatestVersionFromGitTags(this.outputDir) ?? void 0,
42333
+ "git tags"
42334
+ );
42311
42335
  if (tagVersion != null) {
42312
42336
  return this.normalizeVersionPrefix(tagVersion, mappedMagicVersion);
42313
42337
  }
@@ -42329,6 +42353,27 @@ var AutoVersionStep = class extends BaseStep {
42329
42353
  return void 0;
42330
42354
  }
42331
42355
  }
42356
+ /**
42357
+ * Drops candidate previous versions that are the magic placeholder. SDK repos
42358
+ * that derive their published version at release time keep the placeholder
42359
+ * committed, so every resolution source (baseVersion, diff extraction,
42360
+ * metadata.json, git tags) can hand back the sentinel; incrementing it would
42361
+ * emit a mutated placeholder such as `0.0.0-fern-placeholder.0` instead of a
42362
+ * real version. Returning undefined lets the caller fall through to the next
42363
+ * source, and ultimately to the first-generation path.
42364
+ */
42365
+ usableVersion(version2, source) {
42366
+ if (version2 == null) {
42367
+ return void 0;
42368
+ }
42369
+ if (isPlaceholderVersion(version2)) {
42370
+ this.logger.info(
42371
+ `AutoVersionStep: ignoring placeholder version ${version2} from ${source}; trying the next previous-version source.`
42372
+ );
42373
+ return void 0;
42374
+ }
42375
+ return version2;
42376
+ }
42332
42377
  normalizeVersionPrefix(version2, mappedMagicVersion) {
42333
42378
  const stripped = version2.startsWith("v") ? version2.slice(1) : version2;
42334
42379
  return mappedMagicVersion.startsWith("v") ? `v${stripped}` : stripped;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fern-api/generator-cli",
3
- "version": "0.9.53",
3
+ "version": "0.9.54",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/fern-api/fern.git",