@bobfrankston/npmglobalize 1.0.124 → 1.0.126
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/lib.js +53 -0
- package/package.json +1 -1
package/lib.js
CHANGED
|
@@ -681,6 +681,55 @@ function hasUnpublishedTransitiveDeps(packageName, pkg, baseDir, verbose) {
|
|
|
681
681
|
}
|
|
682
682
|
return false;
|
|
683
683
|
}
|
|
684
|
+
/** Check if local package directory has changes newer than the npm-published version.
|
|
685
|
+
* Detects uncommitted changes or commits made after the version was published. */
|
|
686
|
+
function hasLocalChanges(packageName, version, targetPath, verbose) {
|
|
687
|
+
try {
|
|
688
|
+
// Check 1: Uncommitted changes in the package directory
|
|
689
|
+
const statusResult = spawnSafe('git', ['-C', targetPath, 'status', '--porcelain', '.'], {
|
|
690
|
+
encoding: 'utf-8',
|
|
691
|
+
stdio: 'pipe',
|
|
692
|
+
shell: true
|
|
693
|
+
});
|
|
694
|
+
if (statusResult.status === 0 && statusResult.stdout.trim()) {
|
|
695
|
+
if (verbose) {
|
|
696
|
+
console.log(colors.yellow(` ${packageName} has uncommitted changes`));
|
|
697
|
+
}
|
|
698
|
+
return true;
|
|
699
|
+
}
|
|
700
|
+
// Check 2: Compare latest commit time in directory vs npm publish time
|
|
701
|
+
const timeResult = spawnSafe('npm', ['view', packageName, 'time', '--json'], {
|
|
702
|
+
encoding: 'utf-8',
|
|
703
|
+
stdio: 'pipe',
|
|
704
|
+
shell: true
|
|
705
|
+
});
|
|
706
|
+
if (timeResult.status !== 0 || !timeResult.stdout.trim())
|
|
707
|
+
return false;
|
|
708
|
+
const times = JSON.parse(timeResult.stdout.trim());
|
|
709
|
+
const publishTime = times[version];
|
|
710
|
+
if (!publishTime)
|
|
711
|
+
return false;
|
|
712
|
+
const publishDate = new Date(publishTime);
|
|
713
|
+
const logResult = spawnSafe('git', ['-C', targetPath, 'log', '-1', '--format=%aI', '--', '.'], {
|
|
714
|
+
encoding: 'utf-8',
|
|
715
|
+
stdio: 'pipe',
|
|
716
|
+
shell: true
|
|
717
|
+
});
|
|
718
|
+
if (logResult.status !== 0 || !logResult.stdout.trim())
|
|
719
|
+
return false;
|
|
720
|
+
const latestCommitDate = new Date(logResult.stdout.trim());
|
|
721
|
+
if (latestCommitDate > publishDate) {
|
|
722
|
+
if (verbose) {
|
|
723
|
+
console.log(colors.yellow(` ${packageName} has commits newer than npm publish`));
|
|
724
|
+
}
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
catch {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
684
733
|
/** Transform file: dependencies to npm versions */
|
|
685
734
|
export function transformDeps(pkg, baseDir, verbose = false, forcePublish = false) {
|
|
686
735
|
let transformed = false;
|
|
@@ -744,6 +793,10 @@ export function transformDeps(pkg, baseDir, verbose = false, forcePublish = fals
|
|
|
744
793
|
unpublished.push({ name, version: targetVersion, path: targetPath });
|
|
745
794
|
console.log(colors.yellow(` ⟳ ${name}@${targetVersion} has unpublished transitive deps — will republish`));
|
|
746
795
|
}
|
|
796
|
+
else if (hasLocalChanges(name, targetVersion, targetPath, verbose)) {
|
|
797
|
+
unpublished.push({ name, version: targetVersion, path: targetPath });
|
|
798
|
+
console.log(colors.yellow(` ⟳ ${name}@${targetVersion} has local changes not on npm — will republish`));
|
|
799
|
+
}
|
|
747
800
|
}
|
|
748
801
|
pkg[key][name] = npmVersion;
|
|
749
802
|
if (verbose) {
|