@eldrforge/kodrdriv 1.2.20 → 1.2.21

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.
@@ -2,7 +2,7 @@
2
2
  import path__default from 'path';
3
3
  import fs__default from 'fs/promises';
4
4
  import { exec } from 'child_process';
5
- import { safeJsonParse, validatePackageJson, getGloballyLinkedPackages, getGitStatusSummary, getLinkedDependencies, getLinkCompatibilityProblems, runSecure } from '@eldrforge/git-tools';
5
+ import { safeJsonParse, validatePackageJson, getGloballyLinkedPackages, getGitStatusSummary, getLinkedDependencies, getLinkCompatibilityProblems, runSecure, run } from '@eldrforge/git-tools';
6
6
  import util from 'util';
7
7
  import { getLogger } from '../logging.js';
8
8
  import { create } from '../util/storage.js';
@@ -305,19 +305,48 @@ const validateScripts = async (packages, scripts)=>{
305
305
  missingScripts
306
306
  };
307
307
  };
308
- // Extract published version from package.json after successful publish
308
+ // Extract published version from git tags after successful publish
309
+ // After kodrdriv publish, the release version is captured in the git tag,
310
+ // while package.json contains the next dev version
309
311
  const extractPublishedVersion = async (packageDir, packageLogger)=>{
310
312
  const storage = create({
311
313
  log: packageLogger.info
312
314
  });
313
315
  const packageJsonPath = path__default.join(packageDir, 'package.json');
314
316
  try {
317
+ // Get package name from package.json
315
318
  const packageJsonContent = await storage.readFile(packageJsonPath, 'utf-8');
316
319
  const parsed = safeJsonParse(packageJsonContent, packageJsonPath);
317
320
  const packageJson = validatePackageJson(parsed, packageJsonPath);
321
+ // Get the most recently created tag (by creation date, not version number)
322
+ // This ensures we get the tag that was just created by the publish, not an older tag with a higher version
323
+ const { stdout: tagOutput } = await run('git tag --sort=-creatordate', {
324
+ cwd: packageDir
325
+ });
326
+ const tags = tagOutput.trim().split('\n').filter(Boolean);
327
+ if (tags.length === 0) {
328
+ packageLogger.warn('No git tags found after publish');
329
+ return null;
330
+ }
331
+ // Get the most recently created tag (first in the list)
332
+ const latestTag = tags[0];
333
+ // Extract version from tag, handling various formats:
334
+ // - v1.2.3 -> 1.2.3
335
+ // - working/v1.2.3 -> 1.2.3
336
+ // - main/v1.2.3 -> 1.2.3
337
+ let version = latestTag;
338
+ // If tag contains a slash (branch prefix), extract everything after it
339
+ if (version.includes('/')) {
340
+ version = version.split('/').pop() || version;
341
+ }
342
+ // Remove 'v' prefix if present
343
+ if (version.startsWith('v')) {
344
+ version = version.substring(1);
345
+ }
346
+ packageLogger.verbose(`Extracted published version from tag: ${latestTag} -> ${version}`);
318
347
  return {
319
348
  packageName: packageJson.name,
320
- version: packageJson.version,
349
+ version: version,
321
350
  publishTime: new Date()
322
351
  };
323
352
  } catch (error) {