UNPKG

react-native-node-api

Version:
58 lines (57 loc) 2.96 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ANDROID_ARCHITECTURES = exports.DEFAULT_ANDROID_TRIPLETS = void 0; exports.determineAndroidLibsFilename = determineAndroidLibsFilename; exports.createAndroidLibsDirectory = createAndroidLibsDirectory; const strict_1 = __importDefault(require("node:assert/strict")); const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); const path_utils_js_1 = require("../path-utils.js"); exports.DEFAULT_ANDROID_TRIPLETS = [ "aarch64-linux-android", "armv7a-linux-androideabi", "i686-linux-android", "x86_64-linux-android", ]; exports.ANDROID_ARCHITECTURES = { "armv7a-linux-androideabi": "armeabi-v7a", "aarch64-linux-android": "arm64-v8a", "i686-linux-android": "x86", "x86_64-linux-android": "x86_64", }; /** * Determine the filename of the Android libs directory based on the framework paths. * Ensuring that all framework paths have the same base name. */ function determineAndroidLibsFilename(libraryPaths) { const libraryName = (0, path_utils_js_1.determineLibraryBasename)(libraryPaths); return `${libraryName}.android.node`; } async function createAndroidLibsDirectory({ outputPath, libraries, autoLink, }) { // Delete and recreate any existing output directory await node_fs_1.default.promises.rm(outputPath, { recursive: true, force: true }); await node_fs_1.default.promises.mkdir(outputPath, { recursive: true }); for (const { triplet, libraryPath } of libraries) { (0, strict_1.default)(node_fs_1.default.existsSync(libraryPath), `Library not found: ${libraryPath} for triplet ${triplet}`); const arch = exports.ANDROID_ARCHITECTURES[triplet]; const archOutputPath = node_path_1.default.join(outputPath, arch); await node_fs_1.default.promises.mkdir(archOutputPath, { recursive: true }); // Strip the ".node" extension from the library name const libraryName = node_path_1.default.basename(libraryPath, ".node"); const soSuffixedName = node_path_1.default.extname(libraryName) === ".so" ? libraryName : `${libraryName}.so`; const finalLibraryName = libraryName.startsWith("lib") ? soSuffixedName : `lib${soSuffixedName}`; const libraryOutputPath = node_path_1.default.join(archOutputPath, finalLibraryName); await node_fs_1.default.promises.copyFile(libraryPath, libraryOutputPath); // TODO: Update the install path in the library file } if (autoLink) { // Write a file to mark the Android libs directory is a Node-API module await node_fs_1.default.promises.writeFile(node_path_1.default.join(outputPath, "react-native-node-api-module"), "", "utf8"); } return outputPath; }