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

fix(NODE-6592): remove dependency on bindings #220

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}
W-A-James marked this conversation as resolved.
Show resolved Hide resolved

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
Loading