Skip to content

Commit

Permalink
fix(NODE-6592): remove dependency on bindings (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson authored Dec 3, 2024
1 parent 727cc1f commit b07a5d2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
6 changes: 4 additions & 2 deletions lib/kerberos.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';

const kerberos = require('bindings')('kerberos');
const { loadBindings, defineOperation } = require('./util');


const kerberos = loadBindings();
const KerberosClient = kerberos.KerberosClient;
const KerberosServer = kerberos.KerberosServer;
const defineOperation = require('./util').defineOperation;

// GSS Flags
const GSS_C_DELEG_FLAG = 1;
Expand Down
13 changes: 10 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ function validateParameter(parameter, specs, specIndex) {
}

throw new TypeError(
`Invalid type for parameter \`${spec.name}\`, expected \`${
spec.type
`Invalid type for parameter \`${spec.name}\`, expected \`${spec.type
}\` but found \`${typeof parameter}\``
);
}
Expand Down Expand Up @@ -81,4 +80,12 @@ function defineOperation(fn, paramDefs) {
};
}

module.exports = { defineOperation, validateParameter };
function loadBindings() {
try {
return require('../build/Release/kerberos.node');
} catch {
return require('../build/Debug/kerberos.node');
}
}

module.exports = { defineOperation, validateParameter, loadBindings };
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"url": "https://jira.mongodb.org/projects/NODE/issues/"
},
"dependencies": {
"bindings": "^1.5.0",
"node-addon-api": "^6.1.0",
"prebuild-install": "^7.1.2"
},
Expand Down Expand Up @@ -74,4 +73,4 @@
},
"license": "Apache-2.0",
"readmeFilename": "README.md"
}
}
7 changes: 5 additions & 2 deletions test/defineOperation_tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';
const kerberos = require('bindings')('kerberos');

const { loadBindings } = require('../lib/util');

const kerberos = loadBindings();
const defineOperation = require('../lib/util').defineOperation;
const expect = require('chai').expect;

Expand All @@ -16,7 +19,7 @@ describe('defineOperation', () => {
});

it('should validate optional parameters, with valid parameters after', function () {
expect(() => testMethod('llamas', false, true, () => {})).to.throw(
expect(() => testMethod('llamas', false, true, () => { })).to.throw(
/Invalid type for parameter `optionalString`/
);
});
Expand Down

0 comments on commit b07a5d2

Please sign in to comment.