Skip to content

Commit f2c141d

Browse files
authored
feat(zephyr-native-cache): expose root API (#461)
1 parent b394f41 commit f2c141d

7 files changed

Lines changed: 22 additions & 25 deletions

File tree

e2e/deployment/src/index.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ const output = execSync(
55
'pnpm exec nx show projects --affected -t=build --projects="examples/**" --exclude="zephyr-cli-test" --json'
66
);
77
const testTargets = JSON.parse(output.toString()) as string[];
8-
const appUidsPromise: Promise<string[]> = getAllDeployedApps();
8+
9+
if (testTargets.length === 0) {
10+
it('has no affected example deployment tests to run', () => {
11+
expect(testTargets).toHaveLength(0);
12+
});
13+
}
14+
15+
let appUidsPromise: Promise<string[]> | undefined;
916

1017
for (const appName of testTargets) {
1118
describe(`[${appName}]: asset deployment assertion`, () => {
1219
let deployResult: DeployResult;
1320

1421
beforeAll(async () => {
22+
appUidsPromise ??= getAllDeployedApps();
1523
const appUids = await appUidsPromise;
1624
const appUid = appUids.find((uid) => uid.startsWith(replacer(appName)));
1725
if (!appUid) {

libs/zephyr-native-cache/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ cache.events.on('poll:complete', (event) => {
142142
For React Native UIs, use the built-in hook:
143143

144144
```ts
145-
import { useCacheStatus } from 'zephyr-native-cache/react';
145+
import { useCacheStatus } from 'zephyr-native-cache';
146146

147147
export function CacheStatusPanel() {
148148
const { status, latestUpdateEvent } = useCacheStatus();
@@ -158,8 +158,7 @@ Use `latestUpdateEvent` as a raw signal to display your own update banner, toast
158158

159159
```tsx
160160
import { Button, Text, View } from 'react-native';
161-
import { ZephyrNativeCache } from 'zephyr-native-cache';
162-
import { useCacheStatus } from 'zephyr-native-cache/react';
161+
import ZephyrNativeCache, { useCacheStatus } from 'zephyr-native-cache';
163162

164163
export function UpdateBanner() {
165164
const { latestUpdateEvent } = useCacheStatus();
@@ -181,8 +180,7 @@ Use the facade for manual update checks and cache invalidation. These calls are
181180

182181
```tsx
183182
import { Button, View } from 'react-native';
184-
import { ZephyrNativeCache } from 'zephyr-native-cache';
185-
import { useCacheStatus } from 'zephyr-native-cache/react';
183+
import ZephyrNativeCache, { useCacheStatus } from 'zephyr-native-cache';
186184

187185
export function CacheControls() {
188186
const { status } = useCacheStatus();
@@ -215,7 +213,7 @@ The status snapshot contains enough state to show polling progress, last-check r
215213

216214
```tsx
217215
import { Text, View } from 'react-native';
218-
import { useCacheStatus } from 'zephyr-native-cache/react';
216+
import { useCacheStatus } from 'zephyr-native-cache';
219217

220218
export function CacheDiagnostics() {
221219
const { status } = useCacheStatus();
@@ -243,8 +241,7 @@ You can map `status.remotes` into source badges so operators can see whether eac
243241

244242
```tsx
245243
import { Text } from 'react-native';
246-
import type { CacheStatusRemoteEntry } from 'zephyr-native-cache';
247-
import { useCacheStatus } from 'zephyr-native-cache/react';
244+
import { useCacheStatus, type CacheStatusRemoteEntry } from 'zephyr-native-cache';
248245

249246
const SOURCE_LABELS: Record<string, string> = {
250247
'cache-hit': 'from cache',

libs/zephyr-native-cache/package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
"require": "./lib/commonjs/runtime-plugin.js",
2424
"default": "./lib/commonjs/runtime-plugin.js"
2525
},
26-
"./react": {
27-
"react-native": "./src/react/index.ts",
28-
"types": "./lib/typescript/react/index.d.ts",
29-
"import": "./lib/module/react/index.js",
30-
"require": "./lib/commonjs/react/index.js",
31-
"default": "./lib/commonjs/react/index.js"
32-
},
3326
"./package.json": "./package.json"
3427
},
3528
"repository": {

libs/zephyr-native-cache/src/ZephyrNativeCache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ export const ZephyrNativeCache: ZephyrNativeCacheApi = {
4343
clearCache,
4444
reloadApp,
4545
};
46+
47+
export default ZephyrNativeCache;

libs/zephyr-native-cache/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ export {
1111
stopUpdatePolling,
1212
subscribeCacheStatus,
1313
} from './register';
14-
export { ZephyrNativeCache } from './ZephyrNativeCache';
15-
// React hook (useCacheStatus) is intentionally NOT re-exported from the root
16-
// barrel — import it from 'zephyr-native-cache/react' so non-React consumers
17-
// don't pull React into their bundle (Metro/CJS output doesn't tree-shake).
14+
export { ZephyrNativeCache, default } from './ZephyrNativeCache';
15+
export { useCacheStatus } from './useCacheStatus';
1816
export type { ZephyrNativeCacheApi } from './ZephyrNativeCache';
17+
export type { UseCacheStatusResult } from './useCacheStatus';
1918
export type {
2019
CachePollResult,
2120
CacheStatusListener,

libs/zephyr-native-cache/src/react/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

libs/zephyr-native-cache/src/react/useCacheStatus.ts renamed to libs/zephyr-native-cache/src/useCacheStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useEffect, useState } from 'react';
2-
import type { UpdateAvailableEvent } from '../events';
2+
import type { UpdateAvailableEvent } from './events';
33
import {
44
getCacheStatus,
55
getRegisteredCacheLayer,
66
subscribeCacheLayerRegistration,
77
subscribeCacheStatus,
8-
} from '../register';
9-
import type { CacheStatusSnapshot } from '../types';
8+
} from './register';
9+
import type { CacheStatusSnapshot } from './types';
1010

1111
const DEFAULT_POLL_INTERVAL_MS = 5 * 60 * 1000;
1212

0 commit comments

Comments
 (0)