Skip to content

Commit f940702

Browse files
authored
[generator-macos] Enable auto-linking of native modules (#312)
* [generator-macos] Guard against package.json not having scripts yet * [generator-macos] Enable auto-linking Currently uses @react-native-communit/cli-platform-ios, but this is mostly semantics as they work the same. In the future this will move into a cli-platform-apple package which will hold common iOS and macOS tooling.
1 parent a0e09ab commit f940702

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

local-cli/generator-macos/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ function installDependencies(options) {
134134

135135
// Patch package.json to have start:macos
136136
const projectPackageJsonPath = path.join(cwd, 'package.json');
137+
/** @type {{ scripts?: {} }} */
137138
const projectPackageJson = JSON.parse(fs.readFileSync(projectPackageJsonPath, { encoding: 'UTF8' }));
138-
projectPackageJson.scripts['start:macos'] = 'node node_modules/react-native-macos/local-cli/cli.js start --use-react-native-macos';
139+
const scripts = projectPackageJson.scripts || {};
140+
scripts['start:macos'] = 'node node_modules/react-native-macos/local-cli/cli.js start --use-react-native-macos';
141+
projectPackageJson.scripts = scripts;
139142
fs.writeFileSync(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2));
140143

141144
// Install dependencies using correct package manager

local-cli/generator-macos/templates/macos/Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
1+
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
22

33
abstract_target 'Shared' do
4-
# use_native_modules!
4+
use_native_modules!
55

66
pod 'React', :path => "../node_modules/react-native-macos/"
77
pod 'React-Core', :path => "../node_modules/react-native-macos/React"

0 commit comments

Comments
 (0)