Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Podfile.lock paths are no longer absolute #1203

Merged
merged 6 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"editor.rulers": [80],
"editor.rulers": [
80
],
"files.exclude": {
"**/.git": true,
"**/node_modules": true,
Expand Down
1 change: 1 addition & 0 deletions packages/cli-types/src/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type IOSScriptPhase = ({script: string} | {path: string}) & {
* requirements of `native_modules.rb` change.
*/
export interface IOSNativeModulesConfig {
reactNativePath: string;
project: {
ios?: {
sourceDir: string;
Expand Down
12 changes: 8 additions & 4 deletions packages/platform-ios/native_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def use_native_modules!(config = nil)
Pod::UI.puts "Auto-linking React Native #{"module".pluralize(found_pods.size)} for target `#{current_target_definition.name}`: #{pods}"
end

config
absolute_react_native_path = Pathname.new(config["reactNativePath"])

{ :reactNativePath => absolute_react_native_path.relative_path_from(project_root).to_s }
end

# You can run the tests for this file by running:
Expand All @@ -133,6 +135,8 @@ def use_native_modules!(config = nil)
Pod::Config.instance.silent = true
end

return_values = []

podfile = Pod::Podfile.new do
if runInput["podsActivatedByUser"]
runInput["podsActivatedByUser"].each do |name|
Expand All @@ -141,15 +145,15 @@ def use_native_modules!(config = nil)
end
target 'iOS Target' do
platform :ios
use_native_modules!(runInput["dependencyConfig"])
return_values[0] = use_native_modules!(runInput["dependencyConfig"])
end
target 'macOS Target' do
platform :osx
use_native_modules!(runInput["dependencyConfig"])
return_values[1] = use_native_modules!(runInput["dependencyConfig"])
end
end

unless runInput["captureStdout"]
puts podfile.to_hash.to_json
puts podfile.to_hash.merge({ "return_values": return_values }).to_json
end
end
48 changes: 38 additions & 10 deletions packages/platform-ios/src/config/__tests__/native_modules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import hasbin from 'hasbin';

const SCRIPT_PATH = path.resolve(__dirname, '../../../native_modules.rb');
const FIXTURES_ROOT = path.resolve(__dirname, '../__fixtures__/native_modules');
const REACT_NATIVE_ROOT = '/root/app/node_modules/react-native';

interface Dependency {
path: string;
}

interface NativeModulesReturnValue {
reactNativePath: string;
}

interface TargetDefinition {
name: string;
abstract?: boolean;
Expand All @@ -21,8 +26,9 @@ interface TargetDefinition {
script_phases?: unknown[];
}

interface Podfile {
interface TestScriptOutput {
target_definitions: TargetDefinition[];
return_values: NativeModulesReturnValue[];
}

interface RunConfig {
Expand All @@ -31,8 +37,13 @@ interface RunConfig {
dependencyConfig: IOSNativeModulesConfig;
}

interface RunResult {
rootTargetDefinition: TargetDefinition;
returnValues: NativeModulesReturnValue[];
}

function run(runConfig: RunConfig) {
return new Promise<TargetDefinition | string>((resolve, reject) => {
return new Promise<RunResult | string>((resolve, reject) => {
const child = spawn('ruby', [SCRIPT_PATH]);
child.stdin.write(JSON.stringify(runConfig));
child.stdin.end();
Expand All @@ -50,8 +61,14 @@ function run(runConfig: RunConfig) {
if (runConfig.captureStdout) {
resolve(data.trimRight());
} else {
const podfile: Podfile = JSON.parse(data);
resolve(podfile.target_definitions[0]);
const {
target_definitions,
return_values,
}: TestScriptOutput = JSON.parse(data);
resolve({
rootTargetDefinition: target_definitions[0],
returnValues: return_values,
});
}
} else {
reject(Buffer.concat(stderrData).toString());
Expand Down Expand Up @@ -97,6 +114,7 @@ describeIfSupportedEnv()('native_modules.rb', () => {
beforeEach(() => {
runConfig = {
dependencyConfig: {
reactNativePath: REACT_NATIVE_ROOT,
project: {ios: {sourceDir: FIXTURES_ROOT}},
dependencies: {
'android-dep': {
Expand All @@ -110,14 +128,24 @@ describeIfSupportedEnv()('native_modules.rb', () => {
addDependency(runConfig, 'ios-dep');
});

it('returns relative path to a React Native location from source dir', () => {
return run(runConfig).then(({returnValues}: RunResult) => {
returnValues.forEach(rv => {
expect(rv.reactNativePath).toBe(
path.relative(FIXTURES_ROOT, REACT_NATIVE_ROOT),
);
});
});
});

describe('concerning platform specificity', () => {
beforeEach(() => {
addDependency(runConfig, 'macos-dep');
addDependency(runConfig, 'ios-and-macos-dep');
});

it('only activates pods that support iOS in targets that target `ios`', () => {
return run(runConfig).then((rootTargetDefinition: TargetDefinition) => {
return run(runConfig).then(({rootTargetDefinition}: RunResult) => {
expect(
rootTargetDefinition.children.find(
target => target.name === 'iOS Target',
Expand All @@ -144,7 +172,7 @@ describeIfSupportedEnv()('native_modules.rb', () => {
});

it('only activates pods that support macOS in targets that target `osx`', () => {
return run(runConfig).then((rootTargetDefinition: TargetDefinition) => {
return run(runConfig).then(({rootTargetDefinition}: RunResult) => {
expect(
rootTargetDefinition.children.find(
target => target.name === 'macOS Target',
Expand Down Expand Up @@ -173,7 +201,7 @@ describeIfSupportedEnv()('native_modules.rb', () => {

it('does not activate pods that were already activated previously (by the user in their Podfile)', () => {
runConfig.podsActivatedByUser = ['ios-dep'];
return run(runConfig).then(rootTargetDefinition => {
return run(runConfig).then(({rootTargetDefinition}: RunResult) => {
expect(rootTargetDefinition).toMatchInlineSnapshot(`
Object {
"abstract": true,
Expand Down Expand Up @@ -203,7 +231,7 @@ describeIfSupportedEnv()('native_modules.rb', () => {

it('does not activate pods whose root spec were already activated previously (by the user in their Podfile)', () => {
runConfig.podsActivatedByUser = ['ios-dep/foo/bar'];
return run(runConfig).then(rootTargetDefinition => {
return run(runConfig).then(({rootTargetDefinition}: RunResult) => {
expect(rootTargetDefinition).toMatchInlineSnapshot(`
Object {
"abstract": true,
Expand Down Expand Up @@ -253,7 +281,7 @@ describeIfSupportedEnv()('native_modules.rb', () => {
execution_position: 'before_compile',
},
];
return run(runConfig).then((rootTargetDefinition: TargetDefinition) => {
return run(runConfig).then(({rootTargetDefinition}: RunResult) => {
expect(rootTargetDefinition.children[0].script_phases)
.toMatchInlineSnapshot(`
Array [
Expand All @@ -277,7 +305,7 @@ describeIfSupportedEnv()('native_modules.rb', () => {
execution_position: 'before_compile',
},
];
return run(runConfig).then((rootTargetDefinition: TargetDefinition) => {
return run(runConfig).then(({rootTargetDefinition}: RunResult) => {
expect(rootTargetDefinition.children[0].script_phases)
.toMatchInlineSnapshot(`
Array [
Expand Down