vscode-search-node-modules icon indicating copy to clipboard operation
vscode-search-node-modules copied to clipboard

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

Open shobhitchittora opened this issue 7 years ago • 8 comments

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.

shobhitchittora avatar Aug 21 '18 10:08 shobhitchittora

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

jasonnutter avatar Aug 22 '18 04:08 jasonnutter

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

hardikmodha avatar Sep 13 '18 07:09 hardikmodha

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

shobhitchittora avatar Sep 13 '18 07:09 shobhitchittora

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

jasonnutter avatar Sep 15 '18 16:09 jasonnutter

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

hardikmodha avatar Sep 17 '18 04:09 hardikmodha

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

hemal7735 avatar Dec 28 '18 07:12 hemal7735

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.

elektronik2k5 avatar Dec 31 '18 05:12 elektronik2k5

Check out my PR for solving this issue: #11

OriMarron avatar May 06 '19 12:05 OriMarron