Compare commits

...

4 Commits

6 changed files with 193 additions and 27 deletions

View File

@@ -1,5 +1,23 @@
# Changelog # Changelog
## 2026-02-05 - 3.2.0 - feat(update)
enhance package manager detection, version reporting, and add verbose option
- Add IPackageManagerInfo interface and detectPackageManager() to robustly detect npm/yarn/pnpm via 'which' and '--version' fallbacks
- Make isAvailable() delegate to detectPackageManager() and return structured detection info
- Add getPackageManagerVersion() to obtain current and latest versions (parses local --version and queries npm registry)
- Update run() to support a verbose flag, show a package-manager status table, and collect detectedPMs with version/update status
- Update CLI help and command handling to accept --verbose/-v and pass it through to mod_update.run()
## 2026-02-03 - 3.1.3 - fix(mod_update)
try private registry (verdaccio.lossless.digital) first when fetching package versions; fall back to public npm; handle unknown latest versions gracefully in output
- getLatestVersion now attempts a direct API request to https://verdaccio.lossless.digital/<encoded-package> and parses dist-tags.latest
- Falls back to npm view when the private registry request fails
- Scoped package names are URL-encoded (replaces '/' with '%2f') before querying the private registry
- Packages with no resolvable latest version are included with latestVersion set to 'unknown' and displayed as '? Version unknown'
- needsUpdate is set to false when latest version is unknown
## 2026-02-03 - 3.1.2 - fix(scripts) ## 2026-02-03 - 3.1.2 - fix(scripts)
make test script output verbose by using --verbose instead of --web make test script output verbose by using --verbose instead of --web

View File

@@ -1,6 +1,6 @@
{ {
"name": "@git.zone/tools", "name": "@git.zone/tools",
"version": "3.1.2", "version": "3.2.0",
"private": false, "private": false,
"type": "module", "type": "module",
"description": "A CLI tool placeholder for development utilities.", "description": "A CLI tool placeholder for development utilities.",

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tools', name: '@git.zone/tools',
version: '3.1.2', version: '3.2.0',
description: 'A CLI tool placeholder for development utilities.' description: 'A CLI tool placeholder for development utilities.'
} }

View File

@@ -16,6 +16,16 @@ export interface IPackageUpdateInfo {
needsUpdate: boolean; needsUpdate: boolean;
} }
export interface IPackageManagerInfo {
name: TPackageManager;
available: boolean;
detectionMethod?: 'which' | 'version-command';
path?: string;
currentVersion?: string;
latestVersion?: string | null;
needsUpdate?: boolean;
}
export class PackageManagerUtil { export class PackageManagerUtil {
private shell = new plugins.smartshell.Smartshell({ private shell = new plugins.smartshell.Smartshell({
executor: 'bash', executor: 'bash',
@@ -23,14 +33,92 @@ export class PackageManagerUtil {
/** /**
* Check if a package manager is available on the system * Check if a package manager is available on the system
* Uses multiple detection methods for robustness across different shell contexts
*/ */
public async isAvailable(pm: TPackageManager): Promise<boolean> { public async isAvailable(pm: TPackageManager, verbose = false): Promise<boolean> {
try { const info = await this.detectPackageManager(pm, verbose);
const result = await this.shell.execSilent(`which ${pm} >/dev/null 2>&1 && echo "found"`); return info.available;
return result.exitCode === 0 && result.stdout.includes('found');
} catch {
return false;
} }
/**
* Detect a package manager and return detailed info
*/
public async detectPackageManager(pm: TPackageManager, verbose = false): Promise<IPackageManagerInfo> {
const info: IPackageManagerInfo = { name: pm, available: false };
// Primary method: try 'which' command
try {
const whichResult = await this.shell.execSilent(`which ${pm} 2>/dev/null`);
if (whichResult.exitCode === 0 && whichResult.stdout.trim()) {
info.available = true;
info.detectionMethod = 'which';
info.path = whichResult.stdout.trim();
if (verbose) {
console.log(` Checking ${pm}... found via 'which' at ${info.path}`);
}
return info;
}
} catch {
// Continue to fallback
}
// Fallback method: try running pm --version directly
// This can find PMs that are available but not in PATH for 'which'
try {
const versionResult = await this.shell.execSilent(`${pm} --version 2>/dev/null`);
if (versionResult.exitCode === 0 && versionResult.stdout.trim()) {
info.available = true;
info.detectionMethod = 'version-command';
if (verbose) {
console.log(` Checking ${pm}... found via '--version' (which failed)`);
}
return info;
}
} catch {
// Not available
}
if (verbose) {
console.log(` Checking ${pm}... not found`);
}
return info;
}
/**
* Get the current and latest version of a package manager
*/
public async getPackageManagerVersion(pm: TPackageManager): Promise<{ current: string; latest: string | null }> {
let current = 'unknown';
let latest: string | null = null;
// Get current version
try {
const result = await this.shell.execSilent(`${pm} --version 2>/dev/null`);
if (result.exitCode === 0 && result.stdout.trim()) {
// Parse version from output - handle different formats
const output = result.stdout.trim();
// npm: "10.2.0", pnpm: "8.15.0", yarn: "1.22.19"
// Some may include prefix like "v1.22.19"
const versionMatch = output.match(/(\d+\.\d+\.\d+)/);
if (versionMatch) {
current = versionMatch[1];
}
}
} catch {
// Keep as unknown
}
// Get latest version from npm registry
try {
const result = await this.shell.execSilent(`npm view ${pm} version 2>/dev/null`);
if (result.exitCode === 0 && result.stdout.trim()) {
latest = result.stdout.trim();
}
} catch {
// Keep as null
}
return { current, latest };
} }
/** /**
@@ -128,8 +216,28 @@ export class PackageManagerUtil {
/** /**
* Get the latest version of a package from npm registry * Get the latest version of a package from npm registry
* Tries private registry (verdaccio.lossless.digital) first via API, then falls back to public npm
*/ */
public async getLatestVersion(packageName: string): Promise<string | null> { public async getLatestVersion(packageName: string): Promise<string | null> {
// URL-encode the package name for scoped packages (@scope/name -> @scope%2fname)
const encodedName = packageName.replace('/', '%2f');
// Try private registry first via direct API call (npm view doesn't work reliably)
try {
const result = await this.shell.execSilent(
`curl -sf "https://verdaccio.lossless.digital/${encodedName}" 2>/dev/null`
);
if (result.exitCode === 0 && result.stdout.trim()) {
const data = JSON.parse(result.stdout.trim());
if (data['dist-tags']?.latest) {
return data['dist-tags'].latest;
}
}
} catch {
// Continue to public registry
}
// Fall back to public npm
try { try {
const result = await this.shell.execSilent(`npm view ${packageName} version 2>/dev/null`); const result = await this.shell.execSilent(`npm view ${packageName} version 2>/dev/null`);
if (result.exitCode === 0 && result.stdout.trim()) { if (result.exitCode === 0 && result.stdout.trim()) {

View File

@@ -1,5 +1,5 @@
import * as plugins from './mod.plugins.js'; import * as plugins from './mod.plugins.js';
import { PackageManagerUtil, type TPackageManager, type IPackageUpdateInfo } from './classes.packagemanager.js'; import { PackageManagerUtil, type TPackageManager, type IPackageUpdateInfo, type IPackageManagerInfo } from './classes.packagemanager.js';
const GITZONE_PACKAGES = [ const GITZONE_PACKAGES = [
'@git.zone/cli', '@git.zone/cli',
@@ -15,49 +15,83 @@ const GITZONE_PACKAGES = [
export interface IUpdateOptions { export interface IUpdateOptions {
yes?: boolean; yes?: boolean;
verbose?: boolean;
} }
export const run = async (options: IUpdateOptions = {}): Promise<void> => { export const run = async (options: IUpdateOptions = {}): Promise<void> => {
const pmUtil = new PackageManagerUtil(); const pmUtil = new PackageManagerUtil();
const verbose = options.verbose === true;
console.log('Scanning for installed @git.zone packages...\n'); console.log('Scanning for installed @git.zone packages...\n');
// Check which package managers are available // Check which package managers are available
const availablePMs: TPackageManager[] = []; if (verbose) {
console.log('Detecting package managers:');
}
const detectedPMs: IPackageManagerInfo[] = [];
for (const pm of ['npm', 'yarn', 'pnpm'] as TPackageManager[]) { for (const pm of ['npm', 'yarn', 'pnpm'] as TPackageManager[]) {
if (await pmUtil.isAvailable(pm)) { const info = await pmUtil.detectPackageManager(pm, verbose);
availablePMs.push(pm); if (info.available) {
detectedPMs.push(info);
} }
} }
if (availablePMs.length === 0) { if (verbose) {
console.log('');
}
if (detectedPMs.length === 0) {
console.log('No package managers found (npm, yarn, pnpm).'); console.log('No package managers found (npm, yarn, pnpm).');
console.log('Tried detection via \'which\' command and direct version check.');
return; return;
} }
console.log(`Found package managers: ${availablePMs.join(', ')}\n`); // Get version info for each PM and display status table
console.log('Package managers:\n');
console.log(' Name Current Latest Status');
console.log(' ──────────────────────────────────────────────');
for (const pmInfo of detectedPMs) {
const versionInfo = await pmUtil.getPackageManagerVersion(pmInfo.name);
pmInfo.currentVersion = versionInfo.current;
pmInfo.latestVersion = versionInfo.latest;
pmInfo.needsUpdate = versionInfo.latest
? pmUtil.isNewerVersion(versionInfo.current, versionInfo.latest)
: false;
const name = pmInfo.name.padEnd(9);
const current = versionInfo.current.padEnd(12);
const latest = (versionInfo.latest || 'unknown').padEnd(12);
const status = versionInfo.latest === null
? '? Version unknown'
: pmInfo.needsUpdate
? '⬆️ Update available'
: '✓ Up to date';
console.log(` ${name}${current}${latest}${status}`);
}
console.log('');
// Collect all installed @git.zone packages from all package managers // Collect all installed @git.zone packages from all package managers
const allPackages: IPackageUpdateInfo[] = []; const allPackages: IPackageUpdateInfo[] = [];
for (const pm of availablePMs) { for (const pmInfo of detectedPMs) {
const installed = await pmUtil.getInstalledPackages(pm); const installed = await pmUtil.getInstalledPackages(pmInfo.name);
for (const pkg of installed) { for (const pkg of installed) {
// Only include packages from our predefined list // Only include packages from our predefined list
if (GITZONE_PACKAGES.includes(pkg.name)) { if (GITZONE_PACKAGES.includes(pkg.name)) {
const latestVersion = await pmUtil.getLatestVersion(pkg.name); const latestVersion = await pmUtil.getLatestVersion(pkg.name);
if (latestVersion) {
allPackages.push({ allPackages.push({
name: pkg.name, name: pkg.name,
currentVersion: pkg.version, currentVersion: pkg.version,
latestVersion, latestVersion: latestVersion || 'unknown',
packageManager: pm, packageManager: pmInfo.name,
needsUpdate: pmUtil.isNewerVersion(pkg.version, latestVersion), needsUpdate: latestVersion ? pmUtil.isNewerVersion(pkg.version, latestVersion) : false,
}); });
} }
} }
} }
}
if (allPackages.length === 0) { if (allPackages.length === 0) {
console.log('No @git.zone packages found installed globally.'); console.log('No @git.zone packages found installed globally.');
@@ -74,7 +108,11 @@ export const run = async (options: IUpdateOptions = {}): Promise<void> => {
const current = pkg.currentVersion.padEnd(12); const current = pkg.currentVersion.padEnd(12);
const latest = pkg.latestVersion.padEnd(12); const latest = pkg.latestVersion.padEnd(12);
const pm = pkg.packageManager.padEnd(8); const pm = pkg.packageManager.padEnd(8);
const status = pkg.needsUpdate ? '⬆️ Update available' : '✓ Up to date'; const status = pkg.latestVersion === 'unknown'
? '? Version unknown'
: pkg.needsUpdate
? '⬆️ Update available'
: '✓ Up to date';
console.log(` ${name}${current}${latest}${pm}${status}`); console.log(` ${name}${current}${latest}${pm}${status}`);
} }

View File

@@ -9,13 +9,15 @@ export const run = async () => {
console.log('Commands:'); console.log('Commands:');
console.log(' update Check and update globally installed @git.zone packages'); console.log(' update Check and update globally installed @git.zone packages');
console.log(' update -y Update without confirmation prompt'); console.log(' update -y Update without confirmation prompt');
console.log(' update --verbose Show detection diagnostics');
console.log(''); console.log('');
console.log('Use "gtools <command> --help" for more information about a command.'); console.log('Use "gtools <command> --help" for more information about a command.');
}); });
toolsCli.addCommand('update').subscribe(async (argvArg) => { toolsCli.addCommand('update').subscribe(async (argvArg) => {
const yesFlag = argvArg.y === true || argvArg.yes === true; const yesFlag = argvArg.y === true || argvArg.yes === true;
await modUpdate.run({ yes: yesFlag }); const verboseFlag = argvArg.v === true || argvArg.verbose === true;
await modUpdate.run({ yes: yesFlag, verbose: verboseFlag });
}); });
toolsCli.addVersion('3.0.0'); toolsCli.addVersion('3.0.0');