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

tools: add tool to check for N-API modules #346

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
squash! address review comments
  • Loading branch information
Gabriel Schulhof committed Sep 19, 2018
commit 9c81e5feca283d46bb6b29a2f00e049d375a2733
18 changes: 9 additions & 9 deletions tools/check-napi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ function checkFile(file, command, arguments, reducer) {
let isNapi = undefined;
child.stdout.on('data', (chunk) => {
if (isNapi === undefined) {
chunk = leftover + chunk.toString();
const haveLeftover = !!chunk.match(/[\r\n]+$/);
chunk = chunk.split(/[\r\n]+/);
chunk = (leftover + chunk.toString()).split(/[\r\n]+/);
leftover = chunk.pop();
isNapi = chunk.reduce(reducer, isNapi);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, we can kill the child process if isNapi is true, right?

if (isNapi !== undefined) {
child.kill();
}
}
});
child.on('exit', (code, signal) => {
child.on('close', (code, signal) => {
if ((code === null && signal !== null) || (code !== 0)) {
console.log(
command + ' exited with code: ' + code + ' and signal: ' + signal);
Expand All @@ -40,9 +41,8 @@ function checkFileUNIX(file) {
checkFile(file, 'nm', ['-a', file], (soFar, line) => {
if (soFar === undefined) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Indentation is not consistent in this and the other two functions as well.

line = line.match(/([0-9a-f]*)? ([a-zA-Z]) (.*$)/);
line.shift();
if (line[1] === 'U') {
if (line[2].match(/^napi/)) {
if (line[2] === 'U') {
if (/^napi/.test(line[3])) {
soFar = true;
}
}
Expand All @@ -56,7 +56,7 @@ function checkFileWin32(file) {
checkFile(file, 'dumpbin', ['/imports', file], (soFar, line) => {
if (soFar === undefined) {
line = line.match(/([0-9a-f]*)? +([a-zA-Z0-9]) (.*$)/);
if (line && line[line.length - 1].match(/^napi/)) {
if (line && /^napi/.test(line[line.length - 1])) {
soFar = true;
}
}
Expand All @@ -74,7 +74,7 @@ function recurse(top) {
if (!error) {
if (stats.isDirectory()) {
recurse(item);
} else if (item.match(/[.]node$/) &&
} else if (/[.]node$/.test(item) &&
// Explicitly ignore files called 'nothing.node' because they are
// artefacts of node-addon-api having identified a version of
// Node.js that ships with a correct implementation of N-API.
Expand Down