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

[document-picker] Update to use codesigning variables in entitlements #17158

Merged
merged 4 commits into from Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/expo-document-picker/CHANGELOG.md
Expand Up @@ -10,6 +10,8 @@

### 💡 Others

- [plugin] Update to use codesigning variables in entitlements. ([#17158](https://github.com/expo/expo/pull/17158) by [@EvanBacon](https://github.com/EvanBacon))

## 10.2.0 — 2022-04-18

### 💡 Others
Expand Down
13 changes: 3 additions & 10 deletions packages/expo-document-picker/README.md
Expand Up @@ -31,7 +31,7 @@ No additional set up necessary.

### Plugin

In order to enable Apple iCloud storage in managed EAS builds, you'll need to define the `appleTeamId` property in the config plugin:
You can change the `com.apple.developer.icloud-container-environment` entitlement using the `iCloudContainerEnvironment` property.

`app.json`

Expand All @@ -41,18 +41,11 @@ In order to enable Apple iCloud storage in managed EAS builds, you'll need to de
"usesIcloudStorage": true,
"bundleIdentifier": "com.yourname.yourapp"
},
"plugins": [
[
"expo-document-picker",
{
"appleTeamId": "YOUR_TEAM_ID"
}
]
]
"plugins": ["expo-document-picker"]
}
```

> Running `expo eject` will generate a the native project locally with the applied changes in your iOS Entitlements file.
> Running `expo prebuild` will generate a the [native project locally](https://docs.expo.io/workflow/customizing/) with the applied changes in your iOS Entitlements file.

# Contributing

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -2,21 +2,24 @@ import { setICloudEntitlements } from '../withDocumentPickerIOS';

describe(setICloudEntitlements, () => {
it(`skips setting the iCloud entitlements if the flag isn't enabled`, () => {
expect(setICloudEntitlements({ ios: {} }, { appleTeamId: 'X1X2X3X4X' }, {})).toStrictEqual({});
expect(
setICloudEntitlements({ ios: {} }, { iCloudContainerEnvironment: 'Production' }, {})
).toStrictEqual({});
});
it(`sets the iCloud entitlements`, () => {
expect(
setICloudEntitlements(
{ ios: { usesIcloudStorage: true, bundleIdentifier: 'com.bacon.foobar' } },
{ appleTeamId: 'X1X2X3X4X', iCloudContainerEnvironment: 'Production' },
{ iCloudContainerEnvironment: 'Production' },
{}
)
).toStrictEqual({
'com.apple.developer.icloud-container-environment': 'Production',
'com.apple.developer.icloud-container-identifiers': ['iCloud.com.bacon.foobar'],
'com.apple.developer.icloud-container-identifiers': ['iCloud.$(CFBundleIdentifier)'],
'com.apple.developer.icloud-services': ['CloudDocuments'],
'com.apple.developer.ubiquity-container-identifiers': ['iCloud.com.bacon.foobar'],
'com.apple.developer.ubiquity-kvstore-identifier': 'X1X2X3X4X.com.bacon.foobar',
'com.apple.developer.ubiquity-container-identifiers': ['iCloud.$(CFBundleIdentifier)'],
'com.apple.developer.ubiquity-kvstore-identifier':
'$(TeamIdentifierPrefix)$(CFBundleIdentifier)',
});
});
});
14 changes: 3 additions & 11 deletions packages/expo-document-picker/plugin/src/withDocumentPicker.ts
@@ -1,15 +1,7 @@
import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';
import { createRunOncePlugin } from '@expo/config-plugins';

import { withDocumentPickerIOS, IosProps } from './withDocumentPickerIOS';
import { withDocumentPickerIOS } from './withDocumentPickerIOS';

const pkg = require('expo-document-picker/package.json');

const withDocumentPicker: ConfigPlugin<IosProps | void> = (
config,
{ appleTeamId = process.env.EXPO_APPLE_TEAM_ID, iCloudContainerEnvironment } = {}
) => {
config = withDocumentPickerIOS(config, { appleTeamId, iCloudContainerEnvironment });
return config;
};

export default createRunOncePlugin(withDocumentPicker, pkg.name, pkg.version);
export default createRunOncePlugin(withDocumentPickerIOS, pkg.name, pkg.version);
31 changes: 12 additions & 19 deletions packages/expo-document-picker/plugin/src/withDocumentPickerIOS.ts
@@ -1,8 +1,7 @@
import { ConfigPlugin, WarningAggregator, withEntitlementsPlist } from '@expo/config-plugins';
import { ConfigPlugin, withEntitlementsPlist } from '@expo/config-plugins';
import { ExpoConfig } from '@expo/config-types';

export type IosProps = {
appleTeamId?: string;
/**
* Sets the `com.apple.developer.icloud-container-environment` entitlement which is read by EAS CLI to set
* the `iCloudContainerEnvironment` in the `xcodebuild` `exportOptionsPlist`.
Expand All @@ -14,28 +13,21 @@ export type IosProps = {

export const withDocumentPickerIOS: ConfigPlugin<IosProps> = (
config,
{ appleTeamId, iCloudContainerEnvironment }
{ iCloudContainerEnvironment }
) => {
return withEntitlementsPlist(config, (config) => {
if (appleTeamId) {
config.modResults = setICloudEntitlements(
config,
{ appleTeamId, iCloudContainerEnvironment },
config.modResults
);
} else {
WarningAggregator.addWarningIOS(
'expo-document-picker',
'Cannot configure iOS entitlements because neither the appleTeamId property, nor the environment variable EXPO_APPLE_TEAM_ID were defined.'
);
}
config.modResults = setICloudEntitlements(
config,
{ iCloudContainerEnvironment },
config.modResults
);
return config;
});
};

export function setICloudEntitlements(
config: Pick<ExpoConfig, 'ios'>,
{ appleTeamId, iCloudContainerEnvironment }: IosProps,
{ iCloudContainerEnvironment }: IosProps,
{ 'com.apple.developer.icloud-container-environment': _env, ...entitlements }: Record<string, any>
): Record<string, any> {
if (config.ios?.usesIcloudStorage) {
Expand All @@ -44,13 +36,14 @@ export function setICloudEntitlements(
entitlements['com.apple.developer.icloud-container-environment'] = iCloudContainerEnvironment;

entitlements['com.apple.developer.icloud-container-identifiers'] = [
'iCloud.' + config.ios.bundleIdentifier,
'iCloud.$(CFBundleIdentifier)',
];
entitlements['com.apple.developer.ubiquity-container-identifiers'] = [
'iCloud.' + config.ios.bundleIdentifier,
'iCloud.$(CFBundleIdentifier)',
];
entitlements['com.apple.developer.ubiquity-kvstore-identifier'] =
appleTeamId + '.' + config.ios.bundleIdentifier;
'$(TeamIdentifierPrefix)$(CFBundleIdentifier)';

entitlements['com.apple.developer.icloud-services'] = ['CloudDocuments'];
}
return entitlements;
Expand Down