fix(create): sanitize the derived default package name - #2549
Open
m0g3r wants to merge 1 commit into
Open
Conversation
`vp create` derives the default package name from the target directory name. When that name was not a valid npm package name it was replaced outright by a random two-word name, so a directory called `ComfyUI-DenoiseHQNodes.feat-1-save-image-node` scaffolded as something unrelated like `remind-continue`. In a non-interactive run that name lands in `package.json` unnoticed. Lowercase the directory name and replace the characters npm rejects before giving up on it, so the derived name keeps the project's identity. The random fallback still applies when nothing survives sanitization, such as a directory named only with punctuation. Refs voidzero-dev#2521
✅ Deploy Preview for viteplus-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Refs #2521
This implements the first of the two smaller things the reporter listed at the bottom of #2521 and offered to split out. It is deliberately not the issue's headline ask (scaffolding into a non-empty directory), which is a design question with two competing proposals — hence
Refs, notCloses.Problem
deriveDefaultPackageName()inpackages/cli/src/create/utils.tsderives the default package name from the target directory's basename. When that basename is not a valid npm package name, it was discarded entirely and replaced with a random two-word name from@nkzw/safe-word-list.The reporter's directory
ComfyUI-DenoiseHQNodes.feat-1-save-image-nodeis invalid only because of the uppercase letters, and scaffolded asappoint-track,perspective-detailed, andnation-virtuallyacross three runs. In a non-interactive run that unrelated name lands inpackage.jsonunnoticed.Changes
deriveDefaultPackageNamenow tries to repair the basename before giving up on it: lowercase it, replace characters npm rejects, collapse repeated separators, strip leading./_/-and trailing-/., and truncate to npm's 214-character limit. If the repaired name validates, it is used; otherwise the existing random fallback is kept exactly as before.ComfyUI-DenoiseHQNodes.feat-1-save-image-nodecomfyui-denoisehqnodes.feat-1-save-image-nodeMy App (v2)!my-app-v2.hiddenhiddenMy-App(scope@my-scope)@my-scope/my-app!!!/(filesystem root)my-appmy-appmy-app(unchanged)Testing
Four new cases cover the sanitization paths, and the two fallback paths plus the already-valid path are asserted to be unchanged.
Verified in both directions against the current
main, restoring only the old logic inside the module so failures are behavioural rather than import errors:One existing test was intentionally rewritten rather than deleted.
should fallback to random name when directory name is invalidused.hidden, and its comment said "a random name is generated instead" — no longer true, since.hiddennow deriveshidden. Its input became!!!so it still guards the random-fallback path it was written for, and a new case asserts the.hidden→hiddenbehaviour. Coverage is preserved, not weakened.Checks actually run:
packages/cli/src/create/__tests__/utils.spec.ts— 48 → 54 passing.createsuite — before/after diffed in the same build state: identical failure set (all environmental), 50 → 55 passing.packages/cli/src/**spec set — before/after diffed: identical failure set both ways, 223 → 228 passing.oxlint@1.79.0(the repo's pinned version) with-D correctness -D perf -D suspiciouson both changed files — exit 0.git diff --check— clean.Not run:
vp check,pnpm test:unit,tsgo, and the PTY snapshot suite, all of which need a full workspace build that this environment cannot produce.deriveDefaultPackageNameis referenced only bycreate/utils.ts, its spec, andcreate/bin.ts, and no PTY snapshot fixture depends on it.AI assistance
Claude Opus 5 wrote the implementation, the tests, and this description. The change is agent-authored and has not had a separate human review. Every result quoted above is from an actual run, not an estimate.
Generated by Claude Code