Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

wobsoriano
Copy link

@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
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
Author

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 a too many arguments 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
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
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