Skip to content

feat(version): sanitize package names in formatTag function#72

Merged
goosewobbler merged 3 commits intomainfrom
fix/tag-normalisation
Mar 27, 2026
Merged

feat(version): sanitize package names in formatTag function#72
goosewobbler merged 3 commits intomainfrom
fix/tag-normalisation

Conversation

@goosewobbler
Copy link
Copy Markdown
Owner

No description provided.

- Updated the formatTag function to strip the '@' prefix from scoped package names and replace '/' with '-' for tag formatting.
- Enhanced unit tests to verify the correct handling of sanitized package names in various scenarios, ensuring accurate tag generation.
- Changed the tag template format from "${packageName}@v${version}" to "${packageName}-v${version}" for improved consistency in version tagging.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

Release Preview — no release

No release label detected.
Note: Add release:patch, release:minor, or release:major to trigger a release.


Updated automatically by ReleaseKit

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 27, 2026

Greptile Summary

This PR fixes a latent bug where scoped npm package names (e.g. @releasekit/version) were being used verbatim in git tag names, producing invalid or malformed tags like @releasekit/version@v1.0.0. The fix sanitizes the package name in formatTag and formatTagPrefix by stripping the leading @ and replacing / with -, and updates releasekit.config.json's tagTemplate from ${packageName}@v${version} to ${packageName}-v${version} to match the new format.

  • Sanitization logic is correctly applied in both formatTag and formatTagPrefix via an identically-structured one-liner; the warning path still checks the raw packageName, which is the right behaviour (warn only when no name is provided at all).
  • formatCommitMessage is intentionally not sanitized — commit messages can contain scoped names like @releasekit/version@1.0.0 without issue; this asymmetry is by design and aligns with the PR title.
  • formatTagPrefix gains string | null in its packageName type, bringing it in line with formatTag's existing signature.
  • Three new test cases cover the sanitization in the template path, the bare @-prefix path, and the default package-specific tag path; formatTagPrefix with a scoped name is not explicitly tested, though the logic is identical to formatTag.
  • Config change correctly updates the own-project tag template to produce releasekit-version-v1.0.0-style tags going forward.

Confidence Score: 5/5

Safe to merge — the fix is focused, well-tested, and corrects a real bug with no regressions introduced.

The change is minimal and surgical: two identical sanitization one-liners, three new passing tests covering the new behaviour, and a config update that follows directly from the logic change. The previously flagged single-slash replace was already addressed (the PR uses the global /\//g regex). No edge cases in the happy path are left uncovered, and formatCommitMessage is intentionally left unsanitized.

No files require special attention.

Important Files Changed

Filename Overview
packages/version/src/utils/formatting.ts Adds sanitizedPackageName local variable in both formatTag and formatTagPrefix to strip the @ prefix and replace / with - for scoped npm package names; also adds `string
packages/version/test/unit/utils/formatting.spec.ts Adds three new test cases covering scoped package name sanitization in formatTag (template path, unscoped @-prefixed name, and default package-specific format path); no new tests for formatTagPrefix with scoped names.
releasekit.config.json Updates tagTemplate from ${packageName}@v${version} to ${packageName}-v${version} so the sanitized package name produces well-formed tags (e.g. releasekit-version-v1.0.0 instead of the previously broken @releasekit/version@v1.0.0).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["packageName input\n(e.g. '@releasekit/version')"] --> B{startsWith '@'?}
    B -- Yes --> C["slice(1) → 'releasekit/version'"]
    C --> D["replace /\\//g with '-'\n→ 'releasekit-version'"]
    D --> E[sanitizedPackageName]
    B -- No --> F["packageName unchanged\n(e.g. 'my-package')"]
    F --> E
    E --> G{template provided?}
    G -- Yes --> H["template.replace\n'${packageName}' → sanitizedPackageName || ''"]
    G -- No --> I{packageSpecificTags\n&& sanitizedPackageName?}
    I -- Yes --> J["'sanitizedPackageName@prefixversion'\n(formatTag)\nor 'sanitizedPackageName@prefix'\n(formatTagPrefix)"]
    I -- No --> K["prefixversion\nor prefix"]
Loading

Reviews (2): Last reviewed commit: "fix(version): enhance package name sanit..." | Re-trigger Greptile

Comment thread packages/version/src/utils/formatting.ts Outdated
- Updated the `formatTag` and `formatTagPrefix` functions to ensure that the '@' prefix is stripped and '/' is replaced with '-' for all package names, improving consistency in tag formatting.
- Adjusted the handling of `packageName` to account for null values, ensuring robust tag generation.
@goosewobbler goosewobbler merged commit 3325f6c into main Mar 27, 2026
19 checks passed
@goosewobbler goosewobbler deleted the fix/tag-normalisation branch March 27, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant