Skip to content

Commit

Permalink
Merge 5fd5634 into 4486bed
Browse files Browse the repository at this point in the history
  • Loading branch information
allain committed Oct 31, 2015
2 parents 4486bed + 5fd5634 commit 554eb1b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ var Promise = require( 'es6-promise' ).Promise;
*
* @tested
*/
function readDirectory( projectPath, credits ) {
function readDirectory( projectPath, credits, seen ) {
credits = credits || [];
seen = seen || [];

if ( seen[ projectPath ] ) {
return credits;
}

seen[ projectPath ] = true;

var depPath = path.join( projectPath, 'node_modules' );

Expand Down Expand Up @@ -47,7 +54,7 @@ function readDirectory( projectPath, credits ) {
} );
}

readDirectory( path.join( depPath, name ), credits );
readDirectory( fs.realpathSync( path.join( depPath, name ) ), credits, seen );
}
} );

Expand Down
32 changes: 29 additions & 3 deletions index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test( 'credits - folder exists', t => {
'utf8'
);


fs.mkdirSync( `${path}/node_modules/bar/node_modules` );
fs.mkdirSync( `${path}/node_modules/bar/node_modules/boom` );

Expand Down Expand Up @@ -56,6 +57,28 @@ test( 'credits - folder exists', t => {
'utf8'
);



fs.mkdirSync( `${path}/linked/` );
fs.writeFileSync(
`${path}/linked/package.json`,
JSON.stringify( { author : 'Bob Loblaw' } ),
'utf8'
);
fs.symlinkSync( `${path}/linked`, `${path}/node_modules/linked` );


fs.mkdirSync( `${path}/node_modules/cycle` );
fs.writeFileSync(
`${path}/node_modules/cycle/package.json`,
JSON.stringify( { author : 'Bob Loblaw' } ),
'utf8'
);

fs.mkdirSync( `${path}/node_modules/cycle/node_modules` );
fs.symlinkSync( `${path}/node_modules/cycle`, `${path}/node_modules/cycle/node_modules/cycle` );


credits( path )
.then( credits => {
t.same( credits[ 0 ].name, 'Alice Bobson' );
Expand All @@ -64,12 +87,15 @@ test( 'credits - folder exists', t => {
t.same( credits[ 1 ].name, 'Bob Calsow' );
t.same( credits[ 1 ].packages, [ 'boing', 'foo' ] );

t.same( credits[ 2 ].name, 'Randy Ran' );
t.same( credits[ 2 ].packages, [ 'baz' ] );
t.same( credits[ 2 ].name, 'Bob Loblaw' );
t.same( credits[ 2 ].packages, [ 'cycle', 'linked' ] );

t.same( credits[ 3 ].name, 'Bobby Bob' );
t.same( credits[ 3 ].name, 'Randy Ran' );
t.same( credits[ 3 ].packages, [ 'baz' ] );

t.same( credits[ 4 ].name, 'Bobby Bob' );
t.same( credits[ 4 ].packages, [ 'baz' ] );

cleanUpCb();

t.end();
Expand Down

0 comments on commit 554eb1b

Please sign in to comment.