Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion js/react_native/app.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ const pkg = require('onnxruntime-react-native/package.json');
const path = require('path');
const fs = require('fs');

/**
* Converts directory path to node_modules to a relative path for the ios/Podfile file.
* @param {string} iosProjectRoot the ios/ directory path
* @param {string} packageRoot the node_modules/onnxruntime-react-native directory path
* @returns {string} the relative path to the packageRoot from the iosProjectRoot
*/
function toPodfileRelativePath(iosProjectRoot, packageRoot) {
const rel = path.relative(iosProjectRoot, packageRoot);
return rel ? rel.split(path.sep).join('/') : '.';
}

const withOrt = (config) => {
// Add build dependency to gradle file
config = configPlugin.withAppBuildGradle(config, (config) => {
Expand Down Expand Up @@ -79,9 +90,15 @@ const withOrt = (config) => {
(config) => {
const podFilePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
const contents = fs.readFileSync(podFilePath, { encoding: 'utf-8' });
const packageRoot = path.dirname(
require.resolve(`${pkg.name}/package.json`, {
paths: [config.modRequest.projectRoot],
})
);
const podPath = toPodfileRelativePath(config.modRequest.platformProjectRoot, packageRoot);
const updatedContents = generateCode.mergeContents({
src: contents,
newSrc: " pod 'onnxruntime-react-native', :path => '../node_modules/onnxruntime-react-native'",
newSrc: ` pod 'onnxruntime-react-native', :path => '${podPath}'`,
tag: 'onnxruntime-react-native',
anchor: /^target.+do$/,
offset: 1,
Expand Down