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

[rush] Find rush.json location by using 'dirname' at most 10 times #4619

Open
tianmagongyue opened this issue Apr 2, 2024 · 8 comments
Open

Comments

@tianmagongyue
Copy link

tianmagongyue commented Apr 2, 2024

I see rush try to find rush.json location by using 'Path.dirname' at most 10 times. Why was the final decision made ten times? It seems like a magic number. Why not 8 or 12 times?

for (let i: number = 0; i < 10; ++i) {
  const rushJsonFilename: string = path.join(currentFolder, RushConstants.rushJsonFilename);

  if (FileSystem.exists(rushJsonFilename)) {
    if (i > 0 && verbose) {
      // eslint-disable-next-line no-console
      console.log('Found configuration in ' + rushJsonFilename);
    }

    if (verbose) {
      // eslint-disable-next-line no-console
      console.log('');
    }

    return rushJsonFilename;
  }

  const parentFolder: string = path.dirname(currentFolder);
  if (parentFolder === currentFolder) {
    break;
  }

  currentFolder = parentFolder;
}
@iclanton
Copy link
Member

iclanton commented Apr 3, 2024

The way this code was merged into main is slightly weird (it was a cherry-pick from a rush-next branch about eight years ago), so I'm not finding any PR discussion around this. I'm pretty sure it's an arbitrary number that @octogonz picked with the thought that the CWD will probably never be >10 levels deeper than the repo root.

That code likely can/should be refactored to just keep going until the disk root is reached. I might do that in the next few days, unless you, @tianmagongyue, are interested in doing that.

@tianmagongyue
Copy link
Author

tianmagongyue commented Apr 4, 2024

The way this code was merged into main is slightly weird (it was a cherry-pick from a rush-next branch about eight years ago), so I'm not finding any PR discussion around this. I'm pretty sure it's an arbitrary number that @octogonz picked with the thought that the CWD will probably never be >10 levels deeper than the repo root.

That code likely can/should be refactored to just keep going until the disk root is reached. I might do that in the next few days, unless you, @tianmagongyue, are interested in doing that.

OK, I can try to refactor this method with the idea 'keep going until the repo root is reached'. But it may take a little longer for me, and I need you or others to help me review the code.

@octogonz
Copy link
Collaborator

octogonz commented Apr 4, 2024

I was probably worried about the disk i/o cost in the negative case, for example if "rushx" is invoked repeatedly in a context where rush.json will never be found. Agree that this limit can be removed.

@tianmagongyue
Copy link
Author

I was probably worried about the disk i/o cost in the negative case, for example if "rushx" is invoked repeatedly in a context where rush.json will never be found. Agree that this limit can be removed.

Got it

@octogonz
Copy link
Collaborator

octogonz commented Apr 4, 2024

Btw there is a specific way to reliably detect when you reach the root on NTFS vs Unix filesystems. The PackageJsonLookup API in this repo is a good example to copy

@tianmagongyue
Copy link
Author

tianmagongyue commented Apr 6, 2024

hi, I have refactored the tryFindRushJsonLocation function, and I need to be a collaborator of rushstack so that I can start a merge request. cc @iclanton @octogonz

@iclanton
Copy link
Member

iclanton commented Apr 6, 2024

@tianmagongyue - did you create a fork of this repo and push your feature branch there? You shouldn't need any permissions to create a PR from a fork.

@tianmagongyue
Copy link
Author

@tianmagongyue - did you create a fork of this repo and push your feature branch there? You shouldn't need any permissions to create a PR from a fork.

ok, I'll create a fork

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

No branches or pull requests

3 participants