MCPcopy Create free account
hub / github.com/react/create-react-app / getInstallPackage

Function getInstallPackage

packages/create-react-app/createReactApp.js:547–595  ·  view source on GitHub ↗
(version, originalDirectory)

Source from the content-addressed store, hash-verified

545}
546
547function getInstallPackage(version, originalDirectory) {
548 let packageToInstall = 'react-scripts';
549 const validSemver = semver.valid(version);
550 if (validSemver) {
551 packageToInstall += `@${validSemver}`;
552 } else if (version) {
553 if (version[0] === '@' && !version.includes('/')) {
554 packageToInstall += version;
555 } else if (version.match(/^file:/)) {
556 packageToInstall = `file:${path.resolve(
557 originalDirectory,
558 version.match(/^file:(.*)?$/)[1]
559 )}`;
560 } else {
561 // for tar.gz or alternative paths
562 packageToInstall = version;
563 }
564 }
565
566 const scriptsToWarn = [
567 {
568 name: 'react-scripts-ts',
569 message: chalk.yellow(
570 `The react-scripts-ts package is deprecated. TypeScript is now supported natively in Create React App. You can use the ${chalk.green(
571 '--template typescript'
572 )} option instead when generating your app to include TypeScript support. Would you like to continue using react-scripts-ts?`
573 ),
574 },
575 ];
576
577 for (const script of scriptsToWarn) {
578 if (packageToInstall.startsWith(script.name)) {
579 return prompts({
580 type: 'confirm',
581 name: 'useScript',
582 message: script.message,
583 initial: false,
584 }).then(answer => {
585 if (!answer.useScript) {
586 process.exit(0);
587 }
588
589 return packageToInstall;
590 });
591 }
592 }
593
594 return Promise.resolve(packageToInstall);
595}
596
597function getTemplateInstallPackage(template, originalDirectory) {
598 let templateToInstall = 'cra-template';

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected