scripts/patch-package.js
function patchPackageJSON_preNodeGyp_modulePath(filePath)
{
  let packageReadData = fs.readFileSync(filePath);
  let packageJSON = JSON.parse(packageReadData);
  if ( packageJSON && packageJSON.binary && packageJSON.binary.module_path ) {
    let binaryPathConfiguration = packageJSON.binary.module_path;
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{node_abi\}/g, "node_abi");
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{platform\}/g, "platform");
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{arch\}/g, "arch");
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{target_arch\}/g, "target_arch");
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{libc\}/g, "libc");
    packageJSON.binary.module_path = binaryPathConfiguration;
    let packageWriteData = JSON.stringify(packageJSON, null, 2);
    fs.writeFileSync(filePath, packageWriteData);
  }
}
function patchPackageJSON_preNodeGyp_modulePath(filePath)
{
  let packageReadData = fs.readFileSync(filePath);
  let packageJSON = JSON.parse(packageReadData);
  if ( packageJSON && packageJSON.binary && packageJSON.binary.module_path ) {
    let binaryPathConfiguration = packageJSON.binary.module_path;
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{node_abi\}/g, "node_abi");
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{platform\}/g, "platform");
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{arch\}/g, "arch");
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{target_arch\}/g, "target_arch");
    binaryPathConfiguration = binaryPathConfiguration.replace(/\{libc\}/g, "libc");
    packageJSON.binary.module_path = binaryPathConfiguration;
    let packageWriteData = JSON.stringify(packageJSON, null, 2);
    fs.writeFileSync(filePath, packageWriteData);
  }
}
function patchPackageJSON_preNodeGyp_modulePath ( filePath ) { let packageReadData = fs . readFileSync ( filePath ) ; let packageJSON = JSON . parse ( packageReadData ) ; if ( packageJSON && packageJSON . binary && packageJSON . binary . module_path ) { let binaryPathConfiguration = packageJSON . binary . module_path ; binaryPathConfiguration = binaryPathConfiguration . replace ( / \{node_abi\} / g , "node_abi" ) ; binaryPathConfiguration = binaryPathConfiguration . replace ( / \{platform\} / g , "platform" ) ; binaryPathConfiguration = binaryPathConfiguration . replace ( / \{arch\} / g , "arch" ) ; binaryPathConfiguration = binaryPathConfiguration . replace ( / \{target_arch\} / g , "target_arch" ) ; binaryPathConfiguration = binaryPathConfiguration . replace ( / \{libc\} / g , "libc" ) ; packageJSON . binary . module_path = binaryPathConfiguration ; let packageWriteData = JSON . stringify ( packageJSON , null , 2 ) ; fs . writeFileSync ( filePath , packageWriteData ) ; } }
Patches a package.json in case it has variable substitution for the module's binary at runtime. Since we are cross-compiling for mobile, this substitution will have different values at build time and runtime, so we pre-substitute them with fixed values.
Patches a package . json in case it has variable substitution for the module s binary at runtime . Since we are cross - compiling for mobile this substitution will have different values at build time and runtime so we pre - substitute them with fixed values .