Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(database): now nativeBinding supports addon object #974

Merged
merged 8 commits into from
Sep 2, 2023
9 changes: 8 additions & 1 deletion lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ function Database(filenameGiven, options) {
if (nativeBindingPath == null) {
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require('bindings')('better_sqlite3.node'));
} else {
addon = require(path.resolve(nativeBindingPath).replace(/(\.node)?$/, '.node'));
// If webpack is used to build the application, we must use `__non_webpack_require__`.
const requireFunc =
typeof __webpack_require__ === 'function'
? __non_webpack_require__
: require;

addon = requireFunc(path.resolve(nativeBindingPath).replace(/(\.node)?$/, '.node'));
}

if (!addon.isInitialized) {
addon.setErrorConstructor(SqliteError);
addon.isInitialized = true;
Expand Down