Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SparshithNR
Copy link
Collaborator

  1. 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",
Copy link
Collaborator

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 {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

@SparshithNR SparshithNR Jan 10, 2020

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`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants