@eldrforge/kodrdriv 1.2.14 → 1.2.17

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.
@@ -10,6 +10,7 @@ import { calculateBranchDependentVersion, calculateTargetVersion, checkIfTagExis
10
10
  import { DEFAULT_OUTPUT_DIRECTORY, KODRDRIV_DEFAULTS } from '../constants.js';
11
11
  import { safeJsonParse, validatePackageJson } from '../util/validation.js';
12
12
  import { localBranchExists, safeSyncBranchWithRemote, isBranchInSyncWithRemote } from '../util/git.js';
13
+ import fs__default from 'fs/promises';
13
14
 
14
15
  const scanNpmrcForEnvVars = async (storage)=>{
15
16
  const logger = getLogger();
@@ -38,6 +39,76 @@ const scanNpmrcForEnvVars = async (storage)=>{
38
39
  }
39
40
  return envVars;
40
41
  };
42
+ /**
43
+ * Checks if package-lock.json contains file: dependencies (from npm link)
44
+ * and cleans them up if found by removing package-lock.json and regenerating it.
45
+ */ const cleanupNpmLinkReferences = async (isDryRun)=>{
46
+ const logger = getDryRunLogger(isDryRun);
47
+ const packageLockPath = path__default.join(process.cwd(), 'package-lock.json');
48
+ try {
49
+ // Check if package-lock.json exists
50
+ try {
51
+ await fs__default.access(packageLockPath);
52
+ } catch {
53
+ // No package-lock.json, nothing to clean
54
+ logger.verbose('No package-lock.json found, skipping npm link cleanup');
55
+ return;
56
+ }
57
+ // Read and parse package-lock.json
58
+ const packageLockContent = await fs__default.readFile(packageLockPath, 'utf-8');
59
+ const packageLock = safeJsonParse(packageLockContent, packageLockPath);
60
+ // Check for file: dependencies in the lockfile
61
+ let hasFileReferences = false;
62
+ // Check in packages (npm v7+)
63
+ if (packageLock.packages) {
64
+ for (const [pkgPath, pkgInfo] of Object.entries(packageLock.packages)){
65
+ if (pkgInfo.resolved && typeof pkgInfo.resolved === 'string' && pkgInfo.resolved.startsWith('file:')) {
66
+ // Check if it's a relative path (from npm link) rather than a workspace path
67
+ const resolvedPath = pkgInfo.resolved.replace('file:', '');
68
+ if (resolvedPath.startsWith('../') || resolvedPath.startsWith('./')) {
69
+ hasFileReferences = true;
70
+ logger.verbose(`Found npm link reference: ${pkgPath} -> ${pkgInfo.resolved}`);
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ // Check in dependencies (npm v6)
77
+ if (!hasFileReferences && packageLock.dependencies) {
78
+ for (const [pkgName, pkgInfo] of Object.entries(packageLock.dependencies)){
79
+ if (pkgInfo.version && typeof pkgInfo.version === 'string' && pkgInfo.version.startsWith('file:')) {
80
+ const versionPath = pkgInfo.version.replace('file:', '');
81
+ if (versionPath.startsWith('../') || versionPath.startsWith('./')) {
82
+ hasFileReferences = true;
83
+ logger.verbose(`Found npm link reference: ${pkgName} -> ${pkgInfo.version}`);
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ }
89
+ if (hasFileReferences) {
90
+ logger.info('⚠️ Detected npm link references in package-lock.json');
91
+ logger.info('🧹 Cleaning up package-lock.json to remove relative file: dependencies...');
92
+ if (isDryRun) {
93
+ logger.info('DRY RUN: Would remove package-lock.json and regenerate it');
94
+ } else {
95
+ // Remove package-lock.json
96
+ await fs__default.unlink(packageLockPath);
97
+ logger.verbose('Removed package-lock.json with npm link references');
98
+ // Regenerate clean package-lock.json
99
+ logger.verbose('Regenerating package-lock.json from package.json...');
100
+ await runWithDryRunSupport('npm install --package-lock-only --no-audit --no-fund', isDryRun);
101
+ logger.info('✅ Regenerated clean package-lock.json');
102
+ }
103
+ } else {
104
+ logger.verbose('No npm link references found in package-lock.json');
105
+ }
106
+ } catch (error) {
107
+ // Log warning but don't fail - let npm update handle any issues
108
+ logger.warn(`⚠️ Failed to check/clean npm link references: ${error.message}`);
109
+ logger.verbose('Continuing with publish process...');
110
+ }
111
+ };
41
112
  const validateEnvironmentVariables = (requiredEnvVars, isDryRun)=>{
42
113
  const logger = getDryRunLogger(isDryRun);
43
114
  const missingEnvVars = [];
@@ -450,6 +521,9 @@ const execute = async (runConfig)=>{
450
521
  logger.info('No open pull request found, starting new release publishing process...');
451
522
  // STEP 1: Prepare for release (update dependencies and run prepublish checks) with NO version bump yet
452
523
  logger.verbose('Preparing for release: switching from workspace to remote dependencies.');
524
+ // Clean up any npm link references before updating dependencies
525
+ logger.verbose('Checking for npm link references in package-lock.json...');
526
+ await cleanupNpmLinkReferences(isDryRun);
453
527
  logger.verbose('Updating dependencies to latest versions from registry');
454
528
  const updatePatterns = (_runConfig_publish4 = runConfig.publish) === null || _runConfig_publish4 === void 0 ? void 0 : _runConfig_publish4.dependencyUpdatePatterns;
455
529
  if (updatePatterns && updatePatterns.length > 0) {
@@ -999,7 +1073,7 @@ const execute = async (runConfig)=>{
999
1073
  }
1000
1074
  // Switch back to source branch and sync with target
1001
1075
  logger.info('');
1002
- logger.info('🔄 Syncing source branch with target after publish...');
1076
+ logger.info(`🔄 Syncing source branch with target after publish...`);
1003
1077
  await runWithDryRunSupport(`git checkout ${currentBranch}`, isDryRun);
1004
1078
  if (!isDryRun) {
1005
1079
  // Merge target into source (should be fast-forward since PR just merged)