@fern-api/generator-cli 0.9.23 → 0.9.24

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/api.d.ts CHANGED
@@ -582,6 +582,14 @@ interface ReplayRunResult {
582
582
  currentGenerationSha: string | null;
583
583
  /** SHA of main's HEAD before replay ran. Always on main's lineage, stable after squash merges. */
584
584
  baseBranchHead: string | null;
585
+ /** True when this run inlined `bootstrap()` to create the lockfile (auto-init from `fern generate`). */
586
+ autoBootstrapped: boolean;
587
+ /**
588
+ * True when the lockfile-missing branch was entered, regardless of bootstrap outcome.
589
+ * Distinct from `autoBootstrapped` (true only on success) — together they let telemetry
590
+ * distinguish "tried but no anchor / threw" from "lockfile already existed".
591
+ */
592
+ bootstrapAttempted: boolean;
585
593
  /**
586
594
  * Set when prepare or apply crashed (e.g. corrupted lockfile, git failure, library bug).
587
595
  * Distinguishes a real failure from "no replay initialized" (lockfile missing → null report, no failureReason).
package/dist/api.js CHANGED
@@ -10247,7 +10247,7 @@ var import_replay4 = require("@fern-api/replay");
10247
10247
  var import_child_process3 = require("child_process");
10248
10248
  var import_fs3 = require("fs");
10249
10249
  var import_path5 = require("path");
10250
- async function replayPrepare(params) {
10250
+ async function replayPrepare(params, state) {
10251
10251
  const {
10252
10252
  outputDir,
10253
10253
  cliVersion,
@@ -10258,8 +10258,36 @@ async function replayPrepare(params) {
10258
10258
  logger
10259
10259
  } = params;
10260
10260
  const lockfilePath = (0, import_path5.join)(outputDir, ".fern", "replay.lock");
10261
+ let autoBootstrapped = false;
10262
+ let bootstrapAttempted = false;
10261
10263
  if (!(0, import_fs3.existsSync)(lockfilePath)) {
10262
- return null;
10264
+ if (process.env.FERN_DISABLE_AUTO_BOOTSTRAP === "true" || process.env.FERN_DISABLE_AUTO_BOOTSTRAP === "1") {
10265
+ return null;
10266
+ }
10267
+ bootstrapAttempted = true;
10268
+ if (state) {
10269
+ state.bootstrapAttempted = true;
10270
+ }
10271
+ try {
10272
+ const bootstrapResult = await (0, import_replay4.bootstrap)(outputDir, {
10273
+ fernignoreAction: "skip",
10274
+ force: false,
10275
+ importHistory: false
10276
+ });
10277
+ if (bootstrapResult.generationCommit == null) {
10278
+ return null;
10279
+ }
10280
+ autoBootstrapped = true;
10281
+ } catch (error) {
10282
+ logger?.warn("Replay auto-bootstrap failed, continuing without replay: " + String(error));
10283
+ try {
10284
+ if ((0, import_fs3.existsSync)(lockfilePath)) {
10285
+ (0, import_fs3.unlinkSync)(lockfilePath);
10286
+ }
10287
+ } catch {
10288
+ }
10289
+ return null;
10290
+ }
10263
10291
  }
10264
10292
  const baseBranchHead = gitRevParse(outputDir, "HEAD");
10265
10293
  let previousGenerationSha = null;
@@ -10339,7 +10367,9 @@ async function replayPrepare(params) {
10339
10367
  flow: preparation.flow,
10340
10368
  previousGenerationSha,
10341
10369
  currentGenerationSha: preparation.currentGenerationSha,
10342
- baseBranchHead
10370
+ baseBranchHead,
10371
+ autoBootstrapped,
10372
+ bootstrapAttempted
10343
10373
  };
10344
10374
  }
10345
10375
  async function replayApply(prepared, params = {}) {
@@ -10355,6 +10385,8 @@ async function replayApply(prepared, params = {}) {
10355
10385
  previousGenerationSha: prepared.previousGenerationSha,
10356
10386
  currentGenerationSha: prepared.currentGenerationSha,
10357
10387
  baseBranchHead: prepared.baseBranchHead,
10388
+ autoBootstrapped: prepared.autoBootstrapped,
10389
+ bootstrapAttempted: prepared.bootstrapAttempted,
10358
10390
  failureReason: String(error)
10359
10391
  };
10360
10392
  }
@@ -10377,13 +10409,16 @@ async function replayApply(prepared, params = {}) {
10377
10409
  fernignoreUpdated,
10378
10410
  previousGenerationSha: prepared.previousGenerationSha,
10379
10411
  currentGenerationSha: prepared.currentGenerationSha,
10380
- baseBranchHead: resolvedBaseBranchHead
10412
+ baseBranchHead: resolvedBaseBranchHead,
10413
+ autoBootstrapped: prepared.autoBootstrapped,
10414
+ bootstrapAttempted: prepared.bootstrapAttempted
10381
10415
  };
10382
10416
  }
10383
10417
  async function replayRun(params) {
10418
+ const prepareState = { bootstrapAttempted: false };
10384
10419
  let prepared;
10385
10420
  try {
10386
- prepared = await replayPrepare(params);
10421
+ prepared = await replayPrepare(params, prepareState);
10387
10422
  } catch (error) {
10388
10423
  return {
10389
10424
  report: null,
@@ -10391,6 +10426,8 @@ async function replayRun(params) {
10391
10426
  previousGenerationSha: null,
10392
10427
  currentGenerationSha: null,
10393
10428
  baseBranchHead: null,
10429
+ autoBootstrapped: false,
10430
+ bootstrapAttempted: prepareState.bootstrapAttempted,
10394
10431
  failureReason: error instanceof ReplayPrepareError ? error.reason : String(error)
10395
10432
  };
10396
10433
  }
@@ -10400,7 +10437,9 @@ async function replayRun(params) {
10400
10437
  fernignoreUpdated: false,
10401
10438
  previousGenerationSha: null,
10402
10439
  currentGenerationSha: null,
10403
- baseBranchHead: null
10440
+ baseBranchHead: null,
10441
+ autoBootstrapped: false,
10442
+ bootstrapAttempted: prepareState.bootstrapAttempted
10404
10443
  };
10405
10444
  }
10406
10445
  return replayApply(prepared, { stageOnly: params.stageOnly, logger: params.logger });
package/dist/cli.js CHANGED
@@ -39300,7 +39300,7 @@ init_dist3();
39300
39300
  var import_child_process4 = require("child_process");
39301
39301
  var import_fs12 = require("fs");
39302
39302
  var import_path17 = require("path");
39303
- async function replayPrepare(params) {
39303
+ async function replayPrepare(params, state) {
39304
39304
  const {
39305
39305
  outputDir,
39306
39306
  cliVersion,
@@ -39311,8 +39311,36 @@ async function replayPrepare(params) {
39311
39311
  logger
39312
39312
  } = params;
39313
39313
  const lockfilePath = (0, import_path17.join)(outputDir, ".fern", "replay.lock");
39314
+ let autoBootstrapped = false;
39315
+ let bootstrapAttempted = false;
39314
39316
  if (!(0, import_fs12.existsSync)(lockfilePath)) {
39315
- return null;
39317
+ if (process.env.FERN_DISABLE_AUTO_BOOTSTRAP === "true" || process.env.FERN_DISABLE_AUTO_BOOTSTRAP === "1") {
39318
+ return null;
39319
+ }
39320
+ bootstrapAttempted = true;
39321
+ if (state) {
39322
+ state.bootstrapAttempted = true;
39323
+ }
39324
+ try {
39325
+ const bootstrapResult = await bootstrap(outputDir, {
39326
+ fernignoreAction: "skip",
39327
+ force: false,
39328
+ importHistory: false
39329
+ });
39330
+ if (bootstrapResult.generationCommit == null) {
39331
+ return null;
39332
+ }
39333
+ autoBootstrapped = true;
39334
+ } catch (error) {
39335
+ logger?.warn("Replay auto-bootstrap failed, continuing without replay: " + String(error));
39336
+ try {
39337
+ if ((0, import_fs12.existsSync)(lockfilePath)) {
39338
+ (0, import_fs12.unlinkSync)(lockfilePath);
39339
+ }
39340
+ } catch {
39341
+ }
39342
+ return null;
39343
+ }
39316
39344
  }
39317
39345
  const baseBranchHead = gitRevParse(outputDir, "HEAD");
39318
39346
  let previousGenerationSha = null;
@@ -39392,7 +39420,9 @@ async function replayPrepare(params) {
39392
39420
  flow: preparation.flow,
39393
39421
  previousGenerationSha,
39394
39422
  currentGenerationSha: preparation.currentGenerationSha,
39395
- baseBranchHead
39423
+ baseBranchHead,
39424
+ autoBootstrapped,
39425
+ bootstrapAttempted
39396
39426
  };
39397
39427
  }
39398
39428
  async function replayApply(prepared, params = {}) {
@@ -39408,6 +39438,8 @@ async function replayApply(prepared, params = {}) {
39408
39438
  previousGenerationSha: prepared.previousGenerationSha,
39409
39439
  currentGenerationSha: prepared.currentGenerationSha,
39410
39440
  baseBranchHead: prepared.baseBranchHead,
39441
+ autoBootstrapped: prepared.autoBootstrapped,
39442
+ bootstrapAttempted: prepared.bootstrapAttempted,
39411
39443
  failureReason: String(error)
39412
39444
  };
39413
39445
  }
@@ -39430,13 +39462,16 @@ async function replayApply(prepared, params = {}) {
39430
39462
  fernignoreUpdated,
39431
39463
  previousGenerationSha: prepared.previousGenerationSha,
39432
39464
  currentGenerationSha: prepared.currentGenerationSha,
39433
- baseBranchHead: resolvedBaseBranchHead
39465
+ baseBranchHead: resolvedBaseBranchHead,
39466
+ autoBootstrapped: prepared.autoBootstrapped,
39467
+ bootstrapAttempted: prepared.bootstrapAttempted
39434
39468
  };
39435
39469
  }
39436
39470
  async function replayRun(params) {
39471
+ const prepareState = { bootstrapAttempted: false };
39437
39472
  let prepared;
39438
39473
  try {
39439
- prepared = await replayPrepare(params);
39474
+ prepared = await replayPrepare(params, prepareState);
39440
39475
  } catch (error) {
39441
39476
  return {
39442
39477
  report: null,
@@ -39444,6 +39479,8 @@ async function replayRun(params) {
39444
39479
  previousGenerationSha: null,
39445
39480
  currentGenerationSha: null,
39446
39481
  baseBranchHead: null,
39482
+ autoBootstrapped: false,
39483
+ bootstrapAttempted: prepareState.bootstrapAttempted,
39447
39484
  failureReason: error instanceof ReplayPrepareError ? error.reason : String(error)
39448
39485
  };
39449
39486
  }
@@ -39453,7 +39490,9 @@ async function replayRun(params) {
39453
39490
  fernignoreUpdated: false,
39454
39491
  previousGenerationSha: null,
39455
39492
  currentGenerationSha: null,
39456
- baseBranchHead: null
39493
+ baseBranchHead: null,
39494
+ autoBootstrapped: false,
39495
+ bootstrapAttempted: prepareState.bootstrapAttempted
39457
39496
  };
39458
39497
  }
39459
39498
  return replayApply(prepared, { stageOnly: params.stageOnly, logger: params.logger });
@@ -40646,7 +40685,12 @@ var AutoVersionStep = class extends BaseStep {
40646
40685
  async handleNormalFlow(params) {
40647
40686
  const { prepared, service, language, mappedMagicVersion, previousGenerationSha } = params;
40648
40687
  const rawDiff = this.gitDiff(previousGenerationSha, prepared.currentGenerationSha);
40649
- const previousVersion = await this.resolvePreviousVersion({ service, rawDiff, mappedMagicVersion });
40688
+ const previousVersion = await this.resolvePreviousVersion({
40689
+ service,
40690
+ rawDiff,
40691
+ mappedMagicVersion,
40692
+ baseVersion: this.config.baseVersion
40693
+ });
40650
40694
  if (previousVersion == null) {
40651
40695
  return await this.handleFirstGeneration({ service, language, mappedMagicVersion });
40652
40696
  }
@@ -40783,7 +40827,11 @@ var AutoVersionStep = class extends BaseStep {
40783
40827
  };
40784
40828
  }
40785
40829
  async resolvePreviousVersion(params) {
40786
- const { service, rawDiff, mappedMagicVersion } = params;
40830
+ const { service, rawDiff, mappedMagicVersion, baseVersion } = params;
40831
+ if (baseVersion != null && isValidSemver(baseVersion)) {
40832
+ this.logger.debug(`AutoVersionStep: previous version from pipeline baseVersion: ${baseVersion}`);
40833
+ return this.normalizeVersionPrefix(baseVersion, mappedMagicVersion);
40834
+ }
40787
40835
  try {
40788
40836
  const extracted = service.extractPreviousVersion(rawDiff, mappedMagicVersion);
40789
40837
  if (extracted != null) {
@@ -41037,16 +41085,20 @@ var GenerationCommitStep = class extends BaseStep {
41037
41085
  name = "generationCommit";
41038
41086
  async execute(_context) {
41039
41087
  const headBeforePrepare = tryRevParse(this.outputDir, "HEAD");
41088
+ const prepareState = { bootstrapAttempted: false };
41040
41089
  let prepared;
41041
41090
  try {
41042
- prepared = await replayPrepare({
41043
- outputDir: this.outputDir,
41044
- cliVersion: this.cliVersion,
41045
- generatorVersions: this.generatorVersions,
41046
- generatorName: this.generatorName,
41047
- skipApplication: this.config.skipApplication,
41048
- logger: this.logger
41049
- });
41091
+ prepared = await replayPrepare(
41092
+ {
41093
+ outputDir: this.outputDir,
41094
+ cliVersion: this.cliVersion,
41095
+ generatorVersions: this.generatorVersions,
41096
+ generatorName: this.generatorName,
41097
+ skipApplication: this.config.skipApplication,
41098
+ logger: this.logger
41099
+ },
41100
+ prepareState
41101
+ );
41050
41102
  } catch (error) {
41051
41103
  const reason = error instanceof ReplayPrepareError ? error.reason : String(error);
41052
41104
  if (headBeforePrepare != null) {
@@ -41062,14 +41114,16 @@ var GenerationCommitStep = class extends BaseStep {
41062
41114
  executed: true,
41063
41115
  success: true,
41064
41116
  errorMessage: reason,
41065
- preparedReplay: null
41117
+ preparedReplay: null,
41118
+ bootstrapAttempted: prepareState.bootstrapAttempted
41066
41119
  };
41067
41120
  }
41068
41121
  if (prepared == null) {
41069
41122
  return {
41070
41123
  executed: true,
41071
41124
  success: true,
41072
- preparedReplay: null
41125
+ preparedReplay: null,
41126
+ bootstrapAttempted: prepareState.bootstrapAttempted
41073
41127
  };
41074
41128
  }
41075
41129
  return {
@@ -41079,7 +41133,8 @@ var GenerationCommitStep = class extends BaseStep {
41079
41133
  previousGenerationSha: prepared.previousGenerationSha ?? void 0,
41080
41134
  currentGenerationSha: prepared.currentGenerationSha,
41081
41135
  baseBranchHead: prepared.baseBranchHead ?? void 0,
41082
- flow: prepared.flow
41136
+ flow: prepared.flow,
41137
+ bootstrapAttempted: prepareState.bootstrapAttempted
41083
41138
  };
41084
41139
  }
41085
41140
  };
@@ -41830,6 +41885,8 @@ var ReplayStep = class extends BaseStep {
41830
41885
  success: true,
41831
41886
  replayCrashed: true,
41832
41887
  errorMessage: generationCommit.errorMessage,
41888
+ autoBootstrapped: false,
41889
+ bootstrapAttempted: generationCommit.bootstrapAttempted === true,
41833
41890
  flow: "normal-regeneration",
41834
41891
  patchesDetected: 0,
41835
41892
  patchesApplied: 0,
@@ -41840,6 +41897,8 @@ var ReplayStep = class extends BaseStep {
41840
41897
  return {
41841
41898
  executed: true,
41842
41899
  success: true,
41900
+ autoBootstrapped: false,
41901
+ bootstrapAttempted: generationCommit.bootstrapAttempted === true,
41843
41902
  flow: "first-generation",
41844
41903
  patchesDetected: 0,
41845
41904
  patchesApplied: 0,
@@ -41867,6 +41926,8 @@ var ReplayStep = class extends BaseStep {
41867
41926
  previousGenerationSha: result.previousGenerationSha ?? void 0,
41868
41927
  currentGenerationSha: result.currentGenerationSha ?? void 0,
41869
41928
  baseBranchHead: result.baseBranchHead ?? void 0,
41929
+ autoBootstrapped: result.autoBootstrapped,
41930
+ bootstrapAttempted: result.bootstrapAttempted,
41870
41931
  flow: "normal-regeneration",
41871
41932
  patchesDetected: 0,
41872
41933
  patchesApplied: 0,
@@ -41880,6 +41941,8 @@ var ReplayStep = class extends BaseStep {
41880
41941
  previousGenerationSha: result.previousGenerationSha ?? void 0,
41881
41942
  currentGenerationSha: result.currentGenerationSha ?? void 0,
41882
41943
  baseBranchHead: result.baseBranchHead ?? void 0,
41944
+ autoBootstrapped: result.autoBootstrapped,
41945
+ bootstrapAttempted: result.bootstrapAttempted,
41883
41946
  flow: "first-generation",
41884
41947
  patchesDetected: 0,
41885
41948
  patchesApplied: 0,
@@ -41893,6 +41956,8 @@ var ReplayStep = class extends BaseStep {
41893
41956
  previousGenerationSha: result.previousGenerationSha ?? void 0,
41894
41957
  currentGenerationSha: result.currentGenerationSha ?? void 0,
41895
41958
  baseBranchHead: result.baseBranchHead ?? void 0,
41959
+ autoBootstrapped: result.autoBootstrapped,
41960
+ bootstrapAttempted: result.bootstrapAttempted,
41896
41961
  flow: report.flow,
41897
41962
  patchesDetected: report.patchesDetected,
41898
41963
  patchesApplied: report.patchesApplied,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fern-api/generator-cli",
3
- "version": "0.9.23",
3
+ "version": "0.9.24",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/fern-api/fern.git",