MCPcopy Create free account
hub / github.com/reactnativecn/react-native-update / readMetadataFromJSBundle

Function readMetadataFromJSBundle

scripts/read.js:165–184  ·  view source on GitHub ↗

* 从普通 JS bundle 的注释中读取 metadata

(buffer)

Source from the content-addressed store, hash-verified

163 * 从普通 JS bundle 的注释中读取 metadata
164 */
165function readMetadataFromJSBundle(buffer) {
166 const content = buffer.toString('utf8');
167 const metadata = {};
168
169 // 查找 //# BUNDLE_METADATA {...} 注释
170 const metaMatch = content.match(/\/\/# BUNDLE_METADATA\s+(\{[^}]+\})/);
171 if (metaMatch) {
172 try {
173 const metaObj = JSON.parse(metaMatch[1]);
174 metadata.contentHash = metaObj.contentHash;
175 console.log(`✅ Found contentHash in JS bundle comment: ${metadata.contentHash.slice(0, 16)}...`);
176 } catch (e) {
177 console.error('Failed to parse BUNDLE_METADATA comment:', e);
178 }
179 } else {
180 console.warn('⚠️ BUNDLE_METADATA comment not found in JS bundle');
181 }
182
183 return metadata;
184}
185
186// 测试读取
187const metadata = readBundleMetadata('./index.bundlejs');

Callers

nothing calls this directly

Calls 2

errorMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected