binding.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. // prettier-ignore
  2. /* eslint-disable */
  3. /* auto-generated by NAPI-RS */
  4. const { readFileSync } = require('fs')
  5. let nativeBinding = null
  6. const loadErrors = []
  7. const isMusl = () => {
  8. let musl = false
  9. if (process.platform === 'linux') {
  10. musl = isMuslFromFilesystem()
  11. if (musl === null) {
  12. musl = isMuslFromReport()
  13. }
  14. if (musl === null) {
  15. musl = isMuslFromChildProcess()
  16. }
  17. }
  18. return musl
  19. }
  20. const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
  21. const isMuslFromFilesystem = () => {
  22. try {
  23. return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
  24. } catch {
  25. return null
  26. }
  27. }
  28. const isMuslFromReport = () => {
  29. const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
  30. if (!report) {
  31. return null
  32. }
  33. if (report.header && report.header.glibcVersionRuntime) {
  34. return false
  35. }
  36. if (Array.isArray(report.sharedObjects)) {
  37. if (report.sharedObjects.some(isFileMusl)) {
  38. return true
  39. }
  40. }
  41. return false
  42. }
  43. const isMuslFromChildProcess = () => {
  44. try {
  45. return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
  46. } catch (e) {
  47. // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
  48. return false
  49. }
  50. }
  51. function requireNative() {
  52. if (process.platform === 'android') {
  53. if (process.arch === 'arm64') {
  54. try {
  55. return require('./bcrypt.android-arm64.node')
  56. } catch (e) {
  57. loadErrors.push(e)
  58. }
  59. try {
  60. return require('@node-rs/bcrypt-android-arm64')
  61. } catch (e) {
  62. loadErrors.push(e)
  63. }
  64. } else if (process.arch === 'arm') {
  65. try {
  66. return require('./bcrypt.android-arm-eabi.node')
  67. } catch (e) {
  68. loadErrors.push(e)
  69. }
  70. try {
  71. return require('@node-rs/bcrypt-android-arm-eabi')
  72. } catch (e) {
  73. loadErrors.push(e)
  74. }
  75. } else {
  76. loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
  77. }
  78. } else if (process.platform === 'win32') {
  79. if (process.arch === 'x64') {
  80. try {
  81. return require('./bcrypt.win32-x64-msvc.node')
  82. } catch (e) {
  83. loadErrors.push(e)
  84. }
  85. try {
  86. return require('@node-rs/bcrypt-win32-x64-msvc')
  87. } catch (e) {
  88. loadErrors.push(e)
  89. }
  90. } else if (process.arch === 'ia32') {
  91. try {
  92. return require('./bcrypt.win32-ia32-msvc.node')
  93. } catch (e) {
  94. loadErrors.push(e)
  95. }
  96. try {
  97. return require('@node-rs/bcrypt-win32-ia32-msvc')
  98. } catch (e) {
  99. loadErrors.push(e)
  100. }
  101. } else if (process.arch === 'arm64') {
  102. try {
  103. return require('./bcrypt.win32-arm64-msvc.node')
  104. } catch (e) {
  105. loadErrors.push(e)
  106. }
  107. try {
  108. return require('@node-rs/bcrypt-win32-arm64-msvc')
  109. } catch (e) {
  110. loadErrors.push(e)
  111. }
  112. } else {
  113. loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
  114. }
  115. } else if (process.platform === 'darwin') {
  116. try {
  117. return require('./bcrypt.darwin-universal.node')
  118. } catch (e) {
  119. loadErrors.push(e)
  120. }
  121. try {
  122. return require('@node-rs/bcrypt-darwin-universal')
  123. } catch (e) {
  124. loadErrors.push(e)
  125. }
  126. if (process.arch === 'x64') {
  127. try {
  128. return require('./bcrypt.darwin-x64.node')
  129. } catch (e) {
  130. loadErrors.push(e)
  131. }
  132. try {
  133. return require('@node-rs/bcrypt-darwin-x64')
  134. } catch (e) {
  135. loadErrors.push(e)
  136. }
  137. } else if (process.arch === 'arm64') {
  138. try {
  139. return require('./bcrypt.darwin-arm64.node')
  140. } catch (e) {
  141. loadErrors.push(e)
  142. }
  143. try {
  144. return require('@node-rs/bcrypt-darwin-arm64')
  145. } catch (e) {
  146. loadErrors.push(e)
  147. }
  148. } else {
  149. loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
  150. }
  151. } else if (process.platform === 'freebsd') {
  152. if (process.arch === 'x64') {
  153. try {
  154. return require('./bcrypt.freebsd-x64.node')
  155. } catch (e) {
  156. loadErrors.push(e)
  157. }
  158. try {
  159. return require('@node-rs/bcrypt-freebsd-x64')
  160. } catch (e) {
  161. loadErrors.push(e)
  162. }
  163. } else if (process.arch === 'arm64') {
  164. try {
  165. return require('./bcrypt.freebsd-arm64.node')
  166. } catch (e) {
  167. loadErrors.push(e)
  168. }
  169. try {
  170. return require('@node-rs/bcrypt-freebsd-arm64')
  171. } catch (e) {
  172. loadErrors.push(e)
  173. }
  174. } else {
  175. loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
  176. }
  177. } else if (process.platform === 'linux') {
  178. if (process.arch === 'x64') {
  179. if (isMusl()) {
  180. try {
  181. return require('./bcrypt.linux-x64-musl.node')
  182. } catch (e) {
  183. loadErrors.push(e)
  184. }
  185. try {
  186. return require('@node-rs/bcrypt-linux-x64-musl')
  187. } catch (e) {
  188. loadErrors.push(e)
  189. }
  190. } else {
  191. try {
  192. return require('./bcrypt.linux-x64-gnu.node')
  193. } catch (e) {
  194. loadErrors.push(e)
  195. }
  196. try {
  197. return require('@node-rs/bcrypt-linux-x64-gnu')
  198. } catch (e) {
  199. loadErrors.push(e)
  200. }
  201. }
  202. } else if (process.arch === 'arm64') {
  203. if (isMusl()) {
  204. try {
  205. return require('./bcrypt.linux-arm64-musl.node')
  206. } catch (e) {
  207. loadErrors.push(e)
  208. }
  209. try {
  210. return require('@node-rs/bcrypt-linux-arm64-musl')
  211. } catch (e) {
  212. loadErrors.push(e)
  213. }
  214. } else {
  215. try {
  216. return require('./bcrypt.linux-arm64-gnu.node')
  217. } catch (e) {
  218. loadErrors.push(e)
  219. }
  220. try {
  221. return require('@node-rs/bcrypt-linux-arm64-gnu')
  222. } catch (e) {
  223. loadErrors.push(e)
  224. }
  225. }
  226. } else if (process.arch === 'arm') {
  227. if (isMusl()) {
  228. try {
  229. return require('./bcrypt.linux-arm-musleabihf.node')
  230. } catch (e) {
  231. loadErrors.push(e)
  232. }
  233. try {
  234. return require('@node-rs/bcrypt-linux-arm-musleabihf')
  235. } catch (e) {
  236. loadErrors.push(e)
  237. }
  238. } else {
  239. try {
  240. return require('./bcrypt.linux-arm-gnueabihf.node')
  241. } catch (e) {
  242. loadErrors.push(e)
  243. }
  244. try {
  245. return require('@node-rs/bcrypt-linux-arm-gnueabihf')
  246. } catch (e) {
  247. loadErrors.push(e)
  248. }
  249. }
  250. } else if (process.arch === 'riscv64') {
  251. if (isMusl()) {
  252. try {
  253. return require('./bcrypt.linux-riscv64-musl.node')
  254. } catch (e) {
  255. loadErrors.push(e)
  256. }
  257. try {
  258. return require('@node-rs/bcrypt-linux-riscv64-musl')
  259. } catch (e) {
  260. loadErrors.push(e)
  261. }
  262. } else {
  263. try {
  264. return require('./bcrypt.linux-riscv64-gnu.node')
  265. } catch (e) {
  266. loadErrors.push(e)
  267. }
  268. try {
  269. return require('@node-rs/bcrypt-linux-riscv64-gnu')
  270. } catch (e) {
  271. loadErrors.push(e)
  272. }
  273. }
  274. } else if (process.arch === 'ppc64') {
  275. try {
  276. return require('./bcrypt.linux-ppc64-gnu.node')
  277. } catch (e) {
  278. loadErrors.push(e)
  279. }
  280. try {
  281. return require('@node-rs/bcrypt-linux-ppc64-gnu')
  282. } catch (e) {
  283. loadErrors.push(e)
  284. }
  285. } else if (process.arch === 's390x') {
  286. try {
  287. return require('./bcrypt.linux-s390x-gnu.node')
  288. } catch (e) {
  289. loadErrors.push(e)
  290. }
  291. try {
  292. return require('@node-rs/bcrypt-linux-s390x-gnu')
  293. } catch (e) {
  294. loadErrors.push(e)
  295. }
  296. } else {
  297. loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
  298. }
  299. } else {
  300. loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
  301. }
  302. }
  303. nativeBinding = requireNative()
  304. if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
  305. try {
  306. nativeBinding = require('./bcrypt.wasi.cjs')
  307. } catch (err) {
  308. if (process.env.NAPI_RS_FORCE_WASI) {
  309. console.error(err)
  310. }
  311. }
  312. if (!nativeBinding) {
  313. try {
  314. nativeBinding = require('@node-rs/bcrypt-wasm32-wasi')
  315. } catch (err) {
  316. if (process.env.NAPI_RS_FORCE_WASI) {
  317. console.error(err)
  318. }
  319. }
  320. }
  321. }
  322. if (!nativeBinding) {
  323. if (loadErrors.length > 0) {
  324. // TODO Link to documentation with potential fixes
  325. // - The package owner could build/publish bindings for this arch
  326. // - The user may need to bundle the correct files
  327. // - The user may need to re-install node_modules to get new packages
  328. throw new Error('Failed to load native binding', { cause: loadErrors })
  329. }
  330. throw new Error(`Failed to load native binding`)
  331. }
  332. module.exports.DEFAULT_COST = nativeBinding.DEFAULT_COST
  333. module.exports.genSalt = nativeBinding.genSalt
  334. module.exports.genSaltSync = nativeBinding.genSaltSync
  335. module.exports.hash = nativeBinding.hash
  336. module.exports.hashSync = nativeBinding.hashSync
  337. module.exports.verify = nativeBinding.verify
  338. module.exports.verifySync = nativeBinding.verifySync