Skip to content
41 changes: 35 additions & 6 deletions lib/node_modules/@stdlib/_tools/pkgs/addons/lib/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,38 @@
var logger = require( 'debug' );
var dirname = require( '@stdlib/utils/dirname' );
var exists = require( '@stdlib/fs/exists' );
var join = require( '@stdlib/array/base/join' );


// VARIABLES //

var debug = logger( 'pkgs:add-ons:resolve' );

var THRESHOLD = 3;
var FILES = [
[ 'src', 'Makefile' ],
[ 'binding.gyp' ],

// WARNING: we assume that a package does NOT have both an `addon.c` AND an `addon.cpp` file!

Check warning on line 39 in lib/node_modules/@stdlib/_tools/pkgs/addons/lib/inspect.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'warning' comment: 'WARNING: we assume that a package does...'
[ 'src', 'addon.c' ],
[ 'src', 'addon.cpp' ]
];


// MAIN //

/**
* Inspects packages for add-ons.
*
* @private
* @param {StringArray} files - list of `package.json` files
* @param {ArrayLikeObject<string>} files - list of `package.json` files
* @param {Callback} clbk - callback to invoke upon completion
* @returns {void}
*/
function inspect( files, clbk ) {
var counter;
var total;
var npass;
var out;
var i;

Expand All @@ -60,15 +73,20 @@
function next() {
var fpath;
var dir;
var j;

i += 1;
debug( 'Inspecting package %d of %d: %s', i+1, total, files[ i ] );

dir = dirname( files[ i ] );
fpath = resolve( dir, 'src', 'Makefile' );

counter = 0;
npass = 0;
debug( 'Checking for add-on...' );
exists( fpath, onExists );
for ( j = 0; j < FILES.length; j++ ) {
debug( 'Checking for add-on file: %s', join( FILES[ j ], '/' ) );
fpath = resolve.apply( null, [ dir ].concat( FILES[ j ] ) );
exists( fpath, onExists );
}
}

/**
Expand All @@ -81,9 +99,21 @@
*/
function onExists( error, bool ) {
var j = i + 1;

counter += 1;
debug( 'Finished checking for add-on file (%d of %d).', counter, FILES.length );
if ( error ) {
debug( 'Encountered an error when testing for add-on: %s (%d of %d). Error: %s', files[ i ], j, total, error.message );
} else if ( bool ) {
debug( 'Detected add-on file.' );
npass += 1;
} else {
debug( 'Unable to detect add-on file.' );
}
if ( counter < FILES.length ) {
return;
}
if ( npass >= THRESHOLD ) {
debug( 'Detected add-on.' );
out.push( dirname( files[ i ] ) );
} else {
Expand All @@ -99,8 +129,7 @@
* @returns {void}
*/
function done() {
var j;
j = i + 1;
var j = i + 1;
if ( j < total ) {
debug( 'Inspected %d of %d packages.', j, total );
return next();
Expand Down
15 changes: 10 additions & 5 deletions lib/node_modules/@stdlib/_tools/pkgs/addons/lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@ var validate = require( './validate.js' );
* @param {Options} [options] - function options
* @param {string} [options.dir] - root directory from which to search for add-ons
* @param {string} [options.pattern='**\/package.json'] - glob pattern
* @param {StringArray} [options.ignore] - glob pattern(s) to exclude matches
* @param {ArrayLikeObject<string>} [options.ignore] - glob pattern(s) to exclude matches
* @throws {TypeError} options argument must be an object
* @throws {TypeError} must provide valid options
* @throws {Error} `pattern` option must end with `package.json`
* @throws {Error} unable to parse `package.json` as JSON
* @returns {(EmptyArray|StringArray)} list of add-ons
* @returns {(EmptyArray|Array<string>)} list of add-ons
*
* @example
* var pkgs = findAddons();
* // returns [...]
*/
function findAddons( options ) {
var fpath;
var gopts;
var files;
var opts;
Expand Down Expand Up @@ -83,8 +82,14 @@ function findAddons( options ) {
out = [];
for ( i = 0; i < files.length; i++ ) {
dir = dirname( files[ i ] );
fpath = resolve( dir, 'src', 'Makefile' );
if ( exists( fpath ) ) {
if (
exists( resolve( dir, 'src', 'Makefile' ) ) &&
exists( resolve( dir, 'binding.gyp' ) ) &&
(
exists( resolve( dir, 'src', 'addon.c' ) ) ||
exists( resolve( dir, 'src', 'addon.cpp' ) )
)
) {
out.push( dir );
}
}
Expand Down