@buoy-gg/assets 7.0.41 → 7.0.42

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.
Files changed (204) hide show
  1. package/README.md +12 -73
  2. package/bundlers/vite.mjs +1 -53
  3. package/lib/commonjs/autoCapture.js +1 -5
  4. package/lib/commonjs/autoCapture.web.js +1 -6
  5. package/lib/commonjs/capture/assetLifecycle.js +1 -11
  6. package/lib/commonjs/capture/assetLifecycle.web.js +1 -20
  7. package/lib/commonjs/capture/browserAssets.js +1 -83
  8. package/lib/commonjs/capture/expo.js +1 -46
  9. package/lib/commonjs/capture/expo.web.js +1 -19
  10. package/lib/commonjs/capture/install.js +1 -91
  11. package/lib/commonjs/capture/install.web.js +1 -75
  12. package/lib/commonjs/capture/isBuoyAsset.js +1 -23
  13. package/lib/commonjs/capture/measure.js +1 -187
  14. package/lib/commonjs/capture/metroGraph.js +1 -175
  15. package/lib/commonjs/capture/metroGraph.web.js +1 -27
  16. package/lib/commonjs/capture/registry.js +1 -127
  17. package/lib/commonjs/components/AssetDetail.js +1 -211
  18. package/lib/commonjs/components/AssetImage.js +1 -66
  19. package/lib/commonjs/components/AssetRow.js +1 -232
  20. package/lib/commonjs/components/AssetsFilterBar.js +1 -105
  21. package/lib/commonjs/components/AssetsHeader.js +1 -73
  22. package/lib/commonjs/components/AssetsIcon.js +1 -19
  23. package/lib/commonjs/components/AssetsListControls.js +1 -81
  24. package/lib/commonjs/components/AssetsModal.js +1 -378
  25. package/lib/commonjs/components/ScanNotice.js +1 -86
  26. package/lib/commonjs/components/optionalExpoImage.js +1 -16
  27. package/lib/commonjs/components/optionalExpoImage.web.js +1 -10
  28. package/lib/commonjs/export.js +1 -62
  29. package/lib/commonjs/format.js +1 -59
  30. package/lib/commonjs/hooks/useAssetRecords.js +1 -22
  31. package/lib/commonjs/hooks/useAssetScanStatus.js +1 -28
  32. package/lib/commonjs/index.js +1 -294
  33. package/lib/commonjs/preset.js +1 -39
  34. package/lib/commonjs/remote.js +1 -68
  35. package/lib/commonjs/state.js +1 -51
  36. package/lib/commonjs/store/assetStore.js +1 -256
  37. package/lib/commonjs/store/baseline.js +1 -175
  38. package/lib/commonjs/store/insights.js +1 -120
  39. package/lib/commonjs/sync/assetsSyncAdapter.js +1 -157
  40. package/lib/commonjs/types.js +0 -1
  41. package/lib/commonjs/utils/deviceScale.js +1 -50
  42. package/lib/commonjs/utils/testIDs.js +1 -110
  43. package/lib/module/autoCapture.js +1 -5
  44. package/lib/module/autoCapture.web.js +1 -5
  45. package/lib/module/capture/assetLifecycle.js +1 -7
  46. package/lib/module/capture/assetLifecycle.web.js +1 -16
  47. package/lib/module/capture/browserAssets.js +1 -75
  48. package/lib/module/capture/expo.js +1 -41
  49. package/lib/module/capture/expo.web.js +1 -14
  50. package/lib/module/capture/install.js +1 -85
  51. package/lib/module/capture/install.web.js +1 -68
  52. package/lib/module/capture/isBuoyAsset.js +1 -18
  53. package/lib/module/capture/measure.js +1 -180
  54. package/lib/module/capture/metroGraph.js +1 -168
  55. package/lib/module/capture/metroGraph.web.js +1 -21
  56. package/lib/module/capture/registry.js +1 -120
  57. package/lib/module/components/AssetDetail.js +1 -207
  58. package/lib/module/components/AssetImage.js +1 -62
  59. package/lib/module/components/AssetRow.js +1 -228
  60. package/lib/module/components/AssetsFilterBar.js +1 -101
  61. package/lib/module/components/AssetsHeader.js +1 -69
  62. package/lib/module/components/AssetsIcon.js +1 -12
  63. package/lib/module/components/AssetsListControls.js +1 -77
  64. package/lib/module/components/AssetsModal.js +1 -373
  65. package/lib/module/components/ScanNotice.js +1 -82
  66. package/lib/module/components/optionalExpoImage.js +1 -12
  67. package/lib/module/components/optionalExpoImage.web.js +1 -6
  68. package/lib/module/export.js +1 -57
  69. package/lib/module/format.js +1 -51
  70. package/lib/module/hooks/useAssetRecords.js +1 -18
  71. package/lib/module/hooks/useAssetScanStatus.js +1 -23
  72. package/lib/module/index.js +1 -64
  73. package/lib/module/preset.js +1 -35
  74. package/lib/module/remote.js +1 -61
  75. package/lib/module/state.js +1 -47
  76. package/lib/module/store/assetStore.js +1 -240
  77. package/lib/module/store/baseline.js +1 -167
  78. package/lib/module/store/insights.js +1 -116
  79. package/lib/module/sync/assetsSyncAdapter.js +1 -153
  80. package/lib/module/types.js +0 -1
  81. package/lib/module/utils/deviceScale.js +1 -46
  82. package/lib/module/utils/testIDs.js +1 -99
  83. package/lib/web/index.mjs +3 -4
  84. package/package.json +2 -2
  85. package/lib/commonjs/autoCapture.js.map +0 -1
  86. package/lib/commonjs/autoCapture.web.js.map +0 -1
  87. package/lib/commonjs/capture/assetLifecycle.js.map +0 -1
  88. package/lib/commonjs/capture/assetLifecycle.web.js.map +0 -1
  89. package/lib/commonjs/capture/browserAssets.js.map +0 -1
  90. package/lib/commonjs/capture/expo.js.map +0 -1
  91. package/lib/commonjs/capture/expo.web.js.map +0 -1
  92. package/lib/commonjs/capture/install.js.map +0 -1
  93. package/lib/commonjs/capture/install.web.js.map +0 -1
  94. package/lib/commonjs/capture/isBuoyAsset.js.map +0 -1
  95. package/lib/commonjs/capture/measure.js.map +0 -1
  96. package/lib/commonjs/capture/metroGraph.js.map +0 -1
  97. package/lib/commonjs/capture/metroGraph.web.js.map +0 -1
  98. package/lib/commonjs/capture/registry.js.map +0 -1
  99. package/lib/commonjs/components/AssetDetail.js.map +0 -1
  100. package/lib/commonjs/components/AssetImage.js.map +0 -1
  101. package/lib/commonjs/components/AssetRow.js.map +0 -1
  102. package/lib/commonjs/components/AssetsFilterBar.js.map +0 -1
  103. package/lib/commonjs/components/AssetsHeader.js.map +0 -1
  104. package/lib/commonjs/components/AssetsIcon.js.map +0 -1
  105. package/lib/commonjs/components/AssetsListControls.js.map +0 -1
  106. package/lib/commonjs/components/AssetsModal.js.map +0 -1
  107. package/lib/commonjs/components/ScanNotice.js.map +0 -1
  108. package/lib/commonjs/components/optionalExpoImage.js.map +0 -1
  109. package/lib/commonjs/components/optionalExpoImage.web.js.map +0 -1
  110. package/lib/commonjs/export.js.map +0 -1
  111. package/lib/commonjs/format.js.map +0 -1
  112. package/lib/commonjs/hooks/useAssetRecords.js.map +0 -1
  113. package/lib/commonjs/hooks/useAssetScanStatus.js.map +0 -1
  114. package/lib/commonjs/index.js.map +0 -1
  115. package/lib/commonjs/preset.js.map +0 -1
  116. package/lib/commonjs/remote.js.map +0 -1
  117. package/lib/commonjs/state.js.map +0 -1
  118. package/lib/commonjs/store/assetStore.js.map +0 -1
  119. package/lib/commonjs/store/baseline.js.map +0 -1
  120. package/lib/commonjs/store/insights.js.map +0 -1
  121. package/lib/commonjs/sync/assetsSyncAdapter.js.map +0 -1
  122. package/lib/commonjs/types.js.map +0 -1
  123. package/lib/commonjs/utils/deviceScale.js.map +0 -1
  124. package/lib/commonjs/utils/testIDs.js.map +0 -1
  125. package/lib/module/autoCapture.js.map +0 -1
  126. package/lib/module/autoCapture.web.js.map +0 -1
  127. package/lib/module/capture/assetLifecycle.js.map +0 -1
  128. package/lib/module/capture/assetLifecycle.web.js.map +0 -1
  129. package/lib/module/capture/browserAssets.js.map +0 -1
  130. package/lib/module/capture/expo.js.map +0 -1
  131. package/lib/module/capture/expo.web.js.map +0 -1
  132. package/lib/module/capture/install.js.map +0 -1
  133. package/lib/module/capture/install.web.js.map +0 -1
  134. package/lib/module/capture/isBuoyAsset.js.map +0 -1
  135. package/lib/module/capture/measure.js.map +0 -1
  136. package/lib/module/capture/metroGraph.js.map +0 -1
  137. package/lib/module/capture/metroGraph.web.js.map +0 -1
  138. package/lib/module/capture/registry.js.map +0 -1
  139. package/lib/module/components/AssetDetail.js.map +0 -1
  140. package/lib/module/components/AssetImage.js.map +0 -1
  141. package/lib/module/components/AssetRow.js.map +0 -1
  142. package/lib/module/components/AssetsFilterBar.js.map +0 -1
  143. package/lib/module/components/AssetsHeader.js.map +0 -1
  144. package/lib/module/components/AssetsIcon.js.map +0 -1
  145. package/lib/module/components/AssetsListControls.js.map +0 -1
  146. package/lib/module/components/AssetsModal.js.map +0 -1
  147. package/lib/module/components/ScanNotice.js.map +0 -1
  148. package/lib/module/components/optionalExpoImage.js.map +0 -1
  149. package/lib/module/components/optionalExpoImage.web.js.map +0 -1
  150. package/lib/module/export.js.map +0 -1
  151. package/lib/module/format.js.map +0 -1
  152. package/lib/module/hooks/useAssetRecords.js.map +0 -1
  153. package/lib/module/hooks/useAssetScanStatus.js.map +0 -1
  154. package/lib/module/index.js.map +0 -1
  155. package/lib/module/preset.js.map +0 -1
  156. package/lib/module/remote.js.map +0 -1
  157. package/lib/module/state.js.map +0 -1
  158. package/lib/module/store/assetStore.js.map +0 -1
  159. package/lib/module/store/baseline.js.map +0 -1
  160. package/lib/module/store/insights.js.map +0 -1
  161. package/lib/module/sync/assetsSyncAdapter.js.map +0 -1
  162. package/lib/module/types.js.map +0 -1
  163. package/lib/module/utils/deviceScale.js.map +0 -1
  164. package/lib/module/utils/testIDs.js.map +0 -1
  165. package/lib/typescript/autoCapture.d.ts.map +0 -1
  166. package/lib/typescript/autoCapture.web.d.ts.map +0 -1
  167. package/lib/typescript/capture/assetLifecycle.d.ts.map +0 -1
  168. package/lib/typescript/capture/assetLifecycle.web.d.ts.map +0 -1
  169. package/lib/typescript/capture/browserAssets.d.ts.map +0 -1
  170. package/lib/typescript/capture/expo.d.ts.map +0 -1
  171. package/lib/typescript/capture/expo.web.d.ts.map +0 -1
  172. package/lib/typescript/capture/install.d.ts.map +0 -1
  173. package/lib/typescript/capture/install.web.d.ts.map +0 -1
  174. package/lib/typescript/capture/isBuoyAsset.d.ts.map +0 -1
  175. package/lib/typescript/capture/measure.d.ts.map +0 -1
  176. package/lib/typescript/capture/metroGraph.d.ts.map +0 -1
  177. package/lib/typescript/capture/metroGraph.web.d.ts.map +0 -1
  178. package/lib/typescript/capture/registry.d.ts.map +0 -1
  179. package/lib/typescript/components/AssetDetail.d.ts.map +0 -1
  180. package/lib/typescript/components/AssetImage.d.ts.map +0 -1
  181. package/lib/typescript/components/AssetRow.d.ts.map +0 -1
  182. package/lib/typescript/components/AssetsFilterBar.d.ts.map +0 -1
  183. package/lib/typescript/components/AssetsHeader.d.ts.map +0 -1
  184. package/lib/typescript/components/AssetsIcon.d.ts.map +0 -1
  185. package/lib/typescript/components/AssetsListControls.d.ts.map +0 -1
  186. package/lib/typescript/components/AssetsModal.d.ts.map +0 -1
  187. package/lib/typescript/components/ScanNotice.d.ts.map +0 -1
  188. package/lib/typescript/components/optionalExpoImage.d.ts.map +0 -1
  189. package/lib/typescript/components/optionalExpoImage.web.d.ts.map +0 -1
  190. package/lib/typescript/export.d.ts.map +0 -1
  191. package/lib/typescript/format.d.ts.map +0 -1
  192. package/lib/typescript/hooks/useAssetRecords.d.ts.map +0 -1
  193. package/lib/typescript/hooks/useAssetScanStatus.d.ts.map +0 -1
  194. package/lib/typescript/index.d.ts.map +0 -1
  195. package/lib/typescript/preset.d.ts.map +0 -1
  196. package/lib/typescript/remote.d.ts.map +0 -1
  197. package/lib/typescript/state.d.ts.map +0 -1
  198. package/lib/typescript/store/assetStore.d.ts.map +0 -1
  199. package/lib/typescript/store/baseline.d.ts.map +0 -1
  200. package/lib/typescript/store/insights.d.ts.map +0 -1
  201. package/lib/typescript/sync/assetsSyncAdapter.d.ts.map +0 -1
  202. package/lib/typescript/types.d.ts.map +0 -1
  203. package/lib/typescript/utils/deviceScale.d.ts.map +0 -1
  204. package/lib/typescript/utils/testIDs.d.ts.map +0 -1
@@ -1,187 +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 _reactNative = require("react-native");
11
- var _state = require("../state");
12
- var _assetStore = require("../store/assetStore");
13
- var _metroGraph = require("./metroGraph");
14
- /**
15
- * Byte-size measurement.
16
- *
17
- * Dev only in practice: each scale variant is fetched from the Metro dev
18
- * server (HEAD first for Content-Length, GET-blob fallback since Metro
19
- * doesn't reliably answer HEAD) and the per-variant sizes are summed onto
20
- * the record. Android release resource ids and iOS file:// URIs are not
21
- * measurable from JS — those records keep `estDecodedBytes` as their only
22
- * size signal and the UI marks them as estimates.
23
- */
24
-
25
- const CONCURRENCY = 4;
26
-
27
- /**
28
- * Best displayable URL for a record: the resolved runtime URI, or (dev) the
29
- * same dev-server URL the measurement pass uses — this is what gives graph-
30
- * only (never-loaded) images real thumbnails.
31
- */
32
- function previewURL(record) {
33
- if (record.resolvedUri) return record.resolvedUri;
34
- const variants = variantURLs(record);
35
- return variants.length ? variants[0].url : null;
36
- }
37
-
38
- /**
39
- * Image source for thumbnails/previews. On device the NUMERIC registry id is
40
- * preferred (resolves natively — works for Android release resource ids too).
41
- * On dashboard mirrors that id belongs to the DEVICE's registry and rn-web
42
- * throws "asset with ID N could not be found" — use the device's http(s)
43
- * URL instead (the Metro dev server is reachable from the desktop).
44
- */
45
- function displaySource(record) {
46
- const mirror = (0, _state.assetsState)().captureDisabled;
47
- if (!mirror && record.registryId != null) return record.registryId;
48
- const uri = previewURL(record);
49
- if (!uri) return null;
50
- if (mirror && !/^https?:\/\//.test(uri)) return null;
51
- return {
52
- uri
53
- };
54
- }
55
-
56
- /** All scale-variant URLs for a record, derived without re-encoding pitfalls. */
57
- function variantURLs(record) {
58
- const scales = record.scales.length ? record.scales : [1];
59
-
60
- // Preferred: string surgery on the URL resolveAssetSource already proved
61
- // works (handles Expo's ?unstable_path= form and monorepo rewrites).
62
- const resolved = record.resolvedUri;
63
- if (resolved && /^https?:\/\//.test(resolved) && record.resolvedScale != null) {
64
- const pickedSuffix = record.resolvedScale === 1 ? "" : `@${record.resolvedScale}x`;
65
- const marker = `${pickedSuffix}.${record.type}`;
66
- if (resolved.includes(marker) || pickedSuffix === "") {
67
- return scales.map(scale => {
68
- const suffix = scale === 1 ? "" : `@${scale}x`;
69
- 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
70
- return {
71
- scale,
72
- url
73
- };
74
- });
75
- }
76
- }
77
-
78
- // Graph-only records: rebuild the dev-server URL the way Metro's
79
- // AssetSourceResolver does (plain concatenation), encoding only spaces —
80
- // full encodeURI would double-encode Expo's pre-escaped unstable_path.
81
- const origin = (0, _metroGraph.getDevServerOrigin)();
82
- if (!origin || !record.httpServerLocation) return [];
83
- return scales.map(scale => {
84
- const suffix = scale === 1 ? "" : `@${scale}x`;
85
- const path = `${record.httpServerLocation}/${record.name}${suffix}.${record.type}`;
86
- const sep = path.includes("?") ? "&" : "?";
87
- const url = `${origin}${path}${sep}platform=${platformName()}${record.hash ? `&hash=${record.hash}` : ""}`.replace(/ /g, "%20");
88
- return {
89
- scale,
90
- url
91
- };
92
- });
93
- }
94
- function platformName() {
95
- try {
96
- return _reactNative.Platform.OS;
97
- } catch {
98
- return "ios";
99
- }
100
- }
101
- async function fetchSize(url) {
102
- try {
103
- const head = await fetch(url, {
104
- method: "HEAD"
105
- });
106
- if (head.ok) {
107
- const length = Number(head.headers.get("content-length"));
108
- if (Number.isFinite(length) && length > 0) return length;
109
- }
110
- } catch {
111
- // fall through to GET
112
- }
113
- try {
114
- const response = await fetch(url);
115
- if (!response.ok) return null;
116
- const blob = await response.blob();
117
- return blob.size > 0 ? blob.size : null;
118
- } catch {
119
- return null;
120
- }
121
- }
122
- async function measureRecord(record) {
123
- const variants = variantURLs(record);
124
- if (!variants.length) {
125
- (0, _assetStore.updateRecord)(record.id, {
126
- sizeSource: "estimate"
127
- });
128
- return;
129
- }
130
- const sizesByScale = {};
131
- let total = 0;
132
- for (const {
133
- scale,
134
- url
135
- } of variants) {
136
- const size = await fetchSize(url);
137
- if (size != null) {
138
- sizesByScale[String(scale)] = size;
139
- total += size;
140
- }
141
- }
142
- if (total > 0) {
143
- (0, _assetStore.updateRecord)(record.id, {
144
- sizesByScale,
145
- sizeBytes: total,
146
- sizeSource: "measured"
147
- });
148
- } else {
149
- (0, _assetStore.updateRecord)(record.id, {
150
- sizeSource: "estimate"
151
- });
152
- }
153
- }
154
-
155
- /** Measure every unmeasured record; safe to re-run (skips measured ones). */
156
- async function measureSizes() {
157
- const s = (0, _state.assetsState)();
158
- if (s.measuring) return {
159
- measured: s.measuredCount,
160
- total: (0, _assetStore.getSnapshot)().length
161
- };
162
- const pending = (0, _assetStore.getSnapshot)().filter(r => r.sizeSource !== "measured");
163
- s.measuring = true;
164
- (0, _assetStore.invalidate)();
165
- try {
166
- let index = 0;
167
- const worker = async () => {
168
- for (;;) {
169
- const next = pending[index++];
170
- if (!next) return;
171
- await measureRecord(next);
172
- s.measuredCount = (0, _assetStore.getSnapshot)().filter(r => r.sizeSource === "measured").length;
173
- }
174
- };
175
- await Promise.all(Array.from({
176
- length: Math.min(CONCURRENCY, pending.length)
177
- }, worker));
178
- } finally {
179
- s.measuring = false;
180
- (0, _assetStore.invalidate)();
181
- }
182
- return {
183
- measured: s.measuredCount,
184
- total: (0, _assetStore.getSnapshot)().length
185
- };
186
- }
187
- //# sourceMappingURL=measure.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.displaySource=displaySource;exports.measureSizes=measureSizes;exports.previewURL=previewURL;exports.variantURLs=variantURLs;var _reactNative=require("react-native");var _state=require("../state");var _assetStore=require("../store/assetStore");var _metroGraph=require("./metroGraph");const CONCURRENCY=4;function previewURL(e){if(e.resolvedUri)return e.resolvedUri;const s=variantURLs(e);return s.length?s[0].url:null}function displaySource(e){const s=(0,_state.assetsState)().captureDisabled;if(!s&&e.registryId!=null)return e.registryId;const t=previewURL(e);if(!t)return null;if(s&&!/^https?:\/\//.test(t))return null;return{uri:t}}function variantURLs(e){const s=e.scales.length?e.scales:[1];const t=e.resolvedUri;if(t&&/^https?:\/\//.test(t)&&e.resolvedScale!=null){const n=e.resolvedScale===1?"":`@${e.resolvedScale}x`;const i=`${n}.${e.type}`;if(t.includes(i)||n===""){return s.map(r=>{const u=r===1?"":`@${r}x`;const o=(n===""?t.replace(`.${e.type}`,`${u}.${e.type}`):t.replace(i,`${u}.${e.type}`)).replace(/ /g,"%20");return{scale:r,url:o}})}}const a=(0,_metroGraph.getDevServerOrigin)();if(!a||!e.httpServerLocation)return[];return s.map(n=>{const i=n===1?"":`@${n}x`;const r=`${e.httpServerLocation}/${e.name}${i}.${e.type}`;const u=r.includes("?")?"&":"?";const o=`${a}${r}${u}platform=${platformName()}${e.hash?`&hash=${e.hash}`:""}`.replace(/ /g,"%20");return{scale:n,url:o}})}function platformName(){try{return _reactNative.Platform.OS}catch{return"ios"}}async function fetchSize(e){try{const s=await fetch(e,{method:"HEAD"});if(s.ok){const t=Number(s.headers.get("content-length"));if(Number.isFinite(t)&&t>0)return t}}catch{}try{const s=await fetch(e);if(!s.ok)return null;const t=await s.blob();return t.size>0?t.size:null}catch{return null}}async function measureRecord(e){const s=variantURLs(e);if(!s.length){(0,_assetStore.updateRecord)(e.id,{sizeSource:"estimate"});return}const t={};let a=0;for(const{scale:n,url:i}of s){const r=await fetchSize(i);if(r!=null){t[String(n)]=r;a+=r}}if(a>0){(0,_assetStore.updateRecord)(e.id,{sizesByScale:t,sizeBytes:a,sizeSource:"measured"})}else{(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 s=(0,_assetStore.getSnapshot)().filter(t=>t.sizeSource!=="measured");e.measuring=true;(0,_assetStore.invalidate)();try{let t=0;const a=async()=>{for(;;){const n=s[t++];if(!n)return;await measureRecord(n);e.measuredCount=(0,_assetStore.getSnapshot)().filter(i=>i.sizeSource==="measured").length}};await Promise.all(Array.from({length:Math.min(CONCURRENCY,s.length)},a))}finally{e.measuring=false;(0,_assetStore.invalidate)()}return{measured:e.measuredCount,total:(0,_assetStore.getSnapshot)().length}}
@@ -1,175 +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
- const GRAPH_TIMEOUT_MS = 90_000;
27
-
28
- /** Bound the whole discovery pass, including response body reads. */
29
- async function fetchGraphPayload(url, remainingMs) {
30
- const controller = new AbortController();
31
- let timer;
32
- try {
33
- return await Promise.race([(async () => {
34
- const response = await fetch(url, {
35
- signal: controller.signal
36
- });
37
- if (!response.ok) throw new Error(`Metro responded ${response.status} for ${url}`);
38
- return response.json();
39
- })(), new Promise((_, reject) => {
40
- timer = setTimeout(() => {
41
- reject(new Error("Asset discovery timed out. Try again."));
42
- controller.abort();
43
- }, Math.max(0, remainingMs));
44
- })]);
45
- } finally {
46
- clearTimeout(timer);
47
- }
48
- }
49
- function getScriptURL() {
50
- try {
51
- const {
52
- NativeModules
53
- } = require("react-native");
54
- const sourceCode = NativeModules?.SourceCode;
55
- const url = sourceCode?.getConstants?.().scriptURL ?? sourceCode?.scriptURL;
56
- return typeof url === "string" ? url : null;
57
- } catch {
58
- return null;
59
- }
60
- }
61
-
62
- /** http(s) origin of the Metro dev server, or null when running embedded. */
63
- function getDevServerOrigin() {
64
- const scriptURL = getScriptURL();
65
- const match = scriptURL?.match(/^https?:\/\/[^/]+/);
66
- return match ? match[0] : null;
67
- }
68
-
69
- /**
70
- * Candidate graph URLs, most-likely first. The straight `.bundle`→`.assets`
71
- * swap works for RN CLI, but Expo dev builds serve a VIRTUAL entry
72
- * (.expo/.virtual-metro-entry.bundle) that only exists for .bundle requests —
73
- * its .assets twin 404s — so the real entry modules are tried next, keeping
74
- * the original query string (platform/dev/etc.) intact.
75
- */
76
- function getGraphURLCandidates() {
77
- const scriptURL = getScriptURL();
78
- if (!scriptURL || !/^https?:\/\//.test(scriptURL)) return [];
79
- const origin = getDevServerOrigin();
80
- const queryIndex = scriptURL.indexOf("?");
81
- const query = queryIndex >= 0 ? scriptURL.slice(queryIndex) : "?platform=ios&dev=true";
82
- const candidates = [];
83
- if (scriptURL.includes(".bundle")) {
84
- candidates.push(scriptURL.replace(".bundle", ".assets"));
85
- }
86
- if (origin) {
87
- candidates.push(`${origin}/node_modules/expo-router/entry.assets${query}`, `${origin}/node_modules/expo/AppEntry.assets${query}`, `${origin}/index.assets${query}`);
88
- }
89
- return candidates;
90
- }
91
-
92
- /** Fetch the full asset graph from the dev server and merge it into the store. */
93
- async function fetchAssetGraph() {
94
- const s = (0, _state.assetsState)();
95
- const candidates = getGraphURLCandidates();
96
- if (!candidates.length) {
97
- s.graphSupported = false;
98
- s.graphError = "No Metro dev server (embedded bundle)";
99
- (0, _assetStore.invalidate)();
100
- return {
101
- ok: false,
102
- message: s.graphError
103
- };
104
- }
105
- if (s.graphFetchInFlight) return {
106
- ok: false,
107
- message: "Graph fetch already running"
108
- };
109
- s.graphFetchInFlight = true;
110
- s.graphFetchStartedAt = Date.now();
111
- s.graphError = null;
112
- (0, _assetStore.invalidate)();
113
- const deadline = s.graphFetchStartedAt + GRAPH_TIMEOUT_MS;
114
- try {
115
- let data = null;
116
- let lastError = "";
117
- for (const url of candidates) {
118
- try {
119
- const parsed = await fetchGraphPayload(url, deadline - Date.now());
120
- if (Array.isArray(parsed)) {
121
- data = parsed;
122
- break;
123
- }
124
- lastError = "Unexpected .assets payload shape";
125
- } catch (error) {
126
- lastError = String(error?.message ?? error);
127
- if (Date.now() >= deadline) break;
128
- }
129
- }
130
- if (!Array.isArray(data)) throw new Error(lastError || "No graph endpoint answered");
131
- const graph = data;
132
- let count = 0;
133
- for (const asset of graph) {
134
- if (!asset || typeof asset.name !== "string" || typeof asset.type !== "string") {
135
- continue;
136
- }
137
- const record = (0, _assetStore.upsertRecord)({
138
- key: (0, _assetStore.assetKey)(asset.httpServerLocation, asset.name, asset.type),
139
- name: asset.name,
140
- type: asset.type,
141
- origin: "graph",
142
- hash: asset.hash,
143
- httpServerLocation: asset.httpServerLocation,
144
- width: asset.width ?? undefined,
145
- height: asset.height ?? undefined,
146
- scales: asset.scales,
147
- fileSystemLocation: asset.fileSystemLocation,
148
- files: asset.files,
149
- fileHashes: asset.fileHashes
150
- });
151
- if (record) count++;
152
- }
153
- s.graphSupported = true;
154
- s.graphCount = count;
155
- s.graphError = null;
156
- (0, _assetStore.invalidate)();
157
- return {
158
- ok: true,
159
- count
160
- };
161
- } catch (error) {
162
- s.graphSupported = getDevServerOrigin() != null;
163
- s.graphError = String(error?.message ?? error);
164
- (0, _assetStore.invalidate)();
165
- return {
166
- ok: false,
167
- message: s.graphError
168
- };
169
- } finally {
170
- s.graphFetchInFlight = false;
171
- s.graphFetchStartedAt = null;
172
- (0, _assetStore.invalidate)();
173
- }
174
- }
175
- //# sourceMappingURL=metroGraph.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.fetchAssetGraph=fetchAssetGraph;exports.getDevServerOrigin=getDevServerOrigin;exports.getGraphURLCandidates=getGraphURLCandidates;exports.getScriptURL=getScriptURL;var _state=require("../state");var _assetStore=require("../store/assetStore");const GRAPH_TIMEOUT_MS=9e4;async function fetchGraphPayload(e,r){const n=new AbortController;let s;try{return await Promise.race([(async()=>{const a=await fetch(e,{signal:n.signal});if(!a.ok)throw new Error(`Metro responded ${a.status} for ${e}`);return a.json()})(),new Promise((a,i)=>{s=setTimeout(()=>{i(new Error("Asset discovery timed out. Try again."));n.abort()},Math.max(0,r))})])}finally{clearTimeout(s)}}function getScriptURL(){try{const{NativeModules:e}=require("react-native");const r=e?.SourceCode;const n=r?.getConstants?.().scriptURL??r?.scriptURL;return typeof n==="string"?n:null}catch{return null}}function getDevServerOrigin(){const e=getScriptURL();const r=e?.match(/^https?:\/\/[^/]+/);return r?r[0]:null}function getGraphURLCandidates(){const e=getScriptURL();if(!e||!/^https?:\/\//.test(e))return[];const r=getDevServerOrigin();const n=e.indexOf("?");const s=n>=0?e.slice(n):"?platform=ios&dev=true";const a=[];if(e.includes(".bundle")){a.push(e.replace(".bundle",".assets"))}if(r){a.push(`${r}/node_modules/expo-router/entry.assets${s}`,`${r}/node_modules/expo/AppEntry.assets${s}`,`${r}/index.assets${s}`)}return a}async function fetchAssetGraph(){const e=(0,_state.assetsState)();const r=getGraphURLCandidates();if(!r.length){e.graphSupported=false;e.graphError="No Metro dev server (embedded bundle)";(0,_assetStore.invalidate)();return{ok:false,message:e.graphError}}if(e.graphFetchInFlight)return{ok:false,message:"Graph fetch already running"};e.graphFetchInFlight=true;e.graphFetchStartedAt=Date.now();e.graphError=null;(0,_assetStore.invalidate)();const n=e.graphFetchStartedAt+GRAPH_TIMEOUT_MS;try{let s=null;let a="";for(const t of r){try{const o=await fetchGraphPayload(t,n-Date.now());if(Array.isArray(o)){s=o;break}a="Unexpected .assets payload shape"}catch(o){a=String(o?.message??o);if(Date.now()>=n)break}}if(!Array.isArray(s))throw new Error(a||"No graph endpoint answered");const i=s;let c=0;for(const t of i){if(!t||typeof t.name!=="string"||typeof t.type!=="string"){continue}const o=(0,_assetStore.upsertRecord)({key:(0,_assetStore.assetKey)(t.httpServerLocation,t.name,t.type),name:t.name,type:t.type,origin:"graph",hash:t.hash,httpServerLocation:t.httpServerLocation,width:t.width??void 0,height:t.height??void 0,scales:t.scales,fileSystemLocation:t.fileSystemLocation,files:t.files,fileHashes:t.fileHashes});if(o)c++}e.graphSupported=true;e.graphCount=c;e.graphError=null;(0,_assetStore.invalidate)();return{ok:true,count:c}}catch(s){e.graphSupported=getDevServerOrigin()!=null;e.graphError=String(s?.message??s);(0,_assetStore.invalidate)();return{ok:false,message:e.graphError}}finally{e.graphFetchInFlight=false;e.graphFetchStartedAt=null;(0,_assetStore.invalidate)()}}
@@ -1,27 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchAssetGraph = fetchAssetGraph;
7
- exports.getDevServerOrigin = getDevServerOrigin;
8
- exports.getScriptURL = getScriptURL;
9
- var _browserAssets = require("./browserAssets");
10
- function getScriptURL() {
11
- return null;
12
- }
13
- function getDevServerOrigin() {
14
- return null;
15
- }
16
- async function fetchAssetGraph() {
17
- (0, _browserAssets.scanBrowserAssets)();
18
- const count = (0, _browserAssets.getBrowserAssetManifest)().length;
19
- return count ? {
20
- ok: true,
21
- count
22
- } : {
23
- ok: false,
24
- message: 'Register a browser asset manifest to inspect files that have not loaded yet.'
25
- };
26
- }
27
- //# sourceMappingURL=metroGraph.web.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.fetchAssetGraph=fetchAssetGraph;exports.getDevServerOrigin=getDevServerOrigin;exports.getScriptURL=getScriptURL;var _browserAssets=require("./browserAssets");function getScriptURL(){return null}function getDevServerOrigin(){return null}async function fetchAssetGraph(){(0,_browserAssets.scanBrowserAssets)();const e=(0,_browserAssets.getBrowserAssetManifest)().length;return e?{ok:true,count:e}:{ok:false,message:"Register a browser asset manifest to inspect files that have not loaded yet."}}
@@ -1,127 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getRegistryModule = getRegistryModule;
7
- exports.patchRegisterAsset = patchRegisterAsset;
8
- exports.resolveRegistryAsset = resolveRegistryAsset;
9
- exports.upsertFromPackagerAsset = upsertFromPackagerAsset;
10
- exports.walkRegistry = walkRegistry;
11
- var _assetStore = require("../store/assetStore");
12
- /**
13
- * Runtime access to @react-native/assets-registry.
14
- *
15
- * Asset ids are contiguous 1..N (`assets.push` return value), so a plain
16
- * getAssetByID walk enumerates every asset registered so far — including
17
- * everything registered BEFORE this tool was evaluated. That's why, unlike
18
- * the images tool, there is no "must be the first import" requirement here:
19
- * the walk backfills whatever the patch missed.
20
- *
21
- * registerAsset is patched (plain non-frozen CommonJS export, looked up at
22
- * call time by Metro's generated asset modules) purely for LIVE updates as
23
- * lazily-required assets register later.
24
- */
25
-
26
- /** Runtime shape of a registry entry (fileSystemLocation/files are stripped by Metro). */
27
-
28
- let cachedRegistry;
29
- function getRegistryModule() {
30
- if (cachedRegistry !== undefined) return cachedRegistry;
31
- let mod = null;
32
- try {
33
- mod = require("@react-native/assets-registry/registry");
34
- } catch {
35
- // Old RN layouts (< 0.72) don't ship @react-native/assets-registry as a
36
- // resolvable package — the registry only exists at this deep path. RN's
37
- // deep-import deprecation warning fires when this executes, but it only
38
- // executes on those old layouts, where there is no other way in.
39
- try {
40
- mod = require("react-native/Libraries/Image/AssetRegistry");
41
- } catch {
42
- mod = null;
43
- }
44
- }
45
- cachedRegistry = mod && typeof mod.getAssetByID === "function" ? mod : null;
46
- return cachedRegistry;
47
- }
48
-
49
- /** resolveAssetSource(id) → this environment's URI (dev URL / file:// / res id). */
50
- function resolveRegistryAsset(registryId) {
51
- try {
52
- const {
53
- Image
54
- } = require("react-native");
55
- const resolved = Image.resolveAssetSource(registryId);
56
- if (resolved && typeof resolved.uri === "string") {
57
- return {
58
- uri: resolved.uri,
59
- scale: resolved.scale ?? 1
60
- };
61
- }
62
- } catch {
63
- // resolution is enrichment — never let it break the walk
64
- }
65
- return null;
66
- }
67
- function upsertFromPackagerAsset(registryId, asset) {
68
- const resolved = resolveRegistryAsset(registryId);
69
- return (0, _assetStore.upsertRecord)({
70
- key: (0, _assetStore.assetKey)(asset.httpServerLocation, asset.name, asset.type),
71
- name: asset.name,
72
- type: asset.type,
73
- origin: "registry",
74
- registryId,
75
- hash: asset.hash,
76
- httpServerLocation: asset.httpServerLocation,
77
- width: asset.width ?? undefined,
78
- height: asset.height ?? undefined,
79
- scales: asset.scales,
80
- resolvedUri: resolved?.uri,
81
- resolvedScale: resolved?.scale,
82
- loaded: true
83
- });
84
- }
85
-
86
- /** Enumerate every asset registered so far. Returns the highest id seen. */
87
- function walkRegistry() {
88
- const registry = getRegistryModule();
89
- if (!registry) return 0;
90
- let id = 0;
91
- for (;;) {
92
- const asset = registry.getAssetByID(id + 1);
93
- if (!asset) break;
94
- id++;
95
- upsertFromPackagerAsset(id, asset);
96
- }
97
- return id;
98
- }
99
- const PATCH_MARKER = "__buoyAssetsPatched";
100
-
101
- /**
102
- * Wrap registerAsset so future registrations stream in live. Safe to call
103
- * more than once (marker guard); the walk covers anything registered before.
104
- */
105
- function patchRegisterAsset() {
106
- const registry = getRegistryModule();
107
- if (!registry) return false;
108
- const original = registry.registerAsset;
109
- if (original[PATCH_MARKER]) return true;
110
- const wrapped = asset => {
111
- const id = original.call(registry, asset);
112
- try {
113
- upsertFromPackagerAsset(id, asset);
114
- } catch {
115
- // never break app asset registration
116
- }
117
- return id;
118
- };
119
- wrapped[PATCH_MARKER] = true;
120
- try {
121
- registry.registerAsset = wrapped;
122
- } catch {
123
- return false;
124
- }
125
- return true;
126
- }
127
- //# sourceMappingURL=registry.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getRegistryModule=getRegistryModule;exports.patchRegisterAsset=patchRegisterAsset;exports.resolveRegistryAsset=resolveRegistryAsset;exports.upsertFromPackagerAsset=upsertFromPackagerAsset;exports.walkRegistry=walkRegistry;var _assetStore=require("../store/assetStore");let cachedRegistry;function getRegistryModule(){if(cachedRegistry!==void 0)return cachedRegistry;let t=null;try{t=require("@react-native/assets-registry/registry")}catch{try{t=require("react-native/Libraries/Image/AssetRegistry")}catch{t=null}}cachedRegistry=t&&typeof t.getAssetByID==="function"?t:null;return cachedRegistry}function resolveRegistryAsset(t){try{const{Image:e}=require("react-native");const r=e.resolveAssetSource(t);if(r&&typeof r.uri==="string"){return{uri:r.uri,scale:r.scale??1}}}catch{}return null}function upsertFromPackagerAsset(t,e){const r=resolveRegistryAsset(t);return(0,_assetStore.upsertRecord)({key:(0,_assetStore.assetKey)(e.httpServerLocation,e.name,e.type),name:e.name,type:e.type,origin:"registry",registryId:t,hash:e.hash,httpServerLocation:e.httpServerLocation,width:e.width??void 0,height:e.height??void 0,scales:e.scales,resolvedUri:r?.uri,resolvedScale:r?.scale,loaded:true})}function walkRegistry(){const t=getRegistryModule();if(!t)return 0;let e=0;for(;;){const r=t.getAssetByID(e+1);if(!r)break;e++;upsertFromPackagerAsset(e,r)}return e}const PATCH_MARKER="__buoyAssetsPatched";function patchRegisterAsset(){const t=getRegistryModule();if(!t)return false;const e=t.registerAsset;if(e[PATCH_MARKER])return true;const r=s=>{const i=e.call(t,s);try{upsertFromPackagerAsset(i,s)}catch{}return i};r[PATCH_MARKER]=true;try{t.registerAsset=r}catch{return false}return true}