Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57e4d1c043 | |||
| f495f85bdb | |||
| d53e8fec6d | |||
| 00fef1ae06 | |||
| 4c1608cf94 | |||
| e0c4cf2983 |
23
changelog.md
23
changelog.md
@@ -1,5 +1,28 @@
|
||||
# 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)
|
||||
make test script output verbose by using --verbose instead of --web
|
||||
|
||||
- package.json: change npm "test" script from "(tstest test/ --web)" to "(tstest test/ --verbose)" to enable verbose test output
|
||||
|
||||
## 2026-02-03 - 3.1.1 - fix(tools)
|
||||
no changes detected
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@git.zone/tools",
|
||||
"version": "3.1.1",
|
||||
"version": "3.2.0",
|
||||
"private": false,
|
||||
"type": "module",
|
||||
"description": "A CLI tool placeholder for development utilities.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"test": "(tstest test/ --verbose)",
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"bin": {
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tools',
|
||||
version: '3.1.1',
|
||||
version: '3.2.0',
|
||||
description: 'A CLI tool placeholder for development utilities.'
|
||||
}
|
||||
|
||||
@@ -16,6 +16,16 @@ export interface IPackageUpdateInfo {
|
||||
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 {
|
||||
private shell = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
@@ -23,14 +33,92 @@ export class PackageManagerUtil {
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
const info = await this.detectPackageManager(pm, verbose);
|
||||
return info.available;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 result = await this.shell.execSilent(`which ${pm} >/dev/null 2>&1 && echo "found"`);
|
||||
return result.exitCode === 0 && result.stdout.includes('found');
|
||||
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 {
|
||||
return false;
|
||||
// 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
|
||||
* Tries private registry (verdaccio.lossless.digital) first via API, then falls back to public npm
|
||||
*/
|
||||
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 {
|
||||
const result = await this.shell.execSilent(`npm view ${packageName} version 2>/dev/null`);
|
||||
if (result.exitCode === 0 && result.stdout.trim()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 = [
|
||||
'@git.zone/cli',
|
||||
@@ -15,46 +15,80 @@ const GITZONE_PACKAGES = [
|
||||
|
||||
export interface IUpdateOptions {
|
||||
yes?: boolean;
|
||||
verbose?: boolean;
|
||||
}
|
||||
|
||||
export const run = async (options: IUpdateOptions = {}): Promise<void> => {
|
||||
const pmUtil = new PackageManagerUtil();
|
||||
const verbose = options.verbose === true;
|
||||
|
||||
console.log('Scanning for installed @git.zone packages...\n');
|
||||
|
||||
// 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[]) {
|
||||
if (await pmUtil.isAvailable(pm)) {
|
||||
availablePMs.push(pm);
|
||||
const info = await pmUtil.detectPackageManager(pm, verbose);
|
||||
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('Tried detection via \'which\' command and direct version check.');
|
||||
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
|
||||
const allPackages: IPackageUpdateInfo[] = [];
|
||||
|
||||
for (const pm of availablePMs) {
|
||||
const installed = await pmUtil.getInstalledPackages(pm);
|
||||
for (const pmInfo of detectedPMs) {
|
||||
const installed = await pmUtil.getInstalledPackages(pmInfo.name);
|
||||
for (const pkg of installed) {
|
||||
// Only include packages from our predefined list
|
||||
if (GITZONE_PACKAGES.includes(pkg.name)) {
|
||||
const latestVersion = await pmUtil.getLatestVersion(pkg.name);
|
||||
if (latestVersion) {
|
||||
allPackages.push({
|
||||
name: pkg.name,
|
||||
currentVersion: pkg.version,
|
||||
latestVersion,
|
||||
packageManager: pm,
|
||||
needsUpdate: pmUtil.isNewerVersion(pkg.version, latestVersion),
|
||||
});
|
||||
}
|
||||
allPackages.push({
|
||||
name: pkg.name,
|
||||
currentVersion: pkg.version,
|
||||
latestVersion: latestVersion || 'unknown',
|
||||
packageManager: pmInfo.name,
|
||||
needsUpdate: latestVersion ? pmUtil.isNewerVersion(pkg.version, latestVersion) : false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +108,11 @@ export const run = async (options: IUpdateOptions = {}): Promise<void> => {
|
||||
const current = pkg.currentVersion.padEnd(12);
|
||||
const latest = pkg.latestVersion.padEnd(12);
|
||||
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}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,15 +7,17 @@ export const run = async () => {
|
||||
toolsCli.standardCommand().subscribe(async (argvArg) => {
|
||||
console.log('@git.zone/tools - CLI utility for managing @git.zone packages\n');
|
||||
console.log('Commands:');
|
||||
console.log(' update Check and update globally installed @git.zone packages');
|
||||
console.log(' update -y Update without confirmation prompt');
|
||||
console.log(' update Check and update globally installed @git.zone packages');
|
||||
console.log(' update -y Update without confirmation prompt');
|
||||
console.log(' update --verbose Show detection diagnostics');
|
||||
console.log('');
|
||||
console.log('Use "gtools <command> --help" for more information about a command.');
|
||||
});
|
||||
|
||||
toolsCli.addCommand('update').subscribe(async (argvArg) => {
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user