-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
base: main
Are you sure you want to change the base?
feat(create-vite): add TanStack Router commands #19573
Conversation
packages/create-vite/src/index.ts
Outdated
name: 'custom-tanstack-router', | ||
display: 'TanStack Router ↗', | ||
color: cyan, | ||
customCommand: 'npm create -- create-tsrouter-app@latest TARGET_DIR --framework react', |
There was a problem hiding this comment.
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?
customCommand: 'npm create -- create-tsrouter-app@latest TARGET_DIR --framework react', | |
customCommand: 'npm create tsrouter-app@latest -- TARGET_DIR --framework react', |
There was a problem hiding this comment.
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!
packages/create-vite/src/index.ts
Outdated
name: 'custom-tanstack-router', | ||
display: 'TanStack Router ↗', | ||
color: cyan, | ||
customCommand: 'npm create -- tsrouter-app@latest TARGET_DIR --framework react', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
vite/packages/create-vite/src/index.ts
Lines 609 to 616 in c0e68da
.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 ` | |
}) |
There was a problem hiding this comment.
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}`);
});
Description
This PR adds commands to create a new TanStack Router app based on the create-tsrouter-app CLI.