@@ -19,11 +19,7 @@ import {
1919 copyTemplate ,
2020 executePostInitScript ,
2121} from './template' ;
22- import {
23- changePlaceholderInTemplate ,
24- updateDependencies ,
25- normalizeReactNativeDeps ,
26- } from './editTemplate' ;
22+ import { changePlaceholderInTemplate } from './editTemplate' ;
2723import * as PackageManager from '../../tools/packageManager' ;
2824import banner from './banner' ;
2925import TemplateAndVersionError from './errors/TemplateAndVersionError' ;
@@ -220,7 +216,6 @@ async function createFromTemplate({
220216 installCocoaPods,
221217 replaceDirectory,
222218 yarnConfigOptions,
223- version,
224219} : TemplateOptions ) : Promise < TemplateReturnType > {
225220 logger . debug ( 'Initializing new project' ) ;
226221 // Only print out the banner if we're not in a CI
@@ -291,35 +286,6 @@ async function createFromTemplate({
291286 packageName,
292287 } ) ;
293288
294- // Update the react-native dependency if using the new @react-native-community/template.
295- // We can figure this out as it ships with [email protected] set to a dummy version. 296- const templatePackageJson = JSON . parse (
297- fs . readFileSync ( path . join ( process . cwd ( ) , 'package.json' ) , 'utf8' ) ,
298- ) ;
299- if ( templatePackageJson . dependencies ?. [ 'react-native' ] === '1000.0.0' ) {
300- // Since 0.75, the version of all @react-native/ packages are pinned to the version of
301- // react native. Enforce this when updating versions.
302- const concreteVersion = await npmResolveConcreteVersion (
303- 'react-native' ,
304- version ,
305- ) ;
306- updateDependencies ( {
307- dependencies : {
308- 'react-native' : concreteVersion ,
309- ...normalizeReactNativeDeps (
310- templatePackageJson . dependencies ,
311- concreteVersion ,
312- ) ,
313- } ,
314- devDependencies : {
315- ...normalizeReactNativeDeps (
316- templatePackageJson . devDependencies ,
317- concreteVersion ,
318- ) ,
319- } ,
320- } ) ;
321- }
322-
323289 if ( packageManager === 'yarn' && shouldBumpYarnVersion ) {
324290 await bumpYarnVersion ( false , projectDirectory ) ;
325291 }
@@ -462,11 +428,20 @@ async function createTemplateUri(
462428 version ,
463429 ) ;
464430
431+ const validSemverVersion = semver . coerce ( version ) ?. version ;
432+
433+ if ( validSemverVersion == null ) {
434+ logger . warn (
435+ `Version: '${ version } ' is in-valid semver, could not determine which template to used.` ,
436+ ) ;
437+ process . exit ( 1 ) ;
438+ }
439+
465440 // Test #2: Does the react-native@version package *not* have a template embedded. We know that
466441 // this applies to all version before 0.75. The 1st release candidate is the minimal
467442 // version that has no template.
468443 const useLegacyTemplate = semver . lt (
469- version ,
444+ validSemverVersion ,
470445 TEMPLATE_COMMUNITY_REACT_NATIVE_VERSION ,
471446 ) ;
472447
@@ -501,25 +476,32 @@ async function createProject(
501476) : Promise < TemplateReturnType > {
502477 // Handle these cases (when community template is published and react-native >= 0.75
503478 //
504- // +==================================================================+==========+==============+
505- // | Arguments | Template | React Native |
506- // +==================================================================+==========+==============+
507- // | <None> | latest | latest |
508- // +------------------------------------------------------------------+----------+--------------+
509- // | --version 0.75.0 | 0.75.0 | 0.75.0 |
510- // +------------------------------------------------------------------+----------+--------------+
511- // | --template @react-native-community/[email protected] | 0.75.1 | latest | 512- // +------------------------------------------------------------------+----------+--------------+
513- // | --template @react-native-community/[email protected] --version 0.75| 0.75.1 | 0.75.x | 514- // +------------------------------------------------------------------+----------+--------------+
479+ // +==================================================================+==========+===================+
480+ // | Arguments | Template | React Native |
481+ // +==================================================================+==========+===================+
482+ // | <None> | 0.74.x | 0.74.5 (latest) |
483+ // +------------------------------------------------------------------+----------+-------------------+
484+ // | --version next | 0.75.x | 0.75.0-rc.1 (next)|
485+ // +------------------------------------------------------------------+----------+-------------------+
486+ // | --version 0.75.0 | 0.75.x | 0.75.0 |
487+ // +------------------------------------------------------------------+----------+-------------------+
488+ // | --template @react-native-community/[email protected] | 0.75.1 | latest | 489+ // +------------------------------------------------------------------+----------+-------------------+
490+ // | --template @react-native-community/[email protected] --version 0.75| 0.75.1 | 0.75.x | 491+ // +------------------------------------------------------------------+----------+-------------------+
515492 //
516493 // 1. If you specify `--version 0.75.0` and `@react-native-community/[email protected] ` is *NOT* 517494 // published, then `init` will exit and suggest explicitly using the `--template` argument.
518495 //
519496 // 2. `--template` will always win over `--version` for the template.
520497 //
521498 // 3. For version < 0.75, the template ships with react-native.
522- const templateUri = await createTemplateUri ( options , version ) ;
499+ const v = semver . parse ( version ) ;
500+ if ( v == null ) {
501+ throw new Error ( `--version=${ version } isn't valid SEMVER` ) ;
502+ }
503+ const templateVersion = `${ v . major } .${ v . minor } ` ;
504+ const templateUri = await createTemplateUri ( options , templateVersion ) ;
523505
524506 return createFromTemplate ( {
525507 projectName,
0 commit comments