Skip to content

Commit dc7ba26

Browse files
authored
feat: extract @rnef/provider-github package (#343)
* feat: extract @rnef/provider-github package * changeset * cleanup package.json * move resolving github-actions provider to config * remove unnecessary abstraction
1 parent 34f1c59 commit dc7ba26

File tree

29 files changed

+387
-123
lines changed

29 files changed

+387
-123
lines changed

.changeset/curly-deers-try.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rnef/provider-github': patch
3+
'@rnef/tools': patch
4+
---
5+
6+
feat: extract @rnef/provider-github package

packages/cli/src/lib/plugins/remoteCache.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import type { PluginApi, PluginOutput } from '@rnef/config';
2-
import type {
3-
RemoteBuildCache,
4-
SupportedRemoteCacheProviders,
5-
} from '@rnef/tools';
2+
import type { RemoteBuildCache } from '@rnef/tools';
63
import {
7-
createRemoteBuildCache,
84
formatArtifactName,
95
getLocalArtifactPath,
106
getLocalBinaryPath,
@@ -31,18 +27,15 @@ async function remoteCache({
3127
}: {
3228
action: string;
3329
args: Flags;
34-
remoteCacheProvider:
35-
| SupportedRemoteCacheProviders
36-
| null
37-
| { (): RemoteBuildCache };
30+
remoteCacheProvider: null | (() => RemoteBuildCache);
3831
projectRoot: string;
3932
fingerprintOptions: { extraSources: string[]; ignorePaths: string[] };
4033
}) {
4134
const isJsonOutput = args.json;
42-
const remoteBuildCache = await createRemoteBuildCache(remoteCacheProvider);
43-
if (!remoteBuildCache) {
35+
if (!remoteCacheProvider) {
4436
return null;
4537
}
38+
const remoteBuildCache = remoteCacheProvider();
4639

4740
validateArgs(args, action);
4841

@@ -195,7 +188,7 @@ export const remoteCachePlugin =
195188
await remoteCache({
196189
action,
197190
args,
198-
remoteCacheProvider: api.getRemoteCacheProvider() || null,
191+
remoteCacheProvider: (await api.getRemoteCacheProvider()) || null,
199192
projectRoot: api.getProjectRoot(),
200193
fingerprintOptions: api.getFingerprintOptions(),
201194
});

packages/config/src/lib/config.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'node:fs';
22
import { createRequire } from 'node:module';
33
import * as path from 'node:path';
4+
import type { RemoteBuildCache } from '@rnef/tools';
45
import { color, logger } from '@rnef/tools';
56
import type { ValidationError } from 'joi';
67
import { ConfigTypeSchema } from './schema.js';
@@ -21,15 +22,15 @@ export type PluginApi = {
2122
getReactNativeVersion: () => string;
2223
getReactNativePath: () => string;
2324
getPlatforms: () => { [platform: string]: object };
24-
getRemoteCacheProvider: () => SupportedRemoteCacheProviders | undefined;
25+
getRemoteCacheProvider: () => Promise<
26+
null | undefined | (() => RemoteBuildCache)
27+
>;
2528
getFingerprintOptions: () => {
2629
extraSources: string[];
2730
ignorePaths: string[];
2831
};
2932
};
3033

31-
type SupportedRemoteCacheProviders = 'github-actions';
32-
3334
type PluginType = (args: PluginApi) => PluginOutput;
3435

3536
type PlatformType = (args: PluginApi) => PlatformOutput;
@@ -68,7 +69,7 @@ export type ConfigType = {
6869
plugins?: PluginType[];
6970
platforms?: Record<string, PlatformType>;
7071
commands?: Array<CommandType>;
71-
remoteCacheProvider?: SupportedRemoteCacheProviders;
72+
remoteCacheProvider?: null | 'github-actions' |(() => RemoteBuildCache);
7273
fingerprint?: {
7374
extraSources?: string[];
7475
ignorePaths?: string[];
@@ -167,7 +168,15 @@ export async function getConfig(
167168
getReactNativePath: () => resolveReactNativePath(projectRoot),
168169
getPlatforms: () =>
169170
validatedConfig.platforms as { [platform: string]: object },
170-
getRemoteCacheProvider: () => validatedConfig.remoteCacheProvider,
171+
getRemoteCacheProvider: async () => {
172+
// special case for github-actions
173+
if (validatedConfig.remoteCacheProvider === 'github-actions') {
174+
// @ts-expect-error @rnef/provider-github may not be installed
175+
const { providerGitHub } = await import('@rnef/provider-github');
176+
return providerGitHub();
177+
}
178+
return validatedConfig.remoteCacheProvider;
179+
},
171180
getFingerprintOptions: () =>
172181
validatedConfig.fingerprint as {
173182
extraSources: string[];

packages/create-app/src/lib/utils/parse-cli-options.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { SupportedRemoteCacheProviders } from '@rnef/tools';
21
import minimist from 'minimist';
32

43
export type CliOptions = {
@@ -11,7 +10,7 @@ export type CliOptions = {
1110
version: boolean;
1211
dir?: string;
1312
override: boolean;
14-
remoteCacheProvider?: SupportedRemoteCacheProviders | undefined | false;
13+
remoteCacheProvider?: string | undefined | false;
1514
install: boolean;
1615
};
1716

@@ -45,10 +44,7 @@ export function parseCliOptions(argv: string[]): CliOptions {
4544
version: options.version,
4645
dir: ensureOptionalString(options.dir),
4746
override: options.override,
48-
remoteCacheProvider: options['remote-cache-provider'] as
49-
| SupportedRemoteCacheProviders
50-
| undefined
51-
| false,
47+
remoteCacheProvider: options['remote-cache-provider'] as undefined | false,
5248
install: options.install,
5349
};
5450
}

packages/platform-android/src/lib/commands/runAndroid/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function registerRunCommand(
1919
androidConfig,
2020
args as Flags,
2121
projectRoot,
22-
api.getRemoteCacheProvider(),
22+
await api.getRemoteCacheProvider(),
2323
api.getFingerprintOptions()
2424
);
2525
},

packages/platform-android/src/lib/commands/runAndroid/runAndroid.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
AndroidProjectConfig,
55
Config,
66
} from '@react-native-community/cli-types';
7-
import type { SupportedRemoteCacheProviders } from '@rnef/tools';
7+
import type { RemoteBuildCache } from '@rnef/tools';
88
import {
99
fetchCachedBuild,
1010
formatArtifactName,
@@ -46,7 +46,7 @@ export async function runAndroid(
4646
androidProject: AndroidProjectConfig,
4747
args: Flags,
4848
projectRoot: string,
49-
remoteCacheProvider: SupportedRemoteCacheProviders | undefined,
49+
remoteCacheProvider: null | (() => RemoteBuildCache) | undefined,
5050
fingerprintOptions: { extraSources: string[]; ignorePaths: string[] }
5151
) {
5252
intro('Running Android app');

packages/platform-apple-helpers/src/lib/commands/run/createRun.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3-
import type { SupportedRemoteCacheProviders } from '@rnef/tools';
3+
import type { RemoteBuildCache } from '@rnef/tools';
44
import {
55
color,
66
fetchCachedBuild,
@@ -44,7 +44,7 @@ export const createRun = async ({
4444
projectConfig: ProjectConfig;
4545
args: RunFlags;
4646
projectRoot: string;
47-
remoteCacheProvider: SupportedRemoteCacheProviders | undefined;
47+
remoteCacheProvider: null | (() => RemoteBuildCache) | undefined;
4848
fingerprintOptions: { extraSources: string[]; ignorePaths: string[] };
4949
reactNativePath: string;
5050
}) => {

packages/platform-ios/src/lib/platformIOS.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const platformIOS =
5656
projectConfig: iosConfig,
5757
args: args as RunFlags,
5858
projectRoot,
59-
remoteCacheProvider: api.getRemoteCacheProvider(),
59+
remoteCacheProvider: await api.getRemoteCacheProvider(),
6060
fingerprintOptions: api.getFingerprintOptions(),
6161
reactNativePath: api.getReactNativePath(),
6262
});

packages/provider-github/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @rnef/provider-github
2+
3+
GitHub Actions artifact storage provider for React Native Enterprise Framework (RNEF). This package is part of the RNEF ecosystem.
4+
5+
## Documentation
6+
7+
For detailed documentation about RNEF and its tools, visit [RNEF Documentation](https://rnef.dev)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import baseConfig from '../../eslint.config.js';
2+
3+
export default baseConfig;

0 commit comments

Comments
 (0)