From b191464ff9400f8c25a57bcfba52d4778728d139 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Mon, 15 Dec 2025 17:30:51 +0000 Subject: [PATCH] fix(mod_format/formatters): fix(packagejson.formatter): correctly parse scoped package dependency arguments and default to latest --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/mod_format/formatters/packagejson.formatter.ts | 15 ++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index fa03c7d..7bc61e8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-12-15 - 2.11.1 - fix(mod_format/formatters) +fix(packagejson.formatter): correctly parse scoped package dependency arguments and default to latest + +- Handle scoped packages (e.g. @scope/name@version) by detecting the last '@' after the scope slash so package name and version are split correctly. +- Fallback to 'latest' when no version is provided. +- Fixes earlier incorrect splitting on every '@' which broke scoped package names. + ## 2025-12-15 - 2.11.0 - feat(mod_format) feat(mod_format): use unified diff formatter with filenames and context in BaseFormatter.displayDiff diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 76e3138..59b3075 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/cli', - version: '2.11.0', + version: '2.11.1', description: 'A comprehensive CLI tool for enhancing and managing local development workflows with gitzone utilities, focusing on project setup, version control, code formatting, and template management.' } diff --git a/ts/mod_format/formatters/packagejson.formatter.ts b/ts/mod_format/formatters/packagejson.formatter.ts index 708a21d..2869548 100644 --- a/ts/mod_format/formatters/packagejson.formatter.ts +++ b/ts/mod_format/formatters/packagejson.formatter.ts @@ -13,9 +13,18 @@ const ensureDependency = async ( constraint: 'exclude' | 'include' | 'latest', dependencyArg: string, ): Promise => { - const [packageName, version] = dependencyArg.includes('@') - ? dependencyArg.split('@').filter(Boolean) - : [dependencyArg, 'latest']; + // Parse package name and version, handling scoped packages like @scope/name@version + const isScoped = dependencyArg.startsWith('@'); + const lastAtIndex = dependencyArg.lastIndexOf('@'); + + // For scoped packages, the version @ must come after the / + // For unscoped packages, any @ indicates a version + const hasVersion = isScoped + ? lastAtIndex > dependencyArg.indexOf('/') + : lastAtIndex >= 0; + + const packageName = hasVersion ? dependencyArg.slice(0, lastAtIndex) : dependencyArg; + const version = hasVersion ? dependencyArg.slice(lastAtIndex + 1) : 'latest'; const targetSections: string[] = [];