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(analyze): node-gyp-build not including zeromq prebuilds #392

Merged
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "tsc",
"prepublishOnly": "tsc && rm out/utils/*.d.ts && rm out/tsconfig.tsbuildinfo",
"test": "jest --verbose",
"test-watch": "jest --watch",
styfle marked this conversation as resolved.
Show resolved Hide resolved
"test-verbose": "tsc --sourceMap && jest --verbose --coverage --globals \"{\\\"coverage\\\":true}\""
},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@ export default async function analyze(id: string, code: string, job: Job): Promi
// handle case: require("node-gyp-build")(path.join(__dirname, ".."))
const calledWithPathJoinDirname =
node.arguments.length === 1 &&
node.arguments[0].callee.object.name === "path" &&
node.arguments[0].callee.property.name === "join" &&
node.arguments[0].callee?.object?.name === "path" &&
node.arguments[0].callee?.property?.name === "join" &&
node.arguments[0].arguments.length === 2 &&
node.arguments[0].arguments[0].type === 'Identifier' &&
node.arguments[0].arguments[0].name === '__dirname' &&
Expand Down
2 changes: 2 additions & 0 deletions test/integration/zeromq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const zmq = require("zeromq");
const sock = new zmq.Push;
23 changes: 6 additions & 17 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,14 @@ for (const { testName, isRoot } of unitTests) {
}
let sortedFileList = [...fileList].sort()

if (testName === 'microtime-node-gyp') {
let foundMatchingBinary = false
sortedFileList = sortedFileList.filter(file => {
if (file.endsWith('node-napi.node') || file.endsWith('node.napi.node')) {
// remove from fileList for expected checking
// as it will differ per platform
foundMatchingBinary = true
fileList.delete(file)
return false
}
return true
})
expect(foundMatchingBinary).toBe(true)
}

if (testName === 'zeromq-node-gyp') {
if (testName === 'microtime-node-gyp' || testName === 'zeromq-node-gyp') {
let foundMatchingBinary = false
const isBinaryFnMap = {
'microtime-node-gyp': file => file.endsWith('node-napi.node') || file.endsWith('node.napi.node'),
'zeromq-node-gyp': file => file.endsWith('node.napi.glibc.node') || file.endsWith('node.napi.musl.node'),
}
sortedFileList = sortedFileList.filter(file => {
if (file.startsWith('node.napi.')) {
if (isBinaryFnMap[testName](file)) {
// remove from fileList for expected checking
// as it will differ per platform
foundMatchingBinary = true
Expand Down
3 changes: 2 additions & 1 deletion test/unit/zeromq-node-gyp/input.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require('zeromq');
const zeromq = require('zeromq');
const sock = new zmq.Push;
8 changes: 5 additions & 3 deletions test/unit/zeromq-node-gyp/output.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[
"node_modules/@aminya/node-gyp-build/index.js",
"node_modules/@aminya/node-gyp-build/package.json",
"node_modules/zeromq/lib/draft.js",
"node_modules/zeromq/lib/index.js",
"node_modules/zeromq/lib/native.js",
"node_modules/zeromq/lib/util.js",
"node_modules/zeromq/package.json",
"node_modules/zeromq/prebuilds/darwin-x64/node.napi.glibc.node",
styfle marked this conversation as resolved.
Show resolved Hide resolved
"test/unit/zeromq-node-gyp/input.js",
];
"package.json",
"test/unit/zeromq-node-gyp/input.js"
]
Loading