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

Function metadataSerializer

scripts/bundle-metadata-plugin.js:156–180  ·  view source on GitHub ↗
(entryPoint, preModules, graph, options)

Source from the content-addressed store, hash-verified

154}
155
156function metadataSerializer(entryPoint, preModules, graph, options) {
157 setupHermescWrapper();
158 const baseJSBundle = require('metro/src/DeltaBundler/Serializers/baseJSBundle');
159 const bundleToString = require('metro/src/lib/bundleToString');
160 const bundle = baseJSBundle(entryPoint, preModules, graph, options);
161 const { code: bundleCode } = bundleToString(bundle);
162 const contentHash = calculateContentHash(bundleCode);
163 const metadataInjection = generateMetadataInjection(contentHash);
164 const metadataComment = generateMetadataComment(contentHash);
165 const hashFilePath = path.join(PROJECT_ROOT, 'bundle-hash.json');
166
167 try {
168 const hashData = {
169 contentHash,
170 timestamp: new Date().toISOString(),
171 };
172 fs.writeFileSync(hashFilePath, JSON.stringify(hashData, null, 2));
173 console.log(`✅ [Metro] Saved hash to: ${hashFilePath}`);
174 console.log(`🔐 [Metro] Hash: ${contentHash.slice(0, 16)}...`);
175 } catch (error) {
176 console.error('❌ [Metro] Failed to save hash file:', error);
177 }
178
179 return bundleCode + metadataInjection + metadataComment;
180}
181
182module.exports = {
183 metadataSerializer,

Callers

nothing calls this directly

Calls 5

setupHermescWrapperFunction · 0.85
calculateContentHashFunction · 0.85
generateMetadataCommentFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected