Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/create-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ const FRAMEWORKS: Framework[] = [
color: cyan,
customCommand: 'npm create react-router@latest TARGET_DIR',
},
{
name: 'custom-tanstack-router',
display: 'TanStack Router ↗',
color: cyan,
customCommand: 'npm create -- tsrouter-app@latest TARGET_DIR --framework react',
Copy link
Contributor Author

@wobsoriano wobsoriano Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the "--" will be removed when using a different package manager. Without it I'm getting this error:

"error: too many arguments. Expected 1 argument but got"

cc @patak-dev

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this works with npm and yarn, but doesn't with pnpm and bun.
I think we can strip -- here for pnpm and bun.

.replace(/^npm create /, () => {
// `bun create` uses it's own set of templates,
// the closest alternative is using `bun x` directly on the package
if (pkgManager === 'bun') {
return 'bun x create-'
}
return `${pkgManager} create `
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated! I used this to test the regex:

function testReplace(customCommand, pkgManager) {
  const result = customCommand.replace(/^npm create (?:-- )?/, () => {
    if (pkgManager === 'bun') {
      return 'bun x create-';
    }
    if (pkgManager === 'pnpm') {
      return 'pnpm create ';
    }
    return customCommand.startsWith('npm create -- ') 
      ? `${pkgManager} create -- ` 
      : `${pkgManager} create `;
  });
  
  return result;
}

const testCases = [
  // Regular npm create commands
  { cmd: 'npm create vue@latest TARGET_DIR', pkgManager: 'npm' },
  { cmd: 'npm create vue@latest TARGET_DIR', pkgManager: 'pnpm' },
  { cmd: 'npm create vue@latest TARGET_DIR', pkgManager: 'bun' },
  { cmd: 'npm create vue@latest TARGET_DIR', pkgManager: 'yarn' },
  
  // Commands with --
  { cmd: 'npm create -- tsrouter-app@latest TARGET_DIR --framework react', pkgManager: 'npm' },
  { cmd: 'npm create -- tsrouter-app@latest TARGET_DIR --framework react', pkgManager: 'pnpm' },
  { cmd: 'npm create -- tsrouter-app@latest TARGET_DIR --framework react', pkgManager: 'bun' },
  { cmd: 'npm create -- tsrouter-app@latest TARGET_DIR --framework react', pkgManager: 'yarn' }
];

testCases.forEach(({ cmd, pkgManager }) => {
  const result = testReplace(cmd, pkgManager);
  console.log(`\nInput: ${cmd}`);
  console.log(`Package Manager: ${pkgManager}`);
  console.log(`Result: ${result}`);
});

},
],
},
{
Expand Down Expand Up @@ -223,6 +229,12 @@ const FRAMEWORKS: Framework[] = [
display: 'JavaScript',
color: yellow,
},
{
name: 'custom-tanstack-router',
display: 'TanStack Router ↗',
color: cyan,
customCommand: 'npm create -- tsrouter-app@latest TARGET_DIR --framework solid',
},
],
},
{
Expand Down Expand Up @@ -603,7 +615,7 @@ function editFile(file: string, callback: (content: string) => string) {
function getFullCustomCommand(customCommand: string, pkgInfo?: PkgInfo) {
const pkgManager = pkgInfo ? pkgInfo.name : 'npm'
const isYarn1 = pkgManager === 'yarn' && pkgInfo?.version.startsWith('1.')

return (
customCommand
.replace(/^npm create /, () => {
Expand Down
Loading