Skip to content

Commit b22544c

Browse files
committed
fix(create): allow Rsbuild legacy template aliases
1 parent deb4220 commit b22544c

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

packages/cli/src/command-line.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,16 @@ export function validateLegacyCreateFlags(cliOptions: CliOptions): {
321321
} {
322322
const warnings: Array<string> = []
323323
const legacyTemplate = getLegacyTemplateValue(cliOptions.template)
324+
const isSupportedLegacyTemplate =
325+
legacyTemplate !== undefined &&
326+
SUPPORTED_LEGACY_TEMPLATES.has(legacyTemplate)
324327

325328
if (cliOptions.bundler?.toLowerCase() === 'rsbuild') {
326-
if (cliOptions.starter || cliOptions.template || cliOptions.templateId) {
329+
if (
330+
cliOptions.starter ||
331+
(cliOptions.template && !isSupportedLegacyTemplate) ||
332+
cliOptions.templateId
333+
) {
327334
return {
328335
warnings,
329336
error:
@@ -480,6 +487,9 @@ export async function normalizeOptions(
480487
const blank = cliOptions.blank === true
481488

482489
const legacyTemplate = getLegacyTemplateValue(cliOptions.template)
490+
const isSupportedLegacyTemplate =
491+
legacyTemplate !== undefined &&
492+
SUPPORTED_LEGACY_TEMPLATES.has(legacyTemplate)
483493

484494
if (!cliOptions.starter) {
485495
if (cliOptions.template && !legacyTemplate) {
@@ -507,7 +517,11 @@ export async function normalizeOptions(
507517
: (cliOptions.bundler ?? 'vite')
508518

509519
if (bundler === 'rsbuild') {
510-
if (cliOptions.starter || cliOptions.template || cliOptions.templateId) {
520+
if (
521+
cliOptions.starter ||
522+
(cliOptions.template && !isSupportedLegacyTemplate) ||
523+
cliOptions.templateId
524+
) {
511525
throw new Error('Rsbuild does not currently support templates.')
512526
}
513527
if (cliOptions.deployment || opts?.forcedDeployment) {

packages/cli/tests/command-line.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,40 @@ describe('normalizeOptions', () => {
634634
expect(options?.chosenAddOns.map((addOn) => addOn.id)).toEqual(['biome'])
635635
})
636636

637+
it.each([
638+
['file-router', false],
639+
['typescript', true],
640+
['tsx', true],
641+
])(
642+
'normalizes Rsbuild with the legacy %s template alias',
643+
async (template, routerOnly) => {
644+
__testRegisterFramework({
645+
id: 'react',
646+
name: 'React',
647+
bundlers: [
648+
{ id: 'vite', name: 'Vite', description: 'Build with Vite' },
649+
{
650+
id: 'rsbuild',
651+
name: 'Rsbuild',
652+
description: 'Build with Rsbuild',
653+
},
654+
],
655+
defaultBundler: 'vite',
656+
getAddOns: () => [],
657+
})
658+
659+
const options = await normalizeOptions({
660+
projectName: 'test',
661+
framework: 'react',
662+
bundler: 'rsbuild',
663+
template,
664+
})
665+
666+
expect(options?.bundler).toBe('rsbuild')
667+
expect(options?.routerOnly).toBe(routerOnly)
668+
},
669+
)
670+
637671
it('rejects unsupported Rsbuild add-ons during normalization', async () => {
638672
__testRegisterFramework({
639673
id: 'react',
@@ -816,6 +850,19 @@ describe('validateLegacyCreateFlags', () => {
816850
expect(result.error).toBeUndefined()
817851
})
818852

853+
it.each(['file-router', 'typescript', 'tsx'])(
854+
'allows Rsbuild with the legacy %s template alias',
855+
(template) => {
856+
const result = validateLegacyCreateFlags({
857+
bundler: 'rsbuild',
858+
template,
859+
})
860+
861+
expect(result.error).toBeUndefined()
862+
expect(result.warnings[0]).toContain('--template')
863+
},
864+
)
865+
819866
it.each([
820867
[{ starter: 'ecommerce' }, '--starter'],
821868
[{ template: 'ecommerce' }, '--template'],

0 commit comments

Comments
 (0)