Lines 1-53javascript
2/* eslint-disable no-console */
4 * postinstall-fetch-binaries.js — fetch OpenCV binaries matching this
5 * package's version from GitHub Releases.
7 * Runs after `npm install` / `yarn install` in the consumer app.
8 * Reads `package.json#version`, fetches the matching iOS xcframework
9 * + Android per-ABI archives, extracts them into the expected
10 * locations so `pod install` and `./gradlew` find them on the next
13 * The mechanism is fault-tolerant:
14 * - Already-on-disk binaries → skip fetch (matched by .opencv-fetched
15 * marker file recording the version).
16 * - Transient network failures → retry up to 3× with exponential
18 * - Unreachable GH Releases (e.g., offline install of a fresh
19 * package version) → exit cleanly with a warning + instructions
20 * to re-run `npm install` later. This lets `npm install` itself
21 * succeed (the native build will fail later with a clear error,
22 * vs blocking the JS-only `npm install` step here).
25 * OPENCV_BINARY_BASE_URL — override the default GH Releases URL
26 * (useful for internal mirrors).
27 * SKIP_OPENCV_FETCH=1 — bail out (used by CI builds where the
28 * binaries are pre-staged manually).
31const fs = require('fs');
32const path = require('path');
33const https = require('https');
34const { execSync } = require('child_process');
35const zlib = require('zlib');
HighChild Process
Package source references child process execution.
scripts/postinstall-fetch-binaries.jsView on unpkg · L33 37const PKG = require(path.join(__dirname, '..', 'package.json'));
38const VERSION = PKG.version;
39const TAG = `v${VERSION}`;
41// When this script is moved to the public lib repo, BASE_URL becomes
42// `https://github.com/bhargavkanda/react-native-image-stitcher/releases/download`.
43// Until then (development in the monorepo), allow override via env.
44const DEFAULT_BASE_URL =
45 'https://github.com/bhargavkanda/react-native-image-stitcher/releases/download';
46const BASE_URL = process.env.OPENCV_BINARY_BASE_URL || DEFAULT_BASE_URL;
HighEntrypoint Build Divergence
Manifest entrypoint contains risky behavior absent from dist/build output.
scripts/postinstall-fetch-binaries.jsView on unpkg · L7 47
HighSame File Env Network Execution
A single source file combines environment access, network access, and code or shell execution; review context before blocking.
scripts/postinstall-fetch-binaries.jsView on unpkg · L32 48const PKG_ROOT = path.join(__dirname, '..');
49const IOS_DEST = path.join(PKG_ROOT, 'ios', 'Frameworks');
50const ANDROID_DEST = path.join(PKG_ROOT, 'android', 'vendor');
51const MARKER = path.join(PKG_ROOT, '.opencv-fetched');
53const IOS_ASSET = `RNImageStitcher-${TAG}-ios.zip`;