-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
feat: add fs/resolve-parent-paths-by
#2897
base: develop
Are you sure you want to change the base?
feat: add fs/resolve-parent-paths-by
#2897
Conversation
@stdlib/fs/resolve-parent-paths-by
hey @kgryte, can you explain this linting error in |
@gururaj1512 is this when you try to commit? |
@Snehil-Shah that error occurs when commiting and also while running |
@gururaj1512 Weird. I can't seem to reproduce the error. Did you follow the setup guide properly? ( |
lib/node_modules/@stdlib/fs/resolve-parent-paths-by/lib/index.js
Outdated
Show resolved
Hide resolved
Yaa, I have tried |
Co-authored-by: Snehil Shah <snehilshah.989@gmail.com> Signed-off-by: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com>
Ok, was able to reproduce it. Seems to me, it's something specific to npx as I am able to commit the file without any errors. And in any case, you don't need to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise!
lib/node_modules/@stdlib/fs/resolve-parent-paths-by/benchmark/benchmark.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/fs/resolve-parent-paths-by/lib/index.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/fs/resolve-parent-paths-by/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/fs/resolve-parent-paths-by/lib/sync.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/fs/resolve-parent-paths-by/docs/repl.txt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, was the issue with your dev environment resolved @gururaj1512?
lib/node_modules/@stdlib/fs/resolve-parent-paths-by/docs/types/index.d.ts
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/fs/resolve-parent-paths-by/docs/types/index.d.ts
Outdated
Show resolved
Hide resolved
@Snehil-Shah, the issue with my dev environment has been resolved. Thank you for checking in! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. On to @kgryte.
@stdlib/fs/resolve-parent-paths-by
fs/resolve-parent-paths-by
if ( bool ) { | ||
test( spath, onTest ); | ||
} | ||
FLG += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic seems off. test
may be an asynchronous function. In which case, the onTest
callback will be called after hitting FLG += 1
. If done multiple times, that could mean that L203-221 could be exercised before any onTest
call is complete. This race condition needs to be addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kgryte, I wanted to clarify whether using async/await to wait for the test function to complete would be an appropriate solution here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, no using async/await. This implementation should be entirely callback-based
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function some( paths, dir, test, done ) {
var child;
var spath;
var FLG;
var out;
FLG = 0; // initialize flag to track if we are done traversing a directory level
out = [];
// Start at a base directory and continue moving up through each parent directory...
return next( dir );
/**
* Resolves paths within a directory.
*
* @private
* @param {string} dir - directory to search
*/
function next( dir ) {
var i;
for ( i = 0; i < paths.length; i++ ) {
spath = resolve( dir, paths[ i ] );
exists( spath, getCallback( spath ) );
}
}
/**
* Returns a callback to be invoked upon checking for path existence.
*
* @private
* @param {string} spath - resolved path
* @returns {Callback} callback
*/
function getCallback( spath ) {
return onExists;
/**
* Callback invoked after testing a resolved path.
*
* @private
* @param {(Error|null)} error - error object
* @param {boolean} bool - boolean indicating if a path exists
* @returns {void}
*/
function onTest( error, bool ) {
if ( error ) {
return done( error );
}
if ( bool ) {
out.push( spath );
}
// Increment flag after `test` completes:
FLG += 1;
if ( FLG === paths.length ) {
// Check if we have resolved any paths...
if ( out.length > 0 ) {
return done( null, out );
}
// Resolve a parent directory:
child = dir;
dir = resolve( dir, '..' );
// Reset flag:
FLG = 0;
// If we have already reached root, we cannot resolve any higher directories...
if ( child === dir ) {
return done( null, out );
}
// Resolve paths at next directory level:
return next( dir );
}
}
/**
* Callback invoked after checking for path existence.
*
* @private
* @param {(Error|null)} error - error object
* @param {boolean} bool - boolean indicating if a path exists
* @returns {void}
*/
function onExists( error, bool ) { // eslint-disable-line node/handle-callback-err
if ( bool ) {
// Pass the path to the `test` function and use `onTest` as the callback:
test( spath, onTest );
} else {
// Increment flag if the path does not exist:
FLG += 1;
if ( FLG === paths.length ) {
// Check if we have resolved any paths...
if ( out.length > 0 ) {
return done( null, out );
}
// Resolve a parent directory:
child = dir;
dir = resolve( dir, '..' );
// Reset flag:
FLG = 0;
// If we have already reached root, we cannot resolve any higher directories...
if ( child === dir ) {
return done( null, out );
}
// Resolve paths at next directory level:
return next( dir );
}
}
}
}
}
Does this work out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kgryte, Am I doing it right in above mentioned programme, It passes all test cases & would pass the race conditions during async processing
*/ | ||
function onExists( error, bool ) { // eslint-disable-line node/handle-callback-err | ||
if ( bool ) { | ||
test( spath, onTest ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem here.
…/gururaj1512/2897
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR needs to address the race conditions during async processing before we can merge.
Resolves #2567.
Description
This pull request:
@stdlib/fs/resolve-parent-paths-by
#2567Related Issues
This pull request:
@stdlib/fs/resolve-parent-paths-by
#2567Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers