@eldrforge/kodrdriv 1.2.4 → 1.2.6

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.
@@ -7,7 +7,7 @@ import { runWithDryRunSupport, run, validateGitRef, runSecure } from '../util/ch
7
7
  import { getCurrentBranchName, findOpenPullRequestByHeadRef, createPullRequest, waitForPullRequestChecks, mergePullRequest, createRelease, closeMilestoneForVersion, getWorkflowsTriggeredByRelease, waitForReleaseWorkflows } from '../util/github.js';
8
8
  import { create } from '../util/storage.js';
9
9
  import { calculateTargetVersion, checkIfTagExists, confirmVersionInteractively, getOutputPath } from '../util/general.js';
10
- import { DEFAULT_OUTPUT_DIRECTORY } from '../constants.js';
10
+ import { DEFAULT_OUTPUT_DIRECTORY, KODRDRIV_DEFAULTS } from '../constants.js';
11
11
  import { safeJsonParse, validatePackageJson } from '../util/validation.js';
12
12
  import { safeSyncBranchWithRemote, localBranchExists, isBranchInSyncWithRemote } from '../util/git.js';
13
13
 
@@ -189,6 +189,85 @@ const runPrechecks = async (runConfig)=>{
189
189
  }
190
190
  logger.info('All prechecks passed.');
191
191
  };
192
+ // Helper: deep-sort object keys for stable comparison
193
+ const sortObjectKeys = (value)=>{
194
+ if (Array.isArray(value)) {
195
+ return value.map(sortObjectKeys);
196
+ }
197
+ if (value && typeof value === 'object') {
198
+ const sorted = {};
199
+ Object.keys(value).sort().forEach((key)=>{
200
+ sorted[key] = sortObjectKeys(value[key]);
201
+ });
202
+ return sorted;
203
+ }
204
+ return value;
205
+ };
206
+ // Determine if there are substantive changes compared to the target branch (beyond just version bump)
207
+ const isReleaseNecessaryComparedToTarget = async (targetBranch, isDryRun)=>{
208
+ const logger = getDryRunLogger(isDryRun);
209
+ // We compare current HEAD branch to the provided target branch
210
+ const currentBranch = await getCurrentBranchName();
211
+ // If branches are identical, nothing to release
212
+ const { stdout: namesStdout } = await runSecure('git', [
213
+ 'diff',
214
+ '--name-only',
215
+ `${targetBranch}..${currentBranch}`
216
+ ]);
217
+ const changedFiles = namesStdout.split('\n').map((s)=>s.trim()).filter(Boolean);
218
+ if (changedFiles.length === 0) {
219
+ // No definitive signal; proceed with publish rather than skipping
220
+ return {
221
+ necessary: true,
222
+ reason: 'No detectable changes via diff; proceeding conservatively'
223
+ };
224
+ }
225
+ // If any files changed other than package.json or package-lock.json, a release is necessary
226
+ const nonVersionFiles = changedFiles.filter((f)=>f !== 'package.json' && f !== 'package-lock.json');
227
+ if (nonVersionFiles.length > 0) {
228
+ return {
229
+ necessary: true,
230
+ reason: `Changed files beyond version bump: ${nonVersionFiles.join(', ')}`
231
+ };
232
+ }
233
+ // Only package.json and/or package-lock.json changed. Verify package.json change is only the version field
234
+ try {
235
+ // Read package.json content from both branches
236
+ const { stdout: basePkgStdout } = await runSecure('git', [
237
+ 'show',
238
+ `${targetBranch}:package.json`
239
+ ]);
240
+ const { stdout: headPkgStdout } = await runSecure('git', [
241
+ 'show',
242
+ `${currentBranch}:package.json`
243
+ ]);
244
+ const basePkg = validatePackageJson(safeJsonParse(basePkgStdout, `${targetBranch}:package.json`), `${targetBranch}:package.json`);
245
+ const headPkg = validatePackageJson(safeJsonParse(headPkgStdout, `${currentBranch}:package.json`), `${currentBranch}:package.json`);
246
+ const { version: _baseVersion, ...baseWithoutVersion } = basePkg;
247
+ const { version: _headVersion, ...headWithoutVersion } = headPkg;
248
+ const baseSorted = sortObjectKeys(baseWithoutVersion);
249
+ const headSorted = sortObjectKeys(headWithoutVersion);
250
+ const equalExceptVersion = JSON.stringify(baseSorted) === JSON.stringify(headSorted);
251
+ if (equalExceptVersion) {
252
+ return {
253
+ necessary: false,
254
+ reason: 'Only version changed in package.json (plus lockfile)'
255
+ };
256
+ }
257
+ // Other fields changed inside package.json
258
+ return {
259
+ necessary: true,
260
+ reason: 'package.json changes beyond version field'
261
+ };
262
+ } catch (error) {
263
+ // Conservative: if we cannot prove it is only a version change, proceed with release
264
+ logger.verbose(`Could not conclusively compare package.json changes: ${error.message}`);
265
+ return {
266
+ necessary: true,
267
+ reason: 'Could not compare package.json safely'
268
+ };
269
+ }
270
+ };
192
271
  const handleTargetBranchSyncRecovery = async (runConfig)=>{
193
272
  var _runConfig_publish;
194
273
  const isDryRun = runConfig.dryRun || false;
@@ -233,6 +312,22 @@ const execute = async (runConfig)=>{
233
312
  }
234
313
  // Run prechecks before starting any work
235
314
  await runPrechecks(runConfig);
315
+ // Early check: determine if a release is necessary compared to target branch
316
+ logger.info('Evaluating if a release is necessary compared to target branch...');
317
+ try {
318
+ const necessity = await isReleaseNecessaryComparedToTarget(targetBranch, isDryRun);
319
+ if (!necessity.necessary) {
320
+ logger.info(`Skipping publish: ${necessity.reason}.`);
321
+ // Emit a machine-readable marker so tree mode can detect skip and avoid propagating versions
322
+ logger.info('KODRDRIV_PUBLISH_SKIPPED');
323
+ return;
324
+ } else {
325
+ logger.verbose(`Proceeding with publish: ${necessity.reason}.`);
326
+ }
327
+ } catch (error) {
328
+ // On unexpected errors, proceed with publish to avoid false negatives blocking releases
329
+ logger.verbose(`Release necessity check encountered an issue (${error.message}). Proceeding with publish.`);
330
+ }
236
331
  logger.info('Starting release process...');
237
332
  let pr = null;
238
333
  if (isDryRun) {
@@ -245,33 +340,57 @@ const execute = async (runConfig)=>{
245
340
  if (pr) {
246
341
  logger.info(`Found existing pull request for branch: ${pr.html_url}`);
247
342
  } else {
248
- var _runConfig_publish4, _runConfig_publish5, _runConfig_publish6;
343
+ var _runConfig_publish4, _runConfig_publish5, _runConfig_publish6, _runConfig_publish7;
249
344
  logger.info('No open pull request found, starting new release publishing process...');
250
- // STEP 1: Determine and set target version FIRST (before any commits)
345
+ // STEP 1: Prepare for release (update dependencies and run prepublish checks) with NO version bump yet
346
+ logger.verbose('Preparing for release: switching from workspace to remote dependencies.');
347
+ logger.verbose('Updating dependencies to latest versions from registry');
348
+ const updatePatterns = (_runConfig_publish4 = runConfig.publish) === null || _runConfig_publish4 === void 0 ? void 0 : _runConfig_publish4.dependencyUpdatePatterns;
349
+ if (updatePatterns && updatePatterns.length > 0) {
350
+ logger.verbose(`Updating dependencies matching patterns: ${updatePatterns.join(', ')}`);
351
+ const patternsArg = updatePatterns.join(' ');
352
+ await runWithDryRunSupport(`npm update ${patternsArg}`, isDryRun);
353
+ } else {
354
+ logger.verbose('No dependency update patterns specified, updating all dependencies');
355
+ await runWithDryRunSupport('npm update', isDryRun);
356
+ }
357
+ logger.info('Running prepublishOnly script...');
358
+ await runWithDryRunSupport('npm run prepublishOnly', isDryRun, {}, true); // Use inherited stdio
359
+ // STEP 2: Commit dependency updates if any (still no version bump)
360
+ logger.verbose('Staging dependency updates for commit');
361
+ await runWithDryRunSupport('git add package.json package-lock.json', isDryRun);
362
+ logger.verbose('Checking for staged dependency updates...');
363
+ if (isDryRun) {
364
+ logger.verbose('Would create dependency update commit if changes are staged');
365
+ } else {
366
+ if (await hasStagedChanges()) {
367
+ logger.verbose('Staged dependency changes found, creating commit...');
368
+ await execute$1(runConfig);
369
+ } else {
370
+ logger.verbose('No dependency changes to commit, skipping commit.');
371
+ }
372
+ }
373
+ // STEP 3: Determine and set target version AFTER checks and dependency commit
251
374
  logger.info('Determining target version...');
252
375
  let newVersion;
253
376
  if (isDryRun) {
254
377
  logger.info('Would determine target version and update package.json');
255
378
  newVersion = '1.0.0'; // Mock version for dry run
256
379
  } else {
257
- var _runConfig_publish7, _runConfig_publish8;
380
+ var _runConfig_publish8, _runConfig_publish9;
258
381
  const packageJsonContents = await storage.readFile('package.json', 'utf-8');
259
382
  const parsed = safeJsonParse(packageJsonContents, 'package.json');
260
383
  const packageJson = validatePackageJson(parsed, 'package.json');
261
384
  const currentVersion = packageJson.version;
262
- // Determine target version based on --targetVersion option
263
- const targetVersionInput = ((_runConfig_publish7 = runConfig.publish) === null || _runConfig_publish7 === void 0 ? void 0 : _runConfig_publish7.targetVersion) || 'patch';
385
+ const targetVersionInput = ((_runConfig_publish8 = runConfig.publish) === null || _runConfig_publish8 === void 0 ? void 0 : _runConfig_publish8.targetVersion) || 'patch';
264
386
  const proposedVersion = calculateTargetVersion(currentVersion, targetVersionInput);
265
- // Check if target tag already exists
266
387
  const targetTagName = `v${proposedVersion}`;
267
388
  const tagExists = await checkIfTagExists(targetTagName);
268
389
  if (tagExists) {
269
390
  throw new Error(`Tag ${targetTagName} already exists. Please choose a different version or delete the existing tag.`);
270
391
  }
271
- // Interactive confirmation if --interactive flag is set
272
- if ((_runConfig_publish8 = runConfig.publish) === null || _runConfig_publish8 === void 0 ? void 0 : _runConfig_publish8.interactive) {
392
+ if ((_runConfig_publish9 = runConfig.publish) === null || _runConfig_publish9 === void 0 ? void 0 : _runConfig_publish9.interactive) {
273
393
  newVersion = await confirmVersionInteractively(currentVersion, proposedVersion, targetVersionInput);
274
- // Re-check if the confirmed version's tag exists (in case user entered custom version)
275
394
  const confirmedTagName = `v${newVersion}`;
276
395
  const confirmedTagExists = await checkIfTagExists(confirmedTagName);
277
396
  if (confirmedTagExists) {
@@ -281,48 +400,30 @@ const execute = async (runConfig)=>{
281
400
  newVersion = proposedVersion;
282
401
  }
283
402
  logger.info(`Bumping version from ${currentVersion} to ${newVersion}`);
284
- // Update package.json with the new version BEFORE any other operations
285
403
  packageJson.version = newVersion;
286
404
  await storage.writeFile('package.json', JSON.stringify(packageJson, null, 2) + '\n', 'utf-8');
287
405
  logger.info(`Version updated in package.json: ${newVersion}`);
288
406
  }
289
- // STEP 2: Prepare for release (with correct version now in package.json)
290
- logger.verbose('Preparing for release: switching from workspace to remote dependencies.');
291
- logger.verbose('Updating dependencies to latest versions from registry');
292
- const updatePatterns = (_runConfig_publish4 = runConfig.publish) === null || _runConfig_publish4 === void 0 ? void 0 : _runConfig_publish4.dependencyUpdatePatterns;
293
- if (updatePatterns && updatePatterns.length > 0) {
294
- logger.verbose(`Updating dependencies matching patterns: ${updatePatterns.join(', ')}`);
295
- const patternsArg = updatePatterns.join(' ');
296
- await runWithDryRunSupport(`npm update ${patternsArg}`, isDryRun);
297
- } else {
298
- logger.verbose('No dependency update patterns specified, updating all dependencies');
299
- await runWithDryRunSupport('npm update', isDryRun);
300
- }
301
- logger.info('Running prepublishOnly script...');
302
- await runWithDryRunSupport('npm run prepublishOnly', isDryRun, {}, true); // Use inherited stdio
303
- // STEP 3: Stage all changes (version bump + dependencies + any build artifacts)
304
- logger.verbose('Staging all changes for release commit');
407
+ // STEP 4: Commit version bump as a separate commit
408
+ logger.verbose('Staging version bump for commit');
305
409
  await runWithDryRunSupport('git add package.json package-lock.json', isDryRun);
306
- logger.verbose('Checking for staged changes...');
307
410
  if (isDryRun) {
308
- logger.verbose('Assuming staged changes exist for demo purposes');
309
- logger.verbose('Would create commit...');
310
- await execute$1(runConfig);
411
+ logger.verbose('Would create version bump commit');
311
412
  } else {
312
413
  if (await hasStagedChanges()) {
313
- logger.verbose('Staged changes found, creating commit...');
414
+ logger.verbose('Creating version bump commit...');
314
415
  await execute$1(runConfig);
315
416
  } else {
316
- logger.verbose('No changes to commit, skipping commit.');
417
+ logger.verbose('No version changes to commit.');
317
418
  }
318
419
  }
319
420
  logger.info('Generating release notes...');
320
- // Create a modified config for release notes generation that includes the publish --from and --interactive options
421
+ // Create a modified config for release notes generation that includes the publish --from, --interactive, and --from-main options
321
422
  const releaseConfig = {
322
423
  ...runConfig
323
424
  };
324
- if (((_runConfig_publish5 = runConfig.publish) === null || _runConfig_publish5 === void 0 ? void 0 : _runConfig_publish5.from) || ((_runConfig_publish6 = runConfig.publish) === null || _runConfig_publish6 === void 0 ? void 0 : _runConfig_publish6.interactive)) {
325
- // Pass the publish --from and --interactive options to the release config
425
+ if (((_runConfig_publish5 = runConfig.publish) === null || _runConfig_publish5 === void 0 ? void 0 : _runConfig_publish5.from) || ((_runConfig_publish6 = runConfig.publish) === null || _runConfig_publish6 === void 0 ? void 0 : _runConfig_publish6.interactive) || ((_runConfig_publish7 = runConfig.publish) === null || _runConfig_publish7 === void 0 ? void 0 : _runConfig_publish7.fromMain)) {
426
+ // Pass the publish options to the release config
326
427
  releaseConfig.release = {
327
428
  ...runConfig.release,
328
429
  ...runConfig.publish.from && {
@@ -330,6 +431,9 @@ const execute = async (runConfig)=>{
330
431
  },
331
432
  ...runConfig.publish.interactive && {
332
433
  interactive: runConfig.publish.interactive
434
+ },
435
+ ...runConfig.publish.fromMain && {
436
+ fromMain: runConfig.publish.fromMain
333
437
  }
334
438
  };
335
439
  if (runConfig.publish.from) {
@@ -338,6 +442,9 @@ const execute = async (runConfig)=>{
338
442
  if (runConfig.publish.interactive) {
339
443
  logger.verbose('Interactive mode enabled for release notes generation');
340
444
  }
445
+ if (runConfig.publish.fromMain) {
446
+ logger.verbose('Forcing comparison against main branch for release notes');
447
+ }
341
448
  }
342
449
  const releaseSummary = await execute$2(releaseConfig);
343
450
  if (isDryRun) {
@@ -374,12 +481,12 @@ const execute = async (runConfig)=>{
374
481
  }
375
482
  logger.info(`Waiting for PR #${pr.number} checks to complete...`);
376
483
  if (!isDryRun) {
377
- var _runConfig_publish9, _runConfig_publish10, _runConfig_publish11;
484
+ var _runConfig_publish10, _runConfig_publish11, _runConfig_publish12;
378
485
  // Configure timeout and user confirmation behavior
379
- const timeout = ((_runConfig_publish9 = runConfig.publish) === null || _runConfig_publish9 === void 0 ? void 0 : _runConfig_publish9.checksTimeout) || 300000; // 5 minutes default
380
- const senditMode = ((_runConfig_publish10 = runConfig.publish) === null || _runConfig_publish10 === void 0 ? void 0 : _runConfig_publish10.sendit) || false;
486
+ const timeout = ((_runConfig_publish10 = runConfig.publish) === null || _runConfig_publish10 === void 0 ? void 0 : _runConfig_publish10.checksTimeout) || KODRDRIV_DEFAULTS.publish.checksTimeout;
487
+ const senditMode = ((_runConfig_publish11 = runConfig.publish) === null || _runConfig_publish11 === void 0 ? void 0 : _runConfig_publish11.sendit) || false;
381
488
  // sendit flag overrides skipUserConfirmation - if sendit is true, skip confirmation
382
- const skipUserConfirmation = senditMode || ((_runConfig_publish11 = runConfig.publish) === null || _runConfig_publish11 === void 0 ? void 0 : _runConfig_publish11.skipUserConfirmation) || false;
489
+ const skipUserConfirmation = senditMode || ((_runConfig_publish12 = runConfig.publish) === null || _runConfig_publish12 === void 0 ? void 0 : _runConfig_publish12.skipUserConfirmation) || false;
383
490
  await waitForPullRequestChecks(pr.number, {
384
491
  timeout,
385
492
  skipUserConfirmation
@@ -517,9 +624,9 @@ const execute = async (runConfig)=>{
517
624
  }
518
625
  logger.info('Creating GitHub release...');
519
626
  if (isDryRun) {
520
- var _runConfig_publish12;
627
+ var _runConfig_publish13;
521
628
  logger.info('Would read package.json version and create GitHub release with retry logic');
522
- const milestonesEnabled = !((_runConfig_publish12 = runConfig.publish) === null || _runConfig_publish12 === void 0 ? void 0 : _runConfig_publish12.noMilestones);
629
+ const milestonesEnabled = !((_runConfig_publish13 = runConfig.publish) === null || _runConfig_publish13 === void 0 ? void 0 : _runConfig_publish13.noMilestones);
523
630
  if (milestonesEnabled) {
524
631
  logger.info('Would close milestone for released version');
525
632
  } else {
@@ -535,11 +642,11 @@ const execute = async (runConfig)=>{
535
642
  let retries = 3;
536
643
  while(retries > 0){
537
644
  try {
538
- var _runConfig_publish13;
645
+ var _runConfig_publish14;
539
646
  await createRelease(tagName, releaseTitle, releaseNotesContent);
540
647
  logger.info(`GitHub release created successfully for tag: ${tagName}`);
541
648
  // Close milestone for this version if enabled
542
- const milestonesEnabled = !((_runConfig_publish13 = runConfig.publish) === null || _runConfig_publish13 === void 0 ? void 0 : _runConfig_publish13.noMilestones);
649
+ const milestonesEnabled = !((_runConfig_publish14 = runConfig.publish) === null || _runConfig_publish14 === void 0 ? void 0 : _runConfig_publish14.noMilestones);
543
650
  if (milestonesEnabled) {
544
651
  logger.info('🏁 Closing milestone for released version...');
545
652
  const version = tagName.replace(/^v/, ''); // Remove 'v' prefix if present
@@ -572,12 +679,12 @@ const execute = async (runConfig)=>{
572
679
  if (isDryRun) {
573
680
  logger.info('Would monitor GitHub Actions workflows triggered by release');
574
681
  } else {
575
- var _runConfig_publish14, _runConfig_publish15, _runConfig_publish16, _runConfig_publish17;
576
- const workflowTimeout = ((_runConfig_publish14 = runConfig.publish) === null || _runConfig_publish14 === void 0 ? void 0 : _runConfig_publish14.releaseWorkflowsTimeout) || 600000; // 10 minutes default
577
- const senditMode = ((_runConfig_publish15 = runConfig.publish) === null || _runConfig_publish15 === void 0 ? void 0 : _runConfig_publish15.sendit) || false;
578
- const skipUserConfirmation = senditMode || ((_runConfig_publish16 = runConfig.publish) === null || _runConfig_publish16 === void 0 ? void 0 : _runConfig_publish16.skipUserConfirmation) || false;
682
+ var _runConfig_publish15, _runConfig_publish16, _runConfig_publish17, _runConfig_publish18;
683
+ const workflowTimeout = ((_runConfig_publish15 = runConfig.publish) === null || _runConfig_publish15 === void 0 ? void 0 : _runConfig_publish15.releaseWorkflowsTimeout) || KODRDRIV_DEFAULTS.publish.releaseWorkflowsTimeout;
684
+ const senditMode = ((_runConfig_publish16 = runConfig.publish) === null || _runConfig_publish16 === void 0 ? void 0 : _runConfig_publish16.sendit) || false;
685
+ const skipUserConfirmation = senditMode || ((_runConfig_publish17 = runConfig.publish) === null || _runConfig_publish17 === void 0 ? void 0 : _runConfig_publish17.skipUserConfirmation) || false;
579
686
  // Get workflow names - either from config or auto-detect
580
- let workflowNames = (_runConfig_publish17 = runConfig.publish) === null || _runConfig_publish17 === void 0 ? void 0 : _runConfig_publish17.releaseWorkflowNames;
687
+ let workflowNames = (_runConfig_publish18 = runConfig.publish) === null || _runConfig_publish18 === void 0 ? void 0 : _runConfig_publish18.releaseWorkflowNames;
581
688
  if (!workflowNames || workflowNames.length === 0) {
582
689
  logger.info('No specific workflow names configured, auto-detecting workflows triggered by release events...');
583
690
  try {