fix(init): preserve scope/path separators in project slugs#886
Merged
MathurAditya724 merged 1 commit intomainfrom Apr 29, 2026
Merged
fix(init): preserve scope/path separators in project slugs#886MathurAditya724 merged 1 commit intomainfrom
MathurAditya724 merged 1 commit intomainfrom
Conversation
Reported by users running `sentry init` in monorepos with npm-scoped
package names. The package.json `name` field `@t3tools/web` was being
slugified to `t3toolsweb` (silently mashed) instead of `t3tools-web`.
Root cause: `slugify` mirrored Sentry's frontend canonical implementation
(getsentry/sentry/static/app/utils/slugify.tsx), which strips `@` and
`/` along with other invalid characters in a single pass. For npm scopes
and monorepo path segments this destroys structural information.
Fix: normalize `/` and `\` to a space before the strip step. Existing
collapse rule `[-\s]+` then folds them into hyphens.
slugify("@t3tools/web") // before: "t3toolsweb" now: "t3tools-web"
slugify("@scope/pkg") // before: "scopepkg" now: "scope-pkg"
slugify("packages/api") // before: "packagesapi" now: "packages-api"
slugify("apps\\api") // before: "appsapi" now: "apps-api"
All other inputs unchanged: `My Cool App` → `my-cool-app`, `Café Project`
→ `cafe-project`, `my_app` → `my_app`, etc.
Adds:
- test/lib/utils.test.ts — unit cases for JSDoc examples, npm scopes,
monorepo paths, edge cases (empty, all-invalid, leading/trailing
separators)
- test/lib/utils.property.test.ts — invariants for any input: output
matches /^[a-z0-9_-]*$/, no leading/trailing/consecutive hyphens,
idempotent, separator-between-segments always becomes a hyphen
Note for users who previously ran `sentry init` against a scoped-package
project: a re-run will produce a new slug (e.g. `t3tools-web`) and
create a new Sentry project. The old `t3toolsweb` project is orphaned
and can be deleted manually via the Sentry UI or `sentry project delete`.
Contributor
|
Contributor
Codecov Results 📊✅ 6343 passed | Total: 6343 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 13883 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 75.97% 74.87% -1.1%
==========================================
Files 294 294 —
Lines 54449 55248 +799
Branches 0 0 —
==========================================
+ Hits 41365 41365 —
- Misses 13084 13883 +799
- Partials 0 0 —Generated by Codecov Action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sentry initproduces unreadable project slugs for monorepo / npm-scopedpackage names. Reported case: `package.json` with `"name": "@t3tools/web"`
created a Sentry project with slug `t3toolsweb` instead of `t3tools-web`.
Root cause
`slugify()` in `src/lib/utils.ts` mirrors Sentry's frontend canonical
implementation
(`static/app/utils/slugify.tsx`),
which strips invalid characters (including `@` and `/`) in a single pass.
For npm scopes and monorepo path segments this destroys structural
information — `/` should be preserved as a hyphen, not silently dropped.
Fix
Normalize `/` and `\` to a space before the invalid-character strip
step. The existing `[-\s]+` collapse rule then folds them into hyphens.
```ts
return name
.normalize("NFKD")
.toLowerCase()
.replace(/[\\/]+/g, " ") // ← new
.replace(/[^a-z0-9_\\s-]/g, "")
.replace(/[-\s]+/g, "-")
.replace(/^-|-$/g, "");
```
Behavior change
All other inputs unchanged:
Tests
scopes, monorepo paths, edge cases (empty, all-invalid input,
leading/trailing separators).
26 new tests pass; full suite (6,343 tests) passes; lint clean; typecheck clean.
Note for affected users
Anyone who previously ran `sentry init` against a scoped-package project
got a Sentry project with the broken slug (e.g. `t3toolsweb`). After this
fix lands, a re-run of `sentry init` will:
The old project can be deleted via the Sentry UI or
`sentry project delete /t3toolsweb`. We're not adding a fallback
lookup ("if new slug not found, try old slug") because it adds
significant complexity for a small affected user base, and the orphaned
project is easy to clean up manually.
Out of scope
are unambiguous structural separators. Targeting just the reported bug.
safer than expanding the API.
improvement specifically for input shapes (npm scopes, monorepo paths)
the CLI receives that the web UI typically doesn't.