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

Have workspace Resolution functionality along with Node Module Resolution for dependency resolution #2457

Open
knarwani opened this issue Jun 9, 2023 · 9 comments
Labels
enhancement New feature or request feature: align-deps This is related to align-deps good first issue Good for newcomers

Comments

@knarwani
Copy link

knarwani commented Jun 9, 2023

What I need?
Can we please have the workspace resolution functionality as well along with node_module resolution of the dependencies?

Why I need?
I am using rnx-kit for aligning dependencies in my project. I am working on a monorepo and I wanted to use align-deps before installing any dependencies in my project (To run rnx-kit I have created a bundle of it and calling it). For that I need workspace resolution of few of my internal packages which are yet not available in node_modules. So, can we please have the workspace resolution functionality as well along with node_module resolution of the dependencies?

Where to change?
I think this is the place where my functionality can be added.

@tido64
Copy link
Member

tido64 commented Jun 12, 2023

Hi @knarwani,

Just to make sure I understood you correctly, are you seeing align-deps fail because you want to use presets that are part of the monorepo? Like we do here:

"presets": [
"microsoft/react-native",
"@rnx-kit/scripts/align-deps-preset.js"
],
"requirements": [

If that's the case, then yes, that would be the place to add that.

Would you be willing to work on this? We can also do it, but I can't promise any dates.

@knarwani
Copy link
Author

Yes, I would like to work on this actively. I will create PR once I find the correct solution for this.

@tido64 tido64 added enhancement New feature or request good first issue Good for newcomers feature: align-deps This is related to align-deps and removed needs triage 🔍 labels Jun 15, 2023
@krishna8770
Copy link

Hi there,

I wanted to change this file where loadPreset function will change to

function loadPreset(
  preset: string,
  projectRoot: string,
  resolve = require.resolve
): Preset {
  switch (preset) {
    case "microsoft/react-native":
      return reactNativePreset;
    default: {
      const info = loadInfo(preset);
      if (info !== undefined) {
        const returnResolvedPath = path.join(path.dirname(info.packageJsonPath), parsedInfo.path);
        return require(returnResolvedPath);
      }
      else {
        return require(resolve(preset, { paths: [projectRoot] }));
      }
    }
  }
}

and will add this const in config.ts

export const allPackages = getPackageInfos(process.cwd());

I tried this solution in my local and is working fine. Can you have a look at this code and let me know if I can go ahead and create a PR for this change.

Please let me know what your views on this are.

Thanks.

@tido64
Copy link
Member

tido64 commented Jul 19, 2023

Hi @krishna8770,

I'm not sure what loadInfo is supposed to do in your example, but I think it looks correct. My only concern is about doing something very expensive in this function as it may be called many times, especially in a big monorepo. It would be ideal if we can somehow pass all the workspace packages to this function. We've already done the work here:

const manifests = await getManifests(packages);

We should be able to plumb this all the way to loadPreset.

@krishna8770
Copy link

krishna8770 commented Jul 19, 2023

Yes, the expensiveness of the function was my concern also so, to address that I have exported this variable from config.ts file i.e., export const allPackages = getPackageInfos(process.cwd()); which then will be calculated only once and then passed on to further iterations. This solution is not at all increasing the runtime on my monorepo with approx 400 packages. Let me know if you are fine with this solution being merged.

@tido64
Copy link
Member

tido64 commented Jul 20, 2023

We should not use global states as we have no control over how this package may be used. Our best bet is to pipe through the getManifests result to loadPreset as I've mentioned in #2457 (comment).

@krishna8770
Copy link

I have made the subsequent changes. Can you please let me know how to create PR on this repo as I am not getting option to create new branch with either of my accounts (Microsoft or personal).

@tido64
Copy link
Member

tido64 commented Jul 21, 2023

I have made the subsequent changes. Can you please let me know how to create PR on this repo as I am not getting option to create new branch with either of my accounts (Microsoft or personal).

Please follow this guide: https://docs.github.com/en/get-started/quickstart/contributing-to-projects

@krishna8770
Copy link

Here is the PR for the change. I had to make a lot of changes even in the test files. Can you please review this once (There are few pipeline check issues, please ignore them for now I am working on them)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature: align-deps This is related to align-deps good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants