Skip to content

Commit

Permalink
Fix dirname bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Jan 26, 2017
1 parent 62e3993 commit 8349d5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions tools/pkgs/clis/lib/read_pkgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var getKeys = require( 'object-keys' ).shim();
var readJSON = require( '@stdlib/fs/read-json' );
var isString = require( '@stdlib/utils/is-string' ).isPrimitive;
var hasOwnProp = require( '@stdlib/utils/has-own-property' );
var dirname = require( '@stdlib/utils/dirname' );


// MAIN //
Expand All @@ -18,6 +19,7 @@ var hasOwnProp = require( '@stdlib/utils/has-own-property' );
* @private
* @param {StringArray} files - list of `package.json` files
* @param {Callback} clbk - callback to invoke upon completion
* @returns {void}
*/
function readPkgs( files, clbk ) {
var total;
Expand All @@ -28,7 +30,7 @@ function readPkgs( files, clbk ) {
i = -1;
out = [];

next();
return next();

/**
* Reads the next `package.json` file.
Expand All @@ -47,10 +49,12 @@ function readPkgs( files, clbk ) {
* @private
* @param {(Error|null)} error - error object
* @param {Object} json - JSON object
* @returns {void}
*/
function onRead( error, json ) {
var fpath;
var keys;
var dir;
var j;
var k;

Expand All @@ -61,16 +65,17 @@ function readPkgs( files, clbk ) {
}
debug( 'Successfully read file: %s (%d of %d).', files[ i ], j, total );

dir = dirname( files[ i ] );
if ( isString( json.bin ) ) {
fpath = resolve( files[ i ], json.bin );
fpath = resolve( dir, json.bin );
debug( 'Resolved %s.', fpath );
out.push( fpath );
} else if ( hasOwnProp( json, 'bin' ) ) {
debug( 'Resolving CLI paths...' );
keys = getKeys( json.bin );
for ( k = 0; k < keys.length; k++ ) {
fpath = json.bin[ keys[k] ];
fpath = resolve( files[ i ], fpath );
fpath = resolve( dir, fpath );
debug( 'Resolved %s.', fpath );
out.push( fpath );
}
Expand All @@ -89,6 +94,7 @@ function readPkgs( files, clbk ) {
*
* @private
* @param {(Error|null)} error - error object
* @returns {void}
*/
function done( error ) {
if ( error ) {
Expand Down
6 changes: 4 additions & 2 deletions tools/pkgs/clis/lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var copy = require( '@stdlib/utils/copy' );
var readJSON = require( '@stdlib/fs/read-json' ).sync;
var isString = require( '@stdlib/utils/is-string' ).isPrimitive;
var hasOwnProp = require( '@stdlib/utils/has-own-property' );
var dirname = require( '@stdlib/utils/dirname' );
var config = require( './config.json' );
var validate = require( './validate.js' );

Expand Down Expand Up @@ -73,14 +74,15 @@ function findCLIs( options ) {
if ( file instanceof Error ) {
throw file;
}
dir = dirname( files[ i ] );
if ( isString( file.bin ) ) {
fpath = resolve( files[ i ], file.bin );
fpath = resolve( dir, file.bin );
out.push( fpath );
} else if ( hasOwnProp( file, 'bin' ) ) {
keys = getKeys( file.bin );
for ( j = 0; j < keys.length; j++ ) {
fpath = file.bin[ keys[j] ];
fpath = resolve( files[ i ], fpath );
fpath = resolve( dir, fpath );
out.push( fpath );
}
}
Expand Down

0 comments on commit 8349d5e

Please sign in to comment.