Skip to content

Commit

Permalink
Support scoped templates (#7991)
Browse files Browse the repository at this point in the history
  • Loading branch information
klasbj authored and mrmckeb committed Nov 18, 2019
1 parent 58b4738 commit e7cdde6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,17 @@ function getTemplateInstallPackage(template, originalDirectory) {
) {
// for tar.gz or alternative paths
templateToInstall = template;
} else if (template.startsWith(templateToInstall)) {
templateToInstall = template;
} else if (!template.startsWith(templateToInstall)) {
// Add prefix `cra-template` to non-prefixed templates.
templateToInstall += `-${template}`;
} else {
// Add prefix 'cra-template-' to non-prefixed templates, leaving any
// @scope/ intact.
const packageMatch = template.match(/^(@[^/]+\/)?(.+)$/);
const scope = packageMatch[1] || '';
const templateName = packageMatch[2];

const name = templateName.startsWith(templateToInstall)
? templateName
: `${templateToInstall}-${templateName}`;
templateToInstall = `${scope}${name}`;
}
}

Expand Down

0 comments on commit e7cdde6

Please sign in to comment.