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

Allow to search in node_modules of workspaces (yarn / lerna workspaces) #10

Open shobhitchittora opened 6 years ago

shobhitchittora commented 6 years ago

When using tools like yarn and lerna, it's very common to have the below folder structures -

/node_modules
/package.json

workspace-a 
  /node_modules
  /package.json

workspace-b/
  /node_modules
  /package.json

We should have a config to allow search for child packages' node_modules. Is there a way to do that now that I'm not aware of ?

NOTE: for yarn workspaces we can read the root package.json to get workspace config, while lerna projects have a predefined structure.

jasonnutter commented 6 years ago

Right now, no, there isn't, but I'll definitely look into adding proper support for both lerna and yarn.

hardikmodha commented 6 years ago

@jasonnutter I also need this feature. I have a monorepo where the code for both the frontend and the backend repo is stored. Both the repos have node_modules directory.

I have thought of a solution.

Currently, The search-node-modules configuration option takes a single relative path to the node_modules directory. Along with that, We can make it accept an object, Where keys of the object will be user identifiable name and the value will be the path of the node_modules directory.

e.g.

// When the user wants to search inside a monorepo
"search-node-modules-path": {
  "Frontend repo": "./frontend/node_modules",
  "Backend repo": "./backend/node_modules"
}

// Normal scenarios
"search-node-modules-path": "node_modules"

Now, When the user executes the command > search node_modules via command palette we can check the value of the search-node-modules-path. If the value is an object we can display quick-pick to select the repo and user can choose which repo's node_modules to search for.

What do you think? I would be more than happy to raise a PR for this. :)

shobhitchittora commented 6 years ago

@HardikModha Great thinking! But can you think of reading this configuration from a more generalized place like the main package.json, which can use any major mono-repo manager like lerna (lerna.json in this case )or yarn. Please look into each of these and tell me your thoughts.

jasonnutter commented 6 years ago

@HardikModha That's a potential approach, however, I prefer that the extension is able to support vscode/lerna/yarn workspaces without any need for manual configuration. I am starting work now to make that happen, will update here when that is complete.

hardikmodha commented 6 years ago

Cool. Let me know If I can help implement some part of the feature. I would be more than happy to contribute. :)

hemal7735 commented 5 years ago

@jasonnutter I do want this feature 💯 I can volunteer if you need some help 😉

elektronik2k5 commented 5 years ago

Thanks for creating this package!

I believe there's an easier way to handle this scenario - without any configuration. We just need to follow node's native module resolution protocol, starting from the location of the current file/tab, looking for node_modules, recursing up the directory tree until we find a match.

So in the original example, if I'm in workspace-a/package.json, the traversal will start from workspace-a/node_modules. If none is found, we'd search in the parent directory. This isn't specific to yarn/lerna or any other tool/convention.

OriMarron commented 5 years ago

Check out my PR for solving this issue: #11