-
Notifications
You must be signed in to change notification settings - Fork 6
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
Provide a method to find the root for a file path #30
base: master
Are you sure you want to change the base?
Conversation
SparshithNR
commented
Jan 9, 2020
- Ensures that we will have a method to find path for the file
1. Ensures that we will have a method to find path for the file
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "fs-merger", | |||
"version": "3.0.2", | |||
"version": "3.0.3", |
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.
new features are usually minor version bumps so likely: 3.1.0
@@ -265,6 +266,23 @@ class FSMerger { | |||
result.sort((entryA, entryB) => (entryA.relativePath > entryB.relativePath) ? 1 : -1); | |||
return result; | |||
} | |||
|
|||
getRoot(filePath: string): string | undefined { |
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.
I was thinking, should this rather be merger.realpathSync(filePath);
? I believe modeling this after realpathSync
would be ideal, as it is a real and valid fs operation, and also unambiguously will point to the concrete file on disk, regardless of funky links or mergers.
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.
realPathSync
makes more sense. Yes, it will more unambiguous as well.
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.
Awesome, I know its some extra work, but I think since this a public API, it's very well worth it.
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.
realPathSync
implementation wasn't the intention here.
The issue I am trying to solve here is, provided relative path
or absolute path
, find the corresponding root
which is part of the dirList
.
For Example:
/*
test
|
-- realtest.js
/
|
-- user
|
-- unit
|
-- test.js
*/
let fsMerger = new FSMerger(['fixture/test', '/user/testing/unit']);
let root = fsMerger.getRoot('realtest.js'); // returns `fixture/test`
let fullPath = fsMerger.getRoot('/user/testing/unit/test.js'); // returns `/user/testing/unit`
let relativePath = fsMerger.getRoot('test.js'); // returns `/user/testing/unit`