Skip to content

Commit

Permalink
feat(breaking): use 'podspecPath' instead of 'podspec', make it smart…
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee authored Jun 24, 2019
1 parent 9a63f86 commit c6ad37d
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 97 deletions.
8 changes: 4 additions & 4 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following settings are available on iOS and Android:
```ts
type DependencyParamsIOST = {
project?: string;
podspec?: string;
podspecPath?: string;
sharedLibraries?: string[];
};

Expand All @@ -70,11 +70,11 @@ type DependencyParamsAndroidT = {

#### platforms.ios.project

Custom path to `.xcodeproj`
Custom path to `.xcodeproj`.

#### platforms.ios.podspec
#### platforms.ios.podspecPath

Custom `podspec` name to use when auto-linking (without the file extension). Your `podspec` file must be located in the root of the dependency package.
Custom path to `.podspec` file to use when auto-linking. Example: `node_modules/react-native-module/ios/module.podspec`.

#### platforms.ios.sharedLibraries

Expand Down
2 changes: 1 addition & 1 deletion docs/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type ProjectConfigIOST = {
folder: string;
pbxprojPath: string;
podfile: null;
podspec: null;
podspecPath: null;
projectPath: string;
projectName: string;
libraryFolder: string;
Expand Down
1 change: 1 addition & 0 deletions docs/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type ProjectParamsAndroidT = {

type ProjectParamsIOST = {
project?: string;
podspecPath?: string;
sharedLibraries?: string[];
libraryFolder?: string;
plist: any[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Object {
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj",
"plist": Array [],
"podfile": null,
"podspec": null,
"podspecPath": null,
"projectName": "HelloWorld.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
"sharedLibraries": Array [],
Expand Down Expand Up @@ -125,7 +125,7 @@ Object {
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-foo/customLocation/customProject.xcodeproj/project.pbxproj",
"plist": Array [],
"podfile": null,
"podspec": null,
"podspecPath": null,
"projectName": "customProject.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-foo/customLocation/customProject.xcodeproj",
"sharedLibraries": Array [],
Expand Down Expand Up @@ -164,7 +164,7 @@ Object {
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/customLocation/customProject.xcodeproj/project.pbxproj",
"plist": Array [],
"podfile": null,
"podspec": "ReactNativeTest",
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
"projectName": "customProject.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-test/customLocation/customProject.xcodeproj",
"sharedLibraries": Array [],
Expand Down Expand Up @@ -201,7 +201,7 @@ Object {
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj",
"plist": Array [],
"podfile": null,
"podspec": null,
"podspecPath": null,
"projectName": "HelloWorld.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
"sharedLibraries": Array [],
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/tools/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const dependencyConfig = t
ios: t
.object({
project: t.string(),
podspec: t.string(),
podspecPath: t.string(),
sharedLibraries: t.array().items(t.string()),
libraryFolder: t.string(),
})
Expand Down Expand Up @@ -113,7 +113,7 @@ export const projectConfig = t
folder: t.string(),
pbxprojPath: t.string(),
podfile: t.string(),
podspec: t.string(),
podspecPath: t.string(),
projectPath: t.string(),
projectName: t.string(),
libraryFolder: t.string(),
Expand Down
12 changes: 6 additions & 6 deletions packages/platform-ios/native_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def use_native_modules!(root = "..", packages = nil)
packages.each do |package_name, package|
next unless package_config = package["platforms"]["ios"]

podspec_path = File.join(package["root"], "#{package_config["podspec"]}.podspec")
podspec_path = package_config["podspecPath"]
spec = Pod::Specification.from_file(podspec_path)

# We want to do a look up inside the current CocoaPods target
Expand All @@ -57,7 +57,7 @@ def use_native_modules!(root = "..", packages = nil)
existing_dep.name.split('/').first == spec.name
end

pod spec.name, :path => package["root"]
pod spec.name, :path => File.dirname(podspec_path)

if package_config["scriptPhases"]
# Can be either an object, or an array of objects
Expand Down Expand Up @@ -126,16 +126,16 @@ def pluralize(count)
}

@ios_package = ios_package = {
"root" => "/Users/grabbou/Repositories/WebViewDemoApp/node_modules/react",
"root" => "/root/app/node_modules/react",
"platforms" => {
"ios" => {
"podspec" => "React",
"podspecPath" => "/root/app/node_modules/react/React.podspec",
},
"android" => nil,
},
}
@android_package = {
"root" => "/Users/grabbou/Repositories/WebViewDemoApp/node_modules/react-native-google-play-game-services",
"root" => "/root/app/node_modules/react-native-google-play-game-services",
"platforms" => {
"ios" => nil,
"android" => {
Expand All @@ -160,7 +160,7 @@ def pluralize(count)
end

Pod::Specification.singleton_class.send(:define_method, :from_file) do |podspec_path|
podspec_path.must_equal File.join(ios_package["root"], "#{ios_package["platforms"]["ios"]["podspec"]}.podspec")
podspec_path.must_equal ios_package["platforms"]["ios"]["podspecPath"]
spec
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+javascript_foundation
* @flow
*/

import findPodspecName from '../findPodspecName';
import findPodspec from '../findPodspec';
import * as projects from '../__fixtures__/projects';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');

describe('ios::findPodspecName', () => {
describe('ios::findPodspec', () => {
it('returns null if there is not podspec file', () => {
// $FlowFixMe
fs.__setMockFilesystem(projects.flat);
expect(findPodspecName('')).toBeNull();
expect(findPodspec('')).toBeNull();
});

it('returns podspec name if only one exists', () => {
// $FlowFixMe
fs.__setMockFilesystem(projects.withPods.ios);
expect(findPodspecName('/')).toBe('TestPod');
expect(findPodspec('/')).toBe('/TestPod.podspec');
});

it('returns podspec name that match packet directory', () => {
// $FlowFixMe
fs.__setMockFilesystem({
user: {
PacketName: {
Expand All @@ -36,10 +38,13 @@ describe('ios::findPodspecName', () => {
},
},
});
expect(findPodspecName('/user/PacketName')).toBe('PacketName');
expect(findPodspec('/user/PacketName')).toBe(
'/user/PacketName/PacketName.podspec',
);
});

it('returns first podspec name if not match in directory', () => {
// $FlowFixMe
fs.__setMockFilesystem({
user: {
packet: {
Expand All @@ -48,6 +53,6 @@ describe('ios::findPodspecName', () => {
},
},
});
expect(findPodspecName('/user/packet')).toBe('Another');
expect(findPodspec('/user/packet')).toBe('/user/packet/Another.podspec');
});
});
21 changes: 21 additions & 0 deletions packages/platform-ios/src/config/findPodspec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @flow
*/

import glob from 'glob';
import path from 'path';

export default function findPodspec(folder: string): string | null {
const podspecs = glob.sync('*.podspec', {cwd: folder});

if (podspecs.length === 0) {
return null;
}

const packagePodspec = path.basename(folder) + '.podspec';
const podspecFile = podspecs.includes(packagePodspec)
? packagePodspec
: podspecs[0];

return path.join(folder, podspecFile);
}
34 changes: 0 additions & 34 deletions packages/platform-ios/src/config/findPodspecName.js

This file was deleted.

13 changes: 13 additions & 0 deletions packages/platform-ios/src/config/getPodspecName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import path from 'path';

export default function getPodspecName(podspecFile: string) {
return path.basename(podspecFile).replace(/\.podspec$/, '');
}
12 changes: 9 additions & 3 deletions packages/platform-ios/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import path from 'path';
import findProject from './findProject';
import findPodfilePath from './findPodfilePath';
import findPodspecName from './findPodspecName';
import findPodspec from './findPodspec';
import type {UserConfigT} from 'types';

/**
Expand Down Expand Up @@ -47,13 +47,19 @@ export function projectConfig(
}

const projectPath = path.join(folder, project);
const sourceDir = path.dirname(projectPath);

return {
sourceDir: path.dirname(projectPath),
sourceDir,
folder,
pbxprojPath: path.join(projectPath, 'project.pbxproj'),
podfile: findPodfilePath(projectPath),
podspec: userConfig.podspec || findPodspecName(folder),
podspecPath:
userConfig.podspecPath ||
// podspecs are usually placed in the root dir of the library or in the
// iOS project path
findPodspec(folder) ||
findPodspec(sourceDir),
projectPath,
projectName: path.basename(projectPath),
libraryFolder: userConfig.libraryFolder || 'Libraries',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ const PODFILES_PATH = path.join(__dirname, '../__fixtures__/');
describe('pods::isInstalled', () => {
it('returns false if pod is missing', () => {
const project = {podfile: path.join(PODFILES_PATH, 'PodfileSimple')};
const podspecName = {podspec: 'NotExisting'};
const podspecName = {podspecPath: '/path/NotExisting'};
expect(isInstalled(project, podspecName)).toBe(false);
});

it('returns true for existing pod with version number', () => {
const project = {podfile: path.join(PODFILES_PATH, 'PodfileSimple')};
const podspecName = {podspec: 'TestPod'};
const podspecName = {podspecPath: '/path/TestPod.podspec'};
expect(isInstalled(project, podspecName)).toBe(true);
});

it('returns true for existing pod with path', () => {
const project = {podfile: path.join(PODFILES_PATH, 'PodfileWithTarget')};
const podspecName = {podspec: 'Yoga'};
const podspecName = {podspecPath: '/path/Yoga.podspec'};
expect(isInstalled(project, podspecName)).toBe(true);
});

it('returns true for existing pod with multiline definition', () => {
const project = {
podfile: path.join(PODFILES_PATH, 'PodfileWithFunction'),
};
const podspecName = {podspec: 'React'};
const podspecName = {podspecPath: '/path/React.podspec'};
expect(isInstalled(project, podspecName)).toBe(true);
});
});
16 changes: 10 additions & 6 deletions packages/platform-ios/src/link-pods/addPodEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

import {logger} from '@react-native-community/cli-tools';
import getPodspecName from '../config/getPodspecName';

export default function addPodEntry(
podLines,
linesToAddEntry,
podName,
nodePath,
podLines: Array<string>,
linesToAddEntry?:
| Array<{line: number, indentation: number}>
| {line: number, indentation: number},
podspecPath: string,
nodeModulePath: string,
) {
const newEntry = `pod '${podName}', :path => '../node_modules/${nodePath}'\n`;
const podName = getPodspecName(podspecPath);
const newEntry = `pod '${podName}', :path => '../node_modules/${nodeModulePath}'\n`;

if (!linesToAddEntry) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

export const MARKER_TEXT = '# Add new pods below this line';

export default function findMarkedLinesInPodfile(podLines) {
export default function findMarkedLinesInPodfile(podLines: Array<string>) {
const result = [];
for (let i = 0, len = podLines.length; i < len; i++) {
if (podLines[i].includes(MARKER_TEXT)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/platform-ios/src/link-pods/isInstalled.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
*/

import readPodfile from './readPodfile';
import getPodspecName from '../config/getPodspecName';

export default function isInstalled(iOSProject, dependencyConfig) {
if (!iOSProject.podfile) {
return false;
}
// match line with pod declaration: pod 'dependencyPodName' (other possible parameters of pod are ignored)
const dependencyRegExp = new RegExp(
`pod\\s+('|")${dependencyConfig.podspec}('|")`,
`pod\\s+('|")${getPodspecName(dependencyConfig.podspecPath)}('|")`,
'g',
);
const podLines = readPodfile(iOSProject.podfile);
Expand Down
Loading

0 comments on commit c6ad37d

Please sign in to comment.