Skip to content

Commit 3252ee5

Browse files
rrdelaneyfengmk2
andauthored
fix: update resolution logic for vp create to match npm-init (#1041)
Updates the resolution logic of `vp create` to match the logic from [`npm-init`](https://docs.npmjs.com/cli/v11/commands/npm-init), specifically around scoped names without a package. With `npm create` and `pnpm create`, scoped named resolve to `@scope/create`. Ran into this trying to run `vp create @scope` and got hit with a confusing error message, so figured I'd just upstream a fix! --------- Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 5e77c9b commit 3252ee5

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/cli/src/create/__tests__/discovery.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ describe('expandCreateShorthand', () => {
6060
expect(expandCreateShorthand('/absolute/path')).toBe('/absolute/path');
6161
});
6262

63-
it('should handle scope-only input gracefully', () => {
64-
expect(expandCreateShorthand('@scope')).toBe('@scope');
63+
it('should expand scope-only input to @scope/create', () => {
64+
expect(expandCreateShorthand('@scope')).toBe('@scope/create');
65+
expect(expandCreateShorthand('@scope@latest')).toBe('@scope/create@latest');
66+
expect(expandCreateShorthand('@scope@1.2.3')).toBe('@scope/create@1.2.3');
6567
});
6668

6769
it('should handle special cases where default convention does not apply', () => {

packages/cli/src/create/discovery.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ export function expandCreateShorthand(templateName: string): string {
169169
if (templateName.startsWith('@')) {
170170
const slashIndex = templateName.indexOf('/');
171171
if (slashIndex === -1) {
172-
return templateName;
172+
// @scope or @scope@version → @scope/create[@version]
173+
const atIndex = templateName.indexOf('@', 1);
174+
const scope = atIndex === -1 ? templateName : templateName.slice(0, atIndex);
175+
const version = atIndex === -1 ? '' : templateName.slice(atIndex);
176+
return `${scope}/create${version}`;
173177
}
174178
const scope = templateName.slice(0, slashIndex);
175179
const rest = templateName.slice(slashIndex + 1);

0 commit comments

Comments
 (0)