Skip to content

Commit e7cdde6

Browse files
klasbjmrmckeb
authored andcommitted
Support scoped templates (facebook#7991)
1 parent 58b4738 commit e7cdde6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/create-react-app/createReactApp.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,17 @@ function getTemplateInstallPackage(template, originalDirectory) {
647647
) {
648648
// for tar.gz or alternative paths
649649
templateToInstall = template;
650-
} else if (template.startsWith(templateToInstall)) {
651-
templateToInstall = template;
652-
} else if (!template.startsWith(templateToInstall)) {
653-
// Add prefix `cra-template` to non-prefixed templates.
654-
templateToInstall += `-${template}`;
650+
} else {
651+
// Add prefix 'cra-template-' to non-prefixed templates, leaving any
652+
// @scope/ intact.
653+
const packageMatch = template.match(/^(@[^/]+\/)?(.+)$/);
654+
const scope = packageMatch[1] || '';
655+
const templateName = packageMatch[2];
656+
657+
const name = templateName.startsWith(templateToInstall)
658+
? templateName
659+
: `${templateToInstall}-${templateName}`;
660+
templateToInstall = `${scope}${name}`;
655661
}
656662
}
657663

0 commit comments

Comments
 (0)