Skip to content

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

Closed as not planned

Description

@knarwani

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.

Activity

  1. tido64 commented on Jun 12, 2023

    @tido64
    Member

    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.

  2. knarwani commented on Jun 13, 2023

    @knarwani
    Author

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

  3. added
    enhancement
    good first issue
    feature: align-deps
    and removed on Jun 15, 2023
  4. krishna8770 commented on Jul 19, 2023

    @krishna8770

    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.

  5. tido64 commented on Jul 19, 2023

    @tido64
    Member

    Hi Krishna Narwani (@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.

  6. krishna8770 commented on Jul 19, 2023

    @krishna8770

    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.

  7. tido64 commented on Jul 20, 2023

    @tido64
    Member

    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).

  8. krishna8770 commented on Jul 21, 2023

    @krishna8770

    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).

  9. tido64 commented on Jul 21, 2023

    @tido64
    Member

    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

  10. krishna8770 commented on Jul 21, 2023

    @krishna8770

    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)?

  11. tido64 commented on Aug 31, 2026

    @tido64
    Member

    Closing since there's no demand and the PR has gone stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfeature: align-depsgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions