Skip to content

feat(create-vite): add TanStack Router commands#19573

Merged
patak-cat merged 8 commits intovitejs:mainfrom
wobsoriano:rob/add-tanstack-router-commands
Mar 20, 2025
Merged

feat(create-vite): add TanStack Router commands#19573
patak-cat merged 8 commits intovitejs:mainfrom
wobsoriano:rob/add-tanstack-router-commands

Conversation

@wobsoriano
Copy link
Contributor

@wobsoriano wobsoriano commented Mar 4, 2025

Description

This PR adds commands to create a new TanStack Router app based on the create-tsrouter-app CLI.

name: 'custom-tanstack-router',
display: 'TanStack Router ↗',
color: cyan,
customCommand: 'npm create -- create-tsrouter-app@latest TARGET_DIR --framework react',
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't the create- be removed here?

Suggested change
customCommand: 'npm create -- create-tsrouter-app@latest TARGET_DIR --framework react',
customCommand: 'npm create tsrouter-app@latest -- TARGET_DIR --framework react',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, let me try that!

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}`);
});

@wobsoriano wobsoriano marked this pull request as ready for review March 4, 2025 20:09
@sapphi-red sapphi-red changed the title feat(create-vite): Add TanStack Router commands feat(create-vite): add TanStack Router commands Mar 5, 2025
@sapphi-red sapphi-red added p2-nice-to-have Not breaking anything but nice to have (priority) feat: create-vite create-vite package labels Mar 5, 2025
@sapphi-red sapphi-red added this to the 6.3 milestone Mar 6, 2025
@sapphi-red
Copy link
Member

@wobsoriano We are planning to merge this PR in the next few days. Just to be sure, please let me know if the CLI has changed in the last weeks and this PR needs to be changed as well.

@wobsoriano
Copy link
Contributor Author

wobsoriano commented Mar 19, 2025

@wobsoriano We are planning to merge this PR in the next few days. Just to be sure, please let me know if the CLI has changed in the last weeks and this PR needs to be changed as well.

Both still works and has the correct format 👍🏼

@patak-cat patak-cat merged commit e49a3b5 into vitejs:main Mar 20, 2025
15 checks passed
moonlitusun pushed a commit to moonlitusun/vite that referenced this pull request May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: create-vite create-vite package p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants