Skip to content

Commit

Permalink
Clean up entitlements (#41)
Browse files Browse the repository at this point in the history
* Lets try autogenerating the entitlements instead

* Clean up project

* Add INTERNALLY_TEST_PREBUILD

* Fix type errors

* Clean up entitlements in project

* Add createExpoTargetConfig

* Bun install

* Add node for swift-test

* Update getAppGroupFromExpoConfig export import

* Add bundle-example and config-example tests to CI

* Try with more specific path to hashFiles

* Bump some workflow actions

* Add prebuild CI check

* Publish 0.2.3, use npx to publish

* remove unsupported cache

* Add prepublishOnly

* Remove packageManager field
  • Loading branch information
robertherber authored Jan 29, 2025
1 parent 570f065 commit 55ae2b5
Show file tree
Hide file tree
Showing 31 changed files with 207 additions and 245 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
Expand All @@ -41,18 +41,16 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
cache: bun
registry-url: https://registry.npmjs.org/
scope: '@kingstinct'
- uses: actions/setup-node@v4

- run: git config user.name "$(git log -n 1 --pretty=format:%an)"
- run: git config user.email "$(git log -n 1 --pretty=format:%ae)"
- run: echo "versionTag=`npm version ${{ github.event.inputs.release_type }} -m "%s ${{ github.event.inputs.description }}"`" >> $GITHUB_ENV

- run: bun install

- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ on:

jobs:
preview:
name: Preview (pkg-pr-new)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- uses: actions/setup-node@v4
with:
registry-url: https://registry.npmjs.org/
scope: '@kingstinct'

- run: bun install

- run: bun run prepublishOnly

- run: bunx pkg-pr-new publish
- run: npx pkg-pr-new publish
79 changes: 72 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ on:

jobs:
lint:
name: eslint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
Expand All @@ -21,9 +22,10 @@ jobs:
- run: bun lint

typecheck:
name: Typecheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
Expand All @@ -34,9 +36,10 @@ jobs:
- run: bun typecheck

typecheck-example:
name: Typecheck (example project)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
Expand All @@ -50,10 +53,65 @@ jobs:
- run: bun typecheck
working-directory: example

bundle-example:
name: Expo Bundle (example project)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- run: bun install

- run: bun install
working-directory: example

- run: bunx expo export
working-directory: example

config-example:
name: Expo Config (example project)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- run: bun install

- run: bun install
working-directory: example

- run: bunx expo config
working-directory: example

prebuild-example:
name: Expo Prebuild (example project)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- run: bun install

- run: bun install
working-directory: example

- run: bunx expo prebuild
working-directory: example

swift-lint:
name: SwiftLint (example project)
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
Expand All @@ -62,9 +120,11 @@ jobs:
- uses: actions/cache@v4
with:
path: example/ios/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
key: ${{ runner.os }}-pods-${{ hashFiles('example/ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
- run: bun install

- run: bun install
working-directory: example
Expand All @@ -75,9 +135,14 @@ jobs:
- run: example/ios/Pods/SwiftLint/swiftlint lint

swift-test:
name: Swift Test (example project)
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22

- uses: oven-sh/setup-bun@v2
with:
Expand All @@ -88,7 +153,7 @@ jobs:
- uses: actions/cache@v4
with:
path: example/ios/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
key: ${{ runner.os }}-pods-${{ hashFiles('example/ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ The example project is linked specifically to simplify development. This means i
- The swift files in the targets folder are linked to the root project instead of duplicated. If adding new swift files, try to link them instead of duplicating to keep things clean.
- The entitlements and info.plist files however duplicated - to not mess with the example project/signing etc.
- There is a Shared.swift file that can be accessed by all targets. This is linked to each target in the example project, but in the published package it's copied and duplicated to each target. I prefer this to making more changes in @bacons/xcode package which only supports swift files on the root level of each target directory.
- In addition the example project contains an XCode test target as well as SwiftLint.

## Prebuild
To try out prebuild functionality (i.e. the config plugin) run `npm run prebuild` in the example project (it uses the `INTERNALLY_TEST_PREBUILD` env variable to behave like a published package). This should be used to verify changes are expected, but the result should not in it's full state be commited to the example project, since it will break the DX of the example project as explained above.
12 changes: 3 additions & 9 deletions app.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const { createRunOncePlugin } = require("expo/config-plugins");
const withCopyTargetFolder = require("./config-plugin/withCopyTargetFolder");
const withEntitlementsPlugin = require("./config-plugin/withEntitlements");
const withInfoPlistAppGroup = require("./config-plugin/withInfoPlistAppGroup");
const {
withTargetEntitlements,
} = require("./config-plugin/withTargetEntitlements");
const withXcodeSettings = require("./config-plugin/withXCodeSettings");
const pkg = require("./package.json");

Expand All @@ -20,12 +17,9 @@ const withActivityMonitorExtensionPlugin = (config, props) => {
}

return withXcodeSettings(
withEntitlementsPlugin(
withInfoPlistAppGroup(
withTargetsDir(
withTargetEntitlements(withCopyTargetFolder(config, props), props),
),
props,
withInfoPlistAppGroup(
withTargetsDir(
withEntitlementsPlugin(withCopyTargetFolder(config, props), props),
),
props,
),
Expand Down
24 changes: 24 additions & 0 deletions config-plugin/createExpoTargetConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const getAppGroupFromExpoConfig = require("./getAppGroupFromExpoConfig");

/**
* Creates a configuration function for Apple target extensions
* @param {('shield-action' | 'shield-configuration' | 'device-activity-monitor')} targetType - The type of target extension
* @returns {import('@kingstinct/expo-apple-targets/build/config-plugin').ConfigFunction}
*/
const createConfig = (targetType) => {
/** @type {import('@kingstinct/expo-apple-targets/build/config-plugin').ConfigFunction} */
const config = (config) => {
const appGroup = getAppGroupFromExpoConfig(config);

return {
type: targetType,
entitlements: {
"com.apple.developer.family-controls": true,
"com.apple.security.application-groups": [appGroup],
},
};
};
return config;
};

module.exports = { createConfig };
31 changes: 31 additions & 0 deletions config-plugin/getAppGroupFromExpoConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Extracts the app group from Expo config
* @param {import("expo/config").ExpoConfig} config - The Expo config object
* @returns {string|undefined} The app group identifier or undefined if not found
*/
const getAppGroupFromExpoConfig = (config) => {
const plugin = config.plugins?.find((plugin) => {
if (Array.isArray(plugin)) {
const [pluginName] = plugin;
return (
pluginName === "react-native-device-activity" ||
(process.env.INTERNALLY_TEST_PREBUILD &&
pluginName === "../app.plugin.js")
);
}

return null;
});

const { appGroup } = plugin?.[1] ?? {};

if (!appGroup) {
console.error(
"[react-native-device-activity] Required 'appGroup' property missing from Config Plugin",
);
}

return appGroup;
};

module.exports = getAppGroupFromExpoConfig;
7 changes: 2 additions & 5 deletions config-plugin/withCopyTargetFolder.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const fs = require("fs");

/** @type {import('@expo/config-plugins').ConfigPlugin<{ appGroup: string; copyToTargetFolder?: boolean }>} */
const withCopyTargetFolder = (
config,
{ appGroup, copyToTargetFolder = true },
) => {
if (!copyToTargetFolder) {
const withCopyTargetFolder = (config, { copyToTargetFolder = true }) => {
if (!copyToTargetFolder && !process.env.INTERNALLY_TEST_PREBUILD) {
return config;
}

Expand Down
35 changes: 0 additions & 35 deletions config-plugin/withExperimentalExpoAppExtensions.js

This file was deleted.

49 changes: 0 additions & 49 deletions config-plugin/withTargetEntitlements.js

This file was deleted.

2 changes: 1 addition & 1 deletion example/components/CreateActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as ReactNativeDeviceActivity from "react-native-device-activity";
import {
DeviceActivityEvent,
DeviceActivitySelectionEvent,
} from "react-native-device-activity/ReactNativeDeviceActivity.types";
} from "react-native-device-activity/src/ReactNativeDeviceActivity.types";
import { Button, Text, TextInput, Title, useTheme } from "react-native-paper";

const trackEveryXMinutes = 10;
Expand Down
Loading

0 comments on commit 55ae2b5

Please sign in to comment.