(nativeBinding)
| 7 | let DEFAULT_ADDON; |
| 8 | |
| 9 | function getBinding(nativeBinding) { |
| 10 | // If a path was provided, load the binding from the filesystem. |
| 11 | if (typeof nativeBinding === 'string') { |
| 12 | // See <https://webpack.js.org/api/module-variables/#__non_webpack_require__-webpack-specific> |
| 13 | const requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require; |
| 14 | return requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, '.node')); |
| 15 | } |
| 16 | |
| 17 | // If an object was provided, use it as the binding directly. |
| 18 | if (typeof nativeBinding === 'object' && nativeBinding !== null) { |
| 19 | return nativeBinding; |
| 20 | } |
| 21 | |
| 22 | // If we're using the default binding and it already exists, just return it. |
| 23 | if (DEFAULT_ADDON) { |
| 24 | return DEFAULT_ADDON; |
| 25 | } |
| 26 | |
| 27 | // Otherwise, try to find the binding as a prebuilt binary. |
| 28 | let filename = getPrebuildPath(); |
| 29 | if (filename) { |
| 30 | return DEFAULT_ADDON = require(filename); |
| 31 | } |
| 32 | |
| 33 | // If no prebuilt binary was found, try the default node-gyp locations. |
| 34 | filename = path.join(__dirname, '..', 'build', 'Debug', 'better_sqlite3.node'); |
| 35 | if (!fs.existsSync(filename)) { |
| 36 | filename = path.join(__dirname, '..', 'build', 'Release', 'better_sqlite3.node'); |
| 37 | } |
| 38 | return DEFAULT_ADDON = require(filename); |
| 39 | } |
| 40 | |
| 41 | function getPrebuildPath() { |
| 42 | if (PREBUILD_PLATFORMS.includes(process.platform) && PREBUILD_ARCHS.includes(process.arch)) { |
nothing calls this directly
no test coverage detected