jasonnutter / vscode-search-node-modules

Simple plugin for VS Code that allows you to quickly navigate the file inside your project's node_modules directory.
https://marketplace.visualstudio.com/items?itemName=jasonnutter.search-node-modules
MIT License
60 stars 17 forks source link

Suggestion: Add initial support for Lerna monorepos #11

Closed OriMarron closed 5 years ago

OriMarron commented 5 years ago

This is a suggestion to support searching the node_modules of child packages in lerna monorepos.

(related to #10)

background

Workspaces that use lerna usually have the following file structure:

/node_modules
/package.json
/lerna.json

/packages/project-a 
  /node_modules
  /package.json

/packages/project-b/
  /node_modules
  /package.json

Currently, for workspaces with this structure, the extension will search only in the root /node_modules, leaving the user unable to search in one of the child projects.

With this PR, the user will be prompted to select which project to search in. image

Logic

The logic that is used is as follows:

  1. If there is no lerna.json file at the root level - continue as before

  2. read lerna.json file, and look at the packages field. Example json config file:

    {
    "packages": [
    "packages/*"
    ],
    "version": "0.0.0"
    }
  3. Search for packages matching the pattern(s) using glob. a package is a folder containing a pakage.json file

  4. If no packages are found - search the root /node_modules as before

  5. Prompt the user to choose a project to search in: either the root or one of the packages

  6. Search the selected project's /node_modules folder using the existing logic

Note: patterns containing ** are ignored for now

Please tell me what you think. If you agree with this direction, I would gladly extend the support to also include ** and yarn projects. @jasonnutter

jasonnutter commented 5 years ago

This looks great, thanks for the contribution! I tried a couple times to get this working and kept getting stuck, nice to see someone get it figured out.

I have some small pieces of feedback, would you like that now, or were you thinking of adding the yarn support to this PR (if you think yarn support may drastically change this PR, I'll wait to provide any detailed feedback until that's ready)?

Thanks!

OriMarron commented 5 years ago

Please provide any feedback! I will address it as soon as possible :)

OriMarron commented 5 years ago

I just added a commit with support for Yarn workspaces.

It works exactly the same, apart from looking in package.json/workspaces instead of lerna.json/packages

jasonnutter commented 5 years ago

Awesome, I'll take a closer look today!

One question: one thing I kept getting hung up on was how to properly implement support for when VS Code / yarn / lerna workspaces are nested, e.g. a lerna workspace inside a VS Code workspace. Would that be supported with this implementation?

jasonnutter commented 5 years ago

Ultimately not a blocker if not, as that is something that could be added incrementally. Just wanted to see if that was considered.

OriMarron commented 5 years ago

I actually kept it in mind, and this case is fully supported.

Let's say your workspace looks like this:

/regular-repo
    /node_modules
    /package.json

/lerna-repo
    /node_modules
    /lerna.json
    /packages/project1
        /package.json
        /node_modules

    /packages/project2
        /package.json
        /node_modules

you will first be prompted to choose between regular-repo and lerna-repo. If you chose lerna-repo, only then you will be prompted to choose between project1 and project2

OriMarron commented 5 years ago

Thanks for your quick review and feedback! I committed the requested changes

jasonnutter commented 5 years ago

Apologies for the delay, have been on vacation and forgot to circle back on this. I'll get this merged and published this weekend. Thanks again!

OriMarron commented 5 years ago

@jasonnutter Hi, any news on publishing a new version?

jasonnutter commented 5 years ago

Sorry for the delay, working on it! See my comment on #13

OrenZak commented 1 year ago

@jasonnutter when will be a release ?