@fern-api/generator-cli 0.9.26 → 0.9.28

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 (3) hide show
  1. package/dist/api.js +12 -1
  2. package/dist/cli.js +402 -69
  3. package/package.json +1 -1
package/dist/api.js CHANGED
@@ -6362,6 +6362,15 @@ async function cloneRepository({ githubRepository, installationToken, targetDire
6362
6362
  });
6363
6363
  }
6364
6364
 
6365
+ // ../commons/github/lib/getGithubApiBaseUrl.js
6366
+ function getGithubApiBaseUrl(repositoryUri) {
6367
+ const { remote } = parseRepository(repositoryUri);
6368
+ if (remote === DEFAULT_REMOTE) {
6369
+ return void 0;
6370
+ }
6371
+ return `https://${remote}/api/v3`;
6372
+ }
6373
+
6365
6374
  // src/readme/ReadmeGenerator.ts
6366
6375
  var import_compat = require("es-toolkit/compat");
6367
6376
  var import_string2 = require("es-toolkit/string");
@@ -10069,8 +10078,10 @@ var GitHub = class {
10069
10078
  await this.restoreFiles(repository, fernIgnoreFiles);
10070
10079
  await repository.commit("SDK Generation");
10071
10080
  await repository.push();
10081
+ const apiBaseUrl = getGithubApiBaseUrl(this.githubConfig.uri);
10072
10082
  const octokit = new import_rest.Octokit({
10073
- auth: this.githubConfig.token
10083
+ auth: this.githubConfig.token,
10084
+ ...apiBaseUrl != null ? { baseUrl: apiBaseUrl } : {}
10074
10085
  });
10075
10086
  const parsedRepo = parseRepository(this.githubConfig.uri);
10076
10087
  const { owner, repo } = parsedRepo;
package/dist/cli.js CHANGED
@@ -4186,10 +4186,10 @@ var require_tmp_promise = __commonJS({
4186
4186
  "../../node_modules/.pnpm/tmp-promise@3.0.3/node_modules/tmp-promise/index.js"(exports2, module2) {
4187
4187
  "use strict";
4188
4188
  var { promisify } = require("util");
4189
- var tmp3 = require_tmp();
4190
- module2.exports.fileSync = tmp3.fileSync;
4189
+ var tmp4 = require_tmp();
4190
+ module2.exports.fileSync = tmp4.fileSync;
4191
4191
  var fileWithOptions = promisify(
4192
- (options, cb) => tmp3.file(
4192
+ (options, cb) => tmp4.file(
4193
4193
  options,
4194
4194
  (err, path5, fd, cleanup) => err ? cb(err) : cb(void 0, { path: path5, fd, cleanup: promisify(cleanup) })
4195
4195
  )
@@ -4203,9 +4203,9 @@ var require_tmp_promise = __commonJS({
4203
4203
  await cleanup();
4204
4204
  }
4205
4205
  };
4206
- module2.exports.dirSync = tmp3.dirSync;
4206
+ module2.exports.dirSync = tmp4.dirSync;
4207
4207
  var dirWithOptions = promisify(
4208
- (options, cb) => tmp3.dir(
4208
+ (options, cb) => tmp4.dir(
4209
4209
  options,
4210
4210
  (err, path5, cleanup) => err ? cb(err) : cb(void 0, { path: path5, cleanup: promisify(cleanup) })
4211
4211
  )
@@ -4219,10 +4219,10 @@ var require_tmp_promise = __commonJS({
4219
4219
  await cleanup();
4220
4220
  }
4221
4221
  };
4222
- module2.exports.tmpNameSync = tmp3.tmpNameSync;
4223
- module2.exports.tmpName = promisify(tmp3.tmpName);
4224
- module2.exports.tmpdir = tmp3.tmpdir;
4225
- module2.exports.setGracefulCleanup = tmp3.setGracefulCleanup;
4222
+ module2.exports.tmpNameSync = tmp4.tmpNameSync;
4223
+ module2.exports.tmpName = promisify(tmp4.tmpName);
4224
+ module2.exports.tmpdir = tmp4.tmpdir;
4225
+ module2.exports.setGracefulCleanup = tmp4.setGracefulCleanup;
4226
4226
  }
4227
4227
  });
4228
4228
 
@@ -7035,15 +7035,15 @@ var require_sync = __commonJS({
7035
7035
  var { readdirSync: readdirSync2, statSync: statSync4 } = require("fs");
7036
7036
  module2.exports = function(start, callback) {
7037
7037
  let dir = resolve8(".", start);
7038
- let tmp3, stats = statSync4(dir);
7038
+ let tmp4, stats = statSync4(dir);
7039
7039
  if (!stats.isDirectory()) {
7040
7040
  dir = dirname5(dir);
7041
7041
  }
7042
7042
  while (true) {
7043
- tmp3 = callback(dir, readdirSync2(dir));
7044
- if (tmp3) return resolve8(dir, tmp3);
7045
- dir = dirname5(tmp3 = dir);
7046
- if (tmp3 === dir) break;
7043
+ tmp4 = callback(dir, readdirSync2(dir));
7044
+ if (tmp4) return resolve8(dir, tmp4);
7045
+ dir = dirname5(tmp4 = dir);
7046
+ if (tmp4 === dir) break;
7047
7047
  }
7048
7048
  };
7049
7049
  }
@@ -7078,7 +7078,7 @@ var require_require_directory = __commonJS({
7078
7078
  "../../node_modules/.pnpm/require-directory@2.1.1/node_modules/require-directory/index.js"(exports2, module2) {
7079
7079
  "use strict";
7080
7080
  var fs3 = require("fs");
7081
- var join15 = require("path").join;
7081
+ var join16 = require("path").join;
7082
7082
  var resolve8 = require("path").resolve;
7083
7083
  var dirname5 = require("path").dirname;
7084
7084
  var defaultOptions2 = {
@@ -7115,7 +7115,7 @@ var require_require_directory = __commonJS({
7115
7115
  }
7116
7116
  path5 = !path5 ? dirname5(m.filename) : resolve8(dirname5(m.filename), path5);
7117
7117
  fs3.readdirSync(path5).forEach(function(filename) {
7118
- var joined = join15(path5, filename), files, key, obj;
7118
+ var joined = join16(path5, filename), files, key, obj;
7119
7119
  if (fs3.statSync(joined).isDirectory() && options.recurse) {
7120
7120
  files = requireDirectory(m, joined, options);
7121
7121
  if (Object.keys(files).length) {
@@ -22939,17 +22939,17 @@ function overlayRegions(currentGenLines, locInCurrentGen, workingTreeLines, locI
22939
22939
  }
22940
22940
  async function unifiedDiff(beforeContent, afterContent, filePath) {
22941
22941
  if (beforeContent === afterContent) return "";
22942
- const tmp3 = await (0, import_promises6.mkdtemp)((0, import_path11.join)((0, import_os3.tmpdir)(), "fern-replay-pp-"));
22942
+ const tmp4 = await (0, import_promises6.mkdtemp)((0, import_path11.join)((0, import_os3.tmpdir)(), "fern-replay-pp-"));
22943
22943
  try {
22944
- const beforePath = (0, import_path11.join)(tmp3, "before");
22945
- const afterPath = (0, import_path11.join)(tmp3, "after");
22944
+ const beforePath = (0, import_path11.join)(tmp4, "before");
22945
+ const afterPath = (0, import_path11.join)(tmp4, "after");
22946
22946
  await (0, import_promises6.writeFile)(beforePath, beforeContent, "utf-8");
22947
22947
  await (0, import_promises6.writeFile)(afterPath, afterContent, "utf-8");
22948
22948
  const raw = await runGitDiffNoIndex(beforePath, afterPath);
22949
22949
  if (!raw.trim()) return "";
22950
22950
  return rewriteDiffHeaders(raw, filePath);
22951
22951
  } finally {
22952
- await (0, import_promises6.rm)(tmp3, { recursive: true, force: true });
22952
+ await (0, import_promises6.rm)(tmp4, { recursive: true, force: true });
22953
22953
  }
22954
22954
  }
22955
22955
  function runGitDiffNoIndex(beforePath, afterPath) {
@@ -27301,9 +27301,9 @@ var require_path_key = __commonJS({
27301
27301
  }
27302
27302
  });
27303
27303
 
27304
- // ../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/util/resolveCommand.js
27304
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
27305
27305
  var require_resolveCommand = __commonJS({
27306
- "../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports2, module2) {
27306
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports2, module2) {
27307
27307
  "use strict";
27308
27308
  var path5 = require("path");
27309
27309
  var which = require_which();
@@ -27343,9 +27343,9 @@ var require_resolveCommand = __commonJS({
27343
27343
  }
27344
27344
  });
27345
27345
 
27346
- // ../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/util/escape.js
27346
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js
27347
27347
  var require_escape = __commonJS({
27348
- "../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/util/escape.js"(exports2, module2) {
27348
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports2, module2) {
27349
27349
  "use strict";
27350
27350
  var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
27351
27351
  function escapeCommand(arg) {
@@ -27396,9 +27396,9 @@ var require_shebang_command = __commonJS({
27396
27396
  }
27397
27397
  });
27398
27398
 
27399
- // ../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/util/readShebang.js
27399
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
27400
27400
  var require_readShebang = __commonJS({
27401
- "../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/util/readShebang.js"(exports2, module2) {
27401
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports2, module2) {
27402
27402
  "use strict";
27403
27403
  var fs3 = require("fs");
27404
27404
  var shebangCommand = require_shebang_command();
@@ -27418,9 +27418,9 @@ var require_readShebang = __commonJS({
27418
27418
  }
27419
27419
  });
27420
27420
 
27421
- // ../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/parse.js
27421
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js
27422
27422
  var require_parse2 = __commonJS({
27423
- "../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/parse.js"(exports2, module2) {
27423
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports2, module2) {
27424
27424
  "use strict";
27425
27425
  var path5 = require("path");
27426
27426
  var resolveCommand = require_resolveCommand();
@@ -27480,9 +27480,9 @@ var require_parse2 = __commonJS({
27480
27480
  }
27481
27481
  });
27482
27482
 
27483
- // ../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/enoent.js
27483
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js
27484
27484
  var require_enoent = __commonJS({
27485
- "../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/lib/enoent.js"(exports2, module2) {
27485
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js"(exports2, module2) {
27486
27486
  "use strict";
27487
27487
  var isWin = process.platform === "win32";
27488
27488
  function notFoundError(original, syscall) {
@@ -27530,9 +27530,9 @@ var require_enoent = __commonJS({
27530
27530
  }
27531
27531
  });
27532
27532
 
27533
- // ../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/index.js
27533
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js
27534
27534
  var require_cross_spawn = __commonJS({
27535
- "../../node_modules/.pnpm/cross-spawn@7.0.5/node_modules/cross-spawn/index.js"(exports2, module2) {
27535
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports2, module2) {
27536
27536
  "use strict";
27537
27537
  var cp2 = require("child_process");
27538
27538
  var parse3 = require_parse2();
@@ -29638,9 +29638,9 @@ function resolve(...paths) {
29638
29638
  }
29639
29639
 
29640
29640
  // src/cli.ts
29641
- var import_fs15 = __toESM(require("fs"));
29642
- var import_promises15 = require("fs/promises");
29643
- var import_path21 = __toESM(require("path"));
29641
+ var import_fs16 = __toESM(require("fs"));
29642
+ var import_promises16 = require("fs/promises");
29643
+ var import_path22 = __toESM(require("path"));
29644
29644
 
29645
29645
  // ../../node_modules/.pnpm/yargs@17.7.2/node_modules/yargs/build/lib/yerror.js
29646
29646
  var YError = class _YError extends Error {
@@ -30953,15 +30953,15 @@ var import_path3 = require("path");
30953
30953
  var import_fs2 = require("fs");
30954
30954
  function sync_default(start, callback) {
30955
30955
  let dir = (0, import_path3.resolve)(".", start);
30956
- let tmp3, stats = (0, import_fs2.statSync)(dir);
30956
+ let tmp4, stats = (0, import_fs2.statSync)(dir);
30957
30957
  if (!stats.isDirectory()) {
30958
30958
  dir = (0, import_path3.dirname)(dir);
30959
30959
  }
30960
30960
  while (true) {
30961
- tmp3 = callback(dir, (0, import_fs2.readdirSync)(dir));
30962
- if (tmp3) return (0, import_path3.resolve)(dir, tmp3);
30963
- dir = (0, import_path3.dirname)(tmp3 = dir);
30964
- if (tmp3 === dir) break;
30961
+ tmp4 = callback(dir, (0, import_fs2.readdirSync)(dir));
30962
+ if (tmp4) return (0, import_path3.resolve)(dir, tmp4);
30963
+ dir = (0, import_path3.dirname)(tmp4 = dir);
30964
+ if (tmp4 === dir) break;
30965
30965
  }
30966
30966
  }
30967
30967
 
@@ -31728,6 +31728,15 @@ function getUserAgent() {
31728
31728
  return "<environment undetectable>";
31729
31729
  }
31730
31730
 
31731
+ // ../commons/github/lib/getGithubApiBaseUrl.js
31732
+ function getGithubApiBaseUrl(repositoryUri) {
31733
+ const { remote } = parseRepository(repositoryUri);
31734
+ if (remote === DEFAULT_REMOTE) {
31735
+ return void 0;
31736
+ }
31737
+ return `https://${remote}/api/v3`;
31738
+ }
31739
+
31731
31740
  // ../../node_modules/.pnpm/before-after-hook@4.0.0/node_modules/before-after-hook/lib/register.js
31732
31741
  function register(state, name, method, options) {
31733
31742
  if (typeof method !== "function") {
@@ -31993,23 +32002,23 @@ function getValues(context, operator, key, modifier) {
31993
32002
  });
31994
32003
  }
31995
32004
  } else {
31996
- const tmp3 = [];
32005
+ const tmp4 = [];
31997
32006
  if (Array.isArray(value)) {
31998
32007
  value.filter(isDefined).forEach(function(value2) {
31999
- tmp3.push(encodeValue(operator, value2));
32008
+ tmp4.push(encodeValue(operator, value2));
32000
32009
  });
32001
32010
  } else {
32002
32011
  Object.keys(value).forEach(function(k2) {
32003
32012
  if (isDefined(value[k2])) {
32004
- tmp3.push(encodeUnreserved(k2));
32005
- tmp3.push(encodeValue(operator, value[k2].toString()));
32013
+ tmp4.push(encodeUnreserved(k2));
32014
+ tmp4.push(encodeValue(operator, value[k2].toString()));
32006
32015
  }
32007
32016
  });
32008
32017
  }
32009
32018
  if (isKeyOperator(operator)) {
32010
- result.push(encodeUnreserved(key) + "=" + tmp3.join(","));
32011
- } else if (tmp3.length !== 0) {
32012
- result.push(tmp3.join(","));
32019
+ result.push(encodeUnreserved(key) + "=" + tmp4.join(","));
32020
+ } else if (tmp4.length !== 0) {
32021
+ result.push(tmp4.join(","));
32013
32022
  }
32014
32023
  }
32015
32024
  }
@@ -32044,8 +32053,8 @@ function expand2(template2, context) {
32044
32053
  expression = expression.substr(1);
32045
32054
  }
32046
32055
  expression.split(/,/g).forEach(function(variable) {
32047
- var tmp3 = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
32048
- values.push(getValues(context, operator, tmp3[1], tmp3[2] || tmp3[3]));
32056
+ var tmp4 = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
32057
+ values.push(getValues(context, operator, tmp4[1], tmp4[2] || tmp4[3]));
32049
32058
  });
32050
32059
  if (operator && operator !== "+") {
32051
32060
  var separator = ",";
@@ -35418,8 +35427,10 @@ var GitHub = class {
35418
35427
  await this.restoreFiles(repository, fernIgnoreFiles);
35419
35428
  await repository.commit("SDK Generation");
35420
35429
  await repository.push();
35430
+ const apiBaseUrl = getGithubApiBaseUrl(this.githubConfig.uri);
35421
35431
  const octokit = new Octokit2({
35422
- auth: this.githubConfig.token
35432
+ auth: this.githubConfig.token,
35433
+ ...apiBaseUrl != null ? { baseUrl: apiBaseUrl } : {}
35423
35434
  });
35424
35435
  const parsedRepo = parseRepository(this.githubConfig.uri);
35425
35436
  const { owner, repo } = parsedRepo;
@@ -41383,13 +41394,20 @@ async function createReplayBranch(repository, branchName, commitMessage, replayC
41383
41394
  }
41384
41395
  const parentSha = replayConflictInfo.previousGenerationSha;
41385
41396
  await repository.createBranchFromHead(branchName);
41386
- const genTreeHash = await repository.getCommitTreeHash(replayConflictInfo.currentGenerationSha);
41387
- const tagCommitSha = await repository.commitTree(
41388
- genTreeHash,
41389
- parentSha,
41390
- `[fern-generated] ${commitMessage ?? "Update SDK"}`
41391
- );
41392
- return tagCommitSha;
41397
+ try {
41398
+ const genTreeHash = await repository.getCommitTreeHash(replayConflictInfo.currentGenerationSha);
41399
+ const tagCommitSha = await repository.commitTree(
41400
+ genTreeHash,
41401
+ parentSha,
41402
+ `[fern-generated] ${commitMessage ?? "Update SDK"}`
41403
+ );
41404
+ return tagCommitSha;
41405
+ } catch (error) {
41406
+ logger.warn(
41407
+ `Could not create fern-generation-base tag commit: parent ${parentSha} is unreachable in this clone (likely on a squash-merged + deleted branch). Continuing without tag update. Underlying error: ${String(error)}`
41408
+ );
41409
+ return void 0;
41410
+ }
41393
41411
  }
41394
41412
 
41395
41413
  // src/pipeline/github/findExistingUpdatablePR.ts
@@ -41513,6 +41531,7 @@ async function pushSignedCommit({
41513
41531
  branch,
41514
41532
  force,
41515
41533
  rebaseOnConflict = false,
41534
+ author,
41516
41535
  logger
41517
41536
  }) {
41518
41537
  const tempRef = `refs/temp/fern-${Date.now()}`;
@@ -41527,12 +41546,18 @@ async function pushSignedCommit({
41527
41546
  await repository.pushObjectToRef(localHeadSha, tempRef);
41528
41547
  tempRefPushed = true;
41529
41548
  for (let attempt2 = 0; attempt2 < MAX_CONCURRENT_PUSH_RETRIES; attempt2++) {
41549
+ const commitAuthor = {
41550
+ name: author?.name ?? FERN_BOT_NAME2,
41551
+ email: author?.email ?? FERN_BOT_EMAIL2
41552
+ };
41530
41553
  const { data: signedCommit } = await octokit.git.createCommit({
41531
41554
  owner,
41532
41555
  repo,
41533
41556
  message,
41534
41557
  tree: treeSha,
41535
- parents
41558
+ parents,
41559
+ author: commitAuthor,
41560
+ committer: commitAuthor
41536
41561
  });
41537
41562
  const signedSha = signedCommit.sha;
41538
41563
  try {
@@ -41781,8 +41806,8 @@ var GithubStep = class extends BaseStep {
41781
41806
  }
41782
41807
  async executePullRequestMode(repository, newPrBranch, skipCommit, replayConflictInfo, replayResult, resolved) {
41783
41808
  const baseBranch = this.config.branch ?? await repository.getDefaultBranch();
41784
- const octokit = new Octokit2({ auth: this.config.token });
41785
- const { owner, repo } = parseRepository(this.config.uri);
41809
+ const octokit = this.createOctokit();
41810
+ const { owner, repo, remote } = parseRepository(this.config.uri);
41786
41811
  let prBranch;
41787
41812
  let isUpdatingExistingPR = false;
41788
41813
  let generationBaseSha;
@@ -41858,10 +41883,11 @@ var GithubStep = class extends BaseStep {
41858
41883
  repo,
41859
41884
  branch: prBranch,
41860
41885
  force: isUpdatingExistingPR,
41886
+ author: this.config.author,
41861
41887
  logger: this.logger
41862
41888
  });
41863
41889
  const pushedBranch = await repository.getCurrentBranch();
41864
- result.branchUrl = `https://github.com/${this.config.uri}/tree/${pushedBranch}`;
41890
+ result.branchUrl = `https://${remote}/${owner}/${repo}/tree/${pushedBranch}`;
41865
41891
  this.logger.info(`Pushed branch: ${result.branchUrl}`);
41866
41892
  if (generationBaseSha != null) {
41867
41893
  try {
@@ -41876,7 +41902,7 @@ var GithubStep = class extends BaseStep {
41876
41902
  }
41877
41903
  }
41878
41904
  const headSha = await repository.getHeadSha();
41879
- const changelogUrl = resolved.changelogEntry ? `https://github.com/${this.config.uri}/blob/${headSha}/changelog.md` : void 0;
41905
+ const changelogUrl = resolved.changelogEntry ? `https://${remote}/${owner}/${repo}/blob/${headSha}/changelog.md` : void 0;
41880
41906
  const { prTitle, prBody } = parseCommitMessageForPR(
41881
41907
  resolved.commitMessage,
41882
41908
  resolved.changelogEntry,
@@ -41970,8 +41996,8 @@ var GithubStep = class extends BaseStep {
41970
41996
  success: true
41971
41997
  };
41972
41998
  if (!this.config.previewMode) {
41973
- const octokit = new Octokit2({ auth: this.config.token });
41974
- const { owner, repo } = parseRepository(this.config.uri);
41999
+ const octokit = this.createOctokit();
42000
+ const { owner, repo, remote } = parseRepository(this.config.uri);
41975
42001
  await pushSignedCommit({
41976
42002
  repository,
41977
42003
  octokit,
@@ -41980,14 +42006,22 @@ var GithubStep = class extends BaseStep {
41980
42006
  branch: baseBranch,
41981
42007
  force: false,
41982
42008
  rebaseOnConflict: true,
42009
+ author: this.config.author,
41983
42010
  logger: this.logger
41984
42011
  });
41985
42012
  const pushedBranch = await repository.getCurrentBranch();
41986
- result.branchUrl = `https://github.com/${this.config.uri}/tree/${pushedBranch}`;
42013
+ result.branchUrl = `https://${remote}/${owner}/${repo}/tree/${pushedBranch}`;
41987
42014
  this.logger.info(`Pushed branch: ${result.branchUrl}`);
41988
42015
  }
41989
42016
  return result;
41990
42017
  }
42018
+ createOctokit() {
42019
+ const opts = { auth: this.config.token };
42020
+ if (this.config.apiBaseUrl != null) {
42021
+ opts.baseUrl = this.config.apiBaseUrl;
42022
+ }
42023
+ return new Octokit2(opts);
42024
+ }
41991
42025
  async ensureFernignore() {
41992
42026
  this.logger.debug("Checking for .fernignore file...");
41993
42027
  const fernignorePath = (0, import_path20.join)(this.outputDir, ".fernignore");
@@ -42206,6 +42240,278 @@ var ReplayStep = class extends BaseStep {
42206
42240
  }
42207
42241
  };
42208
42242
 
42243
+ // ../cli/generation/local-generation/docker-utils/lib/runDocker.js
42244
+ var import_promises15 = require("fs/promises");
42245
+ var import_tmp_promise3 = __toESM(require_tmp_promise(), 1);
42246
+ async function pullImage(imageName, runner, signal) {
42247
+ await loggingExeca(void 0, runner ?? "docker", ["pull", imageName], {
42248
+ all: true,
42249
+ doNotPipeOutput: true,
42250
+ signal
42251
+ });
42252
+ }
42253
+ async function startContainer({ logger, imageName, runner }) {
42254
+ const containerRunner = runner ?? "docker";
42255
+ const tryStart = async () => {
42256
+ const { stdout, exitCode, stderr } = await loggingExeca(logger, containerRunner, ["run", "--user", "root", "-dit", "--entrypoint", "/bin/sh", imageName], {
42257
+ reject: false,
42258
+ doNotPipeOutput: true
42259
+ });
42260
+ if (exitCode == null) {
42261
+ throw new Error(`Container runtime '${containerRunner}' is not installed or not found on PATH.
42262
+ Error details: ${stderr || stdout || "No output"}`);
42263
+ }
42264
+ if (exitCode !== 0) {
42265
+ throw new Error(`Failed to start container from image ${imageName}.
42266
+ ${stdout}
42267
+ ${stderr}`);
42268
+ }
42269
+ return stdout.trim();
42270
+ };
42271
+ try {
42272
+ return await tryStart();
42273
+ } catch (e) {
42274
+ if (e instanceof Error && e.message.includes("No such image")) {
42275
+ await pullImage(imageName, runner);
42276
+ return await tryStart();
42277
+ }
42278
+ throw e;
42279
+ }
42280
+ }
42281
+ async function execInContainer({ logger, containerId, command, runner, writeLogsToFile = true, reject = true }) {
42282
+ const containerRunner = runner ?? "docker";
42283
+ const { stdout, stderr, exitCode } = await loggingExeca(logger, containerRunner, ["exec", "--user", "root", containerId, ...command], {
42284
+ reject: false,
42285
+ all: true,
42286
+ doNotPipeOutput: true
42287
+ });
42288
+ const logs = stdout + stderr;
42289
+ if (writeLogsToFile) {
42290
+ const tmpFile = await import_tmp_promise3.default.file();
42291
+ await (0, import_promises15.writeFile)(tmpFile.path, logs);
42292
+ logger.info(`Generator logs here: ${tmpFile.path}`);
42293
+ }
42294
+ const resolvedExitCode = exitCode ?? 1;
42295
+ if (reject && resolvedExitCode !== 0) {
42296
+ throw new Error(`Container exec exited with code ${resolvedExitCode}.
42297
+ ${stdout}
42298
+ ${stderr}`);
42299
+ }
42300
+ return { stdout, stderr, exitCode: resolvedExitCode };
42301
+ }
42302
+ async function copyToContainer({ logger, containerId, hostPath, containerPath, runner }) {
42303
+ const containerRunner = runner ?? "docker";
42304
+ const { exitCode, stdout, stderr } = await loggingExeca(logger, containerRunner, ["cp", hostPath, `${containerId}:${containerPath}`], {
42305
+ reject: false,
42306
+ doNotPipeOutput: true
42307
+ });
42308
+ if (exitCode !== 0) {
42309
+ throw new Error(`Failed to copy ${hostPath} to container ${containerId}:${containerPath}.
42310
+ ${stdout}
42311
+ ${stderr}`);
42312
+ }
42313
+ }
42314
+ async function stopContainer({ logger, containerId, runner }) {
42315
+ const containerRunner = runner ?? "docker";
42316
+ await loggingExeca(logger, containerRunner, ["rm", "-f", containerId], {
42317
+ reject: false,
42318
+ doNotPipeOutput: true
42319
+ });
42320
+ }
42321
+
42322
+ // ../cli/logger/lib/LogLevel.js
42323
+ var LogLevel2 = {
42324
+ Trace: "trace",
42325
+ Debug: "debug",
42326
+ Info: "info",
42327
+ Warn: "warn",
42328
+ Error: "error"
42329
+ };
42330
+ var LOG_LEVELS = Object.values(LogLevel2);
42331
+
42332
+ // ../cli/logger/lib/createLogger.js
42333
+ var LoggerImpl = class {
42334
+ log;
42335
+ enabled;
42336
+ constructor(log, enabled = true) {
42337
+ this.log = log;
42338
+ this.enabled = enabled;
42339
+ }
42340
+ disable() {
42341
+ this.enabled = false;
42342
+ }
42343
+ enable() {
42344
+ this.enabled = true;
42345
+ }
42346
+ debug(...args) {
42347
+ if (this.enabled) {
42348
+ this.log(LogLevel2.Debug, ...args);
42349
+ }
42350
+ }
42351
+ info(...args) {
42352
+ if (this.enabled) {
42353
+ this.log(LogLevel2.Info, ...args);
42354
+ }
42355
+ }
42356
+ warn(...args) {
42357
+ if (this.enabled) {
42358
+ this.log(LogLevel2.Warn, ...args);
42359
+ }
42360
+ }
42361
+ error(...args) {
42362
+ if (this.enabled) {
42363
+ this.log(LogLevel2.Error, ...args);
42364
+ }
42365
+ }
42366
+ trace(...args) {
42367
+ if (this.enabled) {
42368
+ this.log(LogLevel2.Trace, ...args);
42369
+ }
42370
+ }
42371
+ };
42372
+ function createLogger4(log) {
42373
+ return new LoggerImpl(log);
42374
+ }
42375
+
42376
+ // src/pipeline/steps/VerificationStep.ts
42377
+ var import_fs15 = require("fs");
42378
+ var import_path21 = require("path");
42379
+ var CONTAINER_WORKSPACE_PATH = "/workspace";
42380
+ var VERIFY_SCRIPT_RELATIVE_PATH = ".fern/verify.sh";
42381
+ var VERIFY_SCRIPT_CONTAINER_PATH = `${CONTAINER_WORKSPACE_PATH}/${VERIFY_SCRIPT_RELATIVE_PATH}`;
42382
+ var VerificationStep = class extends BaseStep {
42383
+ constructor(outputDir, logger, config, generatorName, generatorVersions) {
42384
+ super(outputDir, logger);
42385
+ this.config = config;
42386
+ this.generatorName = generatorName;
42387
+ this.generatorVersions = generatorVersions;
42388
+ }
42389
+ config;
42390
+ generatorName;
42391
+ generatorVersions;
42392
+ name = "verify";
42393
+ async execute(_context) {
42394
+ const verifyScriptHostPath = (0, import_path21.join)(this.outputDir, VERIFY_SCRIPT_RELATIVE_PATH);
42395
+ if (!(0, import_fs15.existsSync)(verifyScriptHostPath)) {
42396
+ return { executed: true, success: true, skipped: true };
42397
+ }
42398
+ const validatorImage = this.deriveValidatorImage();
42399
+ if (validatorImage == null) {
42400
+ const message = "Cannot derive validator image: generatorName and generatorVersions are required to compute the `{generatorImage}-validator:{version}` tag.";
42401
+ this.logger.error(message);
42402
+ return {
42403
+ executed: true,
42404
+ success: false,
42405
+ skipped: false,
42406
+ errorMessage: message
42407
+ };
42408
+ }
42409
+ const runner = this.config.runner ?? "docker";
42410
+ const dockerLogger = createDockerLoggerAdapter(this.logger);
42411
+ let containerId;
42412
+ try {
42413
+ try {
42414
+ containerId = await startContainer({
42415
+ logger: dockerLogger,
42416
+ imageName: validatorImage,
42417
+ runner
42418
+ });
42419
+ } catch (error) {
42420
+ const message = `Failed to start verification container from image ${validatorImage}: ${extractErrorMessage(error)}`;
42421
+ this.logger.error(message);
42422
+ return {
42423
+ executed: true,
42424
+ success: false,
42425
+ skipped: false,
42426
+ errorMessage: message
42427
+ };
42428
+ }
42429
+ try {
42430
+ await copyToContainer({
42431
+ logger: dockerLogger,
42432
+ containerId,
42433
+ hostPath: `${this.outputDir}/.`,
42434
+ containerPath: CONTAINER_WORKSPACE_PATH,
42435
+ runner
42436
+ });
42437
+ } catch (error) {
42438
+ const message = `Failed to copy workspace into verification container: ${extractErrorMessage(error)}`;
42439
+ this.logger.error(message);
42440
+ return {
42441
+ executed: true,
42442
+ success: false,
42443
+ skipped: false,
42444
+ errorMessage: message
42445
+ };
42446
+ }
42447
+ const { stdout, stderr, exitCode } = await execInContainer({
42448
+ logger: dockerLogger,
42449
+ containerId,
42450
+ command: ["bash", VERIFY_SCRIPT_CONTAINER_PATH],
42451
+ runner,
42452
+ writeLogsToFile: false,
42453
+ reject: false
42454
+ });
42455
+ if (exitCode !== 0) {
42456
+ const capturedStderr = stderr.length > 0 ? stderr : stdout;
42457
+ this.logger.error(
42458
+ `Verification failed (exit code ${exitCode}) for image ${validatorImage}.
42459
+ ${capturedStderr}`
42460
+ );
42461
+ return {
42462
+ executed: true,
42463
+ success: false,
42464
+ skipped: false,
42465
+ stderr: capturedStderr,
42466
+ errorMessage: `Verification script exited with code ${exitCode}`
42467
+ };
42468
+ }
42469
+ this.logger.info(`Verification succeeded for image ${validatorImage}`);
42470
+ return { executed: true, success: true, skipped: false };
42471
+ } finally {
42472
+ if (containerId != null) {
42473
+ try {
42474
+ await stopContainer({ logger: dockerLogger, containerId, runner });
42475
+ } catch (error) {
42476
+ this.logger.debug(
42477
+ `Best-effort cleanup: failed to stop verification container ${containerId}: ${extractErrorMessage(error)}`
42478
+ );
42479
+ }
42480
+ }
42481
+ }
42482
+ }
42483
+ deriveValidatorImage() {
42484
+ if (this.generatorName == null) {
42485
+ return void 0;
42486
+ }
42487
+ const version2 = this.generatorVersions?.[this.generatorName];
42488
+ if (version2 == null) {
42489
+ return void 0;
42490
+ }
42491
+ return `${this.generatorName}-validator:${version2}`;
42492
+ }
42493
+ };
42494
+ function createDockerLoggerAdapter(pipelineLogger) {
42495
+ return createLogger4((level, ...args) => {
42496
+ const message = args.join(" ");
42497
+ switch (level) {
42498
+ case LogLevel2.Trace:
42499
+ case LogLevel2.Debug:
42500
+ pipelineLogger.debug(message);
42501
+ return;
42502
+ case LogLevel2.Info:
42503
+ pipelineLogger.info(message);
42504
+ return;
42505
+ case LogLevel2.Warn:
42506
+ pipelineLogger.warn(message);
42507
+ return;
42508
+ case LogLevel2.Error:
42509
+ pipelineLogger.error(message);
42510
+ return;
42511
+ }
42512
+ });
42513
+ }
42514
+
42209
42515
  // src/pipeline/PostGenerationPipeline.ts
42210
42516
  var PostGenerationPipeline = class {
42211
42517
  constructor(config, logger = consolePipelineLogger) {
@@ -42250,6 +42556,17 @@ var PostGenerationPipeline = class {
42250
42556
  )
42251
42557
  );
42252
42558
  }
42559
+ if (config.verify?.enabled) {
42560
+ this.steps.push(
42561
+ new VerificationStep(
42562
+ config.outputDir,
42563
+ this.logger,
42564
+ config.verify,
42565
+ config.generatorName,
42566
+ config.generatorVersions
42567
+ )
42568
+ );
42569
+ }
42253
42570
  if (config.github?.enabled) {
42254
42571
  this.steps.push(new GithubStep(config.outputDir, this.logger, config.github));
42255
42572
  }
@@ -42288,12 +42605,25 @@ var PostGenerationPipeline = class {
42288
42605
  pipelineContext.previousStepResults.autoVersion = stepResult;
42289
42606
  } else if (step.name === "fernignore") {
42290
42607
  result.steps.fernignore = stepResult;
42608
+ } else if (step.name === "verify") {
42609
+ const verifyResult = stepResult;
42610
+ result.steps.verify = verifyResult;
42611
+ pipelineContext.previousStepResults.verify = verifyResult;
42291
42612
  } else if (step.name === "github") {
42292
42613
  result.steps.github = stepResult;
42293
42614
  }
42294
42615
  if (!stepResult.success) {
42295
42616
  result.success = false;
42296
42617
  result.errors = result.errors ?? [];
42618
+ if (step.name === "verify") {
42619
+ const verifyResult = stepResult;
42620
+ if (verifyResult.stderr != null && verifyResult.stderr.length > 0) {
42621
+ result.errors.push(verifyResult.stderr);
42622
+ } else {
42623
+ result.errors.push(verifyResult.errorMessage ?? `${step.name} step failed`);
42624
+ }
42625
+ break;
42626
+ }
42297
42627
  result.errors.push(stepResult.errorMessage ?? `${step.name} step failed`);
42298
42628
  }
42299
42629
  } catch (error) {
@@ -42301,6 +42631,9 @@ var PostGenerationPipeline = class {
42301
42631
  result.errors = result.errors ?? [];
42302
42632
  const errorMessage = extractErrorMessage(error);
42303
42633
  result.errors.push(`${step.name} step error: ${errorMessage}`);
42634
+ if (step.name === "verify") {
42635
+ break;
42636
+ }
42304
42637
  }
42305
42638
  }
42306
42639
  return result;
@@ -42331,7 +42664,7 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
42331
42664
  const readmeConfig = await loadReadmeConfig({
42332
42665
  absolutePathToConfig: resolve(wd, argv.config)
42333
42666
  });
42334
- const originalReadmeContent = argv.originalReadme != null ? await (0, import_promises15.readFile)(argv.originalReadme, "utf8") : void 0;
42667
+ const originalReadmeContent = argv.originalReadme != null ? await (0, import_promises16.readFile)(argv.originalReadme, "utf8") : void 0;
42335
42668
  await generateReadmeToStream({
42336
42669
  originalReadmeContent,
42337
42670
  readmeConfig,
@@ -42459,7 +42792,7 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
42459
42792
  try {
42460
42793
  const wd = cwd();
42461
42794
  const configValue = argv.config;
42462
- const configContent = configValue === STDIN_MARKER ? await readStdin() : configValue.trimStart().startsWith("{") ? configValue : await (0, import_promises15.readFile)(resolve(wd, configValue), "utf-8");
42795
+ const configContent = configValue === STDIN_MARKER ? await readStdin() : configValue.trimStart().startsWith("{") ? configValue : await (0, import_promises16.readFile)(resolve(wd, configValue), "utf-8");
42463
42796
  let config;
42464
42797
  try {
42465
42798
  config = JSON.parse(configContent);
@@ -42755,9 +43088,9 @@ async function createWriteStream(outputPath) {
42755
43088
  }
42756
43089
  async function createWriteStreamFromFile(filepath) {
42757
43090
  if (!await doesPathExist(filepath)) {
42758
- await (0, import_promises15.mkdir)(import_path21.default.dirname(filepath), { recursive: true });
43091
+ await (0, import_promises16.mkdir)(import_path22.default.dirname(filepath), { recursive: true });
42759
43092
  }
42760
- return import_fs15.default.createWriteStream(filepath);
43093
+ return import_fs16.default.createWriteStream(filepath);
42761
43094
  }
42762
43095
  /*! Bundled license information:
42763
43096
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fern-api/generator-cli",
3
- "version": "0.9.26",
3
+ "version": "0.9.28",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/fern-api/fern.git",