@buoy-gg/assets 7.0.36 → 7.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -12
- package/lib/commonjs/capture/expo.js +1 -46
- package/lib/commonjs/capture/install.js +1 -78
- package/lib/commonjs/capture/isBuoyAsset.js +1 -0
- package/lib/commonjs/capture/measure.js +1 -186
- package/lib/commonjs/capture/metroGraph.js +1 -148
- package/lib/commonjs/capture/registry.js +1 -127
- package/lib/commonjs/components/AssetDetail.js +1 -214
- package/lib/commonjs/components/AssetImage.js +1 -0
- package/lib/commonjs/components/AssetRow.js +1 -233
- package/lib/commonjs/components/AssetsFilterBar.js +1 -96
- package/lib/commonjs/components/AssetsHeader.js +1 -72
- package/lib/commonjs/components/AssetsIcon.js +1 -19
- package/lib/commonjs/components/AssetsListControls.js +1 -96
- package/lib/commonjs/components/AssetsModal.js +1 -347
- package/lib/commonjs/components/ScanNotice.js +1 -0
- package/lib/commonjs/components/optionalExpoImage.js +1 -0
- package/lib/commonjs/components/optionalExpoImage.web.js +1 -0
- package/lib/commonjs/export.js +1 -62
- package/lib/commonjs/format.js +1 -59
- package/lib/commonjs/hooks/useAssetRecords.js +1 -22
- package/lib/commonjs/hooks/useAssetScanStatus.js +1 -0
- package/lib/commonjs/index.js +1 -313
- package/lib/commonjs/preset.js +1 -39
- package/lib/commonjs/remote.js +1 -65
- package/lib/commonjs/state.js +1 -51
- package/lib/commonjs/store/assetStore.js +1 -241
- package/lib/commonjs/store/baseline.js +1 -173
- package/lib/commonjs/store/insights.js +1 -120
- package/lib/commonjs/sync/assetsSyncAdapter.js +1 -157
- package/lib/commonjs/types.js +1 -2
- package/lib/commonjs/utils/deviceScale.js +1 -50
- package/lib/commonjs/utils/testIDs.js +1 -114
- package/lib/module/capture/expo.js +1 -41
- package/lib/module/capture/install.js +1 -72
- package/lib/module/capture/isBuoyAsset.js +1 -0
- package/lib/module/capture/measure.js +1 -179
- package/lib/module/capture/metroGraph.js +1 -141
- package/lib/module/capture/registry.js +1 -120
- package/lib/module/components/AssetDetail.js +1 -210
- package/lib/module/components/AssetImage.js +1 -0
- package/lib/module/components/AssetRow.js +1 -229
- package/lib/module/components/AssetsFilterBar.js +1 -92
- package/lib/module/components/AssetsHeader.js +1 -68
- package/lib/module/components/AssetsIcon.js +1 -12
- package/lib/module/components/AssetsListControls.js +1 -92
- package/lib/module/components/AssetsModal.js +1 -342
- package/lib/module/components/ScanNotice.js +1 -0
- package/lib/module/components/optionalExpoImage.js +1 -0
- package/lib/module/components/optionalExpoImage.web.js +1 -0
- package/lib/module/export.js +1 -57
- package/lib/module/format.js +1 -51
- package/lib/module/hooks/useAssetRecords.js +1 -18
- package/lib/module/hooks/useAssetScanStatus.js +1 -0
- package/lib/module/index.js +1 -63
- package/lib/module/preset.js +1 -35
- package/lib/module/remote.js +1 -58
- package/lib/module/state.js +1 -47
- package/lib/module/store/assetStore.js +1 -226
- package/lib/module/store/baseline.js +1 -165
- package/lib/module/store/insights.js +1 -116
- package/lib/module/sync/assetsSyncAdapter.js +1 -153
- package/lib/module/types.js +1 -2
- package/lib/module/utils/deviceScale.js +1 -46
- package/lib/module/utils/testIDs.js +1 -103
- package/lib/typescript/capture/isBuoyAsset.d.ts +9 -0
- package/lib/typescript/capture/registry.d.ts +1 -1
- package/lib/typescript/components/AssetDetail.d.ts +2 -2
- package/lib/typescript/components/AssetImage.d.ts +9 -0
- package/lib/typescript/components/AssetsFilterBar.d.ts +3 -2
- package/lib/typescript/components/AssetsHeader.d.ts +2 -1
- package/lib/typescript/components/AssetsListControls.d.ts +2 -9
- package/lib/typescript/components/ScanNotice.d.ts +7 -0
- package/lib/typescript/components/optionalExpoImage.d.ts +13 -0
- package/lib/typescript/components/optionalExpoImage.web.d.ts +3 -0
- package/lib/typescript/hooks/useAssetScanStatus.d.ts +6 -0
- package/lib/typescript/state.d.ts +2 -0
- package/lib/typescript/store/assetStore.d.ts +3 -1
- package/lib/typescript/types.d.ts +3 -0
- package/lib/typescript/utils/testIDs.d.ts +2 -5
- package/package.json +7 -3
- package/lib/commonjs/capture/expo.js.map +0 -1
- package/lib/commonjs/capture/install.js.map +0 -1
- package/lib/commonjs/capture/measure.js.map +0 -1
- package/lib/commonjs/capture/metroGraph.js.map +0 -1
- package/lib/commonjs/capture/registry.js.map +0 -1
- package/lib/commonjs/components/AssetDetail.js.map +0 -1
- package/lib/commonjs/components/AssetRow.js.map +0 -1
- package/lib/commonjs/components/AssetsFilterBar.js.map +0 -1
- package/lib/commonjs/components/AssetsHeader.js.map +0 -1
- package/lib/commonjs/components/AssetsIcon.js.map +0 -1
- package/lib/commonjs/components/AssetsListControls.js.map +0 -1
- package/lib/commonjs/components/AssetsModal.js.map +0 -1
- package/lib/commonjs/components/BaselineBar.js +0 -115
- package/lib/commonjs/components/BaselineBar.js.map +0 -1
- package/lib/commonjs/export.js.map +0 -1
- package/lib/commonjs/format.js.map +0 -1
- package/lib/commonjs/hooks/useAssetRecords.js.map +0 -1
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/preset.js.map +0 -1
- package/lib/commonjs/remote.js.map +0 -1
- package/lib/commonjs/state.js.map +0 -1
- package/lib/commonjs/store/assetStore.js.map +0 -1
- package/lib/commonjs/store/baseline.js.map +0 -1
- package/lib/commonjs/store/insights.js.map +0 -1
- package/lib/commonjs/sync/assetsSyncAdapter.js.map +0 -1
- package/lib/commonjs/types.js.map +0 -1
- package/lib/commonjs/utils/deviceScale.js.map +0 -1
- package/lib/commonjs/utils/testIDs.js.map +0 -1
- package/lib/module/capture/expo.js.map +0 -1
- package/lib/module/capture/install.js.map +0 -1
- package/lib/module/capture/measure.js.map +0 -1
- package/lib/module/capture/metroGraph.js.map +0 -1
- package/lib/module/capture/registry.js.map +0 -1
- package/lib/module/components/AssetDetail.js.map +0 -1
- package/lib/module/components/AssetRow.js.map +0 -1
- package/lib/module/components/AssetsFilterBar.js.map +0 -1
- package/lib/module/components/AssetsHeader.js.map +0 -1
- package/lib/module/components/AssetsIcon.js.map +0 -1
- package/lib/module/components/AssetsListControls.js.map +0 -1
- package/lib/module/components/AssetsModal.js.map +0 -1
- package/lib/module/components/BaselineBar.js +0 -111
- package/lib/module/components/BaselineBar.js.map +0 -1
- package/lib/module/export.js.map +0 -1
- package/lib/module/format.js.map +0 -1
- package/lib/module/hooks/useAssetRecords.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/preset.js.map +0 -1
- package/lib/module/remote.js.map +0 -1
- package/lib/module/state.js.map +0 -1
- package/lib/module/store/assetStore.js.map +0 -1
- package/lib/module/store/baseline.js.map +0 -1
- package/lib/module/store/insights.js.map +0 -1
- package/lib/module/sync/assetsSyncAdapter.js.map +0 -1
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils/deviceScale.js.map +0 -1
- package/lib/module/utils/testIDs.js.map +0 -1
- package/lib/typescript/capture/expo.d.ts.map +0 -1
- package/lib/typescript/capture/install.d.ts.map +0 -1
- package/lib/typescript/capture/measure.d.ts.map +0 -1
- package/lib/typescript/capture/metroGraph.d.ts.map +0 -1
- package/lib/typescript/capture/registry.d.ts.map +0 -1
- package/lib/typescript/components/AssetDetail.d.ts.map +0 -1
- package/lib/typescript/components/AssetRow.d.ts.map +0 -1
- package/lib/typescript/components/AssetsFilterBar.d.ts.map +0 -1
- package/lib/typescript/components/AssetsHeader.d.ts.map +0 -1
- package/lib/typescript/components/AssetsIcon.d.ts.map +0 -1
- package/lib/typescript/components/AssetsListControls.d.ts.map +0 -1
- package/lib/typescript/components/AssetsModal.d.ts.map +0 -1
- package/lib/typescript/components/BaselineBar.d.ts +0 -13
- package/lib/typescript/components/BaselineBar.d.ts.map +0 -1
- package/lib/typescript/export.d.ts.map +0 -1
- package/lib/typescript/format.d.ts.map +0 -1
- package/lib/typescript/hooks/useAssetRecords.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
- package/lib/typescript/remote.d.ts.map +0 -1
- package/lib/typescript/state.d.ts.map +0 -1
- package/lib/typescript/store/assetStore.d.ts.map +0 -1
- package/lib/typescript/store/baseline.d.ts.map +0 -1
- package/lib/typescript/store/insights.d.ts.map +0 -1
- package/lib/typescript/sync/assetsSyncAdapter.d.ts.map +0 -1
- package/lib/typescript/types.d.ts.map +0 -1
- package/lib/typescript/utils/deviceScale.d.ts.map +0 -1
- package/lib/typescript/utils/testIDs.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@buoy-gg/assets) [](https://www.npmjs.com/package/@buoy-gg/assets)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Inspect assets visible to the runtime registry and, in development, the Metro dependency graph. Compare sizes and find possible duplicates.
|
|
6
6
|
|
|
7
|
-
Part of [Buoy](https://github.com/Buoy-gg/buoy)
|
|
7
|
+
Part of [Buoy](https://github.com/Buoy-gg/buoy). Install the package, complete account setup, and follow the integration steps below.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Use the inventory to investigate large registered assets and possible duplication. Development builds can also query Metro; release builds have less source information.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -14,6 +14,24 @@ How many megabytes of images are you shipping? Is that hero PNG in the bundle tw
|
|
|
14
14
|
npm install @buoy-gg/core @buoy-gg/assets
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
## Before you start
|
|
18
|
+
|
|
19
|
+
Use a development build with `@buoy-gg/core` and a Free or Pro Buoy account key. From your app’s directory, sign in:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx --package=@buoy-gg/core buoy login
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For Expo, initialize Buoy before rendering the menu:
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { Buoy } from "@buoy-gg/core";
|
|
29
|
+
|
|
30
|
+
Buoy.init({ licenseKey: process.env.EXPO_PUBLIC_BUOY_KEY });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The login command writes the Expo key to `.env.local`. For React Native CLI, pass the key from your app’s environment configuration; React Native does not load `.env.local` automatically. Mount `FloatingDevTools` inside the same providers as your screens and restart the development server after installation. The [Quick Start](https://buoy.gg/buoy/latest/docs/quick-start) shows the complete root component setup.
|
|
34
|
+
|
|
17
35
|
## Quick start
|
|
18
36
|
|
|
19
37
|
```tsx
|
|
@@ -29,27 +47,38 @@ export default function App() {
|
|
|
29
47
|
}
|
|
30
48
|
```
|
|
31
49
|
|
|
32
|
-
The ASSETS tool appears in the menu. Open it and browse
|
|
50
|
+
The ASSETS tool appears in the menu. Open it and browse discovered assets, largest first.
|
|
51
|
+
|
|
52
|
+
Buoy's own package assets are excluded from the inventory and its totals. App assets and assets from other libraries remain visible.
|
|
53
|
+
|
|
54
|
+
SVG thumbnails and detail previews use `expo-image` when it is installed and available in the native app. It is an optional peer; `react-native-svg` is not required. Without a compatible renderer, the tool shows a preview-unavailable label. Desktop and web use browser image rendering. Some SVG paths may not render correctly with the iOS system decoder.
|
|
55
|
+
|
|
56
|
+
Registered assets appear immediately. A spinner and a "found so far" count stay visible while the tool queries the development server for more assets. After eight seconds, a message explains that discovery is taking longer than usual. Size checks run afterward. If discovery fails or exceeds 90 seconds, the existing list stays available with a Retry button.
|
|
57
|
+
|
|
58
|
+
## Check the integration
|
|
59
|
+
|
|
60
|
+
Find a known bundled asset and compare its source and dimensions. “Not observed” means not seen in React Native’s asset registry during this app run; it does not prove an asset is unused or safe to delete. Runtime coverage is not a complete inventory of native resources.
|
|
33
61
|
|
|
34
62
|
## What you get
|
|
35
63
|
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
64
|
+
- **Inventory, largest first** — discovered assets with a thumbnail, dimensions, `@1x/@2x/@3x` scale coverage, and its size. Filter by kind, search by name, sort by size/name/type
|
|
65
|
+
- **Size information** — development builds can measure available variants through Metro. Release decoded-memory estimates are not encoded file sizes
|
|
66
|
+
- **Unobserved assets** — compare the available development bundle graph with assets registered during the session. Review candidates before deleting them
|
|
39
67
|
- **Duplicate content** — identical bytes shipped under different names, flagged by content hash (one of the cheapest app-size wins there is)
|
|
40
|
-
- **Baseline diff** — save a baseline, make your change, and see exactly what it added: new assets, removed assets, grown assets, net bytes. App-size regression prevention without CI tooling
|
|
41
68
|
- **Audit findings** — images that decode larger than the device screen, heavy GIFs (every frame decodes into memory), unsubset icon fonts, WebP conversion candidates, missing/broken scale variants
|
|
42
69
|
- **Loaded font families** — build-time embedded and runtime loaded (via the expo-font native module when present)
|
|
43
70
|
- **Markdown report** — the full inventory with findings, ready to paste into an issue or PR
|
|
44
71
|
|
|
45
72
|
## How it relates to @buoy-gg/images
|
|
46
73
|
|
|
47
|
-
[`@buoy-gg/images`](https://www.npmjs.com/package/@buoy-gg/images) shows what your app **renders** at runtime — per-load cache verdicts, timings, failures.
|
|
74
|
+
[`@buoy-gg/images`](https://www.npmjs.com/package/@buoy-gg/images) shows what your app **renders** at runtime — per-load cache verdicts, timings, failures. Assets inspects the available asset inventory. Use both views to investigate loading behavior and bundle size.
|
|
48
75
|
|
|
49
76
|
## Desktop & AI
|
|
50
77
|
|
|
51
|
-
|
|
78
|
+
To connect a React Native app to [Buoy Desktop](https://github.com/Buoy-gg/Buoy-Desktop) or MCP, install `@buoy-gg/external-sync` and follow the [Desktop connection guide](https://buoy.gg/buoy/latest/docs/desktop). Sign in to Desktop separately. [MCP setup](https://buoy.gg/buoy/latest/docs/mcp) also requires a process account and Pro access. Available remote actions depend on the tool and app integration.
|
|
79
|
+
|
|
80
|
+
## Account and plan requirements
|
|
52
81
|
|
|
53
|
-
|
|
82
|
+
Use a Free or Pro Buoy account. History limits and paid features vary by tool; see [pricing](https://buoy.gg/pricing). Production access requires Pro where supported. Development-only hooks and actions remain unavailable in release builds.
|
|
54
83
|
|
|
55
|
-
|
|
84
|
+
Use **Duplicates** at the top of the asset list to show every asset that shares a content hash with another asset. The count includes all copies. Selecting it clears the search; select **All** or tap **Duplicates** again to return to the full list.
|
|
@@ -1,46 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getLoadedFontFamilies = getLoadedFontFamilies;
|
|
7
|
-
exports.getLocalAssets = getLocalAssets;
|
|
8
|
-
/**
|
|
9
|
-
* Expo enrichment — all optional, all read through globalThis.expo guards so
|
|
10
|
-
* bare RN apps (no expo-modules) silently get none of it and no imports are
|
|
11
|
-
* added for anyone.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
function expoModules() {
|
|
15
|
-
return globalThis.expo?.modules;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Every loaded font family — build-time embedded (config plugin / UIAppFonts /
|
|
20
|
-
* android assets/fonts) AND runtime Font.loadAsync, straight from the native
|
|
21
|
-
* module Expo documents as a stable global. [] when unavailable (bare RN).
|
|
22
|
-
*/
|
|
23
|
-
function getLoadedFontFamilies() {
|
|
24
|
-
try {
|
|
25
|
-
const fonts = expoModules()?.ExpoFontLoader?.getLoadedFonts?.();
|
|
26
|
-
return Array.isArray(fonts) ? [...fonts].sort() : [];
|
|
27
|
-
} catch {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* expo-updates' per-file-hash → local URI map: the COMPLETE shipped asset set
|
|
34
|
-
* in Expo Go / OTA environments, independent of what JS has evaluated.
|
|
35
|
-
* null when not running in an updates-managed environment.
|
|
36
|
-
*/
|
|
37
|
-
function getLocalAssets() {
|
|
38
|
-
try {
|
|
39
|
-
const map = expoModules()?.ExpoUpdates?.localAssets;
|
|
40
|
-
if (map && typeof map === "object" && Object.keys(map).length > 0) return map;
|
|
41
|
-
return null;
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=expo.js.map
|
|
1
|
+
"use strict";function expoModules(){return globalThis.expo?.modules}function getLoadedFontFamilies(){try{const e=expoModules()?.ExpoFontLoader?.getLoadedFonts?.();return Array.isArray(e)?[...new Set(e)].sort():[]}catch{return[]}}function getLocalAssets(){try{const e=expoModules()?.ExpoUpdates?.localAssets;return e&&"object"==typeof e&&Object.keys(e).length>0?e:null}catch{return null}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLoadedFontFamilies=getLoadedFontFamilies,exports.getLocalAssets=getLocalAssets;
|
|
@@ -1,78 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getScanStatus = getScanStatus;
|
|
7
|
-
exports.installAssetCapture = installAssetCapture;
|
|
8
|
-
exports.rescan = rescan;
|
|
9
|
-
var _state = require("../state");
|
|
10
|
-
var _assetStore = require("../store/assetStore");
|
|
11
|
-
var _expo = require("./expo");
|
|
12
|
-
var _measure = require("./measure");
|
|
13
|
-
var _metroGraph = require("./metroGraph");
|
|
14
|
-
var _registry = require("./registry");
|
|
15
|
-
/**
|
|
16
|
-
* Capture install + scan orchestration.
|
|
17
|
-
*
|
|
18
|
-
* installAssetCapture() is cheap and synchronous (registry walk + patch) and
|
|
19
|
-
* runs at package import. The expensive passes — Metro graph fetch and byte
|
|
20
|
-
* measurement — run in rescan(), triggered when the modal opens or via the
|
|
21
|
-
* `rescan` sync action, so merely installing Buoy never hits the network.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
function installAssetCapture() {
|
|
25
|
-
const s = (0, _state.assetsState)();
|
|
26
|
-
if (s.captureDisabled || s.installed) return;
|
|
27
|
-
s.installed = true;
|
|
28
|
-
s.registryAvailable = (0, _registry.getRegistryModule)() != null;
|
|
29
|
-
s.patched = (0, _registry.patchRegisterAsset)();
|
|
30
|
-
(0, _registry.walkRegistry)();
|
|
31
|
-
refreshEnrichment();
|
|
32
|
-
s.lastScanAt = Date.now();
|
|
33
|
-
(0, _assetStore.invalidate)();
|
|
34
|
-
}
|
|
35
|
-
function refreshEnrichment() {
|
|
36
|
-
const s = (0, _state.assetsState)();
|
|
37
|
-
s.fontFamilies = (0, _expo.getLoadedFontFamilies)();
|
|
38
|
-
const localAssets = (0, _expo.getLocalAssets)();
|
|
39
|
-
s.localAssetCount = localAssets ? Object.keys(localAssets).length : null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Full scan: registry re-walk (catches anything the patch missed), Metro
|
|
44
|
-
* graph merge (dev), Expo enrichment refresh, then size measurement.
|
|
45
|
-
*/
|
|
46
|
-
async function rescan() {
|
|
47
|
-
const s = (0, _state.assetsState)();
|
|
48
|
-
if (s.captureDisabled) return getScanStatus();
|
|
49
|
-
installAssetCapture();
|
|
50
|
-
(0, _registry.walkRegistry)();
|
|
51
|
-
refreshEnrichment();
|
|
52
|
-
await (0, _metroGraph.fetchAssetGraph)();
|
|
53
|
-
s.lastScanAt = Date.now();
|
|
54
|
-
(0, _assetStore.invalidate)();
|
|
55
|
-
void (0, _measure.measureSizes)();
|
|
56
|
-
return getScanStatus();
|
|
57
|
-
}
|
|
58
|
-
function getScanStatus() {
|
|
59
|
-
const s = (0, _state.assetsState)();
|
|
60
|
-
// Mirrors report the synced DEVICE's status, not the dashboard's.
|
|
61
|
-
if (s.mirrorScanStatus) return s.mirrorScanStatus;
|
|
62
|
-
let registryCount = 0;
|
|
63
|
-
for (const record of s.records) if (record.registryId != null) registryCount++;
|
|
64
|
-
return {
|
|
65
|
-
registryAvailable: s.registryAvailable,
|
|
66
|
-
patched: s.patched,
|
|
67
|
-
registryCount,
|
|
68
|
-
graphSupported: s.graphSupported || (0, _metroGraph.getDevServerOrigin)() != null,
|
|
69
|
-
graphCount: s.graphCount,
|
|
70
|
-
graphError: s.graphError,
|
|
71
|
-
lastScanAt: s.lastScanAt,
|
|
72
|
-
measuring: s.measuring,
|
|
73
|
-
measuredCount: s.measuredCount,
|
|
74
|
-
fontFamilies: s.fontFamilies,
|
|
75
|
-
localAssetCount: s.localAssetCount
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=install.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getScanStatus=getScanStatus,exports.installAssetCapture=installAssetCapture,exports.rescan=rescan;var _state=require("../state"),_assetStore=require("../store/assetStore"),_expo=require("./expo"),_measure=require("./measure"),_metroGraph=require("./metroGraph"),_registry=require("./registry");function installAssetCapture(){const t=(0,_state.assetsState)();t.captureDisabled||t.installed||(t.installed=!0,t.registryAvailable=null!=(0,_registry.getRegistryModule)(),t.patched=(0,_registry.patchRegisterAsset)(),(0,_registry.walkRegistry)(),refreshEnrichment(),t.lastScanAt=Date.now(),(0,_assetStore.invalidate)())}function refreshEnrichment(){const t=(0,_state.assetsState)();t.fontFamilies=(0,_expo.getLoadedFontFamilies)();const e=(0,_expo.getLocalAssets)();t.localAssetCount=e?Object.keys(e).length:null}async function rescan(){const t=(0,_state.assetsState)();if(t.captureDisabled)return getScanStatus();if(t.scanPromise)return t.scanPromise;t.scanPromise=runScan();try{return await t.scanPromise}finally{t.scanPromise=void 0}}async function runScan(){const t=(0,_state.assetsState)();return(0,_assetStore.removeBuoyRecords)(),installAssetCapture(),(0,_registry.walkRegistry)(),refreshEnrichment(),await(0,_metroGraph.fetchAssetGraph)(),t.lastScanAt=Date.now(),(0,_assetStore.invalidate)(),(0,_measure.measureSizes)(),getScanStatus()}function getScanStatus(){const t=(0,_state.assetsState)();if(t.mirrorScanStatus)return t.mirrorScanStatus;let e=0;for(const r of t.records)null!=r.registryId&&e++;return{registryAvailable:t.registryAvailable,patched:t.patched,registryCount:e,graphSupported:t.graphSupported||null!=(0,_metroGraph.getDevServerOrigin)(),graphCount:t.graphCount,graphError:t.graphError,graphFetchInFlight:t.graphFetchInFlight,graphFetchStartedAt:t.graphFetchStartedAt??null,lastScanAt:t.lastScanAt,measuring:t.measuring,measuredCount:t.measuredCount,fontFamilies:t.fontFamilies,localAssetCount:t.localAssetCount}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function isBuoyAssetPath(e){if(!e)return!1;let s=e;try{s=decodeURIComponent(s)}catch{}return s=s.replace(/\\/g,"/"),/(?:^|\/)node_modules\/@buoy-gg\/[^/]+(?:\/|$)/.test(s)||/(?:^|\/)buoy-packages\/packages\/[^/]+(?:\/|$)/.test(s)||/(?:^|\/)packages\/floating-tools-core\/(?:src|lib\/(?:module|commonjs))\/icons\/assets(?:\/|$)/.test(s)}function isBuoyAsset(e){return[e.key,e.httpServerLocation,e.fileSystemLocation,...e.files??[]].some(isBuoyAssetPath)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.isBuoyAsset=isBuoyAsset,exports.isBuoyAssetPath=isBuoyAssetPath;
|
|
@@ -1,186 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.displaySource = displaySource;
|
|
7
|
-
exports.measureSizes = measureSizes;
|
|
8
|
-
exports.previewURL = previewURL;
|
|
9
|
-
exports.variantURLs = variantURLs;
|
|
10
|
-
var _state = require("../state");
|
|
11
|
-
var _assetStore = require("../store/assetStore");
|
|
12
|
-
var _metroGraph = require("./metroGraph");
|
|
13
|
-
/**
|
|
14
|
-
* Byte-size measurement.
|
|
15
|
-
*
|
|
16
|
-
* Dev only in practice: each scale variant is fetched from the Metro dev
|
|
17
|
-
* server (HEAD first for Content-Length, GET-blob fallback since Metro
|
|
18
|
-
* doesn't reliably answer HEAD) and the per-variant sizes are summed onto
|
|
19
|
-
* the record. Android release resource ids and iOS file:// URIs are not
|
|
20
|
-
* measurable from JS — those records keep `estDecodedBytes` as their only
|
|
21
|
-
* size signal and the UI marks them as estimates.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const CONCURRENCY = 4;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Best displayable URL for a record: the resolved runtime URI, or (dev) the
|
|
28
|
-
* same dev-server URL the measurement pass uses — this is what gives graph-
|
|
29
|
-
* only (never-loaded) images real thumbnails.
|
|
30
|
-
*/
|
|
31
|
-
function previewURL(record) {
|
|
32
|
-
if (record.resolvedUri) return record.resolvedUri;
|
|
33
|
-
const variants = variantURLs(record);
|
|
34
|
-
return variants.length ? variants[0].url : null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Image source for thumbnails/previews. On device the NUMERIC registry id is
|
|
39
|
-
* preferred (resolves natively — works for Android release resource ids too).
|
|
40
|
-
* On dashboard mirrors that id belongs to the DEVICE's registry and rn-web
|
|
41
|
-
* throws "asset with ID N could not be found" — use the device's http(s)
|
|
42
|
-
* URL instead (the Metro dev server is reachable from the desktop).
|
|
43
|
-
*/
|
|
44
|
-
function displaySource(record) {
|
|
45
|
-
const mirror = (0, _state.assetsState)().captureDisabled;
|
|
46
|
-
if (!mirror && record.registryId != null) return record.registryId;
|
|
47
|
-
const uri = previewURL(record);
|
|
48
|
-
if (!uri) return null;
|
|
49
|
-
if (mirror && !/^https?:\/\//.test(uri)) return null;
|
|
50
|
-
return {
|
|
51
|
-
uri
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** All scale-variant URLs for a record, derived without re-encoding pitfalls. */
|
|
56
|
-
function variantURLs(record) {
|
|
57
|
-
const scales = record.scales.length ? record.scales : [1];
|
|
58
|
-
|
|
59
|
-
// Preferred: string surgery on the URL resolveAssetSource already proved
|
|
60
|
-
// works (handles Expo's ?unstable_path= form and monorepo rewrites).
|
|
61
|
-
const resolved = record.resolvedUri;
|
|
62
|
-
if (resolved && /^https?:\/\//.test(resolved) && record.resolvedScale != null) {
|
|
63
|
-
const pickedSuffix = record.resolvedScale === 1 ? "" : `@${record.resolvedScale}x`;
|
|
64
|
-
const marker = `${pickedSuffix}.${record.type}`;
|
|
65
|
-
if (resolved.includes(marker) || pickedSuffix === "") {
|
|
66
|
-
return scales.map(scale => {
|
|
67
|
-
const suffix = scale === 1 ? "" : `@${scale}x`;
|
|
68
|
-
const url = (pickedSuffix === "" ? resolved.replace(`.${record.type}`, `${suffix}.${record.type}`) : resolved.replace(marker, `${suffix}.${record.type}`)).replace(/ /g, "%20"); // RN's asset path builder doesn't encode spaces
|
|
69
|
-
return {
|
|
70
|
-
scale,
|
|
71
|
-
url
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Graph-only records: rebuild the dev-server URL the way Metro's
|
|
78
|
-
// AssetSourceResolver does (plain concatenation), encoding only spaces —
|
|
79
|
-
// full encodeURI would double-encode Expo's pre-escaped unstable_path.
|
|
80
|
-
const origin = (0, _metroGraph.getDevServerOrigin)();
|
|
81
|
-
if (!origin || !record.httpServerLocation) return [];
|
|
82
|
-
return scales.map(scale => {
|
|
83
|
-
const suffix = scale === 1 ? "" : `@${scale}x`;
|
|
84
|
-
const path = `${record.httpServerLocation}/${record.name}${suffix}.${record.type}`;
|
|
85
|
-
const sep = path.includes("?") ? "&" : "?";
|
|
86
|
-
const url = `${origin}${path}${sep}platform=${platformName()}${record.hash ? `&hash=${record.hash}` : ""}`.replace(/ /g, "%20");
|
|
87
|
-
return {
|
|
88
|
-
scale,
|
|
89
|
-
url
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
function platformName() {
|
|
94
|
-
try {
|
|
95
|
-
return require("react-native").Platform.OS;
|
|
96
|
-
} catch {
|
|
97
|
-
return "ios";
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async function fetchSize(url) {
|
|
101
|
-
try {
|
|
102
|
-
const head = await fetch(url, {
|
|
103
|
-
method: "HEAD"
|
|
104
|
-
});
|
|
105
|
-
if (head.ok) {
|
|
106
|
-
const length = Number(head.headers.get("content-length"));
|
|
107
|
-
if (Number.isFinite(length) && length > 0) return length;
|
|
108
|
-
}
|
|
109
|
-
} catch {
|
|
110
|
-
// fall through to GET
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
const response = await fetch(url);
|
|
114
|
-
if (!response.ok) return null;
|
|
115
|
-
const blob = await response.blob();
|
|
116
|
-
return blob.size > 0 ? blob.size : null;
|
|
117
|
-
} catch {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async function measureRecord(record) {
|
|
122
|
-
const variants = variantURLs(record);
|
|
123
|
-
if (!variants.length) {
|
|
124
|
-
(0, _assetStore.updateRecord)(record.id, {
|
|
125
|
-
sizeSource: "estimate"
|
|
126
|
-
});
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const sizesByScale = {};
|
|
130
|
-
let total = 0;
|
|
131
|
-
for (const {
|
|
132
|
-
scale,
|
|
133
|
-
url
|
|
134
|
-
} of variants) {
|
|
135
|
-
const size = await fetchSize(url);
|
|
136
|
-
if (size != null) {
|
|
137
|
-
sizesByScale[String(scale)] = size;
|
|
138
|
-
total += size;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (total > 0) {
|
|
142
|
-
(0, _assetStore.updateRecord)(record.id, {
|
|
143
|
-
sizesByScale,
|
|
144
|
-
sizeBytes: total,
|
|
145
|
-
sizeSource: "measured"
|
|
146
|
-
});
|
|
147
|
-
} else {
|
|
148
|
-
(0, _assetStore.updateRecord)(record.id, {
|
|
149
|
-
sizeSource: "estimate"
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/** Measure every unmeasured record; safe to re-run (skips measured ones). */
|
|
155
|
-
async function measureSizes() {
|
|
156
|
-
const s = (0, _state.assetsState)();
|
|
157
|
-
if (s.measuring) return {
|
|
158
|
-
measured: s.measuredCount,
|
|
159
|
-
total: (0, _assetStore.getSnapshot)().length
|
|
160
|
-
};
|
|
161
|
-
const pending = (0, _assetStore.getSnapshot)().filter(r => r.sizeSource !== "measured");
|
|
162
|
-
s.measuring = true;
|
|
163
|
-
(0, _assetStore.invalidate)();
|
|
164
|
-
try {
|
|
165
|
-
let index = 0;
|
|
166
|
-
const worker = async () => {
|
|
167
|
-
for (;;) {
|
|
168
|
-
const next = pending[index++];
|
|
169
|
-
if (!next) return;
|
|
170
|
-
await measureRecord(next);
|
|
171
|
-
s.measuredCount = (0, _assetStore.getSnapshot)().filter(r => r.sizeSource === "measured").length;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
await Promise.all(Array.from({
|
|
175
|
-
length: Math.min(CONCURRENCY, pending.length)
|
|
176
|
-
}, worker));
|
|
177
|
-
} finally {
|
|
178
|
-
s.measuring = false;
|
|
179
|
-
(0, _assetStore.invalidate)();
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
measured: s.measuredCount,
|
|
183
|
-
total: (0, _assetStore.getSnapshot)().length
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
//# sourceMappingURL=measure.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.displaySource=displaySource,exports.measureSizes=measureSizes,exports.previewURL=previewURL,exports.variantURLs=variantURLs;var _state=require("../state"),_assetStore=require("../store/assetStore"),_metroGraph=require("./metroGraph");const CONCURRENCY=4;function previewURL(e){if(e.resolvedUri)return e.resolvedUri;const t=variantURLs(e);return t.length?t[0].url:null}function displaySource(e){const t=(0,_state.assetsState)().captureDisabled;if(!t&&null!=e.registryId)return e.registryId;const r=previewURL(e);return r?t&&!/^https?:\/\//.test(r)?null:{uri:r}:null}function variantURLs(e){const t=e.scales.length?e.scales:[1],r=e.resolvedUri;if(r&&/^https?:\/\//.test(r)&&null!=e.resolvedScale){const s=1===e.resolvedScale?"":`@${e.resolvedScale}x`,a=`${s}.${e.type}`;if(r.includes(a)||""===s)return t.map(t=>{const n=1===t?"":`@${t}x`;return{scale:t,url:(""===s?r.replace(`.${e.type}`,`${n}.${e.type}`):r.replace(a,`${n}.${e.type}`)).replace(/ /g,"%20")}})}const s=(0,_metroGraph.getDevServerOrigin)();return s&&e.httpServerLocation?t.map(t=>{const r=1===t?"":`@${t}x`,a=`${e.httpServerLocation}/${e.name}${r}.${e.type}`,n=a.includes("?")?"&":"?";return{scale:t,url:`${s}${a}${n}platform=${platformName()}${e.hash?`&hash=${e.hash}`:""}`.replace(/ /g,"%20")}}):[]}function platformName(){try{return require("react-native").Platform.OS}catch{return"ios"}}async function fetchSize(e){try{const t=await fetch(e,{method:"HEAD"});if(t.ok){const e=Number(t.headers.get("content-length"));if(Number.isFinite(e)&&e>0)return e}}catch{}try{const t=await fetch(e);if(!t.ok)return null;const r=await t.blob();return r.size>0?r.size:null}catch{return null}}async function measureRecord(e){const t=variantURLs(e);if(!t.length)return void(0,_assetStore.updateRecord)(e.id,{sizeSource:"estimate"});const r={};let s=0;for(const{scale:e,url:a}of t){const t=await fetchSize(a);null!=t&&(r[String(e)]=t,s+=t)}s>0?(0,_assetStore.updateRecord)(e.id,{sizesByScale:r,sizeBytes:s,sizeSource:"measured"}):(0,_assetStore.updateRecord)(e.id,{sizeSource:"estimate"})}async function measureSizes(){const e=(0,_state.assetsState)();if(e.measuring)return{measured:e.measuredCount,total:(0,_assetStore.getSnapshot)().length};const t=(0,_assetStore.getSnapshot)().filter(e=>"measured"!==e.sizeSource);e.measuring=!0,(0,_assetStore.invalidate)();try{let r=0;const s=async()=>{for(;;){const s=t[r++];if(!s)return;await measureRecord(s),e.measuredCount=(0,_assetStore.getSnapshot)().filter(e=>"measured"===e.sizeSource).length}};await Promise.all(Array.from({length:Math.min(CONCURRENCY,t.length)},s))}finally{e.measuring=!1,(0,_assetStore.invalidate)()}return{measured:e.measuredCount,total:(0,_assetStore.getSnapshot)().length}}
|
|
@@ -1,148 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fetchAssetGraph = fetchAssetGraph;
|
|
7
|
-
exports.getDevServerOrigin = getDevServerOrigin;
|
|
8
|
-
exports.getGraphURLCandidates = getGraphURLCandidates;
|
|
9
|
-
exports.getScriptURL = getScriptURL;
|
|
10
|
-
var _state = require("../state");
|
|
11
|
-
var _assetStore = require("../store/assetStore");
|
|
12
|
-
/**
|
|
13
|
-
* Metro dev-server graph fetch.
|
|
14
|
-
*
|
|
15
|
-
* The dev server serves `<entry>.assets` next to `<entry>.bundle` — the full
|
|
16
|
-
* dependency graph's AssetData[], INCLUDING assets never required at runtime
|
|
17
|
-
* and the `fileSystemLocation`/`files` fields Metro strips from runtime
|
|
18
|
-
* records. Deriving the URL by swapping `.bundle` → `.assets` on the running
|
|
19
|
-
* bundle's scriptURL keeps the entry path and platform/dev query params
|
|
20
|
-
* intact for both RN CLI (index.bundle) and Expo (…/entry.bundle) layouts.
|
|
21
|
-
*
|
|
22
|
-
* Graph-only records (in the graph, not the registry) are exactly the
|
|
23
|
-
* "shipped but never loaded" set. Dev-only: no server, no graph.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
function getScriptURL() {
|
|
27
|
-
try {
|
|
28
|
-
const {
|
|
29
|
-
NativeModules
|
|
30
|
-
} = require("react-native");
|
|
31
|
-
const sourceCode = NativeModules?.SourceCode;
|
|
32
|
-
const url = sourceCode?.getConstants?.().scriptURL ?? sourceCode?.scriptURL;
|
|
33
|
-
return typeof url === "string" ? url : null;
|
|
34
|
-
} catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** http(s) origin of the Metro dev server, or null when running embedded. */
|
|
40
|
-
function getDevServerOrigin() {
|
|
41
|
-
const scriptURL = getScriptURL();
|
|
42
|
-
const match = scriptURL?.match(/^https?:\/\/[^/]+/);
|
|
43
|
-
return match ? match[0] : null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Candidate graph URLs, most-likely first. The straight `.bundle`→`.assets`
|
|
48
|
-
* swap works for RN CLI, but Expo dev builds serve a VIRTUAL entry
|
|
49
|
-
* (.expo/.virtual-metro-entry.bundle) that only exists for .bundle requests —
|
|
50
|
-
* its .assets twin 404s — so the real entry modules are tried next, keeping
|
|
51
|
-
* the original query string (platform/dev/etc.) intact.
|
|
52
|
-
*/
|
|
53
|
-
function getGraphURLCandidates() {
|
|
54
|
-
const scriptURL = getScriptURL();
|
|
55
|
-
if (!scriptURL || !/^https?:\/\//.test(scriptURL)) return [];
|
|
56
|
-
const origin = getDevServerOrigin();
|
|
57
|
-
const queryIndex = scriptURL.indexOf("?");
|
|
58
|
-
const query = queryIndex >= 0 ? scriptURL.slice(queryIndex) : "?platform=ios&dev=true";
|
|
59
|
-
const candidates = [];
|
|
60
|
-
if (scriptURL.includes(".bundle")) {
|
|
61
|
-
candidates.push(scriptURL.replace(".bundle", ".assets"));
|
|
62
|
-
}
|
|
63
|
-
if (origin) {
|
|
64
|
-
candidates.push(`${origin}/node_modules/expo-router/entry.assets${query}`, `${origin}/node_modules/expo/AppEntry.assets${query}`, `${origin}/index.assets${query}`);
|
|
65
|
-
}
|
|
66
|
-
return candidates;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Fetch the full asset graph from the dev server and merge it into the store. */
|
|
70
|
-
async function fetchAssetGraph() {
|
|
71
|
-
const s = (0, _state.assetsState)();
|
|
72
|
-
const candidates = getGraphURLCandidates();
|
|
73
|
-
if (!candidates.length) {
|
|
74
|
-
s.graphSupported = false;
|
|
75
|
-
s.graphError = "No Metro dev server (embedded bundle)";
|
|
76
|
-
(0, _assetStore.invalidate)();
|
|
77
|
-
return {
|
|
78
|
-
ok: false,
|
|
79
|
-
message: s.graphError
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (s.graphFetchInFlight) return {
|
|
83
|
-
ok: false,
|
|
84
|
-
message: "Graph fetch already running"
|
|
85
|
-
};
|
|
86
|
-
s.graphFetchInFlight = true;
|
|
87
|
-
try {
|
|
88
|
-
let data = null;
|
|
89
|
-
let lastError = "";
|
|
90
|
-
for (const url of candidates) {
|
|
91
|
-
try {
|
|
92
|
-
const response = await fetch(url);
|
|
93
|
-
if (!response.ok) {
|
|
94
|
-
lastError = `Metro responded ${response.status} for ${url}`;
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
const parsed = await response.json();
|
|
98
|
-
if (Array.isArray(parsed)) {
|
|
99
|
-
data = parsed;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
lastError = "Unexpected .assets payload shape";
|
|
103
|
-
} catch (error) {
|
|
104
|
-
lastError = String(error?.message ?? error);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (!Array.isArray(data)) throw new Error(lastError || "No graph endpoint answered");
|
|
108
|
-
const graph = data;
|
|
109
|
-
for (const asset of graph) {
|
|
110
|
-
if (!asset || typeof asset.name !== "string" || typeof asset.type !== "string") {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
(0, _assetStore.upsertRecord)({
|
|
114
|
-
key: (0, _assetStore.assetKey)(asset.httpServerLocation, asset.name, asset.type),
|
|
115
|
-
name: asset.name,
|
|
116
|
-
type: asset.type,
|
|
117
|
-
origin: "graph",
|
|
118
|
-
hash: asset.hash,
|
|
119
|
-
httpServerLocation: asset.httpServerLocation,
|
|
120
|
-
width: asset.width ?? undefined,
|
|
121
|
-
height: asset.height ?? undefined,
|
|
122
|
-
scales: asset.scales,
|
|
123
|
-
fileSystemLocation: asset.fileSystemLocation,
|
|
124
|
-
files: asset.files,
|
|
125
|
-
fileHashes: asset.fileHashes
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
s.graphSupported = true;
|
|
129
|
-
s.graphCount = graph.length;
|
|
130
|
-
s.graphError = null;
|
|
131
|
-
(0, _assetStore.invalidate)();
|
|
132
|
-
return {
|
|
133
|
-
ok: true,
|
|
134
|
-
count: graph.length
|
|
135
|
-
};
|
|
136
|
-
} catch (error) {
|
|
137
|
-
s.graphSupported = getDevServerOrigin() != null;
|
|
138
|
-
s.graphError = String(error?.message ?? error);
|
|
139
|
-
(0, _assetStore.invalidate)();
|
|
140
|
-
return {
|
|
141
|
-
ok: false,
|
|
142
|
-
message: s.graphError
|
|
143
|
-
};
|
|
144
|
-
} finally {
|
|
145
|
-
s.graphFetchInFlight = false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
//# sourceMappingURL=metroGraph.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetchAssetGraph=fetchAssetGraph,exports.getDevServerOrigin=getDevServerOrigin,exports.getGraphURLCandidates=getGraphURLCandidates,exports.getScriptURL=getScriptURL;var _state=require("../state"),_assetStore=require("../store/assetStore");const GRAPH_TIMEOUT_MS=9e4;async function fetchGraphPayload(e,t){const r=new AbortController;let a;try{return await Promise.race([(async()=>{const t=await fetch(e,{signal:r.signal});if(!t.ok)throw new Error(`Metro responded ${t.status} for ${e}`);return t.json()})(),new Promise((e,s)=>{a=setTimeout(()=>{s(new Error("Asset discovery timed out. Try again.")),r.abort()},Math.max(0,t))})])}finally{clearTimeout(a)}}function getScriptURL(){try{const{NativeModules:e}=require("react-native"),t=e?.SourceCode,r=t?.getConstants?.().scriptURL??t?.scriptURL;return"string"==typeof r?r:null}catch{return null}}function getDevServerOrigin(){const e=getScriptURL(),t=e?.match(/^https?:\/\/[^/]+/);return t?t[0]:null}function getGraphURLCandidates(){const e=getScriptURL();if(!e||!/^https?:\/\//.test(e))return[];const t=getDevServerOrigin(),r=e.indexOf("?"),a=r>=0?e.slice(r):"?platform=ios&dev=true",s=[];return e.includes(".bundle")&&s.push(e.replace(".bundle",".assets")),t&&s.push(`${t}/node_modules/expo-router/entry.assets${a}`,`${t}/node_modules/expo/AppEntry.assets${a}`,`${t}/index.assets${a}`),s}async function fetchAssetGraph(){const e=(0,_state.assetsState)(),t=getGraphURLCandidates();if(!t.length)return e.graphSupported=!1,e.graphError="No Metro dev server (embedded bundle)",(0,_assetStore.invalidate)(),{ok:!1,message:e.graphError};if(e.graphFetchInFlight)return{ok:!1,message:"Graph fetch already running"};e.graphFetchInFlight=!0,e.graphFetchStartedAt=Date.now(),e.graphError=null,(0,_assetStore.invalidate)();const r=e.graphFetchStartedAt+GRAPH_TIMEOUT_MS;try{let a=null,s="";for(const e of t)try{const t=await fetchGraphPayload(e,r-Date.now());if(Array.isArray(t)){a=t;break}s="Unexpected .assets payload shape"}catch(e){if(s=String(e?.message??e),Date.now()>=r)break}if(!Array.isArray(a))throw new Error(s||"No graph endpoint answered");const n=a;let o=0;for(const e of n)e&&"string"==typeof e.name&&"string"==typeof e.type&&(0,_assetStore.upsertRecord)({key:(0,_assetStore.assetKey)(e.httpServerLocation,e.name,e.type),name:e.name,type:e.type,origin:"graph",hash:e.hash,httpServerLocation:e.httpServerLocation,width:e.width??void 0,height:e.height??void 0,scales:e.scales,fileSystemLocation:e.fileSystemLocation,files:e.files,fileHashes:e.fileHashes})&&o++;return e.graphSupported=!0,e.graphCount=o,e.graphError=null,(0,_assetStore.invalidate)(),{ok:!0,count:o}}catch(t){return e.graphSupported=null!=getDevServerOrigin(),e.graphError=String(t?.message??t),(0,_assetStore.invalidate)(),{ok:!1,message:e.graphError}}finally{e.graphFetchInFlight=!1,e.graphFetchStartedAt=null,(0,_assetStore.invalidate)()}}
|