@@ -5,21 +5,53 @@ import type { PackageManager } from '../types/pm.js';
55import { RepackInitError } from '../utils/error.js' ;
66import spinner from '../utils/spinner.js' ;
77
8+ function getCreateCommand ( packageManager : PackageManager ) {
9+ if ( packageManager . name === 'npm' ) {
10+ // Use `npm exec` with the package's explicit bin name. Nested `npx`
11+ // invocations can fail when repack-init itself is launched through `npx`.
12+ return {
13+ command : packageManager . runCommand ,
14+ args : [
15+ 'exec' ,
16+ '--yes' ,
17+ '--package' ,
18+ '@react-native-community/cli@latest' ,
19+ '--' ,
20+ 'rnc-cli' ,
21+ ] ,
22+ shell : false ,
23+ } ;
24+ }
25+
26+ return {
27+ command : packageManager . dlxCommand ,
28+ args : [ '@react-native-community/cli@latest' ] ,
29+ shell : true ,
30+ } ;
31+ }
32+
33+ function getReactNativeVersion ( ) {
34+ const version = versionsJson [ 'react-native' ] ;
35+
36+ return / ^ \d + \. \d + $ / . test ( version ) ? `${ version } .0` : version ;
37+ }
38+
839export default async function createNewProject (
940 cwd : string ,
1041 projectName : string ,
1142 packageManager : PackageManager ,
1243 override : boolean
1344) {
1445 try {
46+ const createCommand = getCreateCommand ( packageManager ) ;
1547 const args = [
16- '@react-native-community/cli@latest' ,
48+ ... createCommand . args ,
1749 'init' ,
1850 projectName ,
1951 '--directory' ,
2052 path . join ( cwd , projectName ) ,
2153 '--version' ,
22- versionsJson [ 'react-native' ] ,
54+ getReactNativeVersion ( ) ,
2355 '--skip-install' ,
2456 '--skip-git-init' ,
2557 ] ;
@@ -32,9 +64,9 @@ export default async function createNewProject(
3264 'Creating new project from the React Native Community Template'
3365 ) ;
3466
35- return await execa ( packageManager . dlxCommand , args , {
67+ return await execa ( createCommand . command , args , {
3668 stdio : 'ignore' ,
37- shell : true ,
69+ shell : createCommand . shell ,
3870 } ) ;
3971 } catch {
4072 throw new RepackInitError (
0 commit comments