@buoy-gg/assets 7.0.38 → 7.0.39
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/lib/commonjs/capture/expo.js +46 -1
- package/lib/commonjs/capture/expo.js.map +1 -0
- package/lib/commonjs/capture/install.js +91 -1
- package/lib/commonjs/capture/install.js.map +1 -0
- package/lib/commonjs/capture/isBuoyAsset.js +23 -1
- package/lib/commonjs/capture/isBuoyAsset.js.map +1 -0
- package/lib/commonjs/capture/measure.js +186 -1
- package/lib/commonjs/capture/measure.js.map +1 -0
- package/lib/commonjs/capture/metroGraph.js +175 -1
- package/lib/commonjs/capture/metroGraph.js.map +1 -0
- package/lib/commonjs/capture/registry.js +127 -1
- package/lib/commonjs/capture/registry.js.map +1 -0
- package/lib/commonjs/components/AssetDetail.js +211 -1
- package/lib/commonjs/components/AssetDetail.js.map +1 -0
- package/lib/commonjs/components/AssetImage.js +66 -1
- package/lib/commonjs/components/AssetImage.js.map +1 -0
- package/lib/commonjs/components/AssetRow.js +232 -1
- package/lib/commonjs/components/AssetRow.js.map +1 -0
- package/lib/commonjs/components/AssetsFilterBar.js +105 -1
- package/lib/commonjs/components/AssetsFilterBar.js.map +1 -0
- package/lib/commonjs/components/AssetsHeader.js +73 -1
- package/lib/commonjs/components/AssetsHeader.js.map +1 -0
- package/lib/commonjs/components/AssetsIcon.js +19 -1
- package/lib/commonjs/components/AssetsIcon.js.map +1 -0
- package/lib/commonjs/components/AssetsListControls.js +81 -1
- package/lib/commonjs/components/AssetsListControls.js.map +1 -0
- package/lib/commonjs/components/AssetsModal.js +378 -1
- package/lib/commonjs/components/AssetsModal.js.map +1 -0
- package/lib/commonjs/components/ScanNotice.js +85 -1
- package/lib/commonjs/components/ScanNotice.js.map +1 -0
- package/lib/commonjs/components/optionalExpoImage.js +16 -1
- package/lib/commonjs/components/optionalExpoImage.js.map +1 -0
- package/lib/commonjs/components/optionalExpoImage.web.js +11 -1
- package/lib/commonjs/components/optionalExpoImage.web.js.map +1 -0
- package/lib/commonjs/export.js +62 -1
- package/lib/commonjs/export.js.map +1 -0
- package/lib/commonjs/format.js +59 -1
- package/lib/commonjs/format.js.map +1 -0
- package/lib/commonjs/hooks/useAssetRecords.js +22 -1
- package/lib/commonjs/hooks/useAssetRecords.js.map +1 -0
- package/lib/commonjs/hooks/useAssetScanStatus.js +28 -1
- package/lib/commonjs/hooks/useAssetScanStatus.js.map +1 -0
- package/lib/commonjs/index.js +313 -1
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/preset.js +39 -1
- package/lib/commonjs/preset.js.map +1 -0
- package/lib/commonjs/remote.js +68 -1
- package/lib/commonjs/remote.js.map +1 -0
- package/lib/commonjs/state.js +51 -1
- package/lib/commonjs/state.js.map +1 -0
- package/lib/commonjs/store/assetStore.js +256 -1
- package/lib/commonjs/store/assetStore.js.map +1 -0
- package/lib/commonjs/store/baseline.js +175 -1
- package/lib/commonjs/store/baseline.js.map +1 -0
- package/lib/commonjs/store/insights.js +120 -1
- package/lib/commonjs/store/insights.js.map +1 -0
- package/lib/commonjs/sync/assetsSyncAdapter.js +157 -1
- package/lib/commonjs/sync/assetsSyncAdapter.js.map +1 -0
- package/lib/commonjs/types.js +2 -1
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/deviceScale.js +50 -1
- package/lib/commonjs/utils/deviceScale.js.map +1 -0
- package/lib/commonjs/utils/testIDs.js +110 -1
- package/lib/commonjs/utils/testIDs.js.map +1 -0
- package/lib/module/capture/expo.js +41 -1
- package/lib/module/capture/expo.js.map +1 -0
- package/lib/module/capture/install.js +85 -1
- package/lib/module/capture/install.js.map +1 -0
- package/lib/module/capture/isBuoyAsset.js +18 -1
- package/lib/module/capture/isBuoyAsset.js.map +1 -0
- package/lib/module/capture/measure.js +179 -1
- package/lib/module/capture/measure.js.map +1 -0
- package/lib/module/capture/metroGraph.js +168 -1
- package/lib/module/capture/metroGraph.js.map +1 -0
- package/lib/module/capture/registry.js +120 -1
- package/lib/module/capture/registry.js.map +1 -0
- package/lib/module/components/AssetDetail.js +207 -1
- package/lib/module/components/AssetDetail.js.map +1 -0
- package/lib/module/components/AssetImage.js +62 -1
- package/lib/module/components/AssetImage.js.map +1 -0
- package/lib/module/components/AssetRow.js +228 -1
- package/lib/module/components/AssetRow.js.map +1 -0
- package/lib/module/components/AssetsFilterBar.js +101 -1
- package/lib/module/components/AssetsFilterBar.js.map +1 -0
- package/lib/module/components/AssetsHeader.js +69 -1
- package/lib/module/components/AssetsHeader.js.map +1 -0
- package/lib/module/components/AssetsIcon.js +12 -1
- package/lib/module/components/AssetsIcon.js.map +1 -0
- package/lib/module/components/AssetsListControls.js +77 -1
- package/lib/module/components/AssetsListControls.js.map +1 -0
- package/lib/module/components/AssetsModal.js +373 -1
- package/lib/module/components/AssetsModal.js.map +1 -0
- package/lib/module/components/ScanNotice.js +81 -1
- package/lib/module/components/ScanNotice.js.map +1 -0
- package/lib/module/components/optionalExpoImage.js +12 -1
- package/lib/module/components/optionalExpoImage.js.map +1 -0
- package/lib/module/components/optionalExpoImage.web.js +7 -1
- package/lib/module/components/optionalExpoImage.web.js.map +1 -0
- package/lib/module/export.js +57 -1
- package/lib/module/export.js.map +1 -0
- package/lib/module/format.js +51 -1
- package/lib/module/format.js.map +1 -0
- package/lib/module/hooks/useAssetRecords.js +18 -1
- package/lib/module/hooks/useAssetRecords.js.map +1 -0
- package/lib/module/hooks/useAssetScanStatus.js +23 -1
- package/lib/module/hooks/useAssetScanStatus.js.map +1 -0
- package/lib/module/index.js +63 -1
- package/lib/module/index.js.map +1 -0
- package/lib/module/preset.js +35 -1
- package/lib/module/preset.js.map +1 -0
- package/lib/module/remote.js +61 -1
- package/lib/module/remote.js.map +1 -0
- package/lib/module/state.js +47 -1
- package/lib/module/state.js.map +1 -0
- package/lib/module/store/assetStore.js +240 -1
- package/lib/module/store/assetStore.js.map +1 -0
- package/lib/module/store/baseline.js +167 -1
- package/lib/module/store/baseline.js.map +1 -0
- package/lib/module/store/insights.js +116 -1
- package/lib/module/store/insights.js.map +1 -0
- package/lib/module/sync/assetsSyncAdapter.js +153 -1
- package/lib/module/sync/assetsSyncAdapter.js.map +1 -0
- package/lib/module/types.js +2 -1
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/deviceScale.js +46 -1
- package/lib/module/utils/deviceScale.js.map +1 -0
- package/lib/module/utils/testIDs.js +99 -1
- package/lib/module/utils/testIDs.js.map +1 -0
- package/lib/typescript/capture/expo.d.ts.map +1 -0
- package/lib/typescript/capture/install.d.ts.map +1 -0
- package/lib/typescript/capture/isBuoyAsset.d.ts.map +1 -0
- package/lib/typescript/capture/measure.d.ts.map +1 -0
- package/lib/typescript/capture/metroGraph.d.ts.map +1 -0
- package/lib/typescript/capture/registry.d.ts.map +1 -0
- package/lib/typescript/components/AssetDetail.d.ts.map +1 -0
- package/lib/typescript/components/AssetImage.d.ts.map +1 -0
- package/lib/typescript/components/AssetRow.d.ts.map +1 -0
- package/lib/typescript/components/AssetsFilterBar.d.ts.map +1 -0
- package/lib/typescript/components/AssetsHeader.d.ts.map +1 -0
- package/lib/typescript/components/AssetsIcon.d.ts.map +1 -0
- package/lib/typescript/components/AssetsListControls.d.ts.map +1 -0
- package/lib/typescript/components/AssetsModal.d.ts.map +1 -0
- package/lib/typescript/components/ScanNotice.d.ts.map +1 -0
- package/lib/typescript/components/optionalExpoImage.d.ts.map +1 -0
- package/lib/typescript/components/optionalExpoImage.web.d.ts.map +1 -0
- package/lib/typescript/export.d.ts.map +1 -0
- package/lib/typescript/format.d.ts.map +1 -0
- package/lib/typescript/hooks/useAssetRecords.d.ts.map +1 -0
- package/lib/typescript/hooks/useAssetScanStatus.d.ts.map +1 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/preset.d.ts.map +1 -0
- package/lib/typescript/remote.d.ts.map +1 -0
- package/lib/typescript/state.d.ts.map +1 -0
- package/lib/typescript/store/assetStore.d.ts.map +1 -0
- package/lib/typescript/store/baseline.d.ts.map +1 -0
- package/lib/typescript/store/insights.d.ts.map +1 -0
- package/lib/typescript/sync/assetsSyncAdapter.d.ts.map +1 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/utils/deviceScale.d.ts.map +1 -0
- package/lib/typescript/utils/testIDs.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1,179 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Byte-size measurement.
|
|
5
|
+
*
|
|
6
|
+
* Dev only in practice: each scale variant is fetched from the Metro dev
|
|
7
|
+
* server (HEAD first for Content-Length, GET-blob fallback since Metro
|
|
8
|
+
* doesn't reliably answer HEAD) and the per-variant sizes are summed onto
|
|
9
|
+
* the record. Android release resource ids and iOS file:// URIs are not
|
|
10
|
+
* measurable from JS — those records keep `estDecodedBytes` as their only
|
|
11
|
+
* size signal and the UI marks them as estimates.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { assetsState } from "../state";
|
|
15
|
+
import { getSnapshot, invalidate, updateRecord } from "../store/assetStore";
|
|
16
|
+
import { getDevServerOrigin } from "./metroGraph";
|
|
17
|
+
const CONCURRENCY = 4;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Best displayable URL for a record: the resolved runtime URI, or (dev) the
|
|
21
|
+
* same dev-server URL the measurement pass uses — this is what gives graph-
|
|
22
|
+
* only (never-loaded) images real thumbnails.
|
|
23
|
+
*/
|
|
24
|
+
export function previewURL(record) {
|
|
25
|
+
if (record.resolvedUri) return record.resolvedUri;
|
|
26
|
+
const variants = variantURLs(record);
|
|
27
|
+
return variants.length ? variants[0].url : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Image source for thumbnails/previews. On device the NUMERIC registry id is
|
|
32
|
+
* preferred (resolves natively — works for Android release resource ids too).
|
|
33
|
+
* On dashboard mirrors that id belongs to the DEVICE's registry and rn-web
|
|
34
|
+
* throws "asset with ID N could not be found" — use the device's http(s)
|
|
35
|
+
* URL instead (the Metro dev server is reachable from the desktop).
|
|
36
|
+
*/
|
|
37
|
+
export function displaySource(record) {
|
|
38
|
+
const mirror = assetsState().captureDisabled;
|
|
39
|
+
if (!mirror && record.registryId != null) return record.registryId;
|
|
40
|
+
const uri = previewURL(record);
|
|
41
|
+
if (!uri) return null;
|
|
42
|
+
if (mirror && !/^https?:\/\//.test(uri)) return null;
|
|
43
|
+
return {
|
|
44
|
+
uri
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** All scale-variant URLs for a record, derived without re-encoding pitfalls. */
|
|
49
|
+
export function variantURLs(record) {
|
|
50
|
+
const scales = record.scales.length ? record.scales : [1];
|
|
51
|
+
|
|
52
|
+
// Preferred: string surgery on the URL resolveAssetSource already proved
|
|
53
|
+
// works (handles Expo's ?unstable_path= form and monorepo rewrites).
|
|
54
|
+
const resolved = record.resolvedUri;
|
|
55
|
+
if (resolved && /^https?:\/\//.test(resolved) && record.resolvedScale != null) {
|
|
56
|
+
const pickedSuffix = record.resolvedScale === 1 ? "" : `@${record.resolvedScale}x`;
|
|
57
|
+
const marker = `${pickedSuffix}.${record.type}`;
|
|
58
|
+
if (resolved.includes(marker) || pickedSuffix === "") {
|
|
59
|
+
return scales.map(scale => {
|
|
60
|
+
const suffix = scale === 1 ? "" : `@${scale}x`;
|
|
61
|
+
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
|
|
62
|
+
return {
|
|
63
|
+
scale,
|
|
64
|
+
url
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Graph-only records: rebuild the dev-server URL the way Metro's
|
|
71
|
+
// AssetSourceResolver does (plain concatenation), encoding only spaces —
|
|
72
|
+
// full encodeURI would double-encode Expo's pre-escaped unstable_path.
|
|
73
|
+
const origin = getDevServerOrigin();
|
|
74
|
+
if (!origin || !record.httpServerLocation) return [];
|
|
75
|
+
return scales.map(scale => {
|
|
76
|
+
const suffix = scale === 1 ? "" : `@${scale}x`;
|
|
77
|
+
const path = `${record.httpServerLocation}/${record.name}${suffix}.${record.type}`;
|
|
78
|
+
const sep = path.includes("?") ? "&" : "?";
|
|
79
|
+
const url = `${origin}${path}${sep}platform=${platformName()}${record.hash ? `&hash=${record.hash}` : ""}`.replace(/ /g, "%20");
|
|
80
|
+
return {
|
|
81
|
+
scale,
|
|
82
|
+
url
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function platformName() {
|
|
87
|
+
try {
|
|
88
|
+
return require("react-native").Platform.OS;
|
|
89
|
+
} catch {
|
|
90
|
+
return "ios";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function fetchSize(url) {
|
|
94
|
+
try {
|
|
95
|
+
const head = await fetch(url, {
|
|
96
|
+
method: "HEAD"
|
|
97
|
+
});
|
|
98
|
+
if (head.ok) {
|
|
99
|
+
const length = Number(head.headers.get("content-length"));
|
|
100
|
+
if (Number.isFinite(length) && length > 0) return length;
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
// fall through to GET
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const response = await fetch(url);
|
|
107
|
+
if (!response.ok) return null;
|
|
108
|
+
const blob = await response.blob();
|
|
109
|
+
return blob.size > 0 ? blob.size : null;
|
|
110
|
+
} catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function measureRecord(record) {
|
|
115
|
+
const variants = variantURLs(record);
|
|
116
|
+
if (!variants.length) {
|
|
117
|
+
updateRecord(record.id, {
|
|
118
|
+
sizeSource: "estimate"
|
|
119
|
+
});
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const sizesByScale = {};
|
|
123
|
+
let total = 0;
|
|
124
|
+
for (const {
|
|
125
|
+
scale,
|
|
126
|
+
url
|
|
127
|
+
} of variants) {
|
|
128
|
+
const size = await fetchSize(url);
|
|
129
|
+
if (size != null) {
|
|
130
|
+
sizesByScale[String(scale)] = size;
|
|
131
|
+
total += size;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (total > 0) {
|
|
135
|
+
updateRecord(record.id, {
|
|
136
|
+
sizesByScale,
|
|
137
|
+
sizeBytes: total,
|
|
138
|
+
sizeSource: "measured"
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
updateRecord(record.id, {
|
|
142
|
+
sizeSource: "estimate"
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Measure every unmeasured record; safe to re-run (skips measured ones). */
|
|
148
|
+
export async function measureSizes() {
|
|
149
|
+
const s = assetsState();
|
|
150
|
+
if (s.measuring) return {
|
|
151
|
+
measured: s.measuredCount,
|
|
152
|
+
total: getSnapshot().length
|
|
153
|
+
};
|
|
154
|
+
const pending = getSnapshot().filter(r => r.sizeSource !== "measured");
|
|
155
|
+
s.measuring = true;
|
|
156
|
+
invalidate();
|
|
157
|
+
try {
|
|
158
|
+
let index = 0;
|
|
159
|
+
const worker = async () => {
|
|
160
|
+
for (;;) {
|
|
161
|
+
const next = pending[index++];
|
|
162
|
+
if (!next) return;
|
|
163
|
+
await measureRecord(next);
|
|
164
|
+
s.measuredCount = getSnapshot().filter(r => r.sizeSource === "measured").length;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
await Promise.all(Array.from({
|
|
168
|
+
length: Math.min(CONCURRENCY, pending.length)
|
|
169
|
+
}, worker));
|
|
170
|
+
} finally {
|
|
171
|
+
s.measuring = false;
|
|
172
|
+
invalidate();
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
measured: s.measuredCount,
|
|
176
|
+
total: getSnapshot().length
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=measure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["assetsState","getSnapshot","invalidate","updateRecord","getDevServerOrigin","CONCURRENCY","previewURL","record","resolvedUri","variants","variantURLs","length","url","displaySource","mirror","captureDisabled","registryId","uri","test","scales","resolved","resolvedScale","pickedSuffix","marker","type","includes","map","scale","suffix","replace","origin","httpServerLocation","path","name","sep","platformName","hash","require","Platform","OS","fetchSize","head","fetch","method","ok","Number","headers","get","isFinite","response","blob","size","measureRecord","id","sizeSource","sizesByScale","total","String","sizeBytes","measureSizes","s","measuring","measured","measuredCount","pending","filter","r","index","worker","next","Promise","all","Array","from","Math","min"],"sourceRoot":"../../../src","sources":["capture/measure.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,QAAQ,UAAU;AACtC,SAASC,WAAW,EAAEC,UAAU,EAAEC,YAAY,QAAQ,qBAAqB;AAC3E,SAASC,kBAAkB,QAAQ,cAAc;AAGjD,MAAMC,WAAW,GAAG,CAAC;;AAErB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,MAAmB,EAAiB;EAC7D,IAAIA,MAAM,CAACC,WAAW,EAAE,OAAOD,MAAM,CAACC,WAAW;EACjD,MAAMC,QAAQ,GAAGC,WAAW,CAACH,MAAM,CAAC;EACpC,OAAOE,QAAQ,CAACE,MAAM,GAAGF,QAAQ,CAAC,CAAC,CAAC,CAAEG,GAAG,GAAG,IAAI;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3BN,MAAmB,EACc;EACjC,MAAMO,MAAM,GAAGd,WAAW,CAAC,CAAC,CAACe,eAAe;EAC5C,IAAI,CAACD,MAAM,IAAIP,MAAM,CAACS,UAAU,IAAI,IAAI,EAAE,OAAOT,MAAM,CAACS,UAAU;EAClE,MAAMC,GAAG,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O;IACL4D,QAAQ,EAAEF,CAAC,CAACG,aAAa;IACzBP,KAAK,EAAEvD,WAAW,CAAC,CAAC,CAACU;EACvB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1,168 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Metro dev-server graph fetch.
|
|
5
|
+
*
|
|
6
|
+
* The dev server serves `<entry>.assets` next to `<entry>.bundle` — the full
|
|
7
|
+
* dependency graph's AssetData[], INCLUDING assets never required at runtime
|
|
8
|
+
* and the `fileSystemLocation`/`files` fields Metro strips from runtime
|
|
9
|
+
* records. Deriving the URL by swapping `.bundle` → `.assets` on the running
|
|
10
|
+
* bundle's scriptURL keeps the entry path and platform/dev query params
|
|
11
|
+
* intact for both RN CLI (index.bundle) and Expo (…/entry.bundle) layouts.
|
|
12
|
+
*
|
|
13
|
+
* Graph-only records (in the graph, not the registry) are exactly the
|
|
14
|
+
* "shipped but never loaded" set. Dev-only: no server, no graph.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { assetsState } from "../state";
|
|
18
|
+
import { assetKey, invalidate, upsertRecord } from "../store/assetStore";
|
|
19
|
+
const GRAPH_TIMEOUT_MS = 90_000;
|
|
20
|
+
|
|
21
|
+
/** Bound the whole discovery pass, including response body reads. */
|
|
22
|
+
async function fetchGraphPayload(url, remainingMs) {
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
let timer;
|
|
25
|
+
try {
|
|
26
|
+
return await Promise.race([(async () => {
|
|
27
|
+
const response = await fetch(url, {
|
|
28
|
+
signal: controller.signal
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) throw new Error(`Metro responded ${response.status} for ${url}`);
|
|
31
|
+
return response.json();
|
|
32
|
+
})(), new Promise((_, reject) => {
|
|
33
|
+
timer = setTimeout(() => {
|
|
34
|
+
reject(new Error("Asset discovery timed out. Try again."));
|
|
35
|
+
controller.abort();
|
|
36
|
+
}, Math.max(0, remainingMs));
|
|
37
|
+
})]);
|
|
38
|
+
} finally {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function getScriptURL() {
|
|
43
|
+
try {
|
|
44
|
+
const {
|
|
45
|
+
NativeModules
|
|
46
|
+
} = require("react-native");
|
|
47
|
+
const sourceCode = NativeModules?.SourceCode;
|
|
48
|
+
const url = sourceCode?.getConstants?.().scriptURL ?? sourceCode?.scriptURL;
|
|
49
|
+
return typeof url === "string" ? url : null;
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** http(s) origin of the Metro dev server, or null when running embedded. */
|
|
56
|
+
export function getDevServerOrigin() {
|
|
57
|
+
const scriptURL = getScriptURL();
|
|
58
|
+
const match = scriptURL?.match(/^https?:\/\/[^/]+/);
|
|
59
|
+
return match ? match[0] : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Candidate graph URLs, most-likely first. The straight `.bundle`→`.assets`
|
|
64
|
+
* swap works for RN CLI, but Expo dev builds serve a VIRTUAL entry
|
|
65
|
+
* (.expo/.virtual-metro-entry.bundle) that only exists for .bundle requests —
|
|
66
|
+
* its .assets twin 404s — so the real entry modules are tried next, keeping
|
|
67
|
+
* the original query string (platform/dev/etc.) intact.
|
|
68
|
+
*/
|
|
69
|
+
export function getGraphURLCandidates() {
|
|
70
|
+
const scriptURL = getScriptURL();
|
|
71
|
+
if (!scriptURL || !/^https?:\/\//.test(scriptURL)) return [];
|
|
72
|
+
const origin = getDevServerOrigin();
|
|
73
|
+
const queryIndex = scriptURL.indexOf("?");
|
|
74
|
+
const query = queryIndex >= 0 ? scriptURL.slice(queryIndex) : "?platform=ios&dev=true";
|
|
75
|
+
const candidates = [];
|
|
76
|
+
if (scriptURL.includes(".bundle")) {
|
|
77
|
+
candidates.push(scriptURL.replace(".bundle", ".assets"));
|
|
78
|
+
}
|
|
79
|
+
if (origin) {
|
|
80
|
+
candidates.push(`${origin}/node_modules/expo-router/entry.assets${query}`, `${origin}/node_modules/expo/AppEntry.assets${query}`, `${origin}/index.assets${query}`);
|
|
81
|
+
}
|
|
82
|
+
return candidates;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Fetch the full asset graph from the dev server and merge it into the store. */
|
|
86
|
+
export async function fetchAssetGraph() {
|
|
87
|
+
const s = assetsState();
|
|
88
|
+
const candidates = getGraphURLCandidates();
|
|
89
|
+
if (!candidates.length) {
|
|
90
|
+
s.graphSupported = false;
|
|
91
|
+
s.graphError = "No Metro dev server (embedded bundle)";
|
|
92
|
+
invalidate();
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
message: s.graphError
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (s.graphFetchInFlight) return {
|
|
99
|
+
ok: false,
|
|
100
|
+
message: "Graph fetch already running"
|
|
101
|
+
};
|
|
102
|
+
s.graphFetchInFlight = true;
|
|
103
|
+
s.graphFetchStartedAt = Date.now();
|
|
104
|
+
s.graphError = null;
|
|
105
|
+
invalidate();
|
|
106
|
+
const deadline = s.graphFetchStartedAt + GRAPH_TIMEOUT_MS;
|
|
107
|
+
try {
|
|
108
|
+
let data = null;
|
|
109
|
+
let lastError = "";
|
|
110
|
+
for (const url of candidates) {
|
|
111
|
+
try {
|
|
112
|
+
const parsed = await fetchGraphPayload(url, deadline - Date.now());
|
|
113
|
+
if (Array.isArray(parsed)) {
|
|
114
|
+
data = parsed;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
lastError = "Unexpected .assets payload shape";
|
|
118
|
+
} catch (error) {
|
|
119
|
+
lastError = String(error?.message ?? error);
|
|
120
|
+
if (Date.now() >= deadline) break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (!Array.isArray(data)) throw new Error(lastError || "No graph endpoint answered");
|
|
124
|
+
const graph = data;
|
|
125
|
+
let count = 0;
|
|
126
|
+
for (const asset of graph) {
|
|
127
|
+
if (!asset || typeof asset.name !== "string" || typeof asset.type !== "string") {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const record = upsertRecord({
|
|
131
|
+
key: assetKey(asset.httpServerLocation, asset.name, asset.type),
|
|
132
|
+
name: asset.name,
|
|
133
|
+
type: asset.type,
|
|
134
|
+
origin: "graph",
|
|
135
|
+
hash: asset.hash,
|
|
136
|
+
httpServerLocation: asset.httpServerLocation,
|
|
137
|
+
width: asset.width ?? undefined,
|
|
138
|
+
height: asset.height ?? undefined,
|
|
139
|
+
scales: asset.scales,
|
|
140
|
+
fileSystemLocation: asset.fileSystemLocation,
|
|
141
|
+
files: asset.files,
|
|
142
|
+
fileHashes: asset.fileHashes
|
|
143
|
+
});
|
|
144
|
+
if (record) count++;
|
|
145
|
+
}
|
|
146
|
+
s.graphSupported = true;
|
|
147
|
+
s.graphCount = count;
|
|
148
|
+
s.graphError = null;
|
|
149
|
+
invalidate();
|
|
150
|
+
return {
|
|
151
|
+
ok: true,
|
|
152
|
+
count
|
|
153
|
+
};
|
|
154
|
+
} catch (error) {
|
|
155
|
+
s.graphSupported = getDevServerOrigin() != null;
|
|
156
|
+
s.graphError = String(error?.message ?? error);
|
|
157
|
+
invalidate();
|
|
158
|
+
return {
|
|
159
|
+
ok: false,
|
|
160
|
+
message: s.graphError
|
|
161
|
+
};
|
|
162
|
+
} finally {
|
|
163
|
+
s.graphFetchInFlight = false;
|
|
164
|
+
s.graphFetchStartedAt = null;
|
|
165
|
+
invalidate();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=metroGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["assetsState","assetKey","invalidate","upsertRecord","GRAPH_TIMEOUT_MS","fetchGraphPayload","url","remainingMs","controller","AbortController","timer","Promise","race","response","fetch","signal","ok","Error","status","json","_","reject","setTimeout","abort","Math","max","clearTimeout","getScriptURL","NativeModules","require","sourceCode","SourceCode","getConstants","scriptURL","getDevServerOrigin","match","getGraphURLCandidates","test","origin","queryIndex","indexOf","query","slice","candidates","includes","push","replace","fetchAssetGraph","s","length","graphSupported","graphError","message","graphFetchInFlight","graphFetchStartedAt","Date","now","deadline","data","lastError","parsed","Array","isArray","error","String","graph","count","asset","name","type","record","key","httpServerLocation","hash","width","undefined","height","scales","fileSystemLocation","files","fileHashes","graphCount"],"sourceRoot":"../../../src","sources":["capture/metroGraph.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,QAAQ,UAAU;AACtC,SAASC,QAAQ,EAAEC,UAAU,EAAEC,YAAY,QAAQ,qBAAqB;AAExE,MAAMC,gBAAgB,GAAG,MAAM;;AAE/B;AACA,eAAeC,iBAAiBA,CAACC,GAAW,EAAEC,WAAmB,EAAoB;EACnF,MAAMC,UAAU,GAAG,IAAIC,eAAe,CAAC,CAAC;EACxC,IAAIC,KAAgD;EACpD,IAAI;IACF,OAAO,MAAMC,OAAO,CAACC,IAAI,CAAC,CACxB,CAAC,YAAY;MACX,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACR,GAAG,EAAE;QAAES,MAAM,EAAEP,UAAU,CAACO;MAAO,CAAC,CAAC;MAChE,IAAI,CAACF,QAAQ,CAACG,EAAE,EAAE,MAAM,IAAIC,KAAK,CAAC,mBAAmBJ,QAAQ,CAACK,MAAM,QAAQZ,GAAG,EAAE,CAAC;MAClF,OAAOO,QAAQ,CAACM,IAAI,CAAC,CAAC;IACxB,CAAC,EAAE,CAAC,EACJ,IAAIR,OAAO,CAAQ,CAACS,CAAC,EAAEC,MAAM,KAAK;MAChCX,KAAK,GAAGY,UAAU,CAAC,MAAM;QACvBD,MAAM,CAAC,IAAIJ,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC1DT,UAAU,CAACe,KAAK,CAAC,CAAC;MACpB,CAAC,EA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X,KAAK,CAACW,kBAAkB;QAC5CC,KAAK,EAAEZ,KAAK,CAACY,KAAK;QAClBC,UAAU,EAAEb,KAAK,CAACa;MACpB,CAAC,CAAC;MACF,IAAIV,MAAM,EAAEJ,KAAK,EAAE;IACrB;IACAlB,CAAC,CAACE,cAAc,GAAG,IAAI;IACvBF,CAAC,CAACiC,UAAU,GAAGf,KAAK;IACpBlB,CAAC,CAACG,UAAU,GAAG,IAAI;IACnBjD,UAAU,CAAC,CAAC;IACZ,OAAO;MAAEc,EAAE,EAAE,IAAI;MAAEkD;IAAM,CAAC;EAC5B,CAAC,CAAC,OAAOH,KAAK,EAAE;IACdf,CAAC,CAACE,cAAc,GAAGhB,kBAAkB,CAAC,CAAC,IAAI,IAAI;IAC/Cc,CAAC,CAACG,UAAU,GAAGa,MAAM,CAAED,KAAK,EAAYX,OAAO,IAAIW,KAAK,CAAC;IACzD7D,UAAU,CAAC,CAAC;IACZ,OAAO;MAAEc,EAAE,EAAE,KAAK;MAAEoC,OAAO,EAAEJ,CAAC,CAACG;IAAW,CAAC;EAC7C,CAAC,SAAS;IACRH,CAAC,CAACK,kBAAkB,GAAG,KAAK;IAC5BL,CAAC,CAACM,mBAAmB,GAAG,IAAI;IAC5BpD,UAAU,CAAC,CAAC;EACd;AACF","ignoreList":[]}
|
|
@@ -1 +1,120 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runtime access to @react-native/assets-registry.
|
|
5
|
+
*
|
|
6
|
+
* Asset ids are contiguous 1..N (`assets.push` return value), so a plain
|
|
7
|
+
* getAssetByID walk enumerates every asset registered so far — including
|
|
8
|
+
* everything registered BEFORE this tool was evaluated. That's why, unlike
|
|
9
|
+
* the images tool, there is no "must be the first import" requirement here:
|
|
10
|
+
* the walk backfills whatever the patch missed.
|
|
11
|
+
*
|
|
12
|
+
* registerAsset is patched (plain non-frozen CommonJS export, looked up at
|
|
13
|
+
* call time by Metro's generated asset modules) purely for LIVE updates as
|
|
14
|
+
* lazily-required assets register later.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { upsertRecord, assetKey } from "../store/assetStore";
|
|
18
|
+
|
|
19
|
+
/** Runtime shape of a registry entry (fileSystemLocation/files are stripped by Metro). */
|
|
20
|
+
|
|
21
|
+
let cachedRegistry;
|
|
22
|
+
export function getRegistryModule() {
|
|
23
|
+
if (cachedRegistry !== undefined) return cachedRegistry;
|
|
24
|
+
let mod = null;
|
|
25
|
+
try {
|
|
26
|
+
mod = require("@react-native/assets-registry/registry");
|
|
27
|
+
} catch {
|
|
28
|
+
// Old RN layouts (< 0.72) don't ship @react-native/assets-registry as a
|
|
29
|
+
// resolvable package — the registry only exists at this deep path. RN's
|
|
30
|
+
// deep-import deprecation warning fires when this executes, but it only
|
|
31
|
+
// executes on those old layouts, where there is no other way in.
|
|
32
|
+
try {
|
|
33
|
+
mod = require("react-native/Libraries/Image/AssetRegistry");
|
|
34
|
+
} catch {
|
|
35
|
+
mod = null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
cachedRegistry = mod && typeof mod.getAssetByID === "function" ? mod : null;
|
|
39
|
+
return cachedRegistry;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** resolveAssetSource(id) → this environment's URI (dev URL / file:// / res id). */
|
|
43
|
+
export function resolveRegistryAsset(registryId) {
|
|
44
|
+
try {
|
|
45
|
+
const {
|
|
46
|
+
Image
|
|
47
|
+
} = require("react-native");
|
|
48
|
+
const resolved = Image.resolveAssetSource(registryId);
|
|
49
|
+
if (resolved && typeof resolved.uri === "string") {
|
|
50
|
+
return {
|
|
51
|
+
uri: resolved.uri,
|
|
52
|
+
scale: resolved.scale ?? 1
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
// resolution is enrichment — never let it break the walk
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
export function upsertFromPackagerAsset(registryId, asset) {
|
|
61
|
+
const resolved = resolveRegistryAsset(registryId);
|
|
62
|
+
return upsertRecord({
|
|
63
|
+
key: assetKey(asset.httpServerLocation, asset.name, asset.type),
|
|
64
|
+
name: asset.name,
|
|
65
|
+
type: asset.type,
|
|
66
|
+
origin: "registry",
|
|
67
|
+
registryId,
|
|
68
|
+
hash: asset.hash,
|
|
69
|
+
httpServerLocation: asset.httpServerLocation,
|
|
70
|
+
width: asset.width ?? undefined,
|
|
71
|
+
height: asset.height ?? undefined,
|
|
72
|
+
scales: asset.scales,
|
|
73
|
+
resolvedUri: resolved?.uri,
|
|
74
|
+
resolvedScale: resolved?.scale,
|
|
75
|
+
loaded: true
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Enumerate every asset registered so far. Returns the highest id seen. */
|
|
80
|
+
export function walkRegistry() {
|
|
81
|
+
const registry = getRegistryModule();
|
|
82
|
+
if (!registry) return 0;
|
|
83
|
+
let id = 0;
|
|
84
|
+
for (;;) {
|
|
85
|
+
const asset = registry.getAssetByID(id + 1);
|
|
86
|
+
if (!asset) break;
|
|
87
|
+
id++;
|
|
88
|
+
upsertFromPackagerAsset(id, asset);
|
|
89
|
+
}
|
|
90
|
+
return id;
|
|
91
|
+
}
|
|
92
|
+
const PATCH_MARKER = "__buoyAssetsPatched";
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Wrap registerAsset so future registrations stream in live. Safe to call
|
|
96
|
+
* more than once (marker guard); the walk covers anything registered before.
|
|
97
|
+
*/
|
|
98
|
+
export function patchRegisterAsset() {
|
|
99
|
+
const registry = getRegistryModule();
|
|
100
|
+
if (!registry) return false;
|
|
101
|
+
const original = registry.registerAsset;
|
|
102
|
+
if (original[PATCH_MARKER]) return true;
|
|
103
|
+
const wrapped = asset => {
|
|
104
|
+
const id = original.call(registry, asset);
|
|
105
|
+
try {
|
|
106
|
+
upsertFromPackagerAsset(id, asset);
|
|
107
|
+
} catch {
|
|
108
|
+
// never break app asset registration
|
|
109
|
+
}
|
|
110
|
+
return id;
|
|
111
|
+
};
|
|
112
|
+
wrapped[PATCH_MARKER] = true;
|
|
113
|
+
try {
|
|
114
|
+
registry.registerAsset = wrapped;
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["upsertRecord","assetKey","cachedRegistry","getRegistryModule","undefined","mod","require","getAssetByID","resolveRegistryAsset","registryId","Image","resolved","resolveAssetSource","uri","scale","upsertFromPackagerAsset","asset","key","httpServerLocation","name","type","origin","hash","width","height","scales","resolvedUri","resolvedScale","loaded","walkRegistry","registry","id","PATCH_MARKER","patchRegisterAsset","original","registerAsset","wrapped","call"],"sourceRoot":"../../../src","sources":["capture/registry.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,EAAEC,QAAQ,QAAQ,qBAAqB;;AAG5D;;AAiBA,IAAIC,cAAiD;AAErD,OAAO,SAASC,iBAAiBA,CAAA,EAA0B;EACzD,IAAID,cAAc,KAAKE,SAAS,EAAE,OAAOF,cAAc;EACvD,IAAIG,GAA0B,GAAG,IAAI;EACrC,IAAI;IACFA,GAAG,GAAGC,OAAO,CAAC,wCAAwC,CAAC;EACzD,CAAC,CAAC,MAAM;IACN;IACA;IACA;IACA;IACA,IAAI;MACFD,GAAG,GAAGC,OAAO,CAAC,4CAA4C,CAAC;IAC7D,CAAC,CAAC,MAAM;MACND,GAAG,GAAG,IAAI;IACZ;EACF;EACAH,cAAc,GACZG,GAAG,IAAI,OAAOA,GAAG,CAACE,YAAY,KAAK,UAAU,GAAGF,GAAG,GAAG,IAAI;EAC5D,OAAOH,cAAc;AACvB;;AAEA;AACA,OAAO,SAASM,oBAAoBA,CAClCC,UAAkB,EACqB;E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