| 819 | } |
| 820 | |
| 821 | function checkAppName(appName) { |
| 822 | const validationResult = validateProjectName(appName); |
| 823 | if (!validationResult.validForNewPackages) { |
| 824 | console.error( |
| 825 | chalk.red( |
| 826 | `Cannot create a project named ${chalk.green( |
| 827 | `"${appName}"` |
| 828 | )} because of npm naming restrictions:\n` |
| 829 | ) |
| 830 | ); |
| 831 | [ |
| 832 | ...(validationResult.errors || []), |
| 833 | ...(validationResult.warnings || []), |
| 834 | ].forEach(error => { |
| 835 | console.error(chalk.red(` * ${error}`)); |
| 836 | }); |
| 837 | console.error(chalk.red('\nPlease choose a different project name.')); |
| 838 | process.exit(1); |
| 839 | } |
| 840 | |
| 841 | // TODO: there should be a single place that holds the dependencies |
| 842 | const dependencies = ['react', 'react-dom', 'react-scripts'].sort(); |
| 843 | if (dependencies.includes(appName)) { |
| 844 | console.error( |
| 845 | chalk.red( |
| 846 | `Cannot create a project named ${chalk.green( |
| 847 | `"${appName}"` |
| 848 | )} because a dependency with the same name exists.\n` + |
| 849 | `Due to the way npm works, the following names are not allowed:\n\n` |
| 850 | ) + |
| 851 | chalk.cyan(dependencies.map(depName => ` ${depName}`).join('\n')) + |
| 852 | chalk.red('\n\nPlease choose a different project name.') |
| 853 | ); |
| 854 | process.exit(1); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | function makeCaretRange(dependencies, name) { |
| 859 | const version = dependencies[name]; |